Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os/user: panic: user: unknown userid 501 when call user.LookupId("501") on Mac OS where 501 is the UserID of the admin #36246

Closed
ling2yt opened this issue Dec 22, 2019 · 3 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@ling2yt
Copy link

ling2yt commented Dec 22, 2019

What version of Go are you using (go version)?

$ go version
go version go1.13.4 darwin/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
go version go1.13.4 darwin/amd64
lings-MacBook-Pro:protobuf-3.11.2 ling$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/ling/Library/Caches/go-build"
GOENV="/Users/ling/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/ling/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13.4/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13.4/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/y1/_847f7z555g5vt1p8d85kh1w0000gn/T/go-build611286238=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

#501 is the admin user of mac
and I can get user information with command dscacheutil -q user
uu, err := user.LookupId("501")
if err != nil {
return nil, err
}

What did you expect to see?

current user name

What did you see instead?

panic: user: unknown userid 501

@randall77
Copy link
Contributor

I can't reproduce this. The following program works fine, both for user IDs which are present and ones which are not:

package main

import (
	"fmt"
	"os/user"
)

func main() {
	uu, err := user.LookupId("501")
	if err != nil {
		println("error", err)
		return
	}
	fmt.Printf("%v\n", uu)
}

If you can, please post an entire program, not just a snippet (I'm guessing the user package is os/user in the stdlib, but without a whole program it's hard to be sure).

What Darwin version are you using? I tested on Catalina (10.15.2).

@agnivade agnivade added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Dec 23, 2019
@odeke-em odeke-em changed the title get panic: user: unknown userid 501 when call user.LookupId("501") on Mac OS os/user: panic: user: unknown userid 501 when call user.LookupId("501") on Mac OS Dec 24, 2019
@odeke-em odeke-em changed the title os/user: panic: user: unknown userid 501 when call user.LookupId("501") on Mac OS os/user: panic: user: unknown userid 501 when call user.LookupId("501") on Mac OS where 501 is the UserID of the admin Dec 24, 2019
@ling2yt
Copy link
Author

ling2yt commented Dec 31, 2019

sorry. I found it happens with the cross-complie

  1. used cross-complie on ubuntu 18.04 to generate darwin and linux binary
  2. run the darwin binary on mac

@ianlancetaylor
Copy link
Contributor

There is a difference in how the os/user package works by default for a native compile and a cross-compile. By default for a native compile the os/user package uses the C function getpwuid_r. By default for a cross-compile the os/user package reads the /etc/passwd file. This difference in implementation is presumably what is leading to the different behavior.

You can get the native compile behavior when cross-compiling by setting the environment variable CGO_ENABLED=1. But that will require you to have a complete macOS cross-compiler with macOS libraries.

@golang golang locked and limited conversation to collaborators Dec 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants