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