ud-generate: deal with users without loginShell
[mirror/userdir-ldap.git] / ud-echelon
index 1bd90ca..b2b4f07 100755 (executable)
@@ -11,10 +11,10 @@ EX_PERMFAIL = 65;      # EX_DATAERR
 Debug = None;
 
 # Try to extract a key fingerprint from a PGP siged message
-def TryGPG(email):
+def TryGPG(mail):
    # Try to get a pgp text
    try:
-      Msg = GetClearSig(email, lax_multipart=True);
+      Msg = GetClearSig(mail, lax_multipart=True);
    except:
       # Log an exception.. but continue. This is to deal with 'sort of' 
       # PGP-MIME things
@@ -30,7 +30,7 @@ def TryGPG(email):
 
    # Failed to find a matching sig
    if not pgp.ok:
-      S = "%s: %s -> PGP Checking failed '%s': %s %s\n" %(Now,MsgID,email["From"],str(pgp.why),str(pgp.key_info));
+      S = "%s: %s -> PGP Checking failed '%s': %s %s\n" %(Now,MsgID,mail["From"],str(pgp.why),str(pgp.key_info));
       ErrLog.write(S);
       return None;
       
@@ -44,16 +44,16 @@ def TryGPG(email):
    return (Attrs[0][1]["uid"][0],"PGP",FormatPGPKey(pgp.key_fpr));
 
 # Try to guess the name from the email address
-def TryMatcher(email):
-   Sender = email["From"];
-   if Sender == None:
+def TryMatcher(mail):
+   Sender = mail["From"];
+   if Sender is None:
       return None;
       
    # Split up the address and invoke the matcher routine
    UID = GetUID(l,SplitEmail(Sender));
    
-   if UID[0] == None:
-      if UID[1] == None or len(UID[1]) == 0:
+   if UID[0] is None:
+      if UID[1] is None or len(UID[1]) == 0:
          return None;
 
       # Print out an error message
@@ -72,7 +72,7 @@ for (switch, val) in options:
       Debug = "";
    
 # Open the log files
-if Debug == None:
+if Debug is None:
    MainLog = open(Ech_MainLog,"a+",0);
    ErrLog = open(Ech_ErrorLog,"a+",0);
 else:
@@ -88,15 +88,15 @@ try:
    # Get the email 
    ErrType = EX_PERMFAIL;
    ErrMsg = "Failed to understand the email or find a signature:";
-   email = email.parser.Parser().parse(sys.stdin);
-   MsgID = email["Message-ID"]
+   mail = email.parser.Parser().parse(sys.stdin);
+   MsgID = mail["Message-ID"]
 
    # Connect to the ldap server
    ErrType = EX_TEMPFAIL;
    ErrMsg = "An error occured while performing the LDAP lookup";
    global l;
    l = connectLDAP()
-   if Debug == None:
+   if Debug is None:
       F = open(PassDir+"/pass-"+pwd.getpwuid(os.getuid())[0],"r");
       AccessPass = F.readline().strip().split(" ")
       l.simple_bind_s("uid="+AccessPass[0]+","+BaseDn,AccessPass[1]);
@@ -107,27 +107,27 @@ try:
    # Try to decode
    ErrType = EX_TEMPFAIL;
    ErrMsg = "An error occured while trying GPG decoding";
-   User = TryGPG(email);
-   if User == None:
+   User = TryGPG(mail);
+   if User is None:
       ErrMsg = "An error occured while trying Matcher decoding";
-      User = TryMatcher(email);
+      User = TryMatcher(mail);
 
    # Get any mailing list information   
-   List = email['X-Mailing-List']
+   List = mail['X-Mailing-List']
    if not List: List = "-";
 
    # Tada, write a log message
-   if User != None:
+   if User is not None:
       Msg = "[%s] \"%s\" \"%s\" \"%s\""%(Now,User[2],List,MsgID);
       MainLog.write("%s %s %s\n"%(User[0],User[1],Msg));
       Dn = "uid=" + User[0] + "," + BaseDn;
       Rec = [(ldap.MOD_REPLACE,"activity-%s"%(User[1]),Msg)];
-      if Debug == None:
+      if Debug is None:
          l.modify_s(Dn,Rec);
       else:
          print Rec;
    else:
-      User = ("-","UKN",email["From"]);
+      User = ("-","UKN",mail["From"]);
       Msg = "[%s] \"%s\" \"%s\" \"%s\""%(Now,User[2],List,MsgID);
       MainLog.write("%s %s %s\n"%(User[0],User[1],Msg));