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

applications and libraries should reach for the lower level APIs instead
This commit is contained in:
Andrew Kelley 2026-01-07 14:25:29 -08:00
parent 213ef95346
commit ceae9600e3
2 changed files with 4 additions and 79 deletions

View file

@ -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
/// protocol 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)) {

View file

@ -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" {