Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions checkLdapPwdExpiration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ MY_MAIL_BIN="mail"
# Log header format
# Could include unix commands
#
MY_LOG_HEADER="$(date +\"%b %e %T\") $(hostname) $0[$$]:"
MY_LOG_HEADER="$(date +"%b %e %T") $(hostname) $0[$$]:"

#
# Path to GAWK (GNU awk) binary
Expand Down Expand Up @@ -261,7 +261,7 @@ if [ "${MY_LDAP_ROOTDN}" ]; then
fi

## Performs global search
${MY_LDAP_SEARCHBIN} "${ldap_param}" -s ${MY_LDAP_SEARCHSCOPE} \
${MY_LDAP_SEARCHBIN} ${ldap_param} -s ${MY_LDAP_SEARCHSCOPE} \
-b "${MY_LDAP_SEARCHBASE}" "${MY_LDAP_SEARCHFILTER}" \
"dn" | grep -iE '^dn:' > ${result_file}

Expand All @@ -277,9 +277,9 @@ do
dn=$(echo "${dnStr}" | cut -d : -f 2)

# Increment users counter
nb_users=$(("${nb_users}" + 1))
${MY_LDAP_SEARCHBIN} "${ldap_param}" -s base -b "${dn}" \
nb_users=$((${nb_users} + 1))

${MY_LDAP_SEARCHBIN} ${ldap_param} -s base -b "${dn}" \
${MY_LDAP_NAME_ATTR} ${MY_LDAP_LOGIN_ATTR} ${MY_LDAP_MAIL_ATTR} pwdChangedTime pwdPolicySubentry \
> ${buffer_file}

Expand Down Expand Up @@ -343,15 +343,14 @@ do
y=$(echo "${pwdChangedTime}" | cut -c 1-4)
currentTime=$(getTimeInSeconds)
pwdChangedTime=$(getTimeInSeconds "$y $M $d $h $m $s")
diffTime=$(("${currentTime}" - "${pwdChangedTime}"))
diffTime=$((${currentTime} - ${pwdChangedTime}))
fi

# Go to next user if password already expired
expireTime=$(("${pwdChangedTime}" + "${pwdMaxAge}"))
expireTime=$((${pwdChangedTime} + ${pwdMaxAge}))
if [ "${currentTime}" -gt "${expireTime}" ]; then
nb_expired_users=$(("${nb_expired_users}" + 1))
nb_expired_users=$((${nb_expired_users} + 1))
echo "${MY_LOG_HEADER} Password expired for ${login}" >&2
continue
fi

expireTimeTZ=$(date -d @"$expireTime" "+%A %d %B %Y %T")
Expand All @@ -372,7 +371,7 @@ do
&& [ "${login}" ] && [ "${diffTime}" ] && [ "${pwdMaxAge}" ]
then
# Ajusts time with delay
diffTime=$(("${diffTime}" + "${MY_MAIL_DELAY}"))
diffTime=$((${diffTime} + ${MY_MAIL_DELAY}))
if [ "${diffTime}" -gt "${pwdMaxAge}" ]; then
logmsg="${MY_MAIL_BODY}"
logmsg=$(echo "${logmsg}" | sed "s/%name/${name}/; \
Expand All @@ -386,7 +385,7 @@ do
echo "${MY_LOG_HEADER} Mail sent to user ${login} (${mail})" >&2

# Increment warning counter
nb_warning_users=$(("${nb_warning_users}" + 1))
nb_warning_users=$((${nb_warning_users} + 1))
fi
fi

Expand Down