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

Defined variables

DebugFlagNames declared in line 273; defined in line 259; used 3 times
DebugFlags declared in line 272; defined in line 258; used 9 times
DowNames declared in line 267; defined in line 248; used 2 times
LineNumber declared in line 269; defined in line 254; used 5 times
MonthNames declared in line 266; defined in line 242; used 2 times
ProgramName declared in line 268; defined in line 253; used 25 times
TargetTime declared in line 270; defined in line 255; used 8 times
allowed defined in line 209; used 1 times
arpadate defined in line 213; used 1 times
copyright declared in line 265; defined in line 236; never used
cron_pclose defined in line 207; used 1 times
do_command defined in line 189; used 1 times
env_copy defined in line 217; used 1 times
env_free defined in line 193; used 2 times
env_init defined in line 216; used 2 times
env_set defined in line 218; used 6 times
find_user defined in line 221; used 1 times
first_word defined in line 215; used 1 times
free_entry defined in line 195; used 1 times
get_char defined in line 203; used 19 times
get_string defined in line 204; used 4 times
job_add defined in line 188; used 2 times
job_runqueue defined in line 201; used 2 times
link_user defined in line 190; used 2 times
load_database defined in line 185; used 2 times
load_env defined in line 206; used 2 times
load_user defined in line 220; used 1 times
log_close defined in line 199; used 1 times
mkprints defined in line 214; used 1 times
open_logfile defined in line 186; never used
sigpipe_func defined in line 187; never used
strcmp_until defined in line 208; used 2 times
strdtb defined in line 210; used 1 times
swap_uids defined in line 205; used 1 times
unget_char defined in line 194; used 2 times
unlink_user defined in line 191; used 3 times

Defined struct's

_cron_db defined in line 177; never used
_entry defined in line 146; used 2 times
  • in line 147(2)
_user defined in line 170; used 2 times
  • in line 171(2)

Defined typedef's

cron_db defined in line 180; used 18 times

Defined macros

DBIT defined in line 85; never used
DEBUGGING defined in line 57; used 4 times
DLOAD defined in line 82; used 9 times
DMISC defined in line 83; used 2 times
DOM_COUNT defined in line 129; used 1 times
DOM_STAR defined in line 158; used 2 times
DOW_COUNT defined in line 138; used 1 times
DOW_STAR defined in line 159; used 2 times
DPARS defined in line 81; used 18 times
DPROC defined in line 80; used 20 times
DSCH defined in line 79; used 4 times
DTEST defined in line 84; used 2 times
ERR defined in line 53; used 4 times
FIRST_DOM defined in line 127; used 6 times
FIRST_DOW defined in line 136; used 7 times
FIRST_HOUR defined in line 123; used 4 times
FIRST_MINUTE defined in line 119; used 3 times
FIRST_MONTH defined in line 131; used 7 times
HOUR_COUNT defined in line 125; used 1 times
LAST_DOM defined in line 128; used 5 times
LAST_DOW defined in line 137; used 6 times
LAST_HOUR defined in line 124; used 3 times
LAST_MINUTE defined in line 120; used 2 times
LAST_MONTH defined in line 132; used 6 times
MAXHOSTNAMELEN defined in line 92; used 1 times
  • in line 91
MAX_FNAME defined in line 67; used 7 times
MAX_UNAME defined in line 71; used 2 times
MINUTE_COUNT defined in line 121; used 1 times
MONTH_COUNT defined in line 133; used 1 times
PPC_NULL defined in line 89; used 4 times
READ_PIPE defined in line 60; used 6 times
REG defined in line 88; never used
ROOT_UID defined in line 72; used 3 times
ROOT_USER defined in line 73; used 1 times
STDERR defined in line 64; used 3 times
STDIN defined in line 62; used 2 times
STDOUT defined in line 63; used 3 times
Skip_Blanks defined in line 95; used 1 times
Skip_Line defined in line 103; never used
Skip_Nonblanks defined in line 99; used 1 times
WRITE_PIPE defined in line 61; used 6 times

Usage of this include

Last modified: 1999-06-16
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 797
Valid CSS Valid XHTML 1.0 Strict