From 6417be52ea097b8c23fcea62f274cf4624c8da96 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 25 Feb 2022 07:40:17 +0100 Subject: [PATCH] s4:sam: Don't use talloc_steal for msg attributes in authsam_make_user_info_dc() This is most likely not a problem for the current callers, but that it is unexpected and will likely cause problems with future changes. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14993 BUG: https://bugzilla.samba.org/show_bug.cgi?id=14995 Signed-off-by: Stefan Metzmacher Reviewed-by: Andrew Bartlett (cherry picked from commit f6fe86924c2ca756083d3628d5dbace0b12d06b0) --- source4/auth/sam.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/source4/auth/sam.c b/source4/auth/sam.c index 93b41be3b210..8b233bab3ad8 100644 --- a/source4/auth/sam.c +++ b/source4/auth/sam.c @@ -454,12 +454,15 @@ _PUBLIC_ NTSTATUS authsam_make_user_info_dc(TALLOC_CTX *mem_ctx, user_info_dc->info = info = talloc_zero(user_info_dc, struct auth_user_info); NT_STATUS_HAVE_NO_MEMORY(user_info_dc->info); - info->account_name = talloc_steal(info, - ldb_msg_find_attr_as_string(msg, "sAMAccountName", NULL)); + str = ldb_msg_find_attr_as_string(msg, "sAMAccountName", NULL); + info->account_name = talloc_strdup(info, str); + if (info->account_name == NULL) { + TALLOC_FREE(user_info_dc); + return NT_STATUS_NO_MEMORY; + } - info->user_principal_name = talloc_steal(info, - ldb_msg_find_attr_as_string(msg, "userPrincipalName", NULL)); - if (info->user_principal_name == NULL && dns_domain_name != NULL) { + str = ldb_msg_find_attr_as_string(msg, "userPrincipalName", NULL); + if (str == NULL && dns_domain_name != NULL) { info->user_principal_name = talloc_asprintf(info, "%s@%s", info->account_name, dns_domain_name); @@ -468,6 +471,12 @@ _PUBLIC_ NTSTATUS authsam_make_user_info_dc(TALLOC_CTX *mem_ctx, return NT_STATUS_NO_MEMORY; } info->user_principal_constructed = true; + } else if (str != NULL) { + info->user_principal_name = talloc_strdup(info, str); + if (info->user_principal_name == NULL) { + TALLOC_FREE(user_info_dc); + return NT_STATUS_NO_MEMORY; + } } info->domain_name = talloc_strdup(info, domain_name); -- 2.25.1