auth3: Simplify auth_check_ntlm_password talloc handling
authorVolker Lendecke <vl@samba.org>
Sat, 11 Feb 2017 10:26:09 +0000 (11:26 +0100)
committerJeremy Allison <jra@samba.org>
Wed, 8 Mar 2017 21:01:15 +0000 (22:01 +0100)
Use talloc_stackframe and talloc_tos. Don't bother to talloc_free
within the loop, we don't have many iterations.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/auth/auth.c

index c5392a5889e3e3b1238060b0a0167e8bc7a5f345..2f84c70b56ecb890119c575d9831c45c8f21dd93 100644 (file)
@@ -165,6 +165,7 @@ NTSTATUS auth_check_ntlm_password(TALLOC_CTX *mem_ctx,
                                  const struct auth_usersupplied_info *user_info,
                                  struct auth_serversupplied_info **pserver_info)
 {
+       TALLOC_CTX *frame;
        /* if all the modules say 'not for me' this is reasonable */
        NTSTATUS nt_status = NT_STATUS_NO_SUCH_USER;
        const char *unix_username;
@@ -174,6 +175,8 @@ NTSTATUS auth_check_ntlm_password(TALLOC_CTX *mem_ctx,
                return NT_STATUS_LOGON_FAILURE;
        }
 
+       frame = talloc_stackframe();
+
        DEBUG(3, ("check_ntlm_password:  Checking password for unmapped user [%s]\\[%s]@[%s] with the new password interface\n", 
                  user_info->client.domain_name, user_info->client.account_name, user_info->workstation_name));
 
@@ -211,7 +214,6 @@ NTSTATUS auth_check_ntlm_password(TALLOC_CTX *mem_ctx,
 
        for (auth_method = auth_context->auth_method_list;auth_method; auth_method = auth_method->next) {
                struct auth_serversupplied_info *server_info;
-               TALLOC_CTX *tmp_ctx;
                NTSTATUS result;
 
                if (user_info->flags & USER_INFO_LOCAL_SAM_ONLY
@@ -219,23 +221,15 @@ NTSTATUS auth_check_ntlm_password(TALLOC_CTX *mem_ctx,
                        continue;
                }
 
-               tmp_ctx = talloc_named(mem_ctx,
-                                      0,
-                                      "%s authentication for user %s\\%s",
-                                      auth_method->name,
-                                      user_info->mapped.domain_name,
-                                      user_info->client.account_name);
-
                result = auth_method->auth(auth_context,
                                           auth_method->private_data,
-                                          tmp_ctx,
+                                          talloc_tos(),
                                           user_info,
                                           &server_info);
 
                /* check if the module did anything */
                if (NT_STATUS_EQUAL(result, NT_STATUS_NOT_IMPLEMENTED)) {
                        DEBUG(10,("check_ntlm_password: %s had nothing to say\n", auth_method->name));
-                       TALLOC_FREE(tmp_ctx);
                        if (user_info->flags & USER_INFO_LOCAL_SAM_ONLY) {
                                /* we don't expose the NT_STATUS_NOT_IMPLEMENTED
                                 * internals, except when the caller is only probing
@@ -258,11 +252,8 @@ NTSTATUS auth_check_ntlm_password(TALLOC_CTX *mem_ctx,
 
                if (NT_STATUS_IS_OK(nt_status)) {
                        *pserver_info = talloc_move(mem_ctx, &server_info);
-                       TALLOC_FREE(tmp_ctx);
                        break;
                }
-
-               TALLOC_FREE(tmp_ctx);
        }
 
        /* successful authentication */
@@ -310,6 +301,7 @@ NTSTATUS auth_check_ntlm_password(TALLOC_CTX *mem_ctx,
                               unix_username));
                }
 
+               TALLOC_FREE(frame);
                return nt_status;
        }
 
@@ -322,6 +314,8 @@ fail:
                  nt_errstr(nt_status)));
        ZERO_STRUCTP(pserver_info);
 
+       TALLOC_FREE(frame);
+
        return nt_status;
 }