host lookup for goutmp (wtmp) tracking

This commit is contained in:
Russ Magee 2018-06-27 19:09:35 -07:00
parent 11fad87345
commit 889203c9de

View file

@ -292,24 +292,29 @@ func main() {
if rec.op[0] == 'c' {
// Non-interactive command
log.Println("[Running command]")
addr := c.RemoteAddr()
hname := goutmp.GetHost(addr.String())
log.Println("[Running command for [%s@%s]]\n", rec.who, hname)
runShellAs(string(rec.who), string(rec.cmd), false, conn, chaffEnabled)
// Returned hopefully via an EOF or exit/logout;
// Clear current op so user can enter next, or EOF
rec.op[0] = 0
log.Println("[Command complete]")
log.Printf("[Command completed for [%s@%s]\n", rec.who, hname)
} else if rec.op[0] == 's' {
log.Println("[Running shell]")
// Interactive session
addr := c.RemoteAddr()
hname := goutmp.GetHost(addr.String())
log.Println("[Running shell for [%s@%s]]\n", rec.who, hname)
utmpx := goutmp.Put_utmp(string(rec.who), addr.String())
utmpx := goutmp.Put_utmp(string(rec.who), hname)
defer func() { goutmp.Unput_utmp(utmpx) }()
goutmp.Put_lastlog_entry("hkexsh", string(rec.who), addr.String())
goutmp.Put_lastlog_entry("hkexsh", string(rec.who), hname)
runShellAs(string(rec.who), string(rec.cmd), true, conn, chaffEnabled)
// Returned hopefully via an EOF or exit/logout;
// Clear current op so user can enter next, or EOF
rec.op[0] = 0
log.Println("[Exiting shell]")
log.Printf("[Exiting shell for [%s@%s]]\n", rec.who, hname)
} else {
log.Println("[Bad cmdSpec]")
}