#include <isc/result.h>
#include <isc/strerr.h>
#include <isc/string.h>
+#include <isc/util.h>
#include <named/globals.h>
#include <named/main.h>
void
named_os_inituserinfo(const char *username) {
- char strbuf[ISC_STRERRORSIZE];
if (username == NULL) {
return;
}
}
if (getuid() == 0) {
+ char strbuf[ISC_STRERRORSIZE];
if (initgroups(runas_pw->pw_name, runas_pw->pw_gid) < 0) {
strerror_r(errno, strbuf, sizeof(strbuf));
named_main_earlyfatal("initgroups(): %s", strbuf);
free(f);
if (switch_user && runas_pw != NULL) {
+ uid_t olduid = getuid();
gid_t oldgid = getgid();
+#if HAVE_SYS_CAPABILITY_H
+ REQUIRE(olduid == runas_pw->pw_uid);
+ REQUIRE(oldgid == runas_pw->pw_gid);
+#else /* HAVE_SYS_CAPABILITY_H */
/* Set UID/GID to the one we'll be running with eventually */
setperms(runas_pw->pw_uid, runas_pw->pw_gid);
-
+#endif
fd = safe_open(filename, mode, false);
- /* Restore UID/GID to root */
- setperms(0, oldgid);
+#if !HAVE_SYS_CAPABILITY_H
+ /* Restore UID/GID to previous uid/gid */
+ setperms(olduid, oldgid);
+#endif
if (fd == -1) {
fd = safe_open(filename, mode, false);