summaryrefslogtreecommitdiffhomepage
path: root/libs/sys/luasrc/sys.lua
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2010-10-11 23:22:25 +0000
committerJo-Philipp Wich <jow@openwrt.org>2010-10-11 23:22:25 +0000
commit051186345c250be79861e2e58419d35f873996a4 (patch)
tree30c2540f51ad478f0b8e9fd31fd1095ff5d92805 /libs/sys/luasrc/sys.lua
parentf372cbda9a3f40d889b0f4a9da399dfdf1435518 (diff)
libs/sys: implement luci.sys.user.getpasswd()
Diffstat (limited to 'libs/sys/luasrc/sys.lua')
-rw-r--r--libs/sys/luasrc/sys.lua18
1 files changed, 15 insertions, 3 deletions
diff --git a/libs/sys/luasrc/sys.lua b/libs/sys/luasrc/sys.lua
index 6985d78fc..4e147c502 100644
--- a/libs/sys/luasrc/sys.lua
+++ b/libs/sys/luasrc/sys.lua
@@ -584,14 +584,26 @@ user = {}
-- { "uid", "gid", "name", "passwd", "dir", "shell", "gecos" }
user.getuser = nixio.getpw
+--- Retrieve the current user password hash.
+-- @param username String containing the username to retrieve the password for
+-- @return String containing the hash or nil if no password is set.
+function user.getpasswd(username)
+ 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 == "!" or pwh == "x" then
+ return nil
+ else
+ return pwh
+ end
+end
+
--- Test whether given string matches the password of a given system user.
-- @param username String containing the Unix user name
-- @param pass String containing the password to compare
-- @return Boolean indicating wheather the passwords are equal
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
+ local pwh = user.getpasswd(username)
+ if not pwh or nixio.crypt(pass, pwh) ~= pwh then
return false
else
return true