summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2013-08-07 13:20:06 +0200
committerKali Kaneko <kali@leap.se>2013-08-09 16:51:16 +0200
commit26a743c6a0415be5f7c1276811fad919700d6dbf (patch)
treea0fe6d0194a9b880ae3f5bd2f6db8d15aaee0701
parent92e1115f6aa76ec656972820021f24387bac117d (diff)
Return code even if bare username
-rw-r--r--changes/bug_3405_return_for_bare_username1
-rw-r--r--src/leap/mx/alias_resolver.py41
-rw-r--r--src/leap/mx/check_recipient_access.py13
3 files changed, 44 insertions, 11 deletions
diff --git a/changes/bug_3405_return_for_bare_username b/changes/bug_3405_return_for_bare_username
new file mode 100644
index 0000000..459882a
--- /dev/null
+++ b/changes/bug_3405_return_for_bare_username
@@ -0,0 +1 @@
+ o Give a return code for bare usernames too. Closes: #3405
diff --git a/src/leap/mx/alias_resolver.py b/src/leap/mx/alias_resolver.py
index 1d478c7..08ebb73 100644
--- a/src/leap/mx/alias_resolver.py
+++ b/src/leap/mx/alias_resolver.py
@@ -19,6 +19,8 @@
"""
Classes for resolving postfix aliases.
+Test this with postmap -v -q "foo" tcp:localhost:4242
+
TODO:
o Look into using twisted.protocols.postfix.policies classes for
controlling concurrent connections and throttling resource consumption.
@@ -35,13 +37,27 @@ except ImportError:
print "for instructions on getting required dependencies."
+class LEAPPostFixTCPMapserver(postfix.PostfixTCPMapServer):
+ def _cbGot(self, value):
+ if value is None:
+ self.sendCode(500, postfix.quote("NOT FOUND SRY"))
+ else:
+ self.sendCode(200, postfix.quote(value))
+
+
class AliasResolverFactory(postfix.PostfixTCPMapDeferringDictServerFactory):
+
+ protocol = LEAPPostFixTCPMapserver
+
def __init__(self, couchdb, *args, **kwargs):
postfix.PostfixTCPMapDeferringDictServerFactory.__init__(
self, *args, **kwargs)
self._cdb = couchdb
def _to_str(self, result):
+ """
+ Properly encodes the result string if any.
+ """
if isinstance(result, unicode):
result = result.encode("utf8")
if result is None:
@@ -49,24 +65,33 @@ class AliasResolverFactory(postfix.PostfixTCPMapDeferringDictServerFactory):
return result
def spit_result(self, result):
+ """
+ Formats the return codes in a postfix friendly format.
+ """
if result is None:
- return defer.succeed("500 NO RESULT")
+ return None
else:
- return defer.succeed("200")
+ return defer.succeed(result)
def get(self, key):
+ """
+ Looks up the passed key, but only up to the username id of the key.
+
+ At some point we will have to consider the domain part too.
+ """
try:
log.msg("Processing key: %s" % (key,))
if key.find("@") == -1:
- log.msg("Ignoring key since it's not an email address")
- return None
- key = key.split("@")[0]
- key = key.split("+")[0]
+ # No proper email address, but we need to continue processing
+ # the query so postmap is happy.
+ log.msg("Key it's not an email address")
+ else:
+ key = key.split("@")[0]
+ key = key.split("+")[0]
log.msg("Final key to query: %s" % (key,))
d = self._cdb.queryByLoginOrAlias(key)
- d.addCallback(self._to_str)
- d.addErrback(log.err)
+ d.addCallback(self._to_str)
d.addCallback(self.spit_result)
d.addErrback(log.err)
return d
diff --git a/src/leap/mx/check_recipient_access.py b/src/leap/mx/check_recipient_access.py
index b75d1eb..0520c7c 100644
--- a/src/leap/mx/check_recipient_access.py
+++ b/src/leap/mx/check_recipient_access.py
@@ -18,6 +18,8 @@
"""
Classes for resolving postfix recipient access
+
+Test this with postmap -v -q "foo" tcp:localhost:2244
"""
from twisted.protocols import postfix
@@ -25,9 +27,14 @@ from twisted.protocols import postfix
from leap.mx.alias_resolver import AliasResolverFactory
-class CheckRecipientAccess(postfix.PostfixTCPMapServer):
- pass
+class LEAPPostFixTCPMapserverAccess(postfix.PostfixTCPMapServer):
+ def _cbGot(self, value):
+ if value is None:
+ self.sendCode(500, postfix.quote("NOT FOUND SORRY"))
+ else:
+ # We do not send the value in this case
+ self.sendCode(200)
class CheckRecipientAccessFactory(AliasResolverFactory):
- protocol = CheckRecipientAccess
+ protocol = LEAPPostFixTCPMapserverAccess