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