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

lib: Only set(re)uid if initial UID != 0 #26

Merged
merged 1 commit into from
Jul 8, 2023
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
10 changes: 5 additions & 5 deletions src/lib/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int aquarium_create_struct(aquarium_opts_t* opts) {
// build filestructure if it doesn't yet exist for convenience
// also create a sanctioned templates file with some default and trusted entries

if (setuid(0) < 0) {
if (opts->initial_uid && setuid(0) < 0) {
warnx("setuid(0): %s", strerror(errno));
return -1;
}
Expand Down Expand Up @@ -86,7 +86,7 @@ int aquarium_create_struct(aquarium_opts_t* opts) {

err:

if (setreuid(opts->initial_uid, 0) < 0) {
if (opts->initial_uid && setreuid(opts->initial_uid, 0) < 0) {
warnx("setreuid(%d): %s", opts->initial_uid, strerror(errno));
rv = -1;
}
Expand Down Expand Up @@ -297,7 +297,7 @@ int aquarium_create(aquarium_opts_t* opts, char const* pointer_path, char const*

// setuid root

if (setuid(0) < 0) {
if (opts->initial_uid && setuid(0) < 0) {
warnx("setuid(0): %s", strerror(errno));
goto setuid_root_err;
}
Expand Down Expand Up @@ -331,7 +331,7 @@ int aquarium_create(aquarium_opts_t* opts, char const* pointer_path, char const*

// finish writing pointer file as user

if (setreuid(opts->initial_uid, 0) < 0) {
if (opts->initial_uid && setreuid(opts->initial_uid, 0) < 0) {
warnx("setreuid(%d, 0): %s", opts->initial_uid, strerror(errno));
goto setuid_user_err;
}
Expand Down Expand Up @@ -374,7 +374,7 @@ int aquarium_create(aquarium_opts_t* opts, char const* pointer_path, char const*
db_open_err:
extract_template_err:

if (setreuid(opts->initial_uid, 0) < 0) {
if (opts->initial_uid && setreuid(opts->initial_uid, 0) < 0) {
warnx("setreuid(%d, 0): %s", opts->initial_uid, strerror(errno));
rv = -1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/enter.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ int aquarium_enter(aquarium_opts_t* opts, char const* path, aquarium_enter_cb_t

// setuid root

if (setuid(0) < 0) {
if (opts->initial_uid && setuid(0) < 0) {
warnx("setuid(0): %s", strerror(errno));
goto setuid_root_err;
}
Expand Down Expand Up @@ -573,7 +573,7 @@ int aquarium_enter(aquarium_opts_t* opts, char const* path, aquarium_enter_cb_t

mount_tmpfs_err:

if (setreuid(opts->initial_uid, 0) < 0) {
if (opts->initial_uid && setreuid(opts->initial_uid, 0) < 0) {
warnx("setreuid(%d, 0): %s", opts->initial_uid, strerror(errno));
rv = -1;
}
Expand Down