X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;ds=sidebyside;f=src%2Fsyscheckd%2Fsyscheck.c;fp=src%2Fsyscheckd%2Fsyscheck.c;h=11a1ada6ede95e48709f94de9d52f221932b7fd2;hb=789cbc8e52da68eba3517b920ef22e000cf3c9fd;hp=d66aa109826ba70c737bb182c84887f9b67e3fea;hpb=ef70704f0b31b59bb719b884d6a99cb9e3e2044a;p=ossec-hids.git diff --git a/src/syscheckd/syscheck.c b/src/syscheckd/syscheck.c index d66aa10..11a1ada 100755 --- a/src/syscheckd/syscheck.c +++ b/src/syscheckd/syscheck.c @@ -30,18 +30,56 @@ #include "rootcheck/rootcheck.h" -int dump_syscheck_entry(config *syscheck, char *entry, int vals, int reg, char *restrictfile); +int dump_syscheck_entry(syscheck_config *syscheck, char *entry, int vals, int reg, char *restrictfile); +#ifdef USE_MAGIC +#include +magic_t magic_cookie = 0; + +void init_magic(magic_t* cookie_ptr) +{ + if(!cookie_ptr || *cookie_ptr) return; + + *cookie_ptr = magic_open(MAGIC_MIME_TYPE); + + if(!*cookie_ptr) + { + const char* err = magic_error(*cookie_ptr); + merror("%s: ERROR: Can't init libmagic: %s", ARGV0, err ? err : "unknown"); + } + else if(magic_load(*cookie_ptr, NULL) < 0) + { + const char* err = magic_error(*cookie_ptr); + merror("%s: ERROR: Can't load magic file: %s", ARGV0, err ? err : "unknown"); + magic_close(*cookie_ptr); + *cookie_ptr = 0; + } +} +#endif /* void read_internal() * Reads syscheck internal options. */ -void read_internal() +void read_internal(int debug_level) { syscheck.tsleep = getDefine_Int("syscheck","sleep",0,64); syscheck.sleep_after = getDefine_Int("syscheck","sleep_after",1,9999); + /* Check current debug_level + * Command line setting takes precedence + */ + if (debug_level == 0) + { + /* Getting debug level */ + debug_level = getDefine_Int("syscheck", "debug", 0, 2); + while(debug_level != 0) + { + nowDebug(); + debug_level--; + } + } + return; } @@ -52,10 +90,18 @@ void read_internal() */ int Start_win32_Syscheck() { + int debug_level = 0; int r = 0; char *cfg = DEFAULTCPATH; + /* Reading internal options */ + read_internal(debug_level); + + + debug1(STARTED_MSG, ARGV0); + + /* Zeroing the structure */ syscheck.workdir = DEFAULTDIR; @@ -94,10 +140,6 @@ int Start_win32_Syscheck() } - /* Reading internal options */ - read_internal(); - - /* Rootcheck config */ if(rootcheck_init(0) == 0) { @@ -157,6 +199,7 @@ int Start_win32_Syscheck() int main(int argc, char **argv) { int c,r; + int debug_level = 0; int test_config = 0,run_foreground = 0; char *cfg = DEFAULTCPATH; @@ -182,6 +225,7 @@ int main(int argc, char **argv) break; case 'd': nowDebug(); + debug_level = 1; break; case 'f': run_foreground = 1; @@ -206,6 +250,13 @@ int main(int argc, char **argv) } + /* Reading internal options */ + read_internal(debug_level); + + + debug1(STARTED_MSG, ARGV0); + + /* Checking if the configuration is present */ if(File_DateofChange(cfg) < 0) ErrorExit(NO_CONFIG, ARGV0, cfg); @@ -237,11 +288,6 @@ int main(int argc, char **argv) } - /* Reading internal options */ - read_internal(); - - - /* Rootcheck config */ if(rootcheck_init(test_config) == 0) { @@ -264,6 +310,12 @@ int main(int argc, char **argv) syscheck.workdir = DEFAULTDIR; + /* Setup libmagic */ + #ifdef USE_MAGIC + init_magic(&magic_cookie); + #endif + + if(!run_foreground) { nowDaemon();