mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
c_types: use libc::{uid_t,gid_t} where appropriate
This commit is contained in:
parent
30df0ca208
commit
b39cf18418
1 changed files with 14 additions and 13 deletions
|
@ -6,6 +6,7 @@ use self::libc::{
|
||||||
c_char,
|
c_char,
|
||||||
c_int,
|
c_int,
|
||||||
uid_t,
|
uid_t,
|
||||||
|
gid_t,
|
||||||
};
|
};
|
||||||
#[cfg(target_os = "macos")] use self::libc::time_t;
|
#[cfg(target_os = "macos")] use self::libc::time_t;
|
||||||
use self::libc::funcs::posix88::unistd::getgroups;
|
use self::libc::funcs::posix88::unistd::getgroups;
|
||||||
|
@ -19,8 +20,8 @@ use std::str::raw::from_c_str;
|
||||||
pub struct c_passwd {
|
pub struct c_passwd {
|
||||||
pub pw_name: *c_char, /* user name */
|
pub pw_name: *c_char, /* user name */
|
||||||
pub pw_passwd: *c_char, /* user name */
|
pub pw_passwd: *c_char, /* user name */
|
||||||
pub pw_uid: c_int, /* user uid */
|
pub pw_uid: uid_t, /* user uid */
|
||||||
pub pw_gid: c_int, /* user gid */
|
pub pw_gid: gid_t, /* user gid */
|
||||||
pub pw_change: time_t,
|
pub pw_change: time_t,
|
||||||
pub pw_class: *c_char,
|
pub pw_class: *c_char,
|
||||||
pub pw_gecos: *c_char,
|
pub pw_gecos: *c_char,
|
||||||
|
@ -33,8 +34,8 @@ pub struct c_passwd {
|
||||||
pub struct c_passwd {
|
pub struct c_passwd {
|
||||||
pub pw_name: *c_char, /* user name */
|
pub pw_name: *c_char, /* user name */
|
||||||
pub pw_passwd: *c_char, /* user name */
|
pub pw_passwd: *c_char, /* user name */
|
||||||
pub pw_uid: c_int, /* user uid */
|
pub pw_uid: uid_t, /* user uid */
|
||||||
pub pw_gid: c_int, /* user gid */
|
pub pw_gid: gid_t, /* user gid */
|
||||||
pub pw_gecos: *c_char,
|
pub pw_gecos: *c_char,
|
||||||
pub pw_dir: *c_char,
|
pub pw_dir: *c_char,
|
||||||
pub pw_shell: *c_char,
|
pub pw_shell: *c_char,
|
||||||
|
@ -76,13 +77,13 @@ pub struct c_tm {
|
||||||
}
|
}
|
||||||
|
|
||||||
extern {
|
extern {
|
||||||
pub fn getpwuid(uid: c_int) -> *c_passwd;
|
pub fn getpwuid(uid: uid_t) -> *c_passwd;
|
||||||
pub fn getpwnam(login: *c_char) -> *c_passwd;
|
pub fn getpwnam(login: *c_char) -> *c_passwd;
|
||||||
pub fn getgrouplist(name: *c_char,
|
pub fn getgrouplist(name: *c_char,
|
||||||
basegid: c_int,
|
basegid: gid_t,
|
||||||
groups: *c_int,
|
groups: *gid_t,
|
||||||
ngroups: *mut c_int) -> c_int;
|
ngroups: *mut c_int) -> c_int;
|
||||||
pub fn getgrgid(gid: uid_t) -> *c_group;
|
pub fn getgrgid(gid: gid_t) -> *c_group;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_pw_from_args(free: &Vec<String>) -> Option<c_passwd> {
|
pub fn get_pw_from_args(free: &Vec<String>) -> Option<c_passwd> {
|
||||||
|
@ -91,8 +92,8 @@ pub fn get_pw_from_args(free: &Vec<String>) -> Option<c_passwd> {
|
||||||
|
|
||||||
// Passed user as id
|
// Passed user as id
|
||||||
if username.chars().all(|c| c.is_digit()) {
|
if username.chars().all(|c| c.is_digit()) {
|
||||||
let id = from_str::<i32>(username).unwrap();
|
let id = from_str::<u32>(username).unwrap();
|
||||||
let pw_pointer = unsafe { getpwuid(id) };
|
let pw_pointer = unsafe { getpwuid(id as uid_t) };
|
||||||
|
|
||||||
if pw_pointer.is_not_null() {
|
if pw_pointer.is_not_null() {
|
||||||
Some(unsafe { read(pw_pointer) })
|
Some(unsafe { read(pw_pointer) })
|
||||||
|
@ -133,7 +134,7 @@ pub fn group(possible_pw: Option<c_passwd>, nflag: bool) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ngroups = unsafe {
|
ngroups = unsafe {
|
||||||
getgroups(NGROUPS, groups.as_mut_ptr() as *mut u32)
|
getgroups(NGROUPS, groups.as_mut_ptr() as *mut gid_t)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +143,7 @@ pub fn group(possible_pw: Option<c_passwd>, nflag: bool) {
|
||||||
|
|
||||||
for &g in groups.iter() {
|
for &g in groups.iter() {
|
||||||
if nflag {
|
if nflag {
|
||||||
let group = unsafe { getgrgid(g as u32) };
|
let group = unsafe { getgrgid(g) };
|
||||||
if group.is_not_null() {
|
if group.is_not_null() {
|
||||||
let name = unsafe {
|
let name = unsafe {
|
||||||
from_c_str(read(group).gr_name)
|
from_c_str(read(group).gr_name)
|
||||||
|
@ -150,7 +151,7 @@ pub fn group(possible_pw: Option<c_passwd>, nflag: bool) {
|
||||||
print!("{:s} ", name);
|
print!("{:s} ", name);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print!("{:d} ", g);
|
print!("{:u} ", g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue