1 /* Copyright 1988,1990,1993 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 * $Id: cron.h,v 1.1 1994/01/05 20:40:12 jtc Exp $
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]
27 /* reorder these #include's at your peril */
29 #include <sys/types.h>
30 #include <sys/param.h>
35 #include <bitstring.h>
38 #include "pathnames.h"
41 /* these are really immutable, and are
42 * defined for symbolic convenience only
43 * TRUE, FALSE, and ERR must be distinct
47 /* system calls return this on success */
49 /* or this on error */
52 /* turn this on to get '-x' code */
54 #define DEBUGGING FALSE
57 #define READ_PIPE 0 /* which end of a pipe pair do you read? */
58 #define WRITE_PIPE 1 /* or write to? */
59 #define STDIN 0 /* what is stdin's file descriptor? */
60 #define STDOUT 1 /* stdout's? */
61 #define STDERR 2 /* stderr's? */
62 #define ERROR_EXIT 1 /* exit() with this will scare the shell */
63 #define OK_EXIT 0 /* exit() with this is considered 'normal' */
64 #define MAX_FNAME 100 /* max length of internally generated fn */
65 #define MAX_COMMAND 1000 /* max length of internally generated cmd */
66 #define MAX_ENVSTR 1000 /* max length of envvar=value\0 strings */
67 #define MAX_TEMPSTR 100 /* obvious */
68 #define MAX_UNAME 20 /* max length of username, should be overkill */
69 #define ROOT_UID 0 /* don't change this, it really must be root */
70 #define ROOT_USER "root" /* ditto */
72 /* NOTE: these correspond to DebugFlagNames,
75 #define DEXT 0x0001 /* extend flag for other debug masks */
76 #define DSCH 0x0002 /* scheduling debug mask */
77 #define DPROC 0x0004 /* process control debug mask */
78 #define DPARS 0x0008 /* parsing debug mask */
79 #define DLOAD 0x0010 /* database loading debug mask */
80 #define DMISC 0x0020 /* misc debug mask */
81 #define DTEST 0x0040 /* test mode: don't execute any commands */
82 #define DBIT 0x0080 /* bit twiddling shown (long) */
84 #define CRON_TAB(u) "%s/%s", SPOOL_DIR, u
86 #define PPC_NULL ((char **)NULL)
88 #ifndef MAXHOSTNAMELEN
89 #define MAXHOSTNAMELEN 64
92 #define Skip_Blanks(c, f) \
93 while (c == '\t' || c == ' ') \
96 #define Skip_Nonblanks(c, f) \
97 while (c!='\t' && c!=' ' && c!='\n' && c != EOF) \
100 #define Skip_Line(c, f) \
101 do {c = get_char(f);} while (c != '\n' && c != EOF);
104 # define Debug(mask, message) \
105 if ( (DebugFlags & (mask) ) == (mask) ) \
107 #else /* !DEBUGGING */
108 # define Debug(mask, message) \
110 #endif /* DEBUGGING */
112 #define MkLower(ch) (isupper(ch) ? tolower(ch) : ch)
113 #define MkUpper(ch) (islower(ch) ? toupper(ch) : ch)
114 #define Set_LineNum(ln) {Debug(DPARS|DEXT,("linenum=%d\n",ln)); \
118 #define FIRST_MINUTE 0
119 #define LAST_MINUTE 59
120 #define MINUTE_COUNT (LAST_MINUTE - FIRST_MINUTE + 1)
124 #define HOUR_COUNT (LAST_HOUR - FIRST_HOUR + 1)
128 #define DOM_COUNT (LAST_DOM - FIRST_DOM + 1)
130 #define FIRST_MONTH 1
131 #define LAST_MONTH 12
132 #define MONTH_COUNT (LAST_MONTH - FIRST_MONTH + 1)
134 /* note on DOW: 0 and 7 are both Sunday, for compatibility reasons. */
137 #define DOW_COUNT (LAST_DOW - FIRST_DOW + 1)
139 /* each user's crontab will be held as a list of
140 * the following structure.
142 * These are the cron commands.
145 typedef struct _entry
{
148 bitstr_t
bit_decl(minute
, MINUTE_COUNT
);
149 bitstr_t
bit_decl(hour
, HOUR_COUNT
);
150 bitstr_t
bit_decl(dom
, DOM_COUNT
);
151 bitstr_t
bit_decl(month
, MONTH_COUNT
);
152 bitstr_t
bit_decl(dow
, DOW_COUNT
);
156 #define WHEN_REBOOT 0x4
157 uid_t exec_uid
; /* 0 = default, else uid */
160 /* the crontab database will be a list of the
161 * following structure, one element per user.
163 * These are the crontabs.
166 typedef struct _user
{
167 struct _user
*next
, *prev
; /* links */
168 uid_t uid
; /* uid from passwd file */
169 gid_t gid
; /* gid from passwd file */
170 char **envp
; /* environ for commands */
171 time_t mtime
; /* last modtime of crontab */
172 entry
*crontab
; /* this person's crontab */
175 typedef struct _cron_db
{
176 user
*head
, *tail
; /* links */
177 time_t mtime
; /* last modtime on spooldir */
182 void set_cron_uid
__P((void)),
183 set_cron_cwd
__P((void)),
184 load_database
__P((cron_db
*)),
185 open_logfile
__P((void)),
186 sigpipe_func
__P((void)),
187 job_add
__P((entry
*, user
*)),
188 do_command
__P((entry
*, user
*)),
189 link_user
__P((cron_db
*, user
*)),
190 unlink_user
__P((cron_db
*, user
*)),
191 free_user
__P((user
*)),
192 unget_char
__P((int, FILE *)),
193 free_entry
__P((entry
*)),
194 acquire_daemonlock
__P((int)),
195 skip_comments
__P((FILE *)),
196 log_it
__P((char *, int, char *, char *));
198 int job_runqueue
__P((void)),
199 set_debug_flags
__P((char *)),
200 get_char
__P((FILE *)),
201 get_string
__P((char *, int, FILE *, char *)),
202 swap_uids
__P((void)),
203 load_env
__P((char *, FILE *)),
204 cron_pclose
__P((FILE *)),
205 strcmp_until
__P((char *, char *, int)),
206 allowed
__P((char *)),
207 strdtb
__P((char *));
209 char *env_get
__P((char *, char **)),
210 *arpadate
__P((time_t *)),
211 *mkprints
__P((unsigned char *, unsigned int)),
212 *first_word
__P((char *, char *)),
213 **env_init
__P((void)),
214 **env_set
__P((char **, char *));
216 user
*load_user
__P((int, char *, int, int, char *, int)),
217 *find_user
__P((cron_db
*, char *));
219 entry
*load_entry
__P((FILE *, void (*)(), int));
221 FILE *cron_popen
__P((char *, char *));
224 /* in the C tradition, we only create
225 * variables for the main program, just
226 * extern them elsewhere.
230 # if !defined(LINT) && !defined(lint)
231 char *copyright
[] = {
232 "@(#) Copyright 1988, 1989, 1990, 1993 by Paul Vixie",
233 "@(#) All rights reserved"
237 char *MonthNames
[] = {
238 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
239 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
244 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
254 char *DebugFlagNames
[] = { /* sync with #defines */
255 "ext", "sch", "proc", "pars", "load", "misc", "test", "bit",
256 NULL
/* NULL must be last element */
258 # endif /* DEBUGGING */
259 #else /*MAIN_PROGRAM*/
260 extern char *copyright
[],
264 extern int LineNumber
;
265 extern time_t TargetTime
;
267 extern int DebugFlags
;
268 extern char *DebugFlagNames
[];
269 # endif /* DEBUGGING */
270 #endif /*MAIN_PROGRAM*/