Replace setuid, setgid with setreuid, setregid
This commit is contained in:
parent
c5e0d77085
commit
1f28ec72b7
1 changed files with 47 additions and 17 deletions
|
|
@ -33,26 +33,52 @@ pub fn getuid() -> Result<usize> {
|
|||
Ok(context.ruid as usize)
|
||||
}
|
||||
|
||||
pub fn setgid(gid: u32) -> Result<usize> {
|
||||
pub fn setregid(rgid: u32, egid: u32) -> Result<usize> {
|
||||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
|
||||
let mut context = context_lock.write();
|
||||
if context.egid == 0 {
|
||||
context.rgid = gid;
|
||||
context.egid = gid;
|
||||
|
||||
if (context.euid == 0
|
||||
|| rgid as i32 == -1
|
||||
|| rgid == context.egid
|
||||
|| rgid == context.rgid)
|
||||
&& (context.euid == 0
|
||||
|| egid as i32 == -1
|
||||
|| egid == context.egid
|
||||
|| egid == context.rgid)
|
||||
{
|
||||
if rgid as i32 != -1 {
|
||||
context.rgid = rgid;
|
||||
}
|
||||
if egid as i32 != -1 {
|
||||
context.egid = egid;
|
||||
}
|
||||
Ok(0)
|
||||
} else {
|
||||
Err(Error::new(EPERM))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn setuid(uid: u32) -> Result<usize> {
|
||||
pub fn setreuid(ruid: u32, euid: u32) -> Result<usize> {
|
||||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
|
||||
let mut context = context_lock.write();
|
||||
if context.euid == 0 {
|
||||
context.ruid = uid;
|
||||
context.euid = uid;
|
||||
|
||||
if (context.euid == 0
|
||||
|| ruid as i32 == -1
|
||||
|| ruid == context.euid
|
||||
|| ruid == context.ruid)
|
||||
&& (context.euid == 0
|
||||
|| euid as i32 == -1
|
||||
|| euid == context.euid
|
||||
|| euid == context.ruid)
|
||||
{
|
||||
if ruid as i32 != -1 {
|
||||
context.ruid = ruid;
|
||||
}
|
||||
if euid as i32 != -1 {
|
||||
context.euid = euid;
|
||||
}
|
||||
Ok(0)
|
||||
} else {
|
||||
Err(Error::new(EPERM))
|
||||
|
|
|
|||
Loading…
Reference in a new issue