Skip to content

Commit 9d6115a

Browse files
committed
Auto merge of #867 - Susurrus:ucreds, r=alexcrichton
Ucreds I'm not positive on the `SOCKCREDSIZE()` implementation, but we'll see what CI says I guess.
2 parents b080eb5 + 35992f2 commit 9d6115a

File tree

7 files changed

+40
-19
lines changed

7 files changed

+40
-19
lines changed

src/dox.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,6 @@ mod imp {
146146

147147
pub mod mem {
148148
pub fn size_of_val<T>(_: &T) -> usize { 4 }
149+
pub fn size_of<T>(_: &T) -> usize { 4 }
149150
}
150151
}

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@ s! {
159159
pub int_p_sign_posn: ::c_char,
160160
pub int_n_sign_posn: ::c_char,
161161
}
162+
163+
pub struct cmsgcred {
164+
pub cmcred_pid: ::pid_t,
165+
pub cmcred_uid: ::uid_t,
166+
pub cmcred_euid: ::uid_t,
167+
pub cmcred_gid: ::gid_t,
168+
pub cmcred_ngroups: ::c_short,
169+
pub cmcred_groups: [::gid_t; CMGROUP_MAX],
170+
}
162171
}
163172

164173
pub const AIO_LISTIO_MAX: ::c_int = 16;
@@ -934,6 +943,8 @@ pub const OCRNL: ::tcflag_t = 0x10;
934943
pub const ONOCR: ::tcflag_t = 0x20;
935944
pub const ONLRET: ::tcflag_t = 0x40;
936945

946+
pub const CMGROUP_MAX: usize = 16;
947+
937948
f! {
938949
pub fn WIFCONTINUED(status: ::c_int) -> bool {
939950
status == 0x13

src/unix/bsd/netbsdlike/netbsd/mod.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use dox::mem;
2+
13
pub type clock_t = ::c_uint;
24
pub type suseconds_t = ::c_int;
35
pub type dev_t = u64;
@@ -281,6 +283,16 @@ s! {
281283
pub ifm_index: ::c_ushort,
282284
pub ifm_data: if_data,
283285
}
286+
287+
pub struct sockcred {
288+
pub sc_pid: ::pid_t,
289+
pub sc_uid: ::uid_t,
290+
pub sc_euid: ::uid_t,
291+
pub sc_gid: ::gid_t,
292+
pub sc_egid: ::gid_t,
293+
pub sc_ngroups: ::c_int,
294+
pub sc_groups: [::gid_t; 1],
295+
}
284296
}
285297

286298
pub const AT_FDCWD: ::c_int = -100;
@@ -910,12 +922,21 @@ pub const SOCK_NONBLOCK: ::c_int = 0x20000000;
910922
// http://cvsweb.netbsd.org/bsdweb.cgi/src/include/dirent.h?rev=1.36
911923
f! {
912924
pub fn dirfd(dirp: *mut ::DIR) -> ::c_int {
913-
unsafe { *(dirp as *const ::c_int) }
925+
*(dirp as *const ::c_int)
914926
}
915927

916928
pub fn WIFCONTINUED(status: ::c_int) -> bool {
917929
status == 0xffff
918930
}
931+
932+
pub fn SOCKCREDSIZE(ngrps: usize) -> usize {
933+
let ngrps = if ngrps > 0 {
934+
ngrps - 1
935+
} else {
936+
0
937+
};
938+
mem::size_of::<sockcred>() + mem::size_of::<::gid_t>() * ngrps
939+
}
919940
}
920941

921942
extern {

src/unix/notbsd/linux/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,12 @@ s! {
448448
pub p_memsz: Elf64_Xword,
449449
pub p_align: Elf64_Xword,
450450
}
451+
452+
pub struct ucred {
453+
pub pid: ::pid_t,
454+
pub uid: ::uid_t,
455+
pub gid: ::gid_t,
456+
}
451457
}
452458

453459
pub const ABDAY_1: ::nl_item = 0x20000;

src/unix/notbsd/linux/musl/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ s! {
7575
pub mem_unit: ::c_uint,
7676
pub __reserved: [::c_char; 256],
7777
}
78-
79-
pub struct ucred {
80-
pub pid: ::pid_t,
81-
pub uid: ::uid_t,
82-
pub gid: ::gid_t,
83-
}
8478
}
8579

8680
pub const SFD_CLOEXEC: ::c_int = 0x080000;

src/unix/notbsd/linux/other/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,6 @@ s! {
104104
__unused5: *mut ::c_void,
105105
}
106106

107-
pub struct ucred {
108-
pub pid: ::pid_t,
109-
pub uid: ::uid_t,
110-
pub gid: ::gid_t,
111-
}
112-
113107
pub struct statfs {
114108
pub f_type: __fsword_t,
115109
pub f_bsize: __fsword_t,

src/unix/notbsd/linux/s390x.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,6 @@ s! {
221221
__unused5: *mut ::c_void,
222222
}
223223

224-
pub struct ucred {
225-
pub pid: ::pid_t,
226-
pub uid: ::uid_t,
227-
pub gid: ::gid_t,
228-
}
229-
230224
pub struct flock {
231225
pub l_type: ::c_short,
232226
pub l_whence: ::c_short,

0 commit comments

Comments
 (0)