ud-mailgate: fix gpg result usage
[mirror/userdir-ldap.git] / userdir_gpg.py
index 1140d44..abe1708 100644 (file)
@@ -52,6 +52,9 @@ CleanCutOff = 7*24*60*60;
 AgeCutOff = 4*24*60*60;
 FutureCutOff = 3*24*60*60;
 
+def ClearKeyrings():
+   del GPGKeyRings[:]
+
 # Set the keyrings, the input is a list of keyrings
 def SetKeyrings(Rings):
    for x in Rings:
@@ -254,6 +257,7 @@ def GPGWriteFilter(Program,Options,Message):
 # 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"
    # 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
@@ -422,7 +426,7 @@ def GPGCheckSig(Message):
       # A gpg failure is an automatic bad signature
       if Exit[1] != 0 and Why == None:
          GoodSig = 0;
-         Why = "GPG execution failed " + str(Exit[0]);
+         Why = "GPG execution returned non-zero exit status: " + str(Exit[1]);
 
       if GoodSig == 0 and (Why == None or len(Why) == 0):
          Why = "Checking Failed";
@@ -438,6 +442,26 @@ def GPGCheckSig(Message):
          Res[1].close();
          Res[2].close();
 
+class GPGCheckSig2:
+       def __init__(self, msg):
+               res = GPGCheckSig(msg)
+               self.why = res[0]
+               self.sig_info = res[1]
+               self.key_info = res[2]
+               self.text = res[3]
+
+               self.ok = self.why is None
+
+               self.sig_id = self.sig_info[0]
+               self.sig_date = self.sig_info[1]
+               self.sig_fpr = self.sig_info[2]
+
+               self.key_id = self.key_info[0]
+               self.key_fpr = self.key_info[1]
+               self.key_owner = self.key_info[2]
+
+               self.is_pgp2 = self.key_info[4]
+
 # Search for keys given a search pattern. The pattern is passed directly
 # to GPG for processing. The result is a list of tuples of the form:
 #   (KeyID,KeyFinger,Owner,Length)
@@ -564,3 +588,6 @@ class ReplayCache:
       else:
          self.DB[Key] = str(int(Sig[1]));
         
+# vim:set et:
+# vim:set ts=3:
+# vim:set shiftwidth=3: