source: trunk/include/samhain.h@ 158

Last change on this file since 158 was 156, checked in by katerina, 17 years ago

Put result vector of rng in skey struct, fix HP-UX compile error.

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