Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /* Authors: Karl MacMillan <kmacmillan@tresys.com>
0003  *          Frank Mayer <mayerf@tresys.com>
0004  *
0005  * Copyright (C) 2003 - 2004 Tresys Technology, LLC
0006  */
0007 
0008 #ifndef _CONDITIONAL_H_
0009 #define _CONDITIONAL_H_
0010 
0011 #include "avtab.h"
0012 #include "symtab.h"
0013 #include "policydb.h"
0014 #include "../include/conditional.h"
0015 
0016 #define COND_EXPR_MAXDEPTH 10
0017 
0018 /*
0019  * A conditional expression is a list of operators and operands
0020  * in reverse polish notation.
0021  */
0022 struct cond_expr_node {
0023 #define COND_BOOL   1 /* plain bool */
0024 #define COND_NOT    2 /* !bool */
0025 #define COND_OR     3 /* bool || bool */
0026 #define COND_AND    4 /* bool && bool */
0027 #define COND_XOR    5 /* bool ^ bool */
0028 #define COND_EQ     6 /* bool == bool */
0029 #define COND_NEQ    7 /* bool != bool */
0030 #define COND_LAST   COND_NEQ
0031     u32 expr_type;
0032     u32 bool;
0033 };
0034 
0035 struct cond_expr {
0036     struct cond_expr_node *nodes;
0037     u32 len;
0038 };
0039 
0040 /*
0041  * Each cond_node contains a list of rules to be enabled/disabled
0042  * depending on the current value of the conditional expression. This
0043  * struct is for that list.
0044  */
0045 struct cond_av_list {
0046     struct avtab_node **nodes;
0047     u32 len;
0048 };
0049 
0050 /*
0051  * A cond node represents a conditional block in a policy. It
0052  * contains a conditional expression, the current state of the expression,
0053  * two lists of rules to enable/disable depending on the value of the
0054  * expression (the true list corresponds to if and the false list corresponds
0055  * to else)..
0056  */
0057 struct cond_node {
0058     int cur_state;
0059     struct cond_expr expr;
0060     struct cond_av_list true_list;
0061     struct cond_av_list false_list;
0062 };
0063 
0064 void cond_policydb_init(struct policydb *p);
0065 void cond_policydb_destroy(struct policydb *p);
0066 
0067 int cond_init_bool_indexes(struct policydb *p);
0068 int cond_destroy_bool(void *key, void *datum, void *p);
0069 
0070 int cond_index_bool(void *key, void *datum, void *datap);
0071 
0072 int cond_read_bool(struct policydb *p, struct symtab *s, void *fp);
0073 int cond_read_list(struct policydb *p, void *fp);
0074 int cond_write_bool(void *key, void *datum, void *ptr);
0075 int cond_write_list(struct policydb *p, void *fp);
0076 
0077 void cond_compute_av(struct avtab *ctab, struct avtab_key *key,
0078         struct av_decision *avd, struct extended_perms *xperms);
0079 void cond_compute_xperms(struct avtab *ctab, struct avtab_key *key,
0080         struct extended_perms_decision *xpermd);
0081 void evaluate_cond_nodes(struct policydb *p);
0082 void cond_policydb_destroy_dup(struct policydb *p);
0083 int cond_policydb_dup(struct policydb *new, struct policydb *orig);
0084 
0085 #endif /* _CONDITIONAL_H_ */