1 <?xml version='
1.0'
?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
4 <!ENTITY % entities SYSTEM
"custom-entities.ent" >
9 This file is part of systemd.
11 Copyright 2014 Zbigniew Jędrzejewski-Szmek
13 systemd is free software; you can redistribute it and/or modify it
14 under the terms of the GNU Lesser General Public License as published by
15 the Free Software Foundation; either version 2.1 of the License, or
16 (at your option) any later version.
18 systemd is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
23 You should have received a copy of the GNU Lesser General Public License
24 along with systemd; If not, see <http://www.gnu.org/licenses/>.
27 <refentry id=
"sd_bus_creds_get_pid">
30 <title>sd_bus_creds_get_pid
</title>
31 <productname>systemd
</productname>
35 <contrib>A monkey with a typewriter
</contrib>
36 <firstname>Zbigniew
</firstname>
37 <surname>Jędrzejewski-Szmek
</surname>
38 <email>zbyszek@in.waw.pl
</email>
44 <refentrytitle>sd_bus_creds_get_pid
</refentrytitle>
45 <manvolnum>3</manvolnum>
49 <refname>sd_bus_creds_get_pid
</refname>
50 <refname>sd_bus_creds_get_ppid
</refname>
51 <refname>sd_bus_creds_get_tid
</refname>
52 <refname>sd_bus_creds_get_uid
</refname>
53 <refname>sd_bus_creds_get_euid
</refname>
54 <refname>sd_bus_creds_get_suid
</refname>
55 <refname>sd_bus_creds_get_fsuid
</refname>
56 <refname>sd_bus_creds_get_gid
</refname>
57 <refname>sd_bus_creds_get_egid
</refname>
58 <refname>sd_bus_creds_get_sgid
</refname>
59 <refname>sd_bus_creds_get_fsgid
</refname>
60 <refname>sd_bus_creds_get_supplementary_gids
</refname>
61 <refname>sd_bus_creds_get_comm
</refname>
62 <refname>sd_bus_creds_get_tid_comm
</refname>
63 <refname>sd_bus_creds_get_exe
</refname>
64 <refname>sd_bus_creds_get_cmdline
</refname>
65 <refname>sd_bus_creds_get_cgroup
</refname>
66 <refname>sd_bus_creds_get_unit
</refname>
67 <refname>sd_bus_creds_get_user_unit
</refname>
68 <refname>sd_bus_creds_get_slice
</refname>
69 <refname>sd_bus_creds_get_session
</refname>
70 <refname>sd_bus_creds_get_owner_uid
</refname>
71 <refname>sd_bus_creds_has_effective_cap
</refname>
72 <refname>sd_bus_creds_has_permitted_cap
</refname>
73 <refname>sd_bus_creds_has_inheritable_cap
</refname>
74 <refname>sd_bus_creds_has_bounding_cap
</refname>
75 <refname>sd_bus_creds_get_selinux_context
</refname>
76 <refname>sd_bus_creds_get_audit_session_id
</refname>
77 <refname>sd_bus_creds_get_audit_login_uid
</refname>
78 <refname>sd_bus_creds_get_tty
</refname>
79 <refname>sd_bus_creds_get_unique_name
</refname>
80 <refname>sd_bus_creds_get_well_known_names
</refname>
81 <refname>sd_bus_creds_get_description
</refname>
83 <refpurpose>Retrieve fields from a credentials object
</refpurpose>
88 <funcsynopsisinfo>#include
<systemd/sd-bus.h
></funcsynopsisinfo>
91 <funcdef>int
<function>sd_bus_creds_get_pid
</function></funcdef>
92 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
93 <paramdef>pid_t *
<parameter>pid
</parameter></paramdef>
97 <funcdef>int
<function>sd_bus_creds_get_ppid
</function></funcdef>
98 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
99 <paramdef>pid_t *
<parameter>ppid
</parameter></paramdef>
103 <funcdef>int
<function>sd_bus_creds_get_tid
</function></funcdef>
104 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
105 <paramdef>pid_t *
<parameter>tid
</parameter></paramdef>
109 <funcdef>int
<function>sd_bus_creds_get_uid
</function></funcdef>
110 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
111 <paramdef>uid_t *
<parameter>uid
</parameter></paramdef>
115 <funcdef>int
<function>sd_bus_creds_get_euid
</function></funcdef>
116 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
117 <paramdef>uid_t *
<parameter>uid
</parameter></paramdef>
121 <funcdef>int
<function>sd_bus_creds_get_suid
</function></funcdef>
122 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
123 <paramdef>uid_t *
<parameter>uid
</parameter></paramdef>
127 <funcdef>int
<function>sd_bus_creds_get_fsuid
</function></funcdef>
128 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
129 <paramdef>uid_t *
<parameter>uid
</parameter></paramdef>
133 <funcdef>int
<function>sd_bus_creds_get_gid
</function></funcdef>
134 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
135 <paramdef>gid_t *
<parameter>gid
</parameter></paramdef>
139 <funcdef>int
<function>sd_bus_creds_get_egid
</function></funcdef>
140 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
141 <paramdef>gid_t *
<parameter>gid
</parameter></paramdef>
145 <funcdef>int
<function>sd_bus_creds_get_sgid
</function></funcdef>
146 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
147 <paramdef>gid_t *
<parameter>gid
</parameter></paramdef>
151 <funcdef>int
<function>sd_bus_creds_get_fsgid
</function></funcdef>
152 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
153 <paramdef>gid_t *
<parameter>gid
</parameter></paramdef>
157 <funcdef>int
<function>sd_bus_creds_get_supplementary_gids
</function></funcdef>
158 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
159 <paramdef>const gid_t **
<parameter>gids
</parameter></paramdef>
163 <funcdef>int
<function>sd_bus_creds_get_comm
</function></funcdef>
164 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
165 <paramdef>const char **
<parameter>comm
</parameter></paramdef>
169 <funcdef>int
<function>sd_bus_creds_get_tid_comm
</function></funcdef>
170 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
171 <paramdef>const char **
<parameter>comm
</parameter></paramdef>
175 <funcdef>int
<function>sd_bus_creds_get_exe
</function></funcdef>
176 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
177 <paramdef>const char **
<parameter>exe
</parameter></paramdef>
181 <funcdef>int
<function>sd_bus_creds_get_cmdline
</function></funcdef>
182 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
183 <paramdef>char ***
<parameter>cmdline
</parameter></paramdef>
187 <funcdef>int
<function>sd_bus_creds_get_cgroup
</function></funcdef>
188 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
189 <paramdef>const char **
<parameter>cgroup
</parameter></paramdef>
193 <funcdef>int
<function>sd_bus_creds_get_unit
</function></funcdef>
194 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
195 <paramdef>const char **
<parameter>unit
</parameter></paramdef>
199 <funcdef>int
<function>sd_bus_creds_get_user_unit
</function></funcdef>
200 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
201 <paramdef>const char **
<parameter>unit
</parameter></paramdef>
205 <funcdef>int
<function>sd_bus_creds_get_slice
</function></funcdef>
206 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
207 <paramdef>const char **
<parameter>slice
</parameter></paramdef>
211 <funcdef>int
<function>sd_bus_creds_get_session
</function></funcdef>
212 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
213 <paramdef>const char **
<parameter>slice
</parameter></paramdef>
217 <funcdef>int
<function>sd_bus_creds_get_owner_uid
</function></funcdef>
218 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
219 <paramdef>uid_t *
<parameter>uid
</parameter></paramdef>
223 <funcdef>int
<function>sd_bus_creds_has_effective_cap
</function></funcdef>
224 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
225 <paramdef>int
<parameter>capability
</parameter></paramdef>
229 <funcdef>int
<function>sd_bus_creds_has_permitted_cap
</function></funcdef>
230 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
231 <paramdef>int
<parameter>capability
</parameter></paramdef>
235 <funcdef>int
<function>sd_bus_creds_has_inheritable_cap
</function></funcdef>
236 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
237 <paramdef>int
<parameter>capability
</parameter></paramdef>
241 <funcdef>int
<function>sd_bus_creds_has_bounding_cap
</function></funcdef>
242 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
243 <paramdef>int
<parameter>capability
</parameter></paramdef>
247 <funcdef>int
<function>sd_bus_creds_get_selinux_context
</function></funcdef>
248 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
249 <paramdef>const char **
<parameter>context
</parameter></paramdef>
253 <funcdef>int
<function>sd_bus_creds_get_audit_session_id
</function></funcdef>
254 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
255 <paramdef>uint32_t *
<parameter>sessionid
</parameter></paramdef>
259 <funcdef>int
<function>sd_bus_creds_get_audit_login_uid
</function></funcdef>
260 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
261 <paramdef>uid_t *
<parameter>loginuid
</parameter></paramdef>
265 <funcdef>int
<function>sd_bus_creds_get_tty
</function></funcdef>
266 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
267 <paramdef>const char **
<parameter>tty
</parameter></paramdef>
271 <funcdef>int
<function>sd_bus_creds_get_unique_name
</function></funcdef>
272 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
273 <paramdef>const char **
<parameter>name
</parameter></paramdef>
277 <funcdef>int
<function>sd_bus_creds_get_well_known_names
</function></funcdef>
278 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
279 <paramdef>char ***
<parameter>name
</parameter></paramdef>
283 <funcdef>int
<function>sd_bus_creds_get_description
</function></funcdef>
284 <paramdef>sd_bus_creds *
<parameter>c
</parameter></paramdef>
285 <paramdef>const char **
<parameter>name
</parameter></paramdef>
292 <title>Description
</title>
294 <para>These functions return information from an
295 <parameter>sd_bus_creds
</parameter> credential object. Credential
296 objects may be created with
297 <citerefentry><refentrytitle>sd_bus_creds_new_from_pid
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
298 in which case they describe the credentials of the process
299 identified by the specified PID, with
300 <citerefentry><refentrytitle>sd_bus_get_name_creds
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
301 in which case they describe the credentials of a bus peer
302 identified by the specified bus name, with
303 <citerefentry><refentrytitle>sd_bus_get_owner_creds
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
304 in which case they describe the credentials of the creator of a
306 <citerefentry><refentrytitle>sd_bus_message_get_creds
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
307 in which case they describe the credentials of the sender of the message.
</para>
309 <para><function>sd_bus_creds_get_pid()
</function> will retrieve
310 the PID (process identifier). Similar,
311 <function>sd_bus_creds_get_ppid()
</function> will retrieve the
312 parent PID. Note that PID
1 has no parent process, in which case
313 -ENXIO is returned.
</para>
315 <para><function>sd_bus_creds_get_tid()
</function> will retrieve the
316 TID (thread identifier).
</para>
318 <para><function>sd_bus_creds_get_uid()
</function> will retrieve
319 the numeric UID (user identifier). Similar,
320 <function>sd_bus_creds_get_euid()
</function> returns the effective
321 UID,
<function>sd_bus_creds_get_suid()
</function> the saved UID
322 and
<function>sd_bus_creds_get_fsuid()
</function> the file system
325 <para><function>sd_bus_creds_get_gid()
</function> will retrieve the
326 numeric GID (group identifier). Similar,
327 <function>sd_bus_creds_get_egid()
</function> returns the effective
328 GID,
<function>sd_bus_creds_get_sgid()
</function> the saved GID
329 and
<function>sd_bus_creds_get_fsgid()
</function> the file system
332 <para><function>sd_bus_creds_get_supplementary_gids()
</function>
333 will retrieve the supplementary GIDs list.
</para>
335 <para><function>sd_bus_creds_get_comm()
</function> will retrieve the
336 comm field (truncated name of the executable, as stored in
337 <filename>/proc/
<replaceable>pid
</replaceable>/comm
</filename>).
340 <para><function>sd_bus_creds_get_tid_comm()
</function> will retrieve
341 the comm field of the thread (as stored in
342 <filename>/proc/
<replaceable>pid
</replaceable>/task/
<replaceable>tid
</replaceable>/comm
</filename>).
345 <para><function>sd_bus_creds_get_exe()
</function> will retrieve
346 the path to the program executable (as stored in the
347 <filename>/proc/
<replaceable>pid
</replaceable>/exe
</filename>
348 link, but with
<literal> (deleted)
</literal> suffix removed). Note
349 that kernel threads do not have an executable path, in which case
350 -ENXIO is returned.
</para>
352 <para><function>sd_bus_creds_get_cmdline()
</function> will
353 retrieve an array of command line arguments (as stored in
354 <filename>/proc/
<replaceable>pid
</replaceable>/cmdline
</filename>). Note
355 that kernel threads do not have a command line, in which case
356 -ENXIO is returned.
</para>
358 <para><function>sd_bus_creds_get_cgroup()
</function> will retrieve
359 the cgroup path. See
<ulink
360 url=
"https://www.kernel.org/doc/Documentation/cgroups/cgroups.txt">cgroups.txt
</ulink>.
363 <para><function>sd_bus_creds_get_unit()
</function> will retrieve
364 the systemd unit name (in the system instance of systemd) that the
365 process is part of. See
366 <citerefentry><refentrytitle>systemd.unit
</refentrytitle><manvolnum>5</manvolnum></citerefentry>. For
367 processes that are not part of a unit returns -ENXIO.
370 <para><function>sd_bus_creds_get_user_unit()
</function> will
371 retrieve the systemd unit name (in the user instance of systemd)
372 that the process is part of. See
373 <citerefentry><refentrytitle>systemd.unit
</refentrytitle><manvolnum>5</manvolnum></citerefentry>. For
374 processes that are not part of a user unit returns -ENXIO.
377 <para><function>sd_bus_creds_get_slice()
</function> will retrieve
378 the systemd slice (a unit in the system instance of systemd) that
379 the process is part of. See
380 <citerefentry><refentrytitle>systemd.slice
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
383 <para><function>sd_bus_creds_get_session()
</function> will
384 retrieve the logind session that the process is part of. See
385 <citerefentry><refentrytitle>systemd-logind.service
</refentrytitle><manvolnum>8</manvolnum></citerefentry>. For
386 processes that are not part of a session returns -ENXIO.
389 <para><function>sd_bus_creds_get_owner_uid()
</function> will
390 retrieve the numeric UID (user identifier) of the user who owns
391 the session that the process is part of. See
392 <citerefentry><refentrytitle>systemd.slice
</refentrytitle><manvolnum>5</manvolnum></citerefentry>
393 For processes that are not part of a session returns -ENXIO.
396 <para><function>sd_bus_creds_has_effective_cap()
</function> will
397 check whether the capability specified by
398 <parameter>capability
</parameter> was set in the effective
399 capabilities mask. A positive return value means that is was
400 set, zero means that it was not set, and a negative return
401 value signifies an error. See
402 <citerefentry project='man-pages'
><refentrytitle>capabilities
</refentrytitle><manvolnum>7</manvolnum></citerefentry>
403 and
<varname>Capabilities=
</varname> and
404 <varname>CapabilityBoundingSet=
</varname> settings in
405 <citerefentry><refentrytitle>systemd.exec
</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
408 <para><function>sd_bus_creds_has_permitted_cap()
</function> is
409 similar to
<function>sd_bus_creds_has_effective_cap()
</function>,
410 but will check the permitted capabilities mask.
</para>
412 <para><function>sd_bus_creds_has_inheritable_cap()
</function> is
413 similar to
<function>sd_bus_creds_has_effective_cap()
</function>,
414 but will check the inheritable capabilities mask.
</para>
416 <para><function>sd_bus_creds_has_bounding_cap()
</function> is
417 similar to
<function>sd_bus_creds_has_effective_cap()
</function>,
418 but will check the bounding capabilities mask.
</para>
420 <para><function>sd_bus_creds_get_selinux_context()
</function> will
421 retrieve the SELinux security context (label) of the process.
</para>
423 <para><function>sd_bus_creds_get_audit_session_id()
</function>
424 will retrieve the audit session identifier of the process. Returns
425 -ENXIO for processes that are not part of an audit session.
</para>
427 <para><function>sd_bus_creds_get_audit_login_uid()
</function> will
428 retrieve the audit user login identifier (the identifier of the
429 user who is
"responsible" for the session). Returns -ENXIO for
430 processes that are not part of an audit session.
</para>
432 <para><function>sd_bus_creds_get_tty()
</function> will retrieve
433 the controlling TTY. Returns -ENXIO for processes that have no
434 controlling TTY.
</para>
436 <para><function>sd_bus_creds_get_unique_name()
</function> will
437 retrieve the D-Bus unique name. See
<ulink
438 url=
"http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus">The
439 D-Bus specification
</ulink>.
</para>
441 <para><function>sd_bus_creds_get_well_known_names()
</function> will
442 retrieve the set of D-Bus well-known names. See
<ulink
443 url=
"http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus">The
444 D-Bus specification
</ulink>.
</para>
446 <para><function>sd_bus_creds_get_description()
</function> will
447 retrieve a descriptive name of the bus connection of the
448 peer. This name is useful to discern multiple bus connections by
449 the same peer, and may be altered by the peer with the
450 <citerefentry><refentrytitle>sd_bus_set_description
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
453 <para>All functions that take a
<parameter>const
454 char**
</parameter> parameter will store the answer there as an
455 address of a NUL-terminated string. It will be valid as long as
456 <parameter>c
</parameter> remains valid, and should not be freed or
457 modified by the caller.
</para>
459 <para>All functions that take a
<parameter>char***
</parameter>
460 parameter will store the answer there as an address of a an array
461 of strings. Each individual string is NUL-terminated, and the
462 array is NULL-terminated as a whole. It will be valid as long as
463 <parameter>c
</parameter> remains valid, and should not be freed or
464 modified by the caller.
</para>
468 <title>Return Value
</title>
470 <para>On success, these calls return
0 or a positive integer. On
471 failure, these calls return a negative errno-style error code.
476 <title>Errors
</title>
478 <para>Returned errors may indicate the following problems:
</para>
482 <term><constant>-ENODATA
</constant></term>
484 <listitem><para>Given field is not available in the
485 credentials object
<parameter>c
</parameter>.
</para>
490 <term><constant>-ENXIO
</constant></term>
492 <listitem><para>Given field is not specified for the described
493 process or peer. This will be returned by
494 <function>sd_bus_get_unit()
</function>,
495 <function>sd_bus_get_user_unit()
</function>,
496 <function>sd_bus_get_slice()
</function>,
497 <function>sd_bus_get_session()
</function>, and
498 <function>sd_bus_get_owner_uid()
</function> if the process is
499 not part of a systemd system unit, systemd user unit, systemd
500 slice, or logind session. It will also be returned by
501 <function>sd_bus_creds_get_exe()
</function> and
502 <function>sd_bus_creds_get_cmdline()
</function> for kernel
503 threads (since these aren't started from an executable binary
504 or have a command line),
505 <function>sd_bus_creds_get_audit_session_id()
</function> and
506 <function>sd_bus_creds_get_audit_login_uid()
</function> when
507 the process is not part of an audit session, and
508 <function>sd_bus_creds_get_tty()
</function> if the process has
515 <term><constant>-EINVAL
</constant></term>
517 <listitem><para>Specified pointer parameter is
<constant>NULL
</constant>.
522 <term><constant>-ENOMEM
</constant></term>
524 <listitem><para>Memory allocation failed.
</para></listitem>
532 <para><function>sd_bus_open_user()
</function> and other functions
533 described here are available as a shared library, which can be
534 compiled and linked to with the
535 <constant>libsystemd
</constant> <citerefentry project='die-net'
><refentrytitle>pkg-config
</refentrytitle><manvolnum>1</manvolnum></citerefentry>
540 <title>See Also
</title>
543 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
544 <citerefentry><refentrytitle>sd-bus
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
545 <citerefentry><refentrytitle>fork
</refentrytitle><manvolnum>2</manvolnum></citerefentry>,
546 <citerefentry><refentrytitle>execve
</refentrytitle><manvolnum>2</manvolnum></citerefentry>,
547 <citerefentry project='man-pages'
><refentrytitle>credentials
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
548 <citerefentry project='man-pages'
><refentrytitle>free
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
549 <citerefentry project='man-pages'
><refentrytitle>proc
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
550 <citerefentry><refentrytitle>systemd.journal-fields
</refentrytitle><manvolnum>7</manvolnum></citerefentry>