text
stringlengths
0
234
then the ancillary data is truncated (or discarded)
and the excess file descriptors are automatically closed
in the receiving process.
.ip
if the number of file descriptors received in the ancillary data would
cause the process to exceed its
.b rlimit_nofile
resource limit (see
.br getrlimit (2)),
the excess file descriptors are automatically closed
in the receiving process.
.ip
the kernel constant
.br scm_max_fd
defines a limit on the number of file descriptors in the array.
attempting to send an array larger than this limit causes
.br sendmsg (2)
to fail with the error
.br einval .
.br scm_max_fd
has the value 253
(or 255 in kernels
.\" commit bba14de98753cb6599a2dae0e520714b2153522d
before 2.6.38).
.tp
.b scm_credentials
send or receive unix credentials.
this can be used for authentication.
the credentials are passed as a
.i struct ucred
ancillary message.
this structure is defined in
.i <sys/socket.h>
as follows:
.ip
.in +4n
.ex
struct ucred {
pid_t pid; /* process id of the sending process */
uid_t uid; /* user id of the sending process */
gid_t gid; /* group id of the sending process */
};
.ee
.in
.ip
since glibc 2.8, the
.b _gnu_source
feature test macro must be defined (before including
.i any
header files) in order to obtain the definition
of this structure.
.ip
the credentials which the sender specifies are checked by the kernel.
a privileged process is allowed to specify values that do not match its own.
the sender must specify its own process id (unless it has the capability
.br cap_sys_admin ,
in which case the pid of any existing process may be specified),
its real user id, effective user id, or saved set-user-id (unless it has
.br cap_setuid ),
and its real group id, effective group id, or saved set-group-id
(unless it has
.br cap_setgid ).
.ip
to receive a
.i struct ucred
message, the
.b so_passcred
option must be enabled on the socket.
.tp
.b scm_security
receive the selinux security context (the security label)
of the peer socket.
the received ancillary data is a null-terminated string containing
the security context.
the receiver should allocate at least
.br name_max
bytes in the data portion of the ancillary message for this data.
.ip
to receive the security context, the
.b so_passsec
option must be enabled on the socket (see above).
.pp
when sending ancillary data with
.br sendmsg (2),
only one item of each of the above types may be included in the sent message.
.pp
at least one byte of real data should be sent when sending ancillary data.
on linux, this is required to successfully send ancillary data over
a unix domain stream socket.
when sending ancillary data over a unix domain datagram socket,
it is not necessary on linux to send any accompanying real data.
however, portable applications should also include at least one byte
of real data when sending ancillary data over a datagram socket.
.pp
when receiving from a stream socket,
ancillary data forms a kind of barrier for the received data.
for example, suppose that the sender transmits as follows:
.pp
.rs
.pd 0