avtab.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* Author : Stephen Smalley, <sds@epoch.ncsc.mil> */
  2. /*
  3. * Updated: Yuichi Nakamura <ynakam@hitachisoft.jp>
  4. * Tuned number of hash slots for avtab to reduce memory usage
  5. */
  6. /* Updated: Frank Mayer <mayerf@tresys.com> and Karl MacMillan <kmacmillan@tresys.com>
  7. *
  8. * Added conditional policy language extensions
  9. *
  10. * Copyright (C) 2003 Tresys Technology, LLC
  11. *
  12. * This library is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU Lesser General Public
  14. * License as published by the Free Software Foundation; either
  15. * version 2.1 of the License, or (at your option) any later version.
  16. *
  17. * This library is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * Lesser General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Lesser General Public
  23. * License along with this library; if not, write to the Free Software
  24. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  25. */
  26. /* FLASK */
  27. /*
  28. * An access vector table (avtab) is a hash table
  29. * of access vectors and transition types indexed
  30. * by a type pair and a class. An access vector
  31. * table is used to represent the type enforcement
  32. * tables.
  33. */
  34. #ifndef _SEPOL_POLICYDB_AVTAB_H_
  35. #define _SEPOL_POLICYDB_AVTAB_H_
  36. #include <sys/types.h>
  37. #include <stdint.h>
  38. typedef struct avtab_key {
  39. uint16_t source_type;
  40. uint16_t target_type;
  41. uint16_t target_class;
  42. #define AVTAB_ALLOWED 1
  43. #define AVTAB_AUDITALLOW 2
  44. #define AVTAB_AUDITDENY 4
  45. #define AVTAB_NEVERALLOW 128
  46. #define AVTAB_AV (AVTAB_ALLOWED | AVTAB_AUDITALLOW | AVTAB_AUDITDENY)
  47. #define AVTAB_TRANSITION 16
  48. #define AVTAB_MEMBER 32
  49. #define AVTAB_CHANGE 64
  50. #define AVTAB_TYPE (AVTAB_TRANSITION | AVTAB_MEMBER | AVTAB_CHANGE)
  51. #define AVTAB_ENABLED_OLD 0x80000000
  52. #define AVTAB_ENABLED 0x8000 /* reserved for used in cond_avtab */
  53. uint16_t specified; /* what fields are specified */
  54. } avtab_key_t;
  55. typedef struct avtab_datum {
  56. uint32_t data; /* access vector or type */
  57. } avtab_datum_t;
  58. typedef struct avtab_node *avtab_ptr_t;
  59. struct avtab_node {
  60. avtab_key_t key;
  61. avtab_datum_t datum;
  62. avtab_ptr_t next;
  63. void *parse_context; /* generic context pointer used by parser;
  64. * not saved in binary policy */
  65. unsigned merged; /* flag for avtab_write only;
  66. not saved in binary policy */
  67. };
  68. typedef struct avtab {
  69. avtab_ptr_t *htable;
  70. uint32_t nel; /* number of elements */
  71. uint32_t nslot; /* number of hash slots */
  72. uint16_t mask; /* mask to compute hash func */
  73. } avtab_t;
  74. extern int avtab_init(avtab_t *);
  75. extern int avtab_alloc(avtab_t *, uint32_t);
  76. extern int avtab_insert(avtab_t * h, avtab_key_t * k, avtab_datum_t * d);
  77. extern avtab_datum_t *avtab_search(avtab_t * h, avtab_key_t * k);
  78. extern void avtab_destroy(avtab_t * h);
  79. extern int avtab_map(avtab_t * h,
  80. int (*apply) (avtab_key_t * k,
  81. avtab_datum_t * d, void *args), void *args);
  82. extern void avtab_hash_eval(avtab_t * h, char *tag);
  83. struct policy_file;
  84. extern int avtab_read_item(struct policy_file *fp, uint32_t vers, avtab_t * a,
  85. int (*insert) (avtab_t * a, avtab_key_t * k,
  86. avtab_datum_t * d, void *p), void *p);
  87. extern int avtab_read(avtab_t * a, struct policy_file *fp, uint32_t vers);
  88. extern avtab_ptr_t avtab_insert_nonunique(avtab_t * h, avtab_key_t * key,
  89. avtab_datum_t * datum);
  90. extern avtab_ptr_t avtab_insert_with_parse_context(avtab_t * h,
  91. avtab_key_t * key,
  92. avtab_datum_t * datum,
  93. void *parse_context);
  94. extern avtab_ptr_t avtab_search_node(avtab_t * h, avtab_key_t * key);
  95. extern avtab_ptr_t avtab_search_node_next(avtab_ptr_t node, int specified);
  96. #define MAX_AVTAB_HASH_BITS 13
  97. #define MAX_AVTAB_HASH_BUCKETS (1 << MAX_AVTAB_HASH_BITS)
  98. #define MAX_AVTAB_HASH_MASK (MAX_AVTAB_HASH_BUCKETS-1)
  99. #define MAX_AVTAB_SIZE MAX_AVTAB_HASH_BUCKETS
  100. #endif /* _AVTAB_H_ */
  101. /* FLASK */