mirror of
https://github.com/chillout2k/ldap-acl-milter.git
synced 2025-12-12 19:00:19 +00:00
LamSession init
This commit is contained in:
parent
d6af0c648d
commit
cc4bcc1e69
17
app/lam.py
17
app/lam.py
@ -9,6 +9,7 @@ from lam_backends import g_config_backend, g_policy_backend
|
|||||||
from lam_rex import g_rex_domain, g_rex_srs
|
from lam_rex import g_rex_domain, g_rex_srs
|
||||||
from lam_logger import log_debug, log_info, log_warning, log_error
|
from lam_logger import log_debug, log_info, log_warning, log_error
|
||||||
from lam_exceptions import LamSoftException, LamHardException
|
from lam_exceptions import LamSoftException, LamHardException
|
||||||
|
from lam_session import LamSession
|
||||||
|
|
||||||
class LdapAclMilter(Milter.Base):
|
class LdapAclMilter(Milter.Base):
|
||||||
# Each new connection is handled in an own thread
|
# Each new connection is handled in an own thread
|
||||||
@ -100,14 +101,6 @@ class LdapAclMilter(Milter.Base):
|
|||||||
self.setreply(smtp_code, smtp_ecode, message)
|
self.setreply(smtp_code, smtp_ecode, message)
|
||||||
return smfir
|
return smfir
|
||||||
|
|
||||||
# Not registered/used callbacks
|
|
||||||
@Milter.nocallback
|
|
||||||
def eoh(self):
|
|
||||||
return self.milter_action(action = 'continue')
|
|
||||||
@Milter.nocallback
|
|
||||||
def body(self, chunk):
|
|
||||||
return self.milter_action(action = 'continue')
|
|
||||||
|
|
||||||
def connect(self, IPname, family, hostaddr):
|
def connect(self, IPname, family, hostaddr):
|
||||||
self.reset()
|
self.reset()
|
||||||
self.proto_stage = 'CONNECT'
|
self.proto_stage = 'CONNECT'
|
||||||
@ -262,6 +255,14 @@ class LdapAclMilter(Milter.Base):
|
|||||||
self.log_info("AR-parse exception: {0}".format(str(e)))
|
self.log_info("AR-parse exception: {0}".format(str(e)))
|
||||||
return self.milter_action(action = 'continue')
|
return self.milter_action(action = 'continue')
|
||||||
|
|
||||||
|
# Not registered/used callbacks
|
||||||
|
@Milter.nocallback
|
||||||
|
def eoh(self):
|
||||||
|
return self.milter_action(action = 'continue')
|
||||||
|
@Milter.nocallback
|
||||||
|
def body(self, chunk):
|
||||||
|
return self.milter_action(action = 'continue')
|
||||||
|
|
||||||
def eom(self):
|
def eom(self):
|
||||||
self.proto_stage = 'EOM'
|
self.proto_stage = 'EOM'
|
||||||
if g_config_backend.milter_max_rcpt_enabled:
|
if g_config_backend.milter_max_rcpt_enabled:
|
||||||
|
|||||||
@ -9,6 +9,7 @@ from lam_exceptions import (
|
|||||||
LamPolicyBackendException, LamHardException, LamSoftException
|
LamPolicyBackendException, LamHardException, LamSoftException
|
||||||
)
|
)
|
||||||
from lam_config_backend import LamConfigBackend
|
from lam_config_backend import LamConfigBackend
|
||||||
|
from lam_session import LamSession
|
||||||
|
|
||||||
class LamPolicyBackend():
|
class LamPolicyBackend():
|
||||||
def __init__(self, lam_config: LamConfigBackend):
|
def __init__(self, lam_config: LamConfigBackend):
|
||||||
@ -59,7 +60,7 @@ class LamPolicyBackend():
|
|||||||
log_debug("{0} rcpt_domain={1}".format(mcid, rcpt_domain))
|
log_debug("{0} rcpt_domain={1}".format(mcid, rcpt_domain))
|
||||||
try:
|
try:
|
||||||
if self.config.milter_schema == True:
|
if self.config.milter_schema == True:
|
||||||
# LDAP-ACL-Milter schema
|
# LDAP-ACL-Milter schema enabled
|
||||||
auth_method = ''
|
auth_method = ''
|
||||||
if self.config.milter_expect_auth == True:
|
if self.config.milter_expect_auth == True:
|
||||||
auth_method = "(|(allowedClientAddr=" + lam_session.client_addr + ")%SASL_AUTH%%X509_AUTH%)"
|
auth_method = "(|(allowedClientAddr=" + lam_session.client_addr + ")%SASL_AUTH%%X509_AUTH%)"
|
||||||
@ -124,14 +125,16 @@ class LamPolicyBackend():
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# Wildcard-domain DISABLED
|
# Wildcard-domain DISABLED
|
||||||
# Asterisk must be ASCII-HEX encoded for LDAP queries
|
# Asterisk (*) must be ASCII-HEX encoded for LDAP queries
|
||||||
query_from = from_addr.replace("*","\\2a")
|
query_from = from_addr.replace("*","\\2a")
|
||||||
query_to = rcpt_addr.replace("*","\\2a")
|
query_to = rcpt_addr.replace("*","\\2a")
|
||||||
self.ldap_conn.search(self.config.ldap_base,
|
self.ldap_conn.search(self.config.ldap_base,
|
||||||
"(&" +
|
"(&" +
|
||||||
auth_method +
|
auth_method +
|
||||||
"(allowedSenders=" + query_from + ")" +
|
"(allowedSenders=" + query_from + ")" +
|
||||||
|
"(!(deniedSenders=" + query_from + "))" +
|
||||||
"(allowedRcpts=" + query_to + ")" +
|
"(allowedRcpts=" + query_to + ")" +
|
||||||
|
"(!(deniedRcpts=" + query_to + "))" +
|
||||||
")",
|
")",
|
||||||
attributes=['policyID']
|
attributes=['policyID']
|
||||||
)
|
)
|
||||||
@ -149,7 +152,7 @@ class LamPolicyBackend():
|
|||||||
))
|
))
|
||||||
# Policy found in LDAP, but which one?
|
# Policy found in LDAP, but which one?
|
||||||
entry = self.ldap_conn.entries[0]
|
entry = self.ldap_conn.entries[0]
|
||||||
log_info("{0} match: '{1}' from_src={2}".format(
|
log_info("{0} match='{1}' from_src={2}".format(
|
||||||
mcid, entry.policyID.value, from_source
|
mcid, entry.policyID.value, from_source
|
||||||
))
|
))
|
||||||
elif len(self.ldap_conn.entries) > 1:
|
elif len(self.ldap_conn.entries) > 1:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user