]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
user mode: use CWD as logdir
authorVictor Julien <victor@inliniac.net>
Fri, 5 Apr 2019 10:23:05 +0000 (12:23 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 5 Apr 2019 12:39:08 +0000 (14:39 +0200)
Introduce util func for handling user mode settings.

src/suricata.c
src/suricata.h

index f45851494cf9f840fdb3b05fdb12a66757c09698..22aacad01ec5241077c02ca30e468596f378cb44 100644 (file)
@@ -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);
index 2a11960a7322bd3626208aa23ba26f56590d4f2f..bbd2a3aafa8018707bf63c9de9e3873ee7badd62 100644 (file)
@@ -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;