whoami and id use c_types

This commit is contained in:
Alan Andrade 2014-02-23 21:55:01 -08:00
parent 2420c38b7e
commit b6018f38e8
3 changed files with 33 additions and 28 deletions

24
common/c_types.rs Normal file
View 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 */
}

View file

@ -22,7 +22,6 @@ use std::ptr::read;
use std::libc::{
c_char,
c_int,
time_t,
uid_t,
getgid,
getegid,
@ -31,27 +30,13 @@ use std::libc::{
};
use std::str::raw::from_c_str;
use getopts::{getopts, optflag, usage};
use c_types::{
c_passwd,
c_group
};
#[path = "../common/util.rs"]
mod util;
// 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 */
}
#[path = "../common/util.rs"] mod util;
#[path = "../common/c_types.rs"] mod c_types;
#[cfg(not(target_os = "linux"))]
mod audit {

View file

@ -22,14 +22,10 @@ use std::io::print;
use std::os;
use std::str;
use std::libc;
use c_types::c_passwd;
#[path = "../common/util.rs"]
mod util;
struct c_passwd {
pw_name: *libc::c_char,
// Maybe I should put here others struct members, but...Well, maybe.
}
#[path = "../common/util.rs"] mod util;
#[path = "../common/c_types.rs"] mod c_types;
extern {
pub fn geteuid() -> libc::c_int;