diff options
-rw-r--r-- | contrib/bitlib/.gitignore | 1 | ||||
-rw-r--r-- | contrib/bitlib/Makefile | 36 | ||||
-rw-r--r-- | contrib/luadoc/lua/luadoc/doclet/html.lua | 2 | ||||
-rw-r--r-- | contrib/luadoc/lua/luadoc/taglet/standard.lua | 12 | ||||
-rw-r--r-- | contrib/luadoc/lua/luadoc/util.lua | 2 | ||||
-rw-r--r-- | contrib/luaposix/.gitignore | 3 | ||||
-rw-r--r-- | contrib/luaposix/Makefile | 35 | ||||
-rw-r--r-- | contrib/package/luci/Makefile | 4 | ||||
-rw-r--r-- | libs/cbi/luasrc/view/cbi/filebrowser.htm | 8 | ||||
-rw-r--r-- | libs/cbi/luasrc/view/cbi/upload.htm | 2 | ||||
-rw-r--r-- | libs/core/luasrc/ccache.lua | 15 | ||||
-rw-r--r-- | libs/core/luasrc/fs.lua | 128 | ||||
-rw-r--r-- | libs/httpclient/luasrc/httpclient/receiver.lua | 9 | ||||
-rw-r--r-- | libs/sys/luasrc/sys.lua | 85 | ||||
-rw-r--r-- | libs/uvl/luasrc/uvl/datatypes.lua | 12 | ||||
-rw-r--r-- | libs/web/luasrc/dispatcher.lua | 11 | ||||
-rw-r--r-- | libs/web/luasrc/sauth.lua | 16 | ||||
-rw-r--r-- | libs/web/luasrc/template.lua | 10 | ||||
-rwxr-xr-x | modules/freifunk/root/usr/sbin/ff_olsr_watchdog | 6 |
19 files changed, 126 insertions, 271 deletions
diff --git a/contrib/bitlib/.gitignore b/contrib/bitlib/.gitignore deleted file mode 100644 index 7211268c8..000000000 --- a/contrib/bitlib/.gitignore +++ /dev/null @@ -1 +0,0 @@ -bitlib-* diff --git a/contrib/bitlib/Makefile b/contrib/bitlib/Makefile deleted file mode 100644 index ea08c973b..000000000 --- a/contrib/bitlib/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -include ../../build/config.mk -include ../../build/gccconfig.mk - -BITLIB_VERSION = 25 -BITLIB_SITE = http://dev.luci.freifunk-halle.net/sources/ -BITLIB_DIR = bitlib-$(BITLIB_VERSION) -BITLIB_FILE = $(BITLIB_DIR).tar.gz -BITLIB_URL = $(BITLIB_SITE)/$(BITLIB_FILE) - -all: compile - -include ../../build/module.mk - -$(BITLIB_FILE): - wget -O $@ $(BITLIB_URL) || rm -f $@ - -$(BITLIB_DIR)/.prepared: $(BITLIB_FILE) - rm -rf $(BITLIB_DIR) - tar xvfz $(BITLIB_FILE) - test -f $(BITLIB_DIR)/config.h || cp $(BITLIB_DIR)/config.h.in $(BITLIB_DIR)/config.h - touch $@ - -compile: $(BITLIB_DIR)/.prepared dist$(LUA_LIBRARYDIR)/bit.so - -dist$(LUA_LIBRARYDIR)/bit.so: - mkdir -p dist$(LUA_LIBRARYDIR) - $(COMPILE) -DHAVE_CONFIG_H -I$(BITLIB_DIR) -O2 -c $(BITLIB_DIR)/lbitlib.c $(FPIC) $(LUA_CFLAGS) -o $(BITLIB_DIR)/lbitlib.o - $(LINK) $(SHLIB_FLAGS) $(LDFLAGS) $(BITLIB_DIR)/lbitlib.o $(LUA_SHLIBS) -lm -ldl -o dist$(LUA_LIBRARYDIR)/bit.so - -luasource: -luastrip: -luacompile: -compile-all: compile - -clean: - rm -rf $(BITLIB_DIR) $(BITLIB_FILE) diff --git a/contrib/luadoc/lua/luadoc/doclet/html.lua b/contrib/luadoc/lua/luadoc/doclet/html.lua index a94e1983f..e77fb7441 100644 --- a/contrib/luadoc/lua/luadoc/doclet/html.lua +++ b/contrib/luadoc/lua/luadoc/doclet/html.lua @@ -14,7 +14,7 @@ local assert, getfenv, ipairs, loadstring, pairs, setfenv, tostring, tonumber, type = assert, getfenv, ipairs, loadstring, pairs, setfenv, tostring, tonumber, type local io = require"io" -local posix = require "posix" +local posix = require "nixio.fs" local lp = require "luadoc.lp" local luadoc = require"luadoc" local package = package diff --git a/contrib/luadoc/lua/luadoc/taglet/standard.lua b/contrib/luadoc/lua/luadoc/taglet/standard.lua index f55ea7204..17a305889 100644 --- a/contrib/luadoc/lua/luadoc/taglet/standard.lua +++ b/contrib/luadoc/lua/luadoc/taglet/standard.lua @@ -4,7 +4,7 @@ local assert, pairs, tostring, type = assert, pairs, tostring, type local io = require "io" -local posix = require "posix" +local posix = require "nixio.fs" local luadoc = require "luadoc" local util = require "luadoc.util" local tags = require "luadoc.taglet.standard.tags" @@ -505,14 +505,14 @@ end -- @return table with documentation function directory (path, doc) - for f in posix.files(path) do + for f in posix.dir(path) do local fullpath = path .. "/" .. f local attr = posix.stat(fullpath) assert(attr, string.format("error stating file `%s'", fullpath)) - if attr.type == "regular" then + if attr.type == "reg" then doc = file(fullpath, doc) - elseif attr.type == "directory" and f ~= "." and f ~= ".." then + elseif attr.type == "dir" and f ~= "." and f ~= ".." then doc = directory(fullpath, doc) end end @@ -550,9 +550,9 @@ function start (files, doc) local attr = posix.stat(path) assert(attr, string.format("error stating path `%s'", path)) - if attr.type == "regular" then + if attr.type == "reg" then doc = file(path, doc) - elseif attr.type == "directory" then + elseif attr.type == "dir" then doc = directory(path, doc) end end) diff --git a/contrib/luadoc/lua/luadoc/util.lua b/contrib/luadoc/lua/luadoc/util.lua index 3a48e7418..acaaac828 100644 --- a/contrib/luadoc/lua/luadoc/util.lua +++ b/contrib/luadoc/lua/luadoc/util.lua @@ -3,7 +3,7 @@ -- @release $Id: util.lua,v 1.16 2008/02/17 06:42:51 jasonsantos Exp $ ------------------------------------------------------------------------------- -local posix = require "posix" +local posix = require "nixio.fs" local type, table, string, io, assert, tostring, setmetatable, pcall = type, table, string, io, assert, tostring, setmetatable, pcall ------------------------------------------------------------------------------- diff --git a/contrib/luaposix/.gitignore b/contrib/luaposix/.gitignore deleted file mode 100644 index 1407d2387..000000000 --- a/contrib/luaposix/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -luaposix-* -lua-posix_* -patches/series diff --git a/contrib/luaposix/Makefile b/contrib/luaposix/Makefile deleted file mode 100644 index 70d3c9c4c..000000000 --- a/contrib/luaposix/Makefile +++ /dev/null @@ -1,35 +0,0 @@ -include ../../build/config.mk -include ../../build/gccconfig.mk - -LUAPOSIX_VERSION = 5.1.4 -LUAPOSIX_SITE = http://dev.luci.freifunk-halle.net/sources/ -LUAPOSIX_DIR = luaposix-$(LUAPOSIX_VERSION) -LUAPOSIX_FILE = lua-posix_5.1.4.orig.tar.gz -LUAPOSIX_URL = $(LUAPOSIX_SITE)/$(LUAPOSIX_FILE) -LUAPOSIX_PATCHDIR = patches - -all: compile - -include ../../build/module.mk - -$(LUAPOSIX_FILE): - wget -O $@ $(LUAPOSIX_URL) || rm -f $@ - -$(LUAPOSIX_DIR)/.prepared: $(LUAPOSIX_FILE) - rm -rf $(LUAPOSIX_DIR) - tar xvfz $(LUAPOSIX_FILE) - touch $@ - -compile: $(LUAPOSIX_DIR)/.prepared - $(MAKE) -C $(LUAPOSIX_DIR) CC=$(CC) CFLAGS="$(CFLAGS) $(LUA_CFLAGS)" LDFLAGS="$(LDFLAGS) $(LUA_SHLIBS)" OS="$(OS)" - mkdir -p dist$(LUA_LIBRARYDIR) - cp $(LUAPOSIX_DIR)/posix.so dist$(LUA_LIBRARYDIR) - -luasource: -luastrip: -luacompile: -compile-all: compile - -clean: - rm -rf $(LUAPOSIX_DIR) $(LUAPOSIX_FILE) - rm -f $(LUAPOSIX_PATCHDIR)/series diff --git a/contrib/package/luci/Makefile b/contrib/package/luci/Makefile index 826fc193b..4680d6576 100644 --- a/contrib/package/luci/Makefile +++ b/contrib/package/luci/Makefile @@ -98,7 +98,7 @@ endef define Package/luci-core $(call Package/luci/libtemplate) - DEPENDS:=+lua + DEPENDS:=+lua +luci-nixio TITLE:=LuCI core libraries endef @@ -246,7 +246,7 @@ NIXIO_TLS:=axtls define Package/luci-nixio $(call Package/luci/libtemplate) - TITLE:=NIXIO Socket Library + TITLE:=NIXIO POSIX Library DEPENDS:= endef 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) diff --git a/modules/freifunk/root/usr/sbin/ff_olsr_watchdog b/modules/freifunk/root/usr/sbin/ff_olsr_watchdog index 3e5258d9b..aa8de6162 100755 --- a/modules/freifunk/root/usr/sbin/ff_olsr_watchdog +++ b/modules/freifunk/root/usr/sbin/ff_olsr_watchdog @@ -3,9 +3,9 @@ require "os" require "io" require "uci" -require "posix" +local fs = require "nixio.fs" -if posix.access("/var/run/olsrd.pid") then +if fs.access("/var/run/olsrd.pid") then local stamp, intv local x = uci.cursor() @@ -17,7 +17,7 @@ if posix.access("/var/run/olsrd.pid") then end end) - if intv and posix.access(stamp) then + if intv and fs.access(stamp) then local systime = os.time() local wdgtime = tonumber(io.lines(stamp)()) |