SigningTable refactor to work with the revised table structure - mostly works, but not thoroughly tested
This commit is contained in:
+27
-28
@@ -218,8 +218,9 @@ class dkimMilter(Milter.Base):
|
|||||||
for domain in domains:
|
for domain in domains:
|
||||||
rhs = '.'+domain
|
rhs = '.'+domain
|
||||||
# compare right hand side of fdomain against .domain
|
# compare right hand side of fdomain against .domain
|
||||||
if self.fdomain[-len(rhs):] == rhs:
|
if fdomain[-len(rhs):] == rhs:
|
||||||
# return parent domain on match
|
# return parent domain on match
|
||||||
|
syslog.syslog('domain: {0}'.format(domain))
|
||||||
return domain
|
return domain
|
||||||
# or return the fdomain itself
|
# or return the fdomain itself
|
||||||
return fdomain
|
return fdomain
|
||||||
@@ -228,40 +229,38 @@ class dkimMilter(Milter.Base):
|
|||||||
"""Determine d= and i= identiies for signature"""
|
"""Determine d= and i= identiies for signature"""
|
||||||
self.domain = []
|
self.domain = []
|
||||||
iequals = None
|
iequals = None
|
||||||
if self.conf.get('SigningTableEd25519'):
|
if self.conf.get('SigningTable'):
|
||||||
for tablerow in self.conf.get('SigningTableEd25519'):
|
match = False
|
||||||
if tablerow[0] == '%':
|
for dictkey, dictvalues in self.conf.get('SigningTable').items():
|
||||||
|
if dictkey == '%':
|
||||||
|
self.domain.append(self.fdomain)
|
||||||
|
match = True
|
||||||
|
elif len(dictkey.split('*')) == 1:
|
||||||
|
if dictkey == self.author:
|
||||||
|
self.domain.append(self.fdomain)
|
||||||
|
match = True
|
||||||
|
else:
|
||||||
|
if len(dictkey.split('*')) == 2:
|
||||||
|
if dictkey.split('*')[1] == self.author[:-len(dictkey.split('*')[1])]:
|
||||||
|
self.domain.append(self.fdomain)
|
||||||
|
match = True
|
||||||
self.domain.append(self.fdomain)
|
self.domain.append(self.fdomain)
|
||||||
try:
|
try:
|
||||||
if tablerow[1]:
|
if len(dictvalues) == 2 and match:
|
||||||
if tablerow[1] =='%':
|
if dictvalues[0] =='%':
|
||||||
self.iequals = codces.encode('@' + self.fdomain)
|
self.iequals = codecs.encode('@' + self.fdomain)
|
||||||
elif tablerow[1][1:] == self.fdomain or tablerow[1][1:] == self.get_parent_domain(tablerow[1][1:], self.domain):
|
elif dictvalues[0][1:] == self.fdomain or self.get_parent_domain(dictvalues[0][1:], self.domain) == self.fdomain:
|
||||||
self.iequals = codces.encode(tablerow[1])
|
self.iequals = codecs.encode(dictvalues[0])
|
||||||
except:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
domain2 = []
|
if match:
|
||||||
if self.conf.get('SigningTable'):
|
#TODO add KeyTable stuffs here.
|
||||||
for tablerow in self.conf.get('SigningTable'):
|
break
|
||||||
if tablerow[0] == '%':
|
|
||||||
domain2.append(self.fdomain)
|
|
||||||
try:
|
|
||||||
if tablerow[1]:
|
|
||||||
iequals = codces.encode('@' + self.fdomain)
|
|
||||||
elif tablerow[1][1:] == fdomain or tablerow[1][1:] == self.get_parent_domain(tablerow[1][1:], domain):
|
|
||||||
iequals = codces.encode(tablerow[1])
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
if not self.domain:
|
|
||||||
self.domain = domain2
|
|
||||||
if not self.iequals:
|
|
||||||
self.iequals = iequals
|
|
||||||
if not self.domain and self.conf.get('Domain'):
|
if not self.domain and self.conf.get('Domain'):
|
||||||
self.domain = self.conf.get('Domain')
|
self.domain = self.conf.get('Domain')
|
||||||
if self.conf.get('SubDomains'):
|
if self.conf.get('SubDomains'):
|
||||||
self.fdomain = self.get_parent_domain(self.fdomain, self.domain)
|
self.fdomain = self.get_parent_domain(self.fdomain, self.domain)
|
||||||
|
|
||||||
|
|
||||||
def sign_dkim(self, txt):
|
def sign_dkim(self, txt):
|
||||||
canon = codecs.encode(self.conf.get('Canonicalization'), 'ascii')
|
canon = codecs.encode(self.conf.get('Canonicalization'), 'ascii')
|
||||||
canonicalize = []
|
canonicalize = []
|
||||||
@@ -446,11 +445,11 @@ def main():
|
|||||||
if socketname is None:
|
if socketname is None:
|
||||||
socketname = 'local:/var/run/dkimpy-milter/dkimpy-milter.sock'
|
socketname = 'local:/var/run/dkimpy-milter/dkimpy-milter.sock'
|
||||||
own_socketfile(milterconfig, socketname)
|
own_socketfile(milterconfig, socketname)
|
||||||
drop_privileges(milterconfig)
|
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
if milterconfig.get('Syslog'):
|
if milterconfig.get('Syslog'):
|
||||||
syslog.syslog('dkimpy-milter starting:{0} user:{1}'
|
syslog.syslog('dkimpy-milter starting:{0} user:{1}'
|
||||||
.format(pid, milterconfig.get('UserID')))
|
.format(pid, milterconfig.get('UserID')))
|
||||||
|
drop_privileges(milterconfig)
|
||||||
Milter.runmilter(miltername, socketname, 240)
|
Milter.runmilter(miltername, socketname, 240)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user