Skip to content

Commit 7da14cc

Browse files
committed
This code was written by: @brandonpayton Co-authored-by: @brandonpayton
1 parent 220caa5 commit 7da14cc

File tree

10 files changed

+61
-1
lines changed

10 files changed

+61
-1
lines changed

headers/modsecurity/audit_log.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ class AuditLog {
167167
bool setType(AuditLogType audit_type);
168168

169169
bool init(std::string *error);
170+
bool reopen(std::string *error);
170171
virtual bool close();
171172

172173
bool saveIfRelevant(Transaction *transaction);

headers/modsecurity/rules_set.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ int msc_rules_add_file(RulesSet *rules, const char *file, const char **error);
102102
int msc_rules_add(RulesSet *rules, const char *plain_rules, const char **error);
103103
void msc_rules_error_cleanup(const char *error);
104104
int msc_rules_cleanup(RulesSet *rules);
105+
int msc_rules_reopen_audit_log(RulesSet *rules, const char **error);
105106

106107
#ifdef __cplusplus
107108
}

src/audit_log/audit_log.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,12 @@ bool AuditLog::merge(AuditLog *from, std::string *error) {
369369
return init(error);
370370
}
371371

372+
bool AuditLog::reopen(std::string *error) {
373+
if (m_writer != NULL) {
374+
return m_writer->reopen(error);
375+
}
376+
return true;
377+
}
372378

373379
} // namespace audit_log
374380
} // namespace modsecurity

src/audit_log/writer/https.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class Https : public Writer {
4242
bool init(std::string *error) override;
4343
bool write(Transaction *transaction, int parts,
4444
std::string *error) override;
45+
bool reopen(std::string *error) override {
46+
return true;
47+
}
4548
};
4649

4750
} // namespace writer

src/audit_log/writer/parallel.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,34 @@ bool Parallel::write(Transaction *transaction, int parts, std::string *error) {
195195
return true;
196196
}
197197

198+
bool Parallel::reopen(std::string *error) {
199+
bool success1 = true;
200+
bool success2 = true;
201+
std::string error1;
202+
std::string error2;
203+
204+
if(!m_audit->m_path1.empty()) {
205+
success1 = utils::SharedFiles::getInstance().reopen(m_audit->m_path1, &error1);
206+
}
207+
if (!m_audit->m_path2.empty()) {
208+
success2 = utils::SharedFiles::getInstance().reopen(m_audit->m_path2, &error2);
209+
}
210+
std::stringstream errorStream;
211+
if (!success1 || !success2) {
212+
errorStream << "There was an error reopening parallel audit logs.";
213+
214+
if (!success1 && !error1.empty()) {
215+
errorStream << " " << error1;
216+
}
217+
if (!success2 && !error2.empty()) {
218+
errorStream << " " << error2;
219+
}
220+
221+
*error = errorStream.str();
222+
}
223+
return success1 && success2;
224+
}
225+
198226
} // namespace writer
199227
} // namespace audit_log
200228
} // namespace modsecurity

src/audit_log/writer/serial.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ bool Serial::write(Transaction *transaction, int parts, std::string *error) {
4949
error);
5050
}
5151

52+
bool Serial::reopen(std::string *error) {
53+
bool success;
54+
55+
std::string errorDetail;
56+
success = utils::SharedFiles::getInstance().reopen(m_audit->m_path1, &errorDetail);
57+
if (!success) {
58+
*error = "There was an error reopening the serial audit log. ";
59+
error->append(errorDetail);
60+
}
61+
62+
return success;
63+
}
64+
5265
} // namespace writer
5366
} // namespace audit_log
5467
} // namespace modsecurity

src/audit_log/writer/serial.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Serial : public Writer {
4747
bool init(std::string *error) override;
4848
bool write(Transaction *transaction, int parts,
4949
std::string *error) override;
50+
bool reopen(std::string *error) override;
5051
};
5152

5253
} // namespace writer

src/audit_log/writer/writer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Writer {
5151
virtual bool init(std::string *error) = 0;
5252
virtual bool write(Transaction *transaction, int parts,
5353
std::string *error) = 0;
54+
virtual bool reopen(std::string *error) = 0;
5455

5556
static void generateBoundary(std::string *boundary);
5657

src/utils/shared_files.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace utils {
3333
class SharedFiles {
3434
public:
3535
bool open(const std::string& fileName, std::string *error);
36+
bool reopen(const std::string& filename, std::string *error);
3637
void close(const std::string& fileName);
3738
bool write(const std::string& fileName, const std::string &msg,
3839
std::string *error);

test/cppcheck_suppressions.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ shiftNegative:src/utils/msc_tree.cc
2121

2222
//
2323
// ModSecurity v3 code...
24-
//
24+
//
25+
26+
functionConst:src/utils/shared_files.h:60
27+
useInitializationList:src/utils/shared_files.h:88
28+
29+
2530
variableScope:src/operators/rx.cc
2631
variableScope:src/operators/rx_global.cc
2732

0 commit comments

Comments
 (0)