*
* \return output_ctx if succesful, NULL otherwise
*/
-static OutputCtx *AlertDebugLogInitCtx(ConfNode *conf)
+static OutputInitResult AlertDebugLogInitCtx(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
LogFileCtx *file_ctx = NULL;
file_ctx = LogFileNewCtx();
output_ctx->DeInit = AlertDebugLogDeInitCtx;
SCLogDebug("Alert debug log output initialized");
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
error:
if (file_ctx != NULL) {
LogFileFreeCtx(file_ctx);
}
- return NULL;
+ return result;
}
static int AlertDebugLogCondition(ThreadVars *tv, const Packet *p)
* \param conf The configuration node for this output.
* \return A LogFileCtx pointer on success, NULL on failure.
*/
-OutputCtx *AlertFastLogInitCtx(ConfNode *conf)
+OutputInitResult AlertFastLogInitCtx(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
LogFileCtx *logfile_ctx = LogFileNewCtx();
if (logfile_ctx == NULL) {
SCLogDebug("AlertFastLogInitCtx2: Could not create new LogFileCtx");
- return NULL;
+ return result;
}
if (SCConfLogOpenGeneric(conf, logfile_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(logfile_ctx);
- return NULL;
+ return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL))
- return NULL;
+ return result;
output_ctx->data = logfile_ctx;
output_ctx->DeInit = AlertFastLogDeInitCtx;
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
static void AlertFastLogDeInitCtx(OutputCtx *output_ctx)
void AlertFastLogRegister(void);
void TmModuleAlertFastLogIPv4Register(void);
void TmModuleAlertFastLogIPv6Register(void);
-OutputCtx *AlertFastLogInitCtx(ConfNode *);
+OutputInitResult AlertFastLogInitCtx(ConfNode *);
#endif /* __ALERT_FASTLOG_H__ */
*
* \return A newly allocated AlertPreludeCtx structure, or NULL
*/
-static OutputCtx *AlertPreludeInitCtx(ConfNode *conf)
+static OutputInitResult AlertPreludeInitCtx(ConfNode *conf)
{
int ret;
prelude_client_t *client;
const char *prelude_profile_name;
const char *log_packet_content;
const char *log_packet_header;
+ OutputInitResult result = { NULL, false };
OutputCtx *output_ctx;
SCEnter();
ret = prelude_init(0, NULL);
if (unlikely(ret < 0)) {
prelude_perror(ret, "unable to initialize the prelude library");
- SCReturnPtr(NULL, "AlertPreludeCtx");
+ SCReturnCT(result, "OutputInitResult");
}
prelude_profile_name = ConfNodeLookupChildValue(conf, "profile");
if ( unlikely(ret < 0 || client == NULL )) {
prelude_perror(ret, "Unable to create a prelude client object");
prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
- SCReturnPtr(NULL, "AlertPreludeCtx");
+ SCReturnCT(result, "OutputInitResult");
}
ret = prelude_client_set_flags(client, prelude_client_get_flags(client) | PRELUDE_CLIENT_FLAGS_ASYNC_TIMER|PRELUDE_CLIENT_FLAGS_ASYNC_SEND);
if (unlikely(ret < 0)) {
SCLogDebug("Unable to set asynchronous send and timer.");
prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
- SCReturnPtr(NULL, "AlertPreludeCtx");
+ SCReturnCT(result, "OutputInitResult");
}
ret = SetupAnalyzer(prelude_client_get_analyzer(client));
if (ret < 0) {
SCLogDebug("Unable to setup prelude client analyzer.");
prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
- SCReturnPtr(NULL, "AlertPreludeCtx");
+ SCReturnCT(result, "OutputInitResult");
}
ret = prelude_client_start(client);
if (unlikely(ret < 0)) {
prelude_perror(ret, "Unable to start prelude client");
prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
- SCReturnPtr(NULL, "AlertPreludeCtx");
+ SCReturnCT(result, "OutputInitResult");
}
ctx = SCMalloc(sizeof(AlertPreludeCtx));
if (unlikely(ctx == NULL)) {
prelude_perror(ret, "Unable to allocate memory");
prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
- SCReturnPtr(NULL, "AlertPreludeCtx");
+ SCReturnCT(result, "OutputInitResult");
}
ctx->client = client;
SCFree(ctx);
prelude_perror(ret, "Unable to allocate memory");
prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
- SCReturnPtr(NULL, "AlertPreludeCtx");
+ SCReturnCT(result, "OutputInitResult");
}
output_ctx->data = ctx;
output_ctx->DeInit = AlertPreludeDeinitCtx;
- SCReturnPtr((void*)output_ctx, "OutputCtx");
+ result.ctx = output_ctx;
+ result.ok = true;
+ SCReturnCT(result, "OutputInitResult");
}
static int AlertPreludeCondition(ThreadVars *tv, const Packet *p)
* \param conf The configuration node for this output.
* \return A OutputCtx pointer on success, NULL on failure.
*/
-static OutputCtx *AlertSyslogInitCtx(ConfNode *conf)
+static OutputInitResult AlertSyslogInitCtx(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
const char *facility_s = ConfNodeLookupChildValue(conf, "facility");
if (facility_s == NULL) {
facility_s = DEFAULT_ALERT_SYSLOG_FACILITY_STR;
LogFileCtx *logfile_ctx = LogFileNewCtx();
if (logfile_ctx == NULL) {
SCLogDebug("AlertSyslogInitCtx: Could not create new LogFileCtx");
- return NULL;
+ return result;
}
int facility = SCMapEnumNameToValue(facility_s, SCSyslogGetFacilityMap());
OutputCtx *output_ctx = SCMalloc(sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCLogDebug("AlertSyslogInitCtx: Could not create new OutputCtx");
- return NULL;
+ return result;
}
memset(output_ctx, 0x00, sizeof(OutputCtx));
SCLogInfo("Syslog output initialized");
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
/**
#include "threadvars.h"
#include "tm-threads.h"
+#include "output.h"
+
#include "util-unittest.h"
#include "alert-unified2-alert.h"
#include "decode-ipv4.h"
#include "app-layer.h"
#include "app-layer-htp-xff.h"
-#include "output.h"
#include "util-privs.h"
#include "stream.h"
* \param conf The configuration node for this output.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
-OutputCtx *Unified2AlertInitCtx(ConfNode *conf)
+OutputInitResult Unified2AlertInitCtx(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
int ret = 0;
LogFileCtx* file_ctx = NULL;
OutputCtx* output_ctx = NULL;
SC_ATOMIC_INIT(unified2_event_id);
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
error:
if (xff_cfg != NULL) {
SCFree(output_ctx);
}
- return NULL;
+ return result;
}
static void Unified2AlertDeInitCtx(OutputCtx *output_ctx)
DecodeThreadVars dtv;
PacketQueue pq;
void *data = NULL;
- OutputCtx *oc;
+ OutputInitResult oc;
LogFileCtx *lf;
Unified2AlertFileCtx *uaf = NULL;
Signature s;
oc = Unified2AlertInitCtx(NULL);
- if (oc == NULL) {
+ if (oc.ctx == NULL) {
goto end;
}
- uaf = oc->data;
+ uaf = oc.ctx->data;
if (uaf == NULL)
return 0;
lf = uaf->file_ctx;
if(lf == NULL) {
goto end;
}
- ret = Unified2AlertThreadInit(&tv, oc, &data);
+ ret = Unified2AlertThreadInit(&tv, oc.ctx, &data);
if(ret == TM_ECODE_FAILED) {
goto end;
}
goto end;
}
- Unified2AlertDeInitCtx(oc);
+ Unified2AlertDeInitCtx(oc.ctx);
PACKET_RECYCLE(p);
SCFree(p);
DecodeThreadVars dtv;
PacketQueue pq;
void *data = NULL;
- OutputCtx *oc;
+ OutputInitResult oc;
LogFileCtx *lf;
Unified2AlertFileCtx *uaf = NULL;
Signature s;
DecodeEthernet(&tv, &dtv, p, raw_ipv6_tcp, sizeof(raw_ipv6_tcp), &pq);
oc = Unified2AlertInitCtx(NULL);
- if (oc == NULL) {
+ if (oc.ctx == NULL) {
goto end;
}
- uaf = oc->data;
+ uaf = oc.ctx->data;
if (uaf == NULL)
return 0;
lf = uaf->file_ctx;
if(lf == NULL) {
goto end;
}
- ret = Unified2AlertThreadInit(&tv, oc, &data);
+ ret = Unified2AlertThreadInit(&tv, oc.ctx, &data);
if(ret == -1) {
goto end;
}
goto end;
}
- Unified2AlertDeInitCtx(oc);
+ Unified2AlertDeInitCtx(oc.ctx);
PACKET_RECYCLE(p);
SCFree(p);
DecodeThreadVars dtv;
PacketQueue pq;
void *data = NULL;
- OutputCtx *oc;
+ OutputInitResult oc;
LogFileCtx *lf;
Unified2AlertFileCtx *uaf = NULL;
Signature s;
DecodeEthernet(&tv, &dtv, p, raw_gre, sizeof(raw_gre), &pq);
oc = Unified2AlertInitCtx(NULL);
- if (oc == NULL) {
+ if (oc.ctx == NULL) {
goto end;
}
- uaf = oc->data;
+ uaf = oc.ctx->data;
if (uaf == NULL)
return 0;
lf = uaf->file_ctx;
if(lf == NULL) {
goto end;
}
- ret = Unified2AlertThreadInit(&tv, oc, &data);
+ ret = Unified2AlertThreadInit(&tv, oc.ctx, &data);
if(ret == -1) {
goto end;
}
goto end;
}
- Unified2AlertDeInitCtx(oc);
+ Unified2AlertDeInitCtx(oc.ctx);
pkt = PacketDequeue(&pq);
while (pkt != NULL) {
DecodeThreadVars dtv;
PacketQueue pq;
void *data = NULL;
- OutputCtx *oc;
+ OutputInitResult oc;
LogFileCtx *lf;
Unified2AlertFileCtx *uaf = NULL;
Signature s;
DecodePPP(&tv, &dtv, p, raw_ppp, sizeof(raw_ppp), &pq);
oc = Unified2AlertInitCtx(NULL);
- if (oc == NULL) {
+ if (oc.ctx == NULL) {
goto end;
}
- uaf = oc->data;
+ uaf = oc.ctx->data;
if (uaf == NULL)
return 0;
lf = uaf->file_ctx;
if(lf == NULL) {
goto end;
}
- ret = Unified2AlertThreadInit(&tv, oc, &data);
+ ret = Unified2AlertThreadInit(&tv, oc.ctx, &data);
if(ret == -1) {
goto end;
}
goto end;
}
- Unified2AlertDeInitCtx(oc);
+ Unified2AlertDeInitCtx(oc.ctx);
PACKET_RECYCLE(p);
SCFree(p);
DecodeThreadVars dtv;
PacketQueue pq;
void *data = NULL;
- OutputCtx *oc;
+ OutputInitResult oc;
LogFileCtx *lf;
Unified2AlertFileCtx *uaf = NULL;
Signature s;
p->action = ACTION_DROP;
oc = Unified2AlertInitCtx(NULL);
- if (oc == NULL) {
+ if (oc.ctx == NULL) {
goto end;
}
- uaf = oc->data;
+ uaf = oc.ctx->data;
if (uaf == NULL)
return 0;
lf = uaf->file_ctx;
if(lf == NULL) {
goto end;
}
- ret = Unified2AlertThreadInit(&tv, oc, &data);
+ ret = Unified2AlertThreadInit(&tv, oc.ctx, &data);
if(ret == -1) {
goto end;
}
goto end;
}
- Unified2AlertDeInitCtx(oc);
+ Unified2AlertDeInitCtx(oc.ctx);
PACKET_RECYCLE(p);
SCFree(p);
int ret = 0;
int r = 0;
ThreadVars tv;
- OutputCtx *oc;
+ OutputInitResult oc;
LogFileCtx *lf;
Unified2AlertFileCtx *uaf = NULL;
void *data = NULL;
char *filename = NULL;
oc = Unified2AlertInitCtx(NULL);
- if (oc == NULL)
+ if (oc.ctx == NULL)
return 0;
- uaf = oc->data;
+ uaf = oc.ctx->data;
if (uaf == NULL)
return 0;
lf = uaf->file_ctx;
memset(&tv, 0, sizeof(ThreadVars));
- ret = Unified2AlertThreadInit(&tv, oc, &data);
+ ret = Unified2AlertThreadInit(&tv, oc.ctx, &data);
if (ret == TM_ECODE_FAILED) {
LogFileFreeCtx(lf);
if (filename != NULL)
if(ret == TM_ECODE_FAILED) {
printf("Unified2AlertThreadDeinit error");
}
- if (oc != NULL)
- Unified2AlertDeInitCtx(oc);
+ if (oc.ctx != NULL)
+ Unified2AlertDeInitCtx(oc.ctx);
if (filename != NULL)
SCFree(filename);
return r;
#define UNIFIED2_EXTRADATA_TYPE_EXTRA_DATA 4
void Unified2AlertRegister(void);
-OutputCtx *Unified2AlertInitCtx(ConfNode *);
+OutputInitResult Unified2AlertInitCtx(ConfNode *);
#endif /* __ALERT_UNIFIED2_ALERT_H__ */
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
-static OutputCtx *LogDnsLogInitCtx(ConfNode *conf)
+static OutputInitResult LogDnsLogInitCtx(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
LogFileCtx* file_ctx = LogFileNewCtx();
if(file_ctx == NULL) {
SCLogError(SC_ERR_DNS_LOG_GENERIC, "couldn't create new file_ctx");
- return NULL;
+ return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
LogDnsFileCtx *dnslog_ctx = SCMalloc(sizeof(LogDnsFileCtx));
if (unlikely(dnslog_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
memset(dnslog_ctx, 0x00, sizeof(LogDnsFileCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(dnslog_ctx);
- return NULL;
+ return result;
}
output_ctx->data = dnslog_ctx;
AppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_DNS);
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_DNS);
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
#endif /* !HAVE_RUST */
* \param conf The configuration node for this output.
* \return A LogFileCtx pointer on success, NULL on failure.
*/
-static OutputCtx *LogDropLogInitCtx(ConfNode *conf)
+static OutputInitResult LogDropLogInitCtx(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
if (OutputDropLoggerEnable() != 0) {
SCLogError(SC_ERR_CONF_YAML_ERROR, "only one 'drop' logger "
"can be enabled");
- return NULL;
+ return result;
}
LogFileCtx *logfile_ctx = LogFileNewCtx();
if (logfile_ctx == NULL) {
SCLogDebug("LogDropLogInitCtx: Could not create new LogFileCtx");
- return NULL;
+ return result;
}
if (SCConfLogOpenGeneric(conf, logfile_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(logfile_ctx);
- return NULL;
+ return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(logfile_ctx);
- return NULL;
+ return result;
}
output_ctx->data = logfile_ctx;
output_ctx->DeInit = LogDropLogDeInitCtx;
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
/**
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
-static OutputCtx *LogFileLogInitCtx(ConfNode *conf)
+static OutputInitResult LogFileLogInitCtx(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
LogFileCtx *logfile_ctx = LogFileNewCtx();
if (logfile_ctx == NULL) {
SCLogDebug("Could not create new LogFileCtx");
- return NULL;
+ return result;
}
if (SCConfLogOpenGeneric(conf, logfile_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(logfile_ctx);
- return NULL;
+ return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL))
- return NULL;
+ return result;
output_ctx->data = logfile_ctx;
output_ctx->DeInit = LogFileLogDeInitCtx;
FileForceHashParseCfg(conf);
FileForceTrackingEnable();
- SCReturnPtr(output_ctx, "OutputCtx");
+
+ result.ctx = output_ctx;
+ result.ok = true;
+ SCReturnCT(result, "OutputInitResult");
}
void LogFileLogRegister (void)
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFilestoreCtx* to the file_ctx if succesful
* */
-static OutputCtx *LogFilestoreLogInitCtx(ConfNode *conf)
+static OutputInitResult LogFilestoreLogInitCtx(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL))
- return NULL;
+ return result;
output_ctx->data = NULL;
output_ctx->DeInit = LogFilestoreLogDeInitCtx;
SCLogInfo("enabling pid as a part of all file names");
}
- SCReturnPtr(output_ctx, "OutputCtx");
+ result.ctx = output_ctx;
+ result.ok = true;
+ SCReturnCT(result, "OutputInitResult");
}
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
-OutputCtx *LogHttpLogInitCtx(ConfNode *conf)
+OutputInitResult LogHttpLogInitCtx(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
LogFileCtx* file_ctx = LogFileNewCtx();
if(file_ctx == NULL) {
SCLogError(SC_ERR_HTTP_LOG_GENERIC, "couldn't create new file_ctx");
- return NULL;
+ return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
LogHttpFileCtx *httplog_ctx = SCMalloc(sizeof(LogHttpFileCtx));
if (unlikely(httplog_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
memset(httplog_ctx, 0x00, sizeof(LogHttpFileCtx));
/* enable the logger for the app layer */
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_HTTP);
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
parsererror:
SCLogError(SC_ERR_INVALID_ARGUMENT,"Syntax error in custom http log format string.");
LogCustomFormatFree(httplog_ctx->cf);
LogFileFreeCtx(file_ctx);
SCFree(httplog_ctx);
- return NULL;
+ return result;
}
void LogHttpLogRegister(void);
void TmModuleLogHttpLogIPv4Register (void);
void TmModuleLogHttpLogIPv6Register (void);
-OutputCtx *LogHttpLogInitCtx(ConfNode *);
+OutputInitResult LogHttpLogInitCtx(ConfNode *);
#endif /* __LOG_HTTPLOG_H__ */
static TmEcode PcapLogDataInit(ThreadVars *, const void *, void **);
static TmEcode PcapLogDataDeinit(ThreadVars *, void *);
static void PcapLogFileDeInitCtx(OutputCtx *);
-static OutputCtx *PcapLogInitCtx(ConfNode *);
+static OutputInitResult PcapLogInitCtx(ConfNode *);
static void PcapLogProfilingDump(PcapLogData *);
static int PcapLogCondition(ThreadVars *, const Packet *);
* \param conf The configuration node for this output.
* \retval output_ctx
* */
-static OutputCtx *PcapLogInitCtx(ConfNode *conf)
+static OutputInitResult PcapLogInitCtx(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
const char *pcre_errbuf;
int pcre_erroffset;
output_ctx->DeInit = PcapLogFileDeInitCtx;
g_pcap_data = pl;
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
static void PcapLogFileDeInitCtx(OutputCtx *output_ctx)
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
-static OutputCtx *LogStatsLogInitCtx(ConfNode *conf)
+static OutputInitResult LogStatsLogInitCtx(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
LogFileCtx *file_ctx = LogFileNewCtx();
if (file_ctx == NULL) {
SCLogError(SC_ERR_STATS_LOG_GENERIC, "couldn't create new file_ctx");
- return NULL;
+ return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
LogStatsFileCtx *statslog_ctx = SCMalloc(sizeof(LogStatsFileCtx));
if (unlikely(statslog_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
memset(statslog_ctx, 0x00, sizeof(LogStatsFileCtx));
SCFree(statslog_ctx);
SCLogError(SC_ERR_STATS_LOG_NEGATED,
"Cannot disable both totals and threads in stats logging");
- return NULL;
+ return result;
}
if (totals != NULL && ConfValIsFalse(totals)) {
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(statslog_ctx);
- return NULL;
+ return result;
}
output_ctx->data = statslog_ctx;
SCLogDebug("STATS log output initialized");
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
static void LogStatsLogDeInitCtx(OutputCtx *output_ctx)
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
-OutputCtx *LogTcpDataLogInitCtx(ConfNode *conf)
+OutputInitResult LogTcpDataLogInitCtx(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
char filename[PATH_MAX] = "";
char dirname[32] = "";
strlcpy(filename, DEFAULT_LOG_FILENAME, sizeof(filename));
LogFileCtx *file_ctx = LogFileNewCtx();
if(file_ctx == NULL) {
SCLogError(SC_ERR_TCPDATA_LOG_GENERIC, "couldn't create new file_ctx");
- return NULL;
+ return result;
}
LogTcpDataFileCtx *tcpdatalog_ctx = SCMalloc(sizeof(LogTcpDataFileCtx));
if (unlikely(tcpdatalog_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
memset(tcpdatalog_ctx, 0x00, sizeof(LogTcpDataFileCtx));
if (SCConfLogOpenGeneric(conf, file_ctx, filename, 1) < 0) {
LogFileFreeCtx(file_ctx);
SCFree(tcpdatalog_ctx);
- return NULL;
+ return result;
}
}
output_ctx->DeInit = LogTcpDataLogDeInitCtx;
SCLogDebug("Streaming log output initialized");
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
parsererror:
LogFileFreeCtx(file_ctx);
SCFree(tcpdatalog_ctx);
SCLogError(SC_ERR_INVALID_ARGUMENT,"Syntax error in custom http log format string.");
- return NULL;
+ return result;
}
#define __LOG_TCPDATALOG_H__
void LogTcpDataLogRegister(void);
-OutputCtx *LogTcpDataLogInitCtx(ConfNode *);
+OutputInitResult LogTcpDataLogInitCtx(ConfNode *);
#endif /* __LOG_TCPDATALOG_H__ */
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
-static OutputCtx *LogTlsLogInitCtx(ConfNode *conf)
+static OutputInitResult LogTlsLogInitCtx(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
LogFileCtx* file_ctx = LogFileNewCtx();
if (file_ctx == NULL) {
SCLogError(SC_ERR_TLS_LOG_GENERIC, "LogTlsLogInitCtx: Couldn't "
"create new file_ctx");
- return NULL;
+ return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
/* enable the logger for the app layer */
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_TLS);
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
parser_error:
SCLogError(SC_ERR_INVALID_ARGUMENT,"Syntax error in custom tls log format string.");
tlslog_error:
SCFree(tlslog_ctx);
filectx_error:
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
/* Custom format logging */
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFilestoreCtx* to the file_ctx if succesful
* */
-static OutputCtx *LogTlsStoreLogInitCtx(ConfNode *conf)
+static OutputInitResult LogTlsStoreLogInitCtx(ConfNode *conf)
{
-
+ OutputInitResult result = { NULL, false };
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL))
- return NULL;
+ return result;
output_ctx->data = NULL;
output_ctx->DeInit = LogTlsStoreLogDeInitCtx;
/* enable the logger for the app layer */
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_TLS);
- SCReturnPtr(output_ctx, "OutputCtx");
+ result.ctx = output_ctx;
+ result.ok = true;
+ SCReturnCT(result, "OutputInitResult");
}
void LogTlsStoreRegister (void)
* \param conf The configuration node for this output.
* \return A LogFileCtx pointer on success, NULL on failure.
*/
-static OutputCtx *JsonAlertLogInitCtx(ConfNode *conf)
+static OutputInitResult JsonAlertLogInitCtx(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
AlertJsonOutputCtx *json_output_ctx = NULL;
LogFileCtx *logfile_ctx = LogFileNewCtx();
if (logfile_ctx == NULL) {
SCLogDebug("AlertFastLogInitCtx2: Could not create new LogFileCtx");
- return NULL;
+ return result;
}
if (SCConfLogOpenGeneric(conf, logfile_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(logfile_ctx);
- return NULL;
+ return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(logfile_ctx);
- return NULL;
+ return result;
}
json_output_ctx = SCMalloc(sizeof(AlertJsonOutputCtx));
if (unlikely(json_output_ctx == NULL)) {
LogFileFreeCtx(logfile_ctx);
SCFree(output_ctx);
- return NULL;
+ return result;
}
memset(json_output_ctx, 0, sizeof(AlertJsonOutputCtx));
output_ctx->data = json_output_ctx;
output_ctx->DeInit = JsonAlertLogDeInitCtx;
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
/**
* \param conf The configuration node for this output.
* \return A LogFileCtx pointer on success, NULL on failure.
*/
-static OutputCtx *JsonAlertLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult JsonAlertLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
{
+ OutputInitResult result = { NULL, false };
OutputJsonCtx *ajt = parent_ctx->data;
AlertJsonOutputCtx *json_output_ctx = NULL;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL))
- return NULL;
+ return result;
json_output_ctx = SCMalloc(sizeof(AlertJsonOutputCtx));
if (unlikely(json_output_ctx == NULL)) {
output_ctx->data = json_output_ctx;
output_ctx->DeInit = JsonAlertLogDeInitCtxSub;
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
error:
if (json_output_ctx != NULL) {
SCFree(output_ctx);
}
- return NULL;
+ return result;
}
void JsonAlertLogRegister (void)
#define DEFAULT_LOG_FILENAME "dnp3.json"
-static OutputCtx *OutputDNP3LogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult OutputDNP3LogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
+ OutputInitResult result = { NULL, false };
OutputJsonCtx *ajt = parent_ctx->data;
LogDNP3FileCtx *dnp3log_ctx = SCCalloc(1, sizeof(*dnp3log_ctx));
if (unlikely(dnp3log_ctx == NULL)) {
- return NULL;
+ return result;
}
dnp3log_ctx->file_ctx = ajt->file_ctx;
OutputCtx *output_ctx = SCCalloc(1, sizeof(*output_ctx));
if (unlikely(output_ctx == NULL)) {
SCFree(dnp3log_ctx);
- return NULL;
+ return result;
}
output_ctx->data = dnp3log_ctx;
output_ctx->DeInit = OutputDNP3LogDeInitCtxSub;
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_DNP3);
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
#define OUTPUT_BUFFER_SIZE 65535
}
}
-static OutputCtx *JsonDnsLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult JsonDnsLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
{
+ OutputInitResult result = { NULL, false };
OutputJsonCtx *ojc = parent_ctx->data;
LogDnsFileCtx *dnslog_ctx = SCMalloc(sizeof(LogDnsFileCtx));
if (unlikely(dnslog_ctx == NULL)) {
- return NULL;
+ return result;
}
memset(dnslog_ctx, 0x00, sizeof(LogDnsFileCtx));
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCFree(dnslog_ctx);
- return NULL;
+ return result;
}
output_ctx->data = dnslog_ctx;
AppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_DNS);
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_DNS);
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
#define DEFAULT_LOG_FILENAME "dns.json"
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
-static OutputCtx *JsonDnsLogInitCtx(ConfNode *conf)
+static OutputInitResult JsonDnsLogInitCtx(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
LogFileCtx *file_ctx = LogFileNewCtx();
if(file_ctx == NULL) {
SCLogError(SC_ERR_DNS_LOG_GENERIC, "couldn't create new file_ctx");
- return NULL;
+ return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
LogDnsFileCtx *dnslog_ctx = SCMalloc(sizeof(LogDnsFileCtx));
if (unlikely(dnslog_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
memset(dnslog_ctx, 0x00, sizeof(LogDnsFileCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(dnslog_ctx);
- return NULL;
+ return result;
}
output_ctx->data = dnslog_ctx;
AppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_DNS);
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_DNS);
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
}
#define DEFAULT_LOG_FILENAME "drop.json"
-static OutputCtx *JsonDropLogInitCtx(ConfNode *conf)
+static OutputInitResult JsonDropLogInitCtx(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
if (OutputDropLoggerEnable() != 0) {
SCLogError(SC_ERR_CONF_YAML_ERROR, "only one 'drop' logger "
"can be enabled");
- return NULL;
+ return result;
}
JsonDropOutputCtx *drop_ctx = SCCalloc(1, sizeof(*drop_ctx));
if (drop_ctx == NULL)
- return NULL;
+ return result;
drop_ctx->file_ctx = LogFileNewCtx();
if (drop_ctx->file_ctx == NULL) {
JsonDropOutputCtxFree(drop_ctx);
- return NULL;
+ return result;
}
if (SCConfLogOpenGeneric(conf, drop_ctx->file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
JsonDropOutputCtxFree(drop_ctx);
- return NULL;
+ return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
JsonDropOutputCtxFree(drop_ctx);
- return NULL;
+ return result;
}
if (conf) {
output_ctx->data = drop_ctx;
output_ctx->DeInit = JsonDropLogDeInitCtx;
- return output_ctx;
+
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
-static OutputCtx *JsonDropLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult JsonDropLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
{
+ OutputInitResult result = { NULL, false };
if (OutputDropLoggerEnable() != 0) {
SCLogError(SC_ERR_CONF_YAML_ERROR, "only one 'drop' logger "
"can be enabled");
- return NULL;
+ return result;
}
OutputJsonCtx *ajt = parent_ctx->data;
JsonDropOutputCtx *drop_ctx = SCCalloc(1, sizeof(*drop_ctx));
if (drop_ctx == NULL)
- return NULL;
+ return result;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
JsonDropOutputCtxFree(drop_ctx);
- return NULL;
+ return result;
}
if (conf) {
output_ctx->data = drop_ctx;
output_ctx->DeInit = JsonDropLogDeInitCtxSub;
- return output_ctx;
+
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
/**
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* */
-static OutputCtx *OutputFileLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult OutputFileLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
+ OutputInitResult result = { NULL, false };
OutputJsonCtx *ojc = parent_ctx->data;
OutputFileCtx *output_file_ctx = SCMalloc(sizeof(OutputFileCtx));
if (unlikely(output_file_ctx == NULL))
- return NULL;
+ return result;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCFree(output_file_ctx);
- return NULL;
+ return result;
}
output_file_ctx->file_ctx = ojc->file_ctx;
output_ctx->DeInit = OutputFileLogDeinitSub;
FileForceTrackingEnable();
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
void JsonFileLogRegister (void)
}
#define DEFAULT_LOG_FILENAME "flow.json"
-static OutputCtx *OutputFlowLogInit(ConfNode *conf)
+static OutputInitResult OutputFlowLogInit(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
LogFileCtx *file_ctx = LogFileNewCtx();
if(file_ctx == NULL) {
SCLogError(SC_ERR_FLOW_LOG_GENERIC, "couldn't create new file_ctx");
- return NULL;
+ return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
LogJsonFileCtx *flow_ctx = SCMalloc(sizeof(LogJsonFileCtx));
if (unlikely(flow_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(flow_ctx);
- return NULL;
+ return result;
}
flow_ctx->file_ctx = file_ctx;
output_ctx->data = flow_ctx;
output_ctx->DeInit = OutputFlowLogDeinit;
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
static void OutputFlowLogDeinitSub(OutputCtx *output_ctx)
SCFree(output_ctx);
}
-static OutputCtx *OutputFlowLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult OutputFlowLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
+ OutputInitResult result = { NULL, false };
OutputJsonCtx *ojc = parent_ctx->data;
LogJsonFileCtx *flow_ctx = SCMalloc(sizeof(LogJsonFileCtx));
if (unlikely(flow_ctx == NULL))
- return NULL;
+ return result;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCFree(flow_ctx);
- return NULL;
+ return result;
}
flow_ctx->file_ctx = ojc->file_ctx;
output_ctx->data = flow_ctx;
output_ctx->DeInit = OutputFlowLogDeinitSub;
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
#define OUTPUT_BUFFER_SIZE 65535
}
#define DEFAULT_LOG_FILENAME "http.json"
-static OutputCtx *OutputHttpLogInit(ConfNode *conf)
+static OutputInitResult OutputHttpLogInit(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
LogFileCtx *file_ctx = LogFileNewCtx();
if(file_ctx == NULL) {
SCLogError(SC_ERR_HTTP_LOG_GENERIC, "couldn't create new file_ctx");
- return NULL;
+ return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
LogHttpFileCtx *http_ctx = SCMalloc(sizeof(LogHttpFileCtx));
if (unlikely(http_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(http_ctx);
- return NULL;
+ return result;
}
http_ctx->file_ctx = file_ctx;
/* enable the logger for the app layer */
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_HTTP);
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
static void OutputHttpLogDeinitSub(OutputCtx *output_ctx)
SCFree(output_ctx);
}
-static OutputCtx *OutputHttpLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult OutputHttpLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
+ OutputInitResult result = { NULL, false };
OutputJsonCtx *ojc = parent_ctx->data;
LogHttpFileCtx *http_ctx = SCMalloc(sizeof(LogHttpFileCtx));
if (unlikely(http_ctx == NULL))
- return NULL;
+ return result;
memset(http_ctx, 0x00, sizeof(*http_ctx));
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCFree(http_ctx);
- return NULL;
+ return result;
}
http_ctx->file_ctx = ojc->file_ctx;
/* enable the logger for the app layer */
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_HTTP);
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
#define OUTPUT_BUFFER_SIZE 65535
}
#define DEFAULT_LOG_FILENAME "netflow.json"
-static OutputCtx *OutputNetFlowLogInit(ConfNode *conf)
+static OutputInitResult OutputNetFlowLogInit(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
LogFileCtx *file_ctx = LogFileNewCtx();
if(file_ctx == NULL) {
SCLogError(SC_ERR_NETFLOW_LOG_GENERIC, "couldn't create new file_ctx");
- return NULL;
+ return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
LogJsonFileCtx *flow_ctx = SCMalloc(sizeof(LogJsonFileCtx));
if (unlikely(flow_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(flow_ctx);
- return NULL;
+ return result;
}
flow_ctx->file_ctx = file_ctx;
output_ctx->data = flow_ctx;
output_ctx->DeInit = OutputNetFlowLogDeinit;
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
static void OutputNetFlowLogDeinitSub(OutputCtx *output_ctx)
SCFree(output_ctx);
}
-static OutputCtx *OutputNetFlowLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult OutputNetFlowLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
+ OutputInitResult result = { NULL, false };
OutputJsonCtx *ojc = parent_ctx->data;
LogJsonFileCtx *flow_ctx = SCMalloc(sizeof(LogJsonFileCtx));
if (unlikely(flow_ctx == NULL))
- return NULL;
+ return result;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCFree(flow_ctx);
- return NULL;
+ return result;
}
flow_ctx->file_ctx = ojc->file_ctx;
output_ctx->data = flow_ctx;
output_ctx->DeInit = OutputNetFlowLogDeinitSub;
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
#define OUTPUT_BUFFER_SIZE 65535
SCFree(output_ctx);
}
-static OutputCtx *OutputNFSLogInitSub(ConfNode *conf,
+static OutputInitResult OutputNFSLogInitSub(ConfNode *conf,
OutputCtx *parent_ctx)
{
+ OutputInitResult result = { NULL, false };
OutputJsonCtx *ajt = parent_ctx->data;
LogNFSFileCtx *nfslog_ctx = SCCalloc(1, sizeof(*nfslog_ctx));
if (unlikely(nfslog_ctx == NULL)) {
- return NULL;
+ return result;
}
nfslog_ctx->file_ctx = ajt->file_ctx;
OutputCtx *output_ctx = SCCalloc(1, sizeof(*output_ctx));
if (unlikely(output_ctx == NULL)) {
SCFree(nfslog_ctx);
- return NULL;
+ return result;
}
output_ctx->data = nfslog_ctx;
output_ctx->DeInit = OutputNFSLogDeInitCtxSub;
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_NFS);
AppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_NFS);
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
#define OUTPUT_BUFFER_SIZE 65535
}
#define DEFAULT_LOG_FILENAME "smtp.json"
-static OutputCtx *OutputSmtpLogInit(ConfNode *conf)
+static OutputInitResult OutputSmtpLogInit(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
LogFileCtx *file_ctx = LogFileNewCtx();
if(file_ctx == NULL) {
SCLogError(SC_ERR_SMTP_LOG_GENERIC, "couldn't create new file_ctx");
- return NULL;
+ return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
OutputJsonEmailCtx *email_ctx = SCMalloc(sizeof(OutputJsonEmailCtx));
if (unlikely(email_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(email_ctx);
- return NULL;
+ return result;
}
email_ctx->file_ctx = file_ctx;
/* enable the logger for the app layer */
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_SMTP);
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
-static OutputCtx *OutputSmtpLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult OutputSmtpLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
+ OutputInitResult result = { NULL, false };
OutputJsonCtx *ojc = parent_ctx->data;
OutputJsonEmailCtx *email_ctx = SCMalloc(sizeof(OutputJsonEmailCtx));
if (unlikely(email_ctx == NULL))
- return NULL;
+ return result;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCFree(email_ctx);
- return NULL;
+ return result;
}
email_ctx->file_ctx = ojc->file_ctx;
/* enable the logger for the app layer */
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_SMTP);
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
#define OUTPUT_BUFFER_SIZE 65535
}
#define DEFAULT_LOG_FILENAME "ssh.json"
-static OutputCtx *OutputSshLogInit(ConfNode *conf)
+static OutputInitResult OutputSshLogInit(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
LogFileCtx *file_ctx = LogFileNewCtx();
if(file_ctx == NULL) {
SCLogError(SC_ERR_SSH_LOG_GENERIC, "couldn't create new file_ctx");
- return NULL;
+ return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
OutputSshCtx *ssh_ctx = SCMalloc(sizeof(OutputSshCtx));
if (unlikely(ssh_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(ssh_ctx);
- return NULL;
+ return result;
}
ssh_ctx->file_ctx = file_ctx;
output_ctx->DeInit = OutputSshLogDeinit;
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_SSH);
- return output_ctx;
+
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
static void OutputSshLogDeinitSub(OutputCtx *output_ctx)
SCFree(output_ctx);
}
-static OutputCtx *OutputSshLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult OutputSshLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
+ OutputInitResult result = { NULL, false };
OutputJsonCtx *ojc = parent_ctx->data;
OutputSshCtx *ssh_ctx = SCMalloc(sizeof(OutputSshCtx));
if (unlikely(ssh_ctx == NULL))
- return NULL;
+ return result;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCFree(ssh_ctx);
- return NULL;
+ return result;
}
ssh_ctx->file_ctx = ojc->file_ctx;
output_ctx->DeInit = OutputSshLogDeinitSub;
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_SSH);
- return output_ctx;
+
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
void JsonSshLogRegister (void)
}
#define DEFAULT_LOG_FILENAME "stats.json"
-static OutputCtx *OutputStatsLogInit(ConfNode *conf)
+static OutputInitResult OutputStatsLogInit(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
LogFileCtx *file_ctx = LogFileNewCtx();
if(file_ctx == NULL) {
SCLogError(SC_ERR_STATS_LOG_GENERIC, "couldn't create new file_ctx");
- return NULL;
+ return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
OutputStatsCtx *stats_ctx = SCMalloc(sizeof(OutputStatsCtx));
if (unlikely(stats_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
stats_ctx->flags = JSON_STATS_TOTALS;
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(stats_ctx);
- return NULL;
+ return result;
}
stats_ctx->file_ctx = file_ctx;
output_ctx->data = stats_ctx;
output_ctx->DeInit = OutputStatsLogDeinit;
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
static void OutputStatsLogDeinitSub(OutputCtx *output_ctx)
SCFree(output_ctx);
}
-static OutputCtx *OutputStatsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult OutputStatsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
+ OutputInitResult result = { NULL, false };
OutputJsonCtx *ajt = parent_ctx->data;
-
OutputStatsCtx *stats_ctx = SCMalloc(sizeof(OutputStatsCtx));
if (unlikely(stats_ctx == NULL))
- return NULL;
+ return result;
stats_ctx->flags = JSON_STATS_TOTALS;
SCFree(stats_ctx);
SCLogError(SC_ERR_JSON_STATS_LOG_NEGATED,
"Cannot disable both totals and threads in stats logging");
- return NULL;
+ return result;
}
if (totals != NULL && ConfValIsFalse(totals)) {
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCFree(stats_ctx);
- return NULL;
+ return result;
}
stats_ctx->file_ctx = ajt->file_ctx;
output_ctx->data = stats_ctx;
output_ctx->DeInit = OutputStatsLogDeinitSub;
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
void JsonStatsLogRegister(void) {
SCFree(output_ctx);
}
-static OutputCtx *OutputTemplateLogInitSub(ConfNode *conf,
+static OutputInitResult OutputTemplateLogInitSub(ConfNode *conf,
OutputCtx *parent_ctx)
{
+ OutputInitResult result = { NULL, false };
OutputJsonCtx *ajt = parent_ctx->data;
LogTemplateFileCtx *templatelog_ctx = SCCalloc(1, sizeof(*templatelog_ctx));
if (unlikely(templatelog_ctx == NULL)) {
- return NULL;
+ return result;
}
templatelog_ctx->file_ctx = ajt->file_ctx;
OutputCtx *output_ctx = SCCalloc(1, sizeof(*output_ctx));
if (unlikely(output_ctx == NULL)) {
SCFree(templatelog_ctx);
- return NULL;
+ return result;
}
output_ctx->data = templatelog_ctx;
output_ctx->DeInit = OutputTemplateLogDeInitCtxSub;
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_TEMPLATE);
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
#define OUTPUT_BUFFER_SIZE 65535
return tls_ctx;
}
-static OutputCtx *OutputTlsLogInit(ConfNode *conf)
+static OutputInitResult OutputTlsLogInit(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
LogFileCtx *file_ctx = LogFileNewCtx();
if (file_ctx == NULL) {
SCLogError(SC_ERR_TLS_LOG_GENERIC, "couldn't create new file_ctx");
- return NULL;
+ return result;
}
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
OutputTlsCtx *tls_ctx = OutputTlsInitCtx(conf);
if (unlikely(tls_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
- return NULL;
+ return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(tls_ctx);
- return NULL;
+ return result;
}
tls_ctx->file_ctx = file_ctx;
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_TLS);
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
static void OutputTlsLogDeinitSub(OutputCtx *output_ctx)
SCFree(output_ctx);
}
-static OutputCtx *OutputTlsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult OutputTlsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
+ OutputInitResult result = { NULL, false };
OutputJsonCtx *ojc = parent_ctx->data;
OutputTlsCtx *tls_ctx = OutputTlsInitCtx(conf);
if (unlikely(tls_ctx == NULL))
- return NULL;
+ return result;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCFree(tls_ctx);
- return NULL;
+ return result;
}
tls_ctx->file_ctx = ojc->file_ctx;
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_TLS);
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
void JsonTlsLogRegister (void)
* \param conf The configuration node for this output.
* \return A LogFileCtx pointer on success, NULL on failure.
*/
-static OutputCtx *JsonVarsLogInitCtx(ConfNode *conf)
+static OutputInitResult JsonVarsLogInitCtx(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
VarsJsonOutputCtx *json_output_ctx = NULL;
LogFileCtx *logfile_ctx = LogFileNewCtx();
if (logfile_ctx == NULL) {
SCLogDebug("VarsFastLogInitCtx2: Could not create new LogFileCtx");
- return NULL;
+ return result;
}
if (SCConfLogOpenGeneric(conf, logfile_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
LogFileFreeCtx(logfile_ctx);
- return NULL;
+ return result;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(logfile_ctx);
- return NULL;
+ return result;
}
json_output_ctx = SCMalloc(sizeof(VarsJsonOutputCtx));
if (unlikely(json_output_ctx == NULL)) {
LogFileFreeCtx(logfile_ctx);
SCFree(output_ctx);
- return NULL;
+ return result;
}
memset(json_output_ctx, 0, sizeof(VarsJsonOutputCtx));
output_ctx->data = json_output_ctx;
output_ctx->DeInit = JsonVarsLogDeInitCtx;
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
/**
* \param conf The configuration node for this output.
* \return A LogFileCtx pointer on success, NULL on failure.
*/
-static OutputCtx *JsonVarsLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult JsonVarsLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
{
+ OutputInitResult result = { NULL, false };
OutputJsonCtx *ajt = parent_ctx->data;
VarsJsonOutputCtx *json_output_ctx = NULL;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL))
- return NULL;
+ return result;
json_output_ctx = SCMalloc(sizeof(VarsJsonOutputCtx));
if (unlikely(json_output_ctx == NULL)) {
output_ctx->data = json_output_ctx;
output_ctx->DeInit = JsonVarsLogDeInitCtxSub;
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
error:
if (json_output_ctx != NULL) {
SCFree(output_ctx);
}
- return NULL;
+ return result;
}
void JsonVarsLogRegister (void)
* \param conf The configuration node for this output.
* \return A LogFileCtx pointer on success, NULL on failure.
*/
-OutputCtx *OutputJsonInitCtx(ConfNode *conf)
+OutputInitResult OutputJsonInitCtx(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
OutputJsonCtx *json_ctx = SCCalloc(1, sizeof(OutputJsonCtx));;
/* First lookup a sensor-name value in this outputs configuration
if (unlikely(json_ctx == NULL)) {
SCLogDebug("AlertJsonInitCtx: Could not create new LogFileCtx");
- return NULL;
+ return result;
}
json_ctx->file_ctx = LogFileNewCtx();
if (unlikely(json_ctx->file_ctx == NULL)) {
SCLogDebug("AlertJsonInitCtx: Could not create new LogFileCtx");
SCFree(json_ctx);
- return NULL;
+ return result;
}
if (sensor_name) {
if (json_ctx->file_ctx->sensor_name == NULL) {
LogFileFreeCtx(json_ctx->file_ctx);
SCFree(json_ctx);
- return NULL;
+ return result;
}
} else {
json_ctx->file_ctx->sensor_name = NULL;
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(json_ctx->file_ctx);
SCFree(json_ctx);
- return NULL;
+ return result;
}
output_ctx->data = json_ctx;
LogFileFreeCtx(json_ctx->file_ctx);
SCFree(json_ctx);
SCFree(output_ctx);
- return NULL;
+ return result;
}
OutputRegisterFileRotationFlag(&json_ctx->file_ctx->rotation_flag);
} else if (json_ctx->json_out == LOGFILE_TYPE_SYSLOG) {
LogFileFreeCtx(json_ctx->file_ctx);
SCFree(json_ctx);
SCFree(output_ctx);
- return NULL;
+ return result;
}
if (SCConfLogOpenRedis(redis_node, json_ctx->file_ctx) < 0) {
LogFileFreeCtx(json_ctx->file_ctx);
SCFree(json_ctx);
SCFree(output_ctx);
- return NULL;
+ return result;
}
}
#endif
}
SCLogDebug("returning output_ctx %p", output_ctx);
- return output_ctx;
+
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
}
static void OutputJsonDeInitCtx(OutputCtx *output_ctx)
#include "suricata-common.h"
#include "util-buffer.h"
#include "util-logopenfile.h"
+#include "output.h"
void OutputJsonRegister(void);
json_t *CreateJSONHeader(const Packet *p, int direction_sensative, const char *event_type);
json_t *CreateJSONHeaderWithTxId(const Packet *p, int direction_sensitive, const char *event_type, uint64_t tx_id);
int OutputJSONBuffer(json_t *js, LogFileCtx *file_ctx, MemBuffer **buffer);
-OutputCtx *OutputJsonInitCtx(ConfNode *);
+OutputInitResult OutputJsonInitCtx(ConfNode *);
/*
* Global configuration context data
*
* Runs script 'setup' function.
*/
-static OutputCtx *OutputLuaLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult OutputLuaLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{
+ OutputInitResult result = { NULL, false };
if (conf == NULL)
- return NULL;
+ return result;
LogLuaCtx *lua_ctx = SCMalloc(sizeof(LogLuaCtx));
if (unlikely(lua_ctx == NULL))
- return NULL;
+ return result;
memset(lua_ctx, 0x00, sizeof(*lua_ctx));
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
SCFree(lua_ctx);
- return NULL;
+ return result;
}
SCMutexInit(&lua_ctx->m, NULL);
output_ctx->data = lua_ctx;
output_ctx->DeInit = LogLuaSubFree;
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
error:
SCMutexDestroy(&lua_ctx->m);
SCFree(lua_ctx);
SCFree(output_ctx);
- return NULL;
+ return result;
}
static void LogLuaMasterFree(OutputCtx *oc)
* inspect, then fills the OutputCtx::submodules list with the
* proper Logger function for the data type the script needs.
*/
-static OutputCtx *OutputLuaLogInit(ConfNode *conf)
+static OutputInitResult OutputLuaLogInit(ConfNode *conf)
{
+ OutputInitResult result = { NULL, false };
const char *dir = ConfNodeLookupChildValue(conf, "scripts-dir");
if (dir == NULL)
dir = "";
if (scripts == NULL) {
/* No "outputs" section in the configuration. */
SCLogInfo("scripts not defined");
- return NULL;
+ return result;
}
/* global output ctx setup */
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
- return NULL;
+ return result;
}
output_ctx->DeInit = LogLuaMasterFree;
output_ctx->data = SCCalloc(1, sizeof(LogLuaMasterCtx));
if (unlikely(output_ctx->data == NULL)) {
SCFree(output_ctx);
- return NULL;
+ return result;
}
LogLuaMasterCtx *master_config = output_ctx->data;
strlcpy(master_config->path, dir, sizeof(master_config->path));
TAILQ_INSERT_TAIL(&output_ctx->submodules, om, entries);
}
- return output_ctx;
+ result.ctx = output_ctx;
+ result.ok = true;
+ return result;
error:
if (output_ctx->DeInit)
output_ctx->DeInit(output_ctx);
- return NULL;
+ return result;
}
/** \internal
#include "output-streaming.h"
#include "output-stats.h"
-typedef OutputCtx *(*OutputInitFunc)(ConfNode *);
-typedef OutputCtx *(*OutputInitSubFunc)(ConfNode *, OutputCtx *);
+typedef struct OutputInitResult_ {
+ OutputCtx *ctx;
+ bool ok;
+} OutputInitResult;
+
+typedef OutputInitResult (*OutputInitFunc)(ConfNode *);
+typedef OutputInitResult (*OutputInitSubFunc)(ConfNode *, OutputCtx *);
typedef TmEcode (*OutputLogFunc)(ThreadVars *, Packet *, void *);
typedef struct OutputModule_ {
#include "conf.h"
#include "runmodes.h"
#include "runmode-af-packet.h"
-#include "log-httplog.h"
#include "output.h"
+#include "log-httplog.h"
#include "detect-engine-mpm.h"
#include "alert-fastlog.h"
#include "conf.h"
#include "runmodes.h"
#include "runmode-netmap.h"
-#include "log-httplog.h"
#include "output.h"
+#include "log-httplog.h"
#include "detect-engine-mpm.h"
#include "alert-fastlog.h"
#include "conf.h"
#include "runmodes.h"
#include "runmode-pcap.h"
-#include "log-httplog.h"
#include "output.h"
+#include "log-httplog.h"
#include "util-debug.h"
#include "util-time.h"
#include "util-unittest.h"
#include "util-misc.h"
+#include "output.h"
+
#include "alert-fastlog.h"
#include "alert-prelude.h"
#include "alert-unified2-alert.h"
#include "log-httplog.h"
-#include "output.h"
-
#include "source-pfring.h"
#include "tmqh-flow.h"
// sub_output_config may be NULL if no config
/* pass on parent output_ctx */
- OutputCtx *sub_output_ctx =
- sub_module->InitSubFunc(sub_output_config,
- parent_ctx);
- if (sub_output_ctx == NULL) {
+ OutputInitResult result =
+ sub_module->InitSubFunc(sub_output_config, parent_ctx);
+ if (!result.ok || result.ctx == NULL) {
continue;
}
- AddOutputToFreeList(sub_module, sub_output_ctx);
+ AddOutputToFreeList(sub_module, result.ctx);
SetupOutput(sub_module->name, sub_module,
- sub_output_ctx);
+ result.ctx);
}
}
BUG_ON(script == NULL);
/* pass on parent output_ctx */
- OutputCtx *sub_output_ctx =
- m->InitSubFunc(script, parent_ctx);
- if (sub_output_ctx == NULL) {
- SCLogInfo("sub_output_ctx NULL, skipping");
+ OutputInitResult result = m->InitSubFunc(script, parent_ctx);
+ if (!result.ok || result.ctx == NULL) {
continue;
}
- AddOutputToFreeList(m, sub_output_ctx);
- SetupOutput(m->name, m, sub_output_ctx);
+ AddOutputToFreeList(m, result.ctx);
+ SetupOutput(m->name, m, result.ctx);
}
}
OutputCtx *output_ctx = NULL;
if (module->InitFunc != NULL) {
- output_ctx = module->InitFunc(output_config);
- if (output_ctx == NULL) {
+ OutputInitResult r = module->InitFunc(output_config);
+ if (!r.ok) {
FatalErrorOnInit(SC_ERR_INVALID_ARGUMENT,
"output module setup failed");
continue;
+ } else if (r.ctx == NULL) {
+ continue;
}
+ output_ctx = r.ctx;
} else if (module->InitSubFunc != NULL) {
SCLogInfo("skipping submodule");
continue;
OutputCtx *output_ctx = NULL;
if (module->InitFunc != NULL) {
- output_ctx = module->InitFunc(output_config);
- if (output_ctx == NULL) {
+ OutputInitResult r = module->InitFunc(output_config);
+ if (!r.ok) {
+ FatalErrorOnInit(SC_ERR_INVALID_ARGUMENT,
+ "output module setup failed");
+ continue;
+ } else if (r.ctx == NULL) {
continue;
}
+ output_ctx = r.ctx;
}
AddOutputToFreeList(module, output_ctx);
#include "conf.h"
#include "runmodes.h"
#include "runmode-af-packet.h"
-#include "log-httplog.h"
#include "output.h"
+#include "log-httplog.h"
#include "detect-engine.h"
#include "detect-engine-mpm.h"