projects
/
mirror
/
userdir-ldap.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
release
[mirror/userdir-ldap.git]
/
ud-echelon
diff --git
a/ud-echelon
b/ud-echelon
index
6c07a0a
..
38e0718
100755
(executable)
--- a/
ud-echelon
+++ b/
ud-echelon
@@
-2,6
+2,7
@@
# -*- mode: python -*-
import userdir_gpg, userdir_ldap, sys, traceback, time, ldap, os, getopt;
import pwd
# -*- mode: python -*-
import userdir_gpg, userdir_ldap, sys, traceback, time, ldap, os, getopt;
import pwd
+import email, email.parser
from userdir_gpg import *;
from userdir_ldap import *;
from userdir_gpg import *;
from userdir_ldap import *;
@@
-10,10
+11,10
@@
EX_PERMFAIL = 65; # EX_DATAERR
Debug = None;
# Try to extract a key fingerprint from a PGP siged message
Debug = None;
# Try to extract a key fingerprint from a PGP siged message
-def TryGPG(
E
mail):
+def TryGPG(mail):
# Try to get a pgp text
try:
# Try to get a pgp text
try:
- Msg = GetClearSig(
Email
);
+ Msg = GetClearSig(
mail, lax_multipart=True
);
except:
# Log an exception.. but continue. This is to deal with 'sort of'
# PGP-MIME things
except:
# Log an exception.. but continue. This is to deal with 'sort of'
# PGP-MIME things
@@
-25,26
+26,26
@@
def TryGPG(Email):
if Msg[0].find("-----BEGIN PGP SIGNED MESSAGE-----") == -1:
return None;
if Msg[0].find("-----BEGIN PGP SIGNED MESSAGE-----") == -1:
return None;
-
Res = GPGCheckSig
(Msg[0]);
+
pgp = GPGCheckSig2
(Msg[0]);
# Failed to find a matching sig
# Failed to find a matching sig
- if
Res[0] != None
:
- S = "%s: %s -> PGP Checking failed '%s': %s %s\n" %(Now,MsgID,
Email.getheader("From"),str(Res[0]),str(Res[2]
));
+ if
not pgp.ok
:
+ S = "%s: %s -> PGP Checking failed '%s': %s %s\n" %(Now,MsgID,
mail["From"],str(pgp.why),str(pgp.key_info
));
ErrLog.write(S);
return None;
# Search for the matching key fingerprint
ErrLog.write(S);
return None;
# Search for the matching key fingerprint
- Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"keyFingerPrint=" +
Res[2][1]
);
+ Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"keyFingerPrint=" +
pgp.key_fpr
);
if len(Attrs) == 0:
return None;
if len(Attrs) != 1:
raise Error, "Oddly your key fingerprint is assigned to more than one account.."
if len(Attrs) == 0:
return None;
if len(Attrs) != 1:
raise Error, "Oddly your key fingerprint is assigned to more than one account.."
- return (Attrs[0][1]["uid"][0],"PGP",FormatPGPKey(
Res[2][1]
));
+ return (Attrs[0][1]["uid"][0],"PGP",FormatPGPKey(
pgp.key_fpr
));
# Try to guess the name from the email address
# Try to guess the name from the email address
-def TryMatcher(
E
mail):
- Sender =
Email.getheader("From")
;
+def TryMatcher(mail):
+ Sender =
mail["From"]
;
if Sender == None:
return None;
if Sender == None:
return None;
@@
-87,9
+88,9
@@
try:
# Get the email
ErrType = EX_PERMFAIL;
ErrMsg = "Failed to understand the email or find a signature:";
# Get the email
ErrType = EX_PERMFAIL;
ErrMsg = "Failed to understand the email or find a signature:";
-
Email = mimetools.Message(sys.stdin,0
);
- MsgID =
Email.getheader("Message-ID");
-
+
mail = email.parser.Parser().parse(sys.stdin
);
+ MsgID =
mail["Message-ID"]
+
# Connect to the ldap server
ErrType = EX_TEMPFAIL;
ErrMsg = "An error occured while performing the LDAP lookup";
# Connect to the ldap server
ErrType = EX_TEMPFAIL;
ErrMsg = "An error occured while performing the LDAP lookup";
@@
-106,15
+107,14
@@
try:
# Try to decode
ErrType = EX_TEMPFAIL;
ErrMsg = "An error occured while trying GPG decoding";
# Try to decode
ErrType = EX_TEMPFAIL;
ErrMsg = "An error occured while trying GPG decoding";
- User = TryGPG(
E
mail);
+ User = TryGPG(mail);
if User == None:
ErrMsg = "An error occured while trying Matcher decoding";
if User == None:
ErrMsg = "An error occured while trying Matcher decoding";
- User = TryMatcher(
E
mail);
+ User = TryMatcher(mail);
# Get any mailing list information
# Get any mailing list information
- List = Email.getheader("X-Mailing-List");
- if List == None:
- List = "-";
+ List = mail['X-Mailing-List']
+ if not List: List = "-";
# Tada, write a log message
if User != None:
# Tada, write a log message
if User != None:
@@
-127,7
+127,7
@@
try:
else:
print Rec;
else:
else:
print Rec;
else:
- User = ("-","UKN",
Email.getheader("From")
);
+ User = ("-","UKN",
mail["From"]
);
Msg = "[%s] \"%s\" \"%s\" \"%s\""%(Now,User[2],List,MsgID);
MainLog.write("%s %s %s\n"%(User[0],User[1],Msg));
Msg = "[%s] \"%s\" \"%s\" \"%s\""%(Now,User[2],List,MsgID);
MainLog.write("%s %s %s\n"%(User[0],User[1],Msg));