=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/calendar/calendar.c,v retrieving revision 1.8 retrieving revision 1.13 diff -u -r1.8 -r1.13 --- src/usr.bin/calendar/calendar.c 1997/08/26 23:37:21 1.8 +++ src/usr.bin/calendar/calendar.c 2000/06/30 16:00:11 1.13 @@ -1,4 +1,4 @@ -/* $OpenBSD: calendar.c,v 1.8 1997/08/26 23:37:21 millert Exp $ */ +/* $OpenBSD: calendar.c,v 1.13 2000/06/30 16:00:11 millert Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -43,7 +43,7 @@ #if 0 static const char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94"; #else -static char rcsid[] = "$OpenBSD: calendar.c,v 1.8 1997/08/26 23:37:21 millert Exp $"; +static char rcsid[] = "$OpenBSD: calendar.c,v 1.13 2000/06/30 16:00:11 millert Exp $"; #endif #endif /* not lint */ @@ -55,6 +55,7 @@ #include #include #include +#include #include #include "pathnames.h" @@ -67,22 +68,24 @@ int f_dayAfter = 0; /* days after current date */ int f_dayBefore = 0; /* days before current date */ +struct specialev spev[NUMEV]; + int main(argc, argv) int argc; char *argv[]; { - int ch; + int ch, i; char *caldir; - (void) setlocale(LC_ALL, ""); + (void)setlocale(LC_ALL, ""); while ((ch = getopt(argc, argv, "-af:t:A:B:")) != -1) switch (ch) { case '-': /* backward contemptible */ case 'a': if (getuid()) - errx(1, strerror(EPERM)); + errx(1, "%s", strerror(EPERM)); doall = 1; break; @@ -91,7 +94,8 @@ break; case 't': /* other date, undocumented, for tests */ - f_time = Mktime (optarg); + if ((f_time = Mktime(optarg)) <= 0) + errx(1, "specified date is outside allowed range"); break; case 'A': /* days after current date */ @@ -115,17 +119,30 @@ if (f_time <= 0) (void)time(&f_time); - settime(f_time); + if (f_dayBefore) { + /* Move back in time and only look forwards */ + f_dayAfter += f_dayBefore; + f_time -= SECSPERDAY * f_dayBefore; + f_dayBefore = 0; + } + settime(&f_time); - if (doall) + if (doall) { while ((pw = getpwent()) != NULL) { + (void)setlocale(LC_ALL, ""); (void)setegid(pw->pw_gid); (void)initgroups(pw->pw_name, pw->pw_gid); (void)seteuid(pw->pw_uid); - if (!chdir(pw->pw_dir)) + if (!chdir(pw->pw_dir)) { cal(); + /* Keep user settings from propogating */ + for (i = 0; i < NUMEV; i++) + if (spev[i].uname != NULL) + free(spev[i].uname); + } (void)seteuid(0); } + } else if ((caldir = getenv("CALENDAR_DIR")) != NULL) { if(!chdir(caldir)) cal();