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