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