import userdir_gpg, userdir_ldap, sys, traceback, time, ldap, os, commands
import pwd, tempfile
import subprocess
+import email, email.parser
from userdir_gpg import *
from userdir_ldap import *
global SudoPasswd
result = "\n"
+ if len(SudoPasswd) == 0:
+ return None
+
res = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid="+uid, ['sudoPassword']);
if len(res) != 1:
raise UDFormatError, "Not exactly one hit when searching for user"
# Connect to the ldap server
l = connect_to_ldap_and_check_if_locked(DnRecord)
- if CommitChanges == 1: # only if we are still good to go
+ if CommitChanges == 1 and len(Attrs) > 0: # only if we are still good to go
try:
Res = FinishConfirmSudopassword(l, GetAttr(DnRecord,"uid"), Attrs)
- Result = Result + Res + "\n";
+ if not Res is None:
+ Result = Result + Res + "\n";
except Error, e:
CommitChanges = 0
Result = Result + "FinishConfirmSudopassword raised an error (%s) - no changes committed\n"%(e);
- # Modify the record
- if CommitChanges == 1:
+ if CommitChanges == 1 and len(Attrs) > 0:
Dn = "uid=" + GetAttr(DnRecord,"uid") + "," + BaseDn;
l.modify_s(Dn,Attrs);
# Get the email
ErrType = EX_PERMFAIL;
ErrMsg = "Failed to understand the email or find a signature:";
- Email = mimetools.Message(sys.stdin,0);
- Msg = GetClearSig(Email);
+ mail = email.parser.Parser().parse(sys.stdin);
+ Msg = GetClearSig(mail);
ErrMsg = "Message is not PGP signed:"
if Msg[0].find("-----BEGIN PGP SIGNED MESSAGE-----") == -1 and \
global PlainText;
ErrMsg = "Problem stripping MIME headers from the decoded message"
if Msg[1] == 1:
- try:
- Index = pgp.text.index("\n\n") + 2
- except ValueError:
- Index = pgp.text.index("\n\r\n") + 3
- PlainText = pgp.text[Index:]
+ e = email.parser.Parser().parsestr(pgp.text)
+ PlainText = e.get_payload(decode=True)
else:
PlainText = pgp.text
# Check the signature against the replay cache
RC = ReplayCache(ReplayCacheFile);
- RC.Clean();
- ErrMsg = "The replay cache rejected your message. Check your clock!";
- Rply = RC.Check(pgp.sig_info);
- if Rply != None:
- RC.close()
- raise UDNotAllowedError, Rply;
- RC.Add(pgp.sig_info);
- RC.close()
+ RC.process(pgp.sig_info)
# Determine the sender address
ErrMsg = "A problem occured while trying to formulate the reply";
- Sender = Email.getheader("Reply-To");
- if Sender == None:
- Sender = Email.getheader("From");
- if Sender == None:
- raise UDFormatError, "Unable to determine the sender's address";
+ Sender = mail['Reply-To']
+ if not Sender: Sender = mail['From']
+ if not Sender: raise UDFormatError, "Unable to determine the sender's address";
# Formulate a reply
Date = time.strftime("%a, %d %b %Y %H:%M:%S +0000",time.gmtime(time.time()));