summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorNathan Angelacos <nangel@tetrasec.net>2007-12-04 16:03:51 +0000
committerNathan Angelacos <nangel@tetrasec.net>2007-12-04 16:03:51 +0000
commit4beb4e80541545a6ada7dc5e217658cccee30b48 (patch)
tree929d7855a8c2c721e5cf2087424bf8d48be326a9 /lib
parent19b53b147471298d093a81a0fdb102584dc28ae9 (diff)
downloadacf-core-4beb4e80541545a6ada7dc5e217658cccee30b48.tar.bz2
acf-core-4beb4e80541545a6ada7dc5e217658cccee30b48.tar.xz
plaintext authenticator library
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@404 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile3
-rw-r--r--lib/authenticator-plaintext.lua81
2 files changed, 83 insertions, 1 deletions
diff --git a/lib/Makefile b/lib/Makefile
index 3089928..3311d68 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -11,7 +11,8 @@ LIB_DIST=fs.lua\
session.lua\
split.lua\
validator.lua\
- web_elements.lua
+ web_elements.lua\
+ authenticator-plaintext.lua
EXTRA_DIST=README Makefile
DISTFILES=$(LIB_DIST) $(EXTRA_DIST)
diff --git a/lib/authenticator-plaintext.lua b/lib/authenticator-plaintext.lua
new file mode 100644
index 0000000..62af3bd
--- /dev/null
+++ b/lib/authenticator-plaintext.lua
@@ -0,0 +1,81 @@
+--[[ ACF Logon/Logoff authenticator that uses plaintext files
+ Copyright (c) 2007 Nathan Angelacos
+ GPL2 license
+
+
+The password file is in the format:
+
+userid:password:username:role1[,role2...]
+
+]]--
+
+module (..., package.seeall)
+
+local sess = require ("session")
+
+local pvt={}
+
+
+pvt.read_authfile = function(id)
+ id = id or ""
+
+ -- open our password file
+ local f = io.open (self.conf.confdir .. "/passwd" )
+ if f then
+ local m = f:read("*all") .. "\n"
+ f:close()
+
+ for l in string.gmatch(m, "(%C*)\n") do
+ local userid, password, username, roles =
+ string.match(l, "([^:]*):([^:]*):([^:]*):(.*)")
+ if userid == id then
+ local r = {}
+ for x in string.gmatch(roles, "([^,]*),?") do
+ table.insert (r, x )
+ end
+
+ local a = {}
+ a.userid = userid
+ a.password = password
+ a.username = username
+ a.roles = r
+ return (a)
+ end
+ end
+ else
+ return false
+ end
+end
+
+
+--- public methods
+
+-- This function returns true or false, and
+-- if false: the reason for failure
+authenticate = function ( userid, password )
+ password = password or ""
+
+ local t = pvt.read_authfile(userid)
+
+ if t == false then
+ return false, "Userid not found"
+ elseif t.password ~= password then
+ return false, "Invalid password"
+ else
+ return true
+ end
+end
+
+
+
+-- This function returns the username and roles
+-- or false on an error
+userinfo = function ( userid )
+ local t = pvt.read_authfile(userid)
+ if t == false then
+ return false
+ else
+ return t
+ end
+end
+