Stop using string exceptions. They were removed in python 2.6.
authorJulien Cristau <jcristau@debian.org>
Fri, 11 Oct 2019 14:13:36 +0000 (16:13 +0200)
committerJulien Cristau <jcristau@debian.org>
Fri, 11 Oct 2019 14:13:36 +0000 (16:13 +0200)
debian/changelog
misc/ud-update-sudopasswords
sigcheck
ud-gpgimport
ud-useradd
userdir_gpg.py
userdir_ldap.py

index 8378dd1..1ccff46 100644 (file)
@@ -19,6 +19,7 @@ userdir-ldap (0.3.97) UNRELEASED; urgency=medium
   * ud-mailgate: use subprocess.Popen instead of os.popen.
   * Use "foo is None" instead of "foo == None".
   * Use "foo is not None" instead of "foo != None".
+  * Stop using string exceptions.  They were removed in python 2.6.
 
  -- Peter Palfrader <weasel@debian.org>  Sat, 06 Apr 2019 22:04:34 +0200
 
index c5585b8..441acb8 100755 (executable)
@@ -34,7 +34,7 @@ l.simple_bind_s("uid="+Pass[0]+","+BaseDn,Pass[1])
 
 PasswdAttrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"sudoPassword=*", ["uid","sudoPassword"])
 if PasswdAttrs == None:
-  raise "No Users"
+  raise Exception("No Users")
 
 for x in PasswdAttrs:
    if not x[1].has_key('sudoPassword'):
index 9c59bd2..2561f1c 100755 (executable)
--- a/sigcheck
+++ b/sigcheck
@@ -31,7 +31,6 @@ from userdir_gpg import *;
 
 EX_TEMPFAIL = 75;
 EX_PERMFAIL = 65;      # EX_DATAERR
-Error = 'Message Error';
 
 # Configuration
 ReplayCacheFile = None;
@@ -42,6 +41,9 @@ Phrases = None;
 AllowMIME = 1;
 Verbose = 0;
 
+class MessageError(Exception):
+   pass
+
 def verbmsg(msg):
    if Verbose:
       sys.stderr.write(msg + "\n")
@@ -63,9 +65,9 @@ def CheckLDAP(FingerPrint):
    verbmsg("Processing fingerprint %s" % FingerPrint)
    Attrs = l.search_s(LDAPDn,ldap.SCOPE_ONELEVEL,"keyfingerprint=" + FingerPrint);
    if len(Attrs) == 0:
-      raise Error, "Key not found"
+      raise MessageError("Key not found")
    if len(Attrs) != 1:
-      raise Error, "Oddly your key fingerprint is assigned to more than one account.."
+      raise MessageError("Oddly your key fingerprint is assigned to more than one account..")
 
    gidnumber_found = 0;
    for key in Attrs[0][1].keys():
@@ -73,12 +75,12 @@ def CheckLDAP(FingerPrint):
          gidnumber_found = 1
 
    if (gidnumber_found != 1):
-      raise Error, "No gidnumber in attributes for fingerprint %s" % FingerPrint
+      raise MessageError("No gidnumber in attributes for fingerprint %s" % FingerPrint)
 
    # Look for the group with the gid of the user
    GAttr = l.search_s(LDAPDn,ldap.SCOPE_ONELEVEL,"(&(objectClass=debianGroup)(gidnumber=%s))" % Attrs[0][1]["gidNumber"][0], ["gid"])
    if len(GAttr) == 0:
-          raise Error, "Database inconsistency found: main group for account not found in database"
+          raise MessageError("Database inconsistency found: main group for account not found in database")
 
    # See if the group membership is OK
    # Only if a group was given on the commandline
@@ -93,7 +95,7 @@ def CheckLDAP(FingerPrint):
              if x == GroupMember:
                  Hit = 1;
       if Hit != 1:
-         raise Error, "You don't have %s group permissions."%(GroupMember);
+         raise MessageError("You don't have %s group permissions."%(GroupMember))
    
 # Start of main program
 # Process options
@@ -137,20 +139,20 @@ try:
    verbmsg("Processing message %s" % MsgID)
    Msg = GetClearSig(mail,1);
    if AllowMIME == 0 and Msg[1] != 0:
-      raise Error, "PGP/MIME disallowed";
+      raise MessageError("PGP/MIME disallowed")
   
    ErrMsg = "Message is not PGP signed:"
    if Msg[0].find("-----BEGIN PGP SIGNED MESSAGE-----") == -1:
-      raise Error, "No PGP signature";
+      raise MessageError("No PGP signature")
    
    # Check the signature
    ErrMsg = "Unable to check the signature or the signature was invalid:";
    pgp = GPGCheckSig2(Msg[0])
 
    if not pgp.ok:
-      raise UDFormatError, pgp.why
+      raise UDFormatError(pgp.why)
    if pgp.text is None:
-      raise UDFormatError, "Null signature text"
+      raise UDFormatError("Null signature text")
 
    # Check the signature against the replay cache
    if ReplayCacheFile is not None:
@@ -167,7 +169,7 @@ try:
          Line = F.readline();
          if Line == "": break;
          if pgp.text.find(Line.strip()) == -1:
-             raise Error,"Phrase '%s' was not found" % (Line.strip())
+             raise MessageError("Phrase '%s' was not found" % (Line.strip()))
       
 except:
    ErrMsg = "[%s] \"%s\" \"%s %s\"\n"%(Now,MsgID,ErrMsg,sys.exc_value);
index 1e95c46..103f472 100755 (executable)
@@ -96,7 +96,7 @@ def load_keys_from_gpg(keyrings):
       keys[fingerprint] = pgp_uid
 
    if Keys.close() is not None:
-      raise "Error","GPG failed"
+      raise Exception("GPG failed")
 
    return keys
 
index 77f71dc..0dee8c4 100755 (executable)
@@ -268,7 +268,7 @@ if Update == 0 or ForceMail == 1:
                                "0x"+Keys[0][1],UsePGP2);
       Password = None;
       if CryptedPass is None:
-        raise "Error","Password Encryption failed"
+        raise Exception("Password Encryption failed")
    else:
       Pass = HashPass(Password);
       CryptedPass = "Your password has been set to the previously agreed value.";
@@ -398,7 +398,7 @@ Child = os.popen("/usr/sbin/sendmail -t","w");
 #Child = os.popen("cat","w");
 Child.write(Reply);
 if Child.close() is not None:
-   raise Error, "Sendmail gave a non-zero return code";
+   raise Exception("Sendmail gave a non-zero return code")
 
 # vim:set et:
 # vim:set ts=3:
index 9329261..f594cea 100644 (file)
@@ -244,12 +244,14 @@ def GPGWriteFilter(Program,Options,Message):
       Output.close();
       GPGText.close();
 
+
+
 # This takes a text passage, a destination and a flag indicating the
 # compatibility to use and returns an encrypted message to the recipient.
 # It is best if the recipient is specified using the hex key fingerprint
 # of the target, ie 0x64BE1319CCF6D393BF87FF9358A6D4EE
 def GPGEncrypt(Message,To,PGP2):
-   Error = "KeyringError"
+   class KeyringError(Exception): pass
    # Encrypt using the PGP5 block encoding and with the PGP5 option set.
    # This will handle either RSA or DSA/DH asymetric keys.
    # In PGP2 compatible mode IDEA and rfc1991 encoding are used so that
@@ -257,11 +259,11 @@ def GPGEncrypt(Message,To,PGP2):
    # can read a message encrypted with blowfish and RSA.
    searchkey = GPGKeySearch(To);
    if len(searchkey) == 0:
-      raise Error, "No key found matching %s"%(To);
+      raise KeyringError("No key found matching %s"%(To))
    elif len(searchkey) > 1:
-      raise Error, "Multiple keys found matching %s"%(To);
+      raise KeyringError("Multiple keys found matching %s"%(To))
    if searchkey[0][4].find("E") < 0:
-      raise Error, "Key %s has no encryption capability - are all encryption subkeys expired or revoked?  Are there any encryption subkeys?"%(To);
+      raise KeyringError("Key %s has no encryption capability - are all encryption subkeys expired or revoked?  Are there any encryption subkeys?"%(To))
 
    if PGP2 == 0:
       try:
index d47909d..eb27ecb 100644 (file)
@@ -244,7 +244,7 @@ def HashPass(Password):
       Salt = Salt + SaltVals[ord(Rand.read(1)[0]) % len(SaltVals)]
    Pass = crypt.crypt(Password, Salt)
    if len(Pass) < 14:
-      raise "Password Error", "MD5 password hashing failed, not changing the password!"
+      raise Exception("MD5 password hashing failed, not changing the password!")
    return Pass