Skip to content

Commit 5bc75ec

Browse files
p0pr0ck5Felipe Zimmerle
authored andcommitted
Do not compile in JSON logging support if yajl is not found
1 parent 0c95a7a commit 5bc75ec

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

apache2/apache2_config.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ void *create_directory_config(apr_pool_t *mp, char *path)
7373
/* audit log variables */
7474
dcfg->auditlog_flag = NOT_SET;
7575
dcfg->auditlog_type = NOT_SET;
76+
#ifdef WITH_YAJL
7677
dcfg->auditlog_format = NOT_SET;
78+
#endif
7779
dcfg->max_rule_time = NOT_SET;
7880
dcfg->auditlog_dirperms = NOT_SET;
7981
dcfg->auditlog_fileperms = NOT_SET;
@@ -504,8 +506,10 @@ void *merge_directory_configs(apr_pool_t *mp, void *_parent, void *_child)
504506
merged->auditlog2_fd = parent->auditlog2_fd;
505507
merged->auditlog2_name = parent->auditlog2_name;
506508
}
509+
#ifdef WITH_YAJL
507510
merged->auditlog_format = (child->auditlog_format == NOT_SET
508511
? parent->auditlog_format : child->auditlog_format);
512+
#endif
509513
merged->auditlog_storage_dir = (child->auditlog_storage_dir == NOT_SET_P
510514
? parent->auditlog_storage_dir : child->auditlog_storage_dir);
511515
merged->auditlog_parts = (child->auditlog_parts == NOT_SET_P
@@ -670,7 +674,9 @@ void init_directory_config(directory_config *dcfg)
670674
/* audit log variables */
671675
if (dcfg->auditlog_flag == NOT_SET) dcfg->auditlog_flag = 0;
672676
if (dcfg->auditlog_type == NOT_SET) dcfg->auditlog_type = AUDITLOG_SERIAL;
677+
#ifdef WITH_YAJL
673678
if (dcfg->auditlog_format == NOT_SET) dcfg->auditlog_format = AUDITLOGFORMAT_NATIVE;
679+
#endif
674680
if (dcfg->max_rule_time == NOT_SET) dcfg->max_rule_time = 0;
675681
if (dcfg->auditlog_dirperms == NOT_SET) dcfg->auditlog_dirperms = CREATEMODE_DIR;
676682
if (dcfg->auditlog_fileperms == NOT_SET) dcfg->auditlog_fileperms = CREATEMODE;
@@ -1295,6 +1301,7 @@ static const char *cmd_audit_log_type(cmd_parms *cmd, void *_dcfg,
12951301
return NULL;
12961302
}
12971303

1304+
#ifdef WITH_YAJL
12981305
static const char *cmd_audit_log_mode(cmd_parms *cmd, void *_dcfg,
12991306
const char *p1)
13001307
{
@@ -1309,6 +1316,7 @@ static const char *cmd_audit_log_mode(cmd_parms *cmd, void *_dcfg,
13091316

13101317
return NULL;
13111318
}
1319+
#endif
13121320

13131321
static const char *cmd_audit_log_dirmode(cmd_parms *cmd, void *_dcfg,
13141322
const char *p1)
@@ -3251,13 +3259,15 @@ const command_rec module_directives[] = {
32513259
"whether to use the old audit log format (Serial) or new (Concurrent)"
32523260
),
32533261

3262+
#ifdef WITH_YAJL
32543263
AP_INIT_TAKE1 (
32553264
"SecAuditLogFormat",
32563265
cmd_audit_log_mode,
32573266
NULL,
32583267
CMD_SCOPE_ANY,
32593268
"whether to emit audit log data in native format or JSON"
32603269
),
3270+
#endif
32613271

32623272
AP_INIT_TAKE1 (
32633273
"SecAuditLogStorageDir",

apache2/modsecurity.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,10 @@ struct directory_config {
519519
/* AUDITLOG_SERIAL (single file) or AUDITLOG_CONCURRENT (multiple files) */
520520
int auditlog_type;
521521

522+
#ifdef WITH_YAJL
522523
/* AUDITLOGFORMAT_NATIVE or AUDITLOGFORMAT_JSON */
523524
int auditlog_format;
525+
#endif
524526

525527
/* Mode for audit log directories and files */
526528
apr_fileperms_t auditlog_dirperms;

apache2/msc_logging.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
#include "apr_version.h"
2626
#include <libxml/xmlversion.h>
2727

28+
#ifdef WITH_YAJL
2829
#include <yajl/yajl_gen.h>
2930
#include "msc_logging_json.h"
31+
#endif
3032

3133
/**
3234
* Write the supplied data to the audit log (if the FD is ready), update
@@ -384,6 +386,7 @@ static void sec_auditlog_write_producer_header(modsec_rec *msr) {
384386
sec_auditlog_write(msr, ".\n", 2);
385387
}
386388

389+
#ifdef WITH_YAJL
387390
/**
388391
* Ouput the Producer header into a JSON generator
389392
*/
@@ -415,6 +418,7 @@ static void sec_auditlog_write_producer_header_json(modsec_rec *msr, yajl_gen g)
415418

416419
yajl_gen_array_close(g); // array for producers is finished
417420
}
421+
#endif
418422

419423
/*
420424
* \brief This function will returns the next chain node
@@ -515,6 +519,7 @@ static int chained_is_matched(modsec_rec *msr, const msre_rule *next_rule) {
515519
return 0;
516520
}
517521

522+
#ifdef WITH_YAJL
518523
/**
519524
* Write detailed information about performance metrics into a JSON generator
520525
*/
@@ -1516,6 +1521,7 @@ void sec_audit_logger_json(modsec_rec *msr) {
15161521
apr_file_write_full(msr->txcfg->auditlog2_fd, text, nbytes, &nbytes_written);
15171522
}
15181523
}
1524+
#endif
15191525

15201526
/*
15211527
* Produce an audit log entry in native format.
@@ -2282,9 +2288,13 @@ void sec_audit_logger_native(modsec_rec *msr) {
22822288
* Handler for audit log writers.
22832289
*/
22842290
void sec_audit_logger(modsec_rec *msr) {
2291+
#ifdef WITH_YAJL
22852292
if (msr->txcfg->auditlog_format == AUDITLOGFORMAT_JSON) {
22862293
sec_audit_logger_json(msr);
22872294
} else {
2295+
#endif
22882296
sec_audit_logger_native(msr);
2297+
#ifdef WITH_YAJL
22892298
}
2299+
#endif
22902300
}

apache2/msc_logging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
#define AUDITLOG_SERIAL 0
2323
#define AUDITLOG_CONCURRENT 1
2424

25+
#ifdef WITH_YAJL
2526
#define AUDITLOGFORMAT_JSON 0
2627
#define AUDITLOGFORMAT_NATIVE 1
28+
#endif
2729

2830
#define AUDITLOG_PART_FIRST 'A'
2931
#define AUDITLOG_PART_HEADER 'A'

0 commit comments

Comments
 (0)