rpcclient: Read first line of cookie instead of trimming space
This commit is contained in:
parent
e6f163e61e
commit
6d521ff8cd
1 changed files with 12 additions and 3 deletions
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue