=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/calendar/calendar.c,v retrieving revision 1.5 retrieving revision 1.13 diff -u -r1.5 -r1.13 --- src/usr.bin/calendar/calendar.c 1996/12/05 06:04:38 1.5 +++ src/usr.bin/calendar/calendar.c 2000/06/30 16:00:11 1.13 @@ -1,4 +1,4 @@ -/* $OpenBSD: calendar.c,v 1.5 1996/12/05 06:04:38 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.5 1996/12/05 06:04:38 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,32 +68,34 @@ 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:")) != EOF) + 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; - case 'f': /* other calendar file */ calendarFile = optarg; 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 */ @@ -103,7 +106,6 @@ f_dayBefore = atoi(optarg); break; - case '?': default: usage(); } @@ -117,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(); @@ -142,6 +157,6 @@ usage() { (void)fprintf(stderr, - "usage: calendar [-a] [-A days] [-B days] [-f calendarfile]\n"); + "usage: calendar [-a] [-A days] [-B days] [-f calendarfile] [-t [[[yy]yy][mm]]dd]\n"); exit(1); }