summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/unit_node/process_test.ts8
-rw-r--r--ext/node/lib.rs1
-rw-r--r--ext/node/ops/os.rs19
-rw-r--r--ext/node/polyfills/process.ts7
4 files changed, 35 insertions, 0 deletions
diff --git a/cli/tests/unit_node/process_test.ts b/cli/tests/unit_node/process_test.ts
index 1f4638b91..cd0dff0a4 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 bbb3f82f8..d38f10f61 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<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,
diff --git a/ext/node/ops/os.rs b/ext/node/ops/os.rs
index 9fb0b44e1..4f6f56f31 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<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::*;
diff --git a/ext/node/polyfills/process.ts b/ext/node/polyfills/process.ts
index a4fc3317d..860825b3e 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 */