Add initgroups
This commit is contained in:
+13
-1
@@ -20,7 +20,7 @@ use alloc::{
|
||||
use crate::{
|
||||
c_str::CStr,
|
||||
fs::File,
|
||||
header::{errno, fcntl, string::strlen},
|
||||
header::{errno, fcntl, limits, string::strlen, unistd},
|
||||
io,
|
||||
io::{prelude::*, BufReader, Lines},
|
||||
platform,
|
||||
@@ -443,3 +443,15 @@ pub unsafe extern "C" fn getgrouplist(
|
||||
grps.len() as c_int
|
||||
}
|
||||
}
|
||||
|
||||
// MT-Safe locale
|
||||
// Not POSIX
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn initgroups(user: *const c_char, gid: gid_t) -> c_int {
|
||||
let mut groups = [0; limits::NGROUPS_MAX];
|
||||
let mut count = groups.len() as c_int;
|
||||
if getgrouplist(user, gid, groups.as_mut_ptr(), &mut count) < 0 {
|
||||
return -1;
|
||||
}
|
||||
unistd::setgroups(count as size_t, groups.as_ptr())
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//! limits.h implementation for relibc
|
||||
|
||||
pub const PATH_MAX: usize = 4096;
|
||||
pub const NGROUPS_MAX: usize = 65536;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use core::convert::TryInto;
|
||||
|
||||
use crate::{
|
||||
header::errno,
|
||||
header::{errno, limits},
|
||||
platform::{self, types::*, Pal, Sys},
|
||||
};
|
||||
|
||||
@@ -37,7 +37,7 @@ pub extern "C" fn sysconf(name: c_int) -> c_long {
|
||||
_SC_ARG_MAX => 4096,
|
||||
_SC_CHILD_MAX => 65536,
|
||||
_SC_CLK_TCK => 100,
|
||||
_SC_NGROUPS_MAX => 65536,
|
||||
_SC_NGROUPS_MAX => limits::NGROUPS_MAX as c_long,
|
||||
_SC_OPEN_MAX => 1024,
|
||||
_SC_STREAM_MAX => 16,
|
||||
_SC_TZNAME_MAX => -1,
|
||||
|
||||
Reference in New Issue
Block a user