From aba75bee048140219fd0d353ed2f0d6395d83809 Mon Sep 17 00:00:00 2001 From: yena Date: Mon, 2 Dec 2024 16:18:07 +0100 Subject: [PATCH 1/2] Dovecot lua auth: Fix encoding of payload --- contrib/checkpasswd.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/checkpasswd.lua b/contrib/checkpasswd.lua index b8f974c3..55374a95 100644 --- a/contrib/checkpasswd.lua +++ b/contrib/checkpasswd.lua @@ -123,7 +123,7 @@ function auth_password_verify(request, password) } http_request:add_header("Content-Type","application/json") http_request:add_header("Authorization","Bearer " .. env_userli_token) - http_request:set_payload(string.format('{"password": "%s"}', password)) + http_request:set_payload(json.encode({password = password})) local http_response = http_request:submit() if http_response:status() == 200 then From 162d50cd385e43bef0d26f5b03b10c8703d453a5 Mon Sep 17 00:00:00 2001 From: yena Date: Sun, 1 Dec 2024 17:45:29 +0100 Subject: [PATCH 2/2] Dovecot Lua auth: Fix quota attribute --- contrib/checkpasswd.lua | 2 +- src/Controller/DovecotController.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/contrib/checkpasswd.lua b/contrib/checkpasswd.lua index 55374a95..9cde153f 100644 --- a/contrib/checkpasswd.lua +++ b/contrib/checkpasswd.lua @@ -96,7 +96,7 @@ function auth_userdb_lookup(request) attributes["uid"] = data.body.uid if data.body.quota ~= "" then - attributes["userdb_quota_rule"] = data.body.quota + attributes["quota_rule"] = data.body.quota end -- Only return mailcrypt attributes if mailcrypt is enabled for user: if data.body.mailCrypt == 2 then diff --git a/src/Controller/DovecotController.php b/src/Controller/DovecotController.php index ccac411e..2cf94e28 100644 --- a/src/Controller/DovecotController.php +++ b/src/Controller/DovecotController.php @@ -61,8 +61,12 @@ public function lookup( } else { $mailCryptReported = 0; } + [$username, $domain] = explode('@', $user->getEmail()); + $customQuota = $user->getQuota(); + $customQuotaString = $customQuota !== null ? sprintf('*:storage=%dM', $customQuota) : ""; + return $this->json([ 'message' => self::MESSAGE_SUCCESS, 'body' => [ @@ -72,7 +76,7 @@ public function lookup( 'mailCryptPublicKey' => $user->getMailCryptPublicKey() ?? "", 'gid' => $this->mailGid, 'uid' => $this->mailUid, - 'quota' => $user->getQuota() ?? "", + 'quota' => $customQuotaString, ] ], Response::HTTP_OK); }