]> granicus.if.org Git - fcron/blob - global.h
- Rewrote the env var management code with Vixie cron compatibility in mind
[fcron] / global.h
1 /*
2  * FCRON - periodic command scheduler 
3  *
4  *  Copyright 2000-2009 Thibault Godouet <fcron@free.fr>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  * 
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  *  The GNU General Public License can also be found in the file
21  *  `LICENSE' that comes with the fcron source distribution.
22  */
23
24  /* $Id: global.h,v 1.51 2007-06-24 22:01:49 thib Exp $ */
25
26
27 /* 
28    WARNING : this file should not be modified.
29    Compilation's options are in config.h
30 */
31
32 #ifndef __GLOBAL_H__
33 #define __GLOBAL_H__
34
35 /* config.h must be included before every other includes 
36  * (contains the compilation options) */
37 #include "config.h"
38
39
40 #include <ctype.h>
41
42 #ifdef HAVE_ERRNO_H
43 #include <errno.h>
44 #endif
45
46 #ifdef WITH_SELINUX
47 #include <selinux.h>
48 #include <get_context_list.h>
49 #include <selinux/flask.h>
50 #include <selinux/av_permissions.h>
51 #endif
52
53 #ifdef HAVE_GETOPT_H
54 #include <getopt.h>
55 #endif
56
57 #ifdef HAVE_GRP_H
58 #include <grp.h>
59 #endif
60
61 #ifdef HAVE_LIMITS_H
62 #include <limits.h>
63 #endif
64
65 #include <pwd.h>
66 #include <signal.h>
67
68 #ifdef HAVE_STDARG_H
69 #include <stdarg.h>
70 #endif
71
72 #include <stdio.h>
73 #include <stdlib.h>
74 #include <string.h>
75
76 #ifdef HAVE_STRINGS_H
77 #include <strings.h>
78 #endif
79
80 #ifdef HAVE_SYS_FILE_H
81 #include <sys/file.h>
82 #endif
83
84 #include <sys/stat.h>
85 #include <sys/types.h>
86
87 #ifdef HAVE_SYS_WAIT_H
88 #include <sys/wait.h>
89 #endif
90
91 #ifdef HAVE_SYSLOG_H
92 #include <syslog.h>
93 #endif
94
95 #ifdef TIME_WITH_SYS_TIME
96 #include <time.h>
97 #elif HAVE_SYS_TIME_H
98 #include <sys/time.h>
99 #endif
100
101 #ifdef HAVE_TERMIOS_H
102 #include <termios.h>
103 #endif
104
105 #ifdef HAVE_UNISTD_H
106 #include <unistd.h>
107 #endif
108
109 #ifdef HAVE_FCNTL_H
110 #include <fcntl.h>
111 #elif HAVE_SYS_FCNTL_H
112 #include <sys/fcntl.h>
113 #endif
114
115 #ifdef HAVE_CRED_H
116 #include <cred.h>
117 #endif
118 #ifdef HAVE_UCRED_H
119 #include <ucred.h>
120 #endif
121 #ifdef HAVE_SYS_CRED_H
122 #include <sys/cred.h>
123 #endif
124 #ifdef HAVE_SYS_UCRED_H
125 #include <sys/ucred.h>
126 #endif
127
128 #ifdef HAVE_LIBPAM
129 #include "pam.h"
130 #endif
131
132 #include "bitstring.h"     /* bit arrays */
133 #include "option.h"        /* manage fcrontab's options */
134 #include "env_list.h"      /* manage fcrontab's environment variable lists */
135
136 /* you should not change this (nor need to do it) */
137 #define ERR     -1           
138 #define OK       0
139
140 /* options for local functions */
141 #define STD 0
142
143 /* macros */
144 #ifndef HAVE_SETEUID
145 #define seteuid(arg) setresuid(-1,(arg),-1)
146 #endif
147
148 #ifndef HAVE_SETEGID
149 #define setegid(arg) setresgid(-1,(arg),-1)
150 #endif
151
152 #define Alloc(PTR, TYPE) \
153         if( (PTR = calloc(1, sizeof(TYPE))) == NULL ) \
154             die_e("Could not calloc.");
155
156 #define Set(VAR, VALUE) \
157         { \
158           free(VAR); \
159           VAR = strdup2(VALUE); \
160         }
161
162 #define Flush(VAR) \
163         { \
164           free(VAR); \
165           VAR = NULL; \
166         }
167
168 #define Skip_blanks(PTR) \
169         while((*(PTR) == ' ') || (*(PTR) == '\t')) \
170             (PTR)++;
171
172 #define Overwrite(x) \
173         do {                     \
174           register char *__xx__; \
175           if ((__xx__=(x)))      \
176             while (*__xx__)      \
177               *__xx__++ = '\0';  \
178         } while (0)
179
180 #define debug if(debug_opt) Debug
181
182 typedef struct cf_t {
183     struct cf_t  *cf_next;
184     struct cl_t  *cf_line_base;
185     char         *cf_user;      /* user-name                                 */
186     env_list_t   *cf_env_list;  /* list of all parsed env var                */
187     int           cf_running;   /* number of jobs running                    */
188     signed char   cf_tzdiff;    /* time diff between system and local hour   */
189 #ifdef WITH_SELINUX
190     security_context_t cf_user_context;
191     security_context_t cf_file_context;
192 #endif
193 } cf_t;
194
195
196 #define OPTION_SIZE 4
197 #define LAVG_SIZE 3
198 /* warning : do not change the order of the members of this structure
199  *   because some tests made are dependent to that order */
200 /* warning : if you change a field type, you may have to also make some changes
201  *   in the save/load binary fcrontab functions */
202 typedef struct cl_t {
203     struct cl_t   *cl_next;
204     struct cf_t   *cl_file;       /* the file in which the line is           */
205     char          *cl_shell;      /* shell command                           */
206     char          *cl_runas;      /* determine permissions of the job        */
207     char          *cl_mailto;     /* mail output to cl_mailto                */
208     char          *cl_tz;         /* time zone of the line                   */
209     long int       cl_id;         /* line's unique id number                 */
210     time_t         cl_until;      /* timeout of the wait for a lavg value    */
211     time_t         cl_first;      /* initial delay preserved for volatile entries */
212     time_t         cl_nextexe;    /* time and date of the next execution     */
213     long int       cl_timefreq;   /* Run every n seconds                     */
214     unsigned short cl_remain;     /* remaining until next execution          */
215     unsigned short cl_runfreq;    /* Run once every n matches(=1 for %-lines)*/
216     unsigned char  cl_option[OPTION_SIZE]; /* line's option (see option.h)   */
217     unsigned char  cl_lavg[LAVG_SIZE];/*load averages needed (1,5,15 mins)   */
218     unsigned char  cl_numexe;     /* entries in queues & running processes   */
219     char           cl_nice;       /* nice value to control priority          */
220     unsigned char  cl_jitter;     /* run randomly late up to jitter seconds  */
221     /* see bitstring(3) man page for more details */
222     bitstr_t       bit_decl(cl_mins, 60); /* 0-59                            */
223     bitstr_t       bit_decl(cl_hrs, 24);  /* 0-23                            */
224     bitstr_t       bit_decl(cl_days, 32); /* 1-31                            */
225     bitstr_t       bit_decl(cl_mons, 12); /* 0-11                            */
226     bitstr_t       bit_decl(cl_dow, 8);   /* 0-7, 0 and 7 are both Sunday    */
227 } cl_t;
228
229 typedef struct job_t {
230     struct cl_t  *j_line;
231     struct job_t   *j_next;
232 } job_t;
233
234
235 #if SIZEOF_TIME_T == SIZEOF_SHORT_INT
236 #define ATTR_SIZE_TIMET "h"
237 #define CAST_TIMET_PTR (short int *)
238 #elif SIZEOF_TIME_T == SIZEOF_INT
239 #define ATTR_SIZE_TIMET ""
240 #define CAST_TIMET_PTR (int *)
241 #elif SIZEOF_TIME_T == SIZEOF_LONG_INT
242 #define ATTR_SIZE_TIMET "l"
243 #define CAST_TIMET_PTR (long int *)
244 #elif SIZEOF_TIME_T == SIZEOF_LONG_LONG_INT
245 #define ATTR_SIZE_TIMET "ll"
246 #define CAST_TIMET_PTR (long long int *)
247 #else
248 #error "SIZEOF_TIME_T does not correspond with a known format."
249 #endif
250
251 #if SIZEOF_PID_T == SIZEOF_SHORT_INT
252 #define ATTR_SIZE_PIDT "h"
253 #define CAST_PIDT_PTR (short int *)
254 #elif SIZEOF_PID_T == SIZEOF_INT
255 #define ATTR_SIZE_PIDT ""
256 #define CAST_PIDT_PTR (int *)
257 #elif SIZEOF_PID_T == SIZEOF_LONG_INT
258 #define ATTR_SIZE_PIDT "l"
259 #define CAST_PIDT_PTR (long int *)
260 #elif SIZEOF_PID_T == SIZEOF_LONG_LONG_INT
261 #define ATTR_SIZE_PIDT "ll"
262 #define CAST_PIDT_PTR (long long int *)
263 #else
264 #error "SIZEOF_PID_T does not correspond with a known format."
265 #endif
266
267
268 /* local header files : we include here the headers which may use some types defined
269  *                      above. */
270
271 /* constants for fcrontabs needed to load and save the fcrontabs to disk */
272 #include "save.h"
273 /* log part */
274 #include "log.h"
275 /* functions used by fcrontab, fcrondyn, and fcron */
276 #include "subs.h"
277
278
279 #endif /* __GLOBAL_H__ */
280