conditional.h 2.4 KB

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