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 b3155c8c8542c8fbda06b8acf4049c3d616ccf18..4bf294678825a5ab5aa0554b2af945fe1ffd5124 100644 (file)
@@ -437,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