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: set HOME to root if the user not found #599

Merged
merged 2 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/libcrun/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,8 @@ set_home_env (uid_t id)
if (stream == NULL)
{
if (errno == ENOENT)
return 0;
goto exit;

return -1;
}

Expand Down Expand Up @@ -1186,6 +1187,10 @@ set_home_env (uid_t id)
return 0;
}
}

exit:
/* If the user was not found, set it to something reasonable. */
setenv ("HOME", "/", 1);
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/podman/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export TMPDIR=/var/tmp

# Skip some tests that are not currently supported in the testing environment:
#
# - search|pull from docker|trust|inspect|logs|generate|import|mounted rw|inherit host devices|privileged CapEff|
# - search|pull from docker|trust|inspect|logs|generate|import|mounted rw|inherit host devices|privileged CapEff|prune unused images|podman images filter|image list filter
# Flaky or not using the runtime.
#
# - selinux
Expand All @@ -34,6 +34,6 @@ export TMPDIR=/var/tmp
# device-cgroup-rule|capabilities|network|overlay volume flag|prune removes a pod with a stopped container: not working on github actions


ginkgo --focus='.*' --skip='.*(selinux|notify_socket|systemd|podman run exit 12*|podman run exit code on failure to exec|failed to start|search|trust|inspect|logs|generate|import|mounted rw|inherit host devices|play kube|cgroups=disabled|privileged CapEff|device-cgroup-rule|capabilities|network|pull from docker|--add-host|removes a pod with a container|prune removes a pod with a stopped container|overlay volume flag).*' \
ginkgo --focus='.*' --skip='.*(selinux|notify_socket|systemd|podman run exit 12*|podman run exit code on failure to exec|failed to start|search|trust|inspect|logs|generate|import|mounted rw|inherit host devices|play kube|cgroups=disabled|privileged CapEff|device-cgroup-rule|capabilities|network|pull from docker|--add-host|removes a pod with a container|prune removes a pod with a stopped container|overlay volume flag|prune unused images|podman images filter|image list filter).*' \
-v -tags "seccomp ostree selinux varlink exclude_graphdriver_devicemapper" \
-timeout=50m -cover -flakeAttempts 3 -progress -trace -noColor test/e2e/.
13 changes: 13 additions & 0 deletions tests/test_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,18 @@ def notify_server():
pass
return 0

def test_empty_home():
conf = base_config()
conf['process']['args'] = ['/sbin/init', 'printenv', 'HOME']
add_all_namespaces(conf)
try:
out, _ = run_and_get_output(conf)
if "/" not in str(out):
return -1
except Exception as e:
return -1
return 0

all_tests = {
"start" : test_start,
"start-override-config" : test_start_override_config,
Expand All @@ -228,6 +240,7 @@ def notify_server():
"test-cwd-relative": test_cwd_relative,
"test-cwd-relative-subdir": test_cwd_relative_subdir,
"test-cwd-absolute": test_cwd_absolute,
"empty-home": test_empty_home,
}

if __name__ == "__main__":
Expand Down