selinux_stub.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // +build !selinux !linux
  2. package selinux
  3. import (
  4. "errors"
  5. )
  6. const (
  7. // Enforcing constant indicate SELinux is in enforcing mode
  8. Enforcing = 1
  9. // Permissive constant to indicate SELinux is in permissive mode
  10. Permissive = 0
  11. // Disabled constant to indicate SELinux is disabled
  12. Disabled = -1
  13. )
  14. var (
  15. // ErrMCSAlreadyExists is returned when trying to allocate a duplicate MCS.
  16. ErrMCSAlreadyExists = errors.New("MCS label already exists")
  17. // ErrEmptyPath is returned when an empty path has been specified.
  18. ErrEmptyPath = errors.New("empty path")
  19. )
  20. // Context is a representation of the SELinux label broken into 4 parts
  21. type Context map[string]string
  22. // SetDisabled disables selinux support for the package
  23. func SetDisabled() {
  24. return
  25. }
  26. // GetEnabled returns whether selinux is currently enabled.
  27. func GetEnabled() bool {
  28. return false
  29. }
  30. // ClassIndex returns the int index for an object class in the loaded policy, or -1 and an error
  31. func ClassIndex(class string) (int, error) {
  32. return -1, nil
  33. }
  34. // SetFileLabel sets the SELinux label for this path or returns an error.
  35. func SetFileLabel(fpath string, label string) error {
  36. return nil
  37. }
  38. // FileLabel returns the SELinux label for this path or returns an error.
  39. func FileLabel(fpath string) (string, error) {
  40. return "", nil
  41. }
  42. /*
  43. SetFSCreateLabel tells kernel the label to create all file system objects
  44. created by this task. Setting label="" to return to default.
  45. */
  46. func SetFSCreateLabel(label string) error {
  47. return nil
  48. }
  49. /*
  50. FSCreateLabel returns the default label the kernel which the kernel is using
  51. for file system objects created by this task. "" indicates default.
  52. */
  53. func FSCreateLabel() (string, error) {
  54. return "", nil
  55. }
  56. // CurrentLabel returns the SELinux label of the current process thread, or an error.
  57. func CurrentLabel() (string, error) {
  58. return "", nil
  59. }
  60. // PidLabel returns the SELinux label of the given pid, or an error.
  61. func PidLabel(pid int) (string, error) {
  62. return "", nil
  63. }
  64. /*
  65. ExecLabel returns the SELinux label that the kernel will use for any programs
  66. that are executed by the current process thread, or an error.
  67. */
  68. func ExecLabel() (string, error) {
  69. return "", nil
  70. }
  71. /*
  72. CanonicalizeContext takes a context string and writes it to the kernel
  73. the function then returns the context that the kernel will use. This function
  74. can be used to see if two contexts are equivalent
  75. */
  76. func CanonicalizeContext(val string) (string, error) {
  77. return "", nil
  78. }
  79. /*
  80. ComputeCreateContext requests the type transition from source to target for class from the kernel.
  81. */
  82. func ComputeCreateContext(source string, target string, class string) (string, error) {
  83. return "", nil
  84. }
  85. /*
  86. SetExecLabel sets the SELinux label that the kernel will use for any programs
  87. that are executed by the current process thread, or an error.
  88. */
  89. func SetExecLabel(label string) error {
  90. return nil
  91. }
  92. /*
  93. SetTaskLabel sets the SELinux label for the current thread, or an error.
  94. This requires the dyntransition permission.
  95. */
  96. func SetTaskLabel(label string) error {
  97. return nil
  98. }
  99. /*
  100. SetSocketLabel sets the SELinux label that the kernel will use for any programs
  101. that are executed by the current process thread, or an error.
  102. */
  103. func SetSocketLabel(label string) error {
  104. return nil
  105. }
  106. // SocketLabel retrieves the current socket label setting
  107. func SocketLabel() (string, error) {
  108. return "", nil
  109. }
  110. // PeerLabel retrieves the label of the client on the other side of a socket
  111. func PeerLabel(fd uintptr) (string, error) {
  112. return "", nil
  113. }
  114. // SetKeyLabel takes a process label and tells the kernel to assign the
  115. // label to the next kernel keyring that gets created
  116. func SetKeyLabel(label string) error {
  117. return nil
  118. }
  119. // KeyLabel retrieves the current kernel keyring label setting
  120. func KeyLabel() (string, error) {
  121. return "", nil
  122. }
  123. // Get returns the Context as a string
  124. func (c Context) Get() string {
  125. return ""
  126. }
  127. // NewContext creates a new Context struct from the specified label
  128. func NewContext(label string) (Context, error) {
  129. c := make(Context)
  130. return c, nil
  131. }
  132. // ClearLabels clears all reserved MLS/MCS levels
  133. func ClearLabels() {
  134. return
  135. }
  136. // ReserveLabel reserves the MLS/MCS level component of the specified label
  137. func ReserveLabel(label string) {
  138. return
  139. }
  140. // EnforceMode returns the current SELinux mode Enforcing, Permissive, Disabled
  141. func EnforceMode() int {
  142. return Disabled
  143. }
  144. /*
  145. SetEnforceMode sets the current SELinux mode Enforcing, Permissive.
  146. Disabled is not valid, since this needs to be set at boot time.
  147. */
  148. func SetEnforceMode(mode int) error {
  149. return nil
  150. }
  151. /*
  152. DefaultEnforceMode returns the systems default SELinux mode Enforcing,
  153. Permissive or Disabled. Note this is is just the default at boot time.
  154. EnforceMode tells you the systems current mode.
  155. */
  156. func DefaultEnforceMode() int {
  157. return Disabled
  158. }
  159. /*
  160. ReleaseLabel will unreserve the MLS/MCS Level field of the specified label.
  161. Allowing it to be used by another process.
  162. */
  163. func ReleaseLabel(label string) {
  164. return
  165. }
  166. // ROFileLabel returns the specified SELinux readonly file label
  167. func ROFileLabel() string {
  168. return ""
  169. }
  170. // KVMContainerLabels returns the default processLabel and mountLabel to be used
  171. // for kvm containers by the calling process.
  172. func KVMContainerLabels() (string, string) {
  173. return "", ""
  174. }
  175. // InitContainerLabels returns the default processLabel and file labels to be
  176. // used for containers running an init system like systemd by the calling
  177. func InitContainerLabels() (string, string) {
  178. return "", ""
  179. }
  180. /*
  181. ContainerLabels returns an allocated processLabel and fileLabel to be used for
  182. container labeling by the calling process.
  183. */
  184. func ContainerLabels() (processLabel string, fileLabel string) {
  185. return "", ""
  186. }
  187. // SecurityCheckContext validates that the SELinux label is understood by the kernel
  188. func SecurityCheckContext(val string) error {
  189. return nil
  190. }
  191. /*
  192. CopyLevel returns a label with the MLS/MCS level from src label replaced on
  193. the dest label.
  194. */
  195. func CopyLevel(src, dest string) (string, error) {
  196. return "", nil
  197. }
  198. // Chcon changes the `fpath` file object to the SELinux label `label`.
  199. // If `fpath` is a directory and `recurse`` is true, Chcon will walk the
  200. // directory tree setting the label.
  201. func Chcon(fpath string, label string, recurse bool) error {
  202. return nil
  203. }
  204. // DupSecOpt takes an SELinux process label and returns security options that
  205. // can be used to set the SELinux Type and Level for future container processes.
  206. func DupSecOpt(src string) ([]string, error) {
  207. return nil, nil
  208. }
  209. // DisableSecOpt returns a security opt that can be used to disable SELinux
  210. // labeling support for future container processes.
  211. func DisableSecOpt() []string {
  212. return []string{"disable"}
  213. }