40 lines
803 B
Go
40 lines
803 B
Go
package cmd
|
|
|
|
import (
|
|
"os"
|
|
"fmt"
|
|
"log"
|
|
"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)
|
|
}
|
|
}
|
|
}
|
|
|
|
fmt.Printf("Jail not found: %s\n", args[0])
|
|
|
|
return nil
|
|
}
|
|
|
|
func shellJail(jail Jail) {
|
|
jid := strconv.Itoa(jail.JID)
|
|
|
|
err := syscall.Exec("/usr/sbin/jexec", []string{"jexec", jid, "/bin/csh"}, os.Environ())
|
|
|
|
// We should never get here, as syscall.Exec replace the gocage binary execution with jexec
|
|
// This means the moment syscall.Exec fires, gocage execution halt.
|
|
if err != nil {
|
|
log.Printf("Exec returned %v\n", err)
|
|
}
|
|
|
|
return
|
|
}
|