mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2025-08-03 09:34:33 +02:00
Fix ldap related critical Problems (#644)
* Fix Dovecot Ldap Problems * Fix typo within DEFAULT_VARS Definitions * Fix wrong ldap hosts value within the bats test * Fix override_config for strings containing & * Fix erroneous removal of an conditional within the postfix override function * Renamed Test 129, to be clear that this belongs to ldap * Fix mail_with_ldap setting dn pass explicit * Add 3 env variables for ldap: LDAP_QUERY_FILTER_{USER,GROUP,ALIAS} * Update README.md
This commit is contained in:
parent
1effcdebd7
commit
21fb3f3c86
4 changed files with 190 additions and 80 deletions
|
@ -317,47 +317,47 @@ function display_startup_daemon() {
|
|||
}
|
||||
|
||||
function override_config() {
|
||||
notify "task" "Starting do do overrides"
|
||||
notify "task" "Starting do do overrides"
|
||||
|
||||
declare -A config_overrides
|
||||
declare -A config_overrides
|
||||
|
||||
_env_variable_prefix=$1
|
||||
[ -z ${_env_variable_prefix} ] && return 1
|
||||
_env_variable_prefix=$1
|
||||
[ -z ${_env_variable_prefix} ] && return 1
|
||||
|
||||
|
||||
IFS=" " read -r -a _config_files <<< $2
|
||||
|
||||
# dispatch env variables
|
||||
for env_variable in $(printenv | grep $_env_variable_prefix);do
|
||||
# get key
|
||||
# IFS not working because values like ldap_query_filter or search base consists of several '='
|
||||
# IFS="=" read -r -a __values <<< $env_variable
|
||||
# key="${__values[0]}"
|
||||
# value="${__values[1]}"
|
||||
key=$(echo $env_variable | cut -d "=" -f1)
|
||||
key=${key#"${_env_variable_prefix}"}
|
||||
# make key lowercase
|
||||
key=${key,,}
|
||||
# get value
|
||||
value=$(echo $env_variable | cut -d "=" -f2-)
|
||||
IFS=" " read -r -a _config_files <<< $2
|
||||
|
||||
config_overrides[$key]=$value
|
||||
done
|
||||
# dispatch env variables
|
||||
for env_variable in $(printenv | grep $_env_variable_prefix);do
|
||||
# get key
|
||||
# IFS not working because values like ldap_query_filter or search base consists of several '='
|
||||
# IFS="=" read -r -a __values <<< $env_variable
|
||||
# key="${__values[0]}"
|
||||
# value="${__values[1]}"
|
||||
key=$(echo $env_variable | cut -d "=" -f1)
|
||||
key=${key#"${_env_variable_prefix}"}
|
||||
# make key lowercase
|
||||
key=${key,,}
|
||||
# get value
|
||||
value=$(echo $env_variable | cut -d "=" -f2-)
|
||||
|
||||
for f in "${_config_files[@]}"
|
||||
do
|
||||
if [ ! -f "${f}" ];then
|
||||
echo "Can not find ${f}. Skipping override"
|
||||
else
|
||||
for key in ${!config_overrides[@]}
|
||||
do
|
||||
[ -z $key ] && echo -e "\t no key provided" && return 1
|
||||
|
||||
sed -i -e "s|^${key}[[:space:]]\+.*|${key} = "${config_overrides[$key]}'|g' \
|
||||
${f}
|
||||
done
|
||||
fi
|
||||
done
|
||||
config_overrides[$key]=$value
|
||||
done
|
||||
|
||||
for f in "${_config_files[@]}"
|
||||
do
|
||||
if [ ! -f "${f}" ];then
|
||||
echo "Can not find ${f}. Skipping override"
|
||||
else
|
||||
for key in ${!config_overrides[@]}
|
||||
do
|
||||
[ -z $key ] && echo -e "\t no key provided" && return 1
|
||||
|
||||
sed -i -e "s|^${key}[[:space:]]\+.*|${key} = ${config_overrides[$key]//&/\\&}|g" \
|
||||
${f}
|
||||
done
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
@ -569,21 +569,37 @@ function _setup_ldap() {
|
|||
for i in 'users' 'groups' 'aliases'; do
|
||||
fpath="/tmp/docker-mailserver/ldap-${i}.cf"
|
||||
if [ -f $fpath ]; then
|
||||
cp ${fpath} /etc/postfix/ldap-${i}.cf
|
||||
cp ${fpath} /etc/postfix/ldap-${i}.cf
|
||||
fi
|
||||
done
|
||||
|
||||
notify 'inf' 'Starting to override configs'
|
||||
override_config "LDAP_" "/etc/postfix/ldap-users.cf /etc/postfix/ldap-groups.cf /etc/postfix/ldap-aliases.cf"
|
||||
for f in /etc/postfix/ldap-users.cf /etc/postfix/ldap-groups.cf /etc/postfix/ldap-aliases.cf
|
||||
do
|
||||
[[ $f =~ ldap-user ]] && export LDAP_QUERY_FILTER="${LDAP_QUERY_FILTER_USER}"
|
||||
[[ $f =~ ldap-group ]] && export LDAP_QUERY_FILTER="${LDAP_QUERY_FILTER_GROUP}"
|
||||
[[ $f =~ ldap-aliases ]] && export LDAP_QUERY_FILTER="${LDAP_QUERY_FILTER_ALIAS}"
|
||||
override_config "LDAP_" "${f}"
|
||||
done
|
||||
|
||||
notify 'inf' "Configuring dovecot LDAP"
|
||||
|
||||
declare -A _dovecot_ldap_mapping
|
||||
|
||||
_dovecot_ldap_mapping["DOVECOT_BASE"]="${DOVECOT_BASE:="${LDAP_SEARCH_BASE}"}"
|
||||
_dovecot_ldap_mapping["DOVECOT_DN"]="${DOVECOT_DN:="${LDAP_BIND_DN}"}"
|
||||
_dovecot_ldap_mapping["DOVECOT_DNPASS"]="${DOVECOT_DNPASS:="${LDAP_BIND_PW}"}"
|
||||
_dovecot_ldap_mapping["DOVECOT_HOSTS"]="${DOVECOT_HOSTS:="${LDAP_SERVER_HOST}"}"
|
||||
# Not sure whether this can be the same or not
|
||||
# _dovecot_ldap_mapping["DOVECOT_PASS_FILTER"]="${DOVECOT_PASS_FILTER:="${LDAP_QUERY_FILTER_USER}"}"
|
||||
# _dovecot_ldap_mapping["DOVECOT_USER_FILTER"]="${DOVECOT_USER_FILTER:="${LDAP_QUERY_FILTER_USER}"}"
|
||||
|
||||
for var in ${!_dovecot_ldap_mapping[@]}; do
|
||||
export $var=${_dovecot_ldap_mapping[$var]}
|
||||
done
|
||||
|
||||
override_config "DOVECOT_" "/etc/dovecot/dovecot-ldap.conf.ext"
|
||||
|
||||
# @TODO: Environment Variables for DOVECOT ldap integration to configure for better control
|
||||
notify 'inf' "Configuring dovecot LDAP authentification"
|
||||
sed -i -e 's|^hosts.*|hosts = '${LDAP_SERVER_HOST:="mail.domain.com"}'|g' \
|
||||
-e 's|^base.*|base = '${LDAP_SEARCH_BASE:="ou=people,dc=domain,dc=com"}'|g' \
|
||||
-e 's|^dn\s*=.*|dn = '${LDAP_BIND_DN:="cn=admin,dc=domain,dc=com"}'|g' \
|
||||
-e 's|^dnpass\s*=.*|dnpass = '${LDAP_BIND_PW:="admin"}'|g' \
|
||||
/etc/dovecot/dovecot-ldap.conf.ext
|
||||
|
||||
# Add domainname to vhost.
|
||||
echo $DOMAINNAME >> /tmp/vhost.tmp
|
||||
|
||||
|
@ -629,7 +645,7 @@ EOF
|
|||
# cyrus sasl or dovecot sasl
|
||||
if [[ ${ENABLE_SASLAUTHD} == 1 ]] || [[ ${SMTP_ONLY} == 0 ]];then
|
||||
sed -i -e 's|^smtpd_sasl_auth_enable[[:space:]]\+.*|smtpd_sasl_auth_enable = yes|g' /etc/postfix/main.cf
|
||||
else
|
||||
else
|
||||
sed -i -e 's|^smtpd_sasl_auth_enable[[:space:]]\+.*|smtpd_sasl_auth_enable = no|g' /etc/postfix/main.cf
|
||||
fi
|
||||
|
||||
|
@ -667,7 +683,7 @@ EOF
|
|||
sed -i \
|
||||
-e "/^[^#].*smtpd_sasl_type.*/s/^/#/g" \
|
||||
-e "/^[^#].*smtpd_sasl_path.*/s/^/#/g" \
|
||||
etc/postfix/master.cf
|
||||
/etc/postfix/master.cf
|
||||
|
||||
sed -i \
|
||||
-e "s|^START=.*|START=yes|g" \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue