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