}
+#------------------------------------------------------------------------------
+get_dn() {
+
+ local user_id="$1"
+ local dn=
+
+ local ldap_filter_oclass="(|"
+ local oclass=
+ local line=
+
+ for oclass in inetLocalMailRecipient inetMailingListUser inetOrgPerson \
+ inetResource mailGroupMember mailRecipient; do
+ ldap_filter_oclass+="(objectClass=${oclass})"
+ done
+ ldap_filter_oclass+=")"
+
+ local filter="(&${ldap_filter_oclass}(|(mail=${user_id})(mailAlternateAddress=${user_id})"
+ filter+="(mailEquivalentAddress=${user_id})(uid=${user_id})))"
+
+ info "Getting DN of LDAP-Object with E-Mail address or UID '${CYAN}${user_id}${NORMAL}' ..."
+
+ cmd="ldapsearch -LLL -o ldif-wrap=no -h \"${LDAP_HOST}\" -p ${LDAP_PORT} -b \"${LDAP_BASE}\""
+ cmd+=" -x -D \"${LDAP_USR}\" -y \"${LDAP_PWD_FILE}\" \"${filter}\" dn"
+ debug "Executing: ${cmd}"
+ for line in $( eval ${cmd} | grep -i '^dn:' | sed -e 's/^dn:[ ]*//i' ) ; do
+ echo "${line}"
+ done
+
+}
+
+#------------------------------------------------------------------------------
+search_memberships() {
+
+ local dn="$1"
+
+ info "Searching for groups with member '${CYAN}${dn}${NORMAL}' ..."
+ local ldap_filter_oclass="(|"
+ local oclass=
+
+ for oclass in groupOfNames groupOfUniqueNames; do
+ ldap_filter_oclass+="(objectClass=${oclass})"
+ done
+ ldap_filter_oclass+=")"
+
+ local filter="(&${ldap_filter_oclass}(|(uniqueMember=${dn})(member=${dn})))"
+ cmd="ldapsearch -LLL -o ldif-wrap=no -h \"${LDAP_HOST}\" -p ${LDAP_PORT} -b \"${LDAP_BASE}\""
+ cmd+=" -x -D \"${LDAP_USR}\" -y \"${LDAP_PWD_FILE}\" \"${filter}\""
+ cmd+=" dn cn description mail mailAlternateAddress mailEquivalentAddress"
+ debug "Executing: ${cmd}"
+ eval ${cmd}
+}
+
+#------------------------------------------------------------------------------
+search_user() {
+
+ local user_id="$1"
+ local dn=
+
+ local oifs="${IFS}"
+ IFS="
+"
+
+ echo
+ if echo "${user_id}" | grep -q -i "${LDAP_BASE}\$" ; then
+ dn="${user_id}"
+ info "Searching for user with DN '${CYAN}${dn}${NORMAL}' ..."
+ search_memberships "${dn}"
+ else
+ for dn in $( get_dn "${user_id}" ); do
+ info "Searching for user '${CYAN}${user_id}${NORMAL}' with DN '${CYAN}${dn}${NORMAL}' ..."
+ search_memberships "${dn}"
+ done
+ fi
+
+ IFS="${oifs}"
+
+}
+
#------------------------------------------------------------------------------
main() {
get_options "$@"
+ local id
+ for id in "${SEARCH_IDS[@]}" ; do
+ search_user "${id}"
+ done
}