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 1.2 1997/12/22 08:10:41 deraadt 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 MkLower(ch) (isupper(ch) ? tolower(ch) : ch) 116 #define MkUpper(ch) (islower(ch) ? toupper(ch) : ch) 117 #define Set_LineNum(ln) {Debug(DPARS|DEXT,("linenum=%d\n",ln)); \ 118 LineNumber = ln; \ 119 } 120 121 typedef int time_min; 122 123 #define SECONDS_PER_MINUTE 60 124 125 #define FIRST_MINUTE 0 126 #define LAST_MINUTE 59 127 #define MINUTE_COUNT (LAST_MINUTE - FIRST_MINUTE + 1) 128 129 #define FIRST_HOUR 0 130 #define LAST_HOUR 23 131 #define HOUR_COUNT (LAST_HOUR - FIRST_HOUR + 1) 132 133 #define FIRST_DOM 1 134 #define LAST_DOM 31 135 #define DOM_COUNT (LAST_DOM - FIRST_DOM + 1) 136 137 #define FIRST_MONTH 1 138 #define LAST_MONTH 12 139 #define MONTH_COUNT (LAST_MONTH - FIRST_MONTH + 1) 140 141 /* note on DOW: 0 and 7 are both Sunday, for compatibility reasons. */ 142 #define FIRST_DOW 0 143 #define LAST_DOW 7 144 #define DOW_COUNT (LAST_DOW - FIRST_DOW + 1) 145 146 /* each user's crontab will be held as a list of 147 * the following structure. 148 * 149 * These are the cron commands. 150 */ 151 152 typedef struct _entry { 153 struct _entry *next; 154 uid_t uid; 155 gid_t gid; 156 char **envp; 157 char *cmd; 158 bitstr_t bit_decl(minute, MINUTE_COUNT); 159 bitstr_t bit_decl(hour, HOUR_COUNT); 160 bitstr_t bit_decl(dom, DOM_COUNT); 161 bitstr_t bit_decl(month, MONTH_COUNT); 162 bitstr_t bit_decl(dow, DOW_COUNT); 163 int flags; 164 #define DOM_STAR 0x01 165 #define DOW_STAR 0x02 166 #define WHEN_REBOOT 0x04 167 #define MIN_STAR 0x08 168 #define HR_STAR 0x10 169 } entry; 170 171 /* the crontab database will be a list of the 172 * following structure, one element per user 173 * plus one for the system. 174 * 175 * These are the crontabs. 176 */ 177 178 typedef struct _user { 179 struct _user *next, *prev; /* links */ 180 char *name; 181 time_t mtime; /* last modtime of crontab */ 182 entry *crontab; /* this person's crontab */ 183 } user; 184 185 typedef struct _cron_db { 186 user *head, *tail; /* links */ 187 time_t mtime; /* last modtime on spooldir */ 188 } cron_db; 189 190 191 void set_cron_uid __P((void)), 192 set_cron_cwd __P((void)), 193 load_database __P((cron_db *)), 194 open_logfile __P((void)), 195 sigpipe_func __P((void)), 196 job_add __P((entry *, user *)), 197 do_command __P((entry *, user *)), 198 link_user __P((cron_db *, user *)), 199 unlink_user __P((cron_db *, user *)), 200 free_user __P((user *)), 201 env_free __P((char **)), 202 unget_char __P((int, FILE *)), 203 free_entry __P((entry *)), 204 acquire_daemonlock __P((int)), 205 skip_comments __P((FILE *)), 206 log_it __P((char *, int, char *, char *)), 207 log_close __P((void)); 208 209 int job_runqueue __P((void)), 210 set_debug_flags __P((char *)), 211 get_char __P((FILE *)), 212 get_string __P((char *, int, FILE *, char *)), 213 swap_uids __P((void)), 214 load_env __P((char *, FILE *)), 215 cron_pclose __P((FILE *)), 216 strcmp_until __P((char *, char *, int)), 217 allowed __P((char *)), 218 strdtb __P((char *)); 219 220 char *env_get __P((char *, char **)), 221 *arpadate __P((time_t *)), 222 *mkprints __P((unsigned char *, unsigned int)), 223 *first_word __P((char *, char *)), 224 **env_init __P((void)), 225 **env_copy __P((char **)), 226 **env_set __P((char **, char *)); 227 228 user *load_user __P((int, struct passwd *, char *)), 229 *find_user __P((cron_db *, char *)); 230 231 entry *load_entry __P((FILE *, void (*)(), 232 struct passwd *, char **)); 233 234 FILE *cron_popen __P((char *, char *)); 235 236 237 /* in the C tradition, we only create 238 * variables for the main program, just 239 * extern them elsewhere. 240 */ 241 242 #ifdef MAIN_PROGRAM 243 # if !defined(LINT) && !defined(lint) 244 char *copyright[] = { 245 "@(#) Copyright 1988,1989,1990,1993,1994 by Paul Vixie", 246 "@(#) All rights reserved" 247 }; 248 # endif 249 250 char *MonthNames[] = { 251 "Jan", "Feb", "Mar", "Apr", "May", "Jun", 252 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 253 NULL 254 }; 255 256 char *DowNames[] = { 257 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", 258 NULL 259 }; 260 261 char *ProgramName; 262 int LineNumber; 263 time_t StartTime; 264 time_min timeRunning; 265 time_min virtualTime; 266 time_min clockTime; 267 268 # if DEBUGGING 269 int DebugFlags; 270 char *DebugFlagNames[] = { /* sync with #defines */ 271 "ext", "sch", "proc", "pars", "load", "misc", "test", "bit", 272 NULL /* NULL must be last element */ 273 }; 274 # else 275 #define DebugFlags 0 276 # endif /* DEBUGGING */ 277 #else /*MAIN_PROGRAM*/ 278 extern char *copyright[], 279 *MonthNames[], 280 *DowNames[], 281 *ProgramName; 282 extern int LineNumber; 283 extern time_t StartTime; 284 extern time_min timeRunning; 285 extern time_min virtualTime; 286 extern time_min clockTime; 287 # if DEBUGGING 288 extern int DebugFlags; 289 extern char *DebugFlagNames[]; 290 # endif /* DEBUGGING */ 291 #endif /*MAIN_PROGRAM*/ 292