]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
unix socket: add 'conf-get' command
authorEric Leblond <eric@regit.org>
Fri, 30 Nov 2012 19:11:44 +0000 (20:11 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 26 Feb 2013 11:32:48 +0000 (12:32 +0100)
This patch adds a 'conf-get' command which get the configuration
value from suricata. Argument of the command is the name of the
variable to fetch.
The command syntax is the following:
{
 "command": "conf-get",
 "arguments": { "variable":value}
}

scripts/suricatasc/suricatasc.in
src/unix-manager.c

index 4feed8e6ff336436a06202296f4afedabfcd7dc8..567c89edf581af8cbdfbd3e4f84dcb8a5f424d1d 100755 (executable)
@@ -137,6 +137,20 @@ try:
                     cmdmsg["command"] = cmd
                     cmdmsg["arguments"] = {}
                     cmdmsg["arguments"]["iface"] = iface
+            elif "conf-get" in command:
+                try:
+                    [cmd, variable] = command.split(' ', 1)
+                except:
+                    print "Error: unable to split command '%s'" % (command)
+                    continue
+                if cmd != "conf-get":
+                    print "Error: invalid command '%s'" % (command)
+                    continue
+                else:
+                    cmdmsg["command"] = cmd
+                    cmdmsg["arguments"] = {}
+                    cmdmsg["arguments"]["variable"] = variable
+
             else:
                 cmdmsg["command"] = command
             socket.send(json.dumps(cmdmsg))
index ef93c8bb33635af67049995b8d156726a90ccf61..0ae1270bceb67042c65aba16a1b372511f110606 100644 (file)
@@ -627,6 +627,36 @@ TmEcode UnixManagerCaptureModeCommand(json_t *cmd,
     SCReturnInt(TM_ECODE_OK);
 }
 
+TmEcode UnixManagerConfGetCommand(json_t *cmd,
+                                   json_t *server_msg, void *data)
+{
+    SCEnter();
+
+    char *confval = NULL;
+    char *variable = NULL;
+
+    json_t *jarg = json_object_get(cmd, "variable");
+    if(!json_is_string(jarg)) {
+        SCLogInfo("error: variable is not a string");
+        json_object_set_new(server_msg, "message", json_string("variable is not a string"));
+        SCReturnInt(TM_ECODE_FAILED);
+    }
+
+    variable = (char *)json_string_value(jarg);
+    if (ConfGet(variable, &confval) != 1) {
+        json_object_set_new(server_msg, "message", json_string("Unable to get value"));
+        SCReturnInt(TM_ECODE_FAILED);
+    }
+
+    if (confval) {
+        json_object_set_new(server_msg, "message", json_string(confval));
+        SCReturnInt(TM_ECODE_OK);
+    }
+
+    json_object_set_new(server_msg, "message", json_string("No string value"));
+    SCReturnInt(TM_ECODE_FAILED);
+}
+
 TmEcode UnixManagerListCommand(json_t *cmd,
                                json_t *answer, void *data)
 {
@@ -819,6 +849,7 @@ void *UnixManagerThread(void *td)
     UnixManagerRegisterCommand("uptime", UnixManagerUptimeCommand, &command, 0);
     UnixManagerRegisterCommand("running-mode", UnixManagerRunningModeCommand, &command, 0);
     UnixManagerRegisterCommand("capture-mode", UnixManagerCaptureModeCommand, &command, 0);
+    UnixManagerRegisterCommand("conf-get", UnixManagerConfGetCommand, &command, UNIX_CMD_TAKE_ARGS);
 #if 0
     UnixManagerRegisterCommand("reload-rules", UnixManagerReloadRules, NULL, 0);
 #endif