X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=libs%2Fsys%2Fluasrc%2Fsys.lua;h=4bf294678825a5ab5aa0554b2af945fe1ffd5124;hp=e27e1c4e8ae6a0a1f180d695682fd86e1bc0d9bf;hb=a63363130730a543c1a7291f18068f027b83c9ed;hpb=2bbc4eb3c33c3590433174c599ec9418bdb8f38a diff --git a/libs/sys/luasrc/sys.lua b/libs/sys/luasrc/sys.lua index e27e1c4e8..4bf294678 100644 --- a/libs/sys/luasrc/sys.lua +++ b/libs/sys/luasrc/sys.lua @@ -77,27 +77,44 @@ function mounts() local data = {} local k = {"fs", "blocks", "used", "available", "percent", "mountpoint"} local ps = luci.util.execi("df") - + if not ps then return else ps() end - + for line in ps do local row = {} - + local j = 1 for value in line:gmatch("[^%s]+") do row[k[j]] = value j = j + 1 end - + if row[k[1]] then + + -- this is a rather ugly workaround to cope with wrapped lines in + -- the df output: + -- + -- /dev/scsi/host0/bus0/target0/lun0/part3 + -- 114382024 93566472 15005244 86% /mnt/usb + -- + + if not row[k[2]] then + j = 2 + line = ps() + for value in line:gmatch("[^%s]+") do + row[k[j]] = value + j = j + 1 + end + end + table.insert(data, row) end end - + return data end @@ -335,37 +352,37 @@ function process.list() local data = {} local k local ps = luci.util.execi("top -bn1") - + if not ps then return end - + while true do local line = ps() if not line then return end - + k = luci.util.split(luci.util.trim(line), "%s+", nil, true) if k[1] == "PID" then break end end - + for line in ps do local row = {} - + line = luci.util.trim(line) for i, value in ipairs(luci.util.split(line, "%s+", #k-1, true)) do row[k[i]] = value end - + local pid = tonumber(row[k[1]]) if pid then data[pid] = row end end - + return data end @@ -420,11 +437,23 @@ function user.checkpasswd(username, password) local account = user.getuser(username) if account then - if account.passwd == "!" then + local pwd = account.passwd + if pwd == "!" then return true - else - return (account.passwd == posix.crypt(password, account.passwd)) + elseif pwd == "x" then + pwd = nil + for l in io.lines("/etc/shadow") do + pwd = l:match("^%s:([^:]+)" % username) + if pwd then + break + end + end + if not pwd then + return nil, "No shadow password for " .. username + end end + + return (pwd == posix.crypt(password, pwd)) end end