TimeManager
crontab_cron.h
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 /*
28  * Rename and modify, 9 April 2013 by Shun Ito <movingentity@gmail.com>
29  */
30 
31 /* reorder these #include's at your peril */
32 
33 //-- MODIFIED >> ---------------------------------------------------------------
34 /*#include <sys/types.h>
35 #include <sys/param.h>
36 #include "compat.h"
37 
38 #include <stdio.h>
39 #include <ctype.h>
40 #include <bitstring.h>
41 #include <pwd.h>
42 #include <sys/wait.h>
43 
44 #include "pathnames.h"
45 #include "config.h"
46 #include "externs.h"*/
47 //-- << MODIFIED ---------------------------------------------------------------
48 
49 //-- ADD >> --------------------------------------------------------------------
50 #include <sys/types.h>
51 #include <stdio.h>
52 #include "crontab_bitstring.h"
53 //-- << ADD --------------------------------------------------------------------
54 
55  /* these are really immutable, and are
56  * defined for symbolic convenience only
57  * TRUE, FALSE, and ERR must be distinct
58  * ERR must be < OK.
59  */
60 #define TRUE 1
61 #define FALSE 0
62  /* system calls return this on success */
63 #define OK 0
64  /* or this on error */
65 #define ERR (-1)
66 
67  /* turn this on to get '-x' code */
68 //-- MODIFIED >> ---------------------------------------------------------------
69 /*#ifndef DEBUGGING
70 #define DEBUGGING FALSE
71 #endif*/
72 //-- << MODIFIED ---------------------------------------------------------------
73 
74 #define READ_PIPE 0 /* which end of a pipe pair do you read? */
75 #define WRITE_PIPE 1 /* or write to? */
76 #define STDIN 0 /* what is stdin's file descriptor? */
77 #define STDOUT 1 /* stdout's? */
78 #define STDERR 2 /* stderr's? */
79 #define ERROR_EXIT 1 /* exit() with this will scare the shell */
80 #define OK_EXIT 0 /* exit() with this is considered 'normal' */
81 #define MAX_FNAME 100 /* max length of internally generated fn */
82 #define MAX_COMMAND 1000 /* max length of internally generated cmd */
83 #define MAX_ENVSTR 1000 /* max length of envvar=value\0 strings */
84 #define MAX_TEMPSTR 100 /* obvious */
85 #define MAX_UNAME 20 /* max length of username, should be overkill */
86 #define ROOT_UID 0 /* don't change this, it really must be root */
87 #define ROOT_USER "root" /* ditto */
88 
89  /* NOTE: these correspond to DebugFlagNames,
90  * defined below.
91  */
92 #define DEXT 0x0001 /* extend flag for other debug masks */
93 #define DSCH 0x0002 /* scheduling debug mask */
94 #define DPROC 0x0004 /* process control debug mask */
95 #define DPARS 0x0008 /* parsing debug mask */
96 #define DLOAD 0x0010 /* database loading debug mask */
97 #define DMISC 0x0020 /* misc debug mask */
98 #define DTEST 0x0040 /* test mode: don't execute any commands */
99 #define DBIT 0x0080 /* bit twiddling shown (long) */
100 
101 //-- MODIFIED >> ---------------------------------------------------------------
102 /*#define CRON_TAB(u) "%s/%s", SPOOL_DIR, u
103 #define REG register*/
104 //-- << MODIFIED ---------------------------------------------------------------
105 #define PPC_NULL ((char **)NULL)
106 //-- MODIFIED >> ---------------------------------------------------------------
107 /*#ifndef MAXHOSTNAMELEN
108 #define MAXHOSTNAMELEN 64
109 #endif*/
110 //-- << MODIFIED ---------------------------------------------------------------
111 
112 #define Skip_Blanks(c, f) \
113  while (c == '\t' || c == ' ') \
114  c = get_char(f);
115 
116 #define Skip_Nonblanks(c, f) \
117  while (c!='\t' && c!=' ' && c!='\n' && c != EOF) \
118  c = get_char(f);
119 
120 //-- MODIFIED >> ---------------------------------------------------------------
121 /*#define Skip_Line(c, f) \
122  do {c = get_char(f);} while (c != '\n' && c != EOF);*/
123 //-- << MODIFIED ---------------------------------------------------------------
124 
125 
126 #if DEBUGGING
127 # define Debug(mask, message) \
128  if ( (DebugFlags & (mask) ) == (mask) ) \
129  printf message;
130 #else /* !DEBUGGING */
131 # define Debug(mask, message) \
132  ;
133 #endif /* DEBUGGING */
134 
135 //-- MODIFIED >> ---------------------------------------------------------------
136 /*#define MkLower(ch) (isupper(ch) ? tolower(ch) : ch)
137 #define MkUpper(ch) (islower(ch) ? toupper(ch) : ch)*/
138 //-- << MODIFIED ---------------------------------------------------------------
139 #define Set_LineNum(ln) {Debug(DPARS|DEXT,("linenum=%d\n",ln)); \
140  LineNumber = ln; \
141  }
142 
143 #define FIRST_MINUTE 0
144 #define LAST_MINUTE 59
145 #define MINUTE_COUNT (LAST_MINUTE - FIRST_MINUTE + 1)
146 
147 #define FIRST_HOUR 0
148 #define LAST_HOUR 23
149 #define HOUR_COUNT (LAST_HOUR - FIRST_HOUR + 1)
150 
151 #define FIRST_DOM 1
152 #define LAST_DOM 31
153 #define DOM_COUNT (LAST_DOM - FIRST_DOM + 1)
154 
155 #define FIRST_MONTH 1
156 #define LAST_MONTH 12
157 #define MONTH_COUNT (LAST_MONTH - FIRST_MONTH + 1)
158 
159 /* note on DOW: 0 and 7 are both Sunday, for compatibility reasons. */
160 #define FIRST_DOW 0
161 #define LAST_DOW 7
162 #define DOW_COUNT (LAST_DOW - FIRST_DOW + 1)
163 
164  /* each user's crontab will be held as a list of
165  * the following structure.
166  *
167  * These are the cron commands.
168  */
169 
170 typedef struct _entry {
171  struct _entry *next;
172  uid_t uid;
173  gid_t gid;
174  char **envp;
175  char *cmd;
176  bitstr_t bit_decl(minute, MINUTE_COUNT);
177  bitstr_t bit_decl(hour, HOUR_COUNT);
178  bitstr_t bit_decl(dom, DOM_COUNT);
179  bitstr_t bit_decl(month, MONTH_COUNT);
180  bitstr_t bit_decl(dow, DOW_COUNT);
181  int flags;
182 #define DOM_STAR 0x01
183 #define DOW_STAR 0x02
184 #define WHEN_REBOOT 0x04
185 } entry;
186 
187  /* the crontab database will be a list of the
188  * following structure, one element per user
189  * plus one for the system.
190  *
191  * These are the crontabs.
192  */
193 //-- MODIFIED >> ---------------------------------------------------------------
194 /*typedef struct _user {
195  struct _user *next, *prev; *//* links *//*
196  char *name;
197  time_t mtime; *//* last modtime of crontab *//*
198  entry *crontab; *//* this person's crontab *//*
199 } user;
200 
201 
202 typedef struct _cron_db {
203  user *head, *tail; *//* links *//*
204  time_t mtime; *//* last modtime on spooldir *//*
205 } cron_db;*/
206 //-- << MODIFIED ---------------------------------------------------------------
207 
208 
209 //-- MODIFIED >> ---------------------------------------------------------------
210 /*void set_cron_uid __P((void)),
211  set_cron_cwd __P((void)),
212  load_database __P((cron_db *)),
213  open_logfile __P((void)),
214  sigpipe_func __P((void)),
215  job_add __P((entry *, user *)),
216  do_command __P((entry *, user *)),
217  link_user __P((cron_db *, user *)),
218  unlink_user __P((cron_db *, user *)),
219  free_user __P((user *)),
220  env_free __P((char **)),
221  unget_char __P((int, FILE *)),
222  free_entry __P((entry *)),
223  acquire_daemonlock __P((int)),
224  skip_comments __P((FILE *)),
225  log_it __P((char *, int, char *, char *)),
226  log_close __P((void));*/
227 //-- << MODIFIED ---------------------------------------------------------------
228 
229 //-- MODIFIED >> ---------------------------------------------------------------
230 /*int job_runqueue __P((void)),
231  set_debug_flags __P((char *)),
232  get_char __P((FILE *)),
233  get_string __P((char *, int, FILE *, char *)),
234  swap_uids __P((void)),
235  load_env __P((char *, FILE *)),
236  cron_pclose __P((FILE *)),
237  strcmp_until __P((char *, char *, int)),
238  allowed __P((char *)),
239  strdtb __P((char *));*/
240 //-- << MODIFIED ---------------------------------------------------------------
241 
242 //-- ADD >> --------------------------------------------------------------------
243 int get_char __P((FILE *));
244 //-- << ADD --------------------------------------------------------------------
245 
246 //-- MODIFIED >> ---------------------------------------------------------------
247 /*char *env_get __P((char *, char **)),
248  *arpadate __P((time_t *)),
249  *mkprints __P((unsigned char *, unsigned int)),
250  *first_word __P((char *, char *)),
251  **env_init __P((void)),
252  **env_copy __P((char **)),
253  **env_set __P((char **, char *));
254 
255 user *load_user __P((int, struct passwd *, char *)),
256  *find_user __P((cron_db *, char *));
257 
258 entry *load_entry __P((FILE *, void (*)(),
259  struct passwd *, char **));
260 
261 FILE *cron_popen __P((char *, char *));*/
262 //-- << MODIFIED ---------------------------------------------------------------
263 
264  /* in the C tradition, we only create
265  * variables for the main program, just
266  * extern them elsewhere.
267  */
268 
269 #ifdef MAIN_PROGRAM
270 # if !defined(LINT) && !defined(lint)
271 char *copyright[] = {
272  "@(#) Copyright 1988,1989,1990,1993,1994 by Paul Vixie",
273  "@(#) All rights reserved"
274  };
275 # endif
276 
277 char *MonthNames[] = {
278  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
279  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
280  NULL
281  };
282 
283 char *DowNames[] = {
284  "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
285  NULL
286  };
287 
288 char *ProgramName;
289 int LineNumber;
290 time_t TargetTime;
291 
292 # if DEBUGGING
293 int DebugFlags;
294 char *DebugFlagNames[] = { /* sync with #defines */
295  "ext", "sch", "proc", "pars", "load", "misc", "test", "bit",
296  NULL /* NULL must be last element */
297  };
298 # endif /* DEBUGGING */
299 #else /*MAIN_PROGRAM*/
300 extern char *copyright[],
301  *MonthNames[],
302  *DowNames[],
303  *ProgramName;
304 extern int LineNumber;
305 extern time_t TargetTime;
306 # if DEBUGGING
307 extern int DebugFlags;
308 extern char *DebugFlagNames[];
309 # endif /* DEBUGGING */
310 #endif /*MAIN_PROGRAM*/
Definition: crontab_cron.h:170