blob: e47ec6ddeaf616a2e665ab7732c3907debfcd101 [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001/* SPDX-License-Identifier: GPL-2.0-only */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/* Authors: Karl MacMillan <kmacmillan@tresys.com>
3 * Frank Mayer <mayerf@tresys.com>
4 *
5 * Copyright (C) 2003 - 2004 Tresys Technology, LLC
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00006 */
7
8#ifndef _CONDITIONAL_H_
9#define _CONDITIONAL_H_
10
11#include "avtab.h"
12#include "symtab.h"
13#include "policydb.h"
14#include "../include/conditional.h"
15
16#define COND_EXPR_MAXDEPTH 10
17
18/*
19 * A conditional expression is a list of operators and operands
20 * in reverse polish notation.
21 */
Olivier Deprez157378f2022-04-04 15:47:50 +020022struct cond_expr_node {
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000023#define COND_BOOL 1 /* plain bool */
24#define COND_NOT 2 /* !bool */
25#define COND_OR 3 /* bool || bool */
26#define COND_AND 4 /* bool && bool */
27#define COND_XOR 5 /* bool ^ bool */
28#define COND_EQ 6 /* bool == bool */
29#define COND_NEQ 7 /* bool != bool */
30#define COND_LAST COND_NEQ
Olivier Deprez157378f2022-04-04 15:47:50 +020031 u32 expr_type;
32 u32 bool;
33};
34
35struct cond_expr {
36 struct cond_expr_node *nodes;
37 u32 len;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000038};
39
40/*
41 * Each cond_node contains a list of rules to be enabled/disabled
42 * depending on the current value of the conditional expression. This
43 * struct is for that list.
44 */
45struct cond_av_list {
Olivier Deprez157378f2022-04-04 15:47:50 +020046 struct avtab_node **nodes;
47 u32 len;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000048};
49
50/*
51 * A cond node represents a conditional block in a policy. It
52 * contains a conditional expression, the current state of the expression,
53 * two lists of rules to enable/disable depending on the value of the
54 * expression (the true list corresponds to if and the false list corresponds
55 * to else)..
56 */
57struct cond_node {
58 int cur_state;
Olivier Deprez157378f2022-04-04 15:47:50 +020059 struct cond_expr expr;
60 struct cond_av_list true_list;
61 struct cond_av_list false_list;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000062};
63
Olivier Deprez157378f2022-04-04 15:47:50 +020064void cond_policydb_init(struct policydb *p);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000065void cond_policydb_destroy(struct policydb *p);
66
67int cond_init_bool_indexes(struct policydb *p);
68int cond_destroy_bool(void *key, void *datum, void *p);
69
70int cond_index_bool(void *key, void *datum, void *datap);
71
Olivier Deprez157378f2022-04-04 15:47:50 +020072int cond_read_bool(struct policydb *p, struct symtab *s, void *fp);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000073int cond_read_list(struct policydb *p, void *fp);
74int cond_write_bool(void *key, void *datum, void *ptr);
Olivier Deprez157378f2022-04-04 15:47:50 +020075int cond_write_list(struct policydb *p, void *fp);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000076
77void cond_compute_av(struct avtab *ctab, struct avtab_key *key,
78 struct av_decision *avd, struct extended_perms *xperms);
79void cond_compute_xperms(struct avtab *ctab, struct avtab_key *key,
80 struct extended_perms_decision *xpermd);
Olivier Deprez157378f2022-04-04 15:47:50 +020081void evaluate_cond_nodes(struct policydb *p);
82void cond_policydb_destroy_dup(struct policydb *p);
83int cond_policydb_dup(struct policydb *new, struct policydb *orig);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000084
85#endif /* _CONDITIONAL_H_ */