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

Grab the home directory from /etc/passwd if needed #255

Merged
merged 1 commit into from
Jul 4, 2024

Conversation

mssola
Copy link
Contributor

@mssola mssola commented Jul 1, 2024

Go's os.UserHomeDir has one big gotcha: it only fetches the value from the HOME environment variable and that's it: it does not try to fetch this value from anywhere else if that environment variable is not set.

In some conditions (e.g. a systemd service file) this environment variable might not be set and hence some important paths will not be properly generated. This commit ensures that the home directory is picked: if Go's os.UserHomeDir fails, then we will try to read this value from /etc/passwd.

Fixes bsc#1226128

@mssola
Copy link
Contributor Author

mssola commented Jul 2, 2024

Copy link
Contributor

@ngetahun ngetahun left a comment

Choose a reason for hiding this comment

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

LGTM!

Go's `os.UserHomeDir` has one big gotcha: it only fetches the value from
the HOME environment variable and that's it: it does not try to fetch
this value from anywhere else if that environment variable is not set.

In some conditions (e.g. a systemd service file) this environment file
might not be set and hence some important paths will not be properly
generated. This commit ensures that the home directory is picked: if
Go's `os.UserHomeDir` fails, then we will try to read this value from
`/etc/passwd`.

Fixes bsc#1226128

Signed-off-by: Miquel Sabaté Solà <[email protected]>
@mssola
Copy link
Contributor Author

mssola commented Jul 4, 2024

Feature tests seem temporarily broken (unrelated to this PR). I'll merge this PR and take a closer look at these tests later.

@mssola mssola merged commit 00b642e into main Jul 4, 2024
1 of 2 checks passed
@mssola mssola deleted the curlcredentialsnohome branch July 4, 2024 09:16
@albertvaka
Copy link

Maybe this could be contributed upstream to Go?

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.

3 participants