X-Git-Url: http://www.dolda2000.com/gitweb/?p=ashd.git;a=blobdiff_plain;f=etc%2Fextauth%2Fmkhtpasswd;fp=etc%2Fextauth%2Fmkhtpasswd;h=923ab070c7cb32a7a85ab1709d28c1a9a7738d8b;hp=0000000000000000000000000000000000000000;hb=bcad6b0c48d516ddc920b52f06083ceaa242e1ca;hpb=589987f8218c9aa61d65f582a3b3e1bbd32bda81 diff --git a/etc/extauth/mkhtpasswd b/etc/extauth/mkhtpasswd new file mode 100755 index 0000000..923ab07 --- /dev/null +++ b/etc/extauth/mkhtpasswd @@ -0,0 +1,37 @@ +#!/usr/bin/python + +import sys, os, termios, hmac, hashlib, getopt, getpass + +def usage(out): + out.write("usage: mkhtpasswd [-h] FILE USERNAME\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) < 2: + usage(sys.stderr) + sys.exit(1) + +def hashpw(usr, pw): + dig = hmac.new(pw, digestmod=hashlib.sha1) + dig.update(usr) + return dig.hexdigest() + +if ':' in args[1]: + sys.stderr.write("mkhtpasswd: username cannot contain `:'\n") + sys.exit(1) + +passwds = {} +if os.path.exists(args[0]): + with open(args[0]) as fp: + for line in fp: + usr, pw = line.strip().split(':') + passwds[usr] = pw + +passwds[args[1]] = hashpw(args[1], getpass.getpass()) + +with open(args[0], "w") as fp: + for usr, pw in passwds.iteritems(): + fp.write("%s:%s\n" % (usr, pw))