return ret;
}
-std::vector<AuditRule> Audit::getRules()
+std::vector<Rule> Audit::getRules()
{
- std::vector<AuditRule> ret;
+ std::vector<Rule> ret;
std::lock_guard<std::mutex> lock(nlLock);
nl.send(AUDIT_LIST_RULES, std::vector<char>());
case NLMSG_DONE:
break;
case AUDIT_LIST_RULES:
- ret.push_back(msg.second);
+ ret.emplace_back(msg.second);
default:
continue;
}
return ret;
}
-void Audit::addRule(const AuditRule& rule)
+void Audit::addRule(const std::vector<char> &rule)
{
std::lock_guard<std::mutex> lock(nlLock);
- nl.send(AUDIT_ADD_RULE, rule.data());
+ nl.send(AUDIT_ADD_RULE, rule);
}
-void Audit::removeRule(const AuditRule& rule)
+void Audit::removeRule(const std::vector<char> &rule)
{
std::lock_guard<std::mutex> lock(nlLock);
- nl.send(AUDIT_DEL_RULE, rule.data());
+ nl.send(AUDIT_DEL_RULE, rule);
}
#include "rule.h"
#include "client.h"
-#include "audit/audit-rule.h"
+#include "audit-rule/rule.h"
#include "rmi/rule-management.h"
using namespace AuditTrail;
-static inline AuditRule& GetAuditRule(void* handle)
+static inline Rule& GetAuditRule(void* handle)
{
- return *reinterpret_cast<AuditRule*>(handle);
+ return *reinterpret_cast<Rule*>(handle);
}
int audit_rule_create(audit_rule_h* handle)
{
RET_ON_FAILURE(handle, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
- *handle = reinterpret_cast<audit_rule_h>(new AuditRule());
+ *handle = reinterpret_cast<audit_rule_h>(new Rule());
return AUDIT_TRAIL_ERROR_NONE;
}
{
RET_ON_FAILURE(handle, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
- GetAuditRule(handle).addSystemcall(syscall);
+ GetAuditRule(handle).setMask(syscall);
return AUDIT_TRAIL_ERROR_NONE;
}
{
RET_ON_FAILURE(handle, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
- GetAuditRule(handle).removeSystemcall(syscall);
+ GetAuditRule(handle).unsetMask(syscall);
return AUDIT_TRAIL_ERROR_NONE;
}
{
RET_ON_FAILURE(handle, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
- GetAuditRule(handle).addAllSystemcalls();
+ GetAuditRule(handle).setMask();
return AUDIT_TRAIL_ERROR_NONE;
}
{
RET_ON_FAILURE(handle, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
- GetAuditRule(handle).removeAllSystemcalls();
+ GetAuditRule(handle).unsetMask();
return AUDIT_TRAIL_ERROR_NONE;
}
RET_ON_FAILURE(handle, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
try {
- GetAuditRule(handle).addCondition({field, op, (int)(intptr_t)value});
+ GetAuditRule(handle).setCondition(Field<int>{field, op, (int)(intptr_t)value});
return AUDIT_TRAIL_ERROR_NONE;
} catch (std::exception &e) {}
try {
- GetAuditRule(handle).addCondition({field, op, (char *)value});
+ GetAuditRule(handle).setCondition(Field<std::string>{field, op, (char *)value});
return AUDIT_TRAIL_ERROR_NONE;
} catch (std::exception &e) {}
RET_ON_FAILURE(handle, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
try {
- GetAuditRule(handle).addCondition({field, op, (int)(intptr_t)value});
+ GetAuditRule(handle).unsetCondition(Field<int>{field, op, (int)(intptr_t)value});
return AUDIT_TRAIL_ERROR_NONE;
} catch (std::exception &e) {}
try {
- GetAuditRule(handle).addCondition({field, op, (char *)value});
+ GetAuditRule(handle).unsetCondition(Field<std::string>{field, op, (char *)value});
return AUDIT_TRAIL_ERROR_NONE;
} catch (std::exception &e) {}
RET_ON_FAILURE(handle, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
RET_ON_FAILURE(callback, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
- auto syscalls = GetAuditRule(handle).getSystemcalls();
+ auto syscalls = GetAuditRule(handle).getMask();
for (auto syscall : syscalls) {
callback(syscall, user_data);
}
RET_ON_FAILURE(handle, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
RET_ON_FAILURE(callback, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
- auto intConds = GetAuditRule(handle).getConditions<int>();
- auto strConds = GetAuditRule(handle).getConditions<std::string>();
-
- for (auto cond : intConds) {
- callback(cond.getField(), cond.getOperator(),
- (void*)(intptr_t)cond.getValue(), user_data);
- }
-
- for (auto cond : strConds) {
- callback(cond.getField(), cond.getOperator(),
- (void*)cond.getValue().c_str(), user_data);
+ std::vector<char> buf(GetAuditRule(handle).data());
+
+ auto r = reinterpret_cast<struct audit_rule_data *>(buf.data());
+ char *tmp = r->buf;
+
+ for (unsigned int i = 0; i < r->field_count; i++) {
+ if (FieldBase::isString(r->fields[i])) {
+ std::string value(tmp, tmp + r->values[i]);
+ callback(r->fields[i], r->fieldflags[i],
+ (void*)(value.c_str()), user_data);
+ tmp += r->values[i];
+ } else {
+ callback(r->fields[i], r->fieldflags[i],
+ (void*)(intptr_t)(r->values[i]), user_data);
+ }
}
-
return AUDIT_TRAIL_ERROR_NONE;
}
auto rulesData = manager.getRules();
for (auto data : rulesData) {
- callback(reinterpret_cast<audit_rule_h>(new AuditRule(data)),
+ callback(reinterpret_cast<audit_rule_h>(new Rule(data)),
user_data);
}