2019-05-31 16:09:32 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Authors: Karl MacMillan <kmacmillan@tresys.com>
|
|
|
|
* Frank Mayer <mayerf@tresys.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 - 2004 Tresys Technology, LLC
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CONDITIONAL_H_
|
|
|
|
#define _CONDITIONAL_H_
|
|
|
|
|
|
|
|
#include "avtab.h"
|
|
|
|
#include "symtab.h"
|
|
|
|
#include "policydb.h"
|
2011-08-30 10:52:32 +08:00
|
|
|
#include "../include/conditional.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#define COND_EXPR_MAXDEPTH 10
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A conditional expression is a list of operators and operands
|
|
|
|
* in reverse polish notation.
|
|
|
|
*/
|
2020-02-03 19:27:22 +08:00
|
|
|
struct cond_expr_node {
|
2005-04-17 06:20:36 +08:00
|
|
|
#define COND_BOOL 1 /* plain bool */
|
|
|
|
#define COND_NOT 2 /* !bool */
|
|
|
|
#define COND_OR 3 /* bool || bool */
|
|
|
|
#define COND_AND 4 /* bool && bool */
|
|
|
|
#define COND_XOR 5 /* bool ^ bool */
|
|
|
|
#define COND_EQ 6 /* bool == bool */
|
|
|
|
#define COND_NEQ 7 /* bool != bool */
|
2008-08-06 23:24:51 +08:00
|
|
|
#define COND_LAST COND_NEQ
|
2020-02-03 19:27:22 +08:00
|
|
|
u32 expr_type;
|
2023-06-02 21:35:10 +08:00
|
|
|
u32 boolean;
|
2020-02-03 19:27:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cond_expr {
|
|
|
|
struct cond_expr_node *nodes;
|
|
|
|
u32 len;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Each cond_node contains a list of rules to be enabled/disabled
|
|
|
|
* depending on the current value of the conditional expression. This
|
|
|
|
* struct is for that list.
|
|
|
|
*/
|
|
|
|
struct cond_av_list {
|
2020-02-03 19:27:21 +08:00
|
|
|
struct avtab_node **nodes;
|
|
|
|
u32 len;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A cond node represents a conditional block in a policy. It
|
|
|
|
* contains a conditional expression, the current state of the expression,
|
|
|
|
* two lists of rules to enable/disable depending on the value of the
|
|
|
|
* expression (the true list corresponds to if and the false list corresponds
|
|
|
|
* to else)..
|
|
|
|
*/
|
|
|
|
struct cond_node {
|
|
|
|
int cur_state;
|
2020-02-03 19:27:22 +08:00
|
|
|
struct cond_expr expr;
|
2020-02-03 19:27:21 +08:00
|
|
|
struct cond_av_list true_list;
|
|
|
|
struct cond_av_list false_list;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2020-03-06 03:55:43 +08:00
|
|
|
void cond_policydb_init(struct policydb *p);
|
2008-04-23 05:46:12 +08:00
|
|
|
void cond_policydb_destroy(struct policydb *p);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-23 05:46:12 +08:00
|
|
|
int cond_init_bool_indexes(struct policydb *p);
|
2005-04-17 06:20:36 +08:00
|
|
|
int cond_destroy_bool(void *key, void *datum, void *p);
|
|
|
|
|
|
|
|
int cond_index_bool(void *key, void *datum, void *datap);
|
|
|
|
|
2020-07-08 19:24:45 +08:00
|
|
|
int cond_read_bool(struct policydb *p, struct symtab *s, void *fp);
|
2005-04-17 06:20:36 +08:00
|
|
|
int cond_read_list(struct policydb *p, void *fp);
|
2010-10-14 05:50:25 +08:00
|
|
|
int cond_write_bool(void *key, void *datum, void *ptr);
|
2020-02-03 19:27:20 +08:00
|
|
|
int cond_write_list(struct policydb *p, void *fp);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-07-11 05:19:56 +08:00
|
|
|
void cond_compute_av(struct avtab *ctab, struct avtab_key *key,
|
|
|
|
struct av_decision *avd, struct extended_perms *xperms);
|
|
|
|
void cond_compute_xperms(struct avtab *ctab, struct avtab_key *key,
|
|
|
|
struct extended_perms_decision *xpermd);
|
2020-02-03 19:27:23 +08:00
|
|
|
void evaluate_cond_nodes(struct policydb *p);
|
2020-08-12 03:01:56 +08:00
|
|
|
void cond_policydb_destroy_dup(struct policydb *p);
|
|
|
|
int cond_policydb_dup(struct policydb *new, struct policydb *orig);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#endif /* _CONDITIONAL_H_ */
|