h2olog: always call setuid() and setgid() on privdrop
@@ -129,7 +129,6 @@ static void show_process(pid_t pid)
static void drop_root_privilege(void)
{
if (getuid() == 0) {
- if (getgid() == 0) {
const char *sudo_gid = getenv("SUDO_GID");
if (sudo_gid == NULL) {
fprintf(stderr, "Error: failed to read the SUDO_GID env variable\n");
@@ -141,11 +140,10 @@ static void drop_root_privilege(void)
fprintf(stderr, "Error: failed to parse SUDO_GID\n");
exit(EXIT_FAILURE);
}
- if (gid != 0 && setgid(gid) != 0) {
+ if (setgid(gid) != 0) {
fprintf(stderr, "Error: failed to drop the root group\n");
exit(EXIT_FAILURE);
}
- }
const char *sudo_uid = getenv("SUDO_UID");
if (sudo_uid == NULL) {
fprintf(stderr, "Error: failed to read the SUDO_UID env variable\n");
@@ -157,7 +155,7 @@ static void drop_root_privilege(void)
fprintf(stderr, "Error: failed to parse SUDO_UID\n");
exit(EXIT_FAILURE);
}
- if (uid != 0 && setuid(uid) != 0) {
+ if (setuid(uid) != 0) {
fprintf(stderr, "Error: failed to drop the root user\n");
exit(EXIT_FAILURE);
}
