2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-22 01:57:43 +00:00

parser: add rule merging for signals

Signed-off-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
John Johansen 2023-07-05 03:27:03 -07:00
parent 3ede2c46cf
commit 53b99a82f6
2 changed files with 32 additions and 0 deletions

View File

@ -230,6 +230,35 @@ int signal_rule::expand_variables(void)
return expand_entry_variables(&peer_label);
}
static int cmp_set_int(Signals const &lhs, Signals const &rhs)
{
int res = lhs.size() - rhs.size();
if (res)
return res;
for (Signals::iterator i = lhs.begin(),
j = rhs.begin();
i != lhs.end(); i++, j++) {
res = *i - *j;
if (res)
return res;
}
return 0;
}
int signal_rule::cmp(rule_t const &rhs) const
{
int res = perms_rule_t::cmp(rhs);
if (res)
return res;
signal_rule const &trhs = rule_cast<signal_rule const &>(rhs);
res = null_strcmp(peer_label, trhs.peer_label);
if (res)
return res;
return cmp_set_int(signals, trhs.signals);
}
void signal_rule::warn_once(const char *name)
{
rule_t::warn_once(name, "signal rules not enforced");

View File

@ -57,6 +57,9 @@ public:
virtual int expand_variables(void);
virtual int gen_policy_re(Profile &prof);
virtual bool is_mergeable(void) { return true; }
virtual int cmp(rule_t const &rhs) const;
protected:
virtual void warn_once(const char *name) override;
};