]> Frank Brehm's Git Trees - pixelpark/ldap-migration.git/commitdiff
Start setting all user password to their pendant in Spk LDAP
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 2 Nov 2021 08:57:03 +0000 (09:57 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 2 Nov 2021 08:57:03 +0000 (09:57 +0100)
after-migration.sh

index d77e4836f88ac3e5de6979d20feb1e7b467e168e..698198252e7e72b106b81d37742a3ce8da2a3ba2 100755 (executable)
@@ -385,6 +385,70 @@ update_passwd_fbrehm() {
 
 }
 
+#------------------------------------------------
+update_passwords() {
+
+    empty_line
+    draw_line
+    info "Setting all user passwords ..."
+
+    local password_file="password-hashes.txt"
+    if [[ ! -f "${password_file}" ]] ; then
+        error "Password Hash file '${RED}${password_file}${NORMAL}' not found."
+        exit 8
+    fi
+
+    local -a uids=()
+    local -A password_hashes=()
+    local line=
+    local uid=
+    local password_hash=
+    local password_hash_shorten=
+    local len_pwh=
+    local len_pwhs=
+    local oifs="${IFS}"
+    IFS="
+"
+    debug "Reading password hash file '${CYAN}${password_file}${NORMAL}' ..."
+    for line in $( cat "${password_file}" ) ; do
+        if echo "${line}" | grep -q -P '^\s*(#|$)' ; then
+            continue
+        fi
+        uid=$( echo "${line}" | awk '{print $1}' )
+        password_hash=$( echo "${line}" | awk '{print $2}' )
+        if [[ -z "${uid}" || -z "${password_hash}" ]] ; then
+            warn "Invalid line '${YELLOW}${line}${NORMAL}' found in '${CYAN}${password_file}${NORMAL}'."
+            continue
+        fi
+        uids+=( "${uid}" )
+        password_hashes[${uid}]="${password_hash}"
+    done
+
+    if [[ "${VERBOSE}" == "y" ]] ; then
+        echo
+        echo -e "${CYAN}Password hashes:${NORMAL}"
+        local max_len_uid=1
+        for uid in "${!password_hashes[@]}" ; do
+            local len_uid=$( printf "${uid}" | wc -c )
+            if [[ "${len_uid}" -gt "${max_len_uid}" ]] ; then
+                max_len_uid="${len_uid}"
+            fi
+        done
+        max_len_uid=$(( max_len_uid + 1 ))
+        for uid in "${uids[@]}" ; do
+            password_hash=$( echo "${password_hashes[${uid}]}" )
+            len_pwh=$( printf "${password_hash}" | wc -c )
+            password_hash_shorten=$( echo "${password_hash}" | cut -c 1-50 )
+            len_pwhs=$( printf "${password_hash_shorten}" | wc -c )
+            if [[ "${len_pwh}" -gt "${len_pwhs}" ]] ; then
+                password_hash_shorten="${password_hash_shorten}..."
+            fi
+            printf "%-*s  %s\n" "${max_len_uid}" "${uid}:" "${password_hash_shorten}"
+        done
+    fi
+
+}
+
 #------------------------------------------------
 update_mailhost() {
 
@@ -471,8 +535,9 @@ main() {
 
     trap cleanup_tmp_file INT TERM EXIT ABRT
 
-    update_passwd_fbrehm
-    update_all_mailhosts
+    # update_passwd_fbrehm
+    update_passwords
+    # update_all_mailhosts
 
 
 }