mirror of
https://github.com/coder/coder.git
synced 2026-06-03 13:08:25 +00:00
d0e2060692
Fixes: https://github.com/coder/internal/issues/377 Added an additional SSH listener on port 22, so the agent now listens on both, port one and port 22. --- Change-Id: Ifd986b260f8ac317e37d65111cd4e0bd1dc38af8 Signed-off-by: Thomas Kosiewski <tk@coder.com>
31 lines
893 B
Go
31 lines
893 B
Go
package usershell
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"golang.org/x/xerrors"
|
|
)
|
|
|
|
// Get returns the $SHELL environment variable.
|
|
// Deprecated: use SystemEnvInfo.UserShell instead.
|
|
func Get(username string) (string, error) {
|
|
// This command will output "UserShell: /bin/zsh" if successful, we
|
|
// can ignore the error since we have fallback behavior.
|
|
if !filepath.IsLocal(username) {
|
|
return "", xerrors.Errorf("username is nonlocal path: %s", username)
|
|
}
|
|
//nolint: gosec // input checked above
|
|
out, _ := exec.Command("dscl", ".", "-read", filepath.Join("/Users", username), "UserShell").Output() //nolint:gocritic
|
|
s, ok := strings.CutPrefix(string(out), "UserShell: ")
|
|
if ok {
|
|
return strings.TrimSpace(s), nil
|
|
}
|
|
if s = os.Getenv("SHELL"); s != "" {
|
|
return s, nil
|
|
}
|
|
return "", xerrors.Errorf("shell for user %q not found via dscl or in $SHELL", username)
|
|
}
|