X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=ud-mailgate;h=6f9b20cfc5fb2bb7e8b1f810b0cbeda88f295653;hb=04be4a35cec33fc9a9be35c0aabbbbb4ab833e86;hp=2aae92b55347a03ff977afd9516a7c7a2c69eca1;hpb=b13771828d0938c805b3824bd2c7162933946ad3;p=mirror%2Fuserdir-ldap.git diff --git a/ud-mailgate b/ud-mailgate index 2aae92b..6f9b20c 100755 --- a/ud-mailgate +++ b/ud-mailgate @@ -36,7 +36,6 @@ mailRHSBL = {} mailWhitelist = {} SeenList = {} DNS = {} -SudoPasswd = {} ValidHostNames = [] # will be initialized in later SSHFingerprint = re.compile('^(\d+) ([0-9a-f\:]{47}) (.+)$') @@ -490,8 +489,8 @@ def DoRBL(Str,Attrs): return "%s replaced with %s" % (Key,Host) # Handle a ConfirmSudoPassword request -def DoConfirmSudopassword(Str): - Match = re.compile('^confirm sudopassword ('+UUID_FORMAT+') ([a-z0-9.,*]+) ([0-9a-f]{40})$').match(Str) +def DoConfirmSudopassword(Str, SudoPasswd): + Match = re.compile('^confirm sudopassword ('+UUID_FORMAT+') ([a-z0-9.,*-]+) ([0-9a-f]{40})$').match(Str) if Match == None: return None @@ -499,12 +498,10 @@ def DoConfirmSudopassword(Str): hosts = Match.group(2) hmac = Match.group(3) - global SudoPasswd SudoPasswd[uuid] = (hosts, hmac) return "got confirm for sudo password %s on host(s) %s, auth code %s" % (uuid,hosts, hmac) -def FinishConfirmSudopassword(l, uid, Attrs): - global SudoPasswd +def FinishConfirmSudopassword(l, uid, Attrs, SudoPasswd): result = "\n" if len(SudoPasswd) == 0: @@ -520,7 +517,7 @@ def FinishConfirmSudopassword(l, uid, Attrs): newldap = [] for entry in inldap: - Match = re.compile('^('+UUID_FORMAT+') (confirmed:[0-9a-f]{40}|unconfirmed) ([a-z0-9.,*]+) ([^ ]+)$').match(entry) + Match = re.compile('^('+UUID_FORMAT+') (confirmed:[0-9a-f]{40}|unconfirmed) ([a-z0-9.,*-]+) ([^ ]+)$').match(entry) if Match == None: raise UDFormatError, "Could not parse existing sudopasswd entry" uuid = Match.group(1) @@ -582,6 +579,7 @@ def HandleChange(Reply,DnRecord,Key): Result = ""; Attrs = []; + SudoPasswd = {} Show = 0; CommitChanges = 1 for Line in Lines: @@ -599,7 +597,7 @@ def HandleChange(Reply,DnRecord,Key): badkeys = LoadBadSSH() Res = DoPosition(Line,Attrs) or DoDNS(Line,Attrs,DnRecord) or \ DoArbChange(Line,Attrs) or DoSSH(Line,Attrs,badkeys,GetAttr(DnRecord,"uid")) or \ - DoDel(Line,Attrs) or DoRBL(Line,Attrs) or DoConfirmSudopassword(Line) + DoDel(Line,Attrs) or DoRBL(Line,Attrs) or DoConfirmSudopassword(Line, SudoPasswd) except: Res = None; Result = Result + "==> %s: %s\n" %(sys.exc_type,sys.exc_value); @@ -617,7 +615,7 @@ def HandleChange(Reply,DnRecord,Key): if CommitChanges == 1 and len(SudoPasswd) > 0: # only if we are still good to go try: - Res = FinishConfirmSudopassword(l, GetAttr(DnRecord,"uid"), Attrs) + Res = FinishConfirmSudopassword(l, GetAttr(DnRecord,"uid"), Attrs, SudoPasswd) if not Res is None: Result = Result + Res + "\n"; except Error, e: