X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=ud-echelon;h=5e98afc8216529adc96f8caeca3af0e8c6e609d2;hb=2525bf73603cb6487cfcea096e2dc347ad360394;hp=2be0112c6ae55b67030d76b6c4447ed7b36bac2d;hpb=a86d975ac15e074f142c75ba5c74596be92e740d;p=mirror%2Fuserdir-ldap.git diff --git a/ud-echelon b/ud-echelon index 2be0112..5e98afc 100755 --- a/ud-echelon +++ b/ud-echelon @@ -1,26 +1,36 @@ #!/usr/bin/env python # -*- mode: python -*- -import userdir_gpg, userdir_ldap, sys, traceback, time, ldap, posix; +import userdir_gpg, userdir_ldap, sys, traceback, time, ldap, os, getopt; import string, pwd from userdir_gpg import *; from userdir_ldap import *; EX_TEMPFAIL = 75; EX_PERMFAIL = 65; # EX_DATAERR -Debug = ""; +Debug = None; # Try to extract a key fingerprint from a PGP siged message def TryGPG(Email): # Try to get a pgp text - Msg = GetClearSig(Email); + try: + Msg = GetClearSig(Email); + except: + # Log an exception.. but continue. This is to deal with 'sort of' + # PGP-MIME things + S = "%s: %s -> %s\n" %(Now,MsgID,ErrMsg); + S = S + " %s: %s\n" %(sys.exc_type,sys.exc_value); + ErrLog.write(S); + return None; + if string.find(Msg[0],"-----BEGIN PGP SIGNED MESSAGE-----") == -1: return None; - - print Msg[0]; + Res = GPGCheckSig(Msg[0]); # Failed to find a matching sig if Res[0] != None: + S = "%s: %s -> PGP Checking failed '%s': %s %s\n" %(Now,MsgID,Email.getheader("From"),str(Res[0]),str(Res[2])); + ErrLog.write(S); return None; # Search for the matching key fingerprint @@ -53,6 +63,12 @@ def TryMatcher(Email): return None; return (UID[0],"FROM",Sender); + +# Process options +(options, arguments) = getopt.getopt(sys.argv[1:], "dr") +for (switch, val) in options: + if (switch == '-d'): + Debug = ""; # Open the log files if Debug == None: @@ -80,7 +96,7 @@ try: global l; l = ldap.open(LDAPServer); if Debug == None: - F = open(PassDir+"/pass-"+pwd.getpwuid(posix.getuid())[0],"r"); + F = open(PassDir+"/pass-"+pwd.getpwuid(os.getuid())[0],"r"); AccessPass = string.split(string.strip(F.readline())," "); l.simple_bind_s("uid="+AccessPass[0]+","+BaseDn,AccessPass[1]); F.close();