cron.h revision 320229
1133333Sstefanf/* Copyright 1988,1990,1993,1994 by Paul Vixie 2133333Sstefanf * All rights reserved 3133333Sstefanf * 4133333Sstefanf * Distribute freely, except: don't remove my name from the source or 5229575Sed * documentation (don't take credit for my work), mark your changes (don't 6229575Sed * get me blamed for your possible bugs), don't alter or remove this 7229575Sed * notice. May be sold if buildable source is provided to buyer. No 8133333Sstefanf * warrantee of any kind, express or implied, is included with this 9133333Sstefanf * software; use at your own risk, responsibility for damages (if any) to 10133333Sstefanf * anyone resulting from the use of this software rests entirely with the 11133333Sstefanf * user. 12133333Sstefanf * 13133333Sstefanf * Send bug reports, bug fixes, enhancements, requests, flames, etc., and 14133333Sstefanf * I'll try to keep a version up to date. I can be reached as follows: 15133333Sstefanf * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul 16133333Sstefanf */ 17133333Sstefanf 18133333Sstefanf/* cron.h - header for vixie's cron 19133333Sstefanf * 20133333Sstefanf * $FreeBSD: stable/10/usr.sbin/cron/cron/cron.h 320229 2017-06-22 07:54:12Z ngie $ 21133333Sstefanf * 22133333Sstefanf * vix 14nov88 [rest of log is in RCS] 23133333Sstefanf * vix 14jan87 [0 or 7 can be sunday; thanks, mwm@berkeley] 24133333Sstefanf * vix 30dec86 [written] 25133333Sstefanf */ 26133333Sstefanf 27133333Sstefanf/* reorder these #include's at your peril */ 28133333Sstefanf 29133333Sstefanf#include <sys/types.h> 30133333Sstefanf#include <sys/param.h> 31133333Sstefanf#include "compat.h" 32133333Sstefanf 33133333Sstefanf#include <bitstring.h> 34133333Sstefanf#include <ctype.h> 35133333Sstefanf#include <err.h> 36133333Sstefanf#include <errno.h> 37133333Sstefanf#include <libutil.h> 38133333Sstefanf#include <pwd.h> 39229575Sed#include <signal.h> 40229575Sed#include <stdio.h> 41229575Sed#include <time.h> 42133333Sstefanf#include <sys/wait.h> 43133333Sstefanf 44133333Sstefanf#include "pathnames.h" 45229575Sed#include "config.h" 46229575Sed#include "externs.h" 47133333Sstefanf 48133333Sstefanf /* these are really immutable, and are 49229575Sed * defined for symbolic convenience only 50133333Sstefanf * TRUE, FALSE, and ERR must be distinct 51133333Sstefanf * ERR must be < OK. 52133333Sstefanf */ 53133333Sstefanf#define TRUE 1 54133333Sstefanf#define FALSE 0 55133333Sstefanf /* system calls return this on success */ 56133333Sstefanf#define OK 0 57133333Sstefanf /* or this on error */ 58229575Sed#define ERR (-1) 59229575Sed 60229575Sed /* turn this on to get '-x' code */ 61133333Sstefanf#ifndef DEBUGGING 62229704Sed#define DEBUGGING FALSE 63229704Sed#endif 64229704Sed 65229704Sed#define READ_PIPE 0 /* which end of a pipe pair do you read? */ 66229704Sed#define WRITE_PIPE 1 /* or write to? */ 67229704Sed#define STDIN 0 /* what is stdin's file descriptor? */ 68229704Sed#define STDOUT 1 /* stdout's? */ 69229704Sed#define STDERR 2 /* stderr's? */ 70229704Sed#define ERROR_EXIT 1 /* exit() with this will scare the shell */ 71229704Sed#define OK_EXIT 0 /* exit() with this is considered 'normal' */ 72229704Sed#define MAX_FNAME 100 /* max length of internally generated fn */ 73229704Sed#define MAX_COMMAND 1000 /* max length of internally generated cmd */ 74229704Sed#define MAX_ENVSTR 1000 /* max length of envvar=value\0 strings */ 75229704Sed#define MAX_TEMPSTR 100 /* obvious */ 76229704Sed#define ROOT_UID 0 /* don't change this, it really must be root */ 77229704Sed#define ROOT_USER "root" /* ditto */ 78229704Sed#define SYS_NAME "*system*" /* magic owner name for system crontab */ 79229704Sed 80229704Sed /* NOTE: these correspond to DebugFlagNames, 81229575Sed * defined below. 82229575Sed */ 83229575Sed#define DEXT 0x0001 /* extend flag for other debug masks */ 84229575Sed#define DSCH 0x0002 /* scheduling debug mask */ 85229591Sed#define DPROC 0x0004 /* process control debug mask */ 86229591Sed#define DPARS 0x0008 /* parsing debug mask */ 87229575Sed#define DLOAD 0x0010 /* database loading debug mask */ 88229575Sed#define DMISC 0x0020 /* misc debug mask */ 89229575Sed#define DTEST 0x0040 /* test mode: don't execute any commands */ 90229575Sed#define DBIT 0x0080 /* bit twiddling shown (long) */ 91229575Sed 92229575Sed#define CRON_TAB(u) "%s/%s", SPOOL_DIR, u 93229575Sed#define REG register 94229575Sed#define PPC_NULL ((char **)NULL) 95229575Sed 96229575Sed#ifndef MAXHOSTNAMELEN 97229575Sed#define MAXHOSTNAMELEN 256 98229575Sed#endif 99229575Sed 100229575Sed#define Skip_Blanks(c, f) \ 101229575Sed while (c == '\t' || c == ' ') \ 102229575Sed c = get_char(f); 103229575Sed 104229575Sed#define Skip_Nonblanks(c, f) \ 105229591Sed while (c!='\t' && c!=' ' && c!='\n' && c != EOF) \ 106229591Sed c = get_char(f); 107229575Sed 108229575Sed#define Skip_Line(c, f) \ 109229575Sed do {c = get_char(f);} while (c != '\n' && c != EOF); 110229575Sed 111229575Sed#if DEBUGGING 112229575Sed# define Debug(mask, message) \ 113229575Sed if ( (DebugFlags & (mask) ) == (mask) ) \ 114229575Sed printf message; 115229575Sed#else /* !DEBUGGING */ 116229704Sed# define Debug(mask, message) \ 117133333Sstefanf ; 118133333Sstefanf#endif /* DEBUGGING */ 119133333Sstefanf 120229575Sed#define MkLower(ch) (isupper(ch) ? tolower(ch) : ch) 121133333Sstefanf#define MkUpper(ch) (islower(ch) ? toupper(ch) : ch) 122229575Sed#define Set_LineNum(ln) {Debug(DPARS|DEXT,("linenum=%d\n",ln)); \ 123229575Sed LineNumber = ln; \ 124229575Sed } 125133333Sstefanf 126229575Sed#define FIRST_SECOND 0 127133333Sstefanf#define LAST_SECOND 59 128229575Sed#define SECOND_COUNT (LAST_SECOND - FIRST_SECOND + 1) 129229575Sed 130229575Sed#define FIRST_MINUTE 0 131133333Sstefanf#define LAST_MINUTE 59 132133333Sstefanf#define MINUTE_COUNT (LAST_MINUTE - FIRST_MINUTE + 1) 133133333Sstefanf 134133333Sstefanf#define FIRST_HOUR 0 135133333Sstefanf#define LAST_HOUR 23 136133333Sstefanf#define HOUR_COUNT (LAST_HOUR - FIRST_HOUR + 1) 137133333Sstefanf 138133333Sstefanf#define FIRST_DOM 1 139133333Sstefanf#define LAST_DOM 31 140133333Sstefanf#define DOM_COUNT (LAST_DOM - FIRST_DOM + 1) 141133333Sstefanf 142133333Sstefanf#define FIRST_MONTH 1 143133333Sstefanf#define LAST_MONTH 12 144133333Sstefanf#define MONTH_COUNT (LAST_MONTH - FIRST_MONTH + 1) 145133333Sstefanf 146133333Sstefanf/* note on DOW: 0 and 7 are both Sunday, for compatibility reasons. */ 147133333Sstefanf#define FIRST_DOW 0 148229575Sed#define LAST_DOW 7 149133333Sstefanf#define DOW_COUNT (LAST_DOW - FIRST_DOW + 1) 150133333Sstefanf 151133333Sstefanf#ifdef LOGIN_CAP 152229575Sed/* see init.c */ 153229575Sed#define RESOURCE_RC "daemon" 154133333Sstefanf#endif 155133333Sstefanf 156133333Sstefanf /* each user's crontab will be held as a list of 157133333Sstefanf * the following structure. 158133333Sstefanf * 159133333Sstefanf * These are the cron commands. 160133333Sstefanf */ 161133333Sstefanf 162133333Sstefanftypedef struct _entry { 163133333Sstefanf struct _entry *next; 164133333Sstefanf uid_t uid; 165133333Sstefanf gid_t gid; 166229575Sed#ifdef LOGIN_CAP 167133333Sstefanf char *class; 168133333Sstefanf#endif 169133333Sstefanf char **envp; 170133333Sstefanf char *cmd; 171133333Sstefanf bitstr_t bit_decl(second, SECOND_COUNT); 172133333Sstefanf bitstr_t bit_decl(minute, MINUTE_COUNT); 173133333Sstefanf bitstr_t bit_decl(hour, HOUR_COUNT); 174133333Sstefanf bitstr_t bit_decl(dom, DOM_COUNT); 175133333Sstefanf bitstr_t bit_decl(month, MONTH_COUNT); 176133333Sstefanf bitstr_t bit_decl(dow, DOW_COUNT); 177133333Sstefanf int flags; 178133333Sstefanf#define DOM_STAR 0x01 179133333Sstefanf#define DOW_STAR 0x02 180133333Sstefanf#define WHEN_REBOOT 0x04 181133333Sstefanf#define RUN_AT 0x08 182133333Sstefanf#define NOT_UNTIL 0x10 183134733Sstefanf#define SEC_RES 0x20 184133333Sstefanf time_t lastrun; 185133333Sstefanf} entry; 186133333Sstefanf 187229575Sed /* the crontab database will be a list of the 188229575Sed * following structure, one element per user 189133333Sstefanf * plus one for the system. 190133333Sstefanf * 191133333Sstefanf * These are the crontabs. 192133333Sstefanf */ 193133333Sstefanf 194133333Sstefanftypedef struct _user { 195133333Sstefanf struct _user *next, *prev; /* links */ 196133333Sstefanf char *name; 197133333Sstefanf time_t mtime; /* last modtime of crontab */ 198133333Sstefanf entry *crontab; /* this person's crontab */ 199133333Sstefanf} user; 200133333Sstefanf 201133333Sstefanftypedef struct _cron_db { 202133333Sstefanf user *head, *tail; /* links */ 203133333Sstefanf time_t mtime; /* last modtime on spooldir */ 204} cron_db; 205 206 207void set_cron_uid(void), 208 set_cron_cwd(void), 209 load_database(cron_db *), 210 open_logfile(void), 211 sigpipe_func(void), 212 job_add(entry *, user *), 213 do_command(entry *, user *), 214 link_user(cron_db *, user *), 215 unlink_user(cron_db *, user *), 216 free_user(user *), 217 env_free(char **), 218 unget_char(int, FILE *), 219 free_entry(entry *), 220 skip_comments(FILE *), 221 log_it(char *, int, char *, char *), 222 log_close(void); 223 224int job_runqueue(void), 225 set_debug_flags(char *), 226 get_char(FILE *), 227 get_string(char *, int, FILE *, char *), 228 swap_uids(void), 229 swap_uids_back(void), 230 load_env(char *, FILE *), 231 cron_pclose(FILE *), 232 strcmp_until(char *, char *, int), 233 allowed(char *), 234 strdtb(char *); 235 236char *env_get(char *, char **), 237 *arpadate(time_t *), 238 *mkprints(unsigned char *, unsigned int), 239 *first_word(char *, char *), 240 **env_init(void), 241 **env_copy(char **), 242 **env_set(char **, char *); 243 244user *load_user(int, struct passwd *, char *), 245 *find_user(cron_db *, char *); 246 247entry *load_entry(FILE *, void (*)(char *), 248 struct passwd *, char **); 249 250FILE *cron_popen(char *, char *, entry *); 251 252 253 /* in the C tradition, we only create 254 * variables for the main program, just 255 * extern them elsewhere. 256 */ 257 258#ifdef MAIN_PROGRAM 259# if !defined(LINT) && !defined(lint) 260char *copyright[] = { 261 "@(#) Copyright 1988,1989,1990,1993,1994 by Paul Vixie", 262 "@(#) All rights reserved" 263 }; 264# endif 265 266char *MonthNames[] = { 267 "Jan", "Feb", "Mar", "Apr", "May", "Jun", 268 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 269 NULL 270 }; 271 272char *DowNames[] = { 273 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", 274 NULL 275 }; 276 277char *ProgramName, 278 *defmailto; 279int LineNumber; 280unsigned Jitter, 281 RootJitter; 282time_t TargetTime; 283 284# if DEBUGGING 285int DebugFlags; 286char *DebugFlagNames[] = { /* sync with #defines */ 287 "ext", "sch", "proc", "pars", "load", "misc", "test", "bit", 288 NULL /* NULL must be last element */ 289 }; 290# endif /* DEBUGGING */ 291#else /*MAIN_PROGRAM*/ 292extern char *copyright[], 293 *MonthNames[], 294 *DowNames[], 295 *ProgramName, 296 *defmailto; 297extern int LineNumber; 298extern unsigned Jitter, 299 RootJitter; 300extern time_t TargetTime; 301extern struct pidfh *pfh; 302# if DEBUGGING 303extern int DebugFlags; 304extern char *DebugFlagNames[]; 305# endif /* DEBUGGING */ 306#endif /*MAIN_PROGRAM*/ 307