label.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Labeling interface for userspace object managers and others.
  3. *
  4. * Author : Eamon Walsh <ewalsh@tycho.nsa.gov>
  5. */
  6. #ifndef _SELABEL_H_
  7. #define _SELABEL_H_
  8. #include <sys/types.h>
  9. #include <selinux/selinux.h>
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /*
  14. * Opaque type used for all label handles.
  15. */
  16. struct selabel_handle;
  17. /*
  18. * Available backends.
  19. */
  20. /* file contexts */
  21. #define SELABEL_CTX_FILE 0
  22. /* media contexts */
  23. #define SELABEL_CTX_MEDIA 1
  24. /* x contexts */
  25. #define SELABEL_CTX_X 2
  26. /* db objects */
  27. #define SELABEL_CTX_DB 3
  28. /*
  29. * Available options
  30. */
  31. /* no-op option, useful for unused slots in an array of options */
  32. #define SELABEL_OPT_UNUSED 0
  33. /* validate contexts before returning them (boolean value) */
  34. #define SELABEL_OPT_VALIDATE 1
  35. /* don't use local customizations to backend data (boolean value) */
  36. #define SELABEL_OPT_BASEONLY 2
  37. /* specify an alternate path to use when loading backend data */
  38. #define SELABEL_OPT_PATH 3
  39. /* select a subset of the search space as an optimization (file backend) */
  40. #define SELABEL_OPT_SUBSET 4
  41. /* total number of options */
  42. #define SELABEL_NOPT 5
  43. /*
  44. * Label operations
  45. */
  46. /**
  47. * selabel_open - Create a labeling handle.
  48. * @backend: one of the constants specifying a supported labeling backend.
  49. * @opts: array of selabel_opt structures specifying label options or NULL.
  50. * @nopts: number of elements in opts array or zero for no options.
  51. *
  52. * Open a labeling backend for use. The available backend identifiers are
  53. * listed above. Options may be provided via the opts parameter; available
  54. * options are listed above. Not all options may be supported by every
  55. * backend. Return value is the created handle on success or NULL with
  56. * @errno set on failure.
  57. */
  58. struct selabel_handle *selabel_open(unsigned int backend,
  59. struct selinux_opt *opts, unsigned nopts);
  60. /**
  61. * selabel_close - Close a labeling handle.
  62. * @handle: specifies handle to close
  63. *
  64. * Destroy the specified handle, closing files, freeing allocated memory,
  65. * etc. The handle may not be further used after it has been closed.
  66. */
  67. void selabel_close(struct selabel_handle *handle);
  68. /**
  69. * selabel_lookup - Perform labeling lookup operation.
  70. * @handle: specifies backend instance to query
  71. * @con: returns the appropriate context with which to label the object
  72. * @key: string input to lookup operation
  73. * @type: numeric input to the lookup operation
  74. *
  75. * Perform a labeling lookup operation. Return %0 on success, -%1 with
  76. * @errno set on failure. The key and type arguments are the inputs to the
  77. * lookup operation; appropriate values are dictated by the backend in use.
  78. * The result is returned in the memory pointed to by @con and must be freed
  79. * by the user with freecon().
  80. */
  81. int selabel_lookup(struct selabel_handle *handle, security_context_t *con,
  82. const char *key, int type);
  83. int selabel_lookup_raw(struct selabel_handle *handle, security_context_t *con,
  84. const char *key, int type);
  85. /**
  86. * selabel_stats - log labeling operation statistics.
  87. * @handle: specifies backend instance to query
  88. *
  89. * Log a message with information about the number of queries performed,
  90. * number of unused matching entries, or other operational statistics.
  91. * Message is backend-specific, some backends may not output a message.
  92. */
  93. void selabel_stats(struct selabel_handle *handle);
  94. /*
  95. * Type codes used by specific backends
  96. */
  97. /* X backend */
  98. #define SELABEL_X_PROP 1
  99. #define SELABEL_X_EXT 2
  100. #define SELABEL_X_CLIENT 3
  101. #define SELABEL_X_EVENT 4
  102. #define SELABEL_X_SELN 5
  103. #define SELABEL_X_POLYPROP 6
  104. #define SELABEL_X_POLYSELN 7
  105. /* DB backend */
  106. #define SELABEL_DB_DATABASE 1
  107. #define SELABEL_DB_SCHEMA 2
  108. #define SELABEL_DB_TABLE 3
  109. #define SELABEL_DB_COLUMN 4
  110. #define SELABEL_DB_SEQUENCE 5
  111. #define SELABEL_DB_VIEW 6
  112. #define SELABEL_DB_PROCEDURE 7
  113. #define SELABEL_DB_BLOB 8
  114. #define SELABEL_DB_TUPLE 9
  115. #ifdef __cplusplus
  116. }
  117. #endif
  118. #endif /* _SELABEL_H_ */