From: Frank Brehm Date: Thu, 10 Mar 2022 11:01:05 +0000 (+0100) Subject: Fixing Setting of mailUserStatus in scripts/disabling-ldap-user X-Git-Tag: 0.4.1^2~48 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=86754ac39b6f61c0a8cc1a2431ae513314be4cbc;p=pixelpark%2Fpp-admin-tools.git Fixing Setting of mailUserStatus in scripts/disabling-ldap-user --- diff --git a/scripts/disabling-ldap-user b/scripts/disabling-ldap-user index b937d68..2b174d6 100755 --- a/scripts/disabling-ldap-user +++ b/scripts/disabling-ldap-user @@ -9,7 +9,7 @@ QUIET='n' SIMULATE='n' YES="n" -VERSION="1.2" +VERSION="1.3" # console colors: RED="" @@ -577,18 +577,35 @@ setting_user_status() { info "Setting UserStatus of '${CYAN}${USER_NAME}${NORMAL}' to '${CYAN}inactive${NORMAL}' ..." + debug "Trying to evaluate, whether '${CYAN}${USER_NAME}${NORMAL}' is a mail user ..." + local is_mail_user="n" + + cmd="ldapsearch -x -LLL -o ldif-wrap=no -H '${LDAP_URL}' " + cmd+="-b \"${USER_DN}\" -x -D \"${BIND_DN}\" -y \"${BIND_PW_FILE}\" -s base objectClass | " + cmd+="grep -i '^objectClass:' | grep -q -i -w 'inetMailUser'" + debug "Executing: ${cmd}" + if $( eval ${cmd} ) ; then + is_mail_user="y" + debug "User '${CYAN}${USER_NAME}${NORMAL}' is an inetMailUser." + else + debug "User '${CYAN}${USER_NAME}${NORMAL}' is ${CYAN}not${NORMAL} an inetMailUser." + fi + cat > "${LDIF_FILE}" <<-EOF dn: ${USER_DN} changetype: modify replace: inetUserStatus inetUserStatus: inactive - - replace: mailUserStatus - mailUserStatus: inactive - - - EOF + if [[ "${is_mail_user}" == "y" ]] ; then + echo "replace: mailUserStatus" >> "${LDIF_FILE}" + echo "mailUserStatus: inactive" >> "${LDIF_FILE}" + echo "-" >> "${LDIF_FILE}" + fi + echo >> "${LDIF_FILE}" + if [[ "${VERBOSE}" == "y" ]] ; then debug "Resulting LDIF:" cat "${LDIF_FILE}"