summaryrefslogtreecommitdiffhomepage
path: root/libs
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2009-06-21 13:42:26 +0000
committerSteven Barth <steven@midlink.org>2009-06-21 13:42:26 +0000
commit30b216f774c2404a965807ddb93a4a4b2aaeac04 (patch)
tree2d4bbdadc263f495e358af0fda9baf5b02274c3b /libs
parent2baab00b19fc6eb4e0aca4da035292e37d94a640 (diff)
Drop support for luaposix and bitlib (obsoleted by nixio)
Mark luci.fs as deprecated
Diffstat (limited to 'libs')
-rw-r--r--libs/cbi/luasrc/view/cbi/filebrowser.htm8
-rw-r--r--libs/cbi/luasrc/view/cbi/upload.htm2
-rw-r--r--libs/core/luasrc/ccache.lua15
-rw-r--r--libs/core/luasrc/fs.lua128
-rw-r--r--libs/httpclient/luasrc/httpclient/receiver.lua9
-rw-r--r--libs/sys/luasrc/sys.lua85
-rw-r--r--libs/uvl/luasrc/uvl/datatypes.lua12
-rw-r--r--libs/web/luasrc/dispatcher.lua11
-rw-r--r--libs/web/luasrc/sauth.lua16
-rw-r--r--libs/web/luasrc/template.lua10
10 files changed, 113 insertions, 183 deletions
diff --git a/libs/cbi/luasrc/view/cbi/filebrowser.htm b/libs/cbi/luasrc/view/cbi/filebrowser.htm
index 0e223a933..5eda993b6 100644
--- a/libs/cbi/luasrc/view/cbi/filebrowser.htm
+++ b/libs/cbi/luasrc/view/cbi/filebrowser.htm
@@ -66,10 +66,10 @@ $Id$
local filestat = luci.fs.stat( filepath )
local baseurl = luci.dispatcher.build_url('admin', 'filebrowser')
- if filestat and filestat.type == "regular" then
+ if filestat and filestat.type == "reg" then
table.remove( path, #path )
filepath = table.concat( path, '/' ) .. '/'
- elseif not ( filestat and filestat.type == "directory" ) then
+ elseif not ( filestat and filestat.type == "dir" ) then
path = { '' }
filepath = '/'
else
@@ -99,7 +99,7 @@ $Id$
<ul>
<% for _, e in luci.util.vspairs(entries) do
local stat = luci.fs.stat(filepath..e)
- if e ~= '.' and e ~= '..' and stat and stat.type == 'directory' then
+ if e ~= '.' and e ~= '..' and stat and stat.type == 'dir' then
-%>
<li class="dir">
<img src="/luci-static/resources/cbi/folder.png" alt="Directory" />
@@ -109,7 +109,7 @@ $Id$
<% for _, e in luci.util.vspairs(entries) do
local stat = luci.fs.stat(filepath..e)
- if stat and stat.type ~= 'directory' then
+ if stat and stat.type ~= 'dir' then
-%>
<li class="file">
<img src="/luci-static/resources/cbi/file.png" alt="File" />
diff --git a/libs/cbi/luasrc/view/cbi/upload.htm b/libs/cbi/luasrc/view/cbi/upload.htm
index 2c293cbdd..a4ab0c958 100644
--- a/libs/cbi/luasrc/view/cbi/upload.htm
+++ b/libs/cbi/luasrc/view/cbi/upload.htm
@@ -19,7 +19,7 @@ $Id$
-%>
<%+cbi/valueheader%>
<% if v then %>
- <%:cbi_upload Uploaded File%> (<%=t.byte_format(luci.fs.stat(v).size or 0)%>)
+ <%:cbi_upload Uploaded File%> (<%=t.byte_format(luci.fs.stat(v, "size") or 0)%>)
<input type="hidden"<%= attr("value", v) .. attr("name", cbid) .. attr("id", cbid) %> />
<input class="cbi-input-image" type="image" value="<%:cbi_replace%>" name="cbi.rlf.<%=section .. "." .. self.option%>" alt="<%:cbi_replace%>" title="<%:cbi_replace%>" src="<%=resource%>/cbi/reload.gif" />
<% else %>
diff --git a/libs/core/luasrc/ccache.lua b/libs/core/luasrc/ccache.lua
index 83e82d9fd..c9771af21 100644
--- a/libs/core/luasrc/ccache.lua
+++ b/libs/core/luasrc/ccache.lua
@@ -14,8 +14,9 @@ $Id$
]]--
local io = require "io"
+local fs = require "nixio.fs"
local util = require "luci.util"
-local posix = require "posix"
+local nixio = require "nixio"
local debug = require "debug"
local string = require "string"
local package = require "package"
@@ -36,10 +37,10 @@ function cache_enable(cachepath, mode)
mode = mode or "r--r--r--"
local loader = package.loaders[2]
- local uid = posix.getpid("uid")
+ local uid = nixio.getpid("uid")
- if not posix.stat(cachepath) then
- posix.mkdir(cachepath)
+ if not fs.stat(cachepath) then
+ fs.mkdir(cachepath)
end
local function _encode_filename(name)
@@ -51,19 +52,19 @@ function cache_enable(cachepath, mode)
end
local function _load_sane(file)
- local stat = posix.stat(file)
+ local stat = fs.stat(file)
if stat and stat.uid == uid and stat.mode == mode then
return loadfile(file)
end
end
local function _write_sane(file, func)
- if posix.getpid("uid") == uid then
+ if nixio.getuid() == uid then
local fp = io.open(file, "w")
if fp then
fp:write(util.get_bytecode(func))
fp:close()
- posix.chmod(file, mode)
+ fs.chmod(file, mode)
end
end
end
diff --git a/libs/core/luasrc/fs.lua b/libs/core/luasrc/fs.lua
index d4247d783..f98f6e605 100644
--- a/libs/core/luasrc/fs.lua
+++ b/libs/core/luasrc/fs.lua
@@ -27,7 +27,8 @@ limitations under the License.
local io = require "io"
local os = require "os"
local ltn12 = require "luci.ltn12"
-local posix = require "posix"
+local fs = require "nixio.fs"
+local nutil = require "nixio.util"
local type = type
@@ -41,7 +42,7 @@ module "luci.fs"
-- @return Number containing the return code, 0 on sucess or nil on error
-- @return String containing the error description (if any)
-- @return Number containing the os specific errno (if any)
-access = posix.access
+access = fs.access
--- Evaluate given shell glob pattern and return a table containing all matching
-- file and directory entries.
@@ -51,81 +52,53 @@ access = posix.access
-- @return Table containing file and directory entries or nil if no matches
-- @return String containing the error description (if no matches)
-- @return Number containing the os specific errno (if no matches)
-glob = posix.glob
+function glob(...)
+ local iter, code, msg = fs.glob(...)
+ if iter then
+ return nutil.consume(iter)
+ else
+ return nil, code, msg
+ end
+end
--- Checks wheather the given path exists and points to a regular file.
-- @param filename String containing the path of the file to test
-- @return Boolean indicating wheather given path points to regular file
function isfile(filename)
- return posix.stat(filename, "type") == "regular"
+ return fs.stat(filename, "type") == "reg"
end
--- Checks wheather the given path exists and points to a directory.
-- @param dirname String containing the path of the directory to test
-- @return Boolean indicating wheather given path points to directory
function isdirectory(dirname)
- return posix.stat(dirname, "type") == "directory"
+ return fs.stat(dirname, "type") == "dir"
end
--- Read the whole content of the given file into memory.
-- @param filename String containing the path of the file to read
-- @return String containing the file contents or nil on error
-- @return String containing the error message on error
-function readfile(filename)
- local fp, err = io.open(filename)
-
- if fp == nil then
- return nil, err
- end
-
- local data = fp:read("*a")
- fp:close()
- return data
-end
+readfile = fs.readfile
--- Write the contents of given string to given file.
-- @param filename String containing the path of the file to read
-- @param data String containing the data to write
-- @return Boolean containing true on success or nil on error
-- @return String containing the error message on error
-function writefile(filename, data)
- local fp, err = io.open(filename, "w")
-
- if fp == nil then
- return nil, err
- end
-
- fp:write(data)
- fp:close()
-
- return true
-end
+writefile = fs.writefile
--- Copies a file.
-- @param source Source file
-- @param dest Destination
-- @return Boolean containing true on success or nil on error
-function copy(source, dest)
- return ltn12.pump.all(
- ltn12.source.file(io.open(source)),
- ltn12.sink.file(io.open(dest, "w"))
- )
-end
+copy = fs.datacopy
--- Renames a file.
-- @param source Source file
-- @param dest Destination
-- @return Boolean containing true on success or nil on error
-function rename(source, dest)
- local stat, err, code = os.rename(source, dest)
- if code == 18 then
- stat, err, code = copy(source, dest)
- if stat then
- stat, err, code = unlink(source)
- end
- end
- return stat, err, code
-end
+rename = fs.move
--- Get the last modification time of given file path in Unix epoch format.
-- @param path String containing the path of the file or directory to read
@@ -133,7 +106,7 @@ end
-- @return String containing the error description (if any)
-- @return Number containing the os specific errno (if any)
function mtime(path)
- return posix.stat(path, "mtime")
+ return fs.stat(path, "mtime")
end
--- Set the last modification time of given file path in Unix epoch format.
@@ -143,7 +116,9 @@ end
-- @return 0 in case of success nil on error
-- @return String containing the error description (if any)
-- @return Number containing the os specific errno (if any)
-utime = posix.utime
+function utime(path, mtime, atime)
+ return fs.utimes(path, atime, mtime)
+end
--- Return the last element - usually the filename - from the given path with
-- the directory component stripped.
@@ -152,7 +127,7 @@ utime = posix.utime
-- @param path String containing the path to strip
-- @return String containing the base name of given path
-- @see dirname
-basename = posix.basename
+basename = fs.basename
--- Return the directory component of the given path with the last element
-- stripped of.
@@ -161,7 +136,7 @@ basename = posix.basename
-- @param path String containing the path to strip
-- @return String containing the directory component of given path
-- @see basename
-dirname = posix.dirname
+dirname = fs.dirname
--- Return a table containing all entries of the specified directory.
-- @class function
@@ -170,7 +145,17 @@ dirname = posix.dirname
-- @return Table containing file and directory entries or nil on error
-- @return String containing the error description on error
-- @return Number containing the os specific errno on error
-dir = posix.dir
+function dir(...)
+ local iter, code, msg = fs.dir(...)
+ if iter then
+ local t = nutil.consume(iter)
+ t[#t+1] = "."
+ t[#t+1] = ".."
+ return t
+ else
+ return nil, code, msg
+ end
+end
--- Create a new directory, recursively on demand.
-- @param path String with the name or path of the directory to create
@@ -179,36 +164,7 @@ dir = posix.dir
-- @return String containing the error description on error
-- @return Number containing the os specific errno on error
function mkdir(path, recursive)
- if recursive then
- local base = "."
-
- if path:sub(1,1) == "/" then
- base = ""
- path = path:gsub("^/+","")
- end
-
- for elem in path:gmatch("([^/]+)/*") do
- base = base .. "/" .. elem
-
- local stat = posix.stat( base )
-
- if not stat then
- local stat, errmsg, errno = posix.mkdir( base )
-
- if type(stat) ~= "number" or stat ~= 0 then
- return stat, errmsg, errno
- end
- else
- if stat.type ~= "directory" then
- return nil, base .. ": File exists", 17
- end
- end
- end
-
- return 0
- else
- return posix.mkdir( path )
- end
+ return recursive and fs.mkdirr(path) or fs.mkdir(path)
end
--- Remove the given empty directory.
@@ -218,7 +174,7 @@ end
-- @return Number with the return code, 0 on sucess or nil on error
-- @return String containing the error description on error
-- @return Number containing the os specific errno on error
-rmdir = posix.rmdir
+rmdir = fs.rmdir
--- Get information about given file or directory.
-- @class function
@@ -227,7 +183,7 @@ rmdir = posix.rmdir
-- @return Table containing file or directory properties or nil on error
-- @return String containing the error description on error
-- @return Number containing the os specific errno on error
-stat = posix.stat
+stat = fs.stat
--- Set permissions on given file or directory.
-- @class function
@@ -237,7 +193,7 @@ stat = posix.stat
-- @return Number with the return code, 0 on sucess or nil on error
-- @return String containing the error description on error
-- @return Number containing the os specific errno on error
-chmod = posix.chmod
+chmod = fs.chmod
--- Create a hard- or symlink from given file (or directory) to specified target
-- file (or directory) path.
@@ -249,7 +205,9 @@ chmod = posix.chmod
-- @return Number with the return code, 0 on sucess or nil on error
-- @return String containing the error description on error
-- @return Number containing the os specific errno on error
-link = posix.link
+function link(src, dest, sym)
+ return sym and fs.symlink(src, dest) or fs.link(src, dest)
+end
--- Remove the given file.
-- @class function
@@ -258,7 +216,7 @@ link = posix.link
-- @return Number with the return code, 0 on sucess or nil on error
-- @return String containing the error description on error
-- @return Number containing the os specific errno on error
-unlink = posix.unlink
+unlink = fs.unlink
--- Retrieve target of given symlink.
-- @class function
@@ -267,4 +225,4 @@ unlink = posix.unlink
-- @return String containing the link target or nil on error
-- @return String containing the error description on error
-- @return Number containing the os specific errno on error
-readlink = posix.readlink
+readlink = fs.readlink
diff --git a/libs/httpclient/luasrc/httpclient/receiver.lua b/libs/httpclient/luasrc/httpclient/receiver.lua
index ad2ac8db7..cac96cd95 100644
--- a/libs/httpclient/luasrc/httpclient/receiver.lua
+++ b/libs/httpclient/luasrc/httpclient/receiver.lua
@@ -114,13 +114,12 @@ end
local function splice_sync(sock, pipeout, pipein, file, cb)
local os = require "os"
- local posix = require "posix"
local ssize = 65536
local smode = nixio.splice_flags("move", "more")
local stat
-- This is probably the only forking http-client ;-)
- local pid, code, msg = posix.fork()
+ local pid, code, msg = nixio.fork()
if not pid then
return pid, code, msg
elseif pid == 0 then
@@ -149,11 +148,11 @@ local function splice_sync(sock, pipeout, pipein, file, cb)
file:close()
if not stat then
- posix.kill(pid)
- posix.wait(pid)
+ nixio.kill(pid, 15)
+ nixio.wait(pid)
return stat, code, msg
else
- pid, msg, code = posix.wait(pid)
+ pid, msg, code = nixio.wait(pid)
if msg == "exited" then
if code == 0 then
return true
diff --git a/libs/sys/luasrc/sys.lua b/libs/sys/luasrc/sys.lua
index 9910ed37c..c9f0bcc88 100644
--- a/libs/sys/luasrc/sys.lua
+++ b/libs/sys/luasrc/sys.lua
@@ -27,7 +27,7 @@ limitations under the License.
local io = require "io"
local os = require "os"
-local posix = require "posix"
+local nixio = require "nixio"
local table = require "table"
local luci = {}
@@ -128,7 +128,7 @@ end
-- @param var Name of the environment variable to retrieve (optional)
-- @return String containg the value of the specified variable
-- @return Table containing all variables if no variable name is given
-getenv = posix.getenv
+getenv = nixio.getenv
--- Get or set the current hostname.
-- @param String containing a new hostname to set (optional)
@@ -138,7 +138,7 @@ function hostname(newname)
luci.fs.writefile( "/proc/sys/kernel/hostname", newname .. "\n" )
return newname
else
- return posix.uname("%n")
+ return nixio.uname().nodename
end
end
@@ -161,11 +161,9 @@ end
-- @return String containing the average load value 1 minute ago
-- @return String containing the average load value 5 minutes ago
-- @return String containing the average load value 15 minutes ago
--- @return String containing the active and total number of processes
--- @return String containing the last used pid
function loadavg()
- local loadavg = io.lines("/proc/loadavg")()
- return loadavg:match("^(.-) (.-) (.-) (.-) (.-)$")
+ local info = nixio.sysinfo()
+ return info.loads[1], info.loads[2], info.loads[3]
end
--- Initiate a system reboot.
@@ -193,7 +191,7 @@ function sysinfo()
local membuffers = tonumber(meminfo:match("Buffers:%s*(%d+)"))
if not system then
- system = posix.uname("%m")
+ system = nixio.uname().machine
model = cpuinfo:match("model name.-:%s*([^\n]+)")
if not model then
model = cpuinfo:match("Processor.-:%s*([^\n]+)")
@@ -243,18 +241,6 @@ function uptime()
return loadavg:match("^(.-) (.-)$")
end
---- LuCI system utilities / POSIX user group related functions.
--- @class module
--- @name luci.sys.group
-group = {}
-
---- Returns information about a POSIX user group.
--- @class function
--- @name getgroup
--- @param group Group ID or name of a system user group
--- @return Table with information about the requested group
-group.getgroup = posix.getgroup
-
--- LuCI system utilities / network related functions.
-- @class module
@@ -484,7 +470,10 @@ process = {}
-- @class function
-- @name process.info
-- @return Number containing the current pid
-process.info = posix.getpid
+function process.info(key)
+ local s = {uid = nixio.getuid(), gid = nixio.getgid()}
+ return not key and s or s[key]
+end
--- Retrieve information about currently running processes.
-- @return Table containing process information
@@ -527,23 +516,21 @@ function process.list()
end
--- Set the gid of a process identified by given pid.
--- @param pid Number containing the process id
-- @param gid Number containing the Unix group id
-- @return Boolean indicating successful operation
-- @return String containing the error message if failed
-- @return Number containing the error code if failed
-function process.setgroup(pid, gid)
- return posix.setpid("g", pid, gid)
+function process.setgroup(gid)
+ return nixio.setgid(gid)
end
--- Set the uid of a process identified by given pid.
--- @param pid Number containing the process id
-- @param uid Number containing the Unix user id
-- @return Boolean indicating successful operation
-- @return String containing the error message if failed
-- @return Number containing the error code if failed
-function process.setuser(pid, uid)
- return posix.setpid("u", pid, uid)
+function process.setuser(uid)
+ return nixio.setuid(uid)
end
--- Send a signal to a process identified by given pid.
@@ -553,7 +540,7 @@ end
-- @param sig Signal to send (default: 15 [SIGTERM])
-- @return Boolean indicating successful operation
-- @return Number containing the error code if failed
-process.signal = posix.kill
+process.signal = nixio.kill
--- LuCI system utilities / user related functions.
@@ -567,44 +554,20 @@ user = {}
-- @param uid Number containing the Unix user id
-- @return Table containing the following fields:
-- { "uid", "gid", "name", "passwd", "dir", "shell", "gecos" }
-user.getuser = posix.getpasswd
+user.getuser = nixio.getpw
--- Test whether given string matches the password of a given system user.
-- @param username String containing the Unix user name
--- @param password String containing the password to compare
+-- @param pass String containing the password to compare
-- @return Boolean indicating wheather the passwords are equal
-function user.checkpasswd(username, password)
- local account = user.getuser(username)
-
- if account then
- local pwd = account.passwd
- local shadowpw
- if #pwd == 1 then
- if luci.fs.stat("/etc/shadow") then
- if not pcall(function()
- for l in io.lines("/etc/shadow") do
- shadowpw = l:match("^%s:([^:]+)" % username)
- if shadowpw then
- pwd = shadowpw
- break
- end
- end
- end) then
- return nil, "Unable to access shadow-file"
- end
- end
-
- if pwd == "!" then
- return true
- end
- end
-
- if pwd and #pwd > 0 and password and #password > 0 then
- return (pwd == posix.crypt(password, pwd))
- end
+function user.checkpasswd(username, pass)
+ local pwe = nixio.getsp and nixio.getsp(username) or nixio.getpw(username)
+ local pwh = pwe and (pwe.pwdp or pwe.passwd)
+ if not pwh or #pwh < 1 or pwh ~= "!" and nixio.crypt(pass, pwh) ~= pwh then
+ return false
+ else
+ return true
end
-
- return false
end
--- Change the password of given user.
diff --git a/libs/uvl/luasrc/uvl/datatypes.lua b/libs/uvl/luasrc/uvl/datatypes.lua
index 615e2946d..1ad0891f2 100644
--- a/libs/uvl/luasrc/uvl/datatypes.lua
+++ b/libs/uvl/luasrc/uvl/datatypes.lua
@@ -144,9 +144,9 @@ function directory( val, seen )
if s and not seen[s.ino] then
seen[s.ino] = true
- if s.type == "directory" then
+ if s.type == "dir" then
return true
- elseif s.type == "link" then
+ elseif s.type == "lnk" then
return directory( fs.readlink(val), seen )
end
end
@@ -160,9 +160,9 @@ function file( val, seen )
if s and not seen[s.ino] then
seen[s.ino] = true
- if s.type == "regular" then
+ if s.type == "reg" then
return true
- elseif s.type == "link" then
+ elseif s.type == "lnk" then
return file( fs.readlink(val), seen )
end
end
@@ -176,9 +176,9 @@ function device( val, seen )
if s and not seen[s.ino] then
seen[s.ino] = true
- if s.type == "character device" or s.type == "block device" then
+ if s.type == "chr" or s.type == "blk" then
return true
- elseif s.type == "link" then
+ elseif s.type == "lnk" then
return device( fs.readlink(val), seen )
end
end
diff --git a/libs/web/luasrc/dispatcher.lua b/libs/web/luasrc/dispatcher.lua
index 71d2a5c74..b0f6c1e4d 100644
--- a/libs/web/luasrc/dispatcher.lua
+++ b/libs/web/luasrc/dispatcher.lua
@@ -30,6 +30,7 @@ local sys = require "luci.sys"
local init = require "luci.init"
local util = require "luci.util"
local http = require "luci.http"
+local nixio = require "nixio", require "nixio.util"
module("luci.dispatcher", package.seeall)
context = util.threadlocal()
@@ -210,7 +211,8 @@ function dispatch(request)
if (c and c.index) or not track.notemplate then
local tpl = require("luci.template")
local media = track.mediaurlbase or luci.config.main.mediaurlbase
- if not pcall(tpl.Template, "themes/%s/header" % fs.basename(media)) then
+ if not tpl.Template("themes/%s/header" % fs.basename(media)) then
+ --if not pcall(tpl.Template, "themes/%s/header" % fs.basename(media)) then
media = nil
for name, theme in pairs(luci.config.themes) do
if name:sub(1,1) ~= "." and pcall(tpl.Template,
@@ -411,7 +413,7 @@ function createindex_plain(path, suffixes)
if cachedate > realdate then
assert(
sys.process.info("uid") == fs.stat(indexcache, "uid")
- and fs.stat(indexcache, "mode") == "rw-------",
+ and fs.stat(indexcache, "modestr") == "rw-------",
"Fatal: Indexcache is not sane!"
)
@@ -438,8 +440,9 @@ function createindex_plain(path, suffixes)
end
if indexcache then
- fs.writefile(indexcache, util.get_bytecode(index))
- fs.chmod(indexcache, "a-rwx,u+rw")
+ local f = nixio.open(indexcache, "w", 600)
+ f:writeall(util.get_bytecode(index))
+ f:close()
end
end
diff --git a/libs/web/luasrc/sauth.lua b/libs/web/luasrc/sauth.lua
index 5d3dc95ca..e5cb17845 100644
--- a/libs/web/luasrc/sauth.lua
+++ b/libs/web/luasrc/sauth.lua
@@ -19,6 +19,8 @@ require("luci.fs")
require("luci.util")
require("luci.sys")
require("luci.config")
+local nixio = require "nixio", require "nixio.util"
+local fs = require "nixio.fs"
luci.config.sauth = luci.config.sauth or {}
@@ -37,7 +39,7 @@ function clean()
for i, file in pairs(files) do
local fname = sessionpath .. "/" .. file
local stat = luci.fs.stat(fname)
- if stat and stat.type == "regular" and stat.atime + sessiontime < now then
+ if stat and stat.type == "reg" and stat.mtime + sessiontime < now then
luci.fs.unlink(fname)
end
end
@@ -45,8 +47,7 @@ end
--- Prepare session storage by creating the session directory.
function prepare()
- luci.fs.mkdir(sessionpath)
- luci.fs.chmod(sessionpath, "a-rwx,u+rwx")
+ fs.mkdir(sessionpath, 700)
if not sane() then
error("Security Exception: Session path is not sane!")
@@ -67,6 +68,7 @@ function read(id)
if not sane(sessionpath .. "/" .. id) then
return
end
+ luci.fs.utime(sessionpath .. "/" .. id)
return luci.fs.readfile(sessionpath .. "/" .. id)
end
@@ -76,7 +78,7 @@ end
function sane(file)
return luci.sys.process.info("uid")
== luci.fs.stat(file or sessionpath, "uid")
- and luci.fs.stat(file or sessionpath, "mode")
+ and luci.fs.stat(file or sessionpath, "modestr")
== (file and "rw-------" or "rwx------")
end
@@ -91,8 +93,10 @@ function write(id, data)
if not id:match("^%w+$") then
error("Session ID is not sane!")
end
- luci.fs.writefile(sessionpath .. "/" .. id, data)
- luci.fs.chmod(sessionpath .. "/" .. id, "a-rwx,u+rw")
+
+ local f = nixio.open(sessionpath .. "/" .. id, "w", 600)
+ f:writeall(data)
+ f:close()
end
diff --git a/libs/web/luasrc/template.lua b/libs/web/luasrc/template.lua
index dc6e5bb7d..83efd2200 100644
--- a/libs/web/luasrc/template.lua
+++ b/libs/web/luasrc/template.lua
@@ -31,6 +31,7 @@ local table = require "table"
local string = require "string"
local config = require "luci.config"
local coroutine = require "coroutine"
+local nixio = require "nixio", require "nixio.util"
local tostring, pairs, loadstring = tostring, pairs, loadstring
local setmetatable, loadfile = setmetatable, loadfile
@@ -177,7 +178,7 @@ function Template.__init__(self, name)
if not fs.mtime(cdir) then
fs.mkdir(cdir, true)
- fs.chmod(fs.dirname(cdir), "a+rxw")
+ fs.chmod(fs.dirname(cdir), 777)
end
assert(tplmt or commt, "No such template: " .. name)
@@ -190,14 +191,15 @@ function Template.__init__(self, name)
if source then
local compiled, err = compile(source)
- fs.writefile(compiledfile, util.get_bytecode(compiled))
- fs.chmod(compiledfile, "a-rwx,u+rw")
+ local f = nixio.open(compiledfile, "w", 600)
+ f:writeall(util.get_bytecode(compiled))
+ f:close()
self.template = compiled
end
else
assert(
sys.process.info("uid") == fs.stat(compiledfile, "uid")
- and fs.stat(compiledfile, "mode") == "rw-------",
+ and fs.stat(compiledfile, "modestr") == "rw-------",
"Fatal: Cachefile is not sane!"
)
self.template, err = loadfile(compiledfile)