return uname

This commit is contained in:
sawka 2022-08-17 12:55:12 -07:00
parent 9542d14473
commit 77bd1fa7bc
2 changed files with 12 additions and 11 deletions

View File

@ -166,7 +166,7 @@ func (m *MServer) runCommand(runPacket *packet.RunPacketType) {
m.Sender.SendErrorResponse(runPacket.ReqId, fmt.Errorf("server run packets require valid ck: %s", err))
return
}
cproc, err := shexec.MakeClientProc(ecmd)
cproc, _, err := shexec.MakeClientProc(ecmd)
if err != nil {
m.Sender.SendErrorResponse(runPacket.ReqId, fmt.Errorf("starting mshell client: %s", err))
return

View File

@ -23,23 +23,24 @@ type ClientProc struct {
Output *packet.PacketParser
}
func MakeClientProc(ecmd *exec.Cmd) (*ClientProc, error) {
// returns (clientproc, uname, error)
func MakeClientProc(ecmd *exec.Cmd) (*ClientProc, string, error) {
inputWriter, err := ecmd.StdinPipe()
if err != nil {
return nil, fmt.Errorf("creating stdin pipe: %v", err)
return nil, "", fmt.Errorf("creating stdin pipe: %v", err)
}
stdoutReader, err := ecmd.StdoutPipe()
if err != nil {
return nil, fmt.Errorf("creating stdout pipe: %v", err)
return nil, "", fmt.Errorf("creating stdout pipe: %v", err)
}
stderrReader, err := ecmd.StderrPipe()
if err != nil {
return nil, fmt.Errorf("creating stderr pipe: %v", err)
return nil, "", fmt.Errorf("creating stderr pipe: %v", err)
}
startTs := time.Now()
err = ecmd.Start()
if err != nil {
return nil, fmt.Errorf("running local client: %w", err)
return nil, "", fmt.Errorf("running local client: %w", err)
}
sender := packet.MakePacketSender(inputWriter)
stdoutPacketParser := packet.MakePacketParser(stdoutReader)
@ -57,25 +58,25 @@ func MakeClientProc(ecmd *exec.Cmd) (*ClientProc, error) {
for pk := range packetParser.MainCh {
if pk.GetType() != packet.InitPacketStr {
cproc.Close()
return nil, fmt.Errorf("invalid packet received from mshell client: %s", packet.AsString(pk))
return nil, "", fmt.Errorf("invalid packet received from mshell client: %s", packet.AsString(pk))
}
initPk := pk.(*packet.InitPacketType)
if initPk.NotFound {
cproc.Close()
return nil, fmt.Errorf("mshell command not found on local server")
return nil, initPk.UName, fmt.Errorf("mshell command not found on local server")
}
if initPk.Version != base.MShellVersion {
cproc.Close()
return nil, fmt.Errorf("invalid remote mshell version 'v%s', must be v%s", initPk.Version, base.MShellVersion)
return nil, initPk.UName, fmt.Errorf("invalid remote mshell version 'v%s', must be v%s", initPk.Version, base.MShellVersion)
}
cproc.InitPk = initPk
break
}
if cproc.InitPk == nil {
cproc.Close()
return nil, fmt.Errorf("no init packet received from mshell client")
return nil, "", fmt.Errorf("no init packet received from mshell client")
}
return cproc, nil
return cproc, cproc.InitPk.UName, nil
}
func (cproc *ClientProc) Close() {