local base_cmd="ldapsearch -x -LLL -o ldif-wrap=no -H \"${LDAP_SERVER}\""
base_cmd+=" -D \"${LDAP_BIND_DN}\" -y \"${LDAP_PWD_FILE}\""
- cmd="${base_cmd} -b \"${LDAP_BASE_DN}\" \"uid=${USER}\" dn | sed -e 's/^dn:[ ][ ]*//i'"
+
+ local cmd="${base_cmd} -b \"${LDAP_BASE_DN}\" \"uid=${USER}\" dn | sed -e 's/^dn:[ ][ ]*//i'"
echo "${cmd}" >&2
local user_dn=$( eval $cmd )
echo "Fand DN '${user_dn}'." >&2
echo >&2
+
cmd="${base_cmd} -b \"${user_dn}\" \"objectclass=*\" mailSieveRuleSource |"
cmd+=" grep -v '^dn:' | sed -e 's/^mailSieveRuleSource::*[ ]*//i' -e 's/[ ]//g' -e 's/=//g' |"
cmd+="tr -d '[:cntrl:]'"
LDAP_SERVER='ldap://ldap.pixelpark.com'
LDAP_BIND_DN='cn=admin'
-LDAP_BIND_PW='3o.o0dlt'
LDAP_BASE_DN='o=isp'
+LDAP_PWD_FILE="${HOME}/.private/ldap-admin-wonl.txt"
USER="frank.brehm"
SIEVE_FILE=""
+LDIF_FILE=
#-------------------------------------------------------------------
detect_color() {
info "Simulation mode, nothing is really done."
fi
+ if [[ ! -f "${LDAP_PWD_FILE}" ]] ; then
+ error "Password file '${LDAP_PWD_FILE}' not found" >&2
+ exit 3
+ fi
+
+ if [[ ! -r "${LDAP_PWD_FILE}" ]] ; then
+ error "Password file '${LDAP_PWD_FILE}' not readable" >&2
+ exit 3
+ fi
+
if [[ ! -f "${SIEVE_FILE}" ]] ; then
error "Sieve file '${SIEVE_FILE}' existiert nicht." >&2
echo >&2
fi
SIEVE_FILE=$( readlink -f "${SIEVE_FILE}" )
- info "Suche DN für User '${USER}' ..."
+ local base_cmd="ldapsearch -x -LLL -o ldif-wrap=no -H \"${LDAP_SERVER}\""
+ base_cmd+=" -D \"${LDAP_BIND_DN}\" -y \"${LDAP_PWD_FILE}\""
- USER_DN=$( ldapsearch -LLL \
- -H "${LDAP_SERVER}" \
- -b "${LDAP_BASE_DN}" \
- -x -D "${LDAP_BIND_DN}" -w "${LDAP_BIND_PW}" \
- "uid=${USER}" \
- dn | sed -e 's/^dn:[ ][ ]*//i' )
+ info "Suche DN für User '${USER}' ..."
- if [[ -z "${USER_DN}" ]] ; then
+ local cmd="${base_cmd} -b \"${LDAP_BASE_DN}\" \"uid=${USER}\" dn | sed -e 's/^dn:[ ][ ]*//i'"
+ info "Ausführen:"
+ echo "${cmd}"
+ local user_dn=$( eval $cmd )
+ if [[ -z "${user_dn}" ]] ; then
error "User '${USER}' nicht im LDAP gefunden." >&2
echo >&2
exit 1
fi
+ info "Fand DN '${GREEN}${user_dn}${NORMAL}'."
+
LDIF_FILE=$( mktemp modify-sieve-XXXXXXXX.ldif )
trap cleanup_tmp_file INT TERM EXIT ABRT
cat > "${LDIF_FILE}" <<-EOF
- dn: ${USER_DN}
+ dn: ${user_dn}
changetype: modify
EOF
- echo
- info "Fand DN '${USER_DN}'."
- echo
info "Suche existierenden Sieve Eintrag ..."
echo
- CUR_SIEVE64=$( ldapsearch -LLL \
- -H "${LDAP_SERVER}" \
- -b "${USER_DN}" \
- -x -D "${LDAP_BIND_DN}" -w "${LDAP_BIND_PW}" \
- "objectclass=*" mailSieveRuleSource | \
- grep -i '^mailSieveRuleSource:' || true )
+ cmd="${base_cmd} -b \"${user_dn}\" \"objectclass=*\" mailSieveRuleSource |"
+ cmd+=" grep -i '^mailSieveRuleSource:' || true"
+ info "Ausführen:"
+ echo "${cmd}"
+ local cur_sieve64=$( eval $cmd )
- if [[ -z "${CUR_SIEVE64}" ]] ; then
+ if [[ -z "${cur_sieve64}" ]] ; then
info "Füge Attribut mailSieveRuleSource hinzu ..."
cat >> "${LDIF_FILE}" <<-EOF
add: mailSieveRuleSource
echo
cat "${LDIF_FILE}"
- CMD="ldapmodify -H \"${LDAP_SERVER}\""
- CMD+=" -x -D \"${LDAP_BIND_DN}\" -w \"${LDAP_BIND_PW}\""
- CMD+=" -f \"$( readlink -f "${LDIF_FILE}" )\""
+ cmd="ldapmodify -H \"${LDAP_SERVER}\" -x -D \"${LDAP_BIND_DN}\" -y \"${LDAP_PWD_FILE}\""
+ cmd+=" -f \"$( readlink -f "${LDIF_FILE}" )\""
+
+ #CMD="ldapmodify -H \"${LDAP_SERVER}\""
+ #CMD+=" -x -D \"${LDAP_BIND_DN}\" -w \"${LDAP_BIND_PW}\""
+ #CMD+=" -f \"$( readlink -f "${LDIF_FILE}" )\""
echo
info "Ausführen:"
- echo "${CMD}"
+ echo "${cmd}"
echo
if [[ "${SIMULATE}" != "y" ]] ; then
- eval ${CMD}
+ eval ${cmd}
echo
fi