2014-04-07 11:41:25 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014
|
|
|
|
* Canonical Ltd. (All rights reserved)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of version 2 of the GNU General Public
|
|
|
|
* License published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, contact Novell, Inc. or Canonical
|
|
|
|
* Ltd.
|
|
|
|
*/
|
|
|
|
#ifndef __AA_RULE_H
|
|
|
|
#define __AA_RULE_H
|
|
|
|
|
2023-05-29 21:24:31 +02:00
|
|
|
#include <cstdint>
|
2014-04-07 11:41:25 -07:00
|
|
|
#include <list>
|
|
|
|
#include <ostream>
|
|
|
|
|
2023-08-02 02:07:36 -07:00
|
|
|
#include "perms.h"
|
2014-04-07 11:41:25 -07:00
|
|
|
#include "policydb.h"
|
|
|
|
|
2021-09-04 03:28:18 -07:00
|
|
|
using namespace std;
|
|
|
|
|
2023-04-23 21:14:18 -07:00
|
|
|
#define PROMPT_COMPAT_UNKNOWN 0
|
|
|
|
#define PROMPT_COMPAT_IGNORE 1
|
|
|
|
#define PROMPT_COMPAT_PERMSV2 2
|
|
|
|
#define PROMPT_COMPAT_DEV 3
|
|
|
|
#define PROMPT_COMPAT_FLAG 4
|
|
|
|
#define PROMPT_COMPAT_PERMSV1 5
|
2023-04-23 20:27:51 -07:00
|
|
|
|
|
|
|
|
2014-04-07 11:41:25 -07:00
|
|
|
class Profile;
|
|
|
|
|
|
|
|
#define RULE_NOT_SUPPORTED 0
|
|
|
|
#define RULE_ERROR -1
|
|
|
|
#define RULE_OK 1
|
|
|
|
|
2021-09-21 03:35:45 -07:00
|
|
|
#define RULE_TYPE_RULE 0
|
|
|
|
#define RULE_TYPE_PREFIX 1
|
|
|
|
#define RULE_TYPE_PERMS 2
|
2023-09-21 20:39:27 -07:00
|
|
|
#define RULE_TYPE_ALL 3
|
2021-09-21 03:35:45 -07:00
|
|
|
// RULE_TYPE_CLASS needs to be last because various class follow it
|
2023-09-21 20:39:27 -07:00
|
|
|
#define RULE_TYPE_CLASS 4
|
2021-09-21 03:35:45 -07:00
|
|
|
|
2023-07-03 23:52:57 -07:00
|
|
|
// rule_cast should only be used after a comparison of rule_type to ensure
|
|
|
|
// that it is valid. Change to dynamic_cast for debugging
|
|
|
|
//#define rule_cast dynamic_cast
|
|
|
|
#define rule_cast static_cast
|
2021-09-21 03:35:45 -07:00
|
|
|
|
2021-09-19 00:59:45 -07:00
|
|
|
typedef enum { RULE_FLAG_NONE = 0,
|
|
|
|
RULE_FLAG_DELETED = 1, // rule deleted - skip
|
|
|
|
RULE_FLAG_MERGED = 2, // rule merged with another rule
|
|
|
|
RULE_FLAG_EXPANDED = 4, // variable expanded
|
|
|
|
RULE_FLAG_SUB = 8, // rule expanded to subrule(s)
|
|
|
|
RULE_FLAG_IMPLIED = 16, // rule not specified in policy but
|
|
|
|
// added because it is implied
|
|
|
|
} rule_flags_t;
|
|
|
|
|
2023-07-03 23:52:57 -07:00
|
|
|
inline rule_flags_t operator|(rule_flags_t a, rule_flags_t b)
|
|
|
|
{
|
|
|
|
return static_cast<rule_flags_t>(static_cast<unsigned int>(a) | static_cast<unsigned int>(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline rule_flags_t operator&(rule_flags_t a, rule_flags_t b)
|
|
|
|
{
|
|
|
|
return static_cast<rule_flags_t>(static_cast<unsigned int>(a) & static_cast<unsigned int>(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline rule_flags_t& operator|=(rule_flags_t &a, const rule_flags_t &b)
|
|
|
|
{
|
|
|
|
a = a | b;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2014-04-07 11:41:25 -07:00
|
|
|
class rule_t {
|
|
|
|
public:
|
2021-09-21 03:35:45 -07:00
|
|
|
int rule_type;
|
2021-09-19 00:59:45 -07:00
|
|
|
rule_flags_t flags;
|
2021-09-21 03:35:45 -07:00
|
|
|
|
2023-07-03 23:52:57 -07:00
|
|
|
rule_t *removed_by;
|
|
|
|
|
parser: add the ability to specify a priority prefix to rules
This enables adding a priority to a rules in policy, finishing out the
priority work done to plumb priority support through the internals in
the previous patch.
Rules have a default priority of 0. The priority prefix can be added
before the other currently support rule prefixes, ie.
[priority prefix][audit qualifier][rule mode][owner]
If present a numerical priority can be assigned to the rule, where the
greater the number the higher the priority. Eg.
priority=1 audit file r /etc/passwd,
priority=-1 deny file w /etc/**,
Rule priority allows the rule with the highest priority to completely
override lower priority rules where they overlap. Within a given
priority level rules will accumulate in standard apparmor fashion.
Eg. given
priority=1 w /*c,
priority=0 r /a*,
priority=-1 k /*b*,
/abc, /bc, /ac .. will have permissions of w
/ab, /abb, /aaa, .. will have permissions of r
/b, /bcb, /bab, .. will have permissions of k
User specified rule priorities are currently capped at the arbitrary
values of 1000, and -1000.
Notes:
* not all rule types support the priority prefix. Rukes like
- network
- capability
- rlimits need to be reworked
need to be reworked to properly preserve the policy rule structure.
* this patch does not support priority on rule blocks
* this patch does not support using a variable in the priority value.
Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-05-11 23:33:42 -07:00
|
|
|
rule_t(int t): rule_type(t), flags(RULE_FLAG_NONE), removed_by(NULL) { }
|
2014-04-07 11:41:25 -07:00
|
|
|
virtual ~rule_t() { };
|
|
|
|
|
2021-09-21 03:35:45 -07:00
|
|
|
bool is_type(int type) { return rule_type == type; }
|
|
|
|
|
2023-07-03 01:41:43 -07:00
|
|
|
// rule has been marked as should be skipped by regular processing
|
2023-07-03 23:52:57 -07:00
|
|
|
bool skip()
|
2023-07-03 01:41:43 -07:00
|
|
|
{
|
2023-07-03 23:52:57 -07:00
|
|
|
return (flags & RULE_FLAG_DELETED);
|
2023-07-03 01:41:43 -07:00
|
|
|
}
|
2014-04-07 11:41:25 -07:00
|
|
|
//virtual bool operator<(rule_t const &rhs)const = 0;
|
|
|
|
virtual std::ostream &dump(std::ostream &os) = 0;
|
2021-09-08 00:25:28 -07:00
|
|
|
|
|
|
|
// Follow methods in order of being called by the parse
|
|
|
|
|
|
|
|
// called when profile is finished parsing
|
|
|
|
virtual void post_parse_profile(Profile &prof __attribute__ ((unused))) { };
|
|
|
|
|
|
|
|
// called before final expansion of variables. So implied rules
|
|
|
|
// can reference variables
|
|
|
|
virtual void add_implied_rules(Profile &prof __attribute__ ((unused))) { };
|
|
|
|
|
|
|
|
// currently only called post parse
|
|
|
|
// needs to change to being interatively called during parse
|
|
|
|
// to support expansion in include names and profile names
|
2014-04-07 11:41:25 -07:00
|
|
|
virtual int expand_variables(void) = 0;
|
2021-09-08 00:25:28 -07:00
|
|
|
|
2021-10-16 02:18:44 -07:00
|
|
|
virtual int cmp(rule_t const &rhs) const {
|
2023-07-03 23:52:57 -07:00
|
|
|
return rule_type - rhs.rule_type;
|
2021-09-19 00:39:28 -07:00
|
|
|
}
|
2021-10-16 02:18:44 -07:00
|
|
|
virtual bool operator<(rule_t const &rhs) const {
|
|
|
|
return cmp(rhs) < 0;
|
|
|
|
}
|
2023-07-03 23:52:57 -07:00
|
|
|
// called by duplicate rule merge/elimination after final expand_vars
|
|
|
|
// to get default rule dedup
|
|
|
|
// child object need to provide
|
|
|
|
// - cmp, operator<
|
|
|
|
// - is_mergeable() returning true
|
|
|
|
// if a child object wants to provide merging of permissions,
|
|
|
|
// it needs to provide a custom cmp fn that doesn't include
|
|
|
|
// permissions and a merge routine that does more than flagging
|
|
|
|
// as dup as below
|
|
|
|
virtual bool is_mergeable(void) { return false; }
|
|
|
|
|
|
|
|
// returns true if merged
|
|
|
|
virtual bool merge(rule_t &rhs)
|
|
|
|
{
|
|
|
|
if (rule_type != rhs.rule_type)
|
|
|
|
return false;
|
|
|
|
if (skip() || rhs.skip())
|
|
|
|
return false;
|
|
|
|
// default merge is just dedup
|
|
|
|
flags |= RULE_FLAG_MERGED;
|
|
|
|
rhs.flags |= (RULE_FLAG_MERGED | RULE_FLAG_DELETED);
|
|
|
|
rhs.removed_by = this;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
2021-09-19 00:39:28 -07:00
|
|
|
|
2021-09-08 00:25:28 -07:00
|
|
|
// called late frontend to generate data for regex backend
|
2014-04-07 11:41:25 -07:00
|
|
|
virtual int gen_policy_re(Profile &prof) = 0;
|
2020-08-09 14:51:55 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
const char *warned_name = NULL;
|
|
|
|
virtual void warn_once(const char *name, const char *msg);
|
|
|
|
virtual void warn_once(const char *name) = 0;
|
|
|
|
|
|
|
|
|
2014-04-07 11:41:25 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
std::ostream &operator<<(std::ostream &os, rule_t &rule);
|
|
|
|
|
|
|
|
typedef std::list<rule_t *> RuleList;
|
|
|
|
|
2021-09-04 03:28:18 -07:00
|
|
|
/* Not classes so they can be used in the bison front end */
|
|
|
|
typedef enum { AUDIT_UNSPECIFIED, AUDIT_FORCE, AUDIT_QUIET } audit_t;
|
2020-06-18 04:06:42 -07:00
|
|
|
typedef enum { RULE_UNSPECIFIED, RULE_ALLOW, RULE_DENY, RULE_PROMPT } rule_mode_t;
|
2023-08-03 23:21:05 -07:00
|
|
|
typedef enum { OWNER_UNSPECIFIED, OWNER_SPECIFIED, OWNER_NOT } owner_t;
|
|
|
|
|
2021-09-04 03:28:18 -07:00
|
|
|
|
|
|
|
/* NOTE: we can not have a constructor for class prefixes. This is
|
|
|
|
* because it will break bison, and we would need to transition to
|
|
|
|
* the C++ bison bindings. Instead get around this by using a
|
|
|
|
* special rule class that inherits prefixes and handles the
|
|
|
|
* contruction
|
|
|
|
*/
|
|
|
|
class prefixes {
|
|
|
|
public:
|
parser: add the ability to specify a priority prefix to rules
This enables adding a priority to a rules in policy, finishing out the
priority work done to plumb priority support through the internals in
the previous patch.
Rules have a default priority of 0. The priority prefix can be added
before the other currently support rule prefixes, ie.
[priority prefix][audit qualifier][rule mode][owner]
If present a numerical priority can be assigned to the rule, where the
greater the number the higher the priority. Eg.
priority=1 audit file r /etc/passwd,
priority=-1 deny file w /etc/**,
Rule priority allows the rule with the highest priority to completely
override lower priority rules where they overlap. Within a given
priority level rules will accumulate in standard apparmor fashion.
Eg. given
priority=1 w /*c,
priority=0 r /a*,
priority=-1 k /*b*,
/abc, /bc, /ac .. will have permissions of w
/ab, /abb, /aaa, .. will have permissions of r
/b, /bcb, /bab, .. will have permissions of k
User specified rule priorities are currently capped at the arbitrary
values of 1000, and -1000.
Notes:
* not all rule types support the priority prefix. Rukes like
- network
- capability
- rlimits need to be reworked
need to be reworked to properly preserve the policy rule structure.
* this patch does not support priority on rule blocks
* this patch does not support using a variable in the priority value.
Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-05-11 23:33:42 -07:00
|
|
|
int priority;
|
2021-09-04 03:28:18 -07:00
|
|
|
audit_t audit;
|
2021-09-09 01:42:51 -07:00
|
|
|
rule_mode_t rule_mode;
|
2023-08-03 23:21:05 -07:00
|
|
|
owner_t owner;
|
2021-09-04 03:28:18 -07:00
|
|
|
|
|
|
|
ostream &dump(ostream &os)
|
|
|
|
{
|
|
|
|
bool output = true;
|
|
|
|
|
|
|
|
switch (audit) {
|
|
|
|
case AUDIT_FORCE:
|
|
|
|
os << "audit";
|
|
|
|
break;
|
|
|
|
case AUDIT_QUIET:
|
|
|
|
os << "quiet";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
output = false;
|
|
|
|
}
|
|
|
|
|
2021-09-09 01:42:51 -07:00
|
|
|
switch (rule_mode) {
|
2020-06-18 04:06:42 -07:00
|
|
|
case RULE_ALLOW:
|
|
|
|
if (output)
|
|
|
|
os << " ";
|
|
|
|
|
|
|
|
os << "allow";
|
|
|
|
output = true;
|
|
|
|
break;
|
2021-09-09 01:42:51 -07:00
|
|
|
case RULE_DENY:
|
2021-09-04 03:28:18 -07:00
|
|
|
if (output)
|
|
|
|
os << " ";
|
|
|
|
|
|
|
|
os << "deny";
|
|
|
|
output = true;
|
2020-06-18 04:06:42 -07:00
|
|
|
break;
|
|
|
|
case RULE_PROMPT:
|
|
|
|
if (output)
|
|
|
|
os << " ";
|
|
|
|
|
|
|
|
os << "prompt";
|
|
|
|
output = true;
|
2021-09-09 01:42:51 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2021-09-04 03:28:18 -07:00
|
|
|
}
|
|
|
|
|
2023-08-03 23:21:05 -07:00
|
|
|
switch (owner) {
|
|
|
|
case OWNER_SPECIFIED:
|
2021-09-04 03:28:18 -07:00
|
|
|
if (output)
|
|
|
|
os << " ";
|
|
|
|
os << "owner";
|
|
|
|
output = true;
|
2023-08-03 23:21:05 -07:00
|
|
|
break;
|
|
|
|
case OWNER_NOT:
|
|
|
|
if (output)
|
|
|
|
os << " ";
|
|
|
|
os << "!owner";
|
|
|
|
output = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2021-09-04 03:28:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (output)
|
|
|
|
os << " ";
|
|
|
|
|
|
|
|
return os;
|
|
|
|
}
|
2023-07-03 23:52:57 -07:00
|
|
|
|
|
|
|
int cmp(prefixes const &rhs) const {
|
parser: add the ability to specify a priority prefix to rules
This enables adding a priority to a rules in policy, finishing out the
priority work done to plumb priority support through the internals in
the previous patch.
Rules have a default priority of 0. The priority prefix can be added
before the other currently support rule prefixes, ie.
[priority prefix][audit qualifier][rule mode][owner]
If present a numerical priority can be assigned to the rule, where the
greater the number the higher the priority. Eg.
priority=1 audit file r /etc/passwd,
priority=-1 deny file w /etc/**,
Rule priority allows the rule with the highest priority to completely
override lower priority rules where they overlap. Within a given
priority level rules will accumulate in standard apparmor fashion.
Eg. given
priority=1 w /*c,
priority=0 r /a*,
priority=-1 k /*b*,
/abc, /bc, /ac .. will have permissions of w
/ab, /abb, /aaa, .. will have permissions of r
/b, /bcb, /bab, .. will have permissions of k
User specified rule priorities are currently capped at the arbitrary
values of 1000, and -1000.
Notes:
* not all rule types support the priority prefix. Rukes like
- network
- capability
- rlimits need to be reworked
need to be reworked to properly preserve the policy rule structure.
* this patch does not support priority on rule blocks
* this patch does not support using a variable in the priority value.
Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-05-11 23:33:42 -07:00
|
|
|
int tmp = priority - rhs.priority;
|
|
|
|
if (tmp != 0)
|
|
|
|
return tmp;
|
|
|
|
tmp = (int) audit - (int) rhs.audit;
|
2024-05-12 02:19:17 -07:00
|
|
|
if (tmp != 0)
|
|
|
|
return tmp;
|
|
|
|
tmp = (int) rule_mode - (int) rhs.rule_mode;
|
|
|
|
if (tmp != 0)
|
|
|
|
return tmp;
|
2023-08-03 23:21:05 -07:00
|
|
|
if ((uint) owner < (uint) rhs.owner)
|
2023-07-03 23:52:57 -07:00
|
|
|
return -1;
|
2023-08-03 23:21:05 -07:00
|
|
|
if ((uint) owner > (uint) rhs.owner)
|
2023-07-03 23:52:57 -07:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator<(prefixes const &rhs) const {
|
2024-05-12 02:19:17 -07:00
|
|
|
if (cmp(rhs) < 0)
|
2023-07-03 23:52:57 -07:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2021-09-04 03:28:18 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class prefix_rule_t: public rule_t, public prefixes {
|
|
|
|
public:
|
2021-09-21 03:35:45 -07:00
|
|
|
prefix_rule_t(int t = RULE_TYPE_PREFIX) : rule_t(t)
|
2021-09-04 03:28:18 -07:00
|
|
|
{
|
|
|
|
/* Must construct prefix here see note on prefixes */
|
parser: add the ability to specify a priority prefix to rules
This enables adding a priority to a rules in policy, finishing out the
priority work done to plumb priority support through the internals in
the previous patch.
Rules have a default priority of 0. The priority prefix can be added
before the other currently support rule prefixes, ie.
[priority prefix][audit qualifier][rule mode][owner]
If present a numerical priority can be assigned to the rule, where the
greater the number the higher the priority. Eg.
priority=1 audit file r /etc/passwd,
priority=-1 deny file w /etc/**,
Rule priority allows the rule with the highest priority to completely
override lower priority rules where they overlap. Within a given
priority level rules will accumulate in standard apparmor fashion.
Eg. given
priority=1 w /*c,
priority=0 r /a*,
priority=-1 k /*b*,
/abc, /bc, /ac .. will have permissions of w
/ab, /abb, /aaa, .. will have permissions of r
/b, /bcb, /bab, .. will have permissions of k
User specified rule priorities are currently capped at the arbitrary
values of 1000, and -1000.
Notes:
* not all rule types support the priority prefix. Rukes like
- network
- capability
- rlimits need to be reworked
need to be reworked to properly preserve the policy rule structure.
* this patch does not support priority on rule blocks
* this patch does not support using a variable in the priority value.
Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-05-11 23:33:42 -07:00
|
|
|
priority = 0;
|
2021-09-04 03:28:18 -07:00
|
|
|
audit = AUDIT_UNSPECIFIED;
|
2021-09-09 01:42:51 -07:00
|
|
|
rule_mode = RULE_UNSPECIFIED;
|
2023-08-03 23:21:05 -07:00
|
|
|
owner = OWNER_UNSPECIFIED;
|
2021-09-04 03:28:18 -07:00
|
|
|
};
|
|
|
|
|
2022-09-01 09:56:45 -07:00
|
|
|
virtual bool valid_prefix(const prefixes &p, const char *&error) = 0;
|
2021-09-04 03:28:18 -07:00
|
|
|
|
2022-09-01 09:56:45 -07:00
|
|
|
virtual bool add_prefix(const prefixes &p, const char *&error) {
|
2021-09-04 03:28:18 -07:00
|
|
|
if (!valid_prefix(p, error))
|
|
|
|
return false;
|
parser: add the ability to specify a priority prefix to rules
This enables adding a priority to a rules in policy, finishing out the
priority work done to plumb priority support through the internals in
the previous patch.
Rules have a default priority of 0. The priority prefix can be added
before the other currently support rule prefixes, ie.
[priority prefix][audit qualifier][rule mode][owner]
If present a numerical priority can be assigned to the rule, where the
greater the number the higher the priority. Eg.
priority=1 audit file r /etc/passwd,
priority=-1 deny file w /etc/**,
Rule priority allows the rule with the highest priority to completely
override lower priority rules where they overlap. Within a given
priority level rules will accumulate in standard apparmor fashion.
Eg. given
priority=1 w /*c,
priority=0 r /a*,
priority=-1 k /*b*,
/abc, /bc, /ac .. will have permissions of w
/ab, /abb, /aaa, .. will have permissions of r
/b, /bcb, /bab, .. will have permissions of k
User specified rule priorities are currently capped at the arbitrary
values of 1000, and -1000.
Notes:
* not all rule types support the priority prefix. Rukes like
- network
- capability
- rlimits need to be reworked
need to be reworked to properly preserve the policy rule structure.
* this patch does not support priority on rule blocks
* this patch does not support using a variable in the priority value.
Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-05-11 23:33:42 -07:00
|
|
|
|
|
|
|
// priority does NOT conflict but allowed at the block
|
|
|
|
// level yet. priority at the block level applies to
|
|
|
|
// the entire block, but only for the level of rules
|
|
|
|
// it is at.
|
|
|
|
// priority within the block arranges order of rules
|
|
|
|
// within the block.
|
|
|
|
if (priority != 0) {
|
|
|
|
error = "priority levels not supported";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
priority = p.priority;
|
|
|
|
|
2023-02-20 14:06:15 -08:00
|
|
|
/* audit conflicts */
|
|
|
|
if (p.audit != AUDIT_UNSPECIFIED) {
|
|
|
|
if (audit != AUDIT_UNSPECIFIED &&
|
|
|
|
audit != p.audit) {
|
2021-09-04 03:28:18 -07:00
|
|
|
error = "conflicting audit prefix";
|
|
|
|
return false;
|
|
|
|
}
|
2023-02-20 14:06:15 -08:00
|
|
|
// audit = p.audit;
|
2021-09-04 03:28:18 -07:00
|
|
|
}
|
2023-02-20 14:06:15 -08:00
|
|
|
|
|
|
|
/* allow deny conflicts */
|
|
|
|
if (p.rule_mode != RULE_UNSPECIFIED) {
|
|
|
|
if (rule_mode != RULE_UNSPECIFIED &&
|
|
|
|
rule_mode != p.rule_mode) {
|
|
|
|
error = "conflicting mode prefix";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
rule_mode = p.rule_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* owner !owner conflicts */
|
|
|
|
if (p.owner) {
|
2023-08-03 23:21:05 -07:00
|
|
|
if (owner != OWNER_UNSPECIFIED &&
|
|
|
|
owner != p.owner) {
|
2023-02-20 14:06:15 -08:00
|
|
|
error = "conflicting owner prefix";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
owner = p.owner;
|
|
|
|
}
|
|
|
|
|
2023-08-03 23:21:05 -07:00
|
|
|
/* TODO: MOVE this ! */
|
2023-02-20 14:06:15 -08:00
|
|
|
/* does the prefix imply a modifier */
|
2021-09-09 01:42:51 -07:00
|
|
|
if (p.rule_mode == RULE_DENY && p.audit == AUDIT_FORCE) {
|
|
|
|
rule_mode = RULE_DENY;
|
|
|
|
} else if (p.rule_mode == RULE_DENY) {
|
|
|
|
rule_mode = RULE_DENY;
|
2021-09-04 03:28:18 -07:00
|
|
|
audit = AUDIT_FORCE;
|
|
|
|
} else if (p.audit != AUDIT_UNSPECIFIED) {
|
|
|
|
audit = p.audit;
|
|
|
|
}
|
2023-02-20 14:06:15 -08:00
|
|
|
|
2021-09-04 03:28:18 -07:00
|
|
|
return true;
|
|
|
|
}
|
2023-09-21 20:39:27 -07:00
|
|
|
virtual bool add_prefix(const prefixes &p) {
|
|
|
|
const char *err;
|
|
|
|
return add_prefix(p, err);
|
|
|
|
}
|
2021-09-04 03:28:18 -07:00
|
|
|
|
2023-07-03 23:52:57 -07:00
|
|
|
int cmp(prefixes const &rhs) const {
|
|
|
|
return prefixes::cmp(rhs);
|
|
|
|
}
|
|
|
|
|
2021-09-19 00:39:28 -07:00
|
|
|
virtual bool operator<(prefixes const &rhs) const {
|
2023-07-03 23:52:57 -07:00
|
|
|
const prefixes *ptr = this;
|
|
|
|
return *ptr < rhs;
|
2021-09-19 00:39:28 -07:00
|
|
|
}
|
2023-07-03 23:52:57 -07:00
|
|
|
|
|
|
|
virtual int cmp(rule_t const &rhs) const {
|
|
|
|
int res = rule_t::cmp(rhs);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
prefix_rule_t const &pr = rule_cast<prefix_rule_t const &>(rhs);
|
|
|
|
const prefixes *lhsptr = this, *rhsptr = ≺
|
|
|
|
return lhsptr->cmp(*rhsptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool operator<(rule_t const &rhs) const {
|
2021-09-19 00:39:28 -07:00
|
|
|
if (rule_type < rhs.rule_type)
|
|
|
|
return true;
|
|
|
|
if (rhs.rule_type < rule_type)
|
|
|
|
return false;
|
2023-07-03 23:52:57 -07:00
|
|
|
prefix_rule_t const &pr = rule_cast<prefix_rule_t const &>(rhs);
|
|
|
|
const prefixes *rhsptr = ≺
|
|
|
|
return *this < *rhsptr;
|
2021-09-19 00:39:28 -07:00
|
|
|
}
|
|
|
|
|
2021-09-04 03:28:18 -07:00
|
|
|
virtual ostream &dump(ostream &os) {
|
|
|
|
prefixes::dump(os);
|
|
|
|
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-09-21 03:35:45 -07:00
|
|
|
/* NOTE: rule_type is RULE_TYPE_CLASS + AA_CLASS */
|
2021-09-10 13:37:54 -07:00
|
|
|
class class_rule_t: public prefix_rule_t {
|
2021-09-04 03:28:18 -07:00
|
|
|
public:
|
2021-09-21 03:35:45 -07:00
|
|
|
class_rule_t(int c): prefix_rule_t(RULE_TYPE_CLASS + c) { }
|
2021-09-10 13:37:54 -07:00
|
|
|
|
2021-09-21 03:35:45 -07:00
|
|
|
int aa_class(void) { return rule_type - RULE_TYPE_CLASS; }
|
2021-09-10 13:37:54 -07:00
|
|
|
|
2023-07-03 23:52:57 -07:00
|
|
|
/* inherit cmp */
|
|
|
|
|
|
|
|
/* we do not inherit operator< from so class_rules children
|
|
|
|
* can in herit the generic one that redirects to cmp()
|
|
|
|
* that does get overriden
|
|
|
|
*/
|
|
|
|
virtual bool operator<(rule_t const &rhs) const {
|
|
|
|
return cmp(rhs) < 0;
|
|
|
|
}
|
|
|
|
|
2021-09-10 13:37:54 -07:00
|
|
|
virtual ostream &dump(ostream &os) {
|
|
|
|
prefix_rule_t::dump(os);
|
|
|
|
|
2021-09-21 03:35:45 -07:00
|
|
|
os << aa_class_table[aa_class()];
|
2021-09-10 13:37:54 -07:00
|
|
|
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2023-07-10 20:04:53 -07:00
|
|
|
/* same as perms_rule_t except enable rule merging instead of just dedup
|
|
|
|
* original permission set is saved off
|
|
|
|
*/
|
2021-09-10 13:37:54 -07:00
|
|
|
class perms_rule_t: public class_rule_t {
|
|
|
|
public:
|
2023-07-10 20:04:53 -07:00
|
|
|
perms_rule_t(int c): class_rule_t(c), perms(0), saved(0) { };
|
2021-09-04 03:28:18 -07:00
|
|
|
|
2023-07-03 23:52:57 -07:00
|
|
|
virtual int cmp(rule_t const &rhs) const {
|
2023-07-10 20:04:53 -07:00
|
|
|
/* don't compare perms so they can be merged */
|
|
|
|
return class_rule_t::cmp(rhs);
|
2023-07-03 23:52:57 -07:00
|
|
|
}
|
|
|
|
|
2023-07-10 17:58:08 -03:00
|
|
|
virtual bool merge(rule_t &rhs)
|
|
|
|
{
|
|
|
|
int res = class_rule_t::merge(rhs);
|
|
|
|
if (!res)
|
|
|
|
return res;
|
2023-07-10 20:04:53 -07:00
|
|
|
if (!saved)
|
|
|
|
saved = perms;
|
2023-07-10 17:58:08 -03:00
|
|
|
perms |= (rule_cast<perms_rule_t const &>(rhs)).perms;
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2021-09-04 03:28:18 -07:00
|
|
|
/* defaut perms, override/mask off if none default used */
|
|
|
|
virtual ostream &dump(ostream &os) {
|
2023-07-10 20:04:53 -07:00
|
|
|
class_rule_t::dump(os);
|
|
|
|
|
|
|
|
if (saved)
|
|
|
|
os << "(0x" << hex << perms << "/orig " << saved << ") ";
|
|
|
|
else
|
|
|
|
os << "(0x" << hex << perms << ") ";
|
2021-09-04 03:28:18 -07:00
|
|
|
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2023-08-02 02:07:36 -07:00
|
|
|
perm32_t perms, saved;
|
2023-07-10 20:04:53 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// alternate perms rule class that only does dedup instead of perms merging
|
|
|
|
class dedup_perms_rule_t: public class_rule_t {
|
|
|
|
public:
|
|
|
|
dedup_perms_rule_t(int c): class_rule_t(c), perms(0) { };
|
|
|
|
|
|
|
|
virtual int cmp(rule_t const &rhs) const {
|
|
|
|
int res = class_rule_t::cmp(rhs);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
return perms - (rule_cast<perms_rule_t const &>(rhs)).perms;
|
|
|
|
}
|
2021-09-04 03:28:18 -07:00
|
|
|
|
2023-07-10 20:04:53 -07:00
|
|
|
// inherit default merge which does dedup
|
|
|
|
|
|
|
|
/* defaut perms, override/mask off if none default used */
|
|
|
|
virtual ostream &dump(ostream &os) {
|
|
|
|
class_rule_t::dump(os);
|
|
|
|
|
|
|
|
os << "(0x" << hex << perms << ") ";
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2023-08-02 02:07:36 -07:00
|
|
|
perm32_t perms;
|
2021-09-04 03:28:18 -07:00
|
|
|
};
|
|
|
|
|
2023-07-10 20:04:53 -07:00
|
|
|
|
2014-04-07 11:41:25 -07:00
|
|
|
#endif /* __AA_RULE_H */
|
|
|
|
|