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