mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 00:06:38 +00:00
[client] Use setsid to avoid the parent process from being killed via HUP by login (#4900)
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
@@ -75,6 +76,29 @@ func (s *Server) detectSuPtySupport(ctx context.Context) bool {
|
||||
return supported
|
||||
}
|
||||
|
||||
// detectUtilLinuxLogin checks if login is from util-linux (vs shadow-utils).
|
||||
// util-linux login uses vhangup() which requires setsid wrapper to avoid killing parent.
|
||||
// See https://bugs.debian.org/1078023 for details.
|
||||
func (s *Server) detectUtilLinuxLogin(ctx context.Context) bool {
|
||||
if runtime.GOOS != "linux" {
|
||||
return false
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, 500*time.Millisecond)
|
||||
defer cancel()
|
||||
|
||||
cmd := exec.CommandContext(ctx, "login", "--version")
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Debugf("login --version failed (likely shadow-utils): %v", err)
|
||||
return false
|
||||
}
|
||||
|
||||
isUtilLinux := strings.Contains(string(output), "util-linux")
|
||||
log.Debugf("util-linux login detected: %v", isUtilLinux)
|
||||
return isUtilLinux
|
||||
}
|
||||
|
||||
// createSuCommand creates a command using su -l -c for privilege switching
|
||||
func (s *Server) createSuCommand(session ssh.Session, localUser *user.User, hasPty bool) (*exec.Cmd, error) {
|
||||
suPath, err := exec.LookPath("su")
|
||||
@@ -144,7 +168,7 @@ func (s *Server) handlePty(logger *log.Entry, session ssh.Session, privilegeResu
|
||||
return false
|
||||
}
|
||||
|
||||
logger.Infof("starting interactive shell: %s", execCmd.Path)
|
||||
logger.Infof("starting interactive shell: %s", strings.Join(execCmd.Args, " "))
|
||||
return s.runPtyCommand(logger, session, execCmd, ptyReq, winCh)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user