From 61fd63d70578043de9f3bff1c3267c499dbf50a0 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 10 Nov 2021 12:06:51 +0100 Subject: [PATCH] auth:creds: Guess the username first via getpwuid(my_id) If we have a container, we often don't have USER or LOGNAME set. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14883 Tested-by: Anoop C S Signed-off-by: Andreas Schneider Reviewed-by: Stefan Metzmacher (cherry picked from commit c28be4067463e582e378df402f812e510883d606) --- auth/credentials/credentials.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/auth/credentials/credentials.c b/auth/credentials/credentials.c index 02a3cf3b354..c5a6ba6940c 100644 --- a/auth/credentials/credentials.c +++ b/auth/credentials/credentials.c @@ -30,6 +30,7 @@ #include "tevent.h" #include "param/param.h" #include "system/filesys.h" +#include "system/passwd.h" /** * Create a new credentials structure @@ -1159,6 +1160,7 @@ _PUBLIC_ bool cli_credentials_guess(struct cli_credentials *cred, { const char *error_string; const char *env = NULL; + struct passwd *pwd = NULL; bool ok; if (lp_ctx != NULL) { @@ -1168,6 +1170,17 @@ _PUBLIC_ bool cli_credentials_guess(struct cli_credentials *cred, } } + pwd = getpwuid(getuid()); + if (pwd != NULL) { + size_t len = strlen(pwd->pw_name); + + if (len > 0 && len <= 1024) { + (void)cli_credentials_parse_string(cred, + pwd->pw_name, + CRED_GUESS_ENV); + } + } + env = getenv("LOGNAME"); if (env != NULL) { size_t len = strlen(env); -- 2.33.1