1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix: Add sys permission kinds for node compat (#24242)

Fixes #24241

* Support "statfs", "username", "getPriority" and "setPriority" kinds
for `--allow-sys`.
* Check individual permissions in `node:os.userInfo()` instead of a
single "userInfo" permission.
* Check for "uid" permission in `node:process.geteuid()` instead of
"geteuid".
* Add missing "homedir" to `SysPermissionDescriptor.kind` union

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
Adam Gregory 2024-07-10 14:15:43 +01:00 committed by GitHub
parent 9a0d59d95d
commit 82f9216610
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 6 deletions

View file

@ -4969,7 +4969,12 @@ declare namespace Deno {
| "osUptime"
| "uid"
| "gid"
| "cpus";
| "username"
| "cpus"
| "homedir"
| "statfs"
| "getPriority"
| "setPriority";
}
/** The permission descriptor for the `allow-ffi` and `deny-ffi` permissions, which controls

View file

@ -50,7 +50,7 @@ where
{
{
let permissions = state.borrow_mut::<P>();
permissions.check_sys("userInfo", "node:os.userInfo()")?;
permissions.check_sys("username", "node:os.userInfo()")?;
}
Ok(deno_whoami::username())
@ -63,7 +63,7 @@ where
{
{
let permissions = state.borrow_mut::<P>();
permissions.check_sys("geteuid", "node:os.geteuid()")?;
permissions.check_sys("uid", "node:os.geteuid()")?;
}
#[cfg(windows)]

View file

@ -997,9 +997,8 @@ impl Descriptor for SysDescriptor {
pub fn parse_sys_kind(kind: &str) -> Result<&str, AnyError> {
match kind {
"hostname" | "osRelease" | "osUptime" | "loadavg" | "networkInterfaces"
| "systemMemoryInfo" | "uid" | "gid" | "cpus" | "homedir" | "getegid" => {
Ok(kind)
}
| "systemMemoryInfo" | "uid" | "gid" | "cpus" | "homedir" | "getegid"
| "username" | "statfs" | "getPriority" | "setPriority" => Ok(kind),
_ => Err(type_error(format!("unknown system info kind \"{kind}\""))),
}
}