mirror of
https://github.com/wavetermdev/backup.git
synced 2026-08-05 13:57:07 -07:00
fix ability to log into ssh with key and password (#130)
* fix ability to log into ssh with key and password A previous refactor to the ssh password system broke the ability to use key+password to log in. This change handles key+password as a special case allowing it to be handled separately. * clean up unnecessary print My last change left in a debug print that wasn't necessary in the code. This has been removed.
This commit is contained in:
@@ -932,6 +932,22 @@ func (msh *MShellProc) isWaitingForPassword_nolock() bool {
|
|||||||
return pwIdx != -1
|
return pwIdx != -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (msh *MShellProc) isWaitingForPassphrase_nolock() bool {
|
||||||
|
barr := msh.PtyBuffer.Bytes()
|
||||||
|
if len(barr) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
nlIdx := bytes.LastIndex(barr, []byte{'\n'})
|
||||||
|
var lastLine string
|
||||||
|
if nlIdx == -1 {
|
||||||
|
lastLine = string(barr)
|
||||||
|
} else {
|
||||||
|
lastLine = string(barr[nlIdx+1:])
|
||||||
|
}
|
||||||
|
pwIdx := strings.Index(lastLine, "Enter passphrase for key")
|
||||||
|
return pwIdx != -1
|
||||||
|
}
|
||||||
|
|
||||||
func (msh *MShellProc) RunPtyReadLoop(cmdPty *os.File) {
|
func (msh *MShellProc) RunPtyReadLoop(cmdPty *os.File) {
|
||||||
buf := make([]byte, PtyReadBufSize)
|
buf := make([]byte, PtyReadBufSize)
|
||||||
var isWaiting bool
|
var isWaiting bool
|
||||||
@@ -964,7 +980,11 @@ func (msh *MShellProc) WaitAndSendPassword(pw string) {
|
|||||||
var isWaiting bool
|
var isWaiting bool
|
||||||
var isConnecting bool
|
var isConnecting bool
|
||||||
msh.WithLock(func() {
|
msh.WithLock(func() {
|
||||||
isWaiting = msh.isWaitingForPassword_nolock()
|
if msh.Remote.SSHOpts.GetAuthType() == sstore.RemoteAuthTypeKeyPassword {
|
||||||
|
isWaiting = msh.isWaitingForPassphrase_nolock()
|
||||||
|
} else {
|
||||||
|
isWaiting = msh.isWaitingForPassword_nolock()
|
||||||
|
}
|
||||||
isConnecting = msh.Status == StatusConnecting
|
isConnecting = msh.Status == StatusConnecting
|
||||||
})
|
})
|
||||||
if !isConnecting {
|
if !isConnecting {
|
||||||
|
|||||||
Reference in New Issue
Block a user