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
# -

View File

@ -15,9 +15,10 @@ tmp_err_msg="$(mktemp)"
## --- Default Settings
## ---
DEFAULT_db_type="pgsql"^
DEFAULT_db_type="pgsql"
DEFAULT_db_name="postfix"
DEFAULT_quota="536870912"
DEFAULT_dovecot_enc_method="SHA512-CRYPT"
DEFAULT_in_file="${conf_dir}/mailboxes_new.lst"
DEFAULT_log_file="${script_dir}/log/postfix_add_mailboxes.log"
@ -134,6 +135,7 @@ fi
[[ -n "$quota" ]] || quota="$DEFAULT_quota"
[[ -n "$in_file" ]] || in_file="$DEFAULT_in_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
@ -146,6 +148,7 @@ echo -e "\033[32mSettings for script \033[37m\033[1msent_userinfo_postfix.sh\033
echo ""
echo " File containing the new mailboxes and passwords.......: $in_file"
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 ""
if [[ "$db_type" = "pgsql" ]] ; then
@ -336,17 +339,33 @@ while read email passwd ; do
echononl " Create entry in table \"mailbox\".."
if [[ "$db_type" = "pgsql" ]] ; then
su postgres -c"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', '$passwd','','${domain}/${user}/','$user','$quota','$domain',NOW(),NOW(),'t')\"" \
> $tmp_err_msg 2>&1
if [[ "$dovecot_enc_method" = "PLAIN" ]]; then
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', '$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
$(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', '$passwd','','${domain}/${user}/','$user','$quota','$domain',NOW(),NOW(),1)" \
> $tmp_err_msg 2>&1)
if [[ "$dovecot_enc_method" = "PLAIN" ]]; then
$(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', '$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
fatal "Database type '$db_type' is not supported."
fi
@ -362,10 +381,10 @@ while read email passwd ; do
echononl " Create entry in table \"alias\".."
if [[ "$db_type" = "pgsql" ]] ; then
su postgres -c "psql $db_name -c\"\
sudo -u postgres psql $db_name -c "\
SET client_encoding to 'UTF8'; \
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
$(mysql "$mysql_credential_args" "$db_name" -N -s -e"
SET NAMES utf8;