* password manager plugin
This commit is contained in:
Pavel Vorobyov
2019-09-24 13:42:09 +03:00
committed by GitHub
parent 9f5347e616
commit d1b9cdc054
8 changed files with 196 additions and 94 deletions

View File

@@ -10,15 +10,16 @@ import (
)
var (
pool *Pool
currentUser string
currentPassword string
currentRaise RaiseType
currentProgressBar bool
currentPrependHostnames bool
currentRemoteTmpdir string
currentDebug bool
outputFile *os.File
pool *Pool
currentUser string
currentPassword string
currentRaise RaiseType
currentUsePasswordManager bool
currentProgressBar bool
currentPrependHostnames bool
currentRemoteTmpdir string
currentDebug bool
outputFile *os.File
noneInterpreter string
suInterpreter string
@@ -83,6 +84,11 @@ func SetPrependHostnames(prependHostnames bool) {
currentPrependHostnames = prependHostnames
}
// SetUsePasswordManager sets using passmgr on/off
func SetUsePasswordManager(usePasswordMgr bool) {
currentUsePasswordManager = usePasswordMgr
}
// SetConnectTimeout sets the ssh connect timeout in sshOptions
func SetConnectTimeout(timeout int) {
sshOptions["ConnectTimeout"] = fmt.Sprintf("%d", timeout)

View File

@@ -10,14 +10,17 @@ import (
"github.com/kr/pty"
"github.com/npat-efault/poller"
"github.com/viert/xc/log"
"github.com/viert/xc/passmgr"
)
func (w *Worker) runcmd(task *Task) int {
var err error
var n int
var passwordSent bool
var (
err error
n int
password string
passwordSent bool
)
passwordSent = currentRaise == RTNone
cmd := createSSHCmd(task.Hostname, task.Cmd)
cmd.Env = append(os.Environ(), environment...)
@@ -38,6 +41,17 @@ func (w *Worker) runcmd(task *Task) int {
shouldSkipEcho := false
msgCount := 0
if currentRaise != RTNone {
passwordSent = false
if currentUsePasswordManager {
password = passmgr.GetPass(task.Hostname)
} else {
password = currentPassword
}
} else {
passwordSent = true
}
execLoop:
for {
if w.forceStopped() {
@@ -68,7 +82,7 @@ execLoop:
// Trying to find Password prompt in first 5 chunks of data from server
if msgCount < 5 {
if !passwordSent && exPasswdPrompt.Match(chunk) {
ptmx.Write([]byte(currentPassword + "\n"))
ptmx.Write([]byte(password + "\n"))
passwordSent = true
shouldSkipEcho = true
continue