From 84322fa55664db73d7432d3b7cd422821a353e98 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Fri, 30 Nov 2012 20:11:44 +0100 Subject: [PATCH] unix socket: add 'conf-get' command 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 | 14 ++++++++++++++ src/unix-manager.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/scripts/suricatasc/suricatasc.in b/scripts/suricatasc/suricatasc.in index 4feed8e6ff..567c89edf5 100755 --- a/scripts/suricatasc/suricatasc.in +++ b/scripts/suricatasc/suricatasc.in @@ -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)) diff --git a/src/unix-manager.c b/src/unix-manager.c index ef93c8bb33..0ae1270bce 100644 --- a/src/unix-manager.c +++ b/src/unix-manager.c @@ -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