Skip to content

Commit 7873029

Browse files
kolyshkinbradfitz
authored andcommitted
crypto/x509: fix getting user home dir on darwin
As pointed out in golang/go#26463, HOME (or equivalent) environment variable (rather than the value obtained by parsing /etc/passwd or the like) should be used to obtain user's home directory. Since commit fa1a49aa556d8 there's a method to obtain user's home directory -- use it here. Change-Id: I852fbb24249bcfe08f3874fae6e7b9d01d869190 Reviewed-on: https://go-review.googlesource.com/c/139426 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 21b3d28 commit 7873029

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

x509/root_darwin.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"io/ioutil"
1717
"os"
1818
"os/exec"
19-
"os/user"
2019
"path/filepath"
2120
"strings"
2221
"sync"
@@ -67,17 +66,17 @@ func execSecurityRoots() (*CertPool, error) {
6766
"/Library/Keychains/System.keychain",
6867
}
6968

70-
u, err := user.Current()
71-
if err != nil {
69+
home := os.UserHomeDir()
70+
if home == "" {
7271
if debugExecDarwinRoots {
73-
println(fmt.Sprintf("crypto/x509: get current user: %v", err))
72+
println("crypto/x509: can't get user home directory")
7473
}
7574
} else {
7675
args = append(args,
77-
filepath.Join(u.HomeDir, "/Library/Keychains/login.keychain"),
76+
filepath.Join(home, "/Library/Keychains/login.keychain"),
7877

7978
// Fresh installs of Sierra use a slightly different path for the login keychain
80-
filepath.Join(u.HomeDir, "/Library/Keychains/login.keychain-db"),
79+
filepath.Join(home, "/Library/Keychains/login.keychain-db"),
8180
)
8281
}
8382

0 commit comments

Comments
 (0)