s3-auth: Simplify how we free the auth_context
authorSimo Sorce <idra@samba.org>
Fri, 16 Jul 2010 22:23:55 +0000 (18:23 -0400)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 19 Jul 2010 04:20:00 +0000 (14:20 +1000)
Turn the freeing function into a destructor and attach it to the
auth_context.
Make all callers TALLOC_FREE() the auth_context instead of calling
the free function.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
source3/auth/auth.c
source3/auth/auth_compat.c
source3/auth/auth_ntlmssp.c
source3/include/auth.h
source3/rpc_server/srv_netlog_nt.c
source3/smbd/negprot.c
source3/smbd/server_exit.c
source3/smbd/sesssetup.c

index a52dab9f01b2e35f90730feeaf62123e26d1f09a..5dc1d970d61f48ccc528dfb83892383e3ceb7c07 100644 (file)
@@ -322,38 +322,40 @@ static NTSTATUS check_ntlm_password(const struct auth_context *auth_context,
  Clear out a auth_context, and destroy the attached TALLOC_CTX
 ***************************************************************************/
 
-static void free_auth_context(struct auth_context **auth_context)
+static int auth_context_destructor(void *ptr)
 {
-       auth_methods *auth_method;
+       struct auth_context *ctx = talloc_get_type(ptr, struct auth_context);
+       struct auth_methods *am;
 
-       if (*auth_context) {
-               /* Free private data of context's authentication methods */
-               for (auth_method = (*auth_context)->auth_method_list; auth_method; auth_method = auth_method->next) {
-                       TALLOC_FREE(auth_method->private_data);
-               }
 
-               talloc_destroy(*auth_context);
-               *auth_context = NULL;
+       /* Free private data of context's authentication methods */
+       for (am = ctx->auth_method_list; am; am = am->next) {
+               TALLOC_FREE(am->private_data);
        }
+
+       return 0;
 }
 
 /***************************************************************************
  Make a auth_info struct
 ***************************************************************************/
 
-static NTSTATUS make_auth_context(struct auth_context **auth_context) 
+static NTSTATUS make_auth_context(struct auth_context **auth_context)
 {
-       *auth_context = TALLOC_ZERO_P(talloc_autofree_context(),
-                                     struct auth_context);
-       if (!*auth_context) {
+       struct auth_context *ctx;
+
+       ctx = talloc_zero(talloc_autofree_context(), struct auth_context);
+       if (!ctx) {
                DEBUG(0,("make_auth_context: talloc failed!\n"));
                return NT_STATUS_NO_MEMORY;
        }
 
-       (*auth_context)->check_ntlm_password = check_ntlm_password;
-       (*auth_context)->get_ntlm_challenge = get_ntlm_challenge;
-       (*auth_context)->free = free_auth_context;
+       ctx->check_ntlm_password = check_ntlm_password;
+       ctx->get_ntlm_challenge = get_ntlm_challenge;
+
+       talloc_set_destructor((TALLOC_CTX *)ctx, auth_context_destructor);
 
+       *auth_context = ctx;
        return NT_STATUS_OK;
 }
 
index e90036f3ff95d4604b955c90777bea694f8227d3..cdd40966542734b682eec2015e84cb43b6064e9a 100644 (file)
@@ -59,7 +59,7 @@ NTSTATUS check_plaintext_password(const char *smb_name,
        nt_status = plaintext_auth_context->check_ntlm_password(plaintext_auth_context, 
                                                                user_info, server_info); 
 
-       (plaintext_auth_context->free)(&plaintext_auth_context);
+       TALLOC_FREE(plaintext_auth_context);
        free_user_info(&user_info);
        return nt_status;
 }
index 363f6114317ed429b75d48c80dda66516dc88a3d..44e9320191758307a05af17aac17bc6096068ea6 100644 (file)
@@ -332,7 +332,7 @@ void auth_ntlmssp_end(struct auth_ntlmssp_state **auth_ntlmssp_state)
                TALLOC_FREE(ans->ntlmssp_state);
        }
        if (ans->auth_context) {
-               ans->auth_context->free(&ans->auth_context);
+               TALLOC_FREE(ans->auth_context);
        }
        if (ans->server_info) {
                TALLOC_FREE(ans->server_info);
index 17257b3433648dde1876e8f9ff541bcec96b55e8..b7089b8c0ad7105dc6ca74bc2209258a36957001 100644 (file)
@@ -115,7 +115,6 @@ struct auth_context {
                                        const struct auth_usersupplied_info *user_info, 
                                        struct auth_serversupplied_info **server_info);
        NTSTATUS (*nt_status_squash)(NTSTATUS nt_status);
-       void (*free)(struct auth_context **auth_context);
 };
 
 typedef struct auth_methods
index ebd37241a6bc1f32fde6fcc98637b2a3f793020d..a57836aa7562bdf8a8189fe5df4cc7737c5c9a44 100644 (file)
@@ -1380,7 +1380,7 @@ static NTSTATUS _netr_LogonSamLogon_base(pipes_struct *p,
                        user_info, &server_info);
        }
 
-       (auth_context->free)(&auth_context);
+       TALLOC_FREE(auth_context);
        free_user_info(&user_info);
 
        DEBUG(5,("%s: check_password returned status %s\n",
index 755d3d97180884d55cb1b84ff4a1013151681d98..4d73216854fa164081283f8ebec3abd3749e3971 100644 (file)
@@ -33,8 +33,7 @@ static void get_challenge(struct smbd_server_connection *sconn, uint8 buff[8])
        if (sconn->smb1.negprot.auth_context) {
                DEBUG(3, ("get challenge: is this a secondary negprot? "
                          "sconn->negprot.auth_context is non-NULL!\n"));
-                       sconn->smb1.negprot.auth_context->free(
-                               &sconn->smb1.negprot.auth_context);
+                       TALLOC_FREE(sconn->smb1.negprot.auth_context);
        }
 
        DEBUG(10, ("get challenge: creating negprot_global_auth_context\n"));
index 97394aea962684293896a40ca6d52f33e61370e4..1a330994b8a74082e323deb04a6f1f8293802dae 100644 (file)
@@ -75,8 +75,7 @@ static void exit_server_common(enum server_exit_reason how,
        change_to_root_user();
 
        if (sconn && sconn->smb1.negprot.auth_context) {
-               struct auth_context *a = sconn->smb1.negprot.auth_context;
-               a->free(&sconn->smb1.negprot.auth_context);
+               TALLOC_FREE(sconn->smb1.negprot.auth_context);
        }
 
        if (lp_log_writeable_files_on_exit()) {
index 52fcd282a66e5e08ac3dd46e8afafc453d6f83c7..525bcafd096235dbbc017aabc58c64b915397abb 100644 (file)
@@ -150,14 +150,14 @@ static NTSTATUS check_guest_password(struct auth_serversupplied_info **server_in
        }
 
        if (!make_user_info_guest(&user_info)) {
-               (auth_context->free)(&auth_context);
+               TALLOC_FREE(auth_context);
                return NT_STATUS_NO_MEMORY;
        }
 
        nt_status = auth_context->check_ntlm_password(auth_context,
                                                user_info,
                                                server_info);
-       (auth_context->free)(&auth_context);
+       TALLOC_FREE(auth_context);
        free_user_info(&user_info);
        return nt_status;
 }
@@ -1751,8 +1751,7 @@ void reply_sesssetup_and_X(struct smb_request *req)
                                                user_info,
                                                &server_info);
 
-                               (plaintext_auth_context->free)(
-                                               &plaintext_auth_context);
+                               TALLOC_FREE(plaintext_auth_context);
                        }
                }
        }