source: trunk/include/samhain.h@ 175

Last change on this file since 175 was 170, checked in by katerina, 17 years ago

Plenty of compiler warnings fixed, SQL query length fixed, doc update.

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