X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=libs%2Fsys%2Fluasrc%2Fsys.lua;h=ea55ed528c9cccf464a3296eac45c8222c62a63f;hb=2b81e10bc62e2ff5b7972bc53a036ac0e8d9097e;hp=b3155c8c8542c8fbda06b8acf4049c3d616ccf18;hpb=ccf1355343ec104146259119b0a61b0e9d856b8d;p=project%2Fluci.git diff --git a/libs/sys/luasrc/sys.lua b/libs/sys/luasrc/sys.lua index b3155c8c8..ea55ed528 100644 --- a/libs/sys/luasrc/sys.lua +++ b/libs/sys/luasrc/sys.lua @@ -437,11 +437,29 @@ function user.checkpasswd(username, password) local account = user.getuser(username) if account then - if account.passwd == "!" then - return true - else - return (account.passwd == posix.crypt(password, account.passwd)) + 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 + + return (pwd == posix.crypt(password, pwd)) end end @@ -512,6 +530,56 @@ function wifi.iwscan(iface) end +--- LuCI system utilities / init related functions. +-- @class module +-- @name luci.sys.init +init = {} +init.dir = "/etc/init.d/" + +--- Get the names of all installed init scripts +-- @return Table containing the names of all inistalled init scripts +function init.names() + local names = { } + for _, name in ipairs(luci.fs.glob(init.dir.."*")) do + names[#names+1] = luci.fs.basename(name) + end + return names +end + +--- Test whether the given init script is enabled +-- @return Boolean indicating whether init is enabled +function init.enabled(name) + if luci.fs.access(init.dir..name) then + return ( call(init.dir..name.." enabled") == 0 ) + end + return false +end + +--- Get the index of he given init script +-- @return Numeric index value +function init.index(name) + if luci.fs.access(init.dir..name) then + return call("source "..init.dir..name.." && exit $START") + end +end + +--- Enable the given init script +-- @return Boolean indicating success +function init.enable(name) + if luci.fs.access(init.dir..name) then + return ( call(init.dir..name.." enable") == 0 ) + end +end + +--- Disable the given init script +-- @return Boolean indicating success +function init.enable(name) + if luci.fs.access(init.dir..name) then + return ( call(init.dir..name.." disable") == 0 ) + end +end + + -- Internal functions function _parse_delimited_table(iter, delimiter)