Remove a pointles call to smb_bufrem
[ira/wip.git] / source3 / smbd / sesssetup.c
index 7cff422507977b37aad17c7f4be6713b49bd3232..b2583861217f93ead7d082233283f4280132d5c0 100644 (file)
@@ -125,21 +125,18 @@ static void reply_sesssetup_blob(struct smb_request *req,
        if (!NT_STATUS_IS_OK(nt_status) &&
            !NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
                reply_nterror(req, nt_status_squash(nt_status));
-       } else {
-               nt_status = nt_status_squash(nt_status);
-               SIVAL(req->outbuf, smb_rcls, NT_STATUS_V(nt_status));
-               SSVAL(req->outbuf, smb_vwv0, 0xFF); /* no chaining possible */
-               SSVAL(req->outbuf, smb_vwv3, blob.length);
-
-               if ((message_push_blob(&req->outbuf, blob) == -1)
-                   || (push_signature(&req->outbuf) == -1)) {
-                       reply_nterror(req, NT_STATUS_NO_MEMORY);
-               }
+               return;
        }
 
-       show_msg((char *)req->outbuf);
-       srv_send_smb(smbd_server_fd(),(char *)req->outbuf,req->encrypted);
-       TALLOC_FREE(req->outbuf);
+       nt_status = nt_status_squash(nt_status);
+       SIVAL(req->outbuf, smb_rcls, NT_STATUS_V(nt_status));
+       SSVAL(req->outbuf, smb_vwv0, 0xFF); /* no chaining possible */
+       SSVAL(req->outbuf, smb_vwv3, blob.length);
+
+       if ((message_push_blob(&req->outbuf, blob) == -1)
+           || (push_signature(&req->outbuf) == -1)) {
+               reply_nterror(req, NT_STATUS_NO_MEMORY);
+       }
 }
 
 /****************************************************************************
@@ -652,7 +649,8 @@ static void reply_spnego_ntlmssp(struct smb_request *req,
 
                data_blob_free(&server_info->user_session_key);
                server_info->user_session_key =
-                       data_blob(
+                       data_blob_talloc(
+                       server_info,
                        (*auth_ntlmssp_state)->ntlmssp_state->session_key.data,
                        (*auth_ntlmssp_state)->ntlmssp_state->session_key.length);
 
@@ -748,7 +746,7 @@ NTSTATUS parse_spnego_mechanisms(DATA_BLOB blob_in,
 
        for (i=0;OIDs[i];i++) {
                DEBUG(5,("parse_spnego_mechanisms: Got OID %s\n", OIDs[i]));
-               free(OIDs[i]);
+               talloc_free(OIDs[i]);
        }
        return ret;
 }
@@ -1000,7 +998,7 @@ static NTSTATUS check_spnego_blob_complete(uint16 smbpid, uint16 vuid,
                DATA_BLOB *pblob)
 {
        struct pending_auth_data *pad = NULL;
-       ASN1_DATA data;
+       ASN1_DATA *data;
        size_t needed_len = 0;
 
        pad = get_pending_auth_data(smbpid);
@@ -1087,34 +1085,39 @@ static NTSTATUS check_spnego_blob_complete(uint16 smbpid, uint16 vuid,
         * the data given in this blob is enough.
         */
 
-       asn1_load(&data, *pblob);
-       asn1_start_tag(&data, pblob->data[0]);
-       if (data.has_error || data.nesting == NULL) {
-               asn1_free(&data);
+       data = asn1_init(NULL);
+       if (data == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       asn1_load(data, *pblob);
+       asn1_start_tag(data, pblob->data[0]);
+       if (data->has_error || data->nesting == NULL) {
+               asn1_free(data);
                /* Let caller catch. */
                return NT_STATUS_OK;
        }
 
        /* Integer wrap paranoia.... */
 
-       if (data.nesting->taglen + data.nesting->start < data.nesting->taglen ||
-           data.nesting->taglen + data.nesting->start < data.nesting->start) {
+       if (data->nesting->taglen + data->nesting->start < data->nesting->taglen ||
+           data->nesting->taglen + data->nesting->start < data->nesting->start) {
 
                DEBUG(2,("check_spnego_blob_complete: integer wrap "
                        "data.nesting->taglen = %u, "
                        "data.nesting->start = %u\n",
-                       (unsigned int)data.nesting->taglen,
-                       (unsigned int)data.nesting->start ));
+                       (unsigned int)data->nesting->taglen,
+                       (unsigned int)data->nesting->start ));
 
-               asn1_free(&data);
+               asn1_free(data);
                return NT_STATUS_INVALID_PARAMETER;
        }
 
        /* Total length of the needed asn1 is the tag length
         * plus the current offset. */
 
-       needed_len = data.nesting->taglen + data.nesting->start;
-       asn1_free(&data);
+       needed_len = data->nesting->taglen + data->nesting->start;
+       asn1_free(data);
 
        DEBUG(10,("check_spnego_blob_complete: needed_len = %u, "
                "pblob->length = %u\n",
@@ -1351,6 +1354,9 @@ static int shutdown_other_smbds(struct db_record *rec,
                return 0;
        }
 
+       DEBUG(0,("shutdown_other_smbds: shutting down pid %d "
+                "(IP %s)\n", procid_to_pid(&crec->pid), ip));
+
        messaging_send(smbd_messaging_context(), crec->pid, MSG_SHUTDOWN,
                       &data_blob_null);
        return 0;
@@ -1441,8 +1447,7 @@ void reply_sesssetup_and_X(struct smb_request *req)
                remove_from_common_flags2(FLAGS2_32_BIT_ERROR_CODES);
 
                if ((passlen1 > MAX_PASS_LEN)
-                   || (passlen1 > smb_bufrem(req->inbuf,
-                                             smb_buf(req->inbuf)))) {
+                   || (passlen1 > smb_buflen(req->inbuf))) {
                        reply_nterror(req, nt_status_squash(
                                              NT_STATUS_INVALID_PARAMETER));
                        END_PROFILE(SMBsesssetupX);
@@ -1734,16 +1739,19 @@ void reply_sesssetup_and_X(struct smb_request *req)
                return;
        }
 
-       nt_status = create_local_token(server_info);
-       if (!NT_STATUS_IS_OK(nt_status)) {
-               DEBUG(10, ("create_local_token failed: %s\n",
-                          nt_errstr(nt_status)));
-               data_blob_free(&nt_resp);
-               data_blob_free(&lm_resp);
-               data_blob_clear_free(&plaintext_password);
-               reply_nterror(req, nt_status_squash(nt_status));
-               END_PROFILE(SMBsesssetupX);
-               return;
+       if (!server_info->ptok) {
+               nt_status = create_local_token(server_info);
+
+               if (!NT_STATUS_IS_OK(nt_status)) {
+                       DEBUG(10, ("create_local_token failed: %s\n",
+                                  nt_errstr(nt_status)));
+                       data_blob_free(&nt_resp);
+                       data_blob_free(&lm_resp);
+                       data_blob_clear_free(&plaintext_password);
+                       reply_nterror(req, nt_status_squash(nt_status));
+                       END_PROFILE(SMBsesssetupX);
+                       return;
+               }
        }
 
        data_blob_clear_free(&plaintext_password);