Skip to content

Commit

Permalink
Drop supplementary groups (if any) as well
Browse files Browse the repository at this point in the history
Fixes #133
  • Loading branch information
roehling committed Jan 6, 2023
1 parent e3c4e9c commit 9c14cb1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
check_include_file(alloca.h HAVE_ALLOCA_H)
check_include_file(errno.h HAVE_ERRNO_H)
check_include_file(fcntl.h HAVE_FCNTL_H)
check_include_file(grp.h HAVE_GRP_H)
check_include_file(netdb.h HAVE_NETDB_H)
check_include_file(poll.h HAVE_POLL_H)
check_include_file(pwd.h HAVE_PWD_H)
Expand Down
10 changes: 10 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_GRP_H
# include <grp.h>
#endif

static volatile sig_atomic_t timeout = 0;

Expand Down Expand Up @@ -100,6 +103,13 @@ static bool drop_privileges(cfg_t* cfg)
}
if (target_uid != 0 || target_gid != 0)
{
#ifdef HAVE_GRP_H
if (setgroups(0, NULL) < 0)
{
log_perror(errno, "cannot drop privileges: setgroups");
return false;
}
#endif
if (setgid(target_gid) < 0)
{
log_perror(errno, "cannot drop privileges: setgid");
Expand Down
1 change: 1 addition & 0 deletions src/postsrsd_build_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#cmakedefine HAVE_ALLOCA_H 1
#cmakedefine HAVE_ERRNO_H 1
#cmakedefine HAVE_FCNTL_H 1
#cmakedefine HAVE_GRP_H 1
#cmakedefine HAVE_NETDB_H 1
#cmakedefine HAVE_POLL_H 1
#cmakedefine HAVE_PWD_H 1
Expand Down

0 comments on commit 9c14cb1

Please sign in to comment.