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_invocation - Retrieve 128-bit IDs
8

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

68       Those calls return 0 on success (in which case ret is filled in), or a
69       negative errno-style error code. In particular, sd_id128_get_machine()
70       and sd_id128_get_machine_app_specific() return -ENOENT if
71       /etc/machine-id is missing, and -ENOMEDIUM if is empty or all zeros.
72

NOTES

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

EXAMPLES

78       Example 1. Application-specific machine ID
79
80       Here's a simple example for an application specific machine ID:
81
82           #include <systemd/sd-id128.h>
83           #include <stdio.h>
84
85           #define OUR_APPLICATION_ID SD_ID128_MAKE(c2,73,27,73,23,db,45,4e,a6,3b,b9,6e,79,b5,3e,97)
86
87           int main(int argc, char *argv[]) {
88                   sd_id128_t id;
89                   sd_id128_get_machine_app_specific(OUR_APPLICATION_ID, &id);
90                   printf("Our application ID: " SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(id));
91                   return 0;
92           }
93

SEE ALSO

95       systemd(1), sd-id128(3), machine-id(5), systemd.exec(5),
96       sd_id128_randomize(3), random(4)
97
98
99
100systemd 239                                            SD_ID128_GET_MACHINE(3)
Impressum