mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2026-11-20 23:43:26 +03:00
- harden the existing optional Maildir domain, mailbox creation/deletion and Dovecot mail-crypt hooks - validate hook argument contracts and keep all derived paths below their configured base directories - quote filesystem operations, check command failures and make deletion hooks safely retryable - update the Dovecot password example for the prompt behaviour available since Dovecot 2.3.19, with a Dovecot 2.4 setting note - add optional Rspamd DKIM creation/deletion helpers, a privilege-separated composite domain hook and deployment documentation These hooks remain optional and disabled by default. Administrators must review the configured paths and service-account names before installation. The mail-crypt password example now requires Dovecot 2.3.19 or newer; its comment identifies the setting name needed by Dovecot 2.4.
47 lines
1.8 KiB
Bash
47 lines
1.8 KiB
Bash
#!/bin/bash
|
|
|
|
# Example script for Dovecot's mail-crypt plugin.
|
|
# Requires Dovecot 2.3.19 or newer for the -O/-N prompt behaviour.
|
|
# https://doc.dovecot.org/2.3/configuration_manual/mail_crypt_plugin/
|
|
|
|
# Dovecot 2.3 setting name. For Dovecot 2.4, use:
|
|
# private_password_setting=crypt_user_key_password
|
|
private_password_setting=plugin/mail_crypt_private_password
|
|
|
|
fail()
|
|
{
|
|
printf '%s\n' "$0: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
[[ $# -eq 2 ]] || fail "expected username and domain arguments"
|
|
username=$1
|
|
domain=$2
|
|
[[ -n $username && -n $domain && $username == *@"$domain" ]] || fail "invalid username or domain"
|
|
|
|
IFS= read -r -d '' old_password || fail "could not read the NUL-terminated old password"
|
|
IFS= read -r -d '' new_password || fail "could not read the NUL-terminated new password"
|
|
[[ -n $new_password ]] || fail "new password must not be empty"
|
|
|
|
openssl_path=$(command -v openssl 2>/dev/null) || fail "could not find openssl in PATH"
|
|
doveadm_path=$(command -v doveadm 2>/dev/null) || fail "could not find doveadm in PATH"
|
|
|
|
if [[ -z $old_password ]]; then
|
|
old_password=$("$openssl_path" rand -hex 16) || fail "could not generate a temporary password"
|
|
[[ -n $old_password ]] || fail "openssl returned an empty temporary password"
|
|
|
|
if ! "$doveadm_path" -o "$private_password_setting=$old_password" \
|
|
mailbox cryptokey generate -u "$username" -U; then
|
|
fail "could not generate the mailbox cryptokey"
|
|
fi
|
|
fi
|
|
|
|
# Since Dovecot 2.3.19, -O asks for the old password and -N asks for the new
|
|
# password twice. Keep passwords on stdin instead of command-line arguments.
|
|
if ! printf '%s\n%s\n%s\n' "$old_password" "$new_password" "$new_password" | \
|
|
"$doveadm_path" mailbox cryptokey password -u "$username" -O -N; then
|
|
fail "could not update the mailbox cryptokey password"
|
|
fi
|
|
|
|
exit 0
|