1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-20 17:29:36 +01:00

Factor out isRootUser function

This commit is contained in:
John Ericson 2024-03-29 15:40:56 -04:00
parent eeecbb9c36
commit e4d9b207c2
11 changed files with 30 additions and 15 deletions

View file

@ -2,6 +2,7 @@
#include "file-system.hh"
#include "globals.hh"
#include "pathlocks.hh"
#include "users.hh"
#include <pwd.h>
#include <grp.h>
@ -192,10 +193,10 @@ std::unique_ptr<UserLock> acquireUserLock(uid_t nrIds, bool useUserNamespace)
bool useBuildUsers()
{
#if __linux__
static bool b = (settings.buildUsersGroup != "" || settings.autoAllocateUids) && getuid() == 0;
static bool b = (settings.buildUsersGroup != "" || settings.autoAllocateUids) && isRootUser();
return b;
#elif __APPLE__
static bool b = settings.buildUsersGroup != "" && getuid() == 0;
static bool b = settings.buildUsersGroup != "" && isRootUser();
return b;
#else
return false;