package cmd import ( "os" "fmt" "log" "errors" "strconv" "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 { cj, err := getJailFromArray(args[0], []string{"jail"}, 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 } } return nil } 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, "login", "-f", "root"}, 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 nil }