Commit d6d32434 authored by Alexandre Julliard's avatar Alexandre Julliard

msv1_0: Convert the Unix library to the __wine_unix_call interface.

parent 9a51a9c4
MODULE = msv1_0.dll
IMPORTS = netapi32 advapi32
EXTRALIBS = -Wl,--subsystem,unixlib
EXTRADLLFLAGS = -mno-cygwin
......
......@@ -39,11 +39,36 @@
WINE_DEFAULT_DEBUG_CHANNEL(ntlm);
static HINSTANCE instance;
static ULONG ntlm_package_id;
static LSA_DISPATCH_TABLE lsa_dispatch;
const struct ntlm_funcs *ntlm_funcs = NULL;
static unixlib_handle_t ntlm_handle;
static NTSTATUS ntlm_check_version(void)
{
return __wine_unix_call( ntlm_handle, unix_check_version, NULL );
}
static void ntlm_cleanup( struct ntlm_ctx *ctx )
{
struct cleanup_params params = { ctx };
__wine_unix_call( ntlm_handle, unix_cleanup, &params );
}
static NTSTATUS ntlm_chat( struct ntlm_ctx *ctx, char *buf, unsigned int buflen, unsigned int *retlen )
{
struct chat_params params = { ctx, buf, buflen, retlen };
return __wine_unix_call( ntlm_handle, unix_chat, &params );
}
static NTSTATUS ntlm_fork( struct ntlm_ctx *ctx, char **argv )
{
struct fork_params params = { ctx, argv };
return __wine_unix_call( ntlm_handle, unix_fork, &params );
}
#define NTLM_CAPS \
( SECPKG_FLAG_INTEGRITY \
......@@ -91,7 +116,7 @@ static NTSTATUS NTAPI ntlm_LsaApInitializePackage( ULONG package_id, LSA_DISPATC
TRACE( "%08x, %p, %s, %s, %p\n", package_id, dispatch, debugstr_as(database), debugstr_as(confidentiality),
package_name );
if (!ntlm_funcs && __wine_init_unix_lib( instance, DLL_PROCESS_ATTACH, NULL, &ntlm_funcs ))
if (ntlm_check_version())
{
ERR( "no NTLM support, expect problems\n" );
return STATUS_UNSUCCESSFUL;
......@@ -114,7 +139,7 @@ static NTSTATUS NTAPI ntlm_SpInitialize( ULONG_PTR package_id, SECPKG_PARAMETERS
{
TRACE( "%lu, %p, %p\n", package_id, params, lsa_function_table );
if (!ntlm_funcs && __wine_init_unix_lib( instance, DLL_PROCESS_ATTACH, NULL, &ntlm_funcs ))
if (ntlm_check_version())
{
ERR( "no NTLM support, expect problems\n" );
return STATUS_UNSUCCESSFUL;
......@@ -657,7 +682,7 @@ static NTSTATUS NTAPI ntlm_SpInitLsaModeContext( LSA_SEC_HANDLE cred_handle, LSA
if (!(ctx = calloc( 1, sizeof(*ctx) ))) goto done;
if ((status = ntlm_funcs->fork( ctx, argv )) != SEC_E_OK) goto done;
if ((status = ntlm_fork( ctx, argv )) != SEC_E_OK) goto done;
status = SEC_E_INSUFFICIENT_MEMORY;
ctx->mode = MODE_CLIENT;
......@@ -697,7 +722,7 @@ static NTSTATUS NTAPI ntlm_SpInitLsaModeContext( LSA_SEC_HANDLE cred_handle, LSA
if (!password && !cred->password)
{
strcpy( buf, "OK" );
if ((status = ntlm_funcs->chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
if ((status = ntlm_chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
/* if the helper replied with "PW" using cached credentials failed */
if (!strncmp( buf, "PW", 2 ))
......@@ -714,19 +739,19 @@ static NTSTATUS NTAPI ntlm_SpInitLsaModeContext( LSA_SEC_HANDLE cred_handle, LSA
}
TRACE( "sending to ntlm_auth: %s\n", debugstr_a(buf) );
if ((status = ntlm_funcs->chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
if ((status = ntlm_chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
TRACE( "ntlm_auth returned %s\n", debugstr_a(buf) );
if (strlen( want_flags ) > 2)
{
TRACE( "want flags are %s\n", debugstr_a(want_flags) );
strcpy( buf, want_flags );
if ((status = ntlm_funcs->chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
if ((status = ntlm_chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
if (!strncmp( buf, "BH", 2 )) ERR( "ntlm_auth doesn't understand new command set\n" );
}
strcpy( buf, "YR" );
if ((status = ntlm_funcs->chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
if ((status = ntlm_chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
TRACE( "ntlm_auth returned %s\n", buf );
if (strncmp( buf, "YR ", 3 ))
{
......@@ -765,7 +790,7 @@ static NTSTATUS NTAPI ntlm_SpInitLsaModeContext( LSA_SEC_HANDLE cred_handle, LSA
encode_base64( bin, bin_len, buf + 3 );
TRACE( "server sent: %s\n", debugstr_a(buf) );
if ((status = ntlm_funcs->chat( ctx, buf, NTLM_MAX_BUF, &len ))) goto done;
if ((status = ntlm_chat( ctx, buf, NTLM_MAX_BUF, &len ))) goto done;
TRACE( "ntlm_auth returned: %s\n", debugstr_a(buf) );
if (strncmp( buf, "KK ", 3 ) && strncmp( buf, "AF ", 3 ))
......@@ -815,12 +840,12 @@ static NTSTATUS NTAPI ntlm_SpInitLsaModeContext( LSA_SEC_HANDLE cred_handle, LSA
if (status == SEC_E_OK)
{
strcpy( buf, "GF" );
if ((status = ntlm_funcs->chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
if ((status = ntlm_chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
if (len < 3) ctx->flags = 0;
else sscanf( buf + 3, "%x", &ctx->flags );
strcpy( buf, "GK" );
if ((status = ntlm_funcs->chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
if ((status = ntlm_chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
if (!strncmp( buf, "BH", 2 )) TRACE( "no key negotiated\n" );
else if (!strncmp( buf, "GK ", 3 ))
......@@ -842,7 +867,7 @@ static NTSTATUS NTAPI ntlm_SpInitLsaModeContext( LSA_SEC_HANDLE cred_handle, LSA
done:
if (status != SEC_E_OK && status != SEC_I_CONTINUE_NEEDED)
{
ntlm_funcs->cleanup( ctx );
ntlm_cleanup( ctx );
free( ctx );
}
free( username );
......@@ -903,7 +928,7 @@ static NTSTATUS NTAPI ntlm_SpAcceptLsaModeContext( LSA_SEC_HANDLE cred_handle, L
argv[0] = (char *)"ntlm_auth";
argv[1] = (char *)"--helper-protocol=squid-2.5-ntlmssp";
argv[2] = NULL;
if ((status = ntlm_funcs->fork( ctx, argv )) != SEC_E_OK) goto done;
if ((status = ntlm_fork( ctx, argv )) != SEC_E_OK) goto done;
ctx->mode = MODE_SERVER;
if (!(want_flags = malloc( 73 )))
......@@ -930,7 +955,7 @@ static NTSTATUS NTAPI ntlm_SpAcceptLsaModeContext( LSA_SEC_HANDLE cred_handle, L
{
TRACE( "want flags are %s\n", debugstr_a(want_flags) );
strcpy( buf, want_flags );
if ((status = ntlm_funcs->chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
if ((status = ntlm_chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
if (!strncmp( buf, "BH", 2 )) ERR( "ntlm_auth doesn't understand new command set\n" );
}
......@@ -938,7 +963,7 @@ static NTSTATUS NTAPI ntlm_SpAcceptLsaModeContext( LSA_SEC_HANDLE cred_handle, L
strcpy( buf, "YR " );
encode_base64( bin, bin_len, buf + 3 );
if ((status = ntlm_funcs->chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
if ((status = ntlm_chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
TRACE( "ntlm_auth returned %s\n", buf );
if (strncmp( buf, "TT ", 3))
{
......@@ -986,7 +1011,7 @@ static NTSTATUS NTAPI ntlm_SpAcceptLsaModeContext( LSA_SEC_HANDLE cred_handle, L
encode_base64( bin, bin_len, buf + 3 );
TRACE( "client sent %s\n", debugstr_a(buf) );
if ((status = ntlm_funcs->chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
if ((status = ntlm_chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
TRACE( "ntlm_auth returned %s\n", debugstr_a(buf) );
/* At this point, we get a NA if the user didn't authenticate, but a BH if ntlm_auth could not
......@@ -1017,12 +1042,12 @@ static NTSTATUS NTAPI ntlm_SpAcceptLsaModeContext( LSA_SEC_HANDLE cred_handle, L
output->pBuffers[0].cbBuffer = 0;
strcpy( buf, "GF" );
if ((status = ntlm_funcs->chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
if ((status = ntlm_chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
if (len < 3) ctx->flags = 0;
else sscanf( buf + 3, "%x", &ctx->flags );
strcpy( buf, "GK" );
if ((status = ntlm_funcs->chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
if ((status = ntlm_chat( ctx, buf, NTLM_MAX_BUF, &len )) != SEC_E_OK) goto done;
if (!strncmp( buf, "BH", 2 )) TRACE( "no key negotiated\n" );
else if (!strncmp( buf, "GK ", 3 ))
......@@ -1058,7 +1083,7 @@ static NTSTATUS NTAPI ntlm_SpAcceptLsaModeContext( LSA_SEC_HANDLE cred_handle, L
done:
if (status != SEC_E_OK && status != SEC_I_CONTINUE_NEEDED)
{
ntlm_funcs->cleanup( ctx );
ntlm_cleanup( ctx );
free( ctx );
}
free( buf );
......@@ -1076,7 +1101,7 @@ static NTSTATUS NTAPI ntlm_SpDeleteContext( LSA_SEC_HANDLE handle )
TRACE( "%lx\n", handle );
if (!ctx) return SEC_E_INVALID_HANDLE;
ntlm_funcs->cleanup( ctx );
ntlm_cleanup( ctx );
free( ctx );
return SEC_E_OK;
}
......@@ -1549,11 +1574,11 @@ BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, void *reserved )
switch (reason)
{
case DLL_PROCESS_ATTACH:
instance = hinst;
if (NtQueryVirtualMemory( GetCurrentProcess(), hinst, MemoryWineUnixFuncs,
&ntlm_handle, sizeof(ntlm_handle), NULL ))
return FALSE;
DisableThreadLibraryCalls( hinst );
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
......@@ -82,22 +82,24 @@ static SECURITY_STATUS read_line( struct ntlm_ctx *ctx, unsigned int *offset )
return SEC_E_OK;
}
static SECURITY_STATUS CDECL ntlm_chat( struct ntlm_ctx *ctx, char *buf, unsigned int buflen, unsigned int *retlen )
static NTSTATUS ntlm_chat( void *args )
{
struct chat_params *params = args;
struct ntlm_ctx *ctx = params->ctx;
SECURITY_STATUS status = SEC_E_OK;
unsigned int offset;
write( ctx->pipe_out, buf, strlen(buf) );
write( ctx->pipe_out, params->buf, strlen(params->buf) );
write( ctx->pipe_out, "\n", 1 );
if ((status = read_line( ctx, &offset )) != SEC_E_OK) return status;
*retlen = strlen( ctx->com_buf );
*params->retlen = strlen( ctx->com_buf );
if (*retlen > buflen) return SEC_E_BUFFER_TOO_SMALL;
if (*retlen < 2) return SEC_E_ILLEGAL_MESSAGE;
if (*params->retlen > params->buflen) return SEC_E_BUFFER_TOO_SMALL;
if (*params->retlen < 2) return SEC_E_ILLEGAL_MESSAGE;
if (!strncmp( ctx->com_buf, "ERR", 3 )) return SEC_E_INVALID_TOKEN;
memcpy( buf, ctx->com_buf, *retlen + 1 );
memcpy( params->buf, ctx->com_buf, *params->retlen + 1 );
if (!offset) ctx->com_buf_offset = 0;
else
......@@ -109,9 +111,12 @@ static SECURITY_STATUS CDECL ntlm_chat( struct ntlm_ctx *ctx, char *buf, unsigne
return SEC_E_OK;
}
static void CDECL ntlm_cleanup( struct ntlm_ctx *ctx )
static NTSTATUS ntlm_cleanup( void *args )
{
if (!ctx || (ctx->mode != MODE_CLIENT && ctx->mode != MODE_SERVER)) return;
struct cleanup_params *params = args;
struct ntlm_ctx *ctx = params->ctx;
if (!ctx || (ctx->mode != MODE_CLIENT && ctx->mode != MODE_SERVER)) return STATUS_INVALID_HANDLE;
ctx->mode = MODE_INVALID;
/* closing stdin will terminate ntlm_auth */
......@@ -127,10 +132,13 @@ static void CDECL ntlm_cleanup( struct ntlm_ctx *ctx )
}
free( ctx->com_buf );
return STATUS_SUCCESS;
}
static SECURITY_STATUS CDECL ntlm_fork( struct ntlm_ctx *ctx, char **argv )
static NTSTATUS ntlm_fork( void *args )
{
struct fork_params *params = args;
struct ntlm_ctx *ctx = params->ctx;
int pipe_in[2], pipe_out[2];
#ifdef HAVE_PIPE2
......@@ -165,7 +173,7 @@ static SECURITY_STATUS CDECL ntlm_fork( struct ntlm_ctx *ctx, char **argv )
close( pipe_in[0] );
close( pipe_in[1] );
execvp( argv[0], argv );
execvp( params->argv[0], params->argv );
write( 1, "BH\n", 3 );
_exit( 1 );
......@@ -185,17 +193,18 @@ static SECURITY_STATUS CDECL ntlm_fork( struct ntlm_ctx *ctx, char **argv )
#define NTLM_AUTH_MINOR_VERSION 0
#define NTLM_AUTH_MICRO_VERSION 25
static BOOL check_version( void )
static NTSTATUS ntlm_check_version( void *args )
{
struct ntlm_ctx ctx = { 0 };
char *argv[3], buf[80];
BOOL ret = FALSE;
NTSTATUS status = STATUS_DLL_NOT_FOUND;
struct fork_params params = { &ctx, argv };
int len;
argv[0] = (char *)"ntlm_auth";
argv[1] = (char *)"--version";
argv[2] = NULL;
if (ntlm_fork( &ctx, argv ) != SEC_E_OK) return FALSE;
if (ntlm_fork( &params ) != SEC_E_OK) return status;
if ((len = read( ctx.pipe_in, buf, sizeof(buf) - 1 )) > 8)
{
......@@ -213,30 +222,23 @@ static BOOL check_version( void )
micro >= NTLM_AUTH_MICRO_VERSION)))
{
TRACE( "detected ntlm_auth version %d.%d.%d\n", major, minor, micro );
ret = TRUE;
status = STATUS_SUCCESS;
}
}
}
if (!ret) ERR_(winediag)( "ntlm_auth was not found or is outdated. "
if (status) ERR_(winediag)( "ntlm_auth was not found or is outdated. "
"Make sure that ntlm_auth >= %d.%d.%d is in your path. "
"Usually, you can find it in the winbind package of your distribution.\n",
NTLM_AUTH_MAJOR_VERSION, NTLM_AUTH_MINOR_VERSION, NTLM_AUTH_MICRO_VERSION );
ntlm_cleanup( &ctx );
return ret;
return status;
}
static const struct ntlm_funcs funcs =
const unixlib_entry_t __wine_unix_call_funcs[] =
{
ntlm_chat,
ntlm_cleanup,
ntlm_fork,
ntlm_check_version,
};
NTSTATUS CDECL __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out )
{
if (reason != DLL_PROCESS_ATTACH) return STATUS_SUCCESS;
if (!check_version()) return STATUS_DLL_NOT_FOUND;
*(const struct ntlm_funcs **)ptr_out = &funcs;
return STATUS_SUCCESS;
}
......@@ -19,6 +19,8 @@
#include <sys/types.h>
#include "wine/unixlib.h"
enum sign_direction
{
SIGN_SEND,
......@@ -88,11 +90,30 @@ struct ntlm_ctx
} crypt;
};
struct ntlm_funcs
struct chat_params
{
struct ntlm_ctx *ctx;
char *buf;
unsigned int buflen;
unsigned int *retlen;
};
struct cleanup_params
{
SECURITY_STATUS (CDECL *chat)( struct ntlm_ctx *, char *, unsigned int, unsigned int * );
void (CDECL *cleanup)( struct ntlm_ctx * );
SECURITY_STATUS (CDECL *fork)( struct ntlm_ctx *, char ** );
struct ntlm_ctx *ctx;
};
extern const struct ntlm_funcs *ntlm_funcs;
struct fork_params
{
struct ntlm_ctx *ctx;
char **argv;
};
enum ntlm_funcs
{
unix_chat,
unix_cleanup,
unix_fork,
unix_check_version,
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment