From: thierry Date: Wed, 5 Sep 2007 12:42:10 +0000 (+0000) Subject: update - does not create .private alias anymore X-Git-Tag: foo~427 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=ae8d201d64415cdeeb55474cf4a45a2110ffcdd6;p=infrastructure.git update - does not create .private alias anymore --- diff --git a/scripts/matching_passwds.py b/scripts/matching_passwds.py new file mode 100755 index 0000000..066a150 --- /dev/null +++ b/scripts/matching_passwds.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python + +#################### +__doc__="""\ +This script expects a mandatory plain passwd, +and an optional MD5-encoded passwd + +If both are provided, we check that they match +Otherwise we return an encrypted passwd +""" + +__author__="Thierry Parmentelat, INRIA Sophia Antipolis" + +#################### +import getopt +import sys +import re + +from crypt import crypt +import random +import string + +#################### md5 passwds syntax +magic='$1$' +re_magic='\$1\$' # $ needs \ in regular expression + +#################### +def usage(): + print "Usage: %s plain [encrypted]"%sys.argv[0] + print __doc__ + +#################### +#################### +def getsalt(chars = string.letters + string.digits): + # generate a random 8-character 'salt' + return (random.choice(chars) + + random.choice(chars) + + random.choice(chars) + + random.choice(chars) + + random.choice(chars) + + random.choice(chars) + + random.choice(chars) + + random.choice(chars)) + +########## +# returns a string +def compute_encrypted (plain): + return crypt(plain,magic+getsalt()+'$') + +#################### +#################### +# returns a boolean +def check_encrypted (plain,passwd): + + no_dollar="[^\$]+" + re_passwd=(re_magic + +"(%s)"%no_dollar + +'\$' + + "(%s)"%no_dollar) +# print "in="+passwd +# print "re="+re_passwd + m_passwd=re.compile(re_passwd) + r=m_passwd.match(passwd) + + if not r: + print 'passwd wrong syntax %s'%passwd + ok= False + else: + salt=r.group(1) + checked=crypt(plain,magic+salt+'$') + ok = (checked==passwd) + return ok + +#################### +def main (): + + (opts, argv) = getopt.getopt(sys.argv[1:], "h") + for (opt, optval) in opts: + if opt == '-h': + usage() + return 1 + + args=len(argv) + if args==1: + [plain]=argv + try: + encrypted=compute_encrypted(plain) + print encrypted + return 0 + except: + return 1 + elif args==2: + [plain,passwd]=argv + try: + ok = check_encrypted (plain,passwd) + if ok: + return 0 + else: + return 1 + except: + return 1 + else: + usage() + return 1 + print "END should not occur" + +#################### +if __name__ == '__main__': + sys.exit(main()) + + + diff --git a/scripts/onelab-aliases.sh b/scripts/onelab-aliases.sh index 2022138..f57bb3c 100755 --- a/scripts/onelab-aliases.sh +++ b/scripts/onelab-aliases.sh @@ -5,9 +5,8 @@ # to be run on the mail server at one-lab.org, to add aliases in that domain # Example: # new-alias.sh francois2.jan@orange-ftgroup.com -# -> creates two aliases -# francois2.jan@one-lab.org -# francois2.jan.private@one-lab.org +# -> creates one alias +# francois2.jan@one-lab.org -> francois2.jan@orange-ftgroup.com COMMAND=$(basename $0) @@ -28,12 +27,10 @@ function create () { echo "WARNING: $target skipped" continue fi - for suffix in "" ".private" ; do - aliasname=${namepart}${suffix}@one-lab.org - sqlcommand="insert into alias values ( '${aliasname}', '${target}' )" - echo "Sending $sqlcommand" - echo "$sqlcommand" | $SQL - done + aliasname=${namepart}@one-lab.org + sqlcommand="insert into alias values ( '${aliasname}', '${target}' )" + echo "Sending $sqlcommand" + echo "$sqlcommand" | $SQL }