selinux_stub.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. /*
  83. SetTaskLabel sets the SELinux label for the current thread, or an error.
  84. This requires the dyntransition permission.
  85. */
  86. func SetTaskLabel(label string) error {
  87. return nil
  88. }
  89. /*
  90. SetSocketLabel sets the SELinux label that the kernel will use for any programs
  91. that are executed by the current process thread, or an error.
  92. */
  93. func SetSocketLabel(label string) error {
  94. return nil
  95. }
  96. // SocketLabel retrieves the current socket label setting
  97. func SocketLabel() (string, error) {
  98. return "", nil
  99. }
  100. // PeerLabel retrieves the label of the client on the other side of a socket
  101. func PeerLabel(fd uintptr) (string, error) {
  102. return "", nil
  103. }
  104. // SetKeyLabel takes a process label and tells the kernel to assign the
  105. // label to the next kernel keyring that gets created
  106. func SetKeyLabel(label string) error {
  107. return nil
  108. }
  109. // KeyLabel retrieves the current kernel keyring label setting
  110. func KeyLabel() (string, error) {
  111. return "", nil
  112. }
  113. // Get returns the Context as a string
  114. func (c Context) Get() string {
  115. return ""
  116. }
  117. // NewContext creates a new Context struct from the specified label
  118. func NewContext(label string) (Context, error) {
  119. c := make(Context)
  120. return c, nil
  121. }
  122. // ClearLabels clears all reserved MLS/MCS levels
  123. func ClearLabels() {
  124. return
  125. }
  126. // ReserveLabel reserves the MLS/MCS level component of the specified label
  127. func ReserveLabel(label string) {
  128. return
  129. }
  130. // EnforceMode returns the current SELinux mode Enforcing, Permissive, Disabled
  131. func EnforceMode() int {
  132. return Disabled
  133. }
  134. /*
  135. SetEnforceMode sets the current SELinux mode Enforcing, Permissive.
  136. Disabled is not valid, since this needs to be set at boot time.
  137. */
  138. func SetEnforceMode(mode int) error {
  139. return nil
  140. }
  141. /*
  142. DefaultEnforceMode returns the systems default SELinux mode Enforcing,
  143. Permissive or Disabled. Note this is is just the default at boot time.
  144. EnforceMode tells you the systems current mode.
  145. */
  146. func DefaultEnforceMode() int {
  147. return Disabled
  148. }
  149. /*
  150. ReleaseLabel will unreserve the MLS/MCS Level field of the specified label.
  151. Allowing it to be used by another process.
  152. */
  153. func ReleaseLabel(label string) {
  154. return
  155. }
  156. // ROFileLabel returns the specified SELinux readonly file label
  157. func ROFileLabel() string {
  158. return ""
  159. }
  160. /*
  161. ContainerLabels returns an allocated processLabel and fileLabel to be used for
  162. container labeling by the calling process.
  163. */
  164. func ContainerLabels() (processLabel string, fileLabel string) {
  165. return "", ""
  166. }
  167. // SecurityCheckContext validates that the SELinux label is understood by the kernel
  168. func SecurityCheckContext(val string) error {
  169. return nil
  170. }
  171. /*
  172. CopyLevel returns a label with the MLS/MCS level from src label replaced on
  173. the dest label.
  174. */
  175. func CopyLevel(src, dest string) (string, error) {
  176. return "", nil
  177. }
  178. // Chcon changes the `fpath` file object to the SELinux label `label`.
  179. // If `fpath` is a directory and `recurse`` is true, Chcon will walk the
  180. // directory tree setting the label.
  181. func Chcon(fpath string, label string, recurse bool) error {
  182. return nil
  183. }
  184. // DupSecOpt takes an SELinux process label and returns security options that
  185. // can be used to set the SELinux Type and Level for future container processes.
  186. func DupSecOpt(src string) ([]string, error) {
  187. return nil, nil
  188. }
  189. // DisableSecOpt returns a security opt that can be used to disable SELinux
  190. // labeling support for future container processes.
  191. func DisableSecOpt() []string {
  192. return []string{"disable"}
  193. }