From: Frank Brehm Date: Fri, 15 Oct 2021 08:49:11 +0000 (+0200) Subject: Adding bin/get-ldap-membership X-Git-Tag: 0.4.1~6^2~1 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=9dd4d3d0944deeabfdee500fa5174c7ebb93209a;p=pixelpark%2Fpp-admin-tools.git Adding bin/get-ldap-membership --- diff --git a/bin/get-ldap-membership b/bin/get-ldap-membership new file mode 100755 index 0000000..de6de3b --- /dev/null +++ b/bin/get-ldap-membership @@ -0,0 +1,125 @@ +#!/bin/bash + +set -e +set -u + +BASE_NAME="$( basename ${0} )" +MY_REAL_NAME=$( readlink -f $0 ) +BIN_DIR=$( dirname "${MY_REAL_NAME}" ) +BASE_DIR=$( dirname "${BIN_DIR}" ) +LIB_DIR="${BASE_DIR}/lib" +CONF_DIR="${BASE_DIR}/etc" + +if [[ -f "${LIB_DIR}/functions.rc" ]] ; then + . "${LIB_DIR}/functions.rc" +else + echo "Bash resource file '${LIB_DIR}/functions.rc' not found" >&2 + exit 5 +fi + +declare -a SEARCH_IDS=() + +detect_color + +DESCRIPTION=$( cat <<-EOF + Get all LDAP groups, where the user with the given DN uid or mail address is a member of. + + EOF +) + +#------------------------------------------------------------------------------ +get_options() { + + local tmp= + local base_dir= + + set +e + tmp=$( getopt -o ${LDAP_STD_OPTS_SHORT}${STD_SHORT_OPTIONS} \ + --long ${LDAP_STD_OPTS_LONG},${STD_LONG_OPTIONS} \ + -n "${BASE_NAME}" -- "$@" ) + if [[ $? != 0 ]] ; then + echo "" >&2 + usage >&2 + exit 1 + fi + set -e + + # Note the quotes around `$TEMP': they are essential! + eval set -- "${tmp}" + eval_common_options "$@" + if [[ "${DEBUG}" == 'y' ]] ; then + declare -p REMAINING_OPTS + declare -p REMAINING_ARGS + fi + + eval_ldap_options "${REMAINING_OPTS[@]}" "${REMAINING_ARGS[@]}" + + if [[ "${DEBUG}" == 'y' ]] ; then + declare -p REMAINING_OPTS + declare -p REMAINING_ARGS + fi + + if [[ "${#REMAINING_OPTS[@]}" -gt 0 ]] ; then + error "Unknown options: ${REMAINING_OPTS[*]}" + echo >&2 + usage >&2 + exit 2 + fi + + if [[ "${#REMAINING_ARGS[@]}" == "0" ]] ; then + error "No user given to retrieve." + echo >&2 + usage >&2 + exit 2 + fi + + local i=0 + local token= + for token in "${REMAINING_ARGS[@]}" ; do + if [[ "$i" == 0 ]]; then + i=1 + continue + fi + SEARCH_IDS+=(${token}) + i=$(( $i + 1 )) + done + + if [[ "${DEBUG}" == 'y' ]] ; then + declare -p SEARCH_IDS + fi + +} + +#------------------------------------------------------------------------------ +usage() { + cat <<-EOF + Usage: ${BASE_NAME} [Common Options] [LDAP Options] [ ...] + ${BASE_NAME} [-h|--help] + ${BASE_NAME} [-V|--version] + + Mandatory Parameter(s): + ID: The DN, UID or mail address of the user to search. + + LDAP Options: + EOF + + echo "${LDAP_USAGE_MSG}" + echo + echo " Common Options:" + echo "${STD_USAGE_MSG}" + +} + +#------------------------------------------------------------------------------ +main() { + + get_options "$@" + + +} + +main "$@" + +exit 0 + +# vim: et list