std: add seteuid/setegid to std.os
Currently these are only implemented for linux.master
parent
01a365f1b0
commit
d0d6647fdb
|
@ -2512,11 +2512,12 @@ pub fn readlinkatZ(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) Read
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const SetIdError = error{
|
pub const SetEidError = error{
|
||||||
ResourceLimitReached,
|
|
||||||
InvalidUserId,
|
InvalidUserId,
|
||||||
PermissionDenied,
|
PermissionDenied,
|
||||||
} || UnexpectedError;
|
};
|
||||||
|
|
||||||
|
pub const SetIdError = error{ResourceLimitReached} || SetEidError || UnexpectedError;
|
||||||
|
|
||||||
pub fn setuid(uid: uid_t) SetIdError!void {
|
pub fn setuid(uid: uid_t) SetIdError!void {
|
||||||
switch (errno(system.setuid(uid))) {
|
switch (errno(system.setuid(uid))) {
|
||||||
|
@ -2528,6 +2529,15 @@ pub fn setuid(uid: uid_t) SetIdError!void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn seteuid(uid: uid_t) SetEidError!void {
|
||||||
|
switch (errno(system.seteuid(uid))) {
|
||||||
|
0 => return,
|
||||||
|
EINVAL => return error.InvalidUserId,
|
||||||
|
EPERM => return error.PermissionDenied,
|
||||||
|
else => |err| return unexpectedErrno(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn setreuid(ruid: uid_t, euid: uid_t) SetIdError!void {
|
pub fn setreuid(ruid: uid_t, euid: uid_t) SetIdError!void {
|
||||||
switch (errno(system.setreuid(ruid, euid))) {
|
switch (errno(system.setreuid(ruid, euid))) {
|
||||||
0 => return,
|
0 => return,
|
||||||
|
@ -2548,6 +2558,15 @@ pub fn setgid(gid: gid_t) SetIdError!void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn setegid(uid: uid_t) SetEidError!void {
|
||||||
|
switch (errno(system.setegid(uid))) {
|
||||||
|
0 => return,
|
||||||
|
EINVAL => return error.InvalidUserId,
|
||||||
|
EPERM => return error.PermissionDenied,
|
||||||
|
else => |err| return unexpectedErrno(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn setregid(rgid: gid_t, egid: gid_t) SetIdError!void {
|
pub fn setregid(rgid: gid_t, egid: gid_t) SetIdError!void {
|
||||||
switch (errno(system.setregid(rgid, egid))) {
|
switch (errno(system.setregid(rgid, egid))) {
|
||||||
0 => return,
|
0 => return,
|
||||||
|
|
Loading…
Reference in New Issue