1 /* Copyright 1988,1990,1993,1994 by Paul Vixie
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
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
18 /* cron.h - header for vixie's cron
20 * $FreeBSD: src/usr.sbin/cron/cron/cron.h,v 1.9.2.3 2001/05/28 23:37:26 babkin Exp $
21 * $DragonFly: src/usr.sbin/cron/cron/cron.h,v 1.2 2003/06/17 04:29:53 dillon Exp $
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]
28 /* reorder these #include's at your peril */
30 #include <sys/types.h>
31 #include <sys/param.h>
34 #include <bitstring.h>
44 #include "pathnames.h"
48 /* these are really immutable, and are
49 * defined for symbolic convenience only
50 * TRUE, FALSE, and ERR must be distinct
55 /* system calls return this on success */
57 /* or this on error */
60 /* turn this on to get '-x' code */
62 #define DEBUGGING FALSE
65 #define READ_PIPE 0 /* which end of a pipe pair do you read? */
66 #define WRITE_PIPE 1 /* or write to? */
67 #define STDIN 0 /* what is stdin's file descriptor? */
68 #define STDOUT 1 /* stdout's? */
69 #define STDERR 2 /* stderr's? */
70 #define ERROR_EXIT 1 /* exit() with this will scare the shell */
71 #define OK_EXIT 0 /* exit() with this is considered 'normal' */
72 #define MAX_FNAME 100 /* max length of internally generated fn */
73 #define MAX_COMMAND 1000 /* max length of internally generated cmd */
74 #define MAX_ENVSTR 1000 /* max length of envvar=value\0 strings */
75 #define MAX_TEMPSTR 100 /* obvious */
76 #define MAX_UNAME 20 /* max length of username, should be overkill */
77 #define ROOT_UID 0 /* don't change this, it really must be root */
78 #define ROOT_USER "root" /* ditto */
80 /* NOTE: these correspond to DebugFlagNames,
83 #define DEXT 0x0001 /* extend flag for other debug masks */
84 #define DSCH 0x0002 /* scheduling debug mask */
85 #define DPROC 0x0004 /* process control debug mask */
86 #define DPARS 0x0008 /* parsing debug mask */
87 #define DLOAD 0x0010 /* database loading debug mask */
88 #define DMISC 0x0020 /* misc debug mask */
89 #define DTEST 0x0040 /* test mode: don't execute any commands */
90 #define DBIT 0x0080 /* bit twiddling shown (long) */
92 #define CRON_TAB(u) "%s/%s", SPOOL_DIR, u
94 #define PPC_NULL ((char **)NULL)
96 #ifndef MAXHOSTNAMELEN
97 #define MAXHOSTNAMELEN 256
100 #define Skip_Blanks(c, f) \
101 while (c == '\t' || c == ' ') \
104 #define Skip_Nonblanks(c, f) \
105 while (c!='\t' && c!=' ' && c!='\n' && c != EOF) \
108 #define Skip_Line(c, f) \
109 do {c = get_char(f);} while (c != '\n' && c != EOF);
112 # define Debug(mask, message) \
113 if ( (DebugFlags & (mask) ) == (mask) ) \
115 #else /* !DEBUGGING */
116 # define Debug(mask, message) \
118 #endif /* DEBUGGING */
120 #define MkLower(ch) (isupper(ch) ? tolower(ch) : ch)
121 #define MkUpper(ch) (islower(ch) ? toupper(ch) : ch)
122 #define Set_LineNum(ln) {Debug(DPARS|DEXT,("linenum=%d\n",ln)); \
126 #define FIRST_MINUTE 0
127 #define LAST_MINUTE 59
128 #define MINUTE_COUNT (LAST_MINUTE - FIRST_MINUTE + 1)
132 #define HOUR_COUNT (LAST_HOUR - FIRST_HOUR + 1)
136 #define DOM_COUNT (LAST_DOM - FIRST_DOM + 1)
138 #define FIRST_MONTH 1
139 #define LAST_MONTH 12
140 #define MONTH_COUNT (LAST_MONTH - FIRST_MONTH + 1)
142 /* note on DOW: 0 and 7 are both Sunday, for compatibility reasons. */
145 #define DOW_COUNT (LAST_DOW - FIRST_DOW + 1)
149 #define RESOURCE_RC "daemon"
152 /* each user's crontab will be held as a list of
153 * the following structure.
155 * These are the cron commands.
158 typedef struct _entry {
167 bitstr_t bit_decl(minute, MINUTE_COUNT);
168 bitstr_t bit_decl(hour, HOUR_COUNT);
169 bitstr_t bit_decl(dom, DOM_COUNT);
170 bitstr_t bit_decl(month, MONTH_COUNT);
171 bitstr_t bit_decl(dow, DOW_COUNT);
173 #define DOM_STAR 0x01
174 #define DOW_STAR 0x02
175 #define WHEN_REBOOT 0x04
177 #define NOT_UNTIL 0x10
181 /* the crontab database will be a list of the
182 * following structure, one element per user
183 * plus one for the system.
185 * These are the crontabs.
188 typedef struct _user {
189 struct _user *next, *prev; /* links */
191 time_t mtime; /* last modtime of crontab */
192 entry *crontab; /* this person's crontab */
195 typedef struct _cron_db {
196 user *head, *tail; /* links */
197 time_t mtime; /* last modtime on spooldir */
201 void set_cron_uid __P((void)),
202 set_cron_cwd __P((void)),
203 load_database __P((cron_db *)),
204 open_logfile __P((void)),
205 sigpipe_func __P((void)),
206 job_add __P((entry *, user *)),
207 do_command __P((entry *, user *)),
208 link_user __P((cron_db *, user *)),
209 unlink_user __P((cron_db *, user *)),
210 free_user __P((user *)),
211 env_free __P((char **)),
212 unget_char __P((int, FILE *)),
213 free_entry __P((entry *)),
214 acquire_daemonlock __P((int)),
215 skip_comments __P((FILE *)),
216 log_it __P((char *, int, char *, char *)),
217 log_close __P((void));
219 int job_runqueue __P((void)),
220 set_debug_flags __P((char *)),
221 get_char __P((FILE *)),
222 get_string __P((char *, int, FILE *, char *)),
223 swap_uids __P((void)),
224 load_env __P((char *, FILE *)),
225 cron_pclose __P((FILE *)),
226 strcmp_until __P((char *, char *, int)),
227 allowed __P((char *)),
228 strdtb __P((char *));
230 char *env_get __P((char *, char **)),
231 *arpadate __P((time_t *)),
232 *mkprints __P((unsigned char *, unsigned int)),
233 *first_word __P((char *, char *)),
234 **env_init __P((void)),
235 **env_copy __P((char **)),
236 **env_set __P((char **, char *));
238 user *load_user __P((int, struct passwd *, char *)),
239 *find_user __P((cron_db *, char *));
241 entry *load_entry __P((FILE *, void (*)(),
242 struct passwd *, char **));
244 FILE *cron_popen __P((char *, char *, entry *));
247 /* in the C tradition, we only create
248 * variables for the main program, just
249 * extern them elsewhere.
253 # if !defined(LINT) && !defined(lint)
254 char *copyright[] = {
255 "@(#) Copyright 1988,1989,1990,1993,1994 by Paul Vixie",
256 "@(#) All rights reserved"
260 char *MonthNames[] = {
261 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
262 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
267 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
277 char *DebugFlagNames[] = { /* sync with #defines */
278 "ext", "sch", "proc", "pars", "load", "misc", "test", "bit",
279 NULL /* NULL must be last element */
281 # endif /* DEBUGGING */
282 #else /*MAIN_PROGRAM*/
283 extern char *copyright[],
287 extern int LineNumber;
288 extern time_t TargetTime;
290 extern int DebugFlags;
291 extern char *DebugFlagNames[];
292 # endif /* DEBUGGING */
293 #endif /*MAIN_PROGRAM*/