source: trunk/include/samhain.h@ 114

Last change on this file since 114 was 114, checked in by rainer, 17 years ago

Revision of file flag code.

File size: 12.2 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/* Flags for file status
128 */
129#define SH_FFLAG_ALLIGNORE (1<<0)
130#define SH_FFLAG_VISITED (1<<1)
131#define SH_FFLAG_CHECKED (1<<3)
132#define SH_FFLAG_REPORTED (1<<3)
133
134#define SH_FFLAG_ALLIGNORE_SET(a) (((a) & SH_FFLAG_ALLIGNORE) != 0)
135#define SET_SH_FFLAG_ALLIGNORE(a) ((a) |= SH_FFLAG_ALLIGNORE)
136#define CLEAR_SH_FFLAG_ALLIGNORE(a) ((a) &= ~SH_FFLAG_ALLIGNORE)
137
138#define SH_FFLAG_VISITED_SET(a) (((a) & SH_FFLAG_VISITED) != 0)
139#define SET_SH_FFLAG_VISITED(a) ((a) |= SH_FFLAG_VISITED)
140#define CLEAR_SH_FFLAG_VISITED(a) ((a) &= ~SH_FFLAG_VISITED)
141
142#define SH_FFLAG_CHECKED_SET(a) (((a) & SH_FFLAG_VISITED) != 0)
143#define SET_SH_FFLAG_CHECKED(a) ((a) |= SH_FFLAG_VISITED)
144#define CLEAR_SH_FFLAG_CHECKED(a) ((a) &= ~SH_FFLAG_VISITED)
145
146#define SH_FFLAG_REPORTED_SET(a) (((a) & SH_FFLAG_REPORTED) != 0)
147#define SET_SH_FFLAG_REPORTED(a) ((a) |= SH_FFLAG_REPORTED)
148#define CLEAR_SH_FFLAG_REPORTED(a) ((a) &= ~SH_FFLAG_REPORTED)
149
150
151
152/**************************************************
153 *
154 * TYPEDEFS
155 *
156 **************************************************/
157
158enum {
159 SH_LEVEL_READONLY = 1,
160 SH_LEVEL_LOGFILES = 2,
161 SH_LEVEL_LOGGROW = 3,
162 SH_LEVEL_NOIGNORE = 4,
163 SH_LEVEL_ALLIGNORE = 5,
164 SH_LEVEL_ATTRIBUTES = 6,
165 SH_LEVEL_USER0 = 7,
166 SH_LEVEL_USER1 = 8,
167 SH_LEVEL_USER2 = 9,
168 SH_LEVEL_USER3 = 10,
169 SH_LEVEL_USER4 = 11,
170 SH_LEVEL_PRELINK = 12
171};
172
173typedef struct {
174 time_t alarm_interval;
175 time_t alarm_last;
176} sh_timer_t;
177
178typedef struct {
179 char path[SH_PATHBUF];
180 char hash[KEY_LEN+1];
181} sh_sh_df;
182
183typedef struct {
184 char user[USER_MAX];
185 char group[GROUP_MAX];
186 char home[SH_PATHBUF];
187 uid_t uid;
188 gid_t gid;
189} sh_sh_user;
190
191typedef struct {
192 char name[SH_PATHBUF]; /* local hostname */
193 char system[SH_MINIBUF]; /* system */
194 char release[SH_MINIBUF]; /* release */
195 char machine[SH_MINIBUF]; /* machine */
196} sh_sh_local;
197
198typedef struct {
199 char name[SH_PATHBUF];
200 char alt[SH_PATHBUF];
201} sh_sh_remote;
202
203typedef struct {
204 unsigned long bytes_hashed; /* bytes last check */
205 unsigned long bytes_speed; /* bytes/sec last check */
206 unsigned long mail_success; /* mails sent */
207 unsigned long mail_failed; /* mails not sent */
208 time_t time_start; /* start last check */
209 time_t time_check; /* time last check */
210 unsigned long dirs_checked; /* #dirs last check */
211 unsigned long files_checked; /* #files last check */
212} sh_sh_stat;
213
214typedef struct {
215 int exit; /* exit value */
216 int checkSum; /* whether to init/check checksums */
217 int update; /* update db */
218 int opts; /* reading cl options */
219 int isdaemon; /* daemon or not */
220 int loop; /* go in loop even if not daemon */
221 int nice; /* desired nicety */
222 int isserver; /* server or not */
223 int islocked; /* BAD if logfile not locked */
224 int smsg; /* GOOD if end message sent */
225 int log_start; /* TRUE if new audit trail */
226 int reportonce; /* TRUE if bad files only once rep.*/
227 int fulldetail; /* TRUE if full details requested */
228 int client_severity; /* TRUE if client severity used */
229 int client_class; /* TRUE if client class used */
230 int audit;
231 unsigned long aud_mask;
232 int hidefile; /* TRUE if file not reveled in log */
233} sh_sh_flag;
234
235typedef struct {
236
237 char prg_name[8];
238
239 sh_sh_df exec;
240 sh_sh_df conf;
241 sh_sh_df data;
242
243 sh_sh_user real;
244 sh_sh_user effective;
245 sh_sh_user run;
246
247 sh_sh_local host;
248
249 sh_sh_remote srvtime;
250 sh_sh_remote srvmail;
251 sh_sh_remote srvexport;
252 sh_sh_remote srvcons;
253 sh_sh_remote srvlog;
254
255 sh_sh_stat statistics;
256 sh_sh_flag flag;
257
258#ifdef SH_STEALTH
259 unsigned long off_data;
260#endif
261
262 sh_timer_t mailNum;
263 sh_timer_t mailTime;
264 sh_timer_t fileCheck;
265
266 int looptime; /* timing for main loop */
267 /*@null@*//*@out@*/ char * timezone;
268} sh_struct;
269
270
271extern volatile int sig_raised;
272extern volatile int sig_urgent;
273extern volatile int sig_debug_switch; /* SIGUSR1 */
274extern volatile int sig_suspend_switch; /* SIGUSR2 */
275extern volatile int sh_global_suspend_flag; /* SIGUSR2 */
276extern volatile int sig_fresh_trail; /* SIGIOT */
277extern volatile int sig_config_read_again; /* SIGHUP */
278extern volatile int sig_terminate; /* SIGQUIT */
279extern volatile int sig_termfast; /* SIGTERM */
280extern volatile int sig_force_check; /* SIGTTOU */
281
282extern long int eintr__result;
283
284extern int sh_argc_store;
285extern char ** sh_argv_store;
286
287#include "sh_calls.h"
288
289
290typedef struct {
291 char sh_sockpass[2*SOCKPASS_MAX+2];
292 char sigkey_old[KEY_LEN+1];
293 char sigkey_new[KEY_LEN+1];
294 char mailkey_old[KEY_LEN+1];
295 char mailkey_new[KEY_LEN+1];
296 char crypt[KEY_LEN+1];
297 char session[KEY_LEN+1];
298 char vernam[KEY_LEN+1];
299 int mlock_failed;
300
301 char pw[PW_LEN];
302
303 char poolv[KEY_BYT];
304 int poolc;
305
306 int rngI;
307 UINT32 rng0[3];
308 UINT32 rng1[3];
309 UINT32 rng2[3];
310
311 UINT32 ErrFlag[2];
312
313#ifdef SH_ENCRYPT
314 /*@out@*/ keyInstance keyInstE;
315 /*@out@*/ keyInstance keyInstD;
316#endif
317} sh_key_t;
318
319extern sh_struct sh;
320/*@null@*/ extern sh_key_t *skey;
321
322/**************************************************
323 *
324 * macros
325 *
326 **************************************************/
327
328#if defined(__GNUC__) && (__GNUC__ >= 4)
329#define SH_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
330#else
331#define SH_GNUC_NULL_TERMINATED
332#endif
333
334/* The semantics of the built-in are that it is expected that expr == const
335 * for __builtin_expect ((expr), const)
336 */
337#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
338#define SH_LIKELY(expr) (__builtin_expect((expr), 1))
339#define SH_UNLIKELY(expr) (__builtin_expect((expr), 0))
340#else
341#define SH_LIKELY(expr) (expr)
342#define SH_UNLIKELY(expr) (expr)
343#endif
344
345/* signal-safe log function
346 */
347int safe_logger (int signal, int method, char * details);
348void safe_fatal (char * details, char *f, int l);
349
350#define SH_VALIDATE_EQ(a,b) \
351 do { \
352 if ((a) != (b)) safe_fatal(#a " != " #b, FIL__, __LINE__);\
353 } while (0)
354
355#define SH_VALIDATE_NE(a,b) \
356 do { \
357 if ((a) == (b)) safe_fatal(#a " == " #b, FIL__, __LINE__);\
358 } while (0)
359
360#define SH_VALIDATE_GE(a,b) \
361 do { \
362 if ((a) < (b)) safe_fatal(#a " < " #b, FIL__, __LINE__);\
363 } while (0)
364
365#if defined(HAVE_MLOCK) && !defined(HAVE_BROKEN_MLOCK)
366#define MLOCK(a, b) \
367 if ((skey != NULL) && skey->mlock_failed == SL_FALSE){ \
368 (void) sl_set_suid(); \
369 if (sh_unix_mlock(FIL__, __LINE__, a, b) < 0) skey->mlock_failed = SL_TRUE; \
370 (void) sl_unset_suid(); }
371#else
372#define MLOCK(a, b) \
373 ;
374#endif
375
376#if defined(HAVE_MLOCK) && !defined(HAVE_BROKEN_MLOCK)
377#define MUNLOCK(a, b) \
378 if ((skey != NULL) && skey->mlock_failed == SL_FALSE){ \
379 (void) sl_set_suid(); \
380 (void) sh_unix_munlock( a, b );\
381 (void) sl_unset_suid(); }
382#else
383#define MUNLOCK(a, b) \
384 ;
385#endif
386
387#ifdef SH_STEALTH
388void sh_do_encode (char * str, int len);
389#define sh_do_decode sh_do_encode
390#endif
391
392/* #if defined(SCREW_IT_UP)
393 * extern volatile int sh_not_traced;
394 * inline int sh_sigtrap_prepare();
395 * inline int sh_derr();
396 * #endif
397 */
398
399#if defined(SCREW_IT_UP) && (defined(__FreeBSD__) || defined(__linux__)) && defined(__i386__)
400#define BREAKEXIT(expr) \
401 do { \
402 int ixi; \
403 for (ixi = 0; ixi < 8; ++ixi) { \
404 if ((*(volatile unsigned *)((unsigned) expr + ixi) & 0xff) == 0xcc) \
405 _exit(EXIT_FAILURE); \
406 } \
407 } \
408 while (1 == 0)
409#else
410#define BREAKEXIT(expr)
411#endif
412
413
414
415#include "sh_cat.h"
416#include "sh_trace.h"
417#include "sh_mem.h"
418
419#endif
420
421/* CRIT: */
422/* NEW_CLIENT <client> */
423/* BAD_CLIENT <client> -- <details> */
424/* ERR_CLIENT <client> -- <details> */
425
426/* ALERT: */
427/* LOG_KEY samhain|yule <key> */
428/* STARTUP samhain|yule -- user <username> */
429/* EXIT samhain|yule */
430/* GOODSIG <file> <user> */
431/* FP_KEY <fingerprint> */
432/* GOODSIG_DAT <file> <user> */
433/* FP_KEY_DAT <fingerprint> */
434/* TIGER_CFG <file> <checksum> */
435/* TIGER_DAT <file> <checksum> */
436
437/* PANIC -- <details> */
438/* ERROR -- <details> */
439
440/* Policy */
441/* POLICY <code> <file> */
442/* <code> = MISSING || ADDED || NOT_A_DIRECTORY || <policy> */
443
444
445
Note: See TracBrowser for help on using the repository browser.