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