rpcclient: Read first line of cookie instead of trimming space

This commit is contained in:
JeremyRand 2019-10-10 22:59:50 +00:00 committed by John C. Vernaleo
parent e6f163e61e
commit 6d521ff8cd

View file

@ -6,18 +6,27 @@
package rpcclient
import (
"bufio"
"fmt"
"io/ioutil"
"os"
"strings"
)
func readCookieFile(path string) (username, password string, err error) {
b, err := ioutil.ReadFile(path)
f, err := os.Open(path)
if err != nil {
return
}
defer f.Close()
scanner := bufio.NewScanner(f)
scanner.Scan()
err = scanner.Err()
if err != nil {
return
}
s := scanner.Text()
s := strings.TrimSpace(string(b))
parts := strings.SplitN(s, ":", 2)
if len(parts) != 2 {
err = fmt.Errorf("malformed cookie file")