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

Fix user query when using libc implementation of os/user #972

Merged
merged 1 commit into from
Oct 19, 2022

Conversation

GaetanLepage
Copy link
Contributor

Fixes #191

In the case where the user is not in /etc/passwd (for e.g. LDAP), the cgo implementation of os/user which uses the libc functions is not able to find the user name and home directory.

This fix implements a fallback that uses the $USER and $HOME environment variables.

Note: This problem does not occur when using the pure go implementation of os/user (for e.g. when specifying CGO_ENABLED=0) which already implements the same kind of fallback.

@@ -66,10 +66,14 @@ func init() {
if err != nil {
log.Printf("user: %s", err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment here, something along the lines:

// When the user is not in /etc/passwd (for e.g. LDAP) and CGO_ENABLED=1 in go env,
// the cgo implementation of user.Current() fails even when HOME and USER are set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done !

@gokcehan
Copy link
Owner

@GaetanLepage Thanks for the patch.

@gokcehan gokcehan merged commit 8e919b8 into gokcehan:master Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic with "unknown userid" and "runtime error: invalid memory address or nil pointer dereference"
3 participants