Add process.setuid(), getuid()

This commit is contained in:
Michael Carter 2010-02-07 22:13:10 -08:00 committed by Ryan Dahl
parent 6f92d8f3b0
commit a38607605c
2 changed files with 33 additions and 0 deletions

View File

@ -136,6 +136,9 @@ success code 0.
+process.cwd()+::
Returns the current working directory of the process.
+process.getuid(), process.setuid(id)+::
Gets/sets the user identity of the process. (See setuid(2).)
+process.chdir(directory)+::
Changes the current working directory of the process.

View File

@ -9,6 +9,8 @@
#include <unistd.h>
#include <errno.h>
#include <dlfcn.h> /* dlopen(), dlsym() */
#include <sys/types.h>
#include <unistd.h> /* setuid, getuid */
#include <node_events.h>
#include <node_dns.h>
@ -464,6 +466,32 @@ static Handle<Value> Umask(const Arguments& args){
return scope.Close(Uint32::New(old));
}
static Handle<Value> GetUid(const Arguments& args) {
HandleScope scope;
int uid = getuid();
return scope.Close(Integer::New(uid));
}
static Handle<Value> SetUid(const Arguments& args) {
HandleScope scope;
if (args.Length() < 1) {
return ThrowException(Exception::Error(
String::New("setuid requires 1 argument")));
}
Local<Integer> given_uid = args[0]->ToInteger();
int uid = given_uid->Int32Value();
int result;
if ((result = setuid(uid)) != 0) {
return ThrowException(Exception::Error(String::New(strerror(errno))));
}
return Undefined();
}
v8::Handle<v8::Value> Exit(const v8::Arguments& args) {
HandleScope scope;
fflush(stderr);
@ -953,6 +981,8 @@ static void Load(int argc, char *argv[]) {
NODE_SET_METHOD(process, "reallyExit", Exit);
NODE_SET_METHOD(process, "chdir", Chdir);
NODE_SET_METHOD(process, "cwd", Cwd);
NODE_SET_METHOD(process, "getuid", GetUid);
NODE_SET_METHOD(process, "setuid", SetUid);
NODE_SET_METHOD(process, "umask", Umask);
NODE_SET_METHOD(process, "dlopen", DLOpen);
NODE_SET_METHOD(process, "kill", Kill);