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

utils: return error from set_home_env() if the user was not found #1633

Conversation

kwilczynski
Copy link
Member

If a given user cannot be found within the container, for example, because the specific UID does not exist, then return an error and let the callers of the set_home_env() function handle the case of the missing user appropriately.

This will fix an issue where when the user cannot be found, the HOME environment variable is not set, which can cause some software not to work correctly.

The two current callers already correctly handled the case when the user was not found per:

  • crun/src/libcrun/container.c

    Lines 1199 to 1207 in bd4f773

    if (getenv ("HOME") == NULL)
    {
    ret = set_home_env (container->container_uid);
    if (UNLIKELY (ret < 0 && errno != ENOTSUP))
    {
    setenv ("HOME", "/", 1);
    libcrun_warning ("cannot detect HOME environment variable, setting default");
    }
    }

  • crun/src/libcrun/container.c

    Lines 3406 to 3414 in bd4f773

    if (getenv ("HOME") == NULL)
    {
    ret = set_home_env (container_uid);
    if (UNLIKELY (ret < 0 && errno != ENOTSUP))
    {
    setenv ("HOME", "/", 1);
    libcrun_warning ("cannot detect HOME environment variable, setting default");
    }
    }

The above will issue a warning and correctly set the HOME environment variable to / as a fall-back on error.

Related:

@kwilczynski kwilczynski force-pushed the fix/handle-mssing-user-when-setting-HOME-environment branch from 2f7ccda to d0b4483 Compare January 7, 2025 08:15
src/libcrun/utils.c Outdated Show resolved Hide resolved
@giuseppe
Copy link
Member

giuseppe commented Jan 7, 2025

CI failure being addressed in: #1634

@kwilczynski
Copy link
Member Author

CI failure being addressed in: #1634

@giuseppe, thank you! Will rebase once this change lands.

If a given user cannot be found within the container, for example,
because the specific UID does not exist, then return an error and
let the callers of the set_home_env() function handle the case of
the missing user appropriately.

Signed-off-by: Krzysztof Wilczyński <kwilczynski@redhat.com>
Signed-off-by: Krzysztof Wilczyński <kwilczynski@redhat.com>
@kwilczynski kwilczynski force-pushed the fix/handle-mssing-user-when-setting-HOME-environment branch from e8c9d44 to 25efd10 Compare January 7, 2025 16:00
@kwilczynski
Copy link
Member Author

Rebased against the current main branch.

Copy link

podman system tests failed. @containers/packit-build please check.

@kwilczynski kwilczynski requested a review from giuseppe January 7, 2025 20:36
@kwilczynski
Copy link
Member Author

/cc @giuseppe
/cc @haircommander
/cc @sohankunkerkar

Copy link
Member

@sohankunkerkar sohankunkerkar left a comment

Choose a reason for hiding this comment

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

/lgtm

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

LGTM

@giuseppe giuseppe merged commit fb1010a into containers:main Jan 8, 2025
47 checks passed
@kwilczynski kwilczynski deleted the fix/handle-mssing-user-when-setting-HOME-environment branch January 8, 2025 08:17
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