[1] | 1 | /* SAMHAIN file system integrity testing */
|
---|
| 2 | /* Copyright (C) 1999 Rainer Wichmann */
|
---|
| 3 | /* */
|
---|
| 4 | /* This program is free software; you can redistribute it */
|
---|
| 5 | /* and/or modify */
|
---|
| 6 | /* it under the terms of the GNU General Public License as */
|
---|
| 7 | /* 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
---|
| 19 |
|
---|
| 20 | #ifndef SAMHAIN_H
|
---|
| 21 | #define SAMHAIN_H
|
---|
| 22 |
|
---|
| 23 | #include <sys/types.h>
|
---|
| 24 | #include "slib.h"
|
---|
| 25 |
|
---|
| 26 | #ifdef SH_ENCRYPT
|
---|
| 27 | #include "rijndael-api-fst.h"
|
---|
| 28 | #endif
|
---|
| 29 |
|
---|
| 30 | /**************************************************
|
---|
| 31 | *
|
---|
| 32 | * STANDARD DEFINES
|
---|
| 33 | *
|
---|
| 34 | **************************************************/
|
---|
| 35 |
|
---|
[295] | 36 | /* IPv6 */
|
---|
| 37 | #if defined(HAVE_GETNAMEINFO) && defined(HAVE_GETADDRINFO)
|
---|
| 38 |
|
---|
| 39 | #if defined(SH_COMPILE_STATIC) && defined(__linux__)
|
---|
| 40 | #undef USE_IPVX
|
---|
| 41 | #define SH_SOCKMAX 1
|
---|
| 42 | #else
|
---|
| 43 |
|
---|
| 44 | #if defined(USE_IPV4)
|
---|
| 45 | #undef USE_IPVX
|
---|
| 46 | #else
|
---|
| 47 | #define USE_IPVX 1
|
---|
| 48 | #endif
|
---|
| 49 |
|
---|
| 50 | #define SH_SOCKMAX 8
|
---|
| 51 | #endif
|
---|
| 52 |
|
---|
| 53 | #else
|
---|
| 54 | #undef USE_IPVX
|
---|
| 55 | #define SH_SOCKMAX 1
|
---|
| 56 | #endif
|
---|
| 57 |
|
---|
| 58 | /* end IPv6 */
|
---|
| 59 |
|
---|
[1] | 60 | #define REPLACE_OLD
|
---|
| 61 |
|
---|
[283] | 62 | /* Standard buffer sizes.
|
---|
| 63 | * IPv6 is 8 groups of 4 hex digits seperated by colons.
|
---|
[1] | 64 | */
|
---|
[295] | 65 | #define SH_IP_BUF 48
|
---|
[1] | 66 | #define SH_MINIBUF 64
|
---|
| 67 | #define SH_BUFSIZE 1024
|
---|
| 68 | #define SH_MAXBUF 4096
|
---|
| 69 | #define SH_PATHBUF 256
|
---|
[170] | 70 | #define SH_MSG_BUF 64512
|
---|
[1] | 71 |
|
---|
[132] | 72 | #define SH_ERRBUF_SIZE 64
|
---|
[131] | 73 |
|
---|
[170] | 74 | /* MAX_PATH_STORE must be >= KEY_LEN
|
---|
| 75 | */
|
---|
| 76 | #define MAX_PATH_STORE 12287
|
---|
| 77 |
|
---|
[1] | 78 | /* Sizes for arrays (user, group, timestamp).
|
---|
| 79 | */
|
---|
[40] | 80 | #define SOCKPASS_MAX 14
|
---|
[149] | 81 | #define USER_MAX 20
|
---|
| 82 | #define GROUP_MAX 20
|
---|
| 83 | #define TIM_MAX 32
|
---|
[1] | 84 |
|
---|
[149] | 85 | #define CMODE_SIZE 11
|
---|
[40] | 86 |
|
---|
[149] | 87 | #define ATTRBUF_SIZE 16
|
---|
| 88 | #define ATTRBUF_USED 12
|
---|
| 89 |
|
---|
[1] | 90 | /* The number of bytes in a key,
|
---|
| 91 | * the number of chars in its hex repesentation,
|
---|
| 92 | * and the block size of the hash algorithm.
|
---|
| 93 | */
|
---|
| 94 | #define KEY_BYT 24
|
---|
| 95 | #define KEY_LEN 48
|
---|
| 96 | #define KEY_BLOCK 24
|
---|
[133] | 97 | #define KEYBUF_SIZE (KEY_LEN+1)
|
---|
[1] | 98 |
|
---|
| 99 | /* The length of the compiled-in password.
|
---|
| 100 | */
|
---|
| 101 | #define PW_LEN 8
|
---|
| 102 |
|
---|
| 103 | #undef GOOD
|
---|
| 104 | #define GOOD 1
|
---|
| 105 | #undef BAD
|
---|
| 106 | #define BAD 0
|
---|
| 107 | #undef ON
|
---|
| 108 | #define ON 1
|
---|
| 109 | #undef OFF
|
---|
| 110 | #define OFF 0
|
---|
| 111 | #undef S_TRUE
|
---|
| 112 | #define S_TRUE 1
|
---|
| 113 | #undef S_FALSE
|
---|
| 114 | #define S_FALSE 0
|
---|
| 115 |
|
---|
| 116 | /* An unsigned integer guaranteed to be 32 bit.
|
---|
| 117 | */
|
---|
| 118 | #if defined(HAVE_INT_32)
|
---|
| 119 | #define UINT32 unsigned int
|
---|
| 120 | #define SINT32 int
|
---|
| 121 | #elif defined(HAVE_LONG_32)
|
---|
| 122 | #define UINT32 unsigned long
|
---|
| 123 | #define SINT32 long
|
---|
| 124 | #elif defined(HAVE_SHORT_32)
|
---|
| 125 | #define UINT32 unsigned short
|
---|
| 126 | #define SINT32 short
|
---|
[415] | 127 | #else
|
---|
| 128 | #error "No 32 bit integer type found"
|
---|
[1] | 129 | #endif
|
---|
| 130 |
|
---|
| 131 | #ifdef HAVE_INTTYPES_H
|
---|
| 132 | #include <inttypes.h>
|
---|
[156] | 133 | #endif
|
---|
[1] | 134 | #ifdef HAVE_STDINT_H
|
---|
| 135 | #include <stdint.h>
|
---|
| 136 | #endif
|
---|
| 137 |
|
---|
[265] | 138 | #if !defined(HAVE_UINT16_T)
|
---|
| 139 | #define UINT16 unsigned short
|
---|
| 140 | #else
|
---|
| 141 | #define UINT16 uint16_t
|
---|
| 142 | #endif
|
---|
| 143 |
|
---|
[156] | 144 | #if !defined(HAVE_UINT64_T)
|
---|
[1] | 145 |
|
---|
| 146 | #ifdef HAVE_LONG_LONG_64
|
---|
| 147 | #define UINT64 unsigned long long
|
---|
| 148 | #else
|
---|
| 149 | #ifdef HAVE_LONG_64
|
---|
| 150 | #define UINT64 unsigned long
|
---|
| 151 | #else
|
---|
[156] | 152 | #error "no 64bit type found"
|
---|
[1] | 153 | #endif
|
---|
| 154 | #endif
|
---|
| 155 |
|
---|
| 156 | #else
|
---|
| 157 | #define UINT64 uint64_t
|
---|
| 158 | #endif
|
---|
| 159 |
|
---|
| 160 |
|
---|
| 161 |
|
---|
| 162 | #define UBYTE unsigned char
|
---|
| 163 |
|
---|
| 164 |
|
---|
| 165 | enum {
|
---|
| 166 | SH_CHECK_NONE = 0,
|
---|
| 167 | SH_CHECK_INIT = 1,
|
---|
| 168 | SH_CHECK_CHECK = 2
|
---|
| 169 | };
|
---|
| 170 |
|
---|
[143] | 171 | #define SH_MOD_THREAD 1
|
---|
| 172 | #define SH_MOD_ACTIVE 0
|
---|
| 173 | #define SH_MOD_FAILED -1
|
---|
[207] | 174 | #define SH_MOD_OFFSET 10
|
---|
[156] | 175 |
|
---|
[114] | 176 | /* Flags for file status
|
---|
| 177 | */
|
---|
| 178 | #define SH_FFLAG_ALLIGNORE (1<<0)
|
---|
| 179 | #define SH_FFLAG_VISITED (1<<1)
|
---|
| 180 | #define SH_FFLAG_CHECKED (1<<3)
|
---|
| 181 | #define SH_FFLAG_REPORTED (1<<3)
|
---|
[115] | 182 | #define SH_FFLAG_SUIDCHK (1<<4)
|
---|
[93] | 183 |
|
---|
[114] | 184 | #define SH_FFLAG_ALLIGNORE_SET(a) (((a) & SH_FFLAG_ALLIGNORE) != 0)
|
---|
| 185 | #define SET_SH_FFLAG_ALLIGNORE(a) ((a) |= SH_FFLAG_ALLIGNORE)
|
---|
| 186 | #define CLEAR_SH_FFLAG_ALLIGNORE(a) ((a) &= ~SH_FFLAG_ALLIGNORE)
|
---|
| 187 |
|
---|
| 188 | #define SH_FFLAG_VISITED_SET(a) (((a) & SH_FFLAG_VISITED) != 0)
|
---|
| 189 | #define SET_SH_FFLAG_VISITED(a) ((a) |= SH_FFLAG_VISITED)
|
---|
| 190 | #define CLEAR_SH_FFLAG_VISITED(a) ((a) &= ~SH_FFLAG_VISITED)
|
---|
| 191 |
|
---|
| 192 | #define SH_FFLAG_CHECKED_SET(a) (((a) & SH_FFLAG_VISITED) != 0)
|
---|
| 193 | #define SET_SH_FFLAG_CHECKED(a) ((a) |= SH_FFLAG_VISITED)
|
---|
| 194 | #define CLEAR_SH_FFLAG_CHECKED(a) ((a) &= ~SH_FFLAG_VISITED)
|
---|
| 195 |
|
---|
| 196 | #define SH_FFLAG_REPORTED_SET(a) (((a) & SH_FFLAG_REPORTED) != 0)
|
---|
| 197 | #define SET_SH_FFLAG_REPORTED(a) ((a) |= SH_FFLAG_REPORTED)
|
---|
| 198 | #define CLEAR_SH_FFLAG_REPORTED(a) ((a) &= ~SH_FFLAG_REPORTED)
|
---|
| 199 |
|
---|
[115] | 200 | #define SH_FFLAG_SUIDCHK_SET(a) (((a) & SH_FFLAG_SUIDCHK) != 0)
|
---|
| 201 | #define SET_SH_FFLAG_SUIDCHK(a) ((a) |= SH_FFLAG_SUIDCHK)
|
---|
| 202 | #define CLEAR_SH_FFLAG_SUIDCHK(a) ((a) &= ~SH_FFLAG_SUIDCHK)
|
---|
[114] | 203 |
|
---|
[367] | 204 | /* Flags for inotify
|
---|
| 205 | */
|
---|
| 206 | #define SH_INOTIFY_USE (1<<0)
|
---|
| 207 | #define SH_INOTIFY_DOSCAN (1<<1)
|
---|
| 208 | #define SH_INOTIFY_NEEDINIT (1<<2)
|
---|
[373] | 209 | #define SH_INOTIFY_INSCAN (1<<3)
|
---|
[114] | 210 |
|
---|
[367] | 211 |
|
---|
[1] | 212 | /**************************************************
|
---|
| 213 | *
|
---|
| 214 | * TYPEDEFS
|
---|
| 215 | *
|
---|
| 216 | **************************************************/
|
---|
| 217 |
|
---|
| 218 | enum {
|
---|
| 219 | SH_LEVEL_READONLY = 1,
|
---|
| 220 | SH_LEVEL_LOGFILES = 2,
|
---|
| 221 | SH_LEVEL_LOGGROW = 3,
|
---|
| 222 | SH_LEVEL_NOIGNORE = 4,
|
---|
| 223 | SH_LEVEL_ALLIGNORE = 5,
|
---|
| 224 | SH_LEVEL_ATTRIBUTES = 6,
|
---|
| 225 | SH_LEVEL_USER0 = 7,
|
---|
| 226 | SH_LEVEL_USER1 = 8,
|
---|
[27] | 227 | SH_LEVEL_USER2 = 9,
|
---|
| 228 | SH_LEVEL_USER3 = 10,
|
---|
| 229 | SH_LEVEL_USER4 = 11,
|
---|
| 230 | SH_LEVEL_PRELINK = 12
|
---|
[1] | 231 | };
|
---|
| 232 |
|
---|
| 233 | typedef struct {
|
---|
| 234 | time_t alarm_interval;
|
---|
| 235 | time_t alarm_last;
|
---|
| 236 | } sh_timer_t;
|
---|
| 237 |
|
---|
| 238 | typedef struct {
|
---|
| 239 | char path[SH_PATHBUF];
|
---|
| 240 | char hash[KEY_LEN+1];
|
---|
| 241 | } sh_sh_df;
|
---|
| 242 |
|
---|
| 243 | typedef struct {
|
---|
| 244 | char user[USER_MAX];
|
---|
| 245 | char group[GROUP_MAX];
|
---|
| 246 | char home[SH_PATHBUF];
|
---|
| 247 | uid_t uid;
|
---|
| 248 | gid_t gid;
|
---|
| 249 | } sh_sh_user;
|
---|
| 250 |
|
---|
| 251 | typedef struct {
|
---|
| 252 | char name[SH_PATHBUF]; /* local hostname */
|
---|
| 253 | char system[SH_MINIBUF]; /* system */
|
---|
| 254 | char release[SH_MINIBUF]; /* release */
|
---|
| 255 | char machine[SH_MINIBUF]; /* machine */
|
---|
| 256 | } sh_sh_local;
|
---|
| 257 |
|
---|
| 258 | typedef struct {
|
---|
| 259 | char name[SH_PATHBUF];
|
---|
| 260 | char alt[SH_PATHBUF];
|
---|
| 261 | } sh_sh_remote;
|
---|
| 262 |
|
---|
| 263 | typedef struct {
|
---|
| 264 | unsigned long bytes_hashed; /* bytes last check */
|
---|
| 265 | unsigned long bytes_speed; /* bytes/sec last check */
|
---|
| 266 | unsigned long mail_success; /* mails sent */
|
---|
| 267 | unsigned long mail_failed; /* mails not sent */
|
---|
| 268 | time_t time_start; /* start last check */
|
---|
| 269 | time_t time_check; /* time last check */
|
---|
| 270 | unsigned long dirs_checked; /* #dirs last check */
|
---|
| 271 | unsigned long files_checked; /* #files last check */
|
---|
[405] | 272 | unsigned long files_report; /* #file reports */
|
---|
| 273 | unsigned long files_error; /* #file access error */
|
---|
| 274 | unsigned long files_nodir; /* #file not a directory*/
|
---|
[1] | 275 | } sh_sh_stat;
|
---|
| 276 |
|
---|
| 277 | typedef struct {
|
---|
| 278 | int exit; /* exit value */
|
---|
| 279 | int checkSum; /* whether to init/check checksums */
|
---|
| 280 | int update; /* update db */
|
---|
| 281 | int opts; /* reading cl options */
|
---|
[256] | 282 | int started; /* finished with startup stuff */
|
---|
[1] | 283 | int isdaemon; /* daemon or not */
|
---|
| 284 | int loop; /* go in loop even if not daemon */
|
---|
| 285 | int nice; /* desired nicety */
|
---|
| 286 | int isserver; /* server or not */
|
---|
| 287 | int islocked; /* BAD if logfile not locked */
|
---|
| 288 | int smsg; /* GOOD if end message sent */
|
---|
| 289 | int log_start; /* TRUE if new audit trail */
|
---|
| 290 | int reportonce; /* TRUE if bad files only once rep.*/
|
---|
| 291 | int fulldetail; /* TRUE if full details requested */
|
---|
| 292 | int client_severity; /* TRUE if client severity used */
|
---|
| 293 | int client_class; /* TRUE if client class used */
|
---|
| 294 | int audit;
|
---|
| 295 | unsigned long aud_mask;
|
---|
[367] | 296 | int hidefile; /* TRUE if file not shown in log */
|
---|
| 297 | int inotify; /* Flags for inotify */
|
---|
[1] | 298 | } sh_sh_flag;
|
---|
| 299 |
|
---|
| 300 | typedef struct {
|
---|
| 301 |
|
---|
| 302 | char prg_name[8];
|
---|
[162] | 303 |
|
---|
| 304 | UINT64 pid;
|
---|
[1] | 305 |
|
---|
| 306 | sh_sh_df exec;
|
---|
| 307 | sh_sh_df conf;
|
---|
| 308 | sh_sh_df data;
|
---|
| 309 |
|
---|
| 310 | sh_sh_user real;
|
---|
| 311 | sh_sh_user effective;
|
---|
| 312 | sh_sh_user run;
|
---|
| 313 |
|
---|
| 314 | sh_sh_local host;
|
---|
| 315 |
|
---|
| 316 | sh_sh_remote srvtime;
|
---|
| 317 | sh_sh_remote srvmail;
|
---|
| 318 | sh_sh_remote srvexport;
|
---|
| 319 | sh_sh_remote srvcons;
|
---|
| 320 | sh_sh_remote srvlog;
|
---|
| 321 |
|
---|
| 322 | sh_sh_stat statistics;
|
---|
| 323 | sh_sh_flag flag;
|
---|
| 324 |
|
---|
| 325 | #ifdef SH_STEALTH
|
---|
| 326 | unsigned long off_data;
|
---|
| 327 | #endif
|
---|
| 328 |
|
---|
| 329 | sh_timer_t mailNum;
|
---|
| 330 | sh_timer_t mailTime;
|
---|
| 331 | sh_timer_t fileCheck;
|
---|
| 332 |
|
---|
| 333 | int looptime; /* timing for main loop */
|
---|
| 334 | /*@null@*//*@out@*/ char * timezone;
|
---|
[411] | 335 |
|
---|
| 336 | #ifdef SCREW_IT_UP
|
---|
| 337 | int sigtrap_max_duration;
|
---|
| 338 | #endif
|
---|
| 339 |
|
---|
[1] | 340 | } sh_struct;
|
---|
| 341 |
|
---|
| 342 |
|
---|
| 343 | extern volatile int sig_raised;
|
---|
| 344 | extern volatile int sig_urgent;
|
---|
| 345 | extern volatile int sig_debug_switch; /* SIGUSR1 */
|
---|
| 346 | extern volatile int sig_suspend_switch; /* SIGUSR2 */
|
---|
[143] | 347 | extern volatile int sh_global_suspend_flag;
|
---|
[1] | 348 | extern volatile int sig_fresh_trail; /* SIGIOT */
|
---|
[143] | 349 | extern volatile int sh_thread_pause_flag;
|
---|
[1] | 350 | extern volatile int sig_config_read_again; /* SIGHUP */
|
---|
| 351 | extern volatile int sig_terminate; /* SIGQUIT */
|
---|
| 352 | extern volatile int sig_termfast; /* SIGTERM */
|
---|
| 353 | extern volatile int sig_force_check; /* SIGTTOU */
|
---|
| 354 |
|
---|
| 355 | extern long int eintr__result;
|
---|
| 356 |
|
---|
[20] | 357 | extern int sh_argc_store;
|
---|
| 358 | extern char ** sh_argv_store;
|
---|
| 359 |
|
---|
[1] | 360 | #include "sh_calls.h"
|
---|
| 361 |
|
---|
| 362 |
|
---|
| 363 | typedef struct {
|
---|
[40] | 364 | char sh_sockpass[2*SOCKPASS_MAX+2];
|
---|
[1] | 365 | char sigkey_old[KEY_LEN+1];
|
---|
| 366 | char sigkey_new[KEY_LEN+1];
|
---|
| 367 | char mailkey_old[KEY_LEN+1];
|
---|
| 368 | char mailkey_new[KEY_LEN+1];
|
---|
| 369 | char crypt[KEY_LEN+1];
|
---|
| 370 | char session[KEY_LEN+1];
|
---|
| 371 | char vernam[KEY_LEN+1];
|
---|
| 372 | int mlock_failed;
|
---|
| 373 |
|
---|
| 374 | char pw[PW_LEN];
|
---|
| 375 |
|
---|
| 376 | char poolv[KEY_BYT];
|
---|
| 377 | int poolc;
|
---|
| 378 |
|
---|
| 379 | int rngI;
|
---|
| 380 | UINT32 rng0[3];
|
---|
| 381 | UINT32 rng1[3];
|
---|
| 382 | UINT32 rng2[3];
|
---|
| 383 |
|
---|
[156] | 384 | UINT32 res_vec[6];
|
---|
| 385 |
|
---|
[1] | 386 | UINT32 ErrFlag[2];
|
---|
| 387 |
|
---|
| 388 | #ifdef SH_ENCRYPT
|
---|
| 389 | /*@out@*/ keyInstance keyInstE;
|
---|
| 390 | /*@out@*/ keyInstance keyInstD;
|
---|
| 391 | #endif
|
---|
| 392 | } sh_key_t;
|
---|
| 393 |
|
---|
| 394 | extern sh_struct sh;
|
---|
| 395 | /*@null@*/ extern sh_key_t *skey;
|
---|
| 396 |
|
---|
[22] | 397 | /**************************************************
|
---|
| 398 | *
|
---|
| 399 | * macros
|
---|
| 400 | *
|
---|
| 401 | **************************************************/
|
---|
[1] | 402 |
|
---|
[76] | 403 | #if defined(__GNUC__) && (__GNUC__ >= 4)
|
---|
[149] | 404 | #define SH_GNUC_SENTINEL __attribute__((__sentinel__))
|
---|
[76] | 405 | #else
|
---|
[149] | 406 | #define SH_GNUC_SENTINEL
|
---|
[76] | 407 | #endif
|
---|
| 408 |
|
---|
[149] | 409 | #if defined(__GNUC__) && (__GNUC__ >= 3)
|
---|
| 410 | #undef SH_GNUC_PURE
|
---|
| 411 | #define SH_GNUC_PURE __attribute__((pure))
|
---|
| 412 | #undef SH_GNUC_CONST
|
---|
| 413 | #define SH_GNUC_CONST __attribute__((const))
|
---|
| 414 | #undef SH_GNUC_NORETURN
|
---|
| 415 | #define SH_GNUC_NORETURN __attribute__((noreturn))
|
---|
| 416 | #undef SH_GNUC_MALLOC
|
---|
| 417 | #define SH_GNUC_MALLOC __attribute__((malloc))
|
---|
| 418 | #else
|
---|
| 419 | #undef SH_GNUC_PURE
|
---|
| 420 | #define SH_GNUC_PURE
|
---|
| 421 | #undef SH_GNUC_CONST
|
---|
| 422 | #define SH_GNUC_CONST
|
---|
| 423 | #undef SH_GNUC_NORETURN
|
---|
| 424 | #define SH_GNUC_NORETURN
|
---|
| 425 | #undef SH_GNUC_MALLOC
|
---|
| 426 | #define SH_GNUC_MALLOC
|
---|
| 427 | #endif
|
---|
| 428 |
|
---|
| 429 |
|
---|
[76] | 430 | /* The semantics of the built-in are that it is expected that expr == const
|
---|
| 431 | * for __builtin_expect ((expr), const)
|
---|
| 432 | */
|
---|
| 433 | #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
|
---|
| 434 | #define SH_LIKELY(expr) (__builtin_expect((expr), 1))
|
---|
| 435 | #define SH_UNLIKELY(expr) (__builtin_expect((expr), 0))
|
---|
| 436 | #else
|
---|
| 437 | #define SH_LIKELY(expr) (expr)
|
---|
| 438 | #define SH_UNLIKELY(expr) (expr)
|
---|
| 439 | #endif
|
---|
| 440 |
|
---|
[22] | 441 | /* signal-safe log function
|
---|
| 442 | */
|
---|
[170] | 443 | int safe_logger (int thesignal, int method, char * details);
|
---|
| 444 | void safe_fatal (const char * details, const char *f, int l);
|
---|
[22] | 445 |
|
---|
[25] | 446 | #define SH_VALIDATE_EQ(a,b) \
|
---|
[22] | 447 | do { \
|
---|
[34] | 448 | if ((a) != (b)) safe_fatal(#a " != " #b, FIL__, __LINE__);\
|
---|
[22] | 449 | } while (0)
|
---|
| 450 |
|
---|
[25] | 451 | #define SH_VALIDATE_NE(a,b) \
|
---|
| 452 | do { \
|
---|
[34] | 453 | if ((a) == (b)) safe_fatal(#a " == " #b, FIL__, __LINE__);\
|
---|
[25] | 454 | } while (0)
|
---|
[22] | 455 |
|
---|
[68] | 456 | #define SH_VALIDATE_GE(a,b) \
|
---|
| 457 | do { \
|
---|
| 458 | if ((a) < (b)) safe_fatal(#a " < " #b, FIL__, __LINE__);\
|
---|
| 459 | } while (0)
|
---|
| 460 |
|
---|
[1] | 461 | #if defined(HAVE_MLOCK) && !defined(HAVE_BROKEN_MLOCK)
|
---|
[412] | 462 | #ifdef USE_SUID
|
---|
[1] | 463 | #define MLOCK(a, b) \
|
---|
| 464 | if ((skey != NULL) && skey->mlock_failed == SL_FALSE){ \
|
---|
| 465 | (void) sl_set_suid(); \
|
---|
[19] | 466 | if (sh_unix_mlock(FIL__, __LINE__, a, b) < 0) skey->mlock_failed = SL_TRUE; \
|
---|
[412] | 467 | (void) sl_unset_suid(); }
|
---|
[1] | 468 | #else
|
---|
| 469 | #define MLOCK(a, b) \
|
---|
[412] | 470 | if ((skey != NULL) && skey->mlock_failed == SL_FALSE){ \
|
---|
| 471 | if (sh_unix_mlock(FIL__, __LINE__, a, b) < 0) skey->mlock_failed = SL_TRUE; }
|
---|
| 472 | #endif
|
---|
| 473 | #else
|
---|
| 474 | #define MLOCK(a, b) \
|
---|
[1] | 475 | ;
|
---|
| 476 | #endif
|
---|
| 477 |
|
---|
| 478 | #if defined(HAVE_MLOCK) && !defined(HAVE_BROKEN_MLOCK)
|
---|
[412] | 479 | #ifdef USE_SUID
|
---|
[1] | 480 | #define MUNLOCK(a, b) \
|
---|
| 481 | if ((skey != NULL) && skey->mlock_failed == SL_FALSE){ \
|
---|
| 482 | (void) sl_set_suid(); \
|
---|
| 483 | (void) sh_unix_munlock( a, b );\
|
---|
[412] | 484 | (void) sl_unset_suid(); }
|
---|
[1] | 485 | #else
|
---|
| 486 | #define MUNLOCK(a, b) \
|
---|
[412] | 487 | if ((skey != NULL) && skey->mlock_failed == SL_FALSE){ \
|
---|
| 488 | (void) sh_unix_munlock( a, b ); }
|
---|
| 489 | #endif
|
---|
| 490 | #else
|
---|
| 491 | #define MUNLOCK(a, b) \
|
---|
[1] | 492 | ;
|
---|
| 493 | #endif
|
---|
| 494 |
|
---|
| 495 | #ifdef SH_STEALTH
|
---|
| 496 | void sh_do_encode (char * str, int len);
|
---|
| 497 | #define sh_do_decode sh_do_encode
|
---|
| 498 | #endif
|
---|
| 499 |
|
---|
| 500 | /* #if defined(SCREW_IT_UP)
|
---|
| 501 | * extern volatile int sh_not_traced;
|
---|
| 502 | * inline int sh_sigtrap_prepare();
|
---|
| 503 | * inline int sh_derr();
|
---|
| 504 | * #endif
|
---|
| 505 | */
|
---|
| 506 |
|
---|
| 507 | #if defined(SCREW_IT_UP) && (defined(__FreeBSD__) || defined(__linux__)) && defined(__i386__)
|
---|
| 508 | #define BREAKEXIT(expr) \
|
---|
| 509 | do { \
|
---|
| 510 | int ixi; \
|
---|
| 511 | for (ixi = 0; ixi < 8; ++ixi) { \
|
---|
| 512 | if ((*(volatile unsigned *)((unsigned) expr + ixi) & 0xff) == 0xcc) \
|
---|
| 513 | _exit(EXIT_FAILURE); \
|
---|
| 514 | } \
|
---|
| 515 | } \
|
---|
| 516 | while (1 == 0)
|
---|
| 517 | #else
|
---|
| 518 | #define BREAKEXIT(expr)
|
---|
| 519 | #endif
|
---|
| 520 |
|
---|
| 521 |
|
---|
| 522 |
|
---|
| 523 | #include "sh_cat.h"
|
---|
| 524 | #include "sh_trace.h"
|
---|
| 525 | #include "sh_mem.h"
|
---|
| 526 |
|
---|
| 527 | #endif
|
---|
| 528 |
|
---|
| 529 | /* CRIT: */
|
---|
| 530 | /* NEW_CLIENT <client> */
|
---|
| 531 | /* BAD_CLIENT <client> -- <details> */
|
---|
| 532 | /* ERR_CLIENT <client> -- <details> */
|
---|
| 533 |
|
---|
| 534 | /* ALERT: */
|
---|
| 535 | /* LOG_KEY samhain|yule <key> */
|
---|
| 536 | /* STARTUP samhain|yule -- user <username> */
|
---|
| 537 | /* EXIT samhain|yule */
|
---|
| 538 | /* GOODSIG <file> <user> */
|
---|
| 539 | /* FP_KEY <fingerprint> */
|
---|
| 540 | /* GOODSIG_DAT <file> <user> */
|
---|
| 541 | /* FP_KEY_DAT <fingerprint> */
|
---|
| 542 | /* TIGER_CFG <file> <checksum> */
|
---|
| 543 | /* TIGER_DAT <file> <checksum> */
|
---|
| 544 |
|
---|
| 545 | /* PANIC -- <details> */
|
---|
| 546 | /* ERROR -- <details> */
|
---|
| 547 |
|
---|
| 548 | /* Policy */
|
---|
| 549 | /* POLICY <code> <file> */
|
---|
| 550 | /* <code> = MISSING || ADDED || NOT_A_DIRECTORY || <policy> */
|
---|
| 551 |
|
---|
| 552 |
|
---|
| 553 |
|
---|