]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
auth:creds: Guess the username first via getpwuid(my_id)
authorAndreas Schneider <asn@samba.org>
Wed, 10 Nov 2021 11:06:51 +0000 (12:06 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 10 Nov 2021 19:11:53 +0000 (19:11 +0000)
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 <anoopcs@samba.org>
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Wed Nov 10 19:11:53 UTC 2021 on sn-devel-184

auth/credentials/credentials.c

index 542edbd43e22dd30e295afc404935365d097d313..67644e806e45646f6d4d1661a46bd48595c4271f 100644 (file)
@@ -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);