Skip to content

Commit

Permalink
Add ucred-like structs for FreeBSDs and NetBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryant Mairs committed Dec 8, 2017
1 parent 6cf652e commit 011ba6d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/dox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,6 @@ mod imp {

pub mod mem {
pub fn size_of_val<T>(_: &T) -> usize { 4 }
pub fn size_of<T>(_: &T) -> usize { 4 }
}
}
11 changes: 11 additions & 0 deletions src/unix/bsd/freebsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ s! {
pub int_p_sign_posn: ::c_char,
pub int_n_sign_posn: ::c_char,
}

pub struct cmsgcred {
pub cmcred_pid: ::pid_t,
pub cmcred_uid: ::uid_t,
pub cmcred_euid: ::uid_t,
pub cmcred_gid: ::gid_t,
pub cmcred_ngroups: ::c_short,
pub cmcred_groups: [::gid_t; CMGROUP_MAX],
}
}

pub const AIO_LISTIO_MAX: ::c_int = 16;
Expand Down Expand Up @@ -934,6 +943,8 @@ pub const OCRNL: ::tcflag_t = 0x10;
pub const ONOCR: ::tcflag_t = 0x20;
pub const ONLRET: ::tcflag_t = 0x40;

pub const CMGROUP_MAX: usize = 16;

f! {
pub fn WIFCONTINUED(status: ::c_int) -> bool {
status == 0x13
Expand Down
21 changes: 21 additions & 0 deletions src/unix/bsd/netbsdlike/netbsd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use dox::mem;

pub type clock_t = ::c_uint;
pub type suseconds_t = ::c_int;
pub type dev_t = u64;
Expand Down Expand Up @@ -281,6 +283,16 @@ s! {
pub ifm_index: ::c_ushort,
pub ifm_data: if_data,
}

pub struct sockcred {
pub sc_pid: ::pid_t,
pub sc_uid: ::uid_t,
pub sc_euid: ::uid_t,
pub sc_gid: ::gid_t,
pub sc_egid: ::gid_t,
pub sc_ngroups: ::c_int,
pub sc_groups: [::gid_t; 1],
}
}

pub const AT_FDCWD: ::c_int = -100;
Expand Down Expand Up @@ -916,6 +928,15 @@ f! {
pub fn WIFCONTINUED(status: ::c_int) -> bool {
status == 0xffff
}

pub fn SOCKCREDSIZE(ngrps: usize) -> usize {
let ngrps = if ngrps > 0 {
ngrps - 1
} else {
0
};
mem::size_of::<sockcred>() + mem::size_of::<::gid_t>() * ngrps
}
}

extern {
Expand Down

0 comments on commit 011ba6d

Please sign in to comment.