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 package rpcclient
import ( import (
"bufio"
"fmt" "fmt"
"io/ioutil" "os"
"strings" "strings"
) )
func readCookieFile(path string) (username, password string, err error) { func readCookieFile(path string) (username, password string, err error) {
b, err := ioutil.ReadFile(path) f, err := os.Open(path)
if err != nil { if err != nil {
return 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) parts := strings.SplitN(s, ":", 2)
if len(parts) != 2 { if len(parts) != 2 {
err = fmt.Errorf("malformed cookie file") err = fmt.Errorf("malformed cookie file")