X-Git-Url: http://www.dolda2000.com/gitweb/?p=ashd.git;a=blobdiff_plain;f=etc%2Fextauth%2Fvhtpasswd;fp=etc%2Fextauth%2Fvhtpasswd;h=422206d347cf5005745ce6e68dbf79d9039ab34d;hp=0000000000000000000000000000000000000000;hb=bcad6b0c48d516ddc920b52f06083ceaa242e1ca;hpb=589987f8218c9aa61d65f582a3b3e1bbd32bda81 diff --git a/etc/extauth/vhtpasswd b/etc/extauth/vhtpasswd new file mode 100755 index 0000000..422206d --- /dev/null +++ b/etc/extauth/vhtpasswd @@ -0,0 +1,34 @@ +#!/usr/bin/python + +import sys, hmac, hashlib, getopt + +def usage(out): + out.write("usage: vhtpasswd [-h] FILE\n") + +opts, args = getopt.getopt(sys.argv[1:], "h") +for o, a in opts: + if o == "-h": + usage(sys.stdout) + sys.exit(0) +if len(args) < 1: + usage(sys.stderr) + sys.exit(1) + +def hashpw(usr, pw): + dig = hmac.new(pw, digestmod=hashlib.sha1) + dig.update(usr) + return dig.hexdigest() + +def findpw(fn, name): + with open(fn) as fp: + for line in fp: + usr, pw = line.strip().split(':') + if usr == name: + return pw + return None + +usr = sys.stdin.readline().strip() +gpw = sys.stdin.readline().strip() +if findpw(args[0], usr) == hashpw(usr, gpw): + sys.exit(0) +sys.exit(1)