]> granicus.if.org Git - fcron/blob - global.h
fix several security vulnerabilities found by iDEFENSE in fcronsighup
[fcron] / global.h
1 /*
2  * FCRON - periodic command scheduler 
3  *
4  *  Copyright 2000-2004 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.43 2004-11-13 19:42:57 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_SYS_TERMIOS_H
102 #include <sys/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_LIBPAM
116 #include "pam.h"
117 #endif
118
119 #include "bitstring.h"     /* bit arrays */
120 #include "option.h"        /* manage fcrontab's options */
121
122 /* you should not change this (nor need to do it) */
123 #define ERR     -1           
124 #define OK       0
125
126 /* options for local functions */
127 #define STD 0
128
129 /* macros */
130 #define Alloc(PTR, TYPE) \
131         if( (PTR = calloc(1, sizeof(TYPE))) == NULL ) \
132             die_e("Could not calloc.");
133
134 #define Set(VAR, VALUE) \
135         { \
136           free(VAR); \
137           VAR = strdup2(VALUE); \
138         }
139
140 #define Flush(VAR) \
141         { \
142           free(VAR); \
143           VAR = NULL; \
144         }
145
146 #define Skip_blanks(PTR) \
147         while((*(PTR) == ' ') || (*(PTR) == '\t')) \
148             (PTR)++;
149
150 #define Overwrite(x) \
151         do {                     \
152           register char *__xx__; \
153           if ((__xx__=(x)))      \
154             while (*__xx__)      \
155               *__xx__++ = '\0';  \
156         } while (0)
157
158
159 #define debug if(debug_opt) Debug
160
161 typedef struct env_t {
162     char         *e_val;        /* env value                            */
163     struct env_t *e_next;
164 } env_t ;
165
166 typedef struct cf_t {
167     struct cf_t  *cf_next;
168     struct cl_t  *cf_line_base;
169     char         *cf_user;      /* user-name                                 */
170     struct env_t *cf_env_base;  /* list of all env variables to set          */
171     int           cf_running;   /* number of jobs running                    */
172     signed char   cf_tzdiff;    /* time diff between system and local hour   */
173 #ifdef WITH_SELINUX
174     security_context_t cf_user_context;
175     security_context_t cf_file_context;
176 #endif
177 } cf_t;
178
179
180 #define OPTION_SIZE 4
181 #define LAVG_SIZE 3
182 /* warning : do not change the order of the members of this structure
183  *   because some tests made are dependent to that order */
184 /* warning : if you change a field type, you may have to also make some changes
185  *   in the save/load binary fcrontab functions */
186 typedef struct cl_t {
187     struct cl_t   *cl_next;
188     struct cf_t   *cl_file;       /* the file in which the line is           */
189     char          *cl_shell;      /* shell command                           */
190     char          *cl_runas;      /* determine permissions of the job        */
191     char          *cl_mailto;     /* mail output to cl_mailto                */
192     long int       cl_id;         /* line's unique id number                 */
193     time_t         cl_until;      /* timeout of the wait for a lavg value    */
194     time_t         cl_first;      /* initial delay preserved for volatile entries */
195     time_t         cl_nextexe;    /* time and date of the next execution     */
196     long int       cl_timefreq;   /* Run every n seconds                     */
197     unsigned short cl_remain;     /* remaining until next execution          */
198     unsigned short cl_runfreq;    /* Run once every n matches                */
199     unsigned char  cl_option[OPTION_SIZE]; /* line's option (see option.h)   */
200     unsigned char  cl_lavg[LAVG_SIZE];/*load averages needed (1,5,15 mins)   */
201     unsigned char  cl_numexe;     /* entries in queues & running processes   */
202     char           cl_nice;       /* nice value to control priority          */
203     /* see bitstring(3) man page for more details */
204     bitstr_t       bit_decl(cl_mins, 60); /* 0-59                            */
205     bitstr_t       bit_decl(cl_hrs, 24);  /* 0-23                            */
206     bitstr_t       bit_decl(cl_days, 32); /* 1-31                            */
207     bitstr_t       bit_decl(cl_mons, 12); /* 0-11                            */
208     bitstr_t       bit_decl(cl_dow, 8);   /* 0-7, 0 and 7 are both Sunday    */
209 } cl_t;
210
211 typedef struct job_t {
212     struct cl_t  *j_line;
213     struct job_t   *j_next;
214 } job_t;
215
216 typedef struct lavg_t {
217     struct cl_t *l_line;  
218     time_t       l_until;   /* the timeout of the wait for load averages */
219 } lavg_t;
220
221 typedef struct exe_t {
222     struct cl_t *e_line;
223     pid_t        e_ctrl_pid; /* pid of the fcron process controling the job */
224     pid_t        e_job_pid;  /* pid of the job itself */
225 } exe_t;
226
227
228 /* local header files : we include here the headers which may use some types defined
229  *                      above. */
230
231 /* constants for fcrontabs needed to load and save the fcrontabs to disk */
232 #include "save.h"
233 /* log part */
234 #include "log.h"
235 /* functions used by fcrontab, fcrondyn, and fcron */
236 #include "subs.h"
237
238
239 #endif /* __GLOBAL_H__ */
240