source: trunk/include/samhain.h@ 25

Last change on this file since 25 was 25, checked in by rainer, 19 years ago

More tests; fix for update+schedule issue.

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