use getJailFromArray so we can handle same name jails on different DS

This commit is contained in:
yo 2022-07-10 14:14:12 +02:00
parent 51dc7d1588
commit d3410c281a

View File

@ -4,27 +4,33 @@ import (
"os"
"fmt"
"log"
"errors"
"strconv"
"strings"
"syscall"
)
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
if len(args) > 0 {
for _, cj := range gJails {
if strings.EqualFold(cj.Name, args[0]) {
shellJail(cj)
}
cj, err := getJailFromArray(args[0], gJails)
if err != nil {
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
}
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)
err := syscall.Exec("/usr/sbin/jexec", []string{"jexec", jid, "/bin/csh"}, os.Environ())
@ -34,6 +40,6 @@ func shellJail(jail Jail) {
if err != nil {
log.Printf("Exec returned %v\n", err)
}
return
return nil
}