X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;ds=sidebyside;f=sigcheck;h=2561f1ce59d3bf3e7747bded10a68f1b4230706d;hb=0f6e06652090e3b2afb9b8b604e50c3637a3e546;hp=9c59bd2d37ac392a308070fef9d6517b0de44c2f;hpb=4eaa444b9eb4c9d24cd2790f99a690054bf2f806;p=mirror%2Fuserdir-ldap.git 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);