authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-07 14:25:29-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-07 17:33:06-08:00
logceae9600e3ce7003907c08af82142242ca3e294c
tree4bf18465fff744ddfbfe3978b43166c72cd551b3
parent213ef953462341b44c52adc0696ab3fbc60e82b4

std.posix: remove setuid, seteuid, setgid, setegid, getuid, etc

applications and libraries should reach for the lower level APIs instead

2 files changed, 4 insertions(+), 79 deletions(-)

lib/std/posix.zig-75
......@@ -551,67 +551,6 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
551551 }
552552}
553553
554pub const SetEidError = error{
555 InvalidUserId,
556 PermissionDenied,
557} || UnexpectedError;
558
559pub const SetIdError = error{ResourceLimitReached} || SetEidError;
560
561pub fn setuid(uid: uid_t) SetIdError!void {
562 switch (errno(system.setuid(uid))) {
563 .SUCCESS => return,
564 .AGAIN => return error.ResourceLimitReached,
565 .INVAL => return error.InvalidUserId,
566 .PERM => return error.PermissionDenied,
567 else => |err| return unexpectedErrno(err),
568 }
569}
570
571pub fn seteuid(uid: uid_t) SetEidError!void {
572 switch (errno(system.seteuid(uid))) {
573 .SUCCESS => return,
574 .INVAL => return error.InvalidUserId,
575 .PERM => return error.PermissionDenied,
576 else => |err| return unexpectedErrno(err),
577 }
578}
579
580pub fn setgid(gid: gid_t) SetIdError!void {
581 switch (errno(system.setgid(gid))) {
582 .SUCCESS => return,
583 .AGAIN => return error.ResourceLimitReached,
584 .INVAL => return error.InvalidUserId,
585 .PERM => return error.PermissionDenied,
586 else => |err| return unexpectedErrno(err),
587 }
588}
589
590pub fn setegid(uid: uid_t) SetEidError!void {
591 switch (errno(system.setegid(uid))) {
592 .SUCCESS => return,
593 .INVAL => return error.InvalidUserId,
594 .PERM => return error.PermissionDenied,
595 else => |err| return unexpectedErrno(err),
596 }
597}
598
599pub fn getuid() uid_t {
600 return system.getuid();
601}
602
603pub fn geteuid() uid_t {
604 return system.geteuid();
605}
606
607pub fn getgid() gid_t {
608 return system.getgid();
609}
610
611pub fn getegid() gid_t {
612 return system.getegid();
613}
614
615554pub const SocketError = error{
616555 /// Permission to create a socket of the specified type and/or
617556 /// pro‐tocol is denied.
......@@ -2800,20 +2739,6 @@ pub fn tcsetpgrp(handle: fd_t, pgrp: pid_t) TermioSetPgrpError!void {
28002739 }
28012740}
28022741
2803pub const SetSidError = error{
2804 /// 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.
2805 PermissionDenied,
2806} || UnexpectedError;
2807
2808pub fn setsid() SetSidError!pid_t {
2809 const rc = system.setsid();
2810 switch (errno(rc)) {
2811 .SUCCESS => return @intCast(rc),
2812 .PERM => return error.PermissionDenied,
2813 else => |err| return unexpectedErrno(err),
2814 }
2815}
2816
28172742pub fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) !fd_t {
28182743 const rc = system.signalfd(fd, mask, flags);
28192744 switch (errno(rc)) {
lib/std/posix/test.zig+4-4
......@@ -35,14 +35,14 @@ test "check WASI CWD" {
3535
3636test "getuid" {
3737 if (native_os == .windows or native_os == .wasi) return error.SkipZigTest;
38 _ = posix.getuid();
39 _ = posix.geteuid();
38 _ = posix.system.getuid();
39 _ = posix.system.geteuid();
4040}
4141
4242test "getgid" {
4343 if (native_os == .windows or native_os == .wasi) return error.SkipZigTest;
44 _ = posix.getgid();
45 _ = posix.getegid();
44 _ = posix.system.getgid();
45 _ = posix.system.getegid();
4646}
4747
4848test "sigaltstack" {