include the breakglass mountpoint in $PATH
That way, users don’t need to use the ./ prefix all the time.
This commit is contained in:
parent
a8f85f5027
commit
b99b39b334
@ -100,6 +100,10 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := os.Setenv("PATH", unpackDir+":"+os.Getenv("PATH")); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
accept := func(listener net.Listener) {
|
||||
for {
|
||||
conn, err := listener.Accept()
|
||||
|
29
ssh.go
29
ssh.go
@ -7,6 +7,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
@ -47,6 +48,32 @@ func handleChannel(newChannel ssh.NewChannel) {
|
||||
}(channel, requests)
|
||||
}
|
||||
|
||||
func expandPath(env []string) []string {
|
||||
pwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return env
|
||||
}
|
||||
found := false
|
||||
for idx, val := range env {
|
||||
parts := strings.Split(val, "=")
|
||||
if len(parts) < 2 {
|
||||
continue // malformed entry
|
||||
}
|
||||
key := parts[0]
|
||||
if key != "PATH" {
|
||||
continue
|
||||
}
|
||||
val := strings.Join(parts[1:], "=")
|
||||
env[idx] = fmt.Sprintf("%s=%s:%s", key, pwd, val)
|
||||
found = true
|
||||
}
|
||||
if !found {
|
||||
const busyboxDefaultPATH = "/sbin:/usr/sbin:/bin:/usr/bin"
|
||||
env = append(env, fmt.Sprintf("PATH=%s:%s", pwd, busyboxDefaultPATH))
|
||||
}
|
||||
return env
|
||||
}
|
||||
|
||||
type session struct {
|
||||
env []string
|
||||
ptyf *os.File
|
||||
@ -124,7 +151,7 @@ func (s *session) request(req *ssh.Request) error {
|
||||
}
|
||||
|
||||
cmd := exec.Command(cmdline[0], cmdline[1:]...)
|
||||
cmd.Env = s.env
|
||||
cmd.Env = expandPath(s.env)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||
|
||||
if s.ttyf == nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user