EX_TEMPFAIL = 75;
EX_PERMFAIL = 65; # EX_DATAERR
-Error = 'Message Error';
# Configuration
ReplayCacheFile = None;
AllowMIME = 1;
Verbose = 0;
+class MessageError(Exception):
+ pass
+
def verbmsg(msg):
if Verbose:
sys.stderr.write(msg + "\n")
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():
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
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
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:
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);
"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.";
#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:
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
# 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: