selinux_stub.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // +build !selinux
  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. // SetFileLabel sets the SELinux label for this path or returns an error.
  31. func SetFileLabel(fpath string, label string) error {
  32. return nil
  33. }
  34. // FileLabel returns the SELinux label for this path or returns an error.
  35. func FileLabel(fpath string) (string, error) {
  36. return "", nil
  37. }
  38. /*
  39. SetFSCreateLabel tells kernel the label to create all file system objects
  40. created by this task. Setting label="" to return to default.
  41. */
  42. func SetFSCreateLabel(label string) error {
  43. return nil
  44. }
  45. /*
  46. FSCreateLabel returns the default label the kernel which the kernel is using
  47. for file system objects created by this task. "" indicates default.
  48. */
  49. func FSCreateLabel() (string, error) {
  50. return "", nil
  51. }
  52. // CurrentLabel returns the SELinux label of the current process thread, or an error.
  53. func CurrentLabel() (string, error) {
  54. return "", nil
  55. }
  56. // PidLabel returns the SELinux label of the given pid, or an error.
  57. func PidLabel(pid int) (string, error) {
  58. return "", nil
  59. }
  60. /*
  61. ExecLabel returns the SELinux label that the kernel will use for any programs
  62. that are executed by the current process thread, or an error.
  63. */
  64. func ExecLabel() (string, error) {
  65. return "", nil
  66. }
  67. /*
  68. CanonicalizeContext takes a context string and writes it to the kernel
  69. the function then returns the context that the kernel will use. This function
  70. can be used to see if two contexts are equivalent
  71. */
  72. func CanonicalizeContext(val string) (string, error) {
  73. return "", nil
  74. }
  75. /*
  76. SetExecLabel sets the SELinux label that the kernel will use for any programs
  77. that are executed by the current process thread, or an error.
  78. */
  79. func SetExecLabel(label string) error {
  80. return nil
  81. }
  82. // Get returns the Context as a string
  83. func (c Context) Get() string {
  84. return ""
  85. }
  86. // NewContext creates a new Context struct from the specified label
  87. func NewContext(label string) Context {
  88. c := make(Context)
  89. return c
  90. }
  91. // ReserveLabel reserves the MLS/MCS level component of the specified label
  92. func ReserveLabel(label string) {
  93. return
  94. }
  95. // EnforceMode returns the current SELinux mode Enforcing, Permissive, Disabled
  96. func EnforceMode() int {
  97. return Disabled
  98. }
  99. /*
  100. SetEnforceMode sets the current SELinux mode Enforcing, Permissive.
  101. Disabled is not valid, since this needs to be set at boot time.
  102. */
  103. func SetEnforceMode(mode int) error {
  104. return nil
  105. }
  106. /*
  107. DefaultEnforceMode returns the systems default SELinux mode Enforcing,
  108. Permissive or Disabled. Note this is is just the default at boot time.
  109. EnforceMode tells you the systems current mode.
  110. */
  111. func DefaultEnforceMode() int {
  112. return Disabled
  113. }
  114. /*
  115. ReleaseLabel will unreserve the MLS/MCS Level field of the specified label.
  116. Allowing it to be used by another process.
  117. */
  118. func ReleaseLabel(label string) {
  119. return
  120. }
  121. // ROFileLabel returns the specified SELinux readonly file label
  122. func ROFileLabel() string {
  123. return ""
  124. }
  125. /*
  126. ContainerLabels returns an allocated processLabel and fileLabel to be used for
  127. container labeling by the calling process.
  128. */
  129. func ContainerLabels() (processLabel string, fileLabel string) {
  130. return "", ""
  131. }
  132. // SecurityCheckContext validates that the SELinux label is understood by the kernel
  133. func SecurityCheckContext(val string) error {
  134. return nil
  135. }
  136. /*
  137. CopyLevel returns a label with the MLS/MCS level from src label replaced on
  138. the dest label.
  139. */
  140. func CopyLevel(src, dest string) (string, error) {
  141. return "", nil
  142. }
  143. // Chcon changes the `fpath` file object to the SELinux label `label`.
  144. // If `fpath` is a directory and `recurse`` is true, Chcon will walk the
  145. // directory tree setting the label.
  146. func Chcon(fpath string, label string, recurse bool) error {
  147. return nil
  148. }
  149. // DupSecOpt takes an SELinux process label and returns security options that
  150. // can be used to set the SELinux Type and Level for future container processes.
  151. func DupSecOpt(src string) []string {
  152. return nil
  153. }
  154. // DisableSecOpt returns a security opt that can be used to disable SELinux
  155. // labeling support for future container processes.
  156. func DisableSecOpt() []string {
  157. return []string{"disable"}
  158. }