From: Andreas Schneider Date: Tue, 26 Apr 2022 05:12:02 +0000 (+0200) Subject: s3:passdb: Add support to handle UPNs in lookup_name() X-Git-Tag: talloc-2.3.4~357 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a03fb91c1120718ada9d4b8421044cb7eae7b83;p=thirdparty%2Fsamba.git s3:passdb: Add support to handle UPNs in lookup_name() 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 Reviewed-by: Jeremy Allison --- diff --git a/source3/passdb/lookup_sid.c b/source3/passdb/lookup_sid.c index 3a28cdc68a6..c14d7a7b123 100644 --- a/source3/passdb/lookup_sid.c +++ b/source3/passdb/lookup_sid.c @@ -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)) {