@@ -16,6 +16,8 @@ mod libc {
16
16
pub use libc:: c_int;
17
17
pub struct ucred ;
18
18
pub struct cmsghdr ;
19
+ #[ cfg( target_os = "dragonfly" ) ]
20
+ pub struct cmsgcred ;
19
21
pub type pid_t = i32 ;
20
22
pub type gid_t = u32 ;
21
23
pub type uid_t = u32 ;
@@ -183,6 +185,11 @@ impl<'a, T> Iterator for AncillaryDataIter<'a, T> {
183
185
#[ derive( Clone ) ]
184
186
pub struct SocketCred ( libc:: ucred ) ;
185
187
188
+ #[ cfg( target_os = "dragonfly" ) ]
189
+ #[ unstable( feature = "unix_socket_ancillary_data" , issue = "76915" ) ]
190
+ #[ derive( Clone ) ]
191
+ pub struct SocketCred ( libc:: cmsgcred ) ;
192
+
186
193
#[ cfg( any( doc, target_os = "android" , target_os = "linux" , ) ) ]
187
194
impl SocketCred {
188
195
/// Create a Unix credential struct.
@@ -234,6 +241,57 @@ impl SocketCred {
234
241
}
235
242
}
236
243
244
+ #[ cfg( target_os = "dragonfly" ) ]
245
+ impl SocketCred {
246
+ /// Create a Unix credential struct.
247
+ ///
248
+ /// PID, UID and GID is set to 0.
249
+ #[ unstable( feature = "unix_socket_ancillary_data" , issue = "76915" ) ]
250
+ #[ must_use]
251
+ pub fn new ( ) -> SocketCred {
252
+ SocketCred ( libc:: cmsgcred { cmsgcred_pid : 0 , cmsgcred_uid : 0 , cmsgcred_gid : 0 } )
253
+ }
254
+
255
+ /// Set the PID.
256
+ #[ unstable( feature = "unix_socket_ancillary_data" , issue = "76915" ) ]
257
+ pub fn set_pid ( & mut self , pid : libc:: pid_t ) {
258
+ self . 0 . cmsgcred_pid = pid;
259
+ }
260
+
261
+ /// Get the current PID.
262
+ #[ must_use]
263
+ #[ unstable( feature = "unix_socket_ancillary_data" , issue = "76915" ) ]
264
+ pub fn get_pid ( & self ) -> libc:: pid_t {
265
+ self . 0 . cmsgcred_pid
266
+ }
267
+
268
+ /// Set the UID.
269
+ #[ unstable( feature = "unix_socket_ancillary_data" , issue = "76915" ) ]
270
+ pub fn set_uid ( & mut self , uid : libc:: uid_t ) {
271
+ self . 0 . cmsgcred_uid = uid;
272
+ }
273
+
274
+ /// Get the current UID.
275
+ #[ must_use]
276
+ #[ unstable( feature = "unix_socket_ancillary_data" , issue = "76915" ) ]
277
+ pub fn get_uid ( & self ) -> libc:: uid_t {
278
+ self . 0 . cmsgcred_uid
279
+ }
280
+
281
+ /// Set the GID.
282
+ #[ unstable( feature = "unix_socket_ancillary_data" , issue = "76915" ) ]
283
+ pub fn set_gid ( & mut self , gid : libc:: gid_t ) {
284
+ self . 0 . cmsgcred_gid = gid;
285
+ }
286
+
287
+ /// Get the current GID.
288
+ #[ must_use]
289
+ #[ unstable( feature = "unix_socket_ancillary_data" , issue = "76915" ) ]
290
+ pub fn get_gid ( & self ) -> libc:: gid_t {
291
+ self . 0 . cmsgcred_gid
292
+ }
293
+ }
294
+
237
295
/// This control message contains file descriptors.
238
296
///
239
297
/// The level is equal to `SOL_SOCKET` and the type is equal to `SCM_RIGHTS`.
@@ -256,7 +314,11 @@ impl<'a> Iterator for ScmRights<'a> {
256
314
#[ unstable( feature = "unix_socket_ancillary_data" , issue = "76915" ) ]
257
315
pub struct ScmCredentials < ' a > ( AncillaryDataIter < ' a , libc:: ucred > ) ;
258
316
259
- #[ cfg( any( doc, target_os = "android" , target_os = "linux" , ) ) ]
317
+ #[ cfg( target_os = "dragonfly" ) ]
318
+ #[ unstable( feature = "unix_socket_ancillary_data" , issue = "76915" ) ]
319
+ pub struct ScmCredentials < ' a > ( AncillaryDataIter < ' a , libc:: cmsgcred > ) ;
320
+
321
+ #[ cfg( any( doc, target_os = "android" , target_os = "linux" , target_os = "dragonfly" , ) ) ]
260
322
#[ unstable( feature = "unix_socket_ancillary_data" , issue = "76915" ) ]
261
323
impl < ' a > Iterator for ScmCredentials < ' a > {
262
324
type Item = SocketCred ;
@@ -300,7 +362,7 @@ impl<'a> AncillaryData<'a> {
300
362
/// # Safety
301
363
///
302
364
/// `data` must contain a valid control message and the control message must be type of
303
- /// `SOL_SOCKET` and level of `SCM_CREDENTIALS` or `SCM_CREDENTIALS `.
365
+ /// `SOL_SOCKET` and level of `SCM_CREDENTIALS` or `SCM_CREDS `.
304
366
#[ cfg( any( doc, target_os = "android" , target_os = "linux" , ) ) ]
305
367
unsafe fn as_credentials ( data : & ' a [ u8 ] ) -> Self {
306
368
let ancillary_data_iter = AncillaryDataIter :: new ( data) ;
@@ -320,6 +382,9 @@ impl<'a> AncillaryData<'a> {
320
382
libc:: SCM_RIGHTS => Ok ( AncillaryData :: as_rights ( data) ) ,
321
383
#[ cfg( any( target_os = "android" , target_os = "linux" , ) ) ]
322
384
libc:: SCM_CREDENTIALS => Ok ( AncillaryData :: as_credentials ( data) ) ,
385
+ #[ cfg( target_os = "dragonfly" ) ]
386
+ libc:: SCM_CREDS => Ok ( AncillaryData :: as_credentials ( data) ) ,
387
+
323
388
cmsg_type => {
324
389
Err ( AncillaryError :: Unknown { cmsg_level : libc:: SOL_SOCKET , cmsg_type } )
325
390
}
@@ -544,6 +609,19 @@ impl<'a> SocketAncillary<'a> {
544
609
)
545
610
}
546
611
612
+ #[ cfg( target_os = "dragonfly" ) ]
613
+ #[ unstable( feature = "unix_socket_ancillary_data" , issue = "76915" ) ]
614
+ pub fn add_creds ( & mut self , creds : & [ SocketCred ] ) -> bool {
615
+ self . truncated = false ;
616
+ add_to_ancillary_data (
617
+ & mut self . buffer ,
618
+ & mut self . length ,
619
+ creds,
620
+ libc:: SOL_SOCKET ,
621
+ libc:: SCM_CREDS ,
622
+ )
623
+ }
624
+
547
625
/// Clears the ancillary data, removing all values.
548
626
///
549
627
/// # Example
0 commit comments