Skip to content

Commit

Permalink
Dovecot Lua auth: Fix quota attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
y3n4 committed Dec 2, 2024
1 parent aba75be commit fb3dbd2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions contrib/checkpasswd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -130,7 +130,7 @@ function auth_password_verify(request, password)
local data = json.decode(http_response:payload())

-- mailCryptPrivateKey may be empty, but cannot be nil
if not(data and data.body and data.body.mailCrypt and data.body.mailCryptPrivateKey and data.body.mailCryptPublicKey) then
if not(data and data.body and data.body.mailCrypt and data.body.mailCryptPrivateKey and data.body.mailCryptPublicKey and data.body.quota) then
request:log_error(log_msg['http-ok-malformed'])
return dovecot.auth.PASSDB_RESULT_INTERNAL_FAILURE, ""
end
Expand Down
6 changes: 5 additions & 1 deletion src/Controller/DovecotController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand All @@ -72,7 +76,7 @@ public function lookup(
'mailCryptPublicKey' => $user->getMailCryptPublicKey() ?? "",
'gid' => $this->mailGid,
'uid' => $this->mailUid,
'quota' => $user->getQuota() ?? "",
'quota' => $customQuotaString,
]
], Response::HTTP_OK);
}
Expand Down

0 comments on commit fb3dbd2

Please sign in to comment.