GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: add ability to get/set effective uid/gid by evanlucas · Pull Request #1536 · nodejs/node

src: add ability to get/set effective uid/gid #1536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
evanlucas merged 1 commit into nodejs:master from evanlucas:geteuid-seteuid
Apr 29, 2015

Uh oh!

There was an error while loading. Please reload this page.

Merged

src: add ability to get/set effective uid/gid #1536

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
3c92ca2
src: add ability to get/set effective uid/gid
evanlucas Apr 27, 2015
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
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: #1536
Reviewed-By: Ben Noordhuis <[email protected]>
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@evanlucas
evanlucas committed Apr 29, 2015
commit 3c92ca2b5c1aea283efebd50b27e2a256adf5f7f

There are no files selected for viewing

68 changes: 68 additions & 0 deletions 68 doc/api/process.markdown
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,19 @@ This is the numerical group id, not the group name.
}


## 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,
Expand All @@ -476,6 +489,27 @@ blocks while resolving it to a numerical ID.
}


## 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,
Expand All @@ -489,6 +523,19 @@ This is the numerical userid, not the username.
}


## 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,
Expand All @@ -510,6 +557,27 @@ blocks while resolving it to a numerical ID.
}


## 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,
Expand Down
54 changes: 54 additions & 0 deletions 54 src/node.cc
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.