@@ -1750,6 +1750,18 @@ static void GetGid(const FunctionCallbackInfo<Value>& args) {
17501750}
17511751
17521752
1753+ static void GetEUid (const FunctionCallbackInfo<Value>& args) {
1754+ // uid_t is an uint32_t on all supported platforms.
1755+ args.GetReturnValue ().Set (static_cast <uint32_t >(geteuid ()));
1756+ }
1757+
1758+
1759+ static void GetEGid (const FunctionCallbackInfo<Value>& args) {
1760+ // gid_t is an uint32_t on all supported platforms.
1761+ args.GetReturnValue ().Set (static_cast <uint32_t >(getegid ()));
1762+ }
1763+
1764+
17531765static void SetGid (const FunctionCallbackInfo<Value>& args) {
17541766 Environment* env = Environment::GetCurrent (args);
17551767
@@ -1769,6 +1781,25 @@ static void SetGid(const FunctionCallbackInfo<Value>& args) {
17691781}
17701782
17711783
1784+ static void SetEGid (const FunctionCallbackInfo<Value>& args) {
1785+ Environment* env = Environment::GetCurrent (args);
1786+
1787+ if (!args[0 ]->IsUint32 () && !args[0 ]->IsString ()) {
1788+ return env->ThrowTypeError (" setegid argument must be a number or string" );
1789+ }
1790+
1791+ gid_t gid = gid_by_name (env->isolate (), args[0 ]);
1792+
1793+ if (gid == gid_not_found) {
1794+ return env->ThrowError (" setegid group id does not exist" );
1795+ }
1796+
1797+ if (setegid (gid)) {
1798+ return env->ThrowErrnoException (errno, " setegid" );
1799+ }
1800+ }
1801+
1802+
17721803static void SetUid (const FunctionCallbackInfo<Value>& args) {
17731804 Environment* env = Environment::GetCurrent (args);
17741805
@@ -1788,6 +1819,25 @@ static void SetUid(const FunctionCallbackInfo<Value>& args) {
17881819}
17891820
17901821
1822+ static void SetEUid (const FunctionCallbackInfo<Value>& args) {
1823+ Environment* env = Environment::GetCurrent (args);
1824+
1825+ if (!args[0 ]->IsUint32 () && !args[0 ]->IsString ()) {
1826+ return env->ThrowTypeError (" seteuid argument must be a number or string" );
1827+ }
1828+
1829+ uid_t uid = uid_by_name (env->isolate (), args[0 ]);
1830+
1831+ if (uid == uid_not_found) {
1832+ return env->ThrowError (" seteuid user id does not exist" );
1833+ }
1834+
1835+ if (seteuid (uid)) {
1836+ return env->ThrowErrnoException (errno, " seteuid" );
1837+ }
1838+ }
1839+
1840+
17911841static void GetGroups (const FunctionCallbackInfo<Value>& args) {
17921842 Environment* env = Environment::GetCurrent (args);
17931843
@@ -2821,10 +2871,14 @@ void SetupProcessObject(Environment* env,
28212871
28222872#if defined(__POSIX__) && !defined(__ANDROID__)
28232873 env->SetMethod (process, " getuid" , GetUid);
2874+ env->SetMethod (process, " geteuid" , GetEUid);
28242875 env->SetMethod (process, " setuid" , SetUid);
2876+ env->SetMethod (process, " seteuid" , SetEUid);
28252877
28262878 env->SetMethod (process, " setgid" , SetGid);
2879+ env->SetMethod (process, " setegid" , SetEGid);
28272880 env->SetMethod (process, " getgid" , GetGid);
2881+ env->SetMethod (process, " getegid" , GetEGid);
28282882
28292883 env->SetMethod (process, " getgroups" , GetGroups);
28302884 env->SetMethod (process, " setgroups" , SetGroups);
0 commit comments