void Audit::addRule(const std::vector<char> &rule)
{
- try {
- std::lock_guard<std::mutex> lock(nlLock);
- nl.send(AUDIT_ADD_RULE, rule);
- } catch (runtime::Exception &e) {
- ERROR("Audit addRule error : " + std::string(e.what()));
- }
+ std::lock_guard<std::mutex> lock(nlLock);
+ nl.send(AUDIT_ADD_RULE, rule);
}
void Audit::removeRule(const std::vector<char> &rule)
{
- try {
- std::lock_guard<std::mutex> lock(nlLock);
- nl.send(AUDIT_DEL_RULE, rule);
- } catch (runtime::Exception &e) {
- ERROR("Audit removeRule error : " + std::string(e.what()));
- }
+ std::lock_guard<std::mutex> lock(nlLock);
+ nl.send(AUDIT_DEL_RULE, rule);
}
Arg3 = AUDIT_ARG3,
Tag = AUDIT_FILTERKEY,
+ InvalidValue,
};
enum class Operator : unsigned int {
GreaterThanEqual = AUDIT_GREATER_THAN_OR_EQUAL,
BitMask = AUDIT_BIT_MASK,
BitTest = AUDIT_BIT_TEST,
+ InvalidValue,
};
class FieldBase {
Field(FieldType type)
: _type(type), _op(Operator::Default), _value()
{
+ if (type >= FieldType::InvalidValue)
+ throw runtime::Exception("Invalid field type");
}
/* TODO: to be removed below constructor */
Field(FieldType type, Operator op, T value)
: _type(type), _op(op), _value(value)
{
+ if ((type >= FieldType::InvalidValue) || (op >= Operator::InvalidValue))
+ throw runtime::Exception("Invalid value to make rule");
+
if (FieldBase::isString(type) && std::is_same<int, T>::value)
throw runtime::Exception("Wrong field value type");
}
unsigned int op, const void *value)
{
RET_ON_FAILURE(handle, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
+ RET_ON_FAILURE(value, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
try {
GetAuditRule(handle).setCondition(
unsigned int op, const void *value)
{
RET_ON_FAILURE(handle, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
+ RET_ON_FAILURE(value, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
try {
GetAuditRule(handle).unsetCondition(FieldType(field));
AuditTrailContext &client = GetAuditTrailContext(handle);
auto manager = client.createInterface<RuleManagement>();
- manager.addRule(GetAuditRule(rule).data());
+ if (manager.addRule(GetAuditRule(rule).data()) < 0)
+ return AUDIT_TRAIL_ERROR_INVALID_PARAMETER;
return AUDIT_TRAIL_ERROR_NONE;
}
AuditTrailContext &client = GetAuditTrailContext(handle);
auto manager = client.createInterface<RuleManagement>();
- manager.removeRule(GetAuditRule(rule).data());
+ if (manager.removeRule(GetAuditRule(rule).data()) < 0)
+ return AUDIT_TRAIL_ERROR_INVALID_PARAMETER;
return AUDIT_TRAIL_ERROR_NONE;
}
AuditTrailContext &client = GetAuditTrailContext(handle);
auto manager = client.createInterface<RuleManagement>();
- manager.loadRuleSet(name);
+ if (manager.loadRuleSet(name) < 0)
+ return AUDIT_TRAIL_ERROR_INVALID_PARAMETER;
return AUDIT_TRAIL_ERROR_NONE;
}
RuleApplyEngine::RuleApplyEngine()
{
- addNeverRules();
}
RuleApplyEngine::~RuleApplyEngine()
if (r == rule)
return;
}
+
+ audit.addRule(data);
+ audit.removeRule(data);
+
adminList.emplace_back(rule);
removeAll(audit);
+ addNeverRules();
+
optimize(rule);
applyNeverRules();
addAll(audit);
void RuleApplyEngine::removeRule(Audit &audit, const std::vector<char> &data)
{
Rule rule(data);
+ bool removed = false;
for (auto r = adminList.begin(); r != adminList.end(); r++) {
if (*r == rule) {
adminList.erase(r);
+ removed = true;
break;
}
}
+ if (!removed)
+ throw runtime::Exception("Failed to remove rule");
+
removeAll(audit);
optimizedList.clear();
addNeverRules();
void RuleApplyEngine::removeAll(Audit &audit)
{
+ if (optimizedList.size() < 2)
+ return;
+
for (auto &r : optimizedList) {
audit.removeRule(r.data());
}
int RuleManagement::addRule(std::vector<char> data)
{
- context.getRuleApplyEngine().addRule(context.getAudit(), data);
+ try {
+ context.getRuleApplyEngine().addRule(context.getAudit(), data);
+ } catch (runtime::Exception &e) {
+ ERROR("Failed to add rule : " + std::string(e.what()));
+ return -1;
+ }
return 0;
}
int RuleManagement::removeRule(std::vector<char> data)
{
- context.getRuleApplyEngine().removeRule(context.getAudit(), data);
+ try {
+ context.getRuleApplyEngine().removeRule(context.getAudit(), data);
+ } catch (runtime::Exception &e) {
+ ERROR("Failed to remove rule : " + std::string(e.what()));
+ return -1;
+ }
return 0;
}
int RuleManagement::loadRuleSet(std::string name)
{
- context.loadRuleSet(name);
+ try {
+ context.loadRuleSet(name);
+ } catch (runtime::Exception &e) {
+ ERROR("Failed to load rule set : " + std::string(e.what()));
+ return -1;
+ }
return 0;
}