summaryrefslogtreecommitdiffstats
path: root/testauth.lua
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2012-12-13 21:28:59 +0100
committerNatanael Copa <ncopa@alpinelinux.org>2012-12-13 21:28:59 +0100
commitc7fcfd5a2dfff5bf99ed00515173d2f8917f9c57 (patch)
treeb91bb9f0c562fadc1a23c8da6d1bc7daa7350609 /testauth.lua
parent9b0cffd1c46ebc77430d19fa173a848450512f6a (diff)
downloadprivsep-c7fcfd5a2dfff5bf99ed00515173d2f8917f9c57.tar.bz2
privsep-c7fcfd5a2dfff5bf99ed00515173d2f8917f9c57.tar.xz
auth: add inital authentication modules and a test
Diffstat (limited to 'testauth.lua')
-rw-r--r--testauth.lua52
1 files changed, 52 insertions, 0 deletions
diff --git a/testauth.lua b/testauth.lua
new file mode 100644
index 0000000..67d703a
--- /dev/null
+++ b/testauth.lua
@@ -0,0 +1,52 @@
+#!/usr/bin/lua
+
+--[[
+
+test authenticate
+
+* If user exist in acf db and passwd field is not 'x' then use this password.
+
+* If user exist in acf db and passwd field is 'x' then use password hash in
+ /etc/shadow.
+
+* If user does not exit in acf db, then authenticate against /etc/shadow
+ If success then create new user with no roles in acf db.
+
+]]--
+
+shadow = require("auth.shadow")
+acfdb = require("auth.acfpasswd")
+
+user = arg[1]
+entry, errmsg = acfdb.getent(user)
+
+authenticate = acfdb.authenticate
+if entry == nil then
+ print("Failed to read user '"..user.."' in "..acfdb.file)
+ if not shadow.getent(user) then
+ print("Faild to read user in "..shadow.file)
+ -- We could fallback to ldap, imaps or similar here
+ return 1
+ end
+ authenticate = shadow.authenticate
+elseif entry.passwd == "x" then
+ -- if passwd field is set to 'x' it means we use password in shadow
+ authenticate = shadow.authenticate
+end
+
+io.write("Enter password (WARNING: will echo): ")
+passwd = io.read("*line")
+
+if not authenticate(user, passwd) then
+ print("Authentication failed")
+ return 1
+end
+
+print("User "..user.." is authenticated")
+if entry == nil then
+ print("A new account should be created here")
+ -- passwd = confirm_password(passwd)
+ -- acfdb.setent(user, passwd, "New User", "NEWUSER")
+end
+
+