From a6a94944e06d5bea3038dd9db039aa8c866d04eb Mon Sep 17 00:00:00 2001 From: link2xt Date: Tue, 17 Oct 2023 19:08:44 +0000 Subject: [PATCH] Add /etc/mailname --- chatmaild/src/chatmaild/dictproxy.py | 12 ++++++++---- deploy-chatmail/src/deploy_chatmail/__init__.py | 7 +++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/chatmaild/src/chatmaild/dictproxy.py b/chatmaild/src/chatmaild/dictproxy.py index 2d60f1f1..8e2698b5 100644 --- a/chatmaild/src/chatmaild/dictproxy.py +++ b/chatmaild/src/chatmaild/dictproxy.py @@ -59,7 +59,7 @@ def lookup_passdb(db, user, password): return userdata -def handle_dovecot_request(msg, db): +def handle_dovecot_request(msg, db, mail_domain): print(f"received msg: {msg!r}", file=sys.stderr) short_command = msg[0] if short_command == "L": # LOOKUP @@ -70,13 +70,15 @@ def handle_dovecot_request(msg, db): res = "" if namespace == "shared": if type == "userdb": - res = lookup_userdb(db, user) + if user.endswith(f"@{mail_domain}"): + res = lookup_userdb(db, user) if res: reply_command = "O" else: reply_command = "N" elif type == "passdb": - res = lookup_passdb(db, user, password=args[0]) + if user.endswith(f"@{mail_domain}"): + res = lookup_passdb(db, user, password=args[0]) if res: reply_command = "O" else: @@ -95,6 +97,8 @@ def main(): socket = sys.argv[1] passwd_entry = pwd.getpwnam(sys.argv[2]) db = Database(sys.argv[3]) + with open("/etc/mailname", "r") as fp: + mail_domain = fp.read().strip() class Handler(StreamRequestHandler): def handle(self): @@ -102,7 +106,7 @@ def main(): msg = self.rfile.readline().strip().decode() if not msg: break - res = handle_dovecot_request(msg, db) + res = handle_dovecot_request(msg, db, mail_domain) if res: print(f"sending result: {res!r}", file=sys.stderr) self.wfile.write(res.encode("ascii")) diff --git a/deploy-chatmail/src/deploy_chatmail/__init__.py b/deploy-chatmail/src/deploy_chatmail/__init__.py index db3e7171..7001b628 100644 --- a/deploy-chatmail/src/deploy_chatmail/__init__.py +++ b/deploy-chatmail/src/deploy_chatmail/__init__.py @@ -244,6 +244,13 @@ def deploy_chatmail(mail_domain: str, mail_server: str, dkim_selector: str) -> N restarted=dovecot_need_restart, ) + # This file is used by auth proxy. + # https://wiki.debian.org/EtcMailName + server.shell( + name="Setup /etc/mailname", + commands=[f"echo {mail_domain} >/etc/mailname; chmod 644 /etc/mailname"], + ) + def callback(): result = server.shell( commands=[