conditional.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Authors: Karl MacMillan <[email protected]>
  3. * Frank Mayer <[email protected]>
  4. *
  5. * Copyright (C) 2003 - 2004 Tresys Technology, LLC
  6. */
  7. #ifndef _CONDITIONAL_H_
  8. #define _CONDITIONAL_H_
  9. #include "avtab.h"
  10. #include "symtab.h"
  11. #include "policydb.h"
  12. #include "../include/conditional.h"
  13. #define COND_EXPR_MAXDEPTH 10
  14. /*
  15. * A conditional expression is a list of operators and operands
  16. * in reverse polish notation.
  17. */
  18. struct cond_expr_node {
  19. #define COND_BOOL 1 /* plain bool */
  20. #define COND_NOT 2 /* !bool */
  21. #define COND_OR 3 /* bool || bool */
  22. #define COND_AND 4 /* bool && bool */
  23. #define COND_XOR 5 /* bool ^ bool */
  24. #define COND_EQ 6 /* bool == bool */
  25. #define COND_NEQ 7 /* bool != bool */
  26. #define COND_LAST COND_NEQ
  27. u32 expr_type;
  28. u32 bool;
  29. };
  30. struct cond_expr {
  31. struct cond_expr_node *nodes;
  32. u32 len;
  33. };
  34. /*
  35. * Each cond_node contains a list of rules to be enabled/disabled
  36. * depending on the current value of the conditional expression. This
  37. * struct is for that list.
  38. */
  39. struct cond_av_list {
  40. struct avtab_node **nodes;
  41. u32 len;
  42. };
  43. /*
  44. * A cond node represents a conditional block in a policy. It
  45. * contains a conditional expression, the current state of the expression,
  46. * two lists of rules to enable/disable depending on the value of the
  47. * expression (the true list corresponds to if and the false list corresponds
  48. * to else)..
  49. */
  50. struct cond_node {
  51. int cur_state;
  52. struct cond_expr expr;
  53. struct cond_av_list true_list;
  54. struct cond_av_list false_list;
  55. };
  56. void cond_policydb_init(struct policydb *p);
  57. void cond_policydb_destroy(struct policydb *p);
  58. int cond_init_bool_indexes(struct policydb *p);
  59. int cond_destroy_bool(void *key, void *datum, void *p);
  60. int cond_index_bool(void *key, void *datum, void *datap);
  61. int cond_read_bool(struct policydb *p, struct symtab *s, void *fp);
  62. int cond_read_list(struct policydb *p, void *fp);
  63. int cond_write_bool(void *key, void *datum, void *ptr);
  64. int cond_write_list(struct policydb *p, void *fp);
  65. void cond_compute_av(struct avtab *ctab, struct avtab_key *key,
  66. struct av_decision *avd, struct extended_perms *xperms);
  67. void cond_compute_xperms(struct avtab *ctab, struct avtab_key *key,
  68. struct extended_perms_decision *xpermd);
  69. void evaluate_cond_nodes(struct policydb *p);
  70. void cond_policydb_destroy_dup(struct policydb *p);
  71. int cond_policydb_dup(struct policydb *new, struct policydb *orig);
  72. #endif /* _CONDITIONAL_H_ */