]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Fixing Setting of mailUserStatus in scripts/disabling-ldap-user
authorFrank Brehm <frank@brehm-online.com>
Thu, 10 Mar 2022 11:01:05 +0000 (12:01 +0100)
committerFrank Brehm <frank@brehm-online.com>
Thu, 10 Mar 2022 11:01:05 +0000 (12:01 +0100)
scripts/disabling-ldap-user

index b937d6820d0f8490bf4916f0b3dc6fccf397bc83..2b174d60c7d0d45b725d07e309d20e686ba5c294 100755 (executable)
@@ -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}"