capability.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (c) 2013, Suryandaru Triandana <[email protected]>
  2. // All rights reserved.
  3. //
  4. // Use of this source code is governed by a BSD-style license that can be
  5. // found in the LICENSE file.
  6. // Package capability provides utilities for manipulating POSIX capabilities.
  7. package capability
  8. type Capabilities interface {
  9. // Get check whether a capability present in the given
  10. // capabilities set. The 'which' value should be one of EFFECTIVE,
  11. // PERMITTED, INHERITABLE or BOUNDING.
  12. Get(which CapType, what Cap) bool
  13. // Empty check whether all capability bits of the given capabilities
  14. // set are zero. The 'which' value should be one of EFFECTIVE,
  15. // PERMITTED, INHERITABLE or BOUNDING.
  16. Empty(which CapType) bool
  17. // Full check whether all capability bits of the given capabilities
  18. // set are one. The 'which' value should be one of EFFECTIVE,
  19. // PERMITTED, INHERITABLE or BOUNDING.
  20. Full(which CapType) bool
  21. // Set sets capabilities of the given capabilities sets. The
  22. // 'which' value should be one or combination (OR'ed) of EFFECTIVE,
  23. // PERMITTED, INHERITABLE or BOUNDING.
  24. Set(which CapType, caps ...Cap)
  25. // Unset unsets capabilities of the given capabilities sets. The
  26. // 'which' value should be one or combination (OR'ed) of EFFECTIVE,
  27. // PERMITTED, INHERITABLE or BOUNDING.
  28. Unset(which CapType, caps ...Cap)
  29. // Fill sets all bits of the given capabilities kind to one. The
  30. // 'kind' value should be one or combination (OR'ed) of CAPS or
  31. // BOUNDS.
  32. Fill(kind CapType)
  33. // Clear sets all bits of the given capabilities kind to zero. The
  34. // 'kind' value should be one or combination (OR'ed) of CAPS or
  35. // BOUNDS.
  36. Clear(kind CapType)
  37. // String return current capabilities state of the given capabilities
  38. // set as string. The 'which' value should be one of EFFECTIVE,
  39. // PERMITTED, INHERITABLE or BOUNDING.
  40. StringCap(which CapType) string
  41. // String return current capabilities state as string.
  42. String() string
  43. // Load load actual capabilities value. This will overwrite all
  44. // outstanding changes.
  45. Load() error
  46. // Apply apply the capabilities settings, so all changes will take
  47. // effect.
  48. Apply(kind CapType) error
  49. }
  50. // NewPid create new initialized Capabilities object for given pid when it
  51. // is nonzero, or for the current pid if pid is 0
  52. func NewPid(pid int) (Capabilities, error) {
  53. return newPid(pid)
  54. }
  55. // NewFile create new initialized Capabilities object for given named file.
  56. func NewFile(name string) (Capabilities, error) {
  57. return newFile(name)
  58. }