Added support for shadow passwords
authorSteven Barth <steven@midlink.org>
Mon, 29 Sep 2008 16:02:54 +0000 (16:02 +0000)
committerSteven Barth <steven@midlink.org>
Mon, 29 Sep 2008 16:02:54 +0000 (16:02 +0000)
libs/sys/luasrc/sys.lua

index b3155c8..4bf2946 100644 (file)
@@ -437,11 +437,23 @@ function user.checkpasswd(username, password)
        local account = user.getuser(username)
 
        if account then
        local account = user.getuser(username)
 
        if account then
-               if account.passwd == "!" then
+               local pwd = account.passwd
+               if pwd == "!" then
                        return true
                        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
                end
+
+               return (pwd == posix.crypt(password, pwd))
        end
 end
 
        end
 end