Annotation of src/usr.bin/calendar/calendar.c, Revision 1.9
1.9 ! millert 1: /* $OpenBSD: calendar.c,v 1.8 1997/08/26 23:37:21 millert Exp $ */
1.1 deraadt 2:
3: /*
4: * Copyright (c) 1989, 1993, 1994
5: * The Regents of the University of California. All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed by the University of
18: * California, Berkeley and its contributors.
19: * 4. Neither the name of the University nor the names of its contributors
20: * may be used to endorse or promote products derived from this software
21: * without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33: * SUCH DAMAGE.
34: */
35:
36: #ifndef lint
1.5 millert 37: static const char copyright[] =
1.1 deraadt 38: "@(#) Copyright (c) 1989, 1993\n\
39: The Regents of the University of California. All rights reserved.\n";
40: #endif /* not lint */
41:
42: #ifndef lint
43: #if 0
1.5 millert 44: static const char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94";
45: #else
1.9 ! millert 46: static char rcsid[] = "$OpenBSD: calendar.c,v 1.8 1997/08/26 23:37:21 millert Exp $";
1.1 deraadt 47: #endif
48: #endif /* not lint */
49:
50: #include <err.h>
51: #include <errno.h>
1.5 millert 52: #include <locale.h>
1.1 deraadt 53: #include <pwd.h>
54: #include <stdio.h>
55: #include <stdlib.h>
56: #include <string.h>
1.5 millert 57: #include <time.h>
1.1 deraadt 58: #include <unistd.h>
59:
60: #include "pathnames.h"
1.5 millert 61: #include "calendar.h"
1.1 deraadt 62:
63: struct passwd *pw;
1.5 millert 64: int doall = 0;
65: time_t f_time = 0;
1.1 deraadt 66:
1.5 millert 67: int f_dayAfter = 0; /* days after current date */
68: int f_dayBefore = 0; /* days before current date */
1.1 deraadt 69:
70: int
71: main(argc, argv)
72: int argc;
73: char *argv[];
74: {
75: int ch;
76: char *caldir;
77:
1.5 millert 78: (void) setlocale(LC_ALL, "");
79:
1.7 deraadt 80: while ((ch = getopt(argc, argv, "-af:t:A:B:")) != -1)
1.1 deraadt 81: switch (ch) {
82: case '-': /* backward contemptible */
83: case 'a':
1.5 millert 84: if (getuid())
85: errx(1, strerror(EPERM));
1.1 deraadt 86: doall = 1;
87: break;
1.5 millert 88:
89: case 'f': /* other calendar file */
90: calendarFile = optarg;
91: break;
92:
93: case 't': /* other date, undocumented, for tests */
94: f_time = Mktime (optarg);
95: break;
96:
97: case 'A': /* days after current date */
98: f_dayAfter = atoi(optarg);
99: break;
100:
101: case 'B': /* days before current date */
102: f_dayBefore = atoi(optarg);
103: break;
104:
1.1 deraadt 105: default:
106: usage();
107: }
108: argc -= optind;
109: argv += optind;
110:
111: if (argc)
112: usage();
113:
1.5 millert 114: /* use current time */
115: if (f_time <= 0)
116: (void)time(&f_time);
117:
118: settime(f_time);
119:
1.1 deraadt 120: if (doall)
121: while ((pw = getpwent()) != NULL) {
122: (void)setegid(pw->pw_gid);
1.4 deraadt 123: (void)initgroups(pw->pw_name, pw->pw_gid);
1.9 ! millert 124: (void)setlogin(pw->pw_name);
1.1 deraadt 125: (void)seteuid(pw->pw_uid);
126: if (!chdir(pw->pw_dir))
127: cal();
128: (void)seteuid(0);
129: }
130: else if ((caldir = getenv("CALENDAR_DIR")) != NULL) {
1.5 millert 131: if(!chdir(caldir))
132: cal();
1.1 deraadt 133: } else
134: cal();
1.5 millert 135:
1.1 deraadt 136: exit(0);
137: }
138:
139:
140: void
141: usage()
142: {
1.5 millert 143: (void)fprintf(stderr,
1.8 millert 144: "usage: calendar [-a] [-A days] [-B days] [-f calendarfile] [-t [[[yy]yy][mm]]dd]\n");
1.1 deraadt 145: exit(1);
146: }