Annotation of src/usr.bin/calendar/calendar.c, Revision 1.6
1.6 ! millert 1: /* $OpenBSD: calendar.c,v 1.5 1996/12/05 06:04:38 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.6 ! millert 46: static char rcsid[] = "$OpenBSD: calendar.c,v 1.5 1996/12/05 06:04:38 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.6 ! millert 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:
90: case 'f': /* other calendar file */
91: calendarFile = optarg;
92: break;
93:
94: case 't': /* other date, undocumented, for tests */
95: f_time = Mktime (optarg);
96: break;
97:
98: case 'A': /* days after current date */
99: f_dayAfter = atoi(optarg);
100: break;
101:
102: case 'B': /* days before current date */
103: f_dayBefore = atoi(optarg);
104: break;
105:
1.1 deraadt 106: case '?':
107: default:
108: usage();
109: }
110: argc -= optind;
111: argv += optind;
112:
113: if (argc)
114: usage();
115:
1.5 millert 116: /* use current time */
117: if (f_time <= 0)
118: (void)time(&f_time);
119:
120: settime(f_time);
121:
1.1 deraadt 122: if (doall)
123: while ((pw = getpwent()) != NULL) {
124: (void)setegid(pw->pw_gid);
1.4 deraadt 125: (void)initgroups(pw->pw_name, pw->pw_gid);
1.1 deraadt 126: (void)seteuid(pw->pw_uid);
127: if (!chdir(pw->pw_dir))
128: cal();
129: (void)seteuid(0);
130: }
131: else if ((caldir = getenv("CALENDAR_DIR")) != NULL) {
1.5 millert 132: if(!chdir(caldir))
133: cal();
1.1 deraadt 134: } else
135: cal();
1.5 millert 136:
1.1 deraadt 137: exit(0);
138: }
139:
140:
141: void
142: usage()
143: {
1.5 millert 144: (void)fprintf(stderr,
145: "usage: calendar [-a] [-A days] [-B days] [-f calendarfile]\n");
1.1 deraadt 146: exit(1);
147: }