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 1, 2024
1 parent 049b3dd commit 2cccd8f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion contrib/checkpasswd.lua
Original file line number Diff line number Diff line change
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 All @@ -142,6 +142,9 @@ function auth_password_verify(request, password)
attributes["userdb_mail_crypt_global_private_key"] = data.body.mailCryptPrivateKey
attributes["userdb_mail_crypt_global_public_key"] = data.body.mailCryptPublicKey
end
if data.body.quota ~= "" then
attributes["userdb_quota_rule"] = data.body.quota
end
return dovecot.auth.PASSDB_RESULT_OK, attributes
end

Expand Down
11 changes: 10 additions & 1 deletion src/Controller/DovecotController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,13 @@ 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 +77,7 @@ public function lookup(
'mailCryptPublicKey' => $user->getMailCryptPublicKey() ?? "",
'gid' => $this->mailGid,
'uid' => $this->mailUid,
'quota' => $user->getQuota() ?? "",
'quota' => $customQuotaString,
]
], Response::HTTP_OK);
}
Expand Down Expand Up @@ -116,12 +121,16 @@ public function authenticate(
$mailCryptReported = 0;
}

$customQuota = $user->getQuota();
$customQuotaString = $customQuota !== null ? sprintf('*:storage=%dM', $customQuota) : "";

return $this->json([
'message' => self::MESSAGE_SUCCESS,
'body' => [
'mailCrypt' => $mailCryptReported,
'mailCryptPrivateKey' => $privateKey ?? "",
'mailCryptPublicKey' => $user->getMailCryptPublicKey() ?? "",
'quota' => $customQuotaString,
]
], Response::HTTP_OK);
}
Expand Down

0 comments on commit 2cccd8f

Please sign in to comment.