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