From 6602e1c9732fccb70a545d9020eeb883844cb00b Mon Sep 17 00:00:00 2001 From: Julien Cristau Date: Fri, 11 Oct 2019 16:13:36 +0200 Subject: [PATCH] Stop using string exceptions. They were removed in python 2.6. --- debian/changelog | 1 + misc/ud-update-sudopasswords | 2 +- sigcheck | 24 +++++++++++++----------- ud-gpgimport | 2 +- ud-useradd | 4 ++-- userdir_gpg.py | 10 ++++++---- userdir_ldap.py | 2 +- 7 files changed, 25 insertions(+), 20 deletions(-) diff --git a/debian/changelog b/debian/changelog index 8378dd1..1ccff46 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 Sat, 06 Apr 2019 22:04:34 +0200 diff --git a/misc/ud-update-sudopasswords b/misc/ud-update-sudopasswords index c5585b8..441acb8 100755 --- a/misc/ud-update-sudopasswords +++ b/misc/ud-update-sudopasswords @@ -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'): diff --git a/sigcheck b/sigcheck index 9c59bd2..2561f1c 100755 --- 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); diff --git a/ud-gpgimport b/ud-gpgimport index 1e95c46..103f472 100755 --- a/ud-gpgimport +++ b/ud-gpgimport @@ -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 diff --git a/ud-useradd b/ud-useradd index 77f71dc..0dee8c4 100755 --- a/ud-useradd +++ b/ud-useradd @@ -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: diff --git a/userdir_gpg.py b/userdir_gpg.py index 9329261..f594cea 100644 --- a/userdir_gpg.py +++ b/userdir_gpg.py @@ -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: diff --git a/userdir_ldap.py b/userdir_ldap.py index d47909d..eb27ecb 100644 --- a/userdir_ldap.py +++ b/userdir_ldap.py @@ -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 -- 2.20.1