Support for (dovecot) encrypted passwordhashes integrated.

This commit is contained in:
Christoph 2017-11-02 15:46:46 +01:00
parent c8de12dd2a
commit 01bde06869
2 changed files with 44 additions and 13 deletions

View File

@ -4,6 +4,18 @@
# --- # ---
# ---------------------------------------------------- # ----------------------------------------------------
# - dovecot_enc_method
# -
# - The (dovecot) password scheme which should be used to generate the hashed
# - passwords of EXISTING users.
# -
# - Possible values are:
# -
# - See output of 'doveadm pw -l'
# -
# - DEFAULTS to: dovecot_enc_method="SHA512-CRYPT"
# -
#dovecot_enc_method="SHA512-CRYPT"
# - in_file # - in_file
# - # -

View File

@ -15,9 +15,10 @@ tmp_err_msg="$(mktemp)"
## --- Default Settings ## --- Default Settings
## --- ## ---
DEFAULT_db_type="pgsql"^ DEFAULT_db_type="pgsql"
DEFAULT_db_name="postfix" DEFAULT_db_name="postfix"
DEFAULT_quota="536870912" DEFAULT_quota="536870912"
DEFAULT_dovecot_enc_method="SHA512-CRYPT"
DEFAULT_in_file="${conf_dir}/mailboxes_new.lst" DEFAULT_in_file="${conf_dir}/mailboxes_new.lst"
DEFAULT_log_file="${script_dir}/log/postfix_add_mailboxes.log" DEFAULT_log_file="${script_dir}/log/postfix_add_mailboxes.log"
@ -134,6 +135,7 @@ fi
[[ -n "$quota" ]] || quota="$DEFAULT_quota" [[ -n "$quota" ]] || quota="$DEFAULT_quota"
[[ -n "$in_file" ]] || in_file="$DEFAULT_in_file" [[ -n "$in_file" ]] || in_file="$DEFAULT_in_file"
[[ -n "$log_file" ]] || log_file="$DEFAULT_log_file" [[ -n "$log_file" ]] || log_file="$DEFAULT_log_file"
[[ -n "$dovecot_enc_method" ]] || dovecot_enc_method="$DEFAULT_dovecot_enc_method"
if [[ ! -f "$in_file" ]];then if [[ ! -f "$in_file" ]];then
@ -146,6 +148,7 @@ echo -e "\033[32mSettings for script \033[37m\033[1msent_userinfo_postfix.sh\033
echo "" echo ""
echo " File containing the new mailboxes and passwords.......: $in_file" echo " File containing the new mailboxes and passwords.......: $in_file"
echo "" echo ""
echo " Passsword scheme used for encryption..................: $dovecot_enc_method"
echo " Mailbox quota to set for each new mailbox.............: $quota ($(echo "scale=2; 536870912 / 1024 /1024" | bc) MB)" echo " Mailbox quota to set for each new mailbox.............: $quota ($(echo "scale=2; 536870912 / 1024 /1024" | bc) MB)"
echo "" echo ""
if [[ "$db_type" = "pgsql" ]] ; then if [[ "$db_type" = "pgsql" ]] ; then
@ -336,17 +339,33 @@ while read email passwd ; do
echononl " Create entry in table \"mailbox\".." echononl " Create entry in table \"mailbox\".."
if [[ "$db_type" = "pgsql" ]] ; then if [[ "$db_type" = "pgsql" ]] ; then
su postgres -c"psql $db_name -c\"\ if [[ "$dovecot_enc_method" = "PLAIN" ]]; then
SET client_encoding to 'UTF8'; \ sudo -u postgres psql $db_name -c "\
INSERT INTO mailbox (username,password,name,maildir,local_part,quota,domain,created,modified,active) \ SET client_encoding to 'UTF8'; \
VALUES ('${user}@$domain', '$passwd','','${domain}/${user}/','$user','$quota','$domain',NOW(),NOW(),'t')\"" \ INSERT INTO mailbox (username,password,name,maildir,local_part,quota,domain,created,modified,active) \
> $tmp_err_msg 2>&1 VALUES ('${user}@$domain', '$passwd','','${domain}/${user}/','$user','$quota','$domain',NOW(),NOW(),'t')" \
> $tmp_err_msg 2>&1
else
sudo -u postgres psql $db_name -c "\
SET client_encoding to 'UTF8'; \
INSERT INTO mailbox (username,password,name,maildir,local_part,quota,domain,created,modified,active) \
VALUES ('${user}@$domain', '$(doveadm pw -s "$dovecot_enc_method" -p "$passwd")','','${domain}/${user}/','$user','$quota','$domain',NOW(),NOW(),'t')" \
> $tmp_err_msg 2>&1
fi
elif [[ "$db_type" = "mysql" ]] ; then elif [[ "$db_type" = "mysql" ]] ; then
$(mysql "$mysql_credential_args" "$db_name" -N -s -e" if [[ "$dovecot_enc_method" = "PLAIN" ]]; then
SET NAMES utf8; $(mysql "$mysql_credential_args" "$db_name" -N -s -e"
INSERT INTO mailbox (username,password,name,maildir,local_part,quota,domain,created,modified,active) SET NAMES utf8;
VALUES ('${user}@$domain', '$passwd','','${domain}/${user}/','$user','$quota','$domain',NOW(),NOW(),1)" \ INSERT INTO mailbox (username,password,name,maildir,local_part,quota,domain,created,modified,active)
> $tmp_err_msg 2>&1) VALUES ('${user}@$domain', '$passwd','','${domain}/${user}/','$user','$quota','$domain',NOW(),NOW(),1)" \
> $tmp_err_msg 2>&1)
else
$(mysql "$mysql_credential_args" "$db_name" -N -s -e"
SET NAMES utf8;
INSERT INTO mailbox (username,password,name,maildir,local_part,quota,domain,created,modified,active)
VALUES ('${user}@$domain', '$(doveadm pw -s "$dovecot_enc_method" -p "$passwd")','','${domain}/${user}/','$user','$quota','$domain',NOW(),NOW(),1)" \
> $tmp_err_msg 2>&1)
fi
else else
fatal "Database type '$db_type' is not supported." fatal "Database type '$db_type' is not supported."
fi fi
@ -362,10 +381,10 @@ while read email passwd ; do
echononl " Create entry in table \"alias\".." echononl " Create entry in table \"alias\".."
if [[ "$db_type" = "pgsql" ]] ; then if [[ "$db_type" = "pgsql" ]] ; then
su postgres -c "psql $db_name -c\"\ sudo -u postgres psql $db_name -c "\
SET client_encoding to 'UTF8'; \ SET client_encoding to 'UTF8'; \
INSERT INTO alias (address,goto,domain,created,modified) \ INSERT INTO alias (address,goto,domain,created,modified) \
VALUES ('${user}@$domain','${user}@$domain','$domain',NOW(),NOW())\"" > $tmp_err_msg 2>&1 VALUES ('${user}@$domain','${user}@$domain','$domain',NOW(),NOW())" > $tmp_err_msg 2>&1
elif [[ "$db_type" = "mysql" ]] ; then elif [[ "$db_type" = "mysql" ]] ; then
$(mysql "$mysql_credential_args" "$db_name" -N -s -e" $(mysql "$mysql_credential_args" "$db_name" -N -s -e"
SET NAMES utf8; SET NAMES utf8;