-ReplyTo = ConfModule.replyto;
-PingFrom = ConfModule.pingfrom;
-ChPassFrom = ConfModule.chpassfrom;
-ChangeFrom = ConfModule.changefrom;
-ReplayCacheFile = ConfModule.replaycachefile;
+ReplyTo = ConfModule.replyto
+PingFrom = ConfModule.pingfrom
+ChPassFrom = ConfModule.chpassfrom
+ChangeFrom = ConfModule.changefrom
+ReplayCacheFile = ConfModule.replaycachefile
SSHFingerprintFile = ConfModule.fingerprintfile
UUID_FORMAT = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
SSHFingerprintFile = ConfModule.fingerprintfile
UUID_FORMAT = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
"mailDefaultOptions": "^(TRUE|FALSE)$",
"VoIP": ".*",
"mailContentInspectionAction": "^(reject|blackhole|markup)$",
"mailDefaultOptions": "^(TRUE|FALSE)$",
"VoIP": ".*",
"mailContentInspectionAction": "^(reject|blackhole|markup)$",
"mailDefaultOptions": None,
"VoIP": None,
"mailContentInspectionAction": None,
"mailDefaultOptions": None,
"VoIP": None,
"mailContentInspectionAction": None,
# Decode a GPS location from some common forms
def LocDecode(Str,Dir):
# Check for Decimal degrees, DGM, or DGMS
if re.match("^[+-]?[\d.]+$",Str) != None:
# Decode a GPS location from some common forms
def LocDecode(Str,Dir):
# Check for Decimal degrees, DGM, or DGMS
if re.match("^[+-]?[\d.]+$",Str) != None:
# Handle changing a set of arbitary fields
# <field>: value
def DoArbChange(Str,Attrs):
# Handle changing a set of arbitary fields
# <field>: value
def DoArbChange(Str,Attrs):
# if attrName == 'birthDate':
# (re.match("^([0-9]{4})([01][0-9])([0-3][0-9])$",G[1]) {
# if attrName == 'birthDate':
# (re.match("^([0-9]{4})([01][0-9])([0-3][0-9])$",G[1]) {
- Attrs.append((ldap.MOD_REPLACE,attrName,value));
- return "Changed entry %s to %s"%(attrName,value);
+ Attrs.append((ldap.MOD_REPLACE,attrName,value))
+ return "Changed entry %s to %s"%(attrName,value)
- Attrs.append((ldap.MOD_DELETE,attrName,None));
- return "Removed entry %s"%(attrName);
+ Attrs.append((ldap.MOD_DELETE,attrName,None))
+ return "Removed entry %s"%(attrName)
# Handle a position change message, the line format is:
# Lat: -12412.23 Long: +12341.2342
def DoPosition(Str,Attrs):
Match = re.match("^lat: ([+\-]?[\d:.ns]+(?: ?[ns])?) long: ([+\-]?[\d:.ew]+(?: ?[ew])?)$", Str.lower())
if Match == None:
# Handle a position change message, the line format is:
# Lat: -12412.23 Long: +12341.2342
def DoPosition(Str,Attrs):
Match = re.match("^lat: ([+\-]?[\d:.ns]+(?: ?[ns])?) long: ([+\-]?[\d:.ew]+(?: ?[ew])?)$", Str.lower())
if Match == None:
- sLat = LocDecode(G[0],"ns");
- sLong = LocDecode(G[1],"ew");
- Lat = DecDegree(sLat,1);
- Long = DecDegree(sLong,1);
+ sLat = LocDecode(G[0],"ns")
+ sLong = LocDecode(G[1],"ew")
+ Lat = DecDegree(sLat,1)
+ Long = DecDegree(sLong,1)
- Attrs.append((ldap.MOD_REPLACE,"latitude",sLat));
- Attrs.append((ldap.MOD_REPLACE,"longitude",sLong));
- return "Position set to %s/%s (%s/%s decimal degrees)"%(sLat,sLong,Lat,Long);
+ Attrs.append((ldap.MOD_REPLACE,"latitude",sLat))
+ Attrs.append((ldap.MOD_REPLACE,"longitude",sLong))
+ return "Position set to %s/%s (%s/%s decimal degrees)"%(sLat,sLong,Lat,Long)
# [allowed_hosts=machine1,machine2 ][options ]ssh-rsa keybytes [comment]
machine_regex = re.compile("^[0-9a-zA-Z.-]+$")
def DoSSH(Str, Attrs, badkeys, uid):
# [allowed_hosts=machine1,machine2 ][options ]ssh-rsa keybytes [comment]
machine_regex = re.compile("^[0-9a-zA-Z.-]+$")
def DoSSH(Str, Attrs, badkeys, uid):
# And now break and stop processing input, which sends a reply to the user.
raise UDFormatError, "Submitted SSH Key known to be bad and insecure, processing halted, NOTHING MODIFIED AT ALL"
# And now break and stop processing input, which sends a reply to the user.
raise UDFormatError, "Submitted SSH Key known to be bad and insecure, processing halted, NOTHING MODIFIED AT ALL"
return "SSH Keys replaced with: %s %s [%s]"%(key_size, fingerprint, FormatSSHAuth(Str))
# Handle changing a dns entry
return "SSH Keys replaced with: %s %s [%s]"%(key_size, fingerprint, FormatSSHAuth(Str))
# Handle changing a dns entry
# Check if the name is already taken
G = re.match('^([-\w+]+)\s',Str)
# Check if the name is already taken
G = re.match('^([-\w+]+)\s',Str)
# [JT 20070409 - search for both tab and space suffixed hostnames
# since we accept either. It'd probably be better to parse the
# incoming string in order to construct what we feed LDAP rather
# than just passing it through as is.]
filter = "(|(dnsZoneEntry=%s *)(dnsZoneEntry=%s *))" % (hostname, hostname)
# [JT 20070409 - search for both tab and space suffixed hostnames
# since we accept either. It'd probably be better to parse the
# incoming string in order to construct what we feed LDAP rather
# than just passing it through as is.]
filter = "(|(dnsZoneEntry=%s *)(dnsZoneEntry=%s *))" % (hostname, hostname)
- Rec = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,filter,["uid"]);
+ Rec = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,filter,["uid"])
for x in Rec:
if GetAttr(x,"uid") != GetAttr(DnRecord,"uid"):
return "DNS entry is already owned by " + GetAttr(x,"uid")
for x in Rec:
if GetAttr(x,"uid") != GetAttr(DnRecord,"uid"):
return "DNS entry is already owned by " + GetAttr(x,"uid")
- Attrs.append((ldap.MOD_ADD,"dnsZoneEntry",sanitized));
- return "DNS Entry added "+sanitized;
+ Attrs.append((ldap.MOD_ADD,"dnsZoneEntry",sanitized))
+ return "DNS Entry added " + sanitized
- Attrs.append((ldap.MOD_REPLACE,"dnsZoneEntry",sanitized));
- SeenDNS = 1;
- return "DNS Entry replaced with "+sanitized;
+ Attrs.append((ldap.MOD_REPLACE,"dnsZoneEntry",sanitized))
+ SeenDNS = 1
+ return "DNS Entry replaced with "+sanitized
return "%s added %s" % (Key,Host)
Attrs.append((ldap.MOD_REPLACE,Key,Host))
return "%s added %s" % (Key,Host)
Attrs.append((ldap.MOD_REPLACE,Key,Host))
return "%s replaced with %s" % (Key,Host)
# Handle a ConfirmSudoPassword request
return "%s replaced with %s" % (Key,Host)
# Handle a ConfirmSudoPassword request
- res = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid="+uid, ['sudoPassword']);
+ 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"
if res[0][1].has_key('sudoPassword'):
if len(res) != 1:
raise UDFormatError, "Not exactly one hit when searching for user"
if res[0][1].has_key('sudoPassword'):
- Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid="+GetAttr(DnRecord,"uid"));
+ Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid="+GetAttr(DnRecord,"uid"))
if (GetAttr(Attrs[0],"userPassword").find("*LK*") != -1) \
or GetAttr(Attrs[0],"userPassword").startswith("!"):
if (GetAttr(Attrs[0],"userPassword").find("*LK*") != -1) \
or GetAttr(Attrs[0],"userPassword").startswith("!"):
return l
# Handle an [almost] arbitary change
def HandleChange(Reply,DnRecord,Key):
return l
# Handle an [almost] arbitary change
def HandleChange(Reply,DnRecord,Key):
else:
badkeys = LoadBadSSH()
Res = DoPosition(Line,Attrs) or DoDNS(Line,Attrs,DnRecord) or \
DoArbChange(Line,Attrs) or DoSSH(Line,Attrs,badkeys,GetAttr(DnRecord,"uid")) or \
DoDel(Line,Attrs) or DoRBL(Line,Attrs) or DoConfirmSudopassword(Line, SudoPasswd)
except:
else:
badkeys = LoadBadSSH()
Res = DoPosition(Line,Attrs) or DoDNS(Line,Attrs,DnRecord) or \
DoArbChange(Line,Attrs) or DoSSH(Line,Attrs,badkeys,GetAttr(DnRecord,"uid")) or \
DoDel(Line,Attrs) or DoRBL(Line,Attrs) or DoConfirmSudopassword(Line, SudoPasswd)
except:
# Fail, if someone tries to send someone elses signed email to the
# daemon then we want to abort ASAP.
if Res == None:
CommitChanges = 0
# Fail, if someone tries to send someone elses signed email to the
# daemon then we want to abort ASAP.
if Res == None:
CommitChanges = 0
if CommitChanges == 1 and len(SudoPasswd) > 0: # only if we are still good to go
try:
Res = FinishConfirmSudopassword(l, GetAttr(DnRecord,"uid"), Attrs, SudoPasswd)
if CommitChanges == 1 and len(SudoPasswd) > 0: # only if we are still good to go
try:
Res = FinishConfirmSudopassword(l, GetAttr(DnRecord,"uid"), Attrs, SudoPasswd)
- Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid="+GetAttr(DnRecord,"uid"));
+ Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"uid="+GetAttr(DnRecord,"uid"))
- Subst = {};
- Subst["__FROM__"] = ChangeFrom;
- Subst["__EMAIL__"] = EmailAddress(DnRecord);
- Subst["__ADMIN__"] = ReplyTo;
- Subst["__RESULT__"] = Result;
- Subst["__ATTR__"] = Attribs;
+ Subst = {}
+ Subst["__FROM__"] = ChangeFrom
+ Subst["__EMAIL__"] = EmailAddress(DnRecord)
+ Subst["__ADMIN__"] = ReplyTo
+ Subst["__RESULT__"] = Result
+ Subst["__ATTR__"] = Attribs
# Handle ping handles an email sent to the 'ping' address (ie this program
# called with a ping argument) It replies with a dump of the public records.
def HandlePing(Reply,DnRecord,Key):
# Handle ping handles an email sent to the 'ping' address (ie this program
# called with a ping argument) It replies with a dump of the public records.
def HandlePing(Reply,DnRecord,Key):
- Subst = {};
- Subst["__FROM__"] = PingFrom;
- Subst["__EMAIL__"] = EmailAddress(DnRecord);
- Subst["__LDAPFIELDS__"] = PrettyShow(DnRecord);
- Subst["__ADMIN__"] = ReplyTo;
+ Subst = {}
+ Subst["__FROM__"] = PingFrom
+ Subst["__EMAIL__"] = EmailAddress(DnRecord)
+ Subst["__LDAPFIELDS__"] = PrettyShow(DnRecord)
+ Subst["__ADMIN__"] = ReplyTo
return type
# Handle a change password email sent to the change password address
# (this program called with the chpass argument)
def HandleChPass(Reply,DnRecord,Key):
# Generate a random password
return type
# Handle a change password email sent to the change password address
# (this program called with the chpass argument)
def HandleChPass(Reply,DnRecord,Key):
# Generate a random password
- Subst["__PASSWORD__"] = Message;
- Subst["__ADMIN__"] = ReplyTo;
- Reply = Reply + TemplateSubst(Subst,open(TemplatesDir+"passwd-changed","r").read());
+ Subst["__PASSWORD__"] = Message
+ Subst["__ADMIN__"] = ReplyTo
+ Reply = Reply + TemplateSubst(Subst,open(TemplatesDir+"passwd-changed","r").read())
l = connect_to_ldap_and_check_if_locked(DnRecord)
# Modify the password
Rec = [(ldap.MOD_REPLACE,"userPassword","{crypt}"+Pass),
l = connect_to_ldap_and_check_if_locked(DnRecord)
# Modify the password
Rec = [(ldap.MOD_REPLACE,"userPassword","{crypt}"+Pass),
- (ldap.MOD_REPLACE,"shadowLastChange",str(int(time.time()/24/60/60)))];
- Dn = "uid=" + GetAttr(DnRecord,"uid") + "," + BaseDn;
- l.modify_s(Dn,Rec);
+ (ldap.MOD_REPLACE,"shadowLastChange",str(int(time.time()/24/60/60)))]
+ Dn = "uid=" + GetAttr(DnRecord,"uid") + "," + BaseDn
+ l.modify_s(Dn,Rec)
def HandleChTOTPSeed(Reply, DnRecord, Key):
# Generate a random seed
seed = binascii.hexlify(open("/dev/urandom", "r").read(32))
def HandleChTOTPSeed(Reply, DnRecord, Key):
# Generate a random seed
seed = binascii.hexlify(open("/dev/urandom", "r").read(32))
- msg = GPGEncrypt("Your new TOTP seed is '%s'\n" % (seed,), "0x"+Key[1],Key[4]);
+ msg = GPGEncrypt("Your new TOTP seed is '%s'\n" % (seed,), "0x"+Key[1],Key[4])
Subst["__FROM__"] = ChPassFrom
Subst["__EMAIL__"] = EmailAddress(DnRecord)
Subst["__PASSWORD__"] = msg
Subst["__FROM__"] = ChPassFrom
Subst["__EMAIL__"] = EmailAddress(DnRecord)
Subst["__PASSWORD__"] = msg
Rec = [(ldap.MOD_REPLACE, "totpSeed", seed)]
Dn = "uid=" + GetAttr(DnRecord,"uid") + "," + BaseDn
l.modify_s(Dn,Rec)
Rec = [(ldap.MOD_REPLACE, "totpSeed", seed)]
Dn = "uid=" + GetAttr(DnRecord,"uid") + "," + BaseDn
l.modify_s(Dn,Rec)
def HandleChKrbPass(Reply,DnRecord,Key):
# Connect to the ldap server, will throw an exception if account locked.
def HandleChKrbPass(Reply,DnRecord,Key):
# Connect to the ldap server, will throw an exception if account locked.
- Subst["__PASSWORD__"] = Message;
- Subst["__ADMIN__"] = ReplyTo;
- Reply = Reply + TemplateSubst(Subst,open(TemplatesDir+"passwd-changed","r").read());
+ Subst["__PASSWORD__"] = Message
+ Subst["__ADMIN__"] = ReplyTo
+ Reply = Reply + TemplateSubst(Subst,open(TemplatesDir+"passwd-changed","r").read())
# Start of main program
# Drop messages from a mailer daemon.
if os.environ.has_key('SENDER') == 0 or len(os.environ['SENDER']) == 0:
# Start of main program
# Drop messages from a mailer daemon.
if os.environ.has_key('SENDER') == 0 or len(os.environ['SENDER']) == 0:
- ErrType = EX_PERMFAIL;
- ErrMsg = "Failed to understand the email or find a signature:";
- mail = email.parser.Parser().parse(sys.stdin);
- Msg = GetClearSig(mail);
+ ErrType = EX_PERMFAIL
+ ErrMsg = "Failed to understand the email or find a signature:"
+ 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 \
Msg[0].find("-----BEGIN PGP MESSAGE-----") == -1:
ErrMsg = "Message is not PGP signed:"
if Msg[0].find("-----BEGIN PGP SIGNED MESSAGE-----") == -1 and \
Msg[0].find("-----BEGIN PGP MESSAGE-----") == -1:
raise UDFormatError, "Null signature text"
# Extract the plain message text in the event of mime encoding
raise UDFormatError, "Null signature text"
# Extract the plain message text in the event of mime encoding
ErrMsg = "Problem stripping MIME headers from the decoded message"
if Msg[1] == 1:
e = email.parser.Parser().parsestr(pgp.text)
ErrMsg = "Problem stripping MIME headers from the decoded message"
if Msg[1] == 1:
e = email.parser.Parser().parsestr(pgp.text)
# Search for the matching key fingerprint
Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"keyFingerPrint=" + pgp.key_fpr)
# Search for the matching key fingerprint
Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"keyFingerPrint=" + pgp.key_fpr)
- Date = time.strftime("%a, %d %b %Y %H:%M:%S +0000",time.gmtime(time.time()));
- Reply = "To: %s\nReply-To: %s\nDate: %s\n" % (Sender,ReplyTo,Date);
+ Date = time.strftime("%a, %d %b %Y %H:%M:%S +0000",time.gmtime(time.time()))
+ Reply = "To: %s\nReply-To: %s\nDate: %s\n" % (Sender,ReplyTo,Date)
Res = l.search_s(HostBaseDn, ldap.SCOPE_SUBTREE, '(objectClass=debianServer)', ['hostname'] )
# Res is a list of tuples.
Res = l.search_s(HostBaseDn, ldap.SCOPE_SUBTREE, '(objectClass=debianServer)', ['hostname'] )
# Res is a list of tuples.
elif PlainText.strip().find("Please change my TOTP seed") >= 0:
Reply = HandleChTOTPSeed(Reply, Attrs[0], pgp.key_info)
else:
elif PlainText.strip().find("Please change my TOTP seed") >= 0:
Reply = HandleChTOTPSeed(Reply, Attrs[0], pgp.key_info)
else:
- ErrMsg = "A problem occured while trying to send the reply";
- Child = os.popen("/usr/sbin/sendmail -t","w");
-# Child = os.popen("cat","w");
- Child.write(Reply);
+ ErrMsg = "A problem occured while trying to send the reply"
+ Child = os.popen("/usr/sbin/sendmail -t","w")
+# Child = os.popen("cat","w")
+ Child.write(Reply)
- Date = time.strftime("%a, %d %b %Y %H:%M:%S +0000",time.gmtime(time.time()));
- ErrReplyHead = "To: %s\nReply-To: %s\nDate: %s\n" % (os.environ['SENDER'],ReplyTo,Date);
+ Date = time.strftime("%a, %d %b %Y %H:%M:%S +0000",time.gmtime(time.time()))
+ ErrReplyHead = "To: %s\nReply-To: %s\nDate: %s\n" % (os.environ['SENDER'],ReplyTo,Date)
- Trace = "==> %s: %s\n" %(sys.exc_type,sys.exc_value);
- List = traceback.extract_tb(sys.exc_traceback);
+ Trace = "==> %s: %s\n" %(sys.exc_type,sys.exc_value)
+ List = traceback.extract_tb(sys.exc_traceback)
- Trace = Trace + " %s %s:%u: %s\n" %(x[2],x[0],x[1],x[3]);
+ Trace = Trace + " %s %s:%u: %s\n" %(x[2],x[0],x[1],x[3])
- Child = os.popen("/usr/sbin/sendmail -t -oi -f ''","w");
- Child.write(ErrReplyHead);
- Child.write(ErrReply);
+ Child = os.popen("/usr/sbin/sendmail -t -oi -f ''","w")
+ Child.write(ErrReplyHead)
+ Child.write(ErrReply)