Skip to content

Commit 7a39b4b

Browse files
p0pr0ck5Felipe Zimmerle
authored andcommitted
Make JSON audit logging a configurable option
Remove compile-time setting for generating audit logs as JSON, creating a new config option (SecAuditLogFormat). sec_audit_logger is now a wrapper for sec_audit_logger_json or sec_audit_logger_native. This has the disadvantage of making the audit log generation code harder to maintain, but the logger function itself now is no longer pepper with binary branches.
1 parent dd79bea commit 7a39b4b

File tree

5 files changed

+819
-348
lines changed

5 files changed

+819
-348
lines changed

apache2/apache2_config.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ 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+
dcfg->auditlog_format = NOT_SET;
7677
dcfg->max_rule_time = NOT_SET;
7778
dcfg->auditlog_dirperms = NOT_SET;
7879
dcfg->auditlog_fileperms = NOT_SET;
@@ -503,6 +504,8 @@ void *merge_directory_configs(apr_pool_t *mp, void *_parent, void *_child)
503504
merged->auditlog2_fd = parent->auditlog2_fd;
504505
merged->auditlog2_name = parent->auditlog2_name;
505506
}
507+
merged->auditlog_format = (child->auditlog_format == NOT_SET
508+
? parent->auditlog_format : child->auditlog_format);
506509
merged->auditlog_storage_dir = (child->auditlog_storage_dir == NOT_SET_P
507510
? parent->auditlog_storage_dir : child->auditlog_storage_dir);
508511
merged->auditlog_parts = (child->auditlog_parts == NOT_SET_P
@@ -667,6 +670,7 @@ void init_directory_config(directory_config *dcfg)
667670
/* audit log variables */
668671
if (dcfg->auditlog_flag == NOT_SET) dcfg->auditlog_flag = 0;
669672
if (dcfg->auditlog_type == NOT_SET) dcfg->auditlog_type = AUDITLOG_SERIAL;
673+
if (dcfg->auditlog_format == NOT_SET) dcfg->auditlog_format = AUDITLOGFORMAT_NATIVE;
670674
if (dcfg->max_rule_time == NOT_SET) dcfg->max_rule_time = 0;
671675
if (dcfg->auditlog_dirperms == NOT_SET) dcfg->auditlog_dirperms = CREATEMODE_DIR;
672676
if (dcfg->auditlog_fileperms == NOT_SET) dcfg->auditlog_fileperms = CREATEMODE;
@@ -1291,6 +1295,21 @@ static const char *cmd_audit_log_type(cmd_parms *cmd, void *_dcfg,
12911295
return NULL;
12921296
}
12931297

1298+
static const char *cmd_audit_log_mode(cmd_parms *cmd, void *_dcfg,
1299+
const char *p1)
1300+
{
1301+
directory_config *dcfg = _dcfg;
1302+
1303+
if (strcasecmp(p1, "JSON") == 0) dcfg->auditlog_format = AUDITLOGFORMAT_JSON;
1304+
else
1305+
if (strcasecmp(p1, "Native") == 0) dcfg->auditlog_format = AUDITLOGFORMAT_NATIVE;
1306+
else
1307+
return (const char *)apr_psprintf(cmd->pool,
1308+
"ModSecurity: Unrecognised parameter value for SecAuditLogFormat: %s", p1);
1309+
1310+
return NULL;
1311+
}
1312+
12941313
static const char *cmd_audit_log_dirmode(cmd_parms *cmd, void *_dcfg,
12951314
const char *p1)
12961315
{
@@ -3232,6 +3251,14 @@ const command_rec module_directives[] = {
32323251
"whether to use the old audit log format (Serial) or new (Concurrent)"
32333252
),
32343253

3254+
AP_INIT_TAKE1 (
3255+
"SecAuditLogFormat",
3256+
cmd_audit_log_mode,
3257+
NULL,
3258+
CMD_SCOPE_ANY,
3259+
"whether to emit audit log data in native format or JSON"
3260+
),
3261+
32353262
AP_INIT_TAKE1 (
32363263
"SecAuditLogStorageDir",
32373264
cmd_audit_log_storage_dir,

apache2/modsecurity.h

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

522+
/* AUDITLOGFORMAT_NATIVE or AUDITLOGFORMAT_JSON */
523+
int auditlog_format;
524+
522525
/* Mode for audit log directories and files */
523526
apr_fileperms_t auditlog_dirperms;
524527
apr_fileperms_t auditlog_fileperms;

0 commit comments

Comments
 (0)