241 |
* Return FALSE in case of a fatal event. |
* Return FALSE in case of a fatal event. |
242 |
*/ |
*/ |
243 |
static int eval_actions(int action, Service_T s, char *report, char *check, |
static int eval_actions(int action, Service_T s, char *report, char *check, |
244 |
int alert_event) { |
int event) { |
245 |
|
|
246 |
ASSERT(s); |
ASSERT(s); |
247 |
ASSERT(check); |
ASSERT(check); |
250 |
switch(action) { |
switch(action) { |
251 |
case ACTION_ALERT: |
case ACTION_ALERT: |
252 |
if(s->def_timeout) s->nstart++; |
if(s->def_timeout) s->nstart++; |
253 |
Event_post(s, alert_event, "Event: %s\n", report); |
Event_post(s, event, "Event: %s\n", report); |
254 |
break; /* continue */ |
break; /* continue */ |
255 |
|
|
256 |
case ACTION_STOP: |
case ACTION_STOP: |
262 |
return FALSE; |
return FALSE; |
263 |
|
|
264 |
case ACTION_EXEC: |
case ACTION_EXEC: |
265 |
Event_post(s, alert_event, "Event: %s\n", report); |
Event_post(s, event, "Event: %s\n", report); |
266 |
return FALSE; |
return FALSE; |
267 |
|
|
268 |
default: |
default: |
308 |
static int check_directory(Service_T s) { |
static int check_directory(Service_T s) { |
309 |
|
|
310 |
struct stat stat_buf; |
struct stat stat_buf; |
311 |
char report[STRLEN]; |
char report[STRLEN]= {0}; |
312 |
|
|
313 |
if(stat(s->path, &stat_buf) != 0) { |
if(stat(s->path, &stat_buf) != 0) { |
314 |
Event_post(s, EVENT_RESTART, |
Event_post(s, EVENT_RESTART, |
324 |
|
|
325 |
if(check_perm(s, stat_buf.st_mode)) { |
if(check_perm(s, stat_buf.st_mode)) { |
326 |
s->perm->event_flag= TRUE; |
s->perm->event_flag= TRUE; |
327 |
if(! eval_actions(s->perm->action, s, report, "permission", EVENT_PERMISSION)) |
if(! eval_actions(s->perm->action, s, report, "permission", |
328 |
|
EVENT_PERMISSION)) |
329 |
return FALSE; |
return FALSE; |
330 |
} |
} |
331 |
|
|
353 |
static int check_file(Service_T s) { |
static int check_file(Service_T s) { |
354 |
|
|
355 |
Size_T sl; |
Size_T sl; |
|
char report[STRLEN]; |
|
356 |
struct stat stat_buf; |
struct stat stat_buf; |
357 |
|
char report[STRLEN]= {0}; |
358 |
|
|
359 |
if(stat(s->path, &stat_buf) != 0) { |
if(stat(s->path, &stat_buf) != 0) { |
360 |
Event_post(s, EVENT_RESTART, "Event: file '%s' doesn't exist\n", s->name); |
Event_post(s, EVENT_RESTART, "Event: file '%s' doesn't exist\n", s->name); |
368 |
|
|
369 |
if(check_checksum(s)) { |
if(check_checksum(s)) { |
370 |
s->checksum->event_flag= TRUE; |
s->checksum->event_flag= TRUE; |
371 |
if(! eval_actions(s->checksum->action, s, report, "checksum", EVENT_CHECKSUM)) |
if(! eval_actions(s->checksum->action, s, report, "checksum", |
372 |
|
EVENT_CHECKSUM)) |
373 |
return FALSE; |
return FALSE; |
374 |
} |
} |
375 |
|
|
376 |
if(check_perm(s, stat_buf.st_mode)) { |
if(check_perm(s, stat_buf.st_mode)) { |
377 |
s->perm->event_flag= TRUE; |
s->perm->event_flag= TRUE; |
378 |
if(! eval_actions(s->perm->action, s, report, "permission", EVENT_PERMISSION)) |
if(! eval_actions(s->perm->action, s, report, "permission", |
379 |
|
EVENT_PERMISSION)) |
380 |
return FALSE; |
return FALSE; |
381 |
} |
} |
382 |
|
|
415 |
static int check_device(Service_T s) { |
static int check_device(Service_T s) { |
416 |
|
|
417 |
Device_T td; |
Device_T td; |
|
char report[STRLEN]; |
|
418 |
struct stat stat_buf; |
struct stat stat_buf; |
419 |
|
char report[STRLEN]= {0}; |
420 |
|
|
421 |
if(stat(s->path, &stat_buf) != 0) { |
if(stat(s->path, &stat_buf) != 0) { |
422 |
Event_post(s, EVENT_RESTART, "Event: device '%s' doesn't exist\n", s->name); |
Event_post(s, EVENT_RESTART, "Event: device '%s' doesn't exist\n", s->name); |
425 |
|
|
426 |
if(check_perm(s, stat_buf.st_mode)) { |
if(check_perm(s, stat_buf.st_mode)) { |
427 |
s->perm->event_flag= TRUE; |
s->perm->event_flag= TRUE; |
428 |
if(! eval_actions(s->perm->action, s, report, "permission", EVENT_PERMISSION)) |
if(! eval_actions(s->perm->action, s, report, "permission", |
429 |
|
EVENT_PERMISSION)) |
430 |
return FALSE; |
return FALSE; |
431 |
} |
} |
432 |
|
|
472 |
Port_T pp; |
Port_T pp; |
473 |
Resource_T pr; |
Resource_T pr; |
474 |
pid_t pid= -1; |
pid_t pid= -1; |
475 |
char report[STRLEN]; |
char report[STRLEN]={0}; |
476 |
|
|
477 |
/* Test for running process */ |
/* Test for running process */ |
478 |
if(!(pid= is_process_running(s))) { |
if(!(pid= is_process_running(s))) { |
852 |
return FALSE; |
return FALSE; |
853 |
|
|
854 |
if( !check_md5(s->path, s->checksum->md5) ) { |
if( !check_md5(s->path, s->checksum->md5) ) { |
|
Event_post(s, EVENT_CHECKSUM, "'%s' CHECKSUM ERROR for %s\n", |
|
|
s->name, s->path); |
|
855 |
return TRUE; |
return TRUE; |
856 |
} |
} |
857 |
|
|
876 |
return FALSE; |
return FALSE; |
877 |
|
|
878 |
if( (mode & 07777) != s->perm->perm ) { |
if( (mode & 07777) != s->perm->perm ) { |
|
Event_post(s, EVENT_PERMISSION, |
|
|
"Event: '%s' permission test failed -- " |
|
|
"current permission: %o\n", |
|
|
s->name, mode&07777); |
|
879 |
return TRUE; |
return TRUE; |
880 |
} |
} |
881 |
|
|
901 |
return FALSE; |
return FALSE; |
902 |
|
|
903 |
if( uid != s->uid->uid ) { |
if( uid != s->uid->uid ) { |
|
Event_post(s, EVENT_UID, |
|
|
"Event: '%s' uid test failed -- " |
|
|
"current uid: %d\n", |
|
|
s->name, (int)uid); |
|
904 |
return TRUE; |
return TRUE; |
905 |
} |
} |
906 |
|
|
926 |
return FALSE; |
return FALSE; |
927 |
|
|
928 |
if( gid != s->gid->gid ) { |
if( gid != s->gid->gid ) { |
|
Event_post(s, EVENT_GID, |
|
|
"Event: '%s' gid test failed -- " |
|
|
"current gid: %d\n", |
|
|
s->name, (int)gid); |
|
929 |
return TRUE; |
return TRUE; |
930 |
} |
} |
931 |
|
|
983 |
/** |
/** |
984 |
* Returns TRUE if the size test succeded, otherwise FALSE |
* Returns TRUE if the size test succeded, otherwise FALSE |
985 |
*/ |
*/ |
986 |
static int check_size_item(Service_T s, Size_T sl, unsigned long size, char *report) { |
static int check_size_item(Service_T s, Size_T sl, unsigned long size, |
987 |
|
char *report) { |
988 |
|
|
989 |
ASSERT(s); |
ASSERT(s); |
990 |
ASSERT(sl); |
ASSERT(sl); |
1076 |
t->devinfo->f_blocks, td->limit_percent)) { |
t->devinfo->f_blocks, td->limit_percent)) { |
1077 |
snprintf(report, STRLEN, |
snprintf(report, STRLEN, |
1078 |
"space usage %ld%% matches resource limit [space usage%s%d%%]", |
"space usage %ld%% matches resource limit [space usage%s%d%%]", |
1079 |
100 * (t->devinfo->f_blocks - t->devinfo->f_blocksfreetotal) / |
100*(t->devinfo->f_blocks - t->devinfo->f_blocksfreetotal) / |
1080 |
t->devinfo->f_blocks, operatorshortnames[td->operator], |
t->devinfo->f_blocks, operatorshortnames[td->operator], |
1081 |
td->limit_percent); |
td->limit_percent); |
1082 |
return FALSE; |
return FALSE; |
1094 |
} |
} |
1095 |
DEBUG("'%s' space usage check passed [current space usage=%.1f%%]\n", |
DEBUG("'%s' space usage check passed [current space usage=%.1f%%]\n", |
1096 |
t->name, |
t->name, |
1097 |
(float) 100 * (t->devinfo->f_blocks - t->devinfo->f_blocksfreetotal) / |
(float) 100*(t->devinfo->f_blocks - t->devinfo->f_blocksfreetotal) / |
1098 |
t->devinfo->f_blocks); |
t->devinfo->f_blocks); |
1099 |
return TRUE; |
return TRUE; |
1100 |
|
|