Skip to content
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.

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

fix(ext/node): implement process.geteuid #21151

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cli/tests/unit_node/process_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,14 @@ Deno.test("process.getuid", () => {
}
});

Deno.test("process.geteuid", () => {
if (Deno.build.os === "windows") {
assertEquals(process.geteuid, undefined);
} else {
assert(typeof process.geteuid?.() === "number");
}
});

Deno.test({
name: "process.exit",
async fn() {
Expand Down
1 change: 1 addition & 0 deletions ext/node/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ deno_core::extension!(deno_node,
ops::os::op_node_os_get_priority<P>,
ops::os::op_node_os_set_priority<P>,
ops::os::op_node_os_username<P>,
ops::os::op_geteuid<P>,
op_node_build_os,
op_is_any_arraybuffer,
op_node_is_promise_rejected,
Expand Down
19 changes: 19 additions & 0 deletions ext/node/ops/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ where
Ok(deno_whoami::username())
}

#[op2(fast)]
pub fn op_geteuid<P>(state: &mut OpState) -> Result<u32, AnyError>
where
P: NodePermissions + 'static,
{
{
let permissions = state.borrow_mut::<P>();
permissions.check_sys("geteuid", "node:os.geteuid()")?;
}

#[cfg(windows)]
let euid = 0;
#[cfg(unix)]
// SAFETY: Call to libc geteuid.
let euid = unsafe { libc::geteuid() };

Ok(euid)
}

#[cfg(unix)]
mod priority {
use super::*;
Expand Down
7 changes: 7 additions & 0 deletions ext/node/polyfills/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

const internals = globalThis.__bootstrap.internals;
const { core } = globalThis.__bootstrap;
const { ops } = core;
import { notImplemented, warnNotImplemented } from "ext:deno_node/_utils.ts";
import { EventEmitter } from "node:events";
import Module from "node:module";
Expand Down Expand Up @@ -652,6 +653,11 @@ class Process extends EventEmitter {
return Deno.uid()!;
}

/** This method is removed on Windows */
geteuid?(): number {
return ops.op_geteuid();
}

// TODO(kt3k): Implement this when we added -e option to node compat mode
_eval: string | undefined = undefined;

Expand Down Expand Up @@ -693,6 +699,7 @@ class Process extends EventEmitter {
if (isWindows) {
delete Process.prototype.getgid;
delete Process.prototype.getuid;
delete Process.prototype.geteuid;
}

/** https://nodejs.org/api/process.html#process_process */
Expand Down