1 /*
2  * $Id: macros.h,v 1.9 2004/01/23 18:56:43 vixie Exp $
3  */
4 
5 /*
6  * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
7  * Copyright (c) 1997,2000 by Internet Software Consortium, Inc.
8  *
9  * Permission to use, copy, modify, and distribute this software for any
10  * purpose with or without fee is hereby granted, provided that the above
11  * copyright notice and this permission notice appear in all copies.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
14  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
16  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
19  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  */
21 
22 	/* these are really immutable, and are
23 	 *   defined for symbolic convenience only
24 	 * TRUE, FALSE, and ERR must be distinct
25 	 * ERR must be < OK.
26 	 */
27 #define TRUE		1
28 #define FALSE		0
29 	/* system calls return this on success */
30 #define OK		0
31 	/*   or this on error */
32 #define ERR		(-1)
33 
34 	/* turn this on to get '-x' code */
35 #ifndef DEBUGGING
36 #define DEBUGGING	FALSE
37 #endif
38 
39 #define	INIT_PID	1	/* parent of orphans */
40 #define READ_PIPE	0	/* which end of a pipe pair do you read? */
41 #define WRITE_PIPE	1	/*   or write to? */
42 #define STDIN		0	/* what is stdin's file descriptor? */
43 #define STDOUT		1	/*   stdout's? */
44 #define STDERR		2	/*   stderr's? */
45 #define ERROR_EXIT	1	/* exit() with this will scare the shell */
46 #define	OK_EXIT		0	/* exit() with this is considered 'normal' */
47 #define	MAX_FNAME	100	/* max length of internally generated fn */
48 #define	MAX_COMMAND	1000	/* max length of internally generated cmd */
49 #define	MAX_ENVSTR	1000	/* max length of envvar=value\0 strings */
50 #define	MAX_TEMPSTR	100	/* obvious */
51 #define	MAX_UNAME	33	/* max length of username, should be overkill */
52 #define	ROOT_UID	0	/* don't change this, it really must be root */
53 #define	ROOT_USER	"root"	/* ditto */
54 
55 				/* NOTE: these correspond to DebugFlagNames,
56 				 *	defined below.
57 				 */
58 #define	DEXT		0x0001	/* extend flag for other debug masks */
59 #define	DSCH		0x0002	/* scheduling debug mask */
60 #define	DPROC		0x0004	/* process control debug mask */
61 #define	DPARS		0x0008	/* parsing debug mask */
62 #define	DLOAD		0x0010	/* database loading debug mask */
63 #define	DMISC		0x0020	/* misc debug mask */
64 #define	DTEST		0x0040	/* test mode: don't execute any commands */
65 
66 #define	PPC_NULL	((const char **)NULL)
67 
68 #ifndef MAXHOSTNAMELEN
69 #define MAXHOSTNAMELEN 64
70 #endif
71 
72 #define	Skip_Blanks(c, f) \
73 			while (c == '\t' || c == ' ') \
74 				c = get_char(f);
75 
76 #define	Skip_Nonblanks(c, f) \
77 			while (c!='\t' && c!=' ' && c!='\n' && c != EOF) \
78 				c = get_char(f);
79 
80 #if DEBUGGING
81 # define Debug(mask, message) \
82 			if ((DebugFlags & (mask)) != 0) \
83 				printf message;
84 #else /* !DEBUGGING */
85 # define Debug(mask, message) \
86 			;
87 #endif /* DEBUGGING */
88 
89 #define	MkUpper(ch)	(islower(ch) ? toupper(ch) : ch)
90 #define	Set_LineNum(ln)	{Debug(DPARS|DEXT,("linenum=%d\n",ln)); \
91 			 LineNumber = ln; \
92 			}
93 
94 #ifdef HAVE_TM_GMTOFF
95 #define	get_gmtoff(c, t)	((t)->tm_gmtoff)
96 #endif
97 
98 #define	SECONDS_PER_MINUTE	60
99 #define	SECONDS_PER_HOUR	3600
100 
101 #define	FIRST_MINUTE	0
102 #define	LAST_MINUTE	59
103 #define	MINUTE_COUNT	(LAST_MINUTE - FIRST_MINUTE + 1)
104 
105 #define	FIRST_HOUR	0
106 #define	LAST_HOUR	23
107 #define	HOUR_COUNT	(LAST_HOUR - FIRST_HOUR + 1)
108 
109 #define	FIRST_DOM	1
110 #define	LAST_DOM	31
111 #define	DOM_COUNT	(LAST_DOM - FIRST_DOM + 1)
112 
113 #define	FIRST_MONTH	1
114 #define	LAST_MONTH	12
115 #define	MONTH_COUNT	(LAST_MONTH - FIRST_MONTH + 1)
116 
117 /* note on DOW: 0 and 7 are both Sunday, for compatibility reasons. */
118 #define	FIRST_DOW	0
119 #define	LAST_DOW	7
120 #define	DOW_COUNT	(LAST_DOW - FIRST_DOW + 1)
121 
122 /*
123  * Because crontab/at files may be owned by their respective users we
124  * take extreme care in opening them.  If the OS lacks the O_NOFOLLOW
125  * we will just have to live without it.  In order for this to be an
126  * issue an attacker would have to subvert group CRON_GROUP.
127  */
128 #ifndef O_NOFOLLOW
129 #define O_NOFOLLOW	0
130 #endif
131