Skip to content

Commit 7af7da3

Browse files
committed
fix: Sudo lecture parsing problem
1 parent 46e9359 commit 7af7da3

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

internal/bridge/session.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,9 @@ func (s *Session) CloseAllConnections() {
5050
func (val *Session) checkOutput(in io.Writer, output *bytes.Buffer) bool {
5151
val.Mutex.Lock()
5252
defer val.Mutex.Unlock()
53-
if output != nil && output.Len() > 0 {
54-
if output.String() == "liman-pass-sudo" {
55-
_, _ = in.Write([]byte(val.password + "\n"))
56-
return true
57-
} else {
58-
return true
59-
}
53+
if output != nil && output.Len() > 0 && strings.Contains(output.String(), "liman-pass-sudo") {
54+
in.Write([]byte(val.password + "\n"))
55+
return true
6056
}
6157
return false
6258
}
@@ -90,19 +86,25 @@ func (val *Session) Run(command string) (string, error) {
9086
For:
9187
for {
9288
select {
89+
case <-time.After(20 * time.Second):
9390
case <-endChan:
9491
break For
9592
default:
9693
if val.checkOutput(in, output) {
9794
break For
9895
}
96+
9997
time.Sleep(500)
10098
}
10199
}
102100
}(in, stdoutB, endChan)
103101
}
104102
sess.Run("(" + command + ") 2> /dev/null")
105-
return stripansi.Strip(strings.TrimSpace(strings.Replace(stdoutB.String(), "liman-pass-sudo", "", 1))), nil
103+
104+
tmp := strings.Split(stdoutB.String(), "liman-pass-sudo")
105+
output := tmp[len(tmp)-1]
106+
107+
return stripansi.Strip(strings.TrimSpace(output)), nil
106108
} else if val.WinRM != nil {
107109
command = "$ProgressPreference = 'SilentlyContinue';" + command
108110
encoder := unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM).NewEncoder()

0 commit comments

Comments
 (0)