]> granicus.if.org Git - fcron/blob - global.h
Added Content-Type and Content-Transfer-Encoding to output emails
[fcron] / global.h
1 /*
2  * FCRON - periodic command scheduler 
3  *
4  *  Copyright 2000-2010 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 <locale.h>
66 #include <nl_types.h>
67 #include <langinfo.h>
68 #include <pwd.h>
69 #include <signal.h>
70
71 #ifdef HAVE_STDARG_H
72 #include <stdarg.h>
73 #endif
74
75 #include <stdio.h>
76 #include <stdlib.h>
77 #include <string.h>
78
79 #ifdef HAVE_STRINGS_H
80 #include <strings.h>
81 #endif
82
83 #ifdef HAVE_SYS_FILE_H
84 #include <sys/file.h>
85 #endif
86
87 #include <sys/stat.h>
88 #include <sys/types.h>
89
90 #ifdef HAVE_SYS_WAIT_H
91 #include <sys/wait.h>
92 #endif
93
94 #ifdef HAVE_SYSLOG_H
95 #include <syslog.h>
96 #endif
97
98 #ifdef TIME_WITH_SYS_TIME
99 #include <time.h>
100 #elif HAVE_SYS_TIME_H
101 #include <sys/time.h>
102 #endif
103
104 #ifdef HAVE_TERMIOS_H
105 #include <termios.h>
106 #endif
107
108 #ifdef HAVE_UNISTD_H
109 #include <unistd.h>
110 #endif
111
112 #ifdef HAVE_FCNTL_H
113 #include <fcntl.h>
114 #elif HAVE_SYS_FCNTL_H
115 #include <sys/fcntl.h>
116 #endif
117
118 #ifdef HAVE_CRED_H
119 #include <cred.h>
120 #endif
121 #ifdef HAVE_UCRED_H
122 #include <ucred.h>
123 #endif
124 #ifdef HAVE_SYS_CRED_H
125 #include <sys/cred.h>
126 #endif
127 #ifdef HAVE_SYS_UCRED_H
128 #include <sys/ucred.h>
129 #endif
130
131 #ifdef HAVE_LIBPAM
132 #include "pam.h"
133 #endif
134
135 #include "bitstring.h"     /* bit arrays */
136 #include "option.h"        /* manage fcrontab's options */
137 #include "env_list.h"      /* manage fcrontab's environment variable lists */
138
139 /* you should not change this (nor need to do it) */
140 #define ERR     -1           
141 #define OK       0
142
143 /* options for local functions */
144 #define STD 0
145
146 /* macros */
147 #ifndef HAVE_SETEUID
148 #define seteuid(arg) setresuid(-1,(arg),-1)
149 #endif
150
151 #ifndef HAVE_SETEGID
152 #define setegid(arg) setresgid(-1,(arg),-1)
153 #endif
154
155 #define Alloc(PTR, TYPE) \
156         if( (PTR = calloc(1, sizeof(TYPE))) == NULL ) \
157             die_e("Could not calloc.");
158
159 #define Set(VAR, VALUE) \
160         { \
161           free_safe(VAR); \
162           VAR = strdup2(VALUE); \
163         }
164
165 #define Skip_blanks(PTR) \
166         while((*(PTR) == ' ') || (*(PTR) == '\t')) \
167             (PTR)++;
168
169 #define Overwrite(x) \
170         do {                     \
171           register char *__xx__; \
172           if ((__xx__=(x)))      \
173             while (*__xx__)      \
174               *__xx__++ = '\0';  \
175         } while (0)
176
177 #define debug if(debug_opt) Debug
178
179 typedef struct cf_t {
180     struct cf_t  *cf_next;
181     struct cl_t  *cf_line_base;
182     char         *cf_user;      /* user-name                                 */
183     env_list_t   *cf_env_list;  /* list of all parsed env var                */
184     int           cf_running;   /* number of jobs running                    */
185     signed char   cf_tzdiff;    /* time diff between system and local hour   */
186 #ifdef WITH_SELINUX
187     security_context_t cf_user_context;
188     security_context_t cf_file_context;
189 #endif
190 } cf_t;
191
192
193 #define OPTION_SIZE 4 /* number of bytes to hold the cl_option bit array */
194 #define LAVG_SIZE 3
195 /* warning : do not change the order of the members of this structure
196  *   because some tests made are dependent to that order */
197 /* warning : if you change a field type, you may have to also make some changes
198  *   in the save/load binary fcrontab functions */
199 typedef struct cl_t {
200     struct cl_t   *cl_next;
201     struct cf_t   *cl_file;       /* the file in which the line is           */
202     char          *cl_shell;      /* shell command                           */
203     char          *cl_runas;      /* determine permissions of the job        */
204     char          *cl_mailto;     /* mail output to cl_mailto                */
205     char          *cl_tz;         /* time zone of the line                   */
206     unsigned long  cl_id;         /* line's unique id number                 */
207     time_t         cl_until;      /* timeout of the wait for a lavg value    */
208     time_t         cl_first;      /* initial delay preserved for volatile entries */
209     time_t         cl_nextexe;    /* time and date of the next execution     */
210     long int       cl_timefreq;   /* Run every n seconds                     */
211     unsigned short cl_remain;     /* remaining until next execution          */
212     unsigned short cl_runfreq;    /* Run once every n matches(=1 for %-lines)*/
213     unsigned char  cl_option[OPTION_SIZE]; /* line's option (see option.h)   */
214     unsigned char  cl_lavg[LAVG_SIZE];/*load averages needed (1,5,15 mins)   */
215     unsigned char  cl_numexe;     /* entries in queues & running processes   */
216     char           cl_nice;       /* nice value to control priority          */
217     unsigned char  cl_jitter;     /* run randomly late up to jitter seconds  */
218     /* see bitstring(3) man page for more details */
219     bitstr_t       bit_decl(cl_mins, 60); /* 0-59                            */
220     bitstr_t       bit_decl(cl_hrs, 24);  /* 0-23                            */
221     bitstr_t       bit_decl(cl_days, 32); /* 1-31                            */
222     bitstr_t       bit_decl(cl_mons, 12); /* 0-11                            */
223     bitstr_t       bit_decl(cl_dow, 8);   /* 0-7, 0 and 7 are both Sunday    */
224 } cl_t;
225
226 typedef struct job_t {
227     struct cl_t  *j_line;
228     struct job_t   *j_next;
229 } job_t;
230
231
232 #if SIZEOF_TIME_T == SIZEOF_SHORT_INT
233 #define ATTR_SIZE_TIMET "h"
234 #define CAST_TIMET_PTR (short int *)
235 #elif SIZEOF_TIME_T == SIZEOF_INT
236 #define ATTR_SIZE_TIMET ""
237 #define CAST_TIMET_PTR (int *)
238 #elif SIZEOF_TIME_T == SIZEOF_LONG_INT
239 #define ATTR_SIZE_TIMET "l"
240 #define CAST_TIMET_PTR (long int *)
241 #elif SIZEOF_TIME_T == SIZEOF_LONG_LONG_INT
242 #define ATTR_SIZE_TIMET "ll"
243 #define CAST_TIMET_PTR (long long int *)
244 #else
245 #error "SIZEOF_TIME_T does not correspond with a known format."
246 #endif
247
248 #if SIZEOF_PID_T == SIZEOF_SHORT_INT
249 #define ATTR_SIZE_PIDT "h"
250 #define CAST_PIDT_PTR (short int *)
251 #elif SIZEOF_PID_T == SIZEOF_INT
252 #define ATTR_SIZE_PIDT ""
253 #define CAST_PIDT_PTR (int *)
254 #elif SIZEOF_PID_T == SIZEOF_LONG_INT
255 #define ATTR_SIZE_PIDT "l"
256 #define CAST_PIDT_PTR (long int *)
257 #elif SIZEOF_PID_T == SIZEOF_LONG_LONG_INT
258 #define ATTR_SIZE_PIDT "ll"
259 #define CAST_PIDT_PTR (long long int *)
260 #else
261 #error "SIZEOF_PID_T does not correspond with a known format."
262 #endif
263
264
265 /* local header files : we include here the headers which may use some types defined
266  *                      above. */
267
268 /* constants for fcrontabs needed to load and save the fcrontabs to disk */
269 #include "save.h"
270 /* log part */
271 #include "log.h"
272 /* functions used by fcrontab, fcrondyn, and fcron */
273 #include "subs.h"
274
275
276 #endif /* __GLOBAL_H__ */
277