* Replaced luafilesystem with luaposix library
[project/luci.git] / src / ffluci / sys.lua
index 4ed2262..97a926b 100644 (file)
@@ -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