2018-07-03 00:15:39 +03:00
<?xml version='1.0'?>
2019-03-14 16:40:58 +03:00
< !DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
2023-12-25 17:48:33 +03:00
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
2020-11-09 07:23:58 +03:00
<!-- SPDX - License - Identifier: LGPL - 2.1 - or - later -->
2014-01-05 04:28:52 +04:00
2018-06-06 12:59:04 +03:00
<refentry id= "sd_bus_creds_new_from_pid" xmlns:xi= "http://www.w3.org/2001/XInclude" >
2014-01-05 04:28:52 +04:00
<refentryinfo >
<title > sd_bus_creds_new_from_pid</title>
<productname > systemd</productname>
</refentryinfo>
<refmeta >
<refentrytitle > sd_bus_creds_new_from_pid</refentrytitle>
<manvolnum > 3</manvolnum>
</refmeta>
<refnamediv >
<refname > sd_bus_creds_new_from_pid</refname>
2024-01-26 21:00:43 +03:00
<refname > sd_bus_creds_new_from_pidfd</refname>
2014-01-05 04:28:52 +04:00
<refname > sd_bus_creds_get_mask</refname>
2015-06-23 21:42:57 +03:00
<refname > sd_bus_creds_get_augmented_mask</refname>
2014-01-05 04:28:52 +04:00
<refname > sd_bus_creds_ref</refname>
<refname > sd_bus_creds_unref</refname>
tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.
With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.
The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).
This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.
Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:
#define _cleanup_(function) __attribute__((cleanup(function)))
Or similar, to make the gcc feature easier to use.
Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.
See #2008.
2015-11-27 21:13:45 +03:00
<refname > sd_bus_creds_unrefp</refname>
2014-01-05 04:28:52 +04:00
<refpurpose > Retrieve credentials object for the specified PID</refpurpose>
</refnamediv>
<refsynopsisdiv >
<funcsynopsis >
<funcsynopsisinfo > #include < systemd/sd-bus.h> </funcsynopsisinfo>
<funcprototype >
<funcdef > int <function > sd_bus_creds_new_from_pid</function> </funcdef>
<paramdef > pid_t <parameter > pid</parameter> </paramdef>
<paramdef > uint64_t <parameter > creds_mask</parameter> </paramdef>
2014-02-16 16:55:27 +04:00
<paramdef > sd_bus_creds **<parameter > ret</parameter> </paramdef>
2014-01-05 04:28:52 +04:00
</funcprototype>
2024-01-26 21:00:43 +03:00
<funcprototype >
<funcdef > int <function > sd_bus_creds_new_from_pidfd</function> </funcdef>
<paramdef > int <parameter > pidfd</parameter> </paramdef>
<paramdef > uint64_t <parameter > creds_mask</parameter> </paramdef>
<paramdef > sd_bus_creds **<parameter > ret</parameter> </paramdef>
</funcprototype>
2014-01-05 04:28:52 +04:00
<funcprototype >
<funcdef > uint64_t <function > sd_bus_creds_get_mask</function> </funcdef>
2016-08-15 15:57:29 +03:00
<paramdef > sd_bus_creds *<parameter > c</parameter> </paramdef>
2014-01-05 04:28:52 +04:00
</funcprototype>
2015-06-23 21:42:57 +03:00
<funcprototype >
<funcdef > uint64_t <function > sd_bus_creds_get_augmented_mask</function> </funcdef>
2016-08-15 15:57:29 +03:00
<paramdef > sd_bus_creds *<parameter > c</parameter> </paramdef>
2015-06-23 21:42:57 +03:00
</funcprototype>
2014-01-05 04:28:52 +04:00
<funcprototype >
2014-02-16 16:55:27 +04:00
<funcdef > sd_bus_creds *<function > sd_bus_creds_ref</function> </funcdef>
<paramdef > sd_bus_creds *<parameter > c</parameter> </paramdef>
2014-01-05 04:28:52 +04:00
</funcprototype>
<funcprototype >
2014-02-16 16:55:27 +04:00
<funcdef > sd_bus_creds *<function > sd_bus_creds_unref</function> </funcdef>
<paramdef > sd_bus_creds *<parameter > c</parameter> </paramdef>
2014-01-05 04:28:52 +04:00
</funcprototype>
tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.
With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.
The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).
This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.
Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:
#define _cleanup_(function) __attribute__((cleanup(function)))
Or similar, to make the gcc feature easier to use.
Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.
See #2008.
2015-11-27 21:13:45 +03:00
<funcprototype >
<funcdef > void <function > sd_bus_creds_unrefp</function> </funcdef>
<paramdef > sd_bus_creds **<parameter > c</parameter> </paramdef>
</funcprototype>
2014-01-05 04:28:52 +04:00
</funcsynopsis>
<para >
<constant > SD_BUS_CREDS_PID</constant> ,
2015-06-23 21:42:57 +03:00
<constant > SD_BUS_CREDS_PPID</constant> ,
2014-01-05 04:28:52 +04:00
<constant > SD_BUS_CREDS_TID</constant> ,
<constant > SD_BUS_CREDS_UID</constant> ,
2015-06-23 21:42:57 +03:00
<constant > SD_BUS_CREDS_EUID</constant> ,
<constant > SD_BUS_CREDS_SUID</constant> ,
<constant > SD_BUS_CREDS_FSUID</constant> ,
2014-01-05 04:28:52 +04:00
<constant > SD_BUS_CREDS_GID</constant> ,
2015-06-23 21:42:57 +03:00
<constant > SD_BUS_CREDS_EGID</constant> ,
<constant > SD_BUS_CREDS_SGID</constant> ,
<constant > SD_BUS_CREDS_FSGID</constant> ,
<constant > SD_BUS_CREDS_SUPPLEMENTARY_GIDS</constant> ,
2014-01-05 04:28:52 +04:00
<constant > SD_BUS_CREDS_COMM</constant> ,
<constant > SD_BUS_CREDS_TID_COMM</constant> ,
<constant > SD_BUS_CREDS_EXE</constant> ,
<constant > SD_BUS_CREDS_CMDLINE</constant> ,
<constant > SD_BUS_CREDS_CGROUP</constant> ,
<constant > SD_BUS_CREDS_UNIT</constant> ,
<constant > SD_BUS_CREDS_SLICE</constant> ,
2015-06-23 21:42:57 +03:00
<constant > SD_BUS_CREDS_USER_UNIT</constant> ,
<constant > SD_BUS_CREDS_USER_SLICE</constant> ,
2014-01-05 04:28:52 +04:00
<constant > SD_BUS_CREDS_SESSION</constant> ,
<constant > SD_BUS_CREDS_OWNER_UID</constant> ,
<constant > SD_BUS_CREDS_EFFECTIVE_CAPS</constant> ,
<constant > SD_BUS_CREDS_PERMITTED_CAPS</constant> ,
<constant > SD_BUS_CREDS_INHERITABLE_CAPS</constant> ,
<constant > SD_BUS_CREDS_BOUNDING_CAPS</constant> ,
<constant > SD_BUS_CREDS_SELINUX_CONTEXT</constant> ,
<constant > SD_BUS_CREDS_AUDIT_SESSION_ID</constant> ,
<constant > SD_BUS_CREDS_AUDIT_LOGIN_UID</constant> ,
2015-06-23 21:42:57 +03:00
<constant > SD_BUS_CREDS_TTY</constant> ,
2014-01-05 04:28:52 +04:00
<constant > SD_BUS_CREDS_UNIQUE_NAME</constant> ,
<constant > SD_BUS_CREDS_WELL_KNOWN_NAMES</constant> ,
2015-06-23 21:42:57 +03:00
<constant > SD_BUS_CREDS_DESCRIPTION</constant> ,
2024-01-26 21:00:43 +03:00
<constant > SD_BUS_CREDS_PIDFD</constant> ,
2015-06-23 21:42:57 +03:00
<constant > SD_BUS_CREDS_AUGMENT</constant> ,
2014-01-05 04:28:52 +04:00
<constant > _SD_BUS_CREDS_ALL</constant>
</para>
</refsynopsisdiv>
<refsect1 >
<title > Description</title>
2015-06-23 21:42:57 +03:00
<para > <function > sd_bus_creds_new_from_pid()</function> creates a
new credentials object and fills it with information about the
process <parameter > pid</parameter> . The pointer to this object
2014-08-03 09:11:37 +04:00
will be stored in the <parameter > ret</parameter> pointer. Note that
2015-06-23 21:42:57 +03:00
credential objects may also be created and retrieved via
<citerefentry > <refentrytitle > sd_bus_get_name_creds</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> ,
<citerefentry > <refentrytitle > sd_bus_get_owner_creds</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry>
and
<citerefentry > <refentrytitle > sd_bus_message_get_creds</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> .</para>
2014-01-05 04:28:52 +04:00
2024-01-26 21:00:43 +03:00
<para > <function > sd_bus_creds_new_from_pidfd()</function> is identical to
<function > sd_bus_creds_new_from_pid()</function> , but takes a PID file descriptor rather than a numeric
PID as reference to the process. See <citerefentry
project='man-pages'><refentrytitle > pidfd_open</refentrytitle> <manvolnum > 2</manvolnum> </citerefentry> .</para>
<para > The information that will be stored is determined by <parameter > creds_mask</parameter> . It may
contain a subset of ORed constants <constant > SD_BUS_CREDS_PID</constant> ,
<constant > SD_BUS_CREDS_PPID</constant> , <constant > SD_BUS_CREDS_TID</constant> ,
<constant > SD_BUS_CREDS_UID</constant> , <constant > SD_BUS_CREDS_EUID</constant> ,
<constant > SD_BUS_CREDS_SUID</constant> , <constant > SD_BUS_CREDS_FSUID</constant> ,
<constant > SD_BUS_CREDS_GID</constant> , <constant > SD_BUS_CREDS_EGID</constant> ,
<constant > SD_BUS_CREDS_SGID</constant> , <constant > SD_BUS_CREDS_FSGID</constant> ,
<constant > SD_BUS_CREDS_SUPPLEMENTARY_GIDS</constant> , <constant > SD_BUS_CREDS_COMM</constant> ,
<constant > SD_BUS_CREDS_TID_COMM</constant> , <constant > SD_BUS_CREDS_EXE</constant> ,
<constant > SD_BUS_CREDS_CMDLINE</constant> , <constant > SD_BUS_CREDS_CGROUP</constant> ,
<constant > SD_BUS_CREDS_UNIT</constant> , <constant > SD_BUS_CREDS_SLICE</constant> ,
<constant > SD_BUS_CREDS_USER_UNIT</constant> , <constant > SD_BUS_CREDS_USER_SLICE</constant> ,
<constant > SD_BUS_CREDS_SESSION</constant> , <constant > SD_BUS_CREDS_OWNER_UID</constant> ,
<constant > SD_BUS_CREDS_EFFECTIVE_CAPS</constant> , <constant > SD_BUS_CREDS_PERMITTED_CAPS</constant> ,
<constant > SD_BUS_CREDS_INHERITABLE_CAPS</constant> , <constant > SD_BUS_CREDS_BOUNDING_CAPS</constant> ,
<constant > SD_BUS_CREDS_SELINUX_CONTEXT</constant> , <constant > SD_BUS_CREDS_AUDIT_SESSION_ID</constant> ,
<constant > SD_BUS_CREDS_AUDIT_LOGIN_UID</constant> , <constant > SD_BUS_CREDS_TTY</constant> ,
<constant > SD_BUS_CREDS_UNIQUE_NAME</constant> , <constant > SD_BUS_CREDS_WELL_KNOWN_NAMES</constant> ,
<constant > SD_BUS_CREDS_DESCRIPTION</constant> , and <constant > SD_BUS_CREDS_PIDFD</constant> . Use the
special value <constant > _SD_BUS_CREDS_ALL</constant> to request all supported fields. The
<constant > SD_BUS_CREDS_AUGMENT</constant> constant may not be ORed into the mask for invocations of
<function > sd_bus_creds_new_from_pid()</function> or
<function > sd_bus_creds_new_from_pidfd()</function> .</para>
2014-01-05 04:28:52 +04:00
<para > Fields can be retrieved from the credentials object using
<citerefentry > <refentrytitle > sd_bus_creds_get_pid</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry>
and other functions which correspond directly to the constants
listed above.</para>
2024-01-26 21:00:43 +03:00
<para > A mask of fields which were actually successfully retrieved can be retrieved with
<function > sd_bus_creds_get_mask()</function> . If the credentials object was created with
<function > sd_bus_creds_new_from_pid()</function> or <function > sd_bus_creds_new_from_pidfd()</function> ,
this will be a subset of fields requested in <parameter > creds_mask</parameter> .
2014-01-05 04:28:52 +04:00
</para>
2024-01-26 21:00:43 +03:00
<para > Similar to <function > sd_bus_creds_get_mask()</function> , the function
<function > sd_bus_creds_get_augmented_mask()</function> returns a bitmask of field constants. The mask
indicates which credential fields have been retrieved in a non-atomic fashion. For credential objects
created via <function > sd_bus_creds_new_from_pid()</function> or
<function > sd_bus_creds_new_from_pidfd()</function> , this mask will be identical to the mask returned by
<function > sd_bus_creds_get_mask()</function> . However, for credential objects retrieved via
<function > sd_bus_get_name_creds()</function> , this mask will be set for the credential fields that could
not be determined atomically at peer connection time, and which were later added by reading augmenting
credential data from <filename > /proc/</filename> . Similarly, for credential objects retrieved via
<function > sd_bus_get_owner_creds()</function> , the mask is set for the fields that could not be
determined atomically at bus creation time, but have been augmented. Similarly, for credential objects
retrieved via <function > sd_bus_message_get_creds()</function> , the mask is set for the fields that could
not be determined atomically at message sending time, but have been augmented. The mask returned by
<function > sd_bus_creds_get_augmented_mask()</function> is always a subset of (or identical to) the mask
returned by <function > sd_bus_creds_get_mask()</function> for the same object. The latter call hence
returns all credential fields available in the credential object, the former then marks the subset of
those that have been augmented. Note that augmented fields are unsuitable for authorization decisions, as
they may be retrieved at different times, thus being subject to races. Hence, augmented fields should be
used exclusively for informational purposes.
2015-06-23 21:42:57 +03:00
</para>
<para > <function > sd_bus_creds_ref()</function> creates a new
2014-01-05 04:28:52 +04:00
reference to the credentials object <parameter > c</parameter> . This
object will not be destroyed until
2015-06-23 21:42:57 +03:00
<function > sd_bus_creds_unref()</function> has been called as many
2014-01-05 04:28:52 +04:00
times plus once more. Once the reference count has dropped to zero,
2014-08-30 19:13:16 +04:00
<parameter > c</parameter> cannot be used anymore, so further
2014-01-05 04:28:52 +04:00
calls to <function > sd_bus_creds_ref(c)</function> or
<function > sd_bus_creds_unref(c)</function> are illegal.</para>
2015-06-23 21:42:57 +03:00
<para > <function > sd_bus_creds_unref()</function> destroys a reference
2014-01-05 04:28:52 +04:00
to <parameter > c</parameter> .</para>
tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.
With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.
The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).
This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.
Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:
#define _cleanup_(function) __attribute__((cleanup(function)))
Or similar, to make the gcc feature easier to use.
Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.
See #2008.
2015-11-27 21:13:45 +03:00
<para > <function > sd_bus_creds_unrefp()</function> is similar to
<function > sd_bus_creds_unref()</function> but takes a pointer to a
pointer to an <type > sd_bus_creds</type> object. This call is useful in
conjunction with GCC's and LLVM's <ulink
url="https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html">Clean-up
Variable Attribute</ulink> . Note that this function is defined as
inline function.</para>
<para > <function > sd_bus_creds_ref()</function> ,
<function > sd_bus_creds_unref()</function> and
<function > sd_bus_creds_unrefp()</function> execute no operation if
the passed in bus credentials object is
<constant > NULL</constant> .</para>
2014-01-05 04:28:52 +04:00
</refsect1>
<refsect1 >
<title > Return Value</title>
2024-01-26 21:00:43 +03:00
<para > On success, <function > sd_bus_creds_new_from_pid()</function> and
<function > sd_bus_creds_new_from_pidfd()</function> return 0 or a positive integer. On failure, they return
a negative errno-style error code.</para>
2014-01-05 04:28:52 +04:00
<para > <function > sd_bus_creds_get_mask()</function> returns the
mask of successfully acquired fields.</para>
2015-06-23 21:42:57 +03:00
<para > <function > sd_bus_creds_get_augmented_mask()</function>
returns the mask of fields that have been augmented from data in
2020-10-05 19:08:21 +03:00
<filename > /proc/</filename> , and are thus not suitable for
2015-06-23 21:42:57 +03:00
authorization decisions.</para>
<para > <function > sd_bus_creds_ref()</function> always returns the
2014-01-05 04:28:52 +04:00
argument.</para>
2015-06-23 21:42:57 +03:00
<para > <function > sd_bus_creds_unref()</function> always returns
2014-01-05 04:28:52 +04:00
<constant > NULL</constant> .</para>
</refsect1>
<refsect1 >
<title > Reference ownership</title>
2024-01-26 21:00:43 +03:00
<para > The functions <function > sd_bus_creds_new_from_pid()</function> and
<function > sd_bus_creds_new_from_pidfd()</function> create a new object and the caller owns the sole
reference. When not needed anymore, this reference should be destroyed with
2014-01-05 04:28:52 +04:00
<citerefentry > <refentrytitle > sd_bus_creds_unref</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> .
</para>
2019-03-21 16:53:00 +03:00
<refsect2 >
<title > Errors</title>
2014-01-05 04:28:52 +04:00
2019-03-21 16:53:00 +03:00
<para > Returned errors may indicate the following problems:</para>
2014-01-05 04:28:52 +04:00
2019-03-21 16:53:00 +03:00
<variablelist >
2014-01-05 04:28:52 +04:00
2019-03-21 16:53:00 +03:00
<varlistentry >
<term > <constant > -ESRCH</constant> </term>
2014-01-05 04:28:52 +04:00
2019-03-21 16:53:00 +03:00
<listitem > <para > Specified <parameter > pid</parameter> could not be found.</para> </listitem>
</varlistentry>
2014-01-05 04:28:52 +04:00
2019-03-21 16:53:00 +03:00
<varlistentry >
<term > <constant > -EINVAL</constant> </term>
2014-01-05 04:28:52 +04:00
2019-03-21 16:53:00 +03:00
<listitem > <para > Specified parameter is invalid (<constant > NULL</constant> in case of output
parameters).</para> </listitem>
</varlistentry>
2014-01-05 04:28:52 +04:00
2019-03-21 16:53:00 +03:00
<varlistentry >
<term > <constant > -ENOMEM</constant> </term>
2014-01-05 04:28:52 +04:00
2019-03-21 16:53:00 +03:00
<listitem > <para > Memory allocation failed.</para> </listitem>
</varlistentry>
2015-06-23 21:42:57 +03:00
2019-03-21 16:53:00 +03:00
<varlistentry >
<term > <constant > -EOPNOTSUPP</constant> </term>
2015-06-23 21:42:57 +03:00
2019-03-21 16:53:00 +03:00
<listitem > <para > One of the requested fields is unknown to the local system.</para> </listitem>
</varlistentry>
</variablelist>
</refsect2>
2014-01-05 04:28:52 +04:00
</refsect1>
2018-06-06 12:59:04 +03:00
<xi:include href= "libsystemd-pkgconfig.xml" />
2014-01-05 04:28:52 +04:00
2023-09-04 15:46:35 +03:00
<refsect1 >
<title > History</title>
2023-09-18 19:44:26 +03:00
<para > <function > sd_bus_creds_new_from_pid()</function> ,
<function > sd_bus_creds_get_mask()</function> ,
2024-04-18 03:45:51 +03:00
<function > sd_bus_creds_ref()</function> ,
<function > sd_bus_creds_unref()</function> , and
<function > sd_bus_creds_get_augmented_mask()</function> were added in version 221.</para>
2023-09-04 15:46:35 +03:00
<para > <function > sd_bus_creds_unrefp()</function> was added in version 229.</para>
2024-01-26 21:00:43 +03:00
<para > <function > sd_bus_creds_new_from_pidfd()</function> was added in version 256.</para>
2023-09-04 15:46:35 +03:00
</refsect1>
2014-01-05 04:28:52 +04:00
<refsect1 >
<title > See Also</title>
2023-12-22 21:09:32 +03:00
<para > <simplelist type= "inline" >
<member > <citerefentry > <refentrytitle > systemd</refentrytitle> <manvolnum > 1</manvolnum> </citerefentry> </member>
<member > <citerefentry > <refentrytitle > sd-bus</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> </member>
<member > <citerefentry > <refentrytitle > sd_bus_creds_get_pid</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> </member>
<member > <citerefentry > <refentrytitle > sd_bus_get_name_creds</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> </member>
<member > <citerefentry > <refentrytitle > sd_bus_get_owner_creds</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> </member>
<member > <citerefentry > <refentrytitle > sd_bus_message_get_creds</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> </member>
</simplelist> </para>
2014-01-05 04:28:52 +04:00
</refsect1>
</refentry>