|
@@ -1,7 +1,6 @@
|
|
|
package libcontainer
|
|
|
|
|
|
import (
|
|
|
- "encoding/json"
|
|
|
"errors"
|
|
|
"github.com/syndtr/gocapability/capability"
|
|
|
)
|
|
@@ -19,29 +18,30 @@ var (
|
|
|
namespaceList = Namespaces{}
|
|
|
|
|
|
capabilityList = Capabilities{
|
|
|
- {Key: "SETPCAP", Value: capability.CAP_SETPCAP},
|
|
|
- {Key: "SYS_MODULE", Value: capability.CAP_SYS_MODULE},
|
|
|
- {Key: "SYS_RAWIO", Value: capability.CAP_SYS_RAWIO},
|
|
|
- {Key: "SYS_PACCT", Value: capability.CAP_SYS_PACCT},
|
|
|
- {Key: "SYS_ADMIN", Value: capability.CAP_SYS_ADMIN},
|
|
|
- {Key: "SYS_NICE", Value: capability.CAP_SYS_NICE},
|
|
|
- {Key: "SYS_RESOURCE", Value: capability.CAP_SYS_RESOURCE},
|
|
|
- {Key: "SYS_TIME", Value: capability.CAP_SYS_TIME},
|
|
|
- {Key: "SYS_TTY_CONFIG", Value: capability.CAP_SYS_TTY_CONFIG},
|
|
|
- {Key: "MKNOD", Value: capability.CAP_MKNOD},
|
|
|
- {Key: "AUDIT_WRITE", Value: capability.CAP_AUDIT_WRITE},
|
|
|
- {Key: "AUDIT_CONTROL", Value: capability.CAP_AUDIT_CONTROL},
|
|
|
- {Key: "MAC_OVERRIDE", Value: capability.CAP_MAC_OVERRIDE},
|
|
|
- {Key: "MAC_ADMIN", Value: capability.CAP_MAC_ADMIN},
|
|
|
- {Key: "NET_ADMIN", Value: capability.CAP_NET_ADMIN},
|
|
|
+ {Key: "SETPCAP", Value: capability.CAP_SETPCAP, Enabled: false},
|
|
|
+ {Key: "SYS_MODULE", Value: capability.CAP_SYS_MODULE, Enabled: false},
|
|
|
+ {Key: "SYS_RAWIO", Value: capability.CAP_SYS_RAWIO, Enabled: false},
|
|
|
+ {Key: "SYS_PACCT", Value: capability.CAP_SYS_PACCT, Enabled: false},
|
|
|
+ {Key: "SYS_ADMIN", Value: capability.CAP_SYS_ADMIN, Enabled: false},
|
|
|
+ {Key: "SYS_NICE", Value: capability.CAP_SYS_NICE, Enabled: false},
|
|
|
+ {Key: "SYS_RESOURCE", Value: capability.CAP_SYS_RESOURCE, Enabled: false},
|
|
|
+ {Key: "SYS_TIME", Value: capability.CAP_SYS_TIME, Enabled: false},
|
|
|
+ {Key: "SYS_TTY_CONFIG", Value: capability.CAP_SYS_TTY_CONFIG, Enabled: false},
|
|
|
+ {Key: "MKNOD", Value: capability.CAP_MKNOD, Enabled: false},
|
|
|
+ {Key: "AUDIT_WRITE", Value: capability.CAP_AUDIT_WRITE, Enabled: false},
|
|
|
+ {Key: "AUDIT_CONTROL", Value: capability.CAP_AUDIT_CONTROL, Enabled: false},
|
|
|
+ {Key: "MAC_OVERRIDE", Value: capability.CAP_MAC_OVERRIDE, Enabled: false},
|
|
|
+ {Key: "MAC_ADMIN", Value: capability.CAP_MAC_ADMIN, Enabled: false},
|
|
|
+ {Key: "NET_ADMIN", Value: capability.CAP_NET_ADMIN, Enabled: false},
|
|
|
}
|
|
|
)
|
|
|
|
|
|
type (
|
|
|
Namespace struct {
|
|
|
- Key string
|
|
|
- Value int
|
|
|
- File string
|
|
|
+ Key string `json:"key,omitempty"`
|
|
|
+ Enabled bool `json:"enabled,omitempty"`
|
|
|
+ Value int `json:"value,omitempty"`
|
|
|
+ File string `json:"file,omitempty"`
|
|
|
}
|
|
|
Namespaces []*Namespace
|
|
|
)
|
|
@@ -50,27 +50,11 @@ func (ns *Namespace) String() string {
|
|
|
return ns.Key
|
|
|
}
|
|
|
|
|
|
-func (ns *Namespace) MarshalJSON() ([]byte, error) {
|
|
|
- return json.Marshal(ns.Key)
|
|
|
-}
|
|
|
-
|
|
|
-func (ns *Namespace) UnmarshalJSON(src []byte) error {
|
|
|
- var nsName string
|
|
|
- if err := json.Unmarshal(src, &nsName); err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- ret := GetNamespace(nsName)
|
|
|
- if ret == nil {
|
|
|
- return ErrUnkownNamespace
|
|
|
- }
|
|
|
- *ns = *ret
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
func GetNamespace(key string) *Namespace {
|
|
|
for _, ns := range namespaceList {
|
|
|
if ns.Key == key {
|
|
|
- return ns
|
|
|
+ cpy := *ns
|
|
|
+ return &cpy
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
@@ -79,18 +63,23 @@ func GetNamespace(key string) *Namespace {
|
|
|
// Contains returns true if the specified Namespace is
|
|
|
// in the slice
|
|
|
func (n Namespaces) Contains(ns string) bool {
|
|
|
+ return n.Get(ns) != nil
|
|
|
+}
|
|
|
+
|
|
|
+func (n Namespaces) Get(ns string) *Namespace {
|
|
|
for _, nsp := range n {
|
|
|
if nsp.Key == ns {
|
|
|
- return true
|
|
|
+ return nsp
|
|
|
}
|
|
|
}
|
|
|
- return false
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
type (
|
|
|
Capability struct {
|
|
|
- Key string
|
|
|
- Value capability.Cap
|
|
|
+ Key string `json:"key,omitempty"`
|
|
|
+ Enabled bool `json:"enabled"`
|
|
|
+ Value capability.Cap `json:"value,omitempty"`
|
|
|
}
|
|
|
Capabilities []*Capability
|
|
|
)
|
|
@@ -99,27 +88,11 @@ func (c *Capability) String() string {
|
|
|
return c.Key
|
|
|
}
|
|
|
|
|
|
-func (c *Capability) MarshalJSON() ([]byte, error) {
|
|
|
- return json.Marshal(c.Key)
|
|
|
-}
|
|
|
-
|
|
|
-func (c *Capability) UnmarshalJSON(src []byte) error {
|
|
|
- var capName string
|
|
|
- if err := json.Unmarshal(src, &capName); err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- ret := GetCapability(capName)
|
|
|
- if ret == nil {
|
|
|
- return ErrUnkownCapability
|
|
|
- }
|
|
|
- *c = *ret
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
func GetCapability(key string) *Capability {
|
|
|
for _, capp := range capabilityList {
|
|
|
if capp.Key == key {
|
|
|
- return capp
|
|
|
+ cpy := *capp
|
|
|
+ return &cpy
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
@@ -128,10 +101,14 @@ func GetCapability(key string) *Capability {
|
|
|
// Contains returns true if the specified Capability is
|
|
|
// in the slice
|
|
|
func (c Capabilities) Contains(capp string) bool {
|
|
|
+ return c.Get(capp) != nil
|
|
|
+}
|
|
|
+
|
|
|
+func (c Capabilities) Get(capp string) *Capability {
|
|
|
for _, cap := range c {
|
|
|
if cap.Key == capp {
|
|
|
- return true
|
|
|
+ return cap
|
|
|
}
|
|
|
}
|
|
|
- return false
|
|
|
+ return nil
|
|
|
}
|