xref: /illumos-gate/usr/src/cmd/cron/cron.h (revision b4fb003914e70b41d96dec8011864f6af1faf3ef)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
28  * Copyright 2022 Sebastian Wiedenroth
29  */
30 
31 #ifndef	_CRON_H
32 #define	_CRON_H
33 
34 #include <unistd.h>
35 
36 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
37 /*	  All Rights Reserved	*/
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 #define	FALSE		0
44 #define	TRUE		1
45 #define	MINUTE		60L
46 #define	HOUR		60L*60L
47 #define	DAY		24L*60L*60L
48 #define	NQUEUE		26		/* number of queues available */
49 #define	ATEVENT		0
50 #define	BATCHEVENT	1
51 #define	CRONEVENT	2
52 
53 #define	ADD		'a'
54 #define	DELETE		'd'
55 #define	AT		'a'
56 #define	CRON		'c'
57 #define	REFRESH		'r'
58 
59 #define	QUE(x)		('a'+(x))
60 #define	RCODE(x)	(((x)>>8)&0377)
61 #define	TSTAT(x)	((x)&0377)
62 
63 /* This constant must be at least sysconf(_SC_LOGIN_NAME_MAX) in size */
64 #define	UNAMESIZE	32	/* max chars in a user name */
65 
66 #define	FLEN	UNAMESIZE
67 #define	LLEN	UNAMESIZE
68 
69 /*
70  * structure used for passing messages from the at and crontab commands to cron
71  */
72 struct	message {
73 	char	etype;
74 	char	action;
75 	char	fname[FLEN];
76 	char	logname[LLEN];
77 };
78 
79 /*
80  * Errors from the crontab field parser.
81  */
82 typedef enum {
83 	CFOK = 0,
84 	CFEOLN,
85 	CFUNEXPECT,
86 	CFOUTOFBOUND,
87 	CFEOVERFLOW,
88 	CFENOMEM
89 } cferror_t;
90 
91 #define	CRONDIR		"/var/spool/cron/crontabs"
92 #define	ATDIR		"/var/spool/cron/atjobs"
93 #define	ACCTFILE	"/var/cron/log"
94 #define	CRONALLOW	"/etc/cron.d/cron.allow"
95 #define	CRONDENY	"/etc/cron.d/cron.deny"
96 #define	ATALLOW		"/etc/cron.d/at.allow"
97 #define	ATDENY		"/etc/cron.d/at.deny"
98 #define	PROTO		"/etc/cron.d/.proto"
99 #define	QUEDEFS		"/etc/cron.d/queuedefs"
100 #define	FIFO		"/etc/cron.d/FIFO"
101 #define	DEFFILE		"/etc/default/cron"
102 
103 #define	SHELL		"/usr/bin/sh"	/* shell to execute */
104 
105 #define	ENV_SHELL		"SHELL="
106 #define	ENV_TZ			"TZ="
107 #define	ENV_HOME		"HOME="
108 #define	ENV_RANDOM_DELAY	"RANDOM_DELAY="
109 
110 #define	CTLINESIZE	1000	/* max chars in a crontab line */
111 
112 extern int	allowed(char *, char *, char *);
113 extern int	days_in_mon(int, int);
114 extern char	*errmsg(int);
115 extern char	*getuser(uid_t);
116 extern void	cron_sendmsg(char, char *, char *, char);
117 extern time_t	 num(char **);
118 extern void	*xmalloc(size_t);
119 extern void	*xcalloc(size_t, size_t);
120 extern char	*xstrdup(const char *);
121 extern int	isvalid_shell(const char *shell);
122 extern int	isvalid_dir(const char *dir);
123 
124 extern int	cron_admin(const char *);
125 extern cferror_t next_field(uint_t, uint_t, char *, int *, char **);
126 
127 #ifdef	__cplusplus
128 }
129 #endif
130 
131 #endif	/* _CRON_H */
132