1 <?xml version='1.0'?> <!--*-nxml-*-->
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 -->
6 <refentry id="sd_bus_query_sender_creds" xmlns:xi="http://www.w3.org/2001/XInclude">
9 <title>sd_bus_query_sender_creds</title>
10 <productname>systemd</productname>
14 <refentrytitle>sd_bus_query_sender_creds</refentrytitle>
15 <manvolnum>3</manvolnum>
19 <refname>sd_bus_query_sender_creds</refname>
20 <refname>sd_bus_query_sender_privilege</refname>
22 <refpurpose>Query bus message sender credentials/privileges</refpurpose>
27 <funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo>
30 <funcdef>int <function>sd_bus_query_sender_creds</function></funcdef>
31 <paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
32 <paramdef>uint64_t <parameter>mask</parameter></paramdef>
33 <paramdef>sd_bus_creds **<parameter>creds</parameter></paramdef>
37 <funcdef>sd_bus_error* <function>sd_bus_query_sender_privilege</function></funcdef>
38 <paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
39 <paramdef>int <parameter>capability</parameter></paramdef>
45 <title>Description</title>
47 <para><function>sd_bus_query_sender_creds()</function> returns the credentials of the message
48 <parameter>m</parameter>. The <parameter>mask</parameter> parameter is a combo of
49 <constant index='false'>SD_BUS_CREDS_*</constant> flags that indicate which credential info the caller is
51 <citerefentry><refentrytitle>sd_bus_creds_new_from_pid</refentrytitle><manvolnum>3</manvolnum></citerefentry>
52 for a list of possible flags. First, this message checks if the requested credentials are attached to the
53 message itself. If not, but the message contains the pid of the sender and the caller specified the
54 <constant index='false'>SD_BUS_CREDS_AUGMENT</constant> flag, this function tries to figure out
55 the missing credentials via other means (starting from the pid). If the pid isn't available but the
56 message has a sender, this function calls
57 <citerefentry><refentrytitle>sd_bus_get_name_creds</refentrytitle><manvolnum>3</manvolnum></citerefentry>
58 to get the requested credentials. If the message has no sender (when a direct connection is used), this
60 <citerefentry><refentrytitle>sd_bus_get_owner_creds</refentrytitle><manvolnum>3</manvolnum></citerefentry>
61 to get the requested credentials. On success, the requested credentials are stored in
62 <parameter>creds</parameter>. Ownership of the credentials object in <parameter>creds</parameter> is
63 transferred to the caller and should be freed by calling
64 <citerefentry><refentrytitle>sd_bus_creds_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
67 <para><function>sd_bus_query_sender_privilege()</function> checks if the message <parameter>m</parameter>
68 has the requested privileges. If <parameter>capability</parameter> is a non-negative integer, this
69 function checks if the message has the capability with the same value. See
70 <citerefentry project='man-pages'><refentrytitle>capabilities</refentrytitle><manvolnum>7</manvolnum></citerefentry>
71 for a list of capabilities. If <parameter>capability</parameter> is a negative integer, this function
72 returns whether the sender of the message runs as the same user as the receiver of the message, or if the
73 sender of the message runs as root and the receiver of the message does not run as root. On success and
74 if the message has the requested privileges, this function returns a positive integer. If the message
75 does not have the requested privileges, this function returns zero.</para>
79 <title>Return Value</title>
81 <para>On success, these functions return a non-negative integer. On failure, they return a negative
82 errno-style error code.</para>
87 <para>Returned errors may indicate the following problems:</para>
91 <term><constant>-EINVAL</constant></term>
93 <listitem><para>The message <parameter>m</parameter> or an output parameter is
94 <constant>NULL</constant>.</para>
96 <xi:include href="version-info.xml" xpointer="v246"/></listitem>
100 <term><constant>-ENOTCONN</constant></term>
102 <listitem><para>The bus of <parameter>m</parameter> is not connected.</para>
104 <xi:include href="version-info.xml" xpointer="v246"/></listitem>
108 <term><constant>-ECHILD</constant></term>
110 <listitem><para>The bus of <parameter>m</parameter> was created in a different process, library or module instance.
113 <xi:include href="version-info.xml" xpointer="v246"/></listitem>
117 <term><constant>-EPERM</constant></term>
119 <listitem><para>The message <parameter>m</parameter> is not sealed.</para>
121 <xi:include href="version-info.xml" xpointer="v246"/></listitem>
127 <xi:include href="libsystemd-pkgconfig.xml" />
130 <title>History</title>
131 <para><function>sd_bus_query_sender_creds()</function> and
132 <function>sd_bus_query_sender_privilege()</function> were added in version 246.</para>
136 <title>See Also</title>
139 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
140 <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
141 <citerefentry><refentrytitle>sd_bus_creds_new_from_pid</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
142 <citerefentry><refentrytitle>sd_bus_get_name_creds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
143 <citerefentry><refentrytitle>sd_bus_get_owner_creds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
144 <citerefentry><refentrytitle>sd_bus_creds_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
145 <citerefentry project='man-pages'><refentrytitle>capabilities</refentrytitle><manvolnum>7</manvolnum></citerefentry>