msv1_0: Define the communication structure only on the Unix side.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2021-11-09 11:40:39 +01:00
parent fcc827d141
commit 1307d44f43
2 changed files with 39 additions and 22 deletions

View File

@ -44,38 +44,51 @@ WINE_DECLARE_DEBUG_CHANNEL(winediag);
#define INITIAL_BUFFER_SIZE 200 #define INITIAL_BUFFER_SIZE 200
struct com_buf
{
char *buffer;
unsigned int size;
unsigned int offset;
};
static SECURITY_STATUS read_line( struct ntlm_ctx *ctx, unsigned int *offset ) static SECURITY_STATUS read_line( struct ntlm_ctx *ctx, unsigned int *offset )
{ {
char *newline; char *newline;
struct com_buf *com_buf = ctx->com_buf;
if (!ctx->com_buf) if (!com_buf)
{ {
if (!(ctx->com_buf = malloc( INITIAL_BUFFER_SIZE ))) if (!(com_buf = malloc( sizeof(*com_buf) ))) return SEC_E_INSUFFICIENT_MEMORY;
if (!(com_buf->buffer = malloc( INITIAL_BUFFER_SIZE )))
{
free( com_buf );
return SEC_E_INSUFFICIENT_MEMORY; return SEC_E_INSUFFICIENT_MEMORY;
ctx->com_buf_size = INITIAL_BUFFER_SIZE; }
ctx->com_buf_offset = 0; com_buf->size = INITIAL_BUFFER_SIZE;
com_buf->offset = 0;
ctx->com_buf = com_buf;
} }
do do
{ {
ssize_t size; ssize_t size;
if (ctx->com_buf_offset + INITIAL_BUFFER_SIZE > ctx->com_buf_size) if (com_buf->offset + INITIAL_BUFFER_SIZE > com_buf->size)
{ {
char *buf = realloc( ctx->com_buf, ctx->com_buf_size + INITIAL_BUFFER_SIZE ); char *buf = realloc( com_buf->buffer, com_buf->size + INITIAL_BUFFER_SIZE );
if (!buf) return SEC_E_INSUFFICIENT_MEMORY; if (!buf) return SEC_E_INSUFFICIENT_MEMORY;
ctx->com_buf_size += INITIAL_BUFFER_SIZE; com_buf->size += INITIAL_BUFFER_SIZE;
ctx->com_buf = buf; com_buf->buffer = buf;
} }
size = read( ctx->pipe_in, ctx->com_buf + ctx->com_buf_offset, ctx->com_buf_size - ctx->com_buf_offset ); size = read( ctx->pipe_in, com_buf->buffer + com_buf->offset, com_buf->size - com_buf->offset );
if (size <= 0) return SEC_E_INTERNAL_ERROR; if (size <= 0) return SEC_E_INTERNAL_ERROR;
ctx->com_buf_offset += size; com_buf->offset += size;
newline = memchr( ctx->com_buf, '\n', ctx->com_buf_offset ); newline = memchr( com_buf->buffer, '\n', com_buf->offset );
} while (!newline); } while (!newline);
/* if there's a newline character, and we read more than that newline, we have to store the offset so we can /* if there's a newline character, and we read more than that newline, we have to store the offset so we can
preserve the additional data */ preserve the additional data */
if (newline != ctx->com_buf + ctx->com_buf_offset) *offset = (ctx->com_buf + ctx->com_buf_offset) - (newline + 1); if (newline != com_buf->buffer + com_buf->offset) *offset = (com_buf->buffer + com_buf->offset) - (newline + 1);
else *offset = 0; else *offset = 0;
*newline = 0; *newline = 0;
@ -86,6 +99,7 @@ static NTSTATUS ntlm_chat( void *args )
{ {
struct chat_params *params = args; struct chat_params *params = args;
struct ntlm_ctx *ctx = params->ctx; struct ntlm_ctx *ctx = params->ctx;
struct com_buf *com_buf;
SECURITY_STATUS status = SEC_E_OK; SECURITY_STATUS status = SEC_E_OK;
unsigned int offset; unsigned int offset;
@ -93,19 +107,20 @@ static NTSTATUS ntlm_chat( void *args )
write( ctx->pipe_out, "\n", 1 ); write( ctx->pipe_out, "\n", 1 );
if ((status = read_line( ctx, &offset )) != SEC_E_OK) return status; if ((status = read_line( ctx, &offset )) != SEC_E_OK) return status;
*params->retlen = strlen( ctx->com_buf ); com_buf = ctx->com_buf;
*params->retlen = strlen( com_buf->buffer );
if (*params->retlen > params->buflen) return SEC_E_BUFFER_TOO_SMALL; if (*params->retlen > params->buflen) return SEC_E_BUFFER_TOO_SMALL;
if (*params->retlen < 2) return SEC_E_ILLEGAL_MESSAGE; if (*params->retlen < 2) return SEC_E_ILLEGAL_MESSAGE;
if (!strncmp( ctx->com_buf, "ERR", 3 )) return SEC_E_INVALID_TOKEN; if (!strncmp( com_buf->buffer, "ERR", 3 )) return SEC_E_INVALID_TOKEN;
memcpy( params->buf, ctx->com_buf, *params->retlen + 1 ); memcpy( params->buf, com_buf->buffer, *params->retlen + 1 );
if (!offset) ctx->com_buf_offset = 0; if (!offset) com_buf->offset = 0;
else else
{ {
memmove( ctx->com_buf, ctx->com_buf + ctx->com_buf_offset, offset ); memmove( com_buf->buffer, com_buf->buffer + com_buf->offset, offset );
ctx->com_buf_offset = offset; com_buf->offset = offset;
} }
return SEC_E_OK; return SEC_E_OK;
@ -115,6 +130,7 @@ static NTSTATUS ntlm_cleanup( void *args )
{ {
struct cleanup_params *params = args; struct cleanup_params *params = args;
struct ntlm_ctx *ctx = params->ctx; struct ntlm_ctx *ctx = params->ctx;
struct com_buf *com_buf = ctx->com_buf;
if (!ctx || (ctx->mode != MODE_CLIENT && ctx->mode != MODE_SERVER)) return STATUS_INVALID_HANDLE; if (!ctx || (ctx->mode != MODE_CLIENT && ctx->mode != MODE_SERVER)) return STATUS_INVALID_HANDLE;
ctx->mode = MODE_INVALID; ctx->mode = MODE_INVALID;
@ -131,7 +147,8 @@ static NTSTATUS ntlm_cleanup( void *args )
} while (ret < 0 && errno == EINTR); } while (ret < 0 && errno == EINTR);
} }
free( ctx->com_buf ); if (com_buf) free( com_buf->buffer );
free( com_buf );
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }

View File

@ -57,6 +57,8 @@ struct arc4_info
#define FLAG_NEGOTIATE_NTLM2 0x00080000 #define FLAG_NEGOTIATE_NTLM2 0x00080000
#define FLAG_NEGOTIATE_KEY_EXCHANGE 0x40000000 #define FLAG_NEGOTIATE_KEY_EXCHANGE 0x40000000
struct com_buf;
struct ntlm_ctx struct ntlm_ctx
{ {
enum mode mode; enum mode mode;
@ -64,11 +66,9 @@ struct ntlm_ctx
unsigned int attrs; unsigned int attrs;
int pipe_in; int pipe_in;
int pipe_out; int pipe_out;
char *com_buf;
unsigned int com_buf_size;
unsigned int com_buf_offset;
char session_key[16]; char session_key[16];
unsigned int flags; unsigned int flags;
struct com_buf *com_buf;
struct struct
{ {
struct struct