From: Frank Brehm Date: Thu, 9 Dec 2021 07:44:38 +0000 (+0100) Subject: Applying shellcheck to functions.rc X-Git-Tag: 0.4.1~4^2~46 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=4275544383a629463872a978e0021e5b6ed31c51;p=pixelpark%2Fpp-admin-tools.git Applying shellcheck to functions.rc --- diff --git a/scripts/check-ldap-passwd b/scripts/check-ldap-passwd index b4633ad..9cf2dde 100755 --- a/scripts/check-ldap-passwd +++ b/scripts/check-ldap-passwd @@ -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}."