diff options
Diffstat (limited to 'src/libsystemd')
-rw-r--r-- | src/libsystemd/libsystemd.sym | 5 | ||||
-rw-r--r-- | src/libsystemd/sd-device/sd-device.c | 5 | ||||
-rw-r--r-- | src/libsystemd/sd-id128/sd-id128.c | 32 | ||||
-rw-r--r-- | src/libsystemd/sd-login/sd-login.c | 12 |
4 files changed, 42 insertions, 12 deletions
diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym index d48ef6bbe2..46c4dac7d7 100644 --- a/src/libsystemd/libsystemd.sym +++ b/src/libsystemd/libsystemd.sym @@ -511,3 +511,8 @@ global: sd_bus_get_exit_on_disconnect; sd_id128_get_invocation; } LIBSYSTEMD_231; + +LIBSYSTEMD_233 { +global: + sd_id128_get_machine_app_specific; +} LIBSYSTEMD_232; diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index 411453e08d..bc5e92f8fe 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -28,6 +28,7 @@ #include "device-internal.h" #include "device-private.h" #include "device-util.h" +#include "dirent-util.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" @@ -164,7 +165,7 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) { } if (verify) { - r = readlink_and_canonicalize(_syspath, &syspath); + r = readlink_and_canonicalize(_syspath, NULL, &syspath); if (r == -ENOENT) /* the device does not exist (any more?) */ return -ENODEV; @@ -1627,7 +1628,7 @@ static int device_sysattrs_read_all(sd_device *device) { if (r < 0) return r; - for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { + FOREACH_DIRENT_ALL(dent, dir, return -errno) { char *path; struct stat statbuf; diff --git a/src/libsystemd/sd-id128/sd-id128.c b/src/libsystemd/sd-id128/sd-id128.c index d4450c70a0..0d673ba655 100644 --- a/src/libsystemd/sd-id128/sd-id128.c +++ b/src/libsystemd/sd-id128/sd-id128.c @@ -27,6 +27,7 @@ #include "hexdecoct.h" #include "id128-util.h" #include "io-util.h" +#include "khash.h" #include "macro.h" #include "random-util.h" #include "util.h" @@ -181,3 +182,34 @@ _public_ int sd_id128_randomize(sd_id128_t *ret) { *ret = make_v4_uuid(t); return 0; } + +_public_ int sd_id128_get_machine_app_specific(sd_id128_t app_id, sd_id128_t *ret) { + _cleanup_(khash_unrefp) khash *h = NULL; + sd_id128_t m, result; + const void *p; + int r; + + assert_return(ret, -EINVAL); + + r = sd_id128_get_machine(&m); + if (r < 0) + return r; + + r = khash_new_with_key(&h, "hmac(sha256)", &m, sizeof(m)); + if (r < 0) + return r; + + r = khash_put(h, &app_id, sizeof(app_id)); + if (r < 0) + return r; + + r = khash_digest_data(h, &p); + if (r < 0) + return r; + + /* We chop off the trailing 16 bytes */ + memcpy(&result, p, MIN(khash_get_size(h), sizeof(result))); + + *ret = make_v4_uuid(result); + return 0; +} diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c index 42ea0badfc..d2cfbdf5b0 100644 --- a/src/libsystemd/sd-login/sd-login.c +++ b/src/libsystemd/sd-login/sd-login.c @@ -793,6 +793,7 @@ _public_ int sd_get_sessions(char ***sessions) { _public_ int sd_get_uids(uid_t **users) { _cleanup_closedir_ DIR *d; + struct dirent *de; int r = 0; unsigned n = 0; _cleanup_free_ uid_t *l = NULL; @@ -801,19 +802,10 @@ _public_ int sd_get_uids(uid_t **users) { if (!d) return -errno; - for (;;) { - struct dirent *de; + FOREACH_DIRENT_ALL(de, d, return -errno) { int k; uid_t uid; - errno = 0; - de = readdir(d); - if (!de && errno > 0) - return -errno; - - if (!de) - break; - dirent_ensure_type(d, de); if (!dirent_is_file(de)) |