chiark / gitweb /
add devuan build control files
[elogind.git] / man / sd_bus_creds_get_pid.xml
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
5 <!--
6   This file is part of elogind.
7
8   Copyright 2014 Zbigniew Jędrzejewski-Szmek
9
10   elogind is free software; you can redistribute it and/or modify it
11   under the terms of the GNU Lesser General Public License as published by
12   the Free Software Foundation; either version 2.1 of the License, or
13   (at your option) any later version.
14
15   elogind is distributed in the hope that it will be useful, but
16   WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18   Lesser General Public License for more details.
19
20   You should have received a copy of the GNU Lesser General Public License
21   along with elogind; If not, see <http://www.gnu.org/licenses/>.
22 -->
23
24 <refentry id="sd_bus_creds_get_pid">
25
26   <refentryinfo>
27     <title>sd_bus_creds_get_pid</title>
28     <productname>elogind</productname>
29
30     <authorgroup>
31       <author>
32         <contrib>A monkey with a typewriter</contrib>
33         <firstname>Zbigniew</firstname>
34         <surname>Jędrzejewski-Szmek</surname>
35         <email>zbyszek@in.waw.pl</email>
36       </author>
37     </authorgroup>
38   </refentryinfo>
39
40   <refmeta>
41     <refentrytitle>sd_bus_creds_get_pid</refentrytitle>
42     <manvolnum>3</manvolnum>
43   </refmeta>
44
45   <refnamediv>
46     <refname>sd_bus_creds_get_pid</refname>
47     <refname>sd_bus_creds_get_ppid</refname>
48     <refname>sd_bus_creds_get_tid</refname>
49     <refname>sd_bus_creds_get_uid</refname>
50     <refname>sd_bus_creds_get_euid</refname>
51     <refname>sd_bus_creds_get_suid</refname>
52     <refname>sd_bus_creds_get_fsuid</refname>
53     <refname>sd_bus_creds_get_gid</refname>
54     <refname>sd_bus_creds_get_egid</refname>
55     <refname>sd_bus_creds_get_sgid</refname>
56     <refname>sd_bus_creds_get_fsgid</refname>
57     <refname>sd_bus_creds_get_supplementary_gids</refname>
58     <refname>sd_bus_creds_get_comm</refname>
59     <refname>sd_bus_creds_get_tid_comm</refname>
60     <refname>sd_bus_creds_get_exe</refname>
61     <refname>sd_bus_creds_get_cmdline</refname>
62     <refname>sd_bus_creds_get_cgroup</refname>
63     <refname>sd_bus_creds_get_session</refname>
64     <refname>sd_bus_creds_get_owner_uid</refname>
65     <refname>sd_bus_creds_has_effective_cap</refname>
66     <refname>sd_bus_creds_has_permitted_cap</refname>
67     <refname>sd_bus_creds_has_inheritable_cap</refname>
68     <refname>sd_bus_creds_has_bounding_cap</refname>
69     <refname>sd_bus_creds_get_selinux_context</refname>
70     <refname>sd_bus_creds_get_audit_session_id</refname>
71     <refname>sd_bus_creds_get_audit_login_uid</refname>
72     <refname>sd_bus_creds_get_tty</refname>
73     <refname>sd_bus_creds_get_unique_name</refname>
74     <refname>sd_bus_creds_get_well_known_names</refname>
75     <refname>sd_bus_creds_get_description</refname>
76
77     <refpurpose>Retrieve fields from a credentials object</refpurpose>
78   </refnamediv>
79
80   <refsynopsisdiv>
81     <funcsynopsis>
82       <funcsynopsisinfo>#include &lt;elogind/sd-bus.h&gt;</funcsynopsisinfo>
83
84       <funcprototype>
85         <funcdef>int <function>sd_bus_creds_get_pid</function></funcdef>
86         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
87         <paramdef>pid_t *<parameter>pid</parameter></paramdef>
88       </funcprototype>
89
90       <funcprototype>
91         <funcdef>int <function>sd_bus_creds_get_ppid</function></funcdef>
92         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
93         <paramdef>pid_t *<parameter>ppid</parameter></paramdef>
94       </funcprototype>
95
96       <funcprototype>
97         <funcdef>int <function>sd_bus_creds_get_tid</function></funcdef>
98         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
99         <paramdef>pid_t *<parameter>tid</parameter></paramdef>
100       </funcprototype>
101
102       <funcprototype>
103         <funcdef>int <function>sd_bus_creds_get_uid</function></funcdef>
104         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
105         <paramdef>uid_t *<parameter>uid</parameter></paramdef>
106       </funcprototype>
107
108       <funcprototype>
109         <funcdef>int <function>sd_bus_creds_get_euid</function></funcdef>
110         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
111         <paramdef>uid_t *<parameter>uid</parameter></paramdef>
112       </funcprototype>
113
114       <funcprototype>
115         <funcdef>int <function>sd_bus_creds_get_suid</function></funcdef>
116         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
117         <paramdef>uid_t *<parameter>uid</parameter></paramdef>
118       </funcprototype>
119
120       <funcprototype>
121         <funcdef>int <function>sd_bus_creds_get_fsuid</function></funcdef>
122         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
123         <paramdef>uid_t *<parameter>uid</parameter></paramdef>
124       </funcprototype>
125
126       <funcprototype>
127         <funcdef>int <function>sd_bus_creds_get_gid</function></funcdef>
128         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
129         <paramdef>gid_t *<parameter>gid</parameter></paramdef>
130       </funcprototype>
131
132       <funcprototype>
133         <funcdef>int <function>sd_bus_creds_get_egid</function></funcdef>
134         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
135         <paramdef>gid_t *<parameter>gid</parameter></paramdef>
136       </funcprototype>
137
138       <funcprototype>
139         <funcdef>int <function>sd_bus_creds_get_sgid</function></funcdef>
140         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
141         <paramdef>gid_t *<parameter>gid</parameter></paramdef>
142       </funcprototype>
143
144       <funcprototype>
145         <funcdef>int <function>sd_bus_creds_get_fsgid</function></funcdef>
146         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
147         <paramdef>gid_t *<parameter>gid</parameter></paramdef>
148       </funcprototype>
149
150       <funcprototype>
151         <funcdef>int <function>sd_bus_creds_get_supplementary_gids</function></funcdef>
152         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
153         <paramdef>const gid_t **<parameter>gids</parameter></paramdef>
154       </funcprototype>
155
156       <funcprototype>
157         <funcdef>int <function>sd_bus_creds_get_comm</function></funcdef>
158         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
159         <paramdef>const char **<parameter>comm</parameter></paramdef>
160       </funcprototype>
161
162       <funcprototype>
163         <funcdef>int <function>sd_bus_creds_get_tid_comm</function></funcdef>
164         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
165         <paramdef>const char **<parameter>comm</parameter></paramdef>
166       </funcprototype>
167
168       <funcprototype>
169         <funcdef>int <function>sd_bus_creds_get_exe</function></funcdef>
170         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
171         <paramdef>const char **<parameter>exe</parameter></paramdef>
172       </funcprototype>
173
174       <funcprototype>
175         <funcdef>int <function>sd_bus_creds_get_cmdline</function></funcdef>
176         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
177         <paramdef>char ***<parameter>cmdline</parameter></paramdef>
178       </funcprototype>
179
180       <funcprototype>
181         <funcdef>int <function>sd_bus_creds_get_cgroup</function></funcdef>
182         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
183         <paramdef>const char **<parameter>cgroup</parameter></paramdef>
184       </funcprototype>
185
186       <funcprototype>
187         <funcdef>int <function>sd_bus_creds_get_session</function></funcdef>
188         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
189         <paramdef>const char **<parameter>slice</parameter></paramdef>
190       </funcprototype>
191
192       <funcprototype>
193         <funcdef>int <function>sd_bus_creds_get_owner_uid</function></funcdef>
194         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
195         <paramdef>uid_t *<parameter>uid</parameter></paramdef>
196       </funcprototype>
197
198       <funcprototype>
199         <funcdef>int <function>sd_bus_creds_has_effective_cap</function></funcdef>
200         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
201         <paramdef>int <parameter>capability</parameter></paramdef>
202       </funcprototype>
203
204       <funcprototype>
205         <funcdef>int <function>sd_bus_creds_has_permitted_cap</function></funcdef>
206         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
207         <paramdef>int <parameter>capability</parameter></paramdef>
208       </funcprototype>
209
210       <funcprototype>
211         <funcdef>int <function>sd_bus_creds_has_inheritable_cap</function></funcdef>
212         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
213         <paramdef>int <parameter>capability</parameter></paramdef>
214       </funcprototype>
215
216       <funcprototype>
217         <funcdef>int <function>sd_bus_creds_has_bounding_cap</function></funcdef>
218         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
219         <paramdef>int <parameter>capability</parameter></paramdef>
220       </funcprototype>
221
222       <funcprototype>
223         <funcdef>int <function>sd_bus_creds_get_selinux_context</function></funcdef>
224         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
225         <paramdef>const char **<parameter>context</parameter></paramdef>
226       </funcprototype>
227
228       <funcprototype>
229         <funcdef>int <function>sd_bus_creds_get_audit_session_id</function></funcdef>
230         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
231         <paramdef>uint32_t *<parameter>sessionid</parameter></paramdef>
232       </funcprototype>
233
234       <funcprototype>
235         <funcdef>int <function>sd_bus_creds_get_audit_login_uid</function></funcdef>
236         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
237         <paramdef>uid_t *<parameter>loginuid</parameter></paramdef>
238       </funcprototype>
239
240       <funcprototype>
241         <funcdef>int <function>sd_bus_creds_get_tty</function></funcdef>
242         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
243         <paramdef>const char **<parameter>tty</parameter></paramdef>
244       </funcprototype>
245
246       <funcprototype>
247         <funcdef>int <function>sd_bus_creds_get_unique_name</function></funcdef>
248         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
249         <paramdef>const char **<parameter>name</parameter></paramdef>
250       </funcprototype>
251
252       <funcprototype>
253         <funcdef>int <function>sd_bus_creds_get_well_known_names</function></funcdef>
254         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
255         <paramdef>char ***<parameter>name</parameter></paramdef>
256       </funcprototype>
257
258       <funcprototype>
259         <funcdef>int <function>sd_bus_creds_get_description</function></funcdef>
260         <paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
261         <paramdef>const char **<parameter>name</parameter></paramdef>
262       </funcprototype>
263
264     </funcsynopsis>
265   </refsynopsisdiv>
266
267   <refsect1>
268     <title>Description</title>
269
270     <para>These functions return credential information from an
271     <parameter>sd_bus_creds</parameter> object. Credential objects may
272     be created with
273     <citerefentry><refentrytitle>sd_bus_creds_new_from_pid</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
274     in which case they describe the credentials of the process
275     identified by the specified PID, with
276     <citerefentry><refentrytitle>sd_bus_get_name_creds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
277     in which case they describe the credentials of a bus peer
278     identified by the specified bus name, with
279     <citerefentry><refentrytitle>sd_bus_get_owner_creds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
280     in which case they describe the credentials of the creator of a
281     bus, or with
282     <citerefentry><refentrytitle>sd_bus_message_get_creds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
283     in which case they describe the credentials of the sender of the
284     message.</para>
285
286     <para>Not all credential fields are part of every
287     <literal>sd_bus_creds</literal> object. Use
288     <citerefentry><refentrytitle>sd_bus_creds_get_mask</refentrytitle><manvolnum>3</manvolnum></citerefentry>
289     to determine the mask of fields available.</para>
290
291     <para><function>sd_bus_creds_get_pid()</function> will retrieve
292     the PID (process identifier). Similarly,
293     <function>sd_bus_creds_get_ppid()</function> will retrieve the
294     parent PID. Note that PID 1 has no parent process, in which case
295     -ENXIO is returned.</para>
296
297     <para><function>sd_bus_creds_get_tid()</function> will retrieve the
298     TID (thread identifier).</para>
299
300     <para><function>sd_bus_creds_get_uid()</function> will retrieve
301     the numeric UID (user identifier). Similarly,
302     <function>sd_bus_creds_get_euid()</function> returns the effective
303     UID, <function>sd_bus_creds_get_suid()</function> the saved UID
304     and <function>sd_bus_creds_get_fsuid()</function> the file system
305     UID.</para>
306
307     <para><function>sd_bus_creds_get_gid()</function> will retrieve the
308     numeric GID (group identifier). Similarly,
309     <function>sd_bus_creds_get_egid()</function> returns the effective
310     GID, <function>sd_bus_creds_get_sgid()</function> the saved GID
311     and <function>sd_bus_creds_get_fsgid()</function> the file system
312     GID.</para>
313
314     <para><function>sd_bus_creds_get_supplementary_gids()</function>
315     will retrieve the supplementary GIDs list.</para>
316
317     <para><function>sd_bus_creds_get_comm()</function> will retrieve the
318     comm field (truncated name of the executable, as stored in
319     <filename>/proc/<replaceable>pid</replaceable>/comm</filename>).
320     </para>
321
322     <para><function>sd_bus_creds_get_tid_comm()</function> will retrieve
323     the comm field of the thread (as stored in
324     <filename>/proc/<replaceable>pid</replaceable>/task/<replaceable>tid</replaceable>/comm</filename>).
325     </para>
326
327     <para><function>sd_bus_creds_get_exe()</function> will retrieve
328     the path to the program executable (as stored in the
329     <filename>/proc/<replaceable>pid</replaceable>/exe</filename>
330     link, but with the <literal> (deleted)</literal> suffix removed). Note
331     that kernel threads do not have an executable path, in which case
332     -ENXIO is returned.</para>
333
334     <para><function>sd_bus_creds_get_cmdline()</function> will
335     retrieve an array of command line arguments (as stored in
336     <filename>/proc/<replaceable>pid</replaceable>/cmdline</filename>). Note
337     that kernel threads do not have a command line, in which case
338     -ENXIO is returned.</para>
339
340     <para><function>sd_bus_creds_get_cgroup()</function> will retrieve
341     the cgroup path. See <ulink
342     url="https://www.kernel.org/doc/Documentation/cgroups/cgroups.txt">cgroups.txt</ulink>.
343     </para>
344
345     <para><function>sd_bus_creds_get_session()</function> will
346     retrieve the identifier of the login session that the process is
347     a part of. See
348     <citerefentry><refentrytitle>elogind-logind.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>. For
349     processes that are not part of a session, returns -ENXIO.
350     </para>
351
352     <para><function>sd_bus_creds_get_owner_uid()</function> will
353     retrieve the numeric UID (user identifier) of the user who owns
354     the login session that the process is a part of. See
355     <citerefentry><refentrytitle>elogind-logind.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
356     For processes that are not part of a session, returns -ENXIO.
357     </para>
358
359     <para><function>sd_bus_creds_has_effective_cap()</function> will
360     check whether the capability specified by
361     <parameter>capability</parameter> was set in the effective
362     capabilities mask. A positive return value means that is was
363     set, zero means that it was not set, and a negative return
364     value indicates an error. See
365     <citerefentry project='man-pages'><refentrytitle>capabilities</refentrytitle><manvolnum>7</manvolnum></citerefentry>
366     and <varname>Capabilities=</varname> and
367     <varname>CapabilityBoundingSet=</varname> settings in
368     <citerefentry><refentrytitle>elogind.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
369     </para>
370
371     <para><function>sd_bus_creds_has_permitted_cap()</function> is
372     similar to <function>sd_bus_creds_has_effective_cap()</function>,
373     but will check the permitted capabilities mask.</para>
374
375     <para><function>sd_bus_creds_has_inheritable_cap()</function> is
376     similar to <function>sd_bus_creds_has_effective_cap()</function>,
377     but will check the inheritable capabilities mask.</para>
378
379     <para><function>sd_bus_creds_has_bounding_cap()</function> is
380     similar to <function>sd_bus_creds_has_effective_cap()</function>,
381     but will check the bounding capabilities mask.</para>
382
383     <para><function>sd_bus_creds_get_selinux_context()</function> will
384     retrieve the SELinux security context (label) of the process.</para>
385
386     <para><function>sd_bus_creds_get_audit_session_id()</function>
387     will retrieve the audit session identifier of the process. Returns
388     -ENXIO for processes that are not part of an audit session.</para>
389
390     <para><function>sd_bus_creds_get_audit_login_uid()</function> will
391     retrieve the audit user login identifier (the identifier of the
392     user who is "responsible" for the session). Returns -ENXIO for
393     processes that are not part of an audit session.</para>
394
395     <para><function>sd_bus_creds_get_tty()</function> will retrieve
396     the controlling TTY, without the prefixing "/dev/". Returns -ENXIO
397     for processes that have no controlling TTY.</para>
398
399     <para><function>sd_bus_creds_get_unique_name()</function> will
400     retrieve the D-Bus unique name. See <ulink
401     url="http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus">The
402     D-Bus specification</ulink>.</para>
403
404     <para><function>sd_bus_creds_get_well_known_names()</function> will
405     retrieve the set of D-Bus well-known names. See <ulink
406     url="http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus">The
407     D-Bus specification</ulink>.</para>
408
409     <para><function>sd_bus_creds_get_description()</function> will
410     retrieve a descriptive name of the bus connection of the
411     peer. This name is useful to discern multiple bus connections by
412     the same peer, and may be altered by the peer with the
413     <citerefentry><refentrytitle>sd_bus_set_description</refentrytitle><manvolnum>3</manvolnum></citerefentry>
414     call.</para>
415
416     <para>All functions that take a <parameter>const
417     char**</parameter> parameter will store the answer there as an
418     address of a NUL-terminated string. It will be valid as long as
419     <parameter>c</parameter> remains valid, and should not be freed or
420     modified by the caller.</para>
421
422     <para>All functions that take a <parameter>char***</parameter>
423     parameter will store the answer there as an address of an array
424     of strings. Each individual string is NUL-terminated, and the
425     array is NULL-terminated as a whole. It will be valid as long as
426     <parameter>c</parameter> remains valid, and should not be freed or
427     modified by the caller.</para>
428   </refsect1>
429
430   <refsect1>
431     <title>Return Value</title>
432
433     <para>On success, these calls return 0 or a positive integer. On
434     failure, these calls return a negative errno-style error code.
435     </para>
436   </refsect1>
437
438   <refsect1>
439     <title>Errors</title>
440
441     <para>Returned errors may indicate the following problems:</para>
442
443     <variablelist>
444       <varlistentry>
445         <term><constant>-ENODATA</constant></term>
446
447         <listitem><para>The given field is not available in the
448         credentials object <parameter>c</parameter>.</para>
449         </listitem>
450       </varlistentry>
451
452       <varlistentry>
453         <term><constant>-ENXIO</constant></term>
454
455         <listitem><para>The given field is not specified for the described
456         process or peer. This will be returned by
457         <function>sd_bus_get_session()</function>, and
458         <function>sd_bus_get_owner_uid()</function> if the process is
459         not part of a elogind system unit, systemd user unit, systemd
460         slice, or logind session. It will also be returned by
461         <function>sd_bus_creds_get_exe()</function> and
462         <function>sd_bus_creds_get_cmdline()</function> for kernel
463         threads (since these are not started from an executable binary,
464         nor have a command line), and by
465         <function>sd_bus_creds_get_audit_session_id()</function> and
466         <function>sd_bus_creds_get_audit_login_uid()</function> when
467         the process is not part of an audit session, and
468         <function>sd_bus_creds_get_tty()</function> if the process has
469         no controlling TTY.
470         </para>
471         </listitem>
472       </varlistentry>
473
474       <varlistentry>
475         <term><constant>-EINVAL</constant></term>
476
477         <listitem><para>Specified pointer parameter is <constant>NULL</constant>.
478         </para></listitem>
479       </varlistentry>
480
481       <varlistentry>
482         <term><constant>-ENOMEM</constant></term>
483
484         <listitem><para>Memory allocation failed.</para></listitem>
485       </varlistentry>
486     </variablelist>
487   </refsect1>
488
489   <refsect1>
490     <title>Notes</title>
491
492     <para><function>sd_bus_creds_get_pid()</function> and the other
493     functions described here are available as a shared library, which
494     can be compiled and linked to with the
495     <constant>libelogind</constant> <citerefentry
496     project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
497     file.</para>
498   </refsect1>
499
500   <refsect1>
501     <title>See Also</title>
502
503     <para>
504       <citerefentry><refentrytitle>elogind</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
505       <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
506       <citerefentry><refentrytitle>sd_bus_creds_new_from_pid</refentrytitle><manvolnum>2</manvolnum></citerefentry>,
507       <citerefentry project='man-pages'><refentrytitle>fork</refentrytitle><manvolnum>2</manvolnum></citerefentry>,
508       <citerefentry project='man-pages'><refentrytitle>execve</refentrytitle><manvolnum>2</manvolnum></citerefentry>,
509       <citerefentry project='man-pages'><refentrytitle>credentials</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
510       <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
511       <citerefentry project='man-pages'><refentrytitle>proc</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
512       <citerefentry><refentrytitle>elogind.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>
513     </para>
514   </refsect1>
515
516 </refentry>