]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_id128_get_machine.xml
tree-wide: remove Lennart's copyright lines
[thirdparty/systemd.git] / man / sd_id128_get_machine.xml
1 <?xml version='1.0'?> <!--*-nxml-*-->
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 SPDX-License-Identifier: LGPL-2.1+
7 -->
8
9 <refentry id="sd_id128_get_machine" xmlns:xi="http://www.w3.org/2001/XInclude">
10
11 <refentryinfo>
12 <title>sd_id128_get_machine</title>
13 <productname>systemd</productname>
14
15 <authorgroup>
16 <author>
17 <contrib>Developer</contrib>
18 <firstname>Lennart</firstname>
19 <surname>Poettering</surname>
20 <email>lennart@poettering.net</email>
21 </author>
22 </authorgroup>
23 </refentryinfo>
24
25 <refmeta>
26 <refentrytitle>sd_id128_get_machine</refentrytitle>
27 <manvolnum>3</manvolnum>
28 </refmeta>
29
30 <refnamediv>
31 <refname>sd_id128_get_machine</refname>
32 <refname>sd_id128_get_machine_app_specific</refname>
33 <refname>sd_id128_get_boot</refname>
34 <refname>sd_id128_get_invocation</refname>
35 <refpurpose>Retrieve 128-bit IDs</refpurpose>
36 </refnamediv>
37
38 <refsynopsisdiv>
39 <funcsynopsis>
40 <funcsynopsisinfo>#include &lt;systemd/sd-id128.h&gt;</funcsynopsisinfo>
41
42 <funcprototype>
43 <funcdef>int <function>sd_id128_get_machine</function></funcdef>
44 <paramdef>sd_id128_t *<parameter>ret</parameter></paramdef>
45 </funcprototype>
46
47 <funcprototype>
48 <funcdef>int <function>sd_id128_get_machine_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
53 <funcprototype>
54 <funcdef>int <function>sd_id128_get_boot</function></funcdef>
55 <paramdef>sd_id128_t *<parameter>ret</parameter></paramdef>
56 </funcprototype>
57
58 <funcprototype>
59 <funcdef>int <function>sd_id128_get_invocation</function></funcdef>
60 <paramdef>sd_id128_t *<parameter>ret</parameter></paramdef>
61 </funcprototype>
62
63 </funcsynopsis>
64 </refsynopsisdiv>
65
66 <refsect1>
67 <title>Description</title>
68
69 <para><function>sd_id128_get_machine()</function> returns the machine ID of the executing host. This reads and
70 parses the <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>
71 file. This function caches the machine ID internally to make retrieving the machine ID a cheap operation. This ID
72 may be used wherever a unique identifier for the local system is needed. However, it is recommended to use this ID
73 as-is only in trusted environments. In untrusted environments it is recommended to derive an application specific
74 ID from this machine ID, in an irreversable (cryptographically secure) way. To make this easy
75 <function>sd_id128_get_machine_app_specific()</function> is provided, see below.</para>
76
77 <para><function>sd_id128_get_machine_app_specific()</function> is similar to
78 <function>sd_id128_get_machine()</function>, but retrieves a machine ID that is specific to the application that is
79 identified by the indicated application ID. It is recommended to use this function instead of
80 <function>sd_id128_get_machine()</function> when passing an ID to untrusted environments, in order to make sure
81 that the original machine ID may not be determined externally. The application-specific ID should be generated via
82 a tool like <command>journalctl --new-id128</command>, and may be compiled into the application. This function will
83 return the same application-specific ID for each combination of machine ID and application ID. Internally, this
84 function calculates HMAC-SHA256 of the application ID, keyed by the machine ID.</para>
85
86 <para><function>sd_id128_get_boot()</function> returns the boot ID
87 of the executing kernel. This reads and parses the
88 <filename>/proc/sys/kernel/random/boot_id</filename> file exposed
89 by the kernel. It is randomly generated early at boot and is
90 unique for every running kernel instance. See
91 <citerefentry project='man-pages'><refentrytitle>random</refentrytitle><manvolnum>4</manvolnum></citerefentry>
92 for more information. This function also internally caches the
93 returned ID to make this call a cheap operation.</para>
94
95 <para><function>sd_id128_get_invocation()</function> returns the invocation ID of the currently executed
96 service. In its current implementation, this reads and parses the <varname>$INVOCATION_ID</varname> environment
97 variable that the service manager sets when activating a service, see
98 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for details. The
99 ID is cached internally. In future a different mechanism to determine the invocation ID may be added.</para>
100
101 <para>Note that <function>sd_id128_get_machine_app_specific()</function>, <function>sd_id128_get_boot()</function>
102 and <function>sd_id128_get_invocation()</function> always return UUID v4 compatible IDs.
103 <function>sd_id128_get_machine()</function> will also return a UUID v4-compatible ID on new installations but might
104 not on older. It is possible to convert the machine ID into a UUID v4-compatible one. For more information, see
105 <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
106
107 <para>For more information about the <literal>sd_id128_t</literal>
108 type see
109 <citerefentry><refentrytitle>sd-id128</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
110 </refsect1>
111
112 <refsect1>
113 <title>Return Value</title>
114
115 <para>Those calls return 0 on success (in which case <parameter>ret</parameter> is filled in),
116 or a negative errno-style error code. In particular, <function>sd_id128_get_machine()</function>
117 and <function>sd_id128_get_machine_app_specific()</function> return <constant>-ENOENT</constant>
118 if <filename>/etc/machine-id</filename> is missing, and <constant>-ENOMEDIUM</constant> if is
119 empty or all zeros.</para>
120 </refsect1>
121
122 <xi:include href="libsystemd-pkgconfig.xml" />
123
124 <refsect1>
125 <title>Examples</title>
126
127 <example>
128 <title>Application-specific machine ID</title>
129
130 <para>Here's a simple example for an application specific machine ID:</para>
131
132 <programlisting>#include &lt;systemd/sd-id128.h&gt;
133 #include &lt;stdio.h&gt;
134
135 #define OUR_APPLICATION_ID SD_ID128_MAKE(c2,73,27,73,23,db,45,4e,a6,3b,b9,6e,79,b5,3e,97)
136
137 int main(int argc, char *argv[]) {
138 sd_id128_t id;
139 sd_id128_get_machine_app_specific(OUR_APPLICATION_ID, &amp;id);
140 printf("Our application ID: " SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(id));
141 return 0;
142 }</programlisting>
143 </example>
144 </refsect1>
145
146 <refsect1>
147 <title>See Also</title>
148
149 <para>
150 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
151 <citerefentry><refentrytitle>sd-id128</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
152 <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
153 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
154 <citerefentry><refentrytitle>sd_id128_randomize</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
155 <citerefentry project='man-pages'><refentrytitle>random</refentrytitle><manvolnum>4</manvolnum></citerefentry>
156 </para>
157 </refsect1>
158
159 </refentry>