Skip to content

Commit

Permalink
Fallback to /usr/bin/getent when /bin/getent doesn't exist
Browse files Browse the repository at this point in the history
Ticket: CFE-4256
Changelog: /usr/bin/getent is now attempted to be used if
           /bin/getent doesn't exist
  • Loading branch information
amousset authored and vpodzime committed Nov 20, 2023
1 parent b3a5bac commit 08ae1d1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion libpromises/unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 08ae1d1

Please sign in to comment.