avtab.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * An access vector table (avtab) is a hash table
  3. * of access vectors and transition types indexed
  4. * by a type pair and a class. An access vector
  5. * table is used to represent the type enforcement
  6. * tables.
  7. *
  8. * Author : Stephen Smalley, <sds@epoch.ncsc.mil>
  9. */
  10. /* Updated: Frank Mayer <mayerf@tresys.com> and Karl MacMillan <kmacmillan@tresys.com>
  11. *
  12. * Added conditional policy language extensions
  13. *
  14. * Copyright (C) 2003 Tresys Technology, LLC
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation, version 2.
  18. *
  19. * Updated: Yuichi Nakamura <ynakam@hitachisoft.jp>
  20. * Tuned number of hash slots for avtab to reduce memory usage
  21. */
  22. #ifndef _SS_AVTAB_H_
  23. #define _SS_AVTAB_H_
  24. struct avtab_key {
  25. u16 source_type; /* source type */
  26. u16 target_type; /* target type */
  27. u16 target_class; /* target object class */
  28. #define AVTAB_ALLOWED 0x0001
  29. #define AVTAB_AUDITALLOW 0x0002
  30. #define AVTAB_AUDITDENY 0x0004
  31. #define AVTAB_AV (AVTAB_ALLOWED | AVTAB_AUDITALLOW | AVTAB_AUDITDENY)
  32. #define AVTAB_TRANSITION 0x0010
  33. #define AVTAB_MEMBER 0x0020
  34. #define AVTAB_CHANGE 0x0040
  35. #define AVTAB_TYPE (AVTAB_TRANSITION | AVTAB_MEMBER | AVTAB_CHANGE)
  36. #define AVTAB_ENABLED_OLD 0x80000000 /* reserved for used in cond_avtab */
  37. #define AVTAB_ENABLED 0x8000 /* reserved for used in cond_avtab */
  38. u16 specified; /* what field is specified */
  39. };
  40. struct avtab_datum {
  41. u32 data; /* access vector or type value */
  42. };
  43. struct avtab_node {
  44. struct avtab_key key;
  45. struct avtab_datum datum;
  46. struct avtab_node *next;
  47. };
  48. struct avtab {
  49. struct avtab_node **htable;
  50. u32 nel; /* number of elements */
  51. u32 nslot; /* number of hash slots */
  52. u16 mask; /* mask to compute hash func */
  53. };
  54. int avtab_init(struct avtab *);
  55. int avtab_alloc(struct avtab *, u32);
  56. struct avtab_datum *avtab_search(struct avtab *h, struct avtab_key *k);
  57. void avtab_destroy(struct avtab *h);
  58. void avtab_hash_eval(struct avtab *h, char *tag);
  59. struct policydb;
  60. int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol,
  61. int (*insert)(struct avtab *a, struct avtab_key *k,
  62. struct avtab_datum *d, void *p),
  63. void *p);
  64. int avtab_read(struct avtab *a, void *fp, struct policydb *pol);
  65. int avtab_write_item(struct policydb *p, struct avtab_node *cur, void *fp);
  66. int avtab_write(struct policydb *p, struct avtab *a, void *fp);
  67. struct avtab_node *avtab_insert_nonunique(struct avtab *h, struct avtab_key *key,
  68. struct avtab_datum *datum);
  69. struct avtab_node *avtab_search_node(struct avtab *h, struct avtab_key *key);
  70. struct avtab_node *avtab_search_node_next(struct avtab_node *node, int specified);
  71. void avtab_cache_init(void);
  72. void avtab_cache_destroy(void);
  73. #define MAX_AVTAB_HASH_BITS 11
  74. #define MAX_AVTAB_HASH_BUCKETS (1 << MAX_AVTAB_HASH_BITS)
  75. #endif /* _SS_AVTAB_H_ */