From 15d5a66c40579bdbd8b40c14e847c712e912e57c Mon Sep 17 00:00:00 2001
From: Pavel Vorobyov
Date: Wed, 25 Sep 2019 16:17:48 +0300
Subject: [PATCH] passmgr in serial mode
---
remote/serial.go | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/remote/serial.go b/remote/serial.go
index e6e68bc..0d4ced6 100644
--- a/remote/serial.go
+++ b/remote/serial.go
@@ -8,6 +8,8 @@ import (
"syscall"
"time"
+ "github.com/viert/xc/passmgr"
+
"github.com/kr/pty"
"github.com/npat-efault/poller"
"github.com/viert/xc/log"
@@ -43,7 +45,7 @@ func forwardUserInput(in *poller.FD, out *os.File, stopped *bool) {
}
}
-func interceptProcessOutput(in []byte, ptmx *os.File) (out []byte, err error) {
+func interceptProcessOutput(in []byte, ptmx *os.File, password string) (out []byte, err error) {
out = []byte{}
err = nil
@@ -58,7 +60,7 @@ func interceptProcessOutput(in []byte, ptmx *os.File) (out []byte, err error) {
}
if !passwordSent && exPasswdPrompt.Match(in) {
- ptmx.Write([]byte(currentPassword + "\n"))
+ ptmx.Write([]byte(password + "\n"))
passwordSent = true
shouldSkipEcho = true
log.Debug("Password sent")
@@ -83,14 +85,16 @@ func interceptProcessOutput(in []byte, ptmx *os.File) (out []byte, err error) {
func runAtHost(host string, cmd *exec.Cmd, r *ExecResult) {
var (
- ptmx *os.File
- si *poller.FD
- buf []byte
- err error
+ ptmx *os.File
+ si *poller.FD
+ buf []byte
+ err error
+ password string
stopped = false
)
+ password = currentPassword
passwordSent = false
shouldSkipEcho = false
@@ -144,11 +148,15 @@ func runAtHost(host string, cmd *exec.Cmd, r *ExecResult) {
buf = make([]byte, bufferSize)
go forwardUserInput(si, ptmx, &stopped)
+ if currentUsePasswordManager {
+ password = passmgr.GetPass(host)
+ }
+
for {
n, err := ptmx.Read(buf)
if n > 0 {
// TODO random stuff with intercepting and omitting data
- data, err := interceptProcessOutput(buf[:n], ptmx)
+ data, err := interceptProcessOutput(buf[:n], ptmx, password)
if err != nil {
// auth error, can't proceed
raise := "su"