Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions client/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package cli
import (
"context"
"os"
"bufio"
"fmt"
"strconv"
"strings"

"github.com/spolu/warp/lib/errors"
)
Expand All @@ -19,10 +23,26 @@ type Shell struct {
func retrieveShell(
ctx context.Context,
) (string, error) {
if os.Getenv("SHELL") != "" {
return os.Getenv("SHELL"), nil
}
return "/bin/bash", nil
if os.Getenv("SHELL") != "" {
return os.Getenv("SHELL"), nil
}
file, err := os.Open("/etc/passwd")
if err != nil {
return nil, errors.Trace(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)

for scanner.Scan() {
s := strings.Split(scanner.Text(), ":")
if (len(s) > 3) {
value, _ := strconv.Atoi(s[2])
if (value >= 1000) && !(strings.Contains(s[6], "nologin")) {
return s[len(s)-1]
}
}
}
return "/bin/bash", nil
}

func DetectShell(
Expand Down