version 1.6, 1997/01/15 23:42:16 |
version 1.13, 2000/06/30 16:00:11 |
|
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <time.h> |
#include <time.h> |
|
#include <tzfile.h> |
#include <unistd.h> |
#include <unistd.h> |
|
|
#include "pathnames.h" |
#include "pathnames.h" |
|
|
int f_dayAfter = 0; /* days after current date */ |
int f_dayAfter = 0; /* days after current date */ |
int f_dayBefore = 0; /* days before current date */ |
int f_dayBefore = 0; /* days before current date */ |
|
|
|
struct specialev spev[NUMEV]; |
|
|
int |
int |
main(argc, argv) |
main(argc, argv) |
int argc; |
int argc; |
char *argv[]; |
char *argv[]; |
{ |
{ |
int ch; |
int ch, i; |
char *caldir; |
char *caldir; |
|
|
(void) setlocale(LC_ALL, ""); |
(void)setlocale(LC_ALL, ""); |
|
|
while ((ch = getopt(argc, argv, "?-af:t:A:B:")) != -1) |
while ((ch = getopt(argc, argv, "-af:t:A:B:")) != -1) |
switch (ch) { |
switch (ch) { |
case '-': /* backward contemptible */ |
case '-': /* backward contemptible */ |
case 'a': |
case 'a': |
if (getuid()) |
if (getuid()) |
errx(1, strerror(EPERM)); |
errx(1, "%s", strerror(EPERM)); |
doall = 1; |
doall = 1; |
break; |
break; |
|
|
|
|
case 'f': /* other calendar file */ |
case 'f': /* other calendar file */ |
calendarFile = optarg; |
calendarFile = optarg; |
break; |
break; |
|
|
case 't': /* other date, undocumented, for tests */ |
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; |
break; |
|
|
case 'A': /* days after current date */ |
case 'A': /* days after current date */ |
|
|
f_dayBefore = atoi(optarg); |
f_dayBefore = atoi(optarg); |
break; |
break; |
|
|
case '?': |
|
default: |
default: |
usage(); |
usage(); |
} |
} |
|
|
if (f_time <= 0) |
if (f_time <= 0) |
(void)time(&f_time); |
(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) { |
while ((pw = getpwent()) != NULL) { |
|
(void)setlocale(LC_ALL, ""); |
(void)setegid(pw->pw_gid); |
(void)setegid(pw->pw_gid); |
(void)initgroups(pw->pw_name, pw->pw_gid); |
(void)initgroups(pw->pw_name, pw->pw_gid); |
(void)seteuid(pw->pw_uid); |
(void)seteuid(pw->pw_uid); |
if (!chdir(pw->pw_dir)) |
if (!chdir(pw->pw_dir)) { |
cal(); |
cal(); |
|
/* Keep user settings from propogating */ |
|
for (i = 0; i < NUMEV; i++) |
|
if (spev[i].uname != NULL) |
|
free(spev[i].uname); |
|
} |
(void)seteuid(0); |
(void)seteuid(0); |
} |
} |
|
} |
else if ((caldir = getenv("CALENDAR_DIR")) != NULL) { |
else if ((caldir = getenv("CALENDAR_DIR")) != NULL) { |
if(!chdir(caldir)) |
if(!chdir(caldir)) |
cal(); |
cal(); |
|
|
usage() |
usage() |
{ |
{ |
(void)fprintf(stderr, |
(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); |
exit(1); |
} |
} |