From: Victor Julien Date: Fri, 5 Apr 2019 10:23:05 +0000 (+0200) Subject: user mode: use CWD as logdir X-Git-Tag: suricata-5.0.0-beta1~77 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a36482e92407f02a70123b1509bde28e84afb6b6;p=thirdparty%2Fsuricata.git user mode: use CWD as logdir Introduce util func for handling user mode settings. --- diff --git a/src/suricata.c b/src/suricata.c index f45851494c..22aacad01e 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -1422,7 +1422,6 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri) int conf_test_force_success = 0; #endif int engine_analysis = 0; - int set_log_directory = 0; int ret = TM_ECODE_OK; #ifdef UNITTESTS @@ -1926,7 +1925,7 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri) "exist. Shutting down the engine.", optarg, optarg); return TM_ECODE_FAILED; } - set_log_directory = 1; + suri->set_logdir = true; break; case 'q': @@ -2078,8 +2077,9 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri) } #endif - if ((suri->run_mode == RUNMODE_UNIX_SOCKET) && set_log_directory) { - SCLogError(SC_ERR_INITIALIZATION, "can't use -l and unix socket runmode at the same time"); + if ((suri->run_mode == RUNMODE_UNIX_SOCKET) && suri->set_logdir) { + SCLogError(SC_ERR_INITIALIZATION, + "can't use -l and unix socket runmode at the same time"); return TM_ECODE_FAILED; } @@ -2641,6 +2641,19 @@ static void PostConfLoadedSetupHostMode(void) } +static void SetupUserMode(SCInstance *suri) +{ + /* apply 'user mode' config updates here */ + if (suri->system == false) { + if (suri->set_logdir == false) { + /* override log dir to current work dir" */ + if (ConfigSetLogDirectory((char *)".") != TM_ECODE_OK) { + FatalError(SC_ERR_LOGDIR_CONFIG, "could not set USER mode logdir"); + } + } + } +} + /** * This function is meant to contain code that needs * to be run once the configuration has been loaded. @@ -2952,6 +2965,8 @@ int main(int argc, char **argv) exit(EXIT_SUCCESS); } + SetupUserMode(&suricata); + /* Since our config is now loaded we can finish configurating the * logging module. */ SCLogLoadConfig(suricata.daemon, suricata.verbose); diff --git a/src/suricata.h b/src/suricata.h index 2a11960a73..bbd2a3aafa 100644 --- a/src/suricata.h +++ b/src/suricata.h @@ -150,7 +150,10 @@ typedef struct SCInstance_ { uint32_t userid; uint32_t groupid; #endif /* OS_WIN32 */ + bool system; + bool set_logdir; + int delayed_detect; int disabled_detect; int daemon;