Skip to content

Instantly share code, notes, and snippets.

@lgaggini
Created August 18, 2021 14:47
Show Gist options
  • Save lgaggini/994e0038c8b6e475f75c8729368df399 to your computer and use it in GitHub Desktop.
Save lgaggini/994e0038c8b6e475f75c8729368df399 to your computer and use it in GitHub Desktop.
Calculates the password expiration date based on pwdChangeTime and validity in days
#!/bin/bash
# Author: Lorenzo Gaggini
#
# Calculates the password expiration date based on pwdChangeTime
# validity in days
usage() {
cat <<USAGE
Calculates the password expiration date based on pwdChangeTime
Usage:
$0 -u
OPTIONS
-u ldap user id (required)
USAGE
}
while getopts "hu:" OPTION; do
case $OPTION in
u) USER_UID=$OPTARG ;;
?) usage
exit 0 ;;
esac
done
if [ -z ${USER_UID} ]; then
echo "ldap user id is required"
usage
exit 2
fi
PASSWORD_DAY_VALIDITY=90
LDAP_HOST=localhost
LDAP_USER=''
LDAP_PASS=''
LDAP_BASE=''
last_change=$(ldapsearch -LLL -u -x -h ${LDAP_HOST} -b ${LDAP_BASE} -D ${LDAP_USER} -w ${LDAP_PASS} "uid=${USER_UID}" pwdChangedTime | grep pwdChangedTime | awk '{print $2}')
year=${last_change:0:4}
month=${last_change:4:2}
day=${last_change:6:2}
hour=${last_change:8:2}
min=${last_change:10:2}
expiration_date=$(date -d "${year}${month}${day} ${hour}${min} +${PASSWORD_DAY_VALIDITY} day")
echo "Password for account ${USER_UID} will expire on ${expiration_date}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment