]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4:sam: Don't use talloc_steal for msg attributes in authsam_make_user_info_dc()
authorStefan Metzmacher <metze@samba.org>
Fri, 25 Feb 2022 06:40:17 +0000 (07:40 +0100)
committerJule Anger <janger@samba.org>
Wed, 2 Mar 2022 11:13:02 +0000 (11:13 +0000)
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 <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from commit f6fe86924c2ca756083d3628d5dbace0b12d06b0)

Autobuild-User(v4-14-test): Jule Anger <janger@samba.org>
Autobuild-Date(v4-14-test): Wed Mar  2 11:13:02 UTC 2022 on sn-devel-184

source4/auth/sam.c

index 93b41be3b21093ef59e46b5918abc175105abb4b..8b233bab3ad8b2ea3ca8c58ec6323c7485059e78 100644 (file)
@@ -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);