1: /* Copyright 1988,1990,1993,1994 by Paul Vixie
2: * All rights reserved
3: *
4: * Distribute freely, except: don't remove my name from the source or
5: * documentation (don't take credit for my work), mark your changes (don't
6: * get me blamed for your possible bugs), don't alter or remove this
7: * notice. May be sold if buildable source is provided to buyer. No
8: * warrantee of any kind, express or implied, is included with this
9: * software; use at your own risk, responsibility for damages (if any) to
10: * anyone resulting from the use of this software rests entirely with the
11: * user.
12: *
13: * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
14: * I'll try to keep a version up to date. I can be reached as follows:
15: * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
16: */
17:
18: /* cron.h - header for vixie's cron
19: *
20: * $Id: cron.h,v 2.10 1994/01/15 20:43:43 vixie Exp $
21: *
22: * vix 14nov88 [rest of log is in RCS]
23: * vix 14jan87 [0 or 7 can be sunday; thanks, mwm@berkeley]
24: * vix 30dec86 [written]
25: */
26:
27: /* reorder these #include's at your peril */
28:
29: #include <sys/types.h>
30: #include <sys/param.h>
31: #include "compat.h"
32:
33: #include <stdio.h>
34: #include <ctype.h>
35: #include <bitstring.h>
36: #include <pwd.h>
37: #include <sys/wait.h>
38:
39: #include "pathnames.h"
40: #include "config.h"
41: #include "externs.h"
42:
43: /* these are really immutable, and are
44: * defined for symbolic convenience only
45: * TRUE, FALSE, and ERR must be distinct
46: * ERR must be < OK.
47: */
48: #define TRUE 1
49: #define FALSE 0
50: /* system calls return this on success */
51: #define OK 0
52: /* or this on error */
53: #define ERR (-1)
54:
55: /* turn this on to get '-x' code */
56: #ifndef DEBUGGING
57: #define DEBUGGING FALSE
58: #endif
59:
60: #define READ_PIPE 0 /* which end of a pipe pair do you read? */
61: #define WRITE_PIPE 1 /* or write to? */
62: #define STDIN 0 /* what is stdin's file descriptor? */
63: #define STDOUT 1 /* stdout's? */
64: #define STDERR 2 /* stderr's? */
65: #define ERROR_EXIT 1 /* exit() with this will scare the shell */
66: #define OK_EXIT 0 /* exit() with this is considered 'normal' */
67: #define MAX_FNAME 100 /* max length of internally generated fn */
68: #define MAX_COMMAND 1000 /* max length of internally generated cmd */
69: #define MAX_ENVSTR 1000 /* max length of envvar=value\0 strings */
70: #define MAX_TEMPSTR 100 /* obvious */
71: #define MAX_UNAME 20 /* max length of username, should be overkill */
72: #define ROOT_UID 0 /* don't change this, it really must be root */
73: #define ROOT_USER "root" /* ditto */
74:
75: /* NOTE: these correspond to DebugFlagNames,
76: * defined below.
77: */
78: #define DEXT 0x0001 /* extend flag for other debug masks */
79: #define DSCH 0x0002 /* scheduling debug mask */
80: #define DPROC 0x0004 /* process control debug mask */
81: #define DPARS 0x0008 /* parsing debug mask */
82: #define DLOAD 0x0010 /* database loading debug mask */
83: #define DMISC 0x0020 /* misc debug mask */
84: #define DTEST 0x0040 /* test mode: don't execute any commands */
85: #define DBIT 0x0080 /* bit twiddling shown (long) */
86:
87: #define CRON_TAB(u) "%s/%s", SPOOL_DIR, u
88: #define REG register
89: #define PPC_NULL ((char **)NULL)
90:
91: #ifndef MAXHOSTNAMELEN
92: #define MAXHOSTNAMELEN 64
93: #endif
94:
95: #define Skip_Blanks(c, f) \
96: while (c == '\t' || c == ' ') \
97: c = get_char(f);
98:
99: #define Skip_Nonblanks(c, f) \
100: while (c!='\t' && c!=' ' && c!='\n' && c != EOF) \
101: c = get_char(f);
102:
103: #define Skip_Line(c, f) \
104: do {c = get_char(f);} while (c != '\n' && c != EOF);
105:
106: #if DEBUGGING
107: # define Debug(mask, message) \
108: if ( (DebugFlags & (mask) ) == (mask) ) \
109: printf message;
110: #else /* !DEBUGGING */
111: # define Debug(mask, message) \
112: ;
113: #endif /* DEBUGGING */
114:
115: #define Set_LineNum(ln) {Debug(DPARS|DEXT,("linenum=%d\n",ln)); \
116: LineNumber = ln; \
117: }
118:
119: #define FIRST_MINUTE 0
120: #define LAST_MINUTE 59
121: #define MINUTE_COUNT (LAST_MINUTE - FIRST_MINUTE + 1)
122:
123: #define FIRST_HOUR 0
124: #define LAST_HOUR 23
125: #define HOUR_COUNT (LAST_HOUR - FIRST_HOUR + 1)
126:
127: #define FIRST_DOM 1
128: #define LAST_DOM 31
129: #define DOM_COUNT (LAST_DOM - FIRST_DOM + 1)
130:
131: #define FIRST_MONTH 1
132: #define LAST_MONTH 12
133: #define MONTH_COUNT (LAST_MONTH - FIRST_MONTH + 1)
134:
135: /* note on DOW: 0 and 7 are both Sunday, for compatibility reasons. */
136: #define FIRST_DOW 0
137: #define LAST_DOW 7
138: #define DOW_COUNT (LAST_DOW - FIRST_DOW + 1)
139:
140: /* each user's crontab will be held as a list of
141: * the following structure.
142: *
143: * These are the cron commands.
144: */
145:
146: typedef struct _entry {
147: struct _entry *next;
148: uid_t uid;
149: gid_t gid;
150: char **envp;
151: char *cmd;
152: bitstr_t bit_decl(minute, MINUTE_COUNT);
153: bitstr_t bit_decl(hour, HOUR_COUNT);
154: bitstr_t bit_decl(dom, DOM_COUNT);
155: bitstr_t bit_decl(month, MONTH_COUNT);
156: bitstr_t bit_decl(dow, DOW_COUNT);
157: int flags;
158: #define DOM_STAR 0x01
159: #define DOW_STAR 0x02
160: #define WHEN_REBOOT 0x04
161: } entry;
162:
163: /* the crontab database will be a list of the
164: * following structure, one element per user
165: * plus one for the system.
166: *
167: * These are the crontabs.
168: */
169:
170: typedef struct _user {
171: struct _user *next, *prev; /* links */
172: char *name;
173: time_t mtime; /* last modtime of crontab */
174: entry *crontab; /* this person's crontab */
175: } user;
176:
177: typedef struct _cron_db {
178: user *head, *tail; /* links */
179: time_t mtime; /* last modtime on spooldir */
180: } cron_db;
181:
182:
183: void set_cron_uid __P((void)),
184: set_cron_cwd __P((void)),
185: load_database __P((cron_db *)),
186: open_logfile __P((void)),
187: sigpipe_func __P((void)),
188: job_add __P((entry *, user *)),
189: do_command __P((entry *, user *)),
190: link_user __P((cron_db *, user *)),
191: unlink_user __P((cron_db *, user *)),
192: free_user __P((user *)),
193: env_free __P((char **)),
194: unget_char __P((int, FILE *)),
195: free_entry __P((entry *)),
196: acquire_daemonlock __P((int)),
197: __P((FILE *)),
198: log_it __P((char *, int, char *, char *)),
199: log_close __P((void));
200:
201: int job_runqueue __P((void)),
202: set_debug_flags __P((char *)),
203: get_char __P((FILE *)),
204: get_string __P((char *, int, FILE *, char *)),
205: swap_uids __P((void)),
206: load_env __P((char *, FILE *)),
207: cron_pclose __P((FILE *)),
208: strcmp_until __P((char *, char *, int)),
209: allowed __P((char *)),
210: strdtb __P((char *));
211:
212: char *env_get __P((char *, char **)),
213: *arpadate __P((time_t *)),
214: *mkprints __P((unsigned char *, unsigned int)),
215: *first_word __P((char *, char *)),
216: **env_init __P((void)),
217: **env_copy __P((char **)),
218: **env_set __P((char **, char *));
219:
220: user *load_user __P((int, struct passwd *, char *)),
221: *find_user __P((cron_db *, char *));
222:
223: entry *load_entry __P((FILE *, void (*)(),
224: struct passwd *, char **));
225:
226: FILE *cron_popen __P((char *, char *));
227:
228:
229: /* in the C tradition, we only create
230: * variables for the main program, just
231: * extern them elsewhere.
232: */
233:
234: #ifdef MAIN_PROGRAM
235: # if !defined(LINT) && !defined(lint)
236: char *copyright[] = {
237: "@(#) Copyright 1988,1989,1990,1993,1994 by Paul Vixie",
238: "@(#) All rights reserved"
239: };
240: # endif
241:
242: char *MonthNames[] = {
243: "Jan", "Feb", "Mar", "Apr", "May", "Jun",
244: "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
245: NULL
246: };
247:
248: char *DowNames[] = {
249: "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
250: NULL
251: };
252:
253: char *ProgramName;
254: int LineNumber;
255: time_t TargetTime;
256:
257: # if DEBUGGING
258: int DebugFlags;
259: char *DebugFlagNames[] = { /* sync with #defines */
260: "ext", "sch", "proc", "pars", "load", "misc", "test", "bit",
261: NULL /* NULL must be last element */
262: };
263: # endif /* DEBUGGING */
264: #else /*MAIN_PROGRAM*/
265: extern char *copyright[],
266: *MonthNames[],
267: *DowNames[],
268: *ProgramName;
269: extern int LineNumber;
270: extern time_t TargetTime;
271: # if DEBUGGING
272: extern int DebugFlags;
273: extern char *DebugFlagNames[];
274: # endif /* DEBUGGING */
275: #endif /*MAIN_PROGRAM*/