From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/secur32/schannel.c | 29 +++++++++++++++++++++++++---- dlls/secur32/schannel_gnutls.c | 26 ++------------------------ dlls/secur32/secur32_priv.h | 1 - 3 files changed, 27 insertions(+), 29 deletions(-)
diff --git a/dlls/secur32/schannel.c b/dlls/secur32/schannel.c index 3242aebebbe..69c753096e7 100644 --- a/dlls/secur32/schannel.c +++ b/dlls/secur32/schannel.c @@ -767,6 +767,7 @@ static SECURITY_STATUS SEC_ENTRY schan_InitializeSecurityContextW( int output_buffer_idx = -1; int idx, i; ULONG input_offset = 0, output_offset = 0; + SecBufferDesc input_desc, output_desc;
TRACE("%p %p %s 0x%08lx %ld %ld %p %ld %p %p %p %p\n", phCredential, phContext, debugstr_w(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput, @@ -917,11 +918,30 @@ static SECURITY_STATUS SEC_ENTRY schan_InitializeSecurityContextW( alloc_buffer.BufferType = SECBUFFER_TOKEN; alloc_buffer.pvBuffer = RtlAllocateHeap( GetProcessHeap(), 0, extra_size ); } + + memset(&input_desc, 0, sizeof(input_desc)); + if (pInput && (idx = schan_find_sec_buffer_idx(pInput, 0, SECBUFFER_TOKEN)) != -1) + { + input_desc.cBuffers = 1; + input_desc.pBuffers = &pInput->pBuffers[idx]; + } + + memset(&output_desc, 0, sizeof(output_desc)); + idx = schan_find_sec_buffer_idx(pOutput, 0, SECBUFFER_TOKEN); + if (idx == -1) + idx = schan_find_sec_buffer_idx(pOutput, 0, SECBUFFER_EMPTY); + if (idx != -1) + { + output_desc.cBuffers = 1; + output_desc.pBuffers = &pOutput->pBuffers[idx]; + if (!output_desc.pBuffers->pvBuffer) + *output_desc.pBuffers = alloc_buffer; + } + params.session = ctx->session; - params.input = pInput; + params.input = pInput ? &input_desc : NULL; params.input_size = expected_size; - params.output = pOutput; - params.alloc_buffer = &alloc_buffer; + params.output = &output_desc; params.input_offset = &input_offset; params.output_buffer_idx = &output_buffer_idx; params.output_offset = &output_offset; @@ -929,7 +949,8 @@ static SECURITY_STATUS SEC_ENTRY schan_InitializeSecurityContextW(
if (output_buffer_idx != -1) { - SecBuffer *buffer = &pOutput->pBuffers[output_buffer_idx]; + SecBuffer *buffer = &output_desc.pBuffers[output_buffer_idx]; + buffer->BufferType = SECBUFFER_TOKEN; buffer->cbBuffer = output_offset; if (buffer->pvBuffer == alloc_buffer.pvBuffer) { diff --git a/dlls/secur32/schannel_gnutls.c b/dlls/secur32/schannel_gnutls.c index 098ca239598..696790f44dc 100644 --- a/dlls/secur32/schannel_gnutls.c +++ b/dlls/secur32/schannel_gnutls.c @@ -146,7 +146,6 @@ struct schan_buffers SIZE_T offset; SIZE_T limit; const SecBufferDesc *desc; - SecBuffer *alloc_buffer; int current_buffer_idx; int (*get_next_buffer)(struct schan_buffers *); }; @@ -234,7 +233,6 @@ static void init_schan_buffers(struct schan_buffers *s, const PSecBufferDesc des s->limit = ~0UL; s->desc = desc; s->current_buffer_idx = -1; - s->alloc_buffer = NULL; s->get_next_buffer = get_next_buffer; }
@@ -257,26 +255,7 @@ static int handshake_get_next_buffer(struct schan_buffers *s) { if (s->current_buffer_idx != -1) return -1; - return schan_find_sec_buffer_idx(s->desc, 0, SECBUFFER_TOKEN); -} - -static int handshake_get_next_buffer_alloc(struct schan_buffers *s) -{ - if (s->current_buffer_idx == -1) - { - int idx = schan_find_sec_buffer_idx(s->desc, 0, SECBUFFER_TOKEN); - if (idx == -1) - { - idx = schan_find_sec_buffer_idx(s->desc, 0, SECBUFFER_EMPTY); - if (idx != -1) s->desc->pBuffers[idx].BufferType = SECBUFFER_TOKEN; - } - if (idx != -1 && !s->desc->pBuffers[idx].pvBuffer && s->alloc_buffer) - { - s->desc->pBuffers[idx] = *s->alloc_buffer; - } - return idx; - } - return -1; + return s->desc->cBuffers ? 0 : -1; }
static int send_message_get_next_buffer(struct schan_buffers *s) @@ -606,8 +585,7 @@ static NTSTATUS schan_handshake( void *args )
init_schan_buffers(&t->in, params->input, handshake_get_next_buffer); t->in.limit = params->input_size; - init_schan_buffers(&t->out, params->output, handshake_get_next_buffer_alloc ); - t->out.alloc_buffer = params->alloc_buffer; + init_schan_buffers(&t->out, params->output, handshake_get_next_buffer);
while (1) { diff --git a/dlls/secur32/secur32_priv.h b/dlls/secur32/secur32_priv.h index 8a59458e875..574d3d51cb5 100644 --- a/dlls/secur32/secur32_priv.h +++ b/dlls/secur32/secur32_priv.h @@ -147,7 +147,6 @@ struct handshake_params SecBufferDesc *input; SIZE_T input_size; SecBufferDesc *output; - SecBuffer *alloc_buffer; ULONG *input_offset; int *output_buffer_idx; ULONG *output_offset;