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="${1:-frank.brehm}"
-echo "Suche DN für User '${USER}' ..." >&2
-
-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' )
-echo "Fand DN '${USER_DN}'." >&2
-echo >&2
-
-SIEVE64=$( ldapsearch -LLL \
- -H "${LDAP_SERVER}" \
- -b "${USER_DN}" \
- -x -D "${LDAP_BIND_DN}" -w "${LDAP_BIND_PW}" \
- "objectclass=*" mailSieveRuleSource | \
- grep -v '^dn:' | \
- sed -e 's/^mailSieveRuleSource::*[ ]*//i' \
- -e 's/[ ]//g' \
- -e 's/=//g' | \
- tr -d '[:cntrl:]' )
-
-printf "${SIEVE64}==" | base64 --decode --ignore-garbage
-
+if [[ ! -f "${LDAP_PWD_FILE}" ]] ; then
+ echo "Password file '${LDAP_PWD_FILE}' not found" >&2
+ exit 3
+fi
+
+if [[ ! -r "${LDAP_PWD_FILE}" ]] ; then
+ echo "Password file '${LDAP_PWD_FILE}' not readable" >&2
+ exit 3
+fi
+
+main() {
+
+ echo "Suche DN für User '${USER}' ..." >&2
+
+ 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'"
+ 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:]'"
+ echo "${cmd}" >&2
+ echo >&2
+ local sieve64=$( eval $cmd )
+ # echo "${sieve64}" >&2
+ printf "${sieve64}==" | base64 --decode --ignore-garbage
+
+}
+
+main "$@"
# vim: ts=4 list