diff --git a/configure.ac b/configure.ac index 87fe49ec..23921b71 100644 --- a/configure.ac +++ b/configure.ac @@ -604,7 +604,6 @@ AC_CHECK_FUNCS([ \ dup2 \ getcwd \ getpwnam \ - initgroups \ localtime_r \ memchr \ memmove \ @@ -626,6 +625,10 @@ AC_CHECK_FUNCS([ \ AC_CHECK_FUNC([timerfd_create], [have_timerfd_create=yes], [have_timerfd_create=no]) +# For cygwin: we can link initgroups, so AC_CHECK_FUNCS succeeds, but +# cygwin disables initgroups due to feature test macro magic with our +# configuration. +AC_CHECK_DECLS([initgroups], [], [], [[#include ]]) # Checks for epoll availability, primarily for examples/tiny-nghttpd AX_HAVE_EPOLL([have_epoll=yes], [have_epoll=no]) diff --git a/src/shrpx.h b/src/shrpx.h index dfc52701..12e17179 100644 --- a/src/shrpx.h +++ b/src/shrpx.h @@ -44,4 +44,8 @@ #define DIE() _Exit(EXIT_FAILURE) +#if defined(HAVE_DECL_INITGROUPS) && !HAVE_DECL_INITGROUPS +inline int initgroups(const char *user, gid_t group) { return 0; } +#endif // defined(HAVE_DECL_INITGROUPS) && !HAVE_DECL_INITGROUPS + #endif // SHRPX_H diff --git a/src/shrpx_worker_process.cc b/src/shrpx_worker_process.cc index 04ff2698..c2358c58 100644 --- a/src/shrpx_worker_process.cc +++ b/src/shrpx_worker_process.cc @@ -64,14 +64,12 @@ void drop_privileges( #endif // HAVE_NEVERBLEED ) { if (getuid() == 0 && get_config()->uid != 0) { -#ifdef HAVE_INITGROUPS if (initgroups(get_config()->user.get(), get_config()->gid) != 0) { auto error = errno; LOG(FATAL) << "Could not change supplementary groups: " << strerror(error); exit(EXIT_FAILURE); } -#endif // HAVE_INITGROUPS if (setgid(get_config()->gid) != 0) { auto error = errno; LOG(FATAL) << "Could not change gid: " << strerror(error);