use getJailFromArray so we can handle same name jails on different DS
This commit is contained in:
parent
51dc7d1588
commit
d3410c281a
@ -4,27 +4,33 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"errors"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ShellJail(args []string) error {
|
func ShellJail(args []string) error {
|
||||||
// We cant shell more than one jail bc we replace gocage execution with jexec, so there wont be no return to gocage
|
// We cant shell more than one jail bc we replace gocage execution with jexec, so there wont be no return to gocage
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
for _, cj := range gJails {
|
cj, err := getJailFromArray(args[0], gJails)
|
||||||
if strings.EqualFold(cj.Name, args[0]) {
|
if err != nil {
|
||||||
shellJail(cj)
|
fmt.Printf("Error getting jail %s: %v\n", args[0], err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := shellJail(cj); err != nil {
|
||||||
|
fmt.Printf("%v\n", err)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Jail not found: %s\n", args[0])
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func shellJail(jail Jail) {
|
func shellJail(jail *Jail) error {
|
||||||
|
if false == jail.Running {
|
||||||
|
return errors.New("Jail is not running")
|
||||||
|
}
|
||||||
|
|
||||||
jid := strconv.Itoa(jail.JID)
|
jid := strconv.Itoa(jail.JID)
|
||||||
|
|
||||||
err := syscall.Exec("/usr/sbin/jexec", []string{"jexec", jid, "/bin/csh"}, os.Environ())
|
err := syscall.Exec("/usr/sbin/jexec", []string{"jexec", jid, "/bin/csh"}, os.Environ())
|
||||||
@ -35,5 +41,5 @@ func shellJail(jail Jail) {
|
|||||||
log.Printf("Exec returned %v\n", err)
|
log.Printf("Exec returned %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user