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. In particular, sd_id128_get_machine(),
84       sd_id128_get_machine_app_specific(), and
85       sd_id128_get_boot_app_specific() return -ENOENT if /etc/machine-id is
86       missing, and -ENOMEDIUM if /etc/machine-id is empty or all zeros.
87

NOTES

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

EXAMPLES

93       Example 1. Application-specific machine ID
94
95       First, generate the application ID:
96
97           $ systemd-id128 -p new
98           As string:
99           c273277323db454ea63bb96e79b53e97
100
101           As UUID:
102           c2732773-23db-454e-a63b-b96e79b53e97
103
104           As man:sd-id128(3) macro:
105           #define MESSAGE_XYZ SD_ID128_MAKE(c2,73,27,73,23,db,45,4e,a6,3b,b9,6e,79,b5,3e,97)
106           ...
107
108       Then use the new identifier in an example application:
109
110           #include <stdio.h>
111           #include <systemd/sd-id128.h>
112
113           #define OUR_APPLICATION_ID SD_ID128_MAKE(c2,73,27,73,23,db,45,4e,a6,3b,b9,6e,79,b5,3e,97)
114
115           int main(int argc, char *argv[]) {
116             sd_id128_t id;
117             sd_id128_get_machine_app_specific(OUR_APPLICATION_ID, &id);
118             printf("Our application ID: " SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(id));
119             return 0;
120           }
121

SEE ALSO

123       systemd(1), systemd-id128(1), sd-id128(3), machine-id(5),
124       systemd.exec(5), sd_id128_randomize(3), random(4)
125
126
127
128systemd 241                                            SD_ID128_GET_MACHINE(3)
Impressum