1SD_ID128_GET_MACHINE(3)      sd_id128_get_machine      SD_ID128_GET_MACHINE(3)
2
3
4

NAME

6       sd_id128_get_machine, sd_id128_get_machine_app_specific,
7       sd_id128_get_boot, sd_id128_get_boot_app_specific,
8       sd_id128_get_invocation - Retrieve 128-bit IDs
9

SYNOPSIS

11       #include <systemd/sd-id128.h>
12
13       int sd_id128_get_machine(sd_id128_t *ret);
14
15       int sd_id128_get_machine_app_specific(sd_id128_t app_id,
16                                             sd_id128_t *ret);
17
18       int sd_id128_get_boot(sd_id128_t *ret);
19
20       int sd_id128_get_boot_app_specific(sd_id128_t app_id, sd_id128_t *ret);
21
22       int sd_id128_get_invocation(sd_id128_t *ret);
23

DESCRIPTION

25       sd_id128_get_machine() returns the machine ID of the executing host.
26       This reads and parses the machine-id(5) file. This function caches the
27       machine ID internally to make retrieving the machine ID a cheap
28       operation. This ID may be used wherever a unique identifier for the
29       local system is needed. However, it is recommended to use this ID as-is
30       only in trusted environments. In untrusted environments it is
31       recommended to derive an application specific ID from this machine ID,
32       in an irreversable (cryptographically secure) way. To make this easy
33       sd_id128_get_machine_app_specific() is provided, see below.
34
35       sd_id128_get_machine_app_specific() is similar to
36       sd_id128_get_machine(), but retrieves a machine ID that is specific to
37       the application that is identified by the indicated application ID. It
38       is recommended to use this function instead of sd_id128_get_machine()
39       when passing an ID to untrusted environments, in order to make sure
40       that the original machine ID may not be determined externally. This
41       way, the ID used by the application remains stable on a given machine,
42       but cannot be easily correlated with IDs used in other applications on
43       the same machine. The application-specific ID should be generated via a
44       tool like systemd-id128 new, and may be compiled into the application.
45       This function will return the same application-specific ID for each
46       combination of machine ID and application ID. Internally, this function
47       calculates HMAC-SHA256 of the application ID, keyed by the machine ID.
48
49       sd_id128_get_boot() returns the boot ID of the executing kernel. This
50       reads and parses the /proc/sys/kernel/random/boot_id file exposed by
51       the kernel. It is randomly generated early at boot and is unique for
52       every running kernel instance. See random(4) for more information. This
53       function also internally caches the returned ID to make this call a
54       cheap operation. It is recommended to use this ID as-is only in trusted
55       environments. In untrusted environments it is recommended to derive an
56       application specific ID using sd_id128_get_machine_app_specific(), see
57       below.
58
59       sd_id128_get_boot_app_specific() is analogous to
60       sd_id128_get_machine_app_specific() but returns an ID that changes
61       between boots. Some machines may be used for a long time without
62       rebooting, hence the boot ID may remain constant for a long time, and
63       has properties similar to the machine ID during that time.
64
65       sd_id128_get_invocation() returns the invocation ID of the currently
66       executed service. In its current implementation, this reads and parses
67       the $INVOCATION_ID environment variable that the service manager sets
68       when activating a service, see systemd.exec(5) for details. The ID is
69       cached internally. In future a different mechanism to determine the
70       invocation ID may be added.
71
72       Note that sd_id128_get_machine_app_specific(), sd_id128_get_boot(),
73       sd_id128_get_boot_app_specific(), and sd_id128_get_invocation() always
74       return UUID v4 compatible IDs.  sd_id128_get_machine() will also return
75       a UUID v4-compatible ID on new installations but might not on older. It
76       is possible to convert the machine ID into a UUID v4-compatible one.
77       For more information, see machine-id(5).
78
79       For more information about the "sd_id128_t" type see sd-id128(3).
80

RETURN VALUE

82       Those calls return 0 on success (in which case ret is filled in), or a
83       negative errno-style error code.
84
85   Errors
86       Returned errors may indicate the following problems:
87
88       -ENOENT
89           Returned by sd_id128_get_machine(),
90           sd_id128_get_machine_app_specific(), and
91           sd_id128_get_boot_app_specific() when /etc/machine-id is missing.
92
93       -ENOMEDIUM
94           Returned by sd_id128_get_machine(),
95           sd_id128_get_machine_app_specific(), and
96           sd_id128_get_boot_app_specific() when /etc/machine-id is empty or
97           all zeros.
98
99       -ENXIO
100           Returned by sd_id128_get_invocation() if no invocation ID is set.
101
102       -EIO
103           Returned by any of the functions described here when the configured
104           value has invalid format.
105
106       -EPERM
107           Requested information could not be retrieved because of
108           insufficient permissions.
109

NOTES

111       These APIs are implemented as a shared library, which can be compiled
112       and linked to with the libsystemd pkg-config(1) file.
113

EXAMPLES

115       Example 1. Application-specific machine ID
116
117       First, generate the application ID:
118
119           $ systemd-id128 -p new
120           As string:
121           c273277323db454ea63bb96e79b53e97
122
123           As UUID:
124           c2732773-23db-454e-a63b-b96e79b53e97
125
126           As man:sd-id128(3) macro:
127           #define MESSAGE_XYZ SD_ID128_MAKE(c2,73,27,73,23,db,45,4e,a6,3b,b9,6e,79,b5,3e,97)
128           ...
129
130       Then use the new identifier in an example application:
131
132           #include <stdio.h>
133           #include <systemd/sd-id128.h>
134
135           #define OUR_APPLICATION_ID SD_ID128_MAKE(c2,73,27,73,23,db,45,4e,a6,3b,b9,6e,79,b5,3e,97)
136
137           int main(int argc, char *argv[]) {
138             sd_id128_t id;
139             sd_id128_get_machine_app_specific(OUR_APPLICATION_ID, &id);
140             printf("Our application ID: " SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(id));
141             return 0;
142           }
143

SEE ALSO

145       systemd(1), systemd-id128(1), sd-id128(3), machine-id(5),
146       systemd.exec(5), sd_id128_randomize(3), random(4)
147
148
149
150systemd 245                                            SD_ID128_GET_MACHINE(3)
Impressum