Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding setreuid and bumping npm version to 0.1.1

  • Loading branch information...
commit 0f16ef546f3d5ad1c3ce0d1f6b73929bcbff16f5 1 parent 3dd6dcb
Daniel Bartlett authored
Showing with 25 additions and 2 deletions.
  1. +23 −0 daemon-tools.cc
  2. +2 −2 package.json
23 daemon-tools.cc
View
@@ -12,6 +12,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <ev.h>
+#include <pwd.h>
#define PID_MAXLEN 10
@@ -115,6 +116,27 @@ Handle<Value> Chroot(const Arguments& args) {
return Boolean::New(true);
}
+// Allow changing the real and effective user ID of this process so a root process
+// can become unprivileged
+Handle<Value> SetREUID(const Arguments& args) {
+ if(args.Length() == 0 || !args[0]->IsString())
+ return ThrowException(Exception::Error(
+ String::New("Must give a username to become")
+ ));
+
+ String::AsciiValue username(args[0]);
+
+ struct passwd* pwd_entry = getpwnam(*username);
+
+ if(pwd_entry) {
+ setreuid(pwd_entry->pw_uid, pwd_entry->pw_uid);
+ } else {
+ return ThrowException(Exception::Error(
+ String::New("User not found")
+ ));
+ }
+}
+
extern "C" void init(Handle<Object> target) {
HandleScope scope;
@@ -122,4 +144,5 @@ extern "C" void init(Handle<Object> target) {
target->Set(String::New("lock"), FunctionTemplate::New(LockD)->GetFunction());
target->Set(String::New("closeIO"), FunctionTemplate::New(CloseIO)->GetFunction());
target->Set(String::New("chroot"), FunctionTemplate::New(Chroot)->GetFunction());
+ target->Set(String::New("setreuid"), FunctionTemplate::New(SetREUID)->GetFunction());
}
4 package.json
View
@@ -2,7 +2,7 @@
"name": "daemon-tools",
"description": "Add-on for creating *nix daemons, handling chroots, etc.",
"homepage": "https://github.com/DanBUK/node-daemon-tools",
- "version": "0.1.0",
+ "version": "0.1.1",
"maintainers": [
{
"name": "Daniel Bartlett",
@@ -39,7 +39,7 @@
"engines": {
"node": ">=0.2.5"
},
- "_id": "daemon-tools@0.1.0",
+ "_id": "daemon-tools@0.1.1",
"_nodeSupported": true,
"_npmVersion": "0.2.15",
"_nodeVersion": "v0.2.5",
Please sign in to comment.
Something went wrong with that request. Please try again.