From e687a59c8a6b5962b9b27cc8f7a683bab99e5006 Mon Sep 17 00:00:00 2001 From: Greg V Date: Wed, 15 Apr 2020 01:01:13 +0300 Subject: [PATCH 1/2] freebsdlike: add SCM_CREDS It is present on both FreeBSD and DragonFly --- src/unix/bsd/freebsdlike/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/unix/bsd/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs index 509bf8c08e975..b10f60f18b625 100644 --- a/src/unix/bsd/freebsdlike/mod.rs +++ b/src/unix/bsd/freebsdlike/mod.rs @@ -738,6 +738,7 @@ pub const MSG_DONTWAIT: ::c_int = 0x00000080; pub const MSG_EOF: ::c_int = 0x00000100; pub const SCM_TIMESTAMP: ::c_int = 0x02; +pub const SCM_CREDS: ::c_int = 0x03; pub const SOCK_STREAM: ::c_int = 1; pub const SOCK_DGRAM: ::c_int = 2; From d8764e8b78b2736ecd74f3fd29d6767e40cac491 Mon Sep 17 00:00:00 2001 From: Greg V Date: Wed, 15 Apr 2020 14:55:21 +0300 Subject: [PATCH 2/2] freebsd: add sockcred/SOCKCREDSIZE Like on NetBSD, but without a pid field in the struct. --- src/unix/bsd/freebsdlike/freebsd/mod.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index 1b714b77514ab..d9dc4f2f7459a 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -107,6 +107,15 @@ s! { pub msg_hdr: ::msghdr, pub msg_len: ::ssize_t, } + + pub struct sockcred { + 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], + } } s_no_extra_traits! { @@ -1136,6 +1145,15 @@ f! { as ::c_uint } + pub fn SOCKCREDSIZE(ngrps: usize) -> usize { + let ngrps = if ngrps > 0 { + ngrps - 1 + } else { + 0 + }; + ::mem::size_of::() + ::mem::size_of::<::gid_t>() * ngrps + } + pub fn uname(buf: *mut ::utsname) -> ::c_int { __xuname(256, buf as *mut ::c_void) }