1<?xml version='1.0'?>
2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3  "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
5
6<refentry id="sd_bus_negotiate_fds" xmlns:xi="http://www.w3.org/2001/XInclude">
7
8  <refentryinfo>
9    <title>sd_bus_negotiate_fds</title>
10    <productname>systemd</productname>
11  </refentryinfo>
12
13  <refmeta>
14    <refentrytitle>sd_bus_negotiate_fds</refentrytitle>
15    <manvolnum>3</manvolnum>
16  </refmeta>
17
18  <refnamediv>
19    <refname>sd_bus_negotiate_fds</refname>
20    <refname>sd_bus_negotiate_timestamp</refname>
21    <refname>sd_bus_negotiate_creds</refname>
22    <refname>sd_bus_get_creds_mask</refname>
23
24    <refpurpose>Control feature negotiation on bus connections</refpurpose>
25  </refnamediv>
26
27  <refsynopsisdiv>
28    <funcsynopsis>
29      <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
30
31      <funcprototype>
32        <funcdef>int <function>sd_bus_negotiate_fds</function></funcdef>
33        <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
34        <paramdef>int <parameter>b</parameter></paramdef>
35      </funcprototype>
36
37      <funcprototype>
38        <funcdef>int <function>sd_bus_negotiate_timestamp</function></funcdef>
39        <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
40        <paramdef>int <parameter>b</parameter></paramdef>
41      </funcprototype>
42
43      <funcprototype>
44        <funcdef>int <function>sd_bus_negotiate_creds</function></funcdef>
45        <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
46        <paramdef>int <parameter>b</parameter></paramdef>
47        <paramdef>uint64_t <parameter>mask</parameter></paramdef>
48      </funcprototype>
49
50      <funcprototype>
51        <funcdef>int <function>sd_bus_get_creds_mask</function></funcdef>
52        <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
53        <paramdef>uint64_t *<parameter>mask</parameter></paramdef>
54      </funcprototype>
55    </funcsynopsis>
56  </refsynopsisdiv>
57
58  <refsect1>
59    <title>Description</title>
60
61    <para><function>sd_bus_negotiate_fds()</function> controls whether file descriptor passing shall be
62    negotiated for the specified bus connection. It takes a bus object and a boolean, which, when true,
63    enables file descriptor passing, and, when false, disables it. Note that not all transports and servers
64    support file descriptor passing. In particular, networked transports generally do not support file
65    descriptor passing. To find out whether file descriptor passing is available after negotiation, use
66    <citerefentry><refentrytitle>sd_bus_can_send</refentrytitle><manvolnum>3</manvolnum></citerefentry>
67    and pass <constant>SD_BUS_TYPE_UNIX_FD</constant>. Note that file descriptor passing is always enabled
68    for both sending and receiving or for neither, but never only in one direction. By default, file
69    descriptor passing is negotiated for all connections.</para>
70
71    <para><function>sd_bus_negotiate_timestamp()</function> controls whether implicit sender timestamps shall
72    be attached automatically to all incoming messages. Takes a bus object and a boolean, which, when true,
73    enables timestamping, and, when false, disables it.  Use
74    <citerefentry><refentrytitle>sd_bus_message_get_monotonic_usec</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
75    <citerefentry><refentrytitle>sd_bus_message_get_realtime_usec</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
76    <citerefentry><refentrytitle>sd_bus_message_get_seqnum</refentrytitle><manvolnum>3</manvolnum></citerefentry>
77    to query the timestamps of incoming messages. If negotiation is disabled or not supported, these calls
78    will fail with <constant>-ENODATA</constant>. Note that currently no transports support timestamping of
79    messages. By default, message timestamping is not negotiated for connections.</para>
80
81    <para><function>sd_bus_negotiate_creds()</function> controls whether and which implicit sender
82    credentials shall be attached automatically to all incoming messages. Takes a bus object and a boolean
83    indicating whether to enable or disable the credential parts encoded in the bit mask value argument. Note
84    that not all transports support attaching sender credentials to messages, or do not support all types of
85    sender credential parameters, or might suppress them under certain circumstances for individual messages.
86    Specifically, dbus1 only supports <constant>SD_BUS_CREDS_UNIQUE_NAME</constant>. The sender credentials
87    are suitable for authorization decisions. By default, only
88    <constant>SD_BUS_CREDS_WELL_KNOWN_NAMES</constant> and <constant>SD_BUS_CREDS_UNIQUE_NAME</constant> are
89    enabled. In fact, these two credential fields are always sent along and cannot be turned off.</para>
90
91    <para><function>sd_bus_get_creds_mask()</function> returns the set of sender credentials that was
92    negotiated to be attached to all incoming messages in <parameter>mask</parameter>. This value is an
93    upper boundary only. Hence, always make sure to explicitly check which credentials are attached to a
94    specific message before using it.</para>
95
96    <para>The <function>sd_bus_negotiate_fds()</function> function may be called only before the connection
97    has been started with
98    <citerefentry><refentrytitle>sd_bus_start</refentrytitle><manvolnum>3</manvolnum></citerefentry>. Both
99    <function>sd_bus_negotiate_timestamp()</function> and <function>sd_bus_negotiate_creds()</function> may
100    also be called after a connection has been set up. Note that, when operating on a connection that is
101    shared between multiple components of the same program (for example via
102    <citerefentry><refentrytitle>sd_bus_default</refentrytitle><manvolnum>3</manvolnum></citerefentry>), it
103    is highly recommended to only enable additional per message metadata fields, but never disable them
104    again, in order not to disable functionality needed by other components.</para>
105  </refsect1>
106
107  <refsect1>
108    <title>Return Value</title>
109
110    <para>On success, these functions return a non-negative integer. On failure, they return a negative
111    errno-style error code.</para>
112
113    <refsect2>
114      <title>Errors</title>
115
116      <para>Returned errors may indicate the following problems:</para>
117
118      <variablelist>
119        <varlistentry>
120          <term><constant>-EPERM</constant></term>
121
122          <listitem><para>The bus connection has already been started.</para></listitem>
123        </varlistentry>
124
125        <varlistentry>
126          <term><constant>-EINVAL</constant></term>
127
128          <listitem><para>An argument is invalid.</para></listitem>
129        </varlistentry>
130
131        <varlistentry>
132          <term><constant>-ENOPKG</constant></term>
133
134          <listitem><para>The bus cannot be resolved.</para></listitem>
135        </varlistentry>
136
137        <varlistentry>
138          <term><constant>-ECHILD</constant></term>
139
140          <listitem><para>The bus was created in a different process.</para></listitem>
141        </varlistentry>
142      </variablelist>
143    </refsect2>
144  </refsect1>
145
146  <xi:include href="libsystemd-pkgconfig.xml" />
147
148  <refsect1>
149    <title>See Also</title>
150
151    <para>
152      <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
153      <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
154      <citerefentry><refentrytitle>sd_bus_start</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
155      <citerefentry><refentrytitle>sd_bus_can_send</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
156      <citerefentry><refentrytitle>sd_bus_message_get_monotonic_usec</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
157      <citerefentry><refentrytitle>sd_bus_message_get_realtime_usec</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
158      <citerefentry><refentrytitle>sd_bus_message_get_seqnum</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
159      <citerefentry><refentrytitle>sd_bus_message_get_creds</refentrytitle><manvolnum>3</manvolnum></citerefentry>
160    </para>
161  </refsect1>
162
163</refentry>
164