commit ceae9600e3ce7003907c08af82142242ca3e294c (tree)
parent 213ef953462341b44c52adc0696ab3fbc60e82b4
Author: Andrew Kelley <andrew@ziglang.org>
Date: Wed, 7 Jan 2026 14:25:29 -0800
std.posix: remove setuid, seteuid, setgid, setegid, getuid, etc
applications and libraries should reach for the lower level APIs instead
Diffstat:
2 files changed, 4 insertions(+), 79 deletions(-)
diff --git a/lib/std/posix.zig b/lib/std/posix.zig
@@ -551,67 +551,6 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
}
}
-pub const SetEidError = error{
- InvalidUserId,
- PermissionDenied,
-} || UnexpectedError;
-
-pub const SetIdError = error{ResourceLimitReached} || SetEidError;
-
-pub fn setuid(uid: uid_t) SetIdError!void {
- switch (errno(system.setuid(uid))) {
- .SUCCESS => return,
- .AGAIN => return error.ResourceLimitReached,
- .INVAL => return error.InvalidUserId,
- .PERM => return error.PermissionDenied,
- else => |err| return unexpectedErrno(err),
- }
-}
-
-pub fn seteuid(uid: uid_t) SetEidError!void {
- switch (errno(system.seteuid(uid))) {
- .SUCCESS => return,
- .INVAL => return error.InvalidUserId,
- .PERM => return error.PermissionDenied,
- else => |err| return unexpectedErrno(err),
- }
-}
-
-pub fn setgid(gid: gid_t) SetIdError!void {
- switch (errno(system.setgid(gid))) {
- .SUCCESS => return,
- .AGAIN => return error.ResourceLimitReached,
- .INVAL => return error.InvalidUserId,
- .PERM => return error.PermissionDenied,
- else => |err| return unexpectedErrno(err),
- }
-}
-
-pub fn setegid(uid: uid_t) SetEidError!void {
- switch (errno(system.setegid(uid))) {
- .SUCCESS => return,
- .INVAL => return error.InvalidUserId,
- .PERM => return error.PermissionDenied,
- else => |err| return unexpectedErrno(err),
- }
-}
-
-pub fn getuid() uid_t {
- return system.getuid();
-}
-
-pub fn geteuid() uid_t {
- return system.geteuid();
-}
-
-pub fn getgid() gid_t {
- return system.getgid();
-}
-
-pub fn getegid() gid_t {
- return system.getegid();
-}
-
pub const SocketError = error{
/// Permission to create a socket of the specified type and/or
/// pro‐tocol is denied.
@@ -2800,20 +2739,6 @@ pub fn tcsetpgrp(handle: fd_t, pgrp: pid_t) TermioSetPgrpError!void {
}
}
-pub const SetSidError = error{
- /// The calling process is already a process group leader, or the process group ID of a process other than the calling process matches the process ID of the calling process.
- PermissionDenied,
-} || UnexpectedError;
-
-pub fn setsid() SetSidError!pid_t {
- const rc = system.setsid();
- switch (errno(rc)) {
- .SUCCESS => return @intCast(rc),
- .PERM => return error.PermissionDenied,
- else => |err| return unexpectedErrno(err),
- }
-}
-
pub fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) !fd_t {
const rc = system.signalfd(fd, mask, flags);
switch (errno(rc)) {
diff --git a/lib/std/posix/test.zig b/lib/std/posix/test.zig
@@ -35,14 +35,14 @@ test "check WASI CWD" {
test "getuid" {
if (native_os == .windows or native_os == .wasi) return error.SkipZigTest;
- _ = posix.getuid();
- _ = posix.geteuid();
+ _ = posix.system.getuid();
+ _ = posix.system.geteuid();
}
test "getgid" {
if (native_os == .windows or native_os == .wasi) return error.SkipZigTest;
- _ = posix.getgid();
- _ = posix.getegid();
+ _ = posix.system.getgid();
+ _ = posix.system.getegid();
}
test "sigaltstack" {