blob: ddb43e7e1c756d83be6a5efa6482307a63089bc2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Authors: Karl MacMillan <kmacmillan@tresys.com>
2 * Frank Mayer <mayerf@tresys.com>
3 *
4 * Copyright (C) 2003 - 2004 Tresys Technology, LLC
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2.
8 */
9
10#ifndef _CONDITIONAL_H_
11#define _CONDITIONAL_H_
12
13#include "avtab.h"
14#include "symtab.h"
15#include "policydb.h"
James Morris7b98a582011-08-30 12:52:32 +100016#include "../include/conditional.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#define COND_EXPR_MAXDEPTH 10
19
20/*
21 * A conditional expression is a list of operators and operands
22 * in reverse polish notation.
23 */
24struct cond_expr {
25#define COND_BOOL 1 /* plain bool */
26#define COND_NOT 2 /* !bool */
27#define COND_OR 3 /* bool || bool */
28#define COND_AND 4 /* bool && bool */
29#define COND_XOR 5 /* bool ^ bool */
30#define COND_EQ 6 /* bool == bool */
31#define COND_NEQ 7 /* bool != bool */
Vesa-Matti Kari421fae02008-08-06 18:24:51 +030032#define COND_LAST COND_NEQ
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 __u32 expr_type;
34 __u32 bool;
35 struct cond_expr *next;
36};
37
38/*
39 * Each cond_node contains a list of rules to be enabled/disabled
40 * depending on the current value of the conditional expression. This
41 * struct is for that list.
42 */
43struct cond_av_list {
44 struct avtab_node *node;
45 struct cond_av_list *next;
46};
47
48/*
49 * A cond node represents a conditional block in a policy. It
50 * contains a conditional expression, the current state of the expression,
51 * two lists of rules to enable/disable depending on the value of the
52 * expression (the true list corresponds to if and the false list corresponds
53 * to else)..
54 */
55struct cond_node {
56 int cur_state;
57 struct cond_expr *expr;
58 struct cond_av_list *true_list;
59 struct cond_av_list *false_list;
60 struct cond_node *next;
61};
62
Eric Parisccb3cbe2008-04-22 17:46:12 -040063int cond_policydb_init(struct policydb *p);
64void cond_policydb_destroy(struct policydb *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Eric Parisccb3cbe2008-04-22 17:46:12 -040066int cond_init_bool_indexes(struct policydb *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067int cond_destroy_bool(void *key, void *datum, void *p);
68
69int cond_index_bool(void *key, void *datum, void *datap);
70
71int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp);
72int cond_read_list(struct policydb *p, void *fp);
Eric Pariscee74f42010-10-13 17:50:25 -040073int cond_write_bool(void *key, void *datum, void *ptr);
74int cond_write_list(struct policydb *p, struct cond_node *list, void *fp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Jeff Vander Stoepfa1aa142015-07-10 17:19:56 -040076void cond_compute_av(struct avtab *ctab, struct avtab_key *key,
77 struct av_decision *avd, struct extended_perms *xperms);
78void cond_compute_xperms(struct avtab *ctab, struct avtab_key *key,
79 struct extended_perms_decision *xpermd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080int evaluate_cond_node(struct policydb *p, struct cond_node *node);
81
82#endif /* _CONDITIONAL_H_ */