diff options
author | Steven Barth <steven@midlink.org> | 2008-03-29 18:22:21 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2008-03-29 18:22:21 +0000 |
commit | 1c6c6d62ca665f9d1126b6bad849f7fd584b6a80 (patch) | |
tree | d0f6d975a17d100a52d158a72904d3cbbf964ab4 /src/ffluci/sys.lua | |
parent | cdb0b2f0bfaa0e0bb40b1b90581e1376f55fb0df (diff) |
* Replaced luafilesystem with luaposix library
* Introduced privilege dropping capability
* Automatically drop privileges for "public" to "nobody/nogroup" (as defined in ffluci.uci)
Diffstat (limited to 'src/ffluci/sys.lua')
-rw-r--r-- | src/ffluci/sys.lua | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/ffluci/sys.lua b/src/ffluci/sys.lua index 4ed2262c8b..97a926b0b1 100644 --- a/src/ffluci/sys.lua +++ b/src/ffluci/sys.lua @@ -25,7 +25,7 @@ limitations under the License. ]]-- module("ffluci.sys", package.seeall) -require("ffluci.fs") +require("posix") -- Returns the hostname function hostname() @@ -38,11 +38,40 @@ function loadavg() return loadavg:match("^(.-) (.-) (.-) (.-) (.-)$") end + +group = {} +group.getgroup = posix.getgroup + +net = {} -- Returns all available network interfaces -function net_devices() +function net.devices() local devices = {} for line in io.lines("/proc/net/dev") do table.insert(devices, line:match(" *(.-):")) end return devices +end + +process = {} +process.info = posix.getpid + +-- Sets the gid of a process +function process.setgroup(pid, gid) + return posix.setpid("g", pid, gid) +end + +-- Sets the uid of a process +function process.setuser(pid, uid) + return posix.setpid("u", pid, uid) +end + +user = {} +-- returns user information to a given uid +user.getuser = posix.getpasswd + +-- Changes the user password of given user +function user.setpasswd(user, pwd1, pwd2) + local cmd = "(echo '"..pwd1.."';sleep 1;echo '"..pwd2.."')|" + cmd = cmd .. "passwd "..user.." 2>&1" + return ffluci.util.exec(cmd) end
\ No newline at end of file |