Created
August 12, 2016 15:59
-
-
Save adkinss/dbbc7828e51489dc6184215e5c0bc376 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Have you ever wondered how to calculate the third column listed | |
# in the shadow password file? It is the date of the last change | |
# to that user's password. The field is calculated by looking at | |
# the number of days that have passed since January 1, 1970. The | |
# expiration fields all depend on a good value for that field. | |
# January 1, 1970 is 18000 in epoch time format in seconds | |
THAT_WAS_THEN=18000 | |
# Now, figure out today in seconds | |
THIS_IS_NOW=`perl -e 'print time()'` | |
# Find the difference to see how many seconds have gone by | |
DELTA=`expr $THIS_IS_NOW - $THAT_WAS_THEN` | |
# There are 86400 seconds in a day. Convert what we have into days. | |
# Keep in mind that expr will truncate the decimal value down to the | |
# nearest integer (unlike "bc -l" for instance). However, this is | |
# what we want and the same behavior the shadow password file follows. | |
DAYS=`expr $DELTA / 86400` | |
# Show it it to the monkey on the other end of the keyboard | |
if [ $# -gt 0 ]; then | |
echo "Sample /etc/shadow entry:" | |
echo " $LOGNAME:<encrypted_password>:$DAYS:0:90:14:::" | |
echo "$DAYS days have passed since January 1, 1970." | |
else | |
echo $DAYS | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment