Fix for ConnDead status

This commit is contained in:
Russ Magee 2023-11-06 21:57:19 -08:00
parent 9244cc9785
commit 908a1bcda2
4 changed files with 18 additions and 12 deletions

View File

@ -1,4 +1,4 @@
VERSION := 0.9.5.5 VERSION := 0.9.5.6-rc
.PHONY: lint vis clean common client server passwd\ .PHONY: lint vis clean common client server passwd\
subpkgs install uninstall reinstall scc subpkgs install uninstall reinstall scc

View File

@ -1151,7 +1151,5 @@ func exitWithStatus(status int) {
log.Fatal("could not write memory profile: ", err) //nolint:gocritic log.Fatal("could not write memory profile: ", err) //nolint:gocritic
} }
} }
fmt.Printf("[exitStatus:%d]\n", status)
os.Exit(status) os.Exit(status)
} }

View File

@ -286,21 +286,28 @@ func runShellAs(who, hname, ttype, cmd string, interactive bool, //nolint:funlen
if interactive { if interactive {
if useSysLogin { if useSysLogin {
// Use the server's login binary (post-auth, which // Use the server's login binary (post-auth)
// is still done via our own bcrypt file)
//
// Note login will drop privs to the intended user for us
// //
// Things UNIX login does, like print the 'motd', // Things UNIX login does, like print the 'motd',
// and use the shell specified by /etc/passwd, will be done // and use the shell specified by /etc/passwd, will be done
// automagically, at the cost of another external tool // automagically, at the cost of another external tool
// dependency. // dependency.
// //
// One drawback of using 'login' is that the remote side
// cannot give us back the shell's exit code, since it
// exits back to 'login', which usually returns its own
// 0 status back to us.
//
// Note login will drop privs to the intended user for us.
//
c = exec.Command(xs.GetTool("login"), "-f", "-p", who) //nolint:gosec c = exec.Command(xs.GetTool("login"), "-f", "-p", who) //nolint:gosec
} else { } else {
// Using our separate login via local passwd file // Run shell directly (which allows nonzero exit codes back to
// the local system upon shell exit, whereas 'login' does not.)
// //
// Note we must drop privs ourselves for the user shell // Note we must drop privs ourselves for the user shell since
// we aren't using 'login' on the remote end which would do it
// for us.
// //
c = exec.Command(xs.GetTool("bash"), "-i", "-l") //nolint:gosec c = exec.Command(xs.GetTool("bash"), "-i", "-l") //nolint:gosec
c.SysProcAttr = &syscall.SysProcAttr{} c.SysProcAttr = &syscall.SysProcAttr{}
@ -412,7 +419,7 @@ func runShellAs(who, hname, ttype, cmd string, interactive bool, //nolint:funlen
} }
conn.SetStatus(xsnet.CSOType(exitStatus)) conn.SetStatus(xsnet.CSOType(exitStatus))
} else { } else {
logger.LogDebug("*** Main proc has exited. ***") //nolint:errcheck logger.LogDebug(fmt.Sprintf("*** Main proc has exited (%d) ***", c.ProcessState.ExitCode())) //nolint:errcheck
// Background jobs still may be running; close the // Background jobs still may be running; close the
// pty anyway, so the client can return before // pty anyway, so the client can return before
// wg.Wait() below completes (Issue #18) // wg.Wait() below completes (Issue #18)

View File

@ -1339,7 +1339,8 @@ func (hc *Conn) Read(b []byte) (n int, err error) {
// Throw away pkt if it's chaff (ie., caller to Read() won't see this data) // Throw away pkt if it's chaff (ie., caller to Read() won't see this data)
log.Printf("[Chaff pkt, discarded (len %d)]\n", decryptN) log.Printf("[Chaff pkt, discarded (len %d)]\n", decryptN)
case CSOKeepAlive: case CSOKeepAlive:
logger.LogDebug(fmt.Sprintf("[got keepAlive pkt, discarded (len %d)]\n", decryptN)) //logger.LogDebug(fmt.Sprintf("[got keepAlive pkt, discarded (len %d)]\n", decryptN))
// payload of keepalive (2 bytes) is not currently used (0x55aa fixed)
_ = binary.BigEndian.Uint16(payloadBytes[0:2]) _ = binary.BigEndian.Uint16(payloadBytes[0:2])
hc.ResetKeepAlive() hc.ResetKeepAlive()
case CSOTermSize: case CSOTermSize:
@ -1625,7 +1626,6 @@ func (hc *Conn) StartupKeepAlive() {
func (hc *Conn) ShutdownKeepAlive() { func (hc *Conn) ShutdownKeepAlive() {
log.Println("Conn SHUTDOWN") log.Println("Conn SHUTDOWN")
hc.SetStatus(CSEConnDead)
hc.Close() hc.Close()
} }
@ -1655,6 +1655,7 @@ func (hc *Conn) keepaliveHelper() {
if hc.keepalive == 0 { if hc.keepalive == 0 {
logger.LogDebug(fmt.Sprintf("*** keepaliveHelper shutting down\n")) logger.LogDebug(fmt.Sprintf("*** keepaliveHelper shutting down\n"))
hc.SetStatus(CSEConnDead)
hc.ShutdownKeepAlive() hc.ShutdownKeepAlive()
break break
} }