blob: ec846e45904c8ddbe655895e6e7c5e6e4faad573 [file] [log] [blame]
Thomas Gleixnera10e7632019-05-31 01:09:32 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/* Authors: Karl MacMillan <kmacmillan@tresys.com>
3 * Frank Mayer <mayerf@tresys.com>
4 *
5 * Copyright (C) 2003 - 2004 Tresys Technology, LLC
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7
8#ifndef _CONDITIONAL_H_
9#define _CONDITIONAL_H_
10
11#include "avtab.h"
12#include "symtab.h"
13#include "policydb.h"
James Morris7b98a582011-08-30 12:52:32 +100014#include "../include/conditional.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
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 */
22struct cond_expr {
23#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 */
Vesa-Matti Kari421fae02008-08-06 18:24:51 +030030#define COND_LAST COND_NEQ
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 __u32 expr_type;
32 __u32 bool;
33 struct cond_expr *next;
34};
35
36/*
37 * Each cond_node contains a list of rules to be enabled/disabled
38 * depending on the current value of the conditional expression. This
39 * struct is for that list.
40 */
41struct cond_av_list {
42 struct avtab_node *node;
43 struct cond_av_list *next;
44};
45
46/*
47 * A cond node represents a conditional block in a policy. It
48 * contains a conditional expression, the current state of the expression,
49 * two lists of rules to enable/disable depending on the value of the
50 * expression (the true list corresponds to if and the false list corresponds
51 * to else)..
52 */
53struct cond_node {
54 int cur_state;
55 struct cond_expr *expr;
56 struct cond_av_list *true_list;
57 struct cond_av_list *false_list;
58 struct cond_node *next;
59};
60
Eric Parisccb3cbe2008-04-22 17:46:12 -040061int cond_policydb_init(struct policydb *p);
62void cond_policydb_destroy(struct policydb *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Eric Parisccb3cbe2008-04-22 17:46:12 -040064int cond_init_bool_indexes(struct policydb *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065int cond_destroy_bool(void *key, void *datum, void *p);
66
67int cond_index_bool(void *key, void *datum, void *datap);
68
69int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp);
70int cond_read_list(struct policydb *p, void *fp);
Eric Pariscee74f42010-10-13 17:50:25 -040071int cond_write_bool(void *key, void *datum, void *ptr);
72int cond_write_list(struct policydb *p, struct cond_node *list, void *fp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Jeff Vander Stoepfa1aa142015-07-10 17:19:56 -040074void cond_compute_av(struct avtab *ctab, struct avtab_key *key,
75 struct av_decision *avd, struct extended_perms *xperms);
76void cond_compute_xperms(struct avtab *ctab, struct avtab_key *key,
77 struct extended_perms_decision *xpermd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078int evaluate_cond_node(struct policydb *p, struct cond_node *node);
79
80#endif /* _CONDITIONAL_H_ */