X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=ud-mailgate;h=26e4b75d30b1906f200227e6f6f422abac6bdba0;hb=187d3edfdc561cd4a929811d63f73114e15932e8;hp=36f1cc3d0e787383a1d58a78727cd6dbef558a95;hpb=eed30e7939bd5f051ff7af072b802925d663641d;p=mirror%2Fuserdir-ldap.git diff --git a/ud-mailgate b/ud-mailgate index 36f1cc3..26e4b75 100755 --- a/ud-mailgate +++ b/ud-mailgate @@ -7,11 +7,6 @@ import userdir_gpg, userdir_ldap, sys, traceback, time, ldap, os, commands import pwd, tempfile -import hmac -try: - import hashlib -except ImportError: - import sha as sha1_module from userdir_gpg import * from userdir_ldap import * @@ -98,14 +93,6 @@ DelItems = {"c": None, "VoIP": None, }; -def make_hmac(str): - F = open(PassDir+"/key-hmac","r"); - key = F.readline() - F.close(); - - return hmac.new(key, str, sha1_module).hexdigest - - # Decode a GPS location from some common forms def LocDecode(Str,Dir): @@ -485,15 +472,14 @@ def FinishConfirmSudopassword(l, uid, Attrs): res = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid="+uid, ['sudoPassword']); if len(res) != 1: raise Error, "Not exactly one hit when searching for user" - Attrs = res[0][1] - if Attrs.has_key('sudoPassword'): - inldap = Attrs['sudoPassword'] + if res[0][1].has_key('sudoPassword'): + inldap = res[0][1]['sudoPassword'] else: inldap = [] newldap = [] for entry in inldap: - Match = re.compile('^('+UUID_FORMAT+') (confirmed|unconfirmed) ([a-z0-9,*]+) ([^ ]+)$'),match(entry.lower()) + Match = re.compile('^('+UUID_FORMAT+') (confirmed:[0-9a-f]{40}|unconfirmed) ([a-z0-9.,*]+) ([^ ]+)$').match(entry.lower()) if Match == None: raise Error, "Could not parse existing sudopasswd entry" uuid = Match.group(1) @@ -504,22 +490,25 @@ def FinishConfirmSudopassword(l, uid, Attrs): if SudoPasswd.has_key(uuid): confirmedHosts = SudoPasswd[uuid][0] confirmedHmac = SudoPasswd[uuid][1] - if status == "confirmed": - result = result + "Entry %s for sudo password on hosts %s already confirmed.\n"%(uuid, hosts) + if status.startswith('confirmed:'): + if status == 'confirmed:'+make_sudopasswd_hmac('password-is-confirmed', uuid, hosts, cryptedpass): + result = result + "Entry %s for sudo password on hosts %s already confirmed.\n"%(uuid, hosts) + else: + result = result + "Entry %s for sudo password on hosts %s is listed as confirmed, but HMAC does not verify.\n"%(uuid, hosts) elif confirmedHosts != hosts: result = result + "Entry %s hostlist mismatch (%s vs. %s).\n"%(uuid, hosts, confirmedHosts) - elif make_hmac(':'.join([uuid, hosts, cryptedpass])) == confirmedHmac: + elif make_sudopasswd_hmac('confirm-new-password', uuid, hosts, cryptedpass) == confirmedHmac: result = result + "Entry %s for sudo password on hosts %s now confirmed.\n"%(uuid, hosts) - status = 'confirmed' + status = 'confirmed:'+make_sudopasswd_hmac('password-is-confirmed', uuid, hosts, cryptedpass) else: result = result + "Entry %s for sudo password on hosts %s HMAC verify failed.\n"%(uuid, hosts) del SudoPasswd[uuid] newentry = " ".join([uuid, status, hosts, cryptedpass]) if len(newldap) == 0: - newldap.append((ldap.MOD_ADD,"sudoPassword",newentry)) - else: newldap.append((ldap.MOD_REPLACE,"sudoPassword",newentry)) + else: + newldap.append((ldap.MOD_ADD,"sudoPassword",newentry)) for entry in SudoPasswd: result = result + "Entry %s that you confirm is not listed in ldap."%(entry)