vcom/internal/ssh/conn/owner_unix.go
vrubelroman 94002e286f feat(ssh): add conn dialer with bounded handshake, host keys and auth chain (2B.2)
The whole handshake (TCP, kex, auth, SFTP init) runs under a deadline
that ctx cancellation cuts short, and a late client is closed (N-P1-3).
HostKeyAlgorithms come from known_hosts (N-P1-4); unknown and changed
keys go to a Prompter (N-P2-14). Auth tries identity files, then agent
keys over one shared agent connection, then default keys, password and
keyboard-interactive through the Prompter (N-P2-1, N-P2-2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 23:33:26 +03:00

23 lines
520 B
Go

//go:build unix
package conn
import (
"os"
"path/filepath"
"syscall"
)
// foreignOwner reports whether path (or, if it does not exist, its parent
// directory) belongs to a user other than the effective one, e.g. the
// invoking user's ~/.ssh while vcom runs under sudo.
func foreignOwner(path string) bool {
fi, err := os.Stat(path)
if err != nil {
if fi, err = os.Stat(filepath.Dir(path)); err != nil {
return false
}
}
st, ok := fi.Sys().(*syscall.Stat_t)
return ok && int(st.Uid) != os.Geteuid()
}