From 08ae1d1be363bdda5629de6c719b423b2fdad8b0 Mon Sep 17 00:00:00 2001 From: Alexis Mousset Date: Mon, 18 Sep 2023 21:41:28 +0200 Subject: [PATCH] Fallback to /usr/bin/getent when /bin/getent doesn't exist Ticket: CFE-4256 Changelog: /usr/bin/getent is now attempted to be used if /bin/getent doesn't exist --- libpromises/unix.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libpromises/unix.c b/libpromises/unix.c index 613146934a..692960b32e 100644 --- a/libpromises/unix.c +++ b/libpromises/unix.c @@ -246,8 +246,19 @@ static bool GetUserGroupInfoFromGetent(const char *type, const char *query, char *name, size_t name_size, uintmax_t *id, LogLevel error_log_level) { + struct stat sb; + char* getent_bin; + if (stat("/bin/getent", &sb) == 0) + { + getent_bin = "/bin/getent"; + } + else + { + getent_bin = "/usr/bin/getent"; + } + char buf[CF_BUFSIZE]; - NDEBUG_UNUSED int print_ret = snprintf(buf, sizeof(buf), "/bin/getent %s %s", type, query); + NDEBUG_UNUSED int print_ret = snprintf(buf, sizeof(buf), "%s %s %s", getent_bin, type, query); assert(print_ret < sizeof(buf)); FILE *out = cf_popen(buf, "r", OUTPUT_SELECT_STDOUT);