source: trunk/include/samhain.h@ 99

Last change on this file since 99 was 93, checked in by rainer, 18 years ago

Add check for PCI ROMs; fix ticket #51 (symlinks in root directory reported with leading double slash).

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