Add is_var_empty_silent for sensitives variables

This commit is contained in:
Jeremy Gardais 2021-11-19 14:48:41 +01:00
parent c9991761dc
commit 29e64cc35d
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 34 additions and 2 deletions

View File

@ -158,6 +158,31 @@ Test var: ${1}."
return "${return_var_empty}"
}
# }}}
is_var_empty_silent() { # {{{
## Return False by default
return_var_empty_silent="1"
## Total number of variables to test
local_total_var="${#}"
loop_count_var_empty_silent="0"
## While it remains a variable to test
while [ "${local_total_var}" -gt "${loop_count_var_empty_silent}" ]; do
### Test if this is empty and set return value to True
[ -z "${1}" ] && return_var_empty_silent="0"
### Increase the number of tested variables
loop_count_var_empty_silent=$((loop_count_var_empty_silent+1))
### Shift to the next variable
shift
done
return "${return_var_empty_silent}"
}
# }}}
main() { # {{{
@ -165,13 +190,20 @@ main() { # {{{
## Define all vars
define_vars
## If ldap_group_cn is empty
## If ldap_group_cn is empty {{{
### Print help message
### AND exit with message and error
is_var_empty "${ldap_group_cn}" \
&& usage \
&& error_message "Please enter a GROUP with -g|--group option." "1"
## }}}
## If ldap_user or ldap_passwd is empty {{{
### Print help message
### AND exit with message and error
is_var_empty_silent "${ldap_user}" "${ldap_passwd}" \
&& usage \
&& error_message "LDAP user or password is empty. Please verify your configuration or the --user-cmd|--passwd-cmd options." "2"
## }}}
## Information message
debug_message "Search for members in ${RED}${ldap_group_cn},${ldap_group_base}${COLOR_DEBUG} group \