From: Victor Julien Date: Fri, 30 Jan 2015 13:27:05 +0000 (+0100) Subject: unix-socket: allow tenant id with pcap-file X-Git-Tag: suricata-3.0RC1~219 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc7e9be5c64b191521bdbe9f198392a59a5b84d5;p=thirdparty%2Fsuricata.git unix-socket: allow tenant id with pcap-file Register the tenant id that the pcap-file optionally got. --- diff --git a/src/runmode-unix-socket.c b/src/runmode-unix-socket.c index 75ab1eed36..e4c848ca1e 100644 --- a/src/runmode-unix-socket.c +++ b/src/runmode-unix-socket.c @@ -52,6 +52,7 @@ int unix_socket_mode_is_running = 0; typedef struct PcapFiles_ { char *filename; char *output_dir; + int tenant_id; TAILQ_ENTRY(PcapFiles_) next; } PcapFiles; @@ -154,7 +155,8 @@ static void PcapFilesFree(PcapFiles *cfile) * * \retval 0 in case of error, 1 in case of success */ -TmEcode UnixListAddFile(PcapCommand *this, const char *filename, const char *output_dir) +static TmEcode UnixListAddFile(PcapCommand *this, + const char *filename, const char *output_dir, int tenant_id) { PcapFiles *cfile = NULL; if (filename == NULL || this == NULL) @@ -183,6 +185,8 @@ TmEcode UnixListAddFile(PcapCommand *this, const char *filename, const char *out } } + cfile->tenant_id = tenant_id; + TAILQ_INSERT_TAIL(&this->files, cfile, next); return TM_ECODE_OK; } @@ -200,6 +204,7 @@ TmEcode UnixSocketAddPcapFile(json_t *cmd, json_t* answer, void *data) int ret; const char *filename; const char *output_dir; + int tenant_id = 0; #ifdef OS_WIN32 struct _stat st; #else @@ -245,7 +250,16 @@ TmEcode UnixSocketAddPcapFile(json_t *cmd, json_t* answer, void *data) return TM_ECODE_FAILED; } - ret = UnixListAddFile(this, filename, output_dir); + json_t *targ = json_object_get(cmd, "tenant"); + if (targ != NULL) { + if(!json_is_number(targ)) { + json_object_set_new(answer, "message", json_string("tenant is not a number")); + return TM_ECODE_FAILED; + } + tenant_id = json_number_value(targ); + } + + ret = UnixListAddFile(this, filename, output_dir, tenant_id); switch(ret) { case TM_ECODE_FAILED: json_object_set_new(answer, "message", json_string("Unable to add file to list")); @@ -343,6 +357,15 @@ TmEcode UnixSocketPcapFilesCheck(void *data) return TM_ECODE_FAILED; } } + if (cfile->tenant_id > 0) { + char tstr[16] = ""; + snprintf(tstr, sizeof(tstr), "%d", cfile->tenant_id); + if (ConfSet("pcap-file.tenant-id", tstr) != 1) { + SCLogInfo("Can not set working tenant-id to '%s'", tstr); + PcapFilesFree(cfile); + return TM_ECODE_FAILED; + } + } this->currentfile = SCStrdup(cfile->filename); if (unlikely(this->currentfile == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Failed file name allocation");