diff options
author | Evan Lucas <evanlucas@me.com> | 2015-04-27 11:24:19 -0500 |
---|---|---|
committer | Evan Lucas <evanlucas@me.com> | 2015-04-29 16:04:26 -0500 |
commit | 3c92ca2b5c1aea283efebd50b27e2a256adf5f7f (patch) | |
tree | ea798272856f7d1ec1e93f36f40be0eb443a4cd8 /src | |
parent | f9b226c1c1e5bfbf355f9fabe03e50333676cc05 (diff) | |
download | android-node-v8-3c92ca2b5c1aea283efebd50b27e2a256adf5f7f.tar.gz android-node-v8-3c92ca2b5c1aea283efebd50b27e2a256adf5f7f.tar.bz2 android-node-v8-3c92ca2b5c1aea283efebd50b27e2a256adf5f7f.zip |
src: add ability to get/set effective uid/gid
Adds the following to process:
- `process.geteuid()`
- `process.seteuid(id)`
- `process.getegid()`
- `process.setegid(id)`
PR-URL: https://github.com/iojs/io.js/pull/1536
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src')
-rw-r--r-- | src/node.cc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/node.cc b/src/node.cc index 67cf140154..4cafe96f44 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1750,6 +1750,18 @@ static void GetGid(const FunctionCallbackInfo<Value>& args) { } +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); @@ -1769,6 +1781,25 @@ static void SetGid(const FunctionCallbackInfo<Value>& 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); @@ -1788,6 +1819,25 @@ static void SetUid(const FunctionCallbackInfo<Value>& 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); @@ -2821,10 +2871,14 @@ void SetupProcessObject(Environment* env, #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); |