types.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package libcontainer
  2. import (
  3. "errors"
  4. "github.com/syndtr/gocapability/capability"
  5. )
  6. var (
  7. ErrUnkownNamespace = errors.New("Unknown namespace")
  8. ErrUnkownCapability = errors.New("Unknown capability")
  9. ErrUnsupported = errors.New("Unsupported method")
  10. )
  11. // namespaceList is used to convert the libcontainer types
  12. // into the names of the files located in /proc/<pid>/ns/* for
  13. // each namespace
  14. var (
  15. namespaceList = Namespaces{}
  16. capabilityList = Capabilities{
  17. {Key: "SETPCAP", Value: capability.CAP_SETPCAP, Enabled: false},
  18. {Key: "SYS_MODULE", Value: capability.CAP_SYS_MODULE, Enabled: false},
  19. {Key: "SYS_RAWIO", Value: capability.CAP_SYS_RAWIO, Enabled: false},
  20. {Key: "SYS_PACCT", Value: capability.CAP_SYS_PACCT, Enabled: false},
  21. {Key: "SYS_ADMIN", Value: capability.CAP_SYS_ADMIN, Enabled: false},
  22. {Key: "SYS_NICE", Value: capability.CAP_SYS_NICE, Enabled: false},
  23. {Key: "SYS_RESOURCE", Value: capability.CAP_SYS_RESOURCE, Enabled: false},
  24. {Key: "SYS_TIME", Value: capability.CAP_SYS_TIME, Enabled: false},
  25. {Key: "SYS_TTY_CONFIG", Value: capability.CAP_SYS_TTY_CONFIG, Enabled: false},
  26. {Key: "MKNOD", Value: capability.CAP_MKNOD, Enabled: false},
  27. {Key: "AUDIT_WRITE", Value: capability.CAP_AUDIT_WRITE, Enabled: false},
  28. {Key: "AUDIT_CONTROL", Value: capability.CAP_AUDIT_CONTROL, Enabled: false},
  29. {Key: "MAC_OVERRIDE", Value: capability.CAP_MAC_OVERRIDE, Enabled: false},
  30. {Key: "MAC_ADMIN", Value: capability.CAP_MAC_ADMIN, Enabled: false},
  31. {Key: "NET_ADMIN", Value: capability.CAP_NET_ADMIN, Enabled: false},
  32. }
  33. )
  34. type (
  35. Namespace struct {
  36. Key string `json:"key,omitempty"`
  37. Enabled bool `json:"enabled,omitempty"`
  38. Value int `json:"value,omitempty"`
  39. File string `json:"file,omitempty"`
  40. }
  41. Namespaces []*Namespace
  42. )
  43. func (ns *Namespace) String() string {
  44. return ns.Key
  45. }
  46. func GetNamespace(key string) *Namespace {
  47. for _, ns := range namespaceList {
  48. if ns.Key == key {
  49. return ns
  50. }
  51. }
  52. return nil
  53. }
  54. // Contains returns true if the specified Namespace is
  55. // in the slice
  56. func (n Namespaces) Contains(ns string) bool {
  57. for _, nsp := range n {
  58. if nsp.Key == ns {
  59. return true
  60. }
  61. }
  62. return false
  63. }
  64. type (
  65. Capability struct {
  66. Key string `json:"key,omitempty"`
  67. Enabled bool `json:"enabled"`
  68. Value capability.Cap `json:"value,omitempty"`
  69. }
  70. Capabilities []*Capability
  71. )
  72. func (c *Capability) String() string {
  73. return c.Key
  74. }
  75. func GetCapability(key string) *Capability {
  76. for _, capp := range capabilityList {
  77. if capp.Key == key {
  78. cpy := *capp
  79. return &cpy
  80. }
  81. }
  82. return nil
  83. }
  84. // Contains returns true if the specified Capability is
  85. // in the slice
  86. func (c Capabilities) Contains(capp string) bool {
  87. return c.Get(capp) != nil
  88. }
  89. func (c Capabilities) Get(capp string) *Capability {
  90. for _, cap := range c {
  91. if cap.Key == capp {
  92. return cap
  93. }
  94. }
  95. return nil
  96. }