}
+## process.getegid()
+
+Note: this function is only available on POSIX platforms (i.e. not Windows,
+Android)
+
+Gets the effective group identity of the process. (See getegid(2).)
+This is the numerical group id, not the group name.
+
+ if (process.getegid) {
+ console.log('Current gid: ' + process.getegid());
+ }
+
+
## process.setgid(id)
Note: this function is only available on POSIX platforms (i.e. not Windows,
}
+## process.setegid(id)
+
+Note: this function is only available on POSIX platforms (i.e. not Windows,
+Android)
+
+Sets the effective group identity of the process. (See setegid(2).)
+This accepts either a numerical ID or a groupname string. If a groupname
+is specified, this method blocks while resolving it to a numerical ID.
+
+ if (process.getegid && process.setegid) {
+ console.log('Current gid: ' + process.getegid());
+ try {
+ process.setegid(501);
+ console.log('New gid: ' + process.getegid());
+ }
+ catch (err) {
+ console.log('Failed to set gid: ' + err);
+ }
+ }
+
+
## process.getuid()
Note: this function is only available on POSIX platforms (i.e. not Windows,
}
+## process.geteuid()
+
+Note: this function is only available on POSIX platforms (i.e. not Windows,
+Android)
+
+Gets the effective user identity of the process. (See geteuid(2).)
+This is the numerical userid, not the username.
+
+ if (process.geteuid) {
+ console.log('Current uid: ' + process.geteuid());
+ }
+
+
## process.setuid(id)
Note: this function is only available on POSIX platforms (i.e. not Windows,
}
+## process.seteuid(id)
+
+Note: this function is only available on POSIX platforms (i.e. not Windows,
+Android)
+
+Sets the effective user identity of the process. (See seteuid(2).)
+This accepts either a numerical ID or a username string. If a username
+is specified, this method blocks while resolving it to a numerical ID.
+
+ if (process.geteuid && process.seteuid) {
+ console.log('Current uid: ' + process.geteuid());
+ try {
+ process.seteuid(501);
+ console.log('New uid: ' + process.geteuid());
+ }
+ catch (err) {
+ console.log('Failed to set uid: ' + err);
+ }
+ }
+
+
## process.getgroups()
Note: this function is only available on POSIX platforms (i.e. not Windows,
}
+static void GetEUid(const FunctionCallbackInfo<Value>& args) {
+ // uid_t is an uint32_t on all supported platforms.
+ args.GetReturnValue().Set(static_cast<uint32_t>(geteuid()));
+}
+
+
+static void GetEGid(const FunctionCallbackInfo<Value>& args) {
+ // gid_t is an uint32_t on all supported platforms.
+ args.GetReturnValue().Set(static_cast<uint32_t>(getegid()));
+}
+
+
static void SetGid(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
}
+static void SetEGid(const FunctionCallbackInfo<Value>& args) {
+ Environment* env = Environment::GetCurrent(args);
+
+ if (!args[0]->IsUint32() && !args[0]->IsString()) {
+ return env->ThrowTypeError("setegid argument must be a number or string");
+ }
+
+ gid_t gid = gid_by_name(env->isolate(), args[0]);
+
+ if (gid == gid_not_found) {
+ return env->ThrowError("setegid group id does not exist");
+ }
+
+ if (setegid(gid)) {
+ return env->ThrowErrnoException(errno, "setegid");
+ }
+}
+
+
static void SetUid(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
}
+static void SetEUid(const FunctionCallbackInfo<Value>& args) {
+ Environment* env = Environment::GetCurrent(args);
+
+ if (!args[0]->IsUint32() && !args[0]->IsString()) {
+ return env->ThrowTypeError("seteuid argument must be a number or string");
+ }
+
+ uid_t uid = uid_by_name(env->isolate(), args[0]);
+
+ if (uid == uid_not_found) {
+ return env->ThrowError("seteuid user id does not exist");
+ }
+
+ if (seteuid(uid)) {
+ return env->ThrowErrnoException(errno, "seteuid");
+ }
+}
+
+
static void GetGroups(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
#if defined(__POSIX__) && !defined(__ANDROID__)
env->SetMethod(process, "getuid", GetUid);
+ env->SetMethod(process, "geteuid", GetEUid);
env->SetMethod(process, "setuid", SetUid);
+ env->SetMethod(process, "seteuid", SetEUid);
env->SetMethod(process, "setgid", SetGid);
+ env->SetMethod(process, "setegid", SetEGid);
env->SetMethod(process, "getgid", GetGid);
+ env->SetMethod(process, "getegid", GetEGid);
env->SetMethod(process, "getgroups", GetGroups);
env->SetMethod(process, "setgroups", SetGroups);