WIP: set jail properties
This commit is contained in:
parent
5a3d26a52c
commit
239bcd4b95
41
cmd/start.go
41
cmd/start.go
@ -12,6 +12,45 @@ import (
|
||||
// "strconv"
|
||||
)
|
||||
|
||||
func SetJailProperties(args []string) {
|
||||
type properties struct {
|
||||
name string
|
||||
value string
|
||||
}
|
||||
|
||||
var jail Jail
|
||||
var props []properties
|
||||
|
||||
if len(args) > 0 {
|
||||
for i, a := range args {
|
||||
// This is the jail name
|
||||
if i == len(args)-1 {
|
||||
jail.Name = a
|
||||
} else {
|
||||
kv := strings.Split(a, "=")
|
||||
if len(kv) != 2 {
|
||||
// TODO : Show help
|
||||
fmt.Printf("Error parsing args: %s\n", a)
|
||||
return
|
||||
} else {
|
||||
p := properties{name: kv[0], value: kv[1]}
|
||||
props = append(props, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(jail.Name) == 0 || len(args) == 0 {
|
||||
// TODO : Show help
|
||||
fmt.Printf("Error\n")
|
||||
return
|
||||
}
|
||||
|
||||
for _, p := range props {
|
||||
setJailProperty(&jail, p.name, p.value)
|
||||
}
|
||||
}
|
||||
|
||||
// WIP. Not working now (need to address the real struct field, not a copy of it)
|
||||
// setJailProperty takes a string as propValue, whatever the real property type is.
|
||||
// It will be converted.
|
||||
@ -47,7 +86,7 @@ func setJailProperty(jail *Jail, propName string, propValue string) error {
|
||||
// panic: reflect: reflect.Value.Set using unaddressable value
|
||||
//val.Set(reflect.ValueOf(propValue).Elem())
|
||||
// ...Because val settability is false :-(
|
||||
fmt.Printf("settability of val: %v\n", val.CanSet())
|
||||
fmt.Printf("settability of val %s: %v\n", val.Interface(), val.CanSet())
|
||||
|
||||
// This is OK, using the index to get the real jail object
|
||||
//gJails[i].Config.Allow_mlock = 1
|
||||
|
13
cmd/utils.go
13
cmd/utils.go
@ -188,10 +188,11 @@ func getStructFieldNames(parentStruct interface{}, result []string, prefix strin
|
||||
func getStructFieldValue(parentStruct interface{}, fieldName string) (*reflect.Value, string, error) {
|
||||
v := reflect.ValueOf(parentStruct)
|
||||
|
||||
/* if v.Kind() == reflect.Ptr {
|
||||
* v = v.Elem()
|
||||
}
|
||||
*/
|
||||
if v.Kind() == reflect.Ptr {
|
||||
fmt.Printf("We got a pointer, get Elem form it\n")
|
||||
v = v.Elem()
|
||||
}
|
||||
|
||||
if false {
|
||||
for i := 0 ; i < v.NumField(); i++ {
|
||||
f := v.Field(i)
|
||||
@ -203,8 +204,8 @@ func getStructFieldValue(parentStruct interface{}, fieldName string) (*reflect.V
|
||||
|
||||
if strings.Contains(fieldName, ".") {
|
||||
fs := strings.Split(fieldName, ".")
|
||||
//f := v.FieldByName(fs[0])
|
||||
f := v.Elem().FieldByName(fs[0])
|
||||
f := v.FieldByName(fs[0])
|
||||
//f := v.Elem().FieldByName(fs[0])
|
||||
if f.Kind() == reflect.Struct {
|
||||
return getStructFieldValue(f.Interface(), strings.Join(fs[1:], "."))
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user