X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=ud-mailgate;h=29a2873097c4743a2f29cf957de50cc7ba458dfa;hb=adad9e118b6dd523870eb3491e709b4dea204058;hp=fe9a6916afe55432c24cafe0e4233ec104a80118;hpb=41fc2a5c34f584714b2b768334d6ccc5839694f4;p=mirror%2Fuserdir-ldap.git diff --git a/ud-mailgate b/ud-mailgate index fe9a691..29a2873 100755 --- a/ud-mailgate +++ b/ud-mailgate @@ -7,7 +7,9 @@ import userdir_gpg, userdir_ldap, sys, traceback, time, ldap, os, commands import pwd, tempfile -import hmac, haslib +import hmac +import sha as sha1_module + from userdir_gpg import * from userdir_ldap import * @@ -95,10 +97,10 @@ DelItems = {"c": None, def make_hmac(str): F = open(PassDir+"/key-hmac","r"); - key = F.readline() + key = F.readline().strip() F.close(); - return hmac.new(key, str, hashlib.sha1).hexdigest + return hmac.new(key, str, sha1_module).hexdigest @@ -473,7 +475,7 @@ def DoConfirmSudopassword(Str): SudoPasswd[uuid] = (hosts, hmac) return "got confirm for sudo password %s on host(s) %s, auth code %s" % (uuid,hosts, hmac) -def FinishConfirmSudopassword(l, dn, Attrs): +def FinishConfirmSudopassword(l, uid, Attrs): global SudoPasswd result = "\n" @@ -486,7 +488,7 @@ def FinishConfirmSudopassword(l, dn, Attrs): else: inldap = [] - first_entry = 0 + newldap = [] for entry in inldap: Match = re.compile('^('+UUID_FORMAT+') (confirmed|unconfirmed) ([a-z0-9,*]+) ([^ ]+)$'),match(entry.lower()) if Match == None: @@ -511,15 +513,17 @@ def FinishConfirmSudopassword(l, dn, Attrs): del SudoPasswd[uuid] newentry = " ".join([uuid, status, hosts, cryptedpass]) - if first_entry: - Attrs.append((ldap.MOD_ADD,"sudoPassword",newentry)) + if len(newldap) == 0: + newldap.append((ldap.MOD_ADD,"sudoPassword",newentry)) else: - Attrs.append((ldap.MOD_REPLACE,"sudoPassword",newentry)) - first_entry = 1 + newldap.append((ldap.MOD_REPLACE,"sudoPassword",newentry)) for entry in SudoPasswd: result = result + "Entry %s that you confirm is not listed in ldap."%(entry) + for entry in newldap: + Attrs.append(entry) + return result # Handle an [almost] arbitary change @@ -573,9 +577,9 @@ def HandleChange(Reply,DnRecord,Key): try: Res = FinishConfirmSudopassword(l, GetAttr(DnRecord,"uid"), Attrs) Result = Result + Res + "\n"; - except: + except Error, e: CommitChanges = 0 - Result = Result + "ConfirmSudopassword raised an error - no changes committed\n"; + Result = Result + "FinishConfirmSudopassword raised an error (%s) - no changes committed\n"%(e); # Modify the record Dn = "uid=" + GetAttr(DnRecord,"uid") + "," + BaseDn; if CommitChanges == 1: