diff --git a/cli/tests/unit_node/process_test.ts b/cli/tests/unit_node/process_test.ts index 1f4638b91e44b4..cd0dff0a4d7c25 100644 --- a/cli/tests/unit_node/process_test.ts +++ b/cli/tests/unit_node/process_test.ts @@ -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() { diff --git a/ext/node/lib.rs b/ext/node/lib.rs index bbb3f82f85183a..d38f10f619f138 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -248,6 +248,7 @@ deno_core::extension!(deno_node, ops::os::op_node_os_get_priority

, ops::os::op_node_os_set_priority

, ops::os::op_node_os_username

, + ops::os::op_geteuid

, op_node_build_os, op_is_any_arraybuffer, op_node_is_promise_rejected, diff --git a/ext/node/ops/os.rs b/ext/node/ops/os.rs index 9fb0b44e1049bc..4f6f56f31d3a1e 100644 --- a/ext/node/ops/os.rs +++ b/ext/node/ops/os.rs @@ -52,6 +52,25 @@ where Ok(deno_whoami::username()) } +#[op2(fast)] +pub fn op_geteuid

(state: &mut OpState) -> Result +where + P: NodePermissions + 'static, +{ + { + let permissions = state.borrow_mut::

(); + 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::*; diff --git a/ext/node/polyfills/process.ts b/ext/node/polyfills/process.ts index a4fc3317d2a752..860825b3e8b9f7 100644 --- a/ext/node/polyfills/process.ts +++ b/ext/node/polyfills/process.ts @@ -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"; @@ -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; @@ -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 */