Return to BSD News archive
Newsgroups: comp.unix.bsd.netbsd.misc Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!news.mel.connect.com.au!munnari.OZ.AU!news.ecn.uoknor.edu!feed1.news.erols.com!howland.erols.net!vixen.cso.uiuc.edu!uchinews!not-for-mail From: eric@fudge.uchicago.edu (Eric Fischer) Subject: Re: Passwd Expire'ing X-Nntp-Posting-Host: fudge.uchicago.edu Message-ID: <E0zD41.174@midway.uchicago.edu> Sender: news@midway.uchicago.edu (News Administrator) Organization: University of Chicago -- Academic Computing Services References: <847976274.19159.0@kevinw.noc.demon.net> <56kvl7$7l@xciv.demon.co.uk> Date: Sat, 16 Nov 1996 20:33:37 GMT Lines: 43 In article <56kvl7$7l@xciv.demon.co.uk>, Paul Civati <paul@xciv.org> wrote: > Now, how to generate such values for your /etc/passwd, I dunno. I've > done it before, I had to write some (not very good) code to do it, gets > difficult when you have to take the various leap year rules into account. You really shouldn't have to take leap years into account yourself, because the time functions already present in the C library will do it for you. Here's a short program that will take the year, month, and day of your choice and give you a value suitable for sticking in /etc/passwd: #include <stdio.h> #include <stdlib.h> #include <time.h> int main (int argc, char **argv) { struct tm tm; time_t t; if (argc != 4) { fprintf (stderr, "Usage: %s year month-number day-number\n", argv[0]); exit (1); } tm.tm_year = atoi (argv[1]) - 1900; tm.tm_mon = atoi (argv[2]) - 1; tm.tm_mday = atoi (argv[3]); tm.tm_hour = tm.tm_min = tm.tm_sec = 0; tm.tm_isdst = -1; t = mktime (&tm); printf ("%ld: %s", (long) t, ctime (&t)); return 0; } Eric