2018-09-07 22:35:33 +00:00
|
|
|
// Session info/routines for the HKExSh
|
|
|
|
//
|
|
|
|
// Copyright (c) 2017-2018 Russell Magee
|
|
|
|
// Licensed under the terms of the MIT license (see LICENSE.mit in this
|
|
|
|
// distribution)
|
|
|
|
//
|
|
|
|
// golang implementation by Russ Magee (rmagee_at_gmail.com)
|
|
|
|
|
|
|
|
package hkexsh
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Session struct {
|
|
|
|
op []byte
|
|
|
|
who []byte
|
2018-09-14 08:13:14 +00:00
|
|
|
connhost []byte
|
2018-09-08 03:37:47 +00:00
|
|
|
termtype []byte // client initial $TERM
|
2018-09-07 22:35:33 +00:00
|
|
|
cmd []byte
|
|
|
|
authCookie []byte
|
|
|
|
status uint32 // exit status (0-255 is std UNIX status)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Output Session record as a string. Implements Stringer interface.
|
|
|
|
func (h *Session) String() string {
|
|
|
|
return fmt.Sprintf("hkexsh.Session:\nOp:%v\nWho:%v\nCmd:%v\nAuthCookie:%v\nStatus:%v",
|
|
|
|
h.op, h.who, h.cmd, h.AuthCookie(false), h.status)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h Session) Op() []byte {
|
|
|
|
return h.op
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Session) SetOp(o []byte) {
|
|
|
|
h.op = o
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h Session) Who() []byte {
|
|
|
|
return h.who
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Session) SetWho(w []byte) {
|
|
|
|
h.who = w
|
|
|
|
}
|
|
|
|
|
2018-09-14 08:13:14 +00:00
|
|
|
func (h Session) ConnHost() []byte {
|
|
|
|
return h.connhost
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Session) SetConnHost(n []byte) {
|
|
|
|
h.connhost = n
|
|
|
|
}
|
|
|
|
|
2018-09-08 03:37:47 +00:00
|
|
|
func (h Session) TermType() []byte {
|
|
|
|
return h.termtype
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Session) SetTermType(t []byte) {
|
|
|
|
h.termtype = t
|
|
|
|
}
|
|
|
|
|
2018-09-07 22:35:33 +00:00
|
|
|
func (h Session) Cmd() []byte {
|
|
|
|
return h.cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Session) SetCmd(c []byte) {
|
|
|
|
h.cmd = c
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h Session) AuthCookie(reallyShow bool) []byte {
|
|
|
|
if reallyShow {
|
|
|
|
return h.authCookie
|
|
|
|
} else {
|
|
|
|
return []byte("**REDACTED**")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Session) SetAuthCookie(a []byte) {
|
|
|
|
h.authCookie = a
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Session) ClearAuthCookie() {
|
|
|
|
for i := range h.authCookie {
|
|
|
|
h.authCookie[i] = 0
|
|
|
|
}
|
|
|
|
runtime.GC()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h Session) Status() uint32 {
|
|
|
|
return h.status
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Session) SetStatus(s uint32) {
|
|
|
|
h.status = s
|
|
|
|
}
|
|
|
|
|
2018-09-14 08:13:14 +00:00
|
|
|
func NewSession(op, who, connhost, ttype, cmd, authcookie []byte, status uint32) *Session {
|
2018-09-07 22:35:33 +00:00
|
|
|
return &Session{
|
|
|
|
op: op,
|
|
|
|
who: who,
|
2018-09-14 08:13:14 +00:00
|
|
|
connhost: connhost,
|
2018-09-08 03:37:47 +00:00
|
|
|
termtype: ttype,
|
2018-09-07 22:35:33 +00:00
|
|
|
cmd: cmd,
|
|
|
|
authCookie: authcookie,
|
|
|
|
status: status}
|
|
|
|
}
|