s3-auth: Refactor and rename auth_ntlmssp_server_info()
authorSimo Sorce <idra@samba.org>
Fri, 16 Jul 2010 22:33:38 +0000 (18:33 -0400)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 20 Jul 2010 05:52:24 +0000 (15:52 +1000)
Rename it to auth_ntlmssp_steal_server_info() to make it clear that
the server_info struct is stolen from the auth_ntlmssp_state structure.
Use talloc_move instead of manual steal&clear
Add comments to explain what is going on.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
source3/auth/auth_ntlmssp.c
source3/include/proto.h
source3/rpc_server/srv_pipe.c
source3/smbd/sesssetup.c
source3/smbd/smb2_sesssetup.c

index a71c02b14f69a961dcd072ce4779d5e3161ab4fc..efeca5c40351b8da04f3ff3ad946c0b0c6807a5a 100644 (file)
@@ -83,23 +83,25 @@ void auth_ntlmssp_want_seal(struct auth_ntlmssp_state *auth_ntlmssp_state)
 
 }
 
-NTSTATUS auth_ntlmssp_server_info(TALLOC_CTX *mem_ctx,
-                                 struct auth_ntlmssp_state *auth_ntlmssp_state,
-                                 struct auth_serversupplied_info **_server_info)
+NTSTATUS auth_ntlmssp_steal_server_info(TALLOC_CTX *mem_ctx,
+                               struct auth_ntlmssp_state *auth_ntlmssp_state,
+                               struct auth_serversupplied_info **server_info)
 {
-       struct auth_serversupplied_info *server_info = auth_ntlmssp_state->server_info;
-       data_blob_free(&server_info->user_session_key);
-       server_info->user_session_key =
+       /* Free the current server_info user_session_key and reset it from the
+        * current ntlmssp_state session_key */
+       data_blob_free(&auth_ntlmssp_state->server_info->user_session_key);
+       auth_ntlmssp_state->server_info->user_session_key =
                data_blob_talloc(
-                       server_info,
+                       auth_ntlmssp_state->server_info,
                        auth_ntlmssp_state->ntlmssp_state->session_key.data,
                        auth_ntlmssp_state->ntlmssp_state->session_key.length);
-       if (auth_ntlmssp_state->ntlmssp_state->session_key.length && !server_info->user_session_key.data) {
-               *_server_info = NULL;
+       if (auth_ntlmssp_state->ntlmssp_state->session_key.length &&
+           !auth_ntlmssp_state->server_info->user_session_key.data) {
+               *server_info = NULL;
                return NT_STATUS_NO_MEMORY;
        }
-       auth_ntlmssp_state->server_info = NULL;
-       *_server_info = talloc_steal(mem_ctx, server_info);
+       /* Steal server_info away from auth_ntlmssp_state */
+       *server_info = talloc_move(mem_ctx, &auth_ntlmssp_state->server_info);
        return NT_STATUS_OK;
 }
 
index a85f7b54342259c7107155aaac556f2e6c0e17f3..7c7611d6723ce1195a999f268b5184ca32974655 100644 (file)
@@ -54,9 +54,9 @@ NTSTATUS auth_netlogond_init(void);
 
 /* The following definitions come from auth/auth_ntlmssp.c  */
 
-NTSTATUS auth_ntlmssp_server_info(TALLOC_CTX *mem_ctx,
-                                 struct auth_ntlmssp_state *auth_ntlmssp_state,
-                                 struct auth_serversupplied_info **_server_info);
+NTSTATUS auth_ntlmssp_steal_server_info(TALLOC_CTX *mem_ctx,
+                               struct auth_ntlmssp_state *auth_ntlmssp_state,
+                               struct auth_serversupplied_info **server_info);
 struct ntlmssp_state *auth_ntlmssp_get_ntlmssp_state(struct auth_ntlmssp_state *auth_ntlmssp_state);
 const char *auth_ntlmssp_get_username(struct auth_ntlmssp_state *auth_ntlmssp_state);
 const char *auth_ntlmssp_get_domain(struct auth_ntlmssp_state *auth_ntlmssp_state);
index 2a995b318bca3d940a5a7249f715fc61699642a9..6211d3b87e6d7826f8cb804f18a21d4cf47b7e00 100644 (file)
@@ -502,7 +502,7 @@ static bool pipe_ntlmssp_verify_final(pipes_struct *p, DATA_BLOB *p_resp_blob)
 
        TALLOC_FREE(p->server_info);
 
-       status = auth_ntlmssp_server_info(p, a, &p->server_info);
+       status = auth_ntlmssp_steal_server_info(p, a, &p->server_info);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0, ("auth_ntlmssp_server_info failed to obtain the server info for authenticated user: %s\n",
                          nt_errstr(status)));
index 08119b2be16d788b9c675935c5ac2d402127caaa..8ff8e08a4639bcc0df7adaced623a16e2826dee4 100644 (file)
@@ -640,7 +640,8 @@ static void reply_spnego_ntlmssp(struct smb_request *req,
        struct smbd_server_connection *sconn = req->sconn;
 
        if (NT_STATUS_IS_OK(nt_status)) {
-               nt_status = auth_ntlmssp_server_info(talloc_tos(), (*auth_ntlmssp_state), &server_info);
+               nt_status = auth_ntlmssp_steal_server_info(talloc_tos(),
+                                       (*auth_ntlmssp_state), &server_info);
        } else {
                /* Note that this server_info won't have a session
                 * key.  But for map to guest, that's exactly the right
index 4d0f03259b5974d132e9f1ae52a1aac90cc66231..a6adf8a66f555c157749cc34c9fb659d55c9777d 100644 (file)
@@ -147,7 +147,7 @@ static NTSTATUS setup_ntlmssp_server_info(struct smbd_smb2_session *session,
                                NTSTATUS status)
 {
        if (NT_STATUS_IS_OK(status)) {
-               status = auth_ntlmssp_server_info(session,
+               status = auth_ntlmssp_steal_server_info(session,
                                session->auth_ntlmssp_state,
                                &session->server_info);
        } else {