On Sunday 15 December 2002 11:45 pm, Ina Patricia Lopez wrote:
> what command i can use to convert the last change field (/etc/shadow)
> to date format?
man shadow (on mandrake, not sure if you have that on your installation)
says that the last password change field is the number of days since
1Jan1970 since the password was changed. so if it is "1", then
the password was last changed on 2 Jan 1970.
i don't know what the quick solution would be offhand. so a hack would be:
use "man 3 mktime" to create a date corresponding to 1 Jan 1970.
take the last change field. multiple by 3600*24 (number of seconds per day).
the number you get is the number of seconds since 1 Jan 1970.
add that number to the number you got from running mktime.
call localtime to get the mm/dd/yy.
NOTE: i have not exhaustively tested. but one or two tests indicate
that this is OK (watch out for whenever it is that longs as seconds from
1/1/1970 roll over, sometime in 2038).
#include <time.h>
#include <stdio.h>
int main(int argc, char **argv)
{
int nd=11957; /* hardcoded, value from last changed in /etc/shadow */
struct tm tm;
time_t zero;
tm.tm_sec=32; /* random number less than 60 */
tm.tm_min=32; /* ditto */
tm.tm_hour=1; /* first hour of the first day of the month */
tm.tm_mday=1;
tm.tm_mon=1;
tm.tm_year=1970;
/* tm now contains Jan 1 1970 1:32:32 */
zero=mktime(&tm);
zero+=(3600*24*nd);
printf("%s\n",ctime(&zero)); /* prints the date that nd corresponds to */
}
tiger
--
Gerald Timothy Quimpo tiger*quimpo*org gquimpo*sni-inc.com tiger*sni*ph
Public Key: "gpg --keyserver pgp.mit.edu --recv-keys 672F4C78"
Pobrecito mexico tan lejos de Dios y a la vez
tan cerca de los Estados Unidos
Gen. Porfirio Diaz
_
Philippine Linux Users Group. Web site and archives at http://plug.linux.org.ph
To leave: send "unsubscribe" in the body to [EMAIL PROTECTED]
Fully Searchable Archives With Friendly Web Interface at http://marc.free.net.ph
To subscribe to the Linux Newbies' List: send "subscribe" in the body to
[EMAIL PROTECTED]