]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Applying shellcheck to functions.rc
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 9 Dec 2021 07:44:38 +0000 (08:44 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 9 Dec 2021 07:44:38 +0000 (08:44 +0100)
scripts/check-ldap-passwd

index b4633ade6a82dbe2f9c020be4c773b3768626e30..9cf2dde875977426de7d8f7b4fafc6208558a60c 100755 (executable)
@@ -3,14 +3,12 @@
 set -u
 set -e
 
-BASE_NAME="$( basename ${0} )"
-MY_REAL_NAME=$( readlink -f $0 )
+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 "${BIN_DIR}/functions.rc" ]] ; then
+    # shellcheck source=functions.rc
     . "${BIN_DIR}/functions.rc"
 else
     echo "Bash resource file '${BIN_DIR}/functions.rc' not found" >&2
@@ -55,12 +53,12 @@ usage() {
 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} \
+    tmp=$( getopt -o "${LDAP_STD_OPTS_SHORT}${STD_SHORT_OPTIONS}" \
+                    --long "${LDAP_STD_OPTS_LONG},${STD_LONG_OPTIONS}" \
                     -n "${BASE_NAME}" -- "$@" )
+    # shellcheck disable=SC2181
     if [[ $? != 0 ]] ; then
         echo "" >&2
         usage >&2
@@ -133,6 +131,7 @@ main() {
     local cmd="${cmd_base} \"${filter}\" userPassword 2>&1 | "
     cmd+=" grep -i '^userPassword:' | sed -e 's/^userPassword::[       ][      ]*//'"
     debug "Executing: ${cmd}"
+    # shellcheck disable=SC2086
     result=$( eval ${cmd} )
     debug "ldap_passwd_coded: '${CYAN}${result}${NORMAL}'."
 
@@ -143,30 +142,40 @@ main() {
         exit 1
     fi
 
-    local ldap_passwd_value=$( echo "${result}" | base64 -d )
+    local ldap_passwd_value
+    ldap_passwd_value=$( echo "${result}" | base64 -d )
     debug "ldap_passwd_value: '${CYAN}${ldap_passwd_value}${NORMAL}'."
 
-    local ldap_hash_method=$( echo "${ldap_passwd_value}" | \
+    local ldap_hash_method
+    ldap_hash_method=$( echo "${ldap_passwd_value}" | \
             sed -e 's/^{//' -e 's/}.*//' | \
             tr '[:upper:]' '[:lower:]' )
     debug "ldap_hash_method:  '${CYAN}${ldap_hash_method}${NORMAL}'."
 
     if [[ "${ldap_hash_method}" != 'crypt' ]] ; then
+        IFS="${oifs}"
         echo
         error "Unbekannte Hash-Methode '${RED}${ldap_hash_method}${NORMAL}'" >&2
         echo
         exit 5
     fi
 
-    local ldap_passwd_hash=$( echo "${ldap_passwd_value}" | sed -e 's/^{[^}]*}//' )
+    local ldap_passwd_hash
+    # shellcheck disable=SC2001
+    ldap_passwd_hash=$( echo "${ldap_passwd_value}" | sed -e 's/^{[^}]*}//' )
     debug "ldap_passwd_hash:  '${CYAN}${ldap_passwd_hash}${NORMAL}'."
 
-    local salt=$( echo "${ldap_passwd_hash}" | sed -e 's/^\(..\).*/\1/' )
+    local salt
+    # shellcheck disable=SC2001
+    salt=$( echo "${ldap_passwd_hash}" | sed -e 's/^\(..\).*/\1/' )
     debug "salt:              '${CYAN}${salt}${NORMAL}'."
 
-    local encr_passwd=$( mkpasswd -m des "${GIVEN_PASSWD}" "${salt}" )
+    local encr_passwd
+    encr_passwd=$( mkpasswd -m des "${GIVEN_PASSWD}" "${salt}" )
     debug "encr_passwd:       '${CYAN}${encr_passwd}${NORMAL}'."
 
+    IFS="${oifs}"
+
     echo
     if [[ "${ldap_passwd_hash}" == "${encr_passwd}" ]] ; then
         echo -e "Passwort ist ${GREEN}OKAY${NORMAL}."