1 /* 2 * FCRON - periodic command scheduler 3 * 4 * Copyright 2000-2016 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 25 26 /* 27 WARNING : this file should not be modified. 28 Compilation's options are in config.h 29 */ 30 31 #ifndef __GLOBAL_H__ 32 #define __GLOBAL_H__ 33 34 /* config.h must be included before every other includes 35 * (contains the compilation options) */ 36 #include "config.h" 37 38 39 #include <ctype.h> 40 41 #ifdef HAVE_ERRNO_H 42 #include <errno.h> 43 #endif 44 45 #ifdef WITH_SELINUX 46 #include <selinux.h> 47 #include <get_context_list.h> 48 #include <selinux/flask.h> 49 #include <selinux/av_permissions.h> 50 #endif 51 52 #ifdef HAVE_GETOPT_H 53 #include <getopt.h> 54 #endif 55 56 #ifdef HAVE_GRP_H 57 #include <grp.h> 58 #endif 59 60 #ifdef HAVE_LIMITS_H 61 #include <limits.h> 62 #endif 63 64 #include <locale.h> 65 #include <nl_types.h> 66 #include <langinfo.h> 67 #include <pwd.h> 68 #include <signal.h> 69 70 #ifdef HAVE_STDARG_H 71 #include <stdarg.h> 72 #endif 73 74 #include <stdio.h> 75 #include <stdlib.h> 76 #include <string.h> 77 78 #ifdef HAVE_STRINGS_H 79 #include <strings.h> 80 #endif 81 82 #ifdef HAVE_SYS_FILE_H 83 #include <sys/file.h> 84 #endif 85 86 #include <sys/stat.h> 87 #include <sys/types.h> 88 89 #ifdef HAVE_SYS_WAIT_H 90 #include <sys/wait.h> 91 #endif 92 93 #ifdef HAVE_SYSLOG_H 94 #include <syslog.h> 95 #endif 96 97 #ifdef TIME_WITH_SYS_TIME 98 #include <time.h> 99 #elif HAVE_SYS_TIME_H 100 #include <sys/time.h> 101 #endif 102 103 #ifdef HAVE_TERMIOS_H 104 #include <termios.h> 105 #endif 106 107 #ifdef HAVE_UNISTD_H 108 #include <unistd.h> 109 #endif 110 111 #ifdef HAVE_FCNTL_H 112 #include <fcntl.h> 113 #elif HAVE_SYS_FCNTL_H 114 #include <sys/fcntl.h> 115 #endif 116 117 #ifdef HAVE_CRED_H 118 #include <cred.h> 119 #endif 120 #ifdef HAVE_UCRED_H 121 #include <ucred.h> 122 #endif 123 #ifdef HAVE_SYS_CRED_H 124 #include <sys/cred.h> 125 #endif 126 #ifdef HAVE_SYS_UCRED_H 127 #include <sys/ucred.h> 128 #endif 129 130 #ifdef WITH_AUDIT 131 #include <libaudit.h> 132 #endif 133 134 #ifdef HAVE_LIBPAM 135 #include "pam.h" 136 #endif 137 138 #include "bitstring.h" /* bit arrays */ 139 #include "option.h" /* manage fcrontab's options */ 140 #include "env_list.h" /* manage fcrontab's environment variable lists */ 141 #include "cl.h" /* Cron Line cl_t type and associated functions */ 142 143 /* you should not change this (nor need to do it) */ 144 #define ERR -1 145 #define OK 0 146 147 /* options for local functions */ 148 #define STD 0 149 150 /* Approximate max value of time_t which localtime() allows: on a 64bits system, 151 * this is less than LONG_MAX (64bits) as this is limited by struct tm's tm_year 152 * which is a (not long) int (32bits). 153 * As a time_t of INT_MAX=2^31 is 'only' in year 2038, we try to use a larger value 154 * if we can. */ 155 // FIXME: test on 32bit system 156 /* 2^33 = 8589934592, so LONG is 64bits at least */ 157 #if (LONG_MAX > INT_MAX) && (LONG_MAX > 8589934592) 158 /* defined as time_t of 1st Jan of year (SHRT_MAX-1900) at 00:00:00 */ 159 #define TIME_T_MAX 971859427200 160 #else 161 /* struct tm's tm_year is of type int, and tm_year will always be smaller than 162 * the equivalent time_t, so INT_MAX is always a safe max value for time_t. */ 163 #define TIME_T_MAX INT_MAX 164 #endif 165 166 /* macros */ 167 #ifndef HAVE_SETEUID 168 #define seteuid(arg) setresuid(-1,(arg),-1) 169 #endif 170 171 #ifndef HAVE_SETEGID 172 #define setegid(arg) setresgid(-1,(arg),-1) 173 #endif 174 175 #define Skip_blanks(PTR) \ 176 while((*(PTR) == ' ') || (*(PTR) == '\t')) \ 177 (PTR)++; 178 179 #define Overwrite(x) \ 180 do { \ 181 register char *__xx__; \ 182 if ((__xx__=(x))) \ 183 while (*__xx__) \ 184 *__xx__++ = '\0'; \ 185 } while (0) 186 187 #define debug if(debug_opt) Debug 188 189 typedef struct cf_t { 190 struct cf_t *cf_next; 191 struct cl_t *cf_line_base; 192 char *cf_user; /* user-name */ 193 env_list_t *cf_env_list; /* list of all parsed env var */ 194 int cf_running; /* number of jobs running */ 195 signed char cf_tzdiff; /* time diff between system and local hour */ 196 #ifdef WITH_SELINUX 197 security_context_t cf_user_context; 198 security_context_t cf_file_context; 199 #endif 200 } cf_t; 201 202 203 typedef struct job_t { 204 struct cl_t *j_line; 205 struct job_t *j_next; 206 } job_t; 207 208 209 #if SIZEOF_TIME_T == SIZEOF_SHORT_INT 210 #define ATTR_SIZE_TIMET "h" 211 #define CAST_TIMET_PTR (short int *) 212 #elif SIZEOF_TIME_T == SIZEOF_INT 213 #define ATTR_SIZE_TIMET "" 214 #define CAST_TIMET_PTR (int *) 215 #elif SIZEOF_TIME_T == SIZEOF_LONG_INT 216 #define ATTR_SIZE_TIMET "l" 217 #define CAST_TIMET_PTR (long int *) 218 #elif SIZEOF_TIME_T == SIZEOF_LONG_LONG_INT 219 #define ATTR_SIZE_TIMET "ll" 220 #define CAST_TIMET_PTR (long long int *) 221 #else 222 #error "SIZEOF_TIME_T does not correspond with a known format." 223 #endif 224 225 #if SIZEOF_PID_T == SIZEOF_SHORT_INT 226 #define ATTR_SIZE_PIDT "h" 227 #define CAST_PIDT_PTR (short int *) 228 #elif SIZEOF_PID_T == SIZEOF_INT 229 #define ATTR_SIZE_PIDT "" 230 #define CAST_PIDT_PTR (int *) 231 #elif SIZEOF_PID_T == SIZEOF_LONG_INT 232 #define ATTR_SIZE_PIDT "l" 233 #define CAST_PIDT_PTR (long int *) 234 #elif SIZEOF_PID_T == SIZEOF_LONG_LONG_INT 235 #define ATTR_SIZE_PIDT "ll" 236 #define CAST_PIDT_PTR (long long int *) 237 #else 238 #error "SIZEOF_PID_T does not correspond with a known format." 239 #endif 240 241 242 /* local header files : we include here the headers which may use some types defined 243 * above. */ 244 245 /* constants for fcrontabs needed to load and save the fcrontabs to disk */ 246 #include "save.h" 247 /* log part */ 248 #include "log.h" 249 /* functions used by fcrontab, fcrondyn, and fcron */ 250 #include "subs.h" 251 /* file related helper functions */ 252 #include "filesubs.h" 253 254 #endif /* __GLOBAL_H__ */ 255