Browse Source

Merge pull request #445 from trapexit/setreuid

call 32bit versions of set/geteuid on 32bit platforms
pull/449/head 2.23.1
trapexit 7 years ago
committed by GitHub
parent
commit
8ea0b395b2
  1. 42
      src/ugid_linux.hpp

42
src/ugid_linux.hpp

@ -27,6 +27,31 @@
#include <map> #include <map>
#include <vector> #include <vector>
#if defined SYS_setreuid32
#define SETREUID(R,E) (::syscall(SYS_setreuid32,(R),(E)))
#else
#define SETREUID(R,E) (::syscall(SYS_setreuid,(R),(E)))
#endif
#if defined SYS_setregid32
#define SETREGID(R,E) (::syscall(SYS_setregid32,(R),(E)))
#else
#define SETREGID(R,E) (::syscall(SYS_setregid,(R),(E)))
#endif
#if defined SYS_geteuid32
#define GETEUID() (::syscall(SYS_geteuid32))
#else
#define GETEUID() (::syscall(SYS_geteuid))
#endif
#if defined SYS_getegid32
#define GETEGID() (::syscall(SYS_getegid32))
#else
#define GETEGID() (::syscall(SYS_getegid))
#endif
namespace mergerfs namespace mergerfs
{ {
namespace ugid namespace ugid
@ -42,8 +67,8 @@ namespace mergerfs
{ {
if(!initialized) if(!initialized)
{ {
currentuid = ::syscall(SYS_geteuid);
currentgid = ::syscall(SYS_getegid);
currentuid = GETEUID();
currentgid = GETEGID();
initialized = true; initialized = true;
} }
@ -52,18 +77,18 @@ namespace mergerfs
if(currentuid != 0) if(currentuid != 0)
{ {
::syscall(SYS_setreuid,-1,0);
::syscall(SYS_setregid,-1,0);
SETREUID(-1,0);
SETREGID(-1,0);
} }
if(newgid) if(newgid)
{ {
::syscall(SYS_setregid,-1,newgid);
SETREGID(-1,newgid);
initgroups(newuid,newgid); initgroups(newuid,newgid);
} }
if(newuid) if(newuid)
::syscall(SYS_setreuid,-1,newuid);
SETREUID(-1,newuid);
currentuid = newuid; currentuid = newuid;
currentgid = newgid; currentgid = newgid;
@ -89,3 +114,8 @@ namespace mergerfs
}; };
} }
} }
#undef SETREUID
#undef SETREGID
#undef GETEUID
#undef GETEGID
Loading…
Cancel
Save