mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
whoami and id use c_types
This commit is contained in:
parent
2420c38b7e
commit
b6018f38e8
3 changed files with 33 additions and 28 deletions
24
common/c_types.rs
Normal file
24
common/c_types.rs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#[allow(dead_code)];
|
||||||
|
|
||||||
|
use std::libc::{
|
||||||
|
c_char,
|
||||||
|
c_int,
|
||||||
|
time_t
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct c_passwd {
|
||||||
|
pw_name: *c_char, /* user name */
|
||||||
|
pw_passwd: *c_char, /* user name */
|
||||||
|
pw_uid: c_int, /* user uid */
|
||||||
|
pw_gid: c_int, /* user gid */
|
||||||
|
pw_change: time_t,
|
||||||
|
pw_class: *c_char,
|
||||||
|
pw_gecos: *c_char,
|
||||||
|
pw_dir: *c_char,
|
||||||
|
pw_shell: *c_char,
|
||||||
|
pw_expire: time_t
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct c_group {
|
||||||
|
gr_name: *c_char /* group name */
|
||||||
|
}
|
27
id/id.rs
27
id/id.rs
|
@ -22,7 +22,6 @@ use std::ptr::read;
|
||||||
use std::libc::{
|
use std::libc::{
|
||||||
c_char,
|
c_char,
|
||||||
c_int,
|
c_int,
|
||||||
time_t,
|
|
||||||
uid_t,
|
uid_t,
|
||||||
getgid,
|
getgid,
|
||||||
getegid,
|
getegid,
|
||||||
|
@ -31,27 +30,13 @@ use std::libc::{
|
||||||
};
|
};
|
||||||
use std::str::raw::from_c_str;
|
use std::str::raw::from_c_str;
|
||||||
use getopts::{getopts, optflag, usage};
|
use getopts::{getopts, optflag, usage};
|
||||||
|
use c_types::{
|
||||||
|
c_passwd,
|
||||||
|
c_group
|
||||||
|
};
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"] mod util;
|
||||||
mod util;
|
#[path = "../common/c_types.rs"] mod c_types;
|
||||||
|
|
||||||
// These could be extracted into their own file
|
|
||||||
struct c_passwd {
|
|
||||||
pw_name: *c_char, /* user name */
|
|
||||||
pw_passwd: *c_char, /* user name */
|
|
||||||
pw_uid: c_int, /* user uid */
|
|
||||||
pw_gid: c_int, /* user gid */
|
|
||||||
pw_change: time_t,
|
|
||||||
pw_class: *c_char,
|
|
||||||
pw_gecos: *c_char,
|
|
||||||
pw_dir: *c_char,
|
|
||||||
pw_shell: *c_char,
|
|
||||||
pw_expire: time_t
|
|
||||||
}
|
|
||||||
|
|
||||||
struct c_group {
|
|
||||||
gr_name: *c_char /* group name */
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(not(target_os = "linux"))]
|
||||||
mod audit {
|
mod audit {
|
||||||
|
|
|
@ -22,14 +22,10 @@ use std::io::print;
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::libc;
|
use std::libc;
|
||||||
|
use c_types::c_passwd;
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"] mod util;
|
||||||
mod util;
|
#[path = "../common/c_types.rs"] mod c_types;
|
||||||
|
|
||||||
struct c_passwd {
|
|
||||||
pw_name: *libc::c_char,
|
|
||||||
// Maybe I should put here others struct members, but...Well, maybe.
|
|
||||||
}
|
|
||||||
|
|
||||||
extern {
|
extern {
|
||||||
pub fn geteuid() -> libc::c_int;
|
pub fn geteuid() -> libc::c_int;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue