s3:passdb: Add support to handle UPNs in lookup_name()
authorAndreas Schneider <asn@cryptomilk.org>
Tue, 26 Apr 2022 05:12:02 +0000 (07:12 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 26 Apr 2022 19:22:29 +0000 (19:22 +0000)
This address an issue if sssd is running and handling nsswitch. If we look up
a user with getpwnam("DOMAIN\user") it will return user@REALM in the passwd
structure. We need to be able to deal with that.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15054

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/passdb/lookup_sid.c

index 3a28cdc68a672b3247e9d9be4919f8fc475367ae..c14d7a7b12380e9dddba8913c25478cbedbfb02f 100644 (file)
@@ -100,8 +100,18 @@ bool lookup_name(TALLOC_CTX *mem_ctx,
                                        PTR_DIFF(p, full_name));
                name = talloc_strdup(tmp_ctx, p+1);
        } else {
-               domain = talloc_strdup(tmp_ctx, "");
-               name = talloc_strdup(tmp_ctx, full_name);
+               char *q = strchr_m(full_name, '@');
+
+               /* Set the domain for UPNs */
+               if (q != NULL) {
+                       name = talloc_strndup(tmp_ctx,
+                                             full_name,
+                                             PTR_DIFF(q, full_name));
+                       domain = talloc_strdup(tmp_ctx, q + 1);
+               } else {
+                       domain = talloc_strdup(tmp_ctx, "");
+                       name = talloc_strdup(tmp_ctx, full_name);
+               }
        }
 
        if ((domain == NULL) || (name == NULL)) {