Fix a bug preventing login in non-shadow environments
authorSteven Barth <steven@midlink.org>
Wed, 1 Oct 2008 15:43:12 +0000 (15:43 +0000)
committerSteven Barth <steven@midlink.org>
Wed, 1 Oct 2008 15:43:12 +0000 (15:43 +0000)
libs/sys/luasrc/sys.lua

index 0bf92e9da4a20d734ae95cedf4911a466bcb510f..0c18a3636ae545e976e9d839e47b3953bd3d433e 100644 (file)
@@ -440,11 +440,17 @@ function user.checkpasswd(username, password)
                local pwd = account.passwd
                local shadowpw
                if #pwd == 1 then
-                       for l in io.lines("/etc/shadow") do
-                               shadowpw = l:match("^%s:([^:]+)" % username)
-                               if shadowpw then
-                                       pwd = shadowpw
-                                       break
+                       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