]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_id128_get_machine.xml
sd-id128: look for invocation id in environment first, keyring second
[thirdparty/systemd.git] / man / sd_id128_get_machine.xml
CommitLineData
a4023a43 1<?xml version='1.0'?> <!--*-nxml-*-->
3a54a157 2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
12b42c76 3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
0307f791 4<!-- SPDX-License-Identifier: LGPL-2.1+ -->
a4023a43 5
7d6b2723 6<refentry id="sd_id128_get_machine" xmlns:xi="http://www.w3.org/2001/XInclude">
a4023a43 7
798d3a52
ZJS
8 <refentryinfo>
9 <title>sd_id128_get_machine</title>
10 <productname>systemd</productname>
798d3a52
ZJS
11 </refentryinfo>
12
13 <refmeta>
14 <refentrytitle>sd_id128_get_machine</refentrytitle>
15 <manvolnum>3</manvolnum>
16 </refmeta>
17
18 <refnamediv>
19 <refname>sd_id128_get_machine</refname>
70fc4f57 20 <refname>sd_id128_get_machine_app_specific</refname>
798d3a52 21 <refname>sd_id128_get_boot</refname>
65d410c7 22 <refname>sd_id128_get_boot_app_specific</refname>
4b58153d 23 <refname>sd_id128_get_invocation</refname>
798d3a52
ZJS
24 <refpurpose>Retrieve 128-bit IDs</refpurpose>
25 </refnamediv>
26
27 <refsynopsisdiv>
28 <funcsynopsis>
29 <funcsynopsisinfo>#include &lt;systemd/sd-id128.h&gt;</funcsynopsisinfo>
30
31 <funcprototype>
32 <funcdef>int <function>sd_id128_get_machine</function></funcdef>
33 <paramdef>sd_id128_t *<parameter>ret</parameter></paramdef>
34 </funcprototype>
35
70fc4f57
LP
36 <funcprototype>
37 <funcdef>int <function>sd_id128_get_machine_app_specific</function></funcdef>
38 <paramdef>sd_id128_t <parameter>app_id</parameter></paramdef>
39 <paramdef>sd_id128_t *<parameter>ret</parameter></paramdef>
40 </funcprototype>
41
798d3a52
ZJS
42 <funcprototype>
43 <funcdef>int <function>sd_id128_get_boot</function></funcdef>
44 <paramdef>sd_id128_t *<parameter>ret</parameter></paramdef>
45 </funcprototype>
46
65d410c7
ZJS
47 <funcprototype>
48 <funcdef>int <function>sd_id128_get_boot_app_specific</function></funcdef>
49 <paramdef>sd_id128_t <parameter>app_id</parameter></paramdef>
50 <paramdef>sd_id128_t *<parameter>ret</parameter></paramdef>
51 </funcprototype>
52
4b58153d
LP
53 <funcprototype>
54 <funcdef>int <function>sd_id128_get_invocation</function></funcdef>
55 <paramdef>sd_id128_t *<parameter>ret</parameter></paramdef>
56 </funcprototype>
57
798d3a52
ZJS
58 </funcsynopsis>
59 </refsynopsisdiv>
60
61 <refsect1>
62 <title>Description</title>
63
70fc4f57
LP
64 <para><function>sd_id128_get_machine()</function> returns the machine ID of the executing host. This reads and
65 parses the <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>
66 file. This function caches the machine ID internally to make retrieving the machine ID a cheap operation. This ID
67 may be used wherever a unique identifier for the local system is needed. However, it is recommended to use this ID
68 as-is only in trusted environments. In untrusted environments it is recommended to derive an application specific
69 ID from this machine ID, in an irreversable (cryptographically secure) way. To make this easy
70 <function>sd_id128_get_machine_app_specific()</function> is provided, see below.</para>
71
72 <para><function>sd_id128_get_machine_app_specific()</function> is similar to
73 <function>sd_id128_get_machine()</function>, but retrieves a machine ID that is specific to the application that is
74 identified by the indicated application ID. It is recommended to use this function instead of
75 <function>sd_id128_get_machine()</function> when passing an ID to untrusted environments, in order to make sure
65d410c7
ZJS
76 that the original machine ID may not be determined externally. This way, the ID used by the application remains
77 stable on a given machine, but cannot be easily correlated with IDs used in other applications on the same
0d1d512f 78 machine. The application-specific ID should be generated via a tool like <command>systemd-id128 new</command>,
65d410c7
ZJS
79 and may be compiled into the application. This function will return the same application-specific ID for each
80 combination of machine ID and application ID. Internally, this function calculates HMAC-SHA256 of the application
81 ID, keyed by the machine ID.</para>
82
83 <para><function>sd_id128_get_boot()</function> returns the boot ID of the executing kernel. This reads and parses
84 the <filename>/proc/sys/kernel/random/boot_id</filename> file exposed by the kernel. It is randomly generated early
85 at boot and is unique for every running kernel instance. See <citerefentry
86 project='man-pages'><refentrytitle>random</refentrytitle><manvolnum>4</manvolnum></citerefentry> for more
87 information. This function also internally caches the returned ID to make this call a cheap operation. It is
88 recommended to use this ID as-is only in trusted environments. In untrusted environments it is recommended to
89 derive an application specific ID using <function>sd_id128_get_machine_app_specific()</function>, see below.</para>
90
91 <para><function>sd_id128_get_boot_app_specific()</function> is analogous to
92 <function>sd_id128_get_machine_app_specific()</function> but returns an ID that changes between boots. Some
93 machines may be used for a long time without rebooting, hence the boot ID may remain constant for a long time, and
94 has properties similar to the machine ID during that time.</para>
798d3a52 95
4b58153d
LP
96 <para><function>sd_id128_get_invocation()</function> returns the invocation ID of the currently executed
97 service. In its current implementation, this reads and parses the <varname>$INVOCATION_ID</varname> environment
98 variable that the service manager sets when activating a service, see
99 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for details. The
100 ID is cached internally. In future a different mechanism to determine the invocation ID may be added.</para>
101
65d410c7
ZJS
102 <para>Note that <function>sd_id128_get_machine_app_specific()</function>, <function>sd_id128_get_boot()</function>,
103 <function>sd_id128_get_boot_app_specific()</function>, and <function>sd_id128_get_invocation()</function> always
104 return UUID v4 compatible IDs. <function>sd_id128_get_machine()</function> will also return a UUID v4-compatible
105 ID on new installations but might not on older. It is possible to convert the machine ID into a UUID v4-compatible
106 one. For more information, see
798d3a52
ZJS
107 <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
108
109 <para>For more information about the <literal>sd_id128_t</literal>
110 type see
111 <citerefentry><refentrytitle>sd-id128</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
112 </refsect1>
113
114 <refsect1>
115 <title>Return Value</title>
116
ea03f6ba 117 <para>Those calls return 0 on success (in which case <parameter>ret</parameter> is filled in),
65d410c7
ZJS
118 or a negative errno-style error code. In particular,
119 <function>sd_id128_get_machine()</function>,
120 <function>sd_id128_get_machine_app_specific()</function>, and
121 <function>sd_id128_get_boot_app_specific()</function> return <constant>-ENOENT</constant> if
850115b3
JH
122 <filename>/etc/machine-id</filename> is missing, and <constant>-ENOMEDIUM</constant> if
123 <filename>/etc/machine-id</filename> is empty or all zeros.</para>
798d3a52
ZJS
124 </refsect1>
125
7d6b2723 126 <xi:include href="libsystemd-pkgconfig.xml" />
798d3a52 127
70fc4f57
LP
128 <refsect1>
129 <title>Examples</title>
130
131 <example>
132 <title>Application-specific machine ID</title>
133
adda90b0
ZJS
134 <para>First, generate the application ID:</para>
135 <programlisting>$ systemd-id128 -p new
136As string:
137c273277323db454ea63bb96e79b53e97
138
139As UUID:
140c2732773-23db-454e-a63b-b96e79b53e97
141
142As man:sd-id128(3) macro:
143#define MESSAGE_XYZ SD_ID128_MAKE(c2,73,27,73,23,db,45,4e,a6,3b,b9,6e,79,b5,3e,97)
144...
145</programlisting>
146
147 <para>Then use the new identifier in an example application:</para>
70fc4f57 148
787f78b6 149 <programlisting><xi:include href="id128-app-specific.c" parse="text" /></programlisting>
70fc4f57
LP
150 </example>
151 </refsect1>
152
798d3a52
ZJS
153 <refsect1>
154 <title>See Also</title>
155
156 <para>
157 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
0d1d512f 158 <citerefentry><refentrytitle>systemd-id128</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
798d3a52
ZJS
159 <citerefentry><refentrytitle>sd-id128</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
160 <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
4b58153d
LP
161 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
162 <citerefentry><refentrytitle>sd_id128_randomize</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
163 <citerefentry project='man-pages'><refentrytitle>random</refentrytitle><manvolnum>4</manvolnum></citerefentry>
798d3a52
ZJS
164 </para>
165 </refsect1>
a4023a43
LP
166
167</refentry>