summaryrefslogtreecommitdiffstats
path: root/src/libsystemd
diff options
context:
space:
mode:
authorAdrian Vovk <adrianvovk@gmail.com>2024-02-02 21:03:54 +0100
committerLennart Poettering <lennart@poettering.net>2024-02-14 09:14:13 +0100
commit80d07162e7cc87455d7b396b3b74fa5ff0391c89 (patch)
treef2c4a0aa2a16ebdc0b55ff56db4726c7620bc932 /src/libsystemd
parenthomed: Add some missing asserts (diff)
downloadsystemd-80d07162e7cc87455d7b396b3b74fa5ff0391c89.tar.xz
systemd-80d07162e7cc87455d7b396b3b74fa5ff0391c89.zip
format-utils: Expose FORMAT_UID and FORMAT_GID
This pulls this generally useful helper out of sysusers and into the util lib, and updates the places throughout the codebase where it makes sense to use it.
Diffstat (limited to 'src/libsystemd')
-rw-r--r--src/libsystemd/sd-bus/sd-bus.c6
-rw-r--r--src/libsystemd/sd-login/sd-login.c5
2 files changed, 3 insertions, 8 deletions
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index 2ad29af105..a25369e930 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -30,6 +30,7 @@
#include "constants.h"
#include "errno-util.h"
#include "fd-util.h"
+#include "format-util.h"
#include "glyph-util.h"
#include "hexdecoct.h"
#include "hostname-util.h"
@@ -1672,10 +1673,7 @@ static int user_and_machine_equivalent(const char *user_and_machine) {
return true;
/* Otherwise, we have to figure out our user id and name, and compare things with that. */
- char buf[DECIMAL_STR_MAX(uid_t)];
- xsprintf(buf, UID_FMT, uid);
-
- f = startswith(user_and_machine, buf);
+ f = startswith(user_and_machine, FORMAT_UID(uid));
if (!f) {
un = getusername_malloc();
if (!un)
diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c
index c72fccc229..4d91ba96f6 100644
--- a/src/libsystemd/sd-login/sd-login.c
+++ b/src/libsystemd/sd-login/sd-login.c
@@ -579,10 +579,7 @@ _public_ int sd_uid_is_on_seat(uid_t uid, int require_active, const char *seat)
if (isempty(content))
return 0;
- char t[DECIMAL_STR_MAX(uid_t)];
- xsprintf(t, UID_FMT, uid);
-
- return string_contains_word(content, NULL, t);
+ return string_contains_word(content, NULL, FORMAT_UID(uid));
}
static int uid_get_array(uid_t uid, const char *variable, char ***array) {