conditional.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* 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. #ifndef _CONDITIONAL_H_
  10. #define _CONDITIONAL_H_
  11. #include "avtab.h"
  12. #include "symtab.h"
  13. #include "policydb.h"
  14. #define COND_EXPR_MAXDEPTH 10
  15. /*
  16. * A conditional expression is a list of operators and operands
  17. * in reverse polish notation.
  18. */
  19. struct cond_expr {
  20. #define COND_BOOL 1 /* plain bool */
  21. #define COND_NOT 2 /* !bool */
  22. #define COND_OR 3 /* bool || bool */
  23. #define COND_AND 4 /* bool && bool */
  24. #define COND_XOR 5 /* bool ^ bool */
  25. #define COND_EQ 6 /* bool == bool */
  26. #define COND_NEQ 7 /* bool != bool */
  27. #define COND_LAST COND_NEQ
  28. __u32 expr_type;
  29. __u32 bool;
  30. struct cond_expr *next;
  31. };
  32. /*
  33. * Each cond_node contains a list of rules to be enabled/disabled
  34. * depending on the current value of the conditional expression. This
  35. * struct is for that list.
  36. */
  37. struct cond_av_list {
  38. struct avtab_node *node;
  39. struct cond_av_list *next;
  40. };
  41. /*
  42. * A cond node represents a conditional block in a policy. It
  43. * contains a conditional expression, the current state of the expression,
  44. * two lists of rules to enable/disable depending on the value of the
  45. * expression (the true list corresponds to if and the false list corresponds
  46. * to else)..
  47. */
  48. struct cond_node {
  49. int cur_state;
  50. struct cond_expr *expr;
  51. struct cond_av_list *true_list;
  52. struct cond_av_list *false_list;
  53. struct cond_node *next;
  54. };
  55. int 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 hashtab *h, void *fp);
  61. int cond_read_list(struct policydb *p, void *fp);
  62. void cond_compute_av(struct avtab *ctab, struct avtab_key *key, struct av_decision *avd);
  63. int evaluate_cond_node(struct policydb *p, struct cond_node *node);
  64. #endif /* _CONDITIONAL_H_ */