secur32: Rewrote NTLM tests in a more flexible way.
This commit is contained in:
parent
4fabe112d7
commit
49943c9cf4
|
@ -35,6 +35,17 @@ static PSecurityFunctionTableA (SEC_ENTRY * pInitSecurityInterfaceA)(void);
|
|||
static SECURITY_STATUS (SEC_ENTRY * pEnumerateSecurityPackagesA)(PULONG, PSecPkgInfoA*);
|
||||
static SECURITY_STATUS (SEC_ENTRY * pFreeContextBuffer)(PVOID pv);
|
||||
static SECURITY_STATUS (SEC_ENTRY * pQuerySecurityPackageInfoA)(SEC_CHAR*, PSecPkgInfoA*);
|
||||
static SECURITY_STATUS (SEC_ENTRY * pAcquireCredentialsHandleA)(SEC_CHAR*, SEC_CHAR*,
|
||||
ULONG, PLUID, PVOID, SEC_GET_KEY_FN, PVOID, PCredHandle, PTimeStamp);
|
||||
static SECURITY_STATUS (SEC_ENTRY * pInitializeSecurityContextA)(PCredHandle, PCtxtHandle,
|
||||
SEC_CHAR*, ULONG, ULONG, ULONG, PSecBufferDesc, ULONG,
|
||||
PCtxtHandle, PSecBufferDesc, PULONG, PTimeStamp);
|
||||
static SECURITY_STATUS (SEC_ENTRY * pCompleteAuthToken)(PCtxtHandle, PSecBufferDesc);
|
||||
static SECURITY_STATUS (SEC_ENTRY * pAcceptSecurityContext)(PCredHandle, PCtxtHandle,
|
||||
PSecBufferDesc, ULONG, ULONG, PCtxtHandle, PSecBufferDesc,
|
||||
PULONG, PTimeStamp);
|
||||
static SECURITY_STATUS (SEC_ENTRY * pFreeCredentialsHandle)(PCredHandle);
|
||||
static SECURITY_STATUS (SEC_ENTRY * pDeleteSecurityContext)(PCtxtHandle);
|
||||
|
||||
void InitFunctionPtrs(void)
|
||||
{
|
||||
|
@ -46,14 +57,20 @@ void InitFunctionPtrs(void)
|
|||
pInitSecurityInterfaceA = (PVOID)GetProcAddress(secdll, "InitSecurityInterfaceA");
|
||||
pEnumerateSecurityPackagesA = (PVOID)GetProcAddress(secdll, "EnumerateSecurityPackagesA");
|
||||
pFreeContextBuffer = (PVOID)GetProcAddress(secdll, "FreeContextBuffer");
|
||||
pQuerySecurityPackageInfoA = (PVOID)GetProcAddress(secdll, "QuerySecurityPackageInfo");
|
||||
pQuerySecurityPackageInfoA = (PVOID)GetProcAddress(secdll, "QuerySecurityPackageInfoA");
|
||||
pAcquireCredentialsHandleA = (PVOID)GetProcAddress(secdll, "AcquireCredentialsHandleA");
|
||||
pInitializeSecurityContextA = (PVOID)GetProcAddress(secdll, "InitializeSecurityContextA");
|
||||
pCompleteAuthToken = (PVOID)GetProcAddress(secdll, "CompleteAuthToken");
|
||||
pAcceptSecurityContext = (PVOID)GetProcAddress(secdll, "AcceptSecurityContext");
|
||||
pFreeCredentialsHandle = (PVOID)GetProcAddress(secdll, "FreeCredentialsHandle");
|
||||
pDeleteSecurityContext = (PVOID)GetProcAddress(secdll, "DeleteSecurityContext");
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*/
|
||||
/* General helper functions */
|
||||
|
||||
static const char* getSecStatusError(SECURITY_STATUS status)
|
||||
static const char* getSecError(SECURITY_STATUS status)
|
||||
{
|
||||
#define _SEC_ERR(x) case (x): return #x;
|
||||
switch(status)
|
||||
|
@ -72,6 +89,10 @@ static const char* getSecStatusError(SECURITY_STATUS status)
|
|||
_SEC_ERR(SEC_E_QOP_NOT_SUPPORTED);
|
||||
_SEC_ERR(SEC_E_NO_IMPERSONATION);
|
||||
_SEC_ERR(SEC_I_CONTINUE_NEEDED);
|
||||
_SEC_ERR(SEC_E_BUFFER_TOO_SMALL);
|
||||
_SEC_ERR(SEC_E_ILLEGAL_MESSAGE);
|
||||
_SEC_ERR(SEC_E_LOGON_DENIED);
|
||||
_SEC_ERR(SEC_E_NO_CREDENTIALS);
|
||||
default:
|
||||
trace("Error = %ld\n", status);
|
||||
return "Unknown error";
|
||||
|
@ -92,133 +113,270 @@ static SECURITY_STATUS setupPackageA(SEC_CHAR *p_package_name,
|
|||
}
|
||||
|
||||
/*---------------------------------------------------------*/
|
||||
/* Helper for testAuthentication */
|
||||
/* Helper for testAuth* */
|
||||
|
||||
static int genClientContext(PBYTE in, DWORD in_count, PBYTE out,
|
||||
DWORD *out_count, BOOL *done, char *target, CredHandle *cred_handle,
|
||||
PCtxtHandle ctxt_handle, PSecurityFunctionTable sft)
|
||||
SECURITY_STATUS setupClient(PCredHandle cred, const char *user,
|
||||
const char *pass, const char *domain, char *provider)
|
||||
{
|
||||
SECURITY_STATUS sec_status;
|
||||
TimeStamp ttl;
|
||||
SecBufferDesc in_sec_buff_desc, out_sec_buff_desc;
|
||||
SecBuffer in_sec_buff, out_sec_buff;
|
||||
ULONG context_attr;
|
||||
SECURITY_STATUS ret;
|
||||
PSEC_WINNT_AUTH_IDENTITY identity = NULL;
|
||||
TimeStamp ttl;
|
||||
|
||||
if(in == NULL){
|
||||
sec_status = (sft->AcquireCredentialsHandle)(NULL, "Negotiate",
|
||||
SECPKG_CRED_OUTBOUND, NULL, NULL, NULL, NULL, cred_handle,
|
||||
&ttl);
|
||||
ok(sec_status == SEC_E_OK,
|
||||
"Client AcquireCredentialsHandle should not return %s\n",
|
||||
getSecStatusError(sec_status) );
|
||||
trace("Running setupClient\n");
|
||||
|
||||
if(user != NULL)
|
||||
{
|
||||
identity = HeapAlloc(GetProcessHeap(), 0,
|
||||
sizeof(SEC_WINNT_AUTH_IDENTITY_A));
|
||||
|
||||
memset( identity, 0, sizeof(identity));
|
||||
identity->Domain = HeapAlloc(GetProcessHeap(), 0,
|
||||
lstrlenA( domain ? domain :"") + 1);
|
||||
lstrcpyA((char*)identity->Domain, domain ? domain :"");
|
||||
identity->DomainLength = domain ? lstrlenA(domain): 0;
|
||||
identity->User = HeapAlloc(GetProcessHeap(), 0,
|
||||
lstrlenA( user ? user :"") + 1);
|
||||
lstrcpyA((char*)identity->User, user ? user :"");
|
||||
identity->UserLength = user ? lstrlenA(user) : 0;
|
||||
identity->Password = HeapAlloc(GetProcessHeap(), 0,
|
||||
lstrlenA( pass ? pass :"") + 1);
|
||||
lstrcpyA((char*)identity->Password, pass ? pass : "");
|
||||
identity->PasswordLength = pass ? lstrlenA(pass): 0;
|
||||
identity->Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
|
||||
}
|
||||
|
||||
out_sec_buff_desc.ulVersion = 0;
|
||||
out_sec_buff_desc.cBuffers = 1;
|
||||
out_sec_buff_desc.pBuffers = &out_sec_buff;
|
||||
|
||||
out_sec_buff.cbBuffer = *out_count;
|
||||
out_sec_buff.BufferType = SECBUFFER_TOKEN;
|
||||
out_sec_buff.pvBuffer = out;
|
||||
|
||||
if(in){
|
||||
/* we got some data, initialize input buffer, too. */
|
||||
in_sec_buff_desc.ulVersion = 0;
|
||||
in_sec_buff_desc.cBuffers = 1;
|
||||
in_sec_buff_desc.pBuffers = &in_sec_buff;
|
||||
|
||||
in_sec_buff.cbBuffer = in_count;
|
||||
in_sec_buff.BufferType = SECBUFFER_TOKEN;
|
||||
in_sec_buff.pvBuffer = in;
|
||||
|
||||
sec_status = (sft->InitializeSecurityContext)( cred_handle, ctxt_handle,
|
||||
target,ISC_REQ_CONFIDENTIALITY, 0, SECURITY_NATIVE_DREP,
|
||||
&in_sec_buff_desc, 0, ctxt_handle, &out_sec_buff_desc,
|
||||
&context_attr, &ttl);
|
||||
|
||||
}
|
||||
else {
|
||||
sec_status = (sft->InitializeSecurityContext)( cred_handle, NULL,
|
||||
target, ISC_REQ_CONFIDENTIALITY, 0, SECURITY_NATIVE_DREP, NULL,
|
||||
0, ctxt_handle, &out_sec_buff_desc, &context_attr, &ttl);
|
||||
if((ret = pAcquireCredentialsHandleA(NULL, provider, SECPKG_CRED_OUTBOUND,
|
||||
NULL, identity, NULL, NULL, cred, &ttl)) != SEC_E_OK)
|
||||
{
|
||||
trace("AcquireCredentialsHandle() returned %s\n", getSecError(ret));
|
||||
}
|
||||
|
||||
ok(ret == SEC_E_OK, "AcquireCredentialsHande() returned %s\n",
|
||||
getSecError(ret));
|
||||
|
||||
if( (sec_status == SEC_I_COMPLETE_NEEDED) ||
|
||||
(sec_status == SEC_I_COMPLETE_AND_CONTINUE)){
|
||||
if(sft->CompleteAuthToken != NULL){
|
||||
sec_status = (sft->CompleteAuthToken)( ctxt_handle,
|
||||
&out_sec_buff_desc);
|
||||
ok((sec_status == SEC_E_OK)||(sec_status == SEC_I_CONTINUE_NEEDED),
|
||||
"CompleteAuthToken should not return %s\n",
|
||||
getSecStatusError(sec_status));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*out_count = out_sec_buff.cbBuffer;
|
||||
*done = !( (sec_status == SEC_I_CONTINUE_NEEDED) ||
|
||||
(sec_status == SEC_I_COMPLETE_AND_CONTINUE));
|
||||
|
||||
return 0;
|
||||
if( identity != NULL)
|
||||
{
|
||||
if(identity->Domain != 0)
|
||||
HeapFree(GetProcessHeap(), 0, identity->Domain);
|
||||
if(identity->User != 0)
|
||||
HeapFree(GetProcessHeap(), 0, identity->User);
|
||||
if(identity->Password != 0)
|
||||
HeapFree(GetProcessHeap(), 0, identity->Password);
|
||||
HeapFree(GetProcessHeap(), 0, identity);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int genServerContext(PBYTE in, DWORD in_count, PBYTE out,
|
||||
DWORD *out_count, BOOL *done, BOOL *new_conn, CredHandle *cred_handle,
|
||||
PCtxtHandle ctxt_handle, PSecurityFunctionTable sft)
|
||||
/**********************************************************************/
|
||||
|
||||
SECURITY_STATUS setupServer(PCredHandle cred, char *provider)
|
||||
{
|
||||
SECURITY_STATUS sec_status;
|
||||
TimeStamp ttl;
|
||||
SecBufferDesc in_sec_buff_desc, out_sec_buff_desc;
|
||||
SecBuffer in_sec_buff, out_sec_buff;
|
||||
DWORD ctxt_attr;
|
||||
SECURITY_STATUS ret;
|
||||
TimeStamp ttl;
|
||||
|
||||
out_sec_buff_desc.ulVersion = 0;
|
||||
out_sec_buff_desc.cBuffers = 1;
|
||||
out_sec_buff_desc.pBuffers = &out_sec_buff;
|
||||
|
||||
out_sec_buff.cbBuffer = *out_count;
|
||||
out_sec_buff.BufferType = SECBUFFER_TOKEN;
|
||||
out_sec_buff.pvBuffer = out;
|
||||
|
||||
in_sec_buff_desc.ulVersion = 0;
|
||||
in_sec_buff_desc.cBuffers = 1;
|
||||
in_sec_buff_desc.pBuffers = &in_sec_buff;
|
||||
|
||||
in_sec_buff.cbBuffer = in_count;
|
||||
in_sec_buff.BufferType = SECBUFFER_TOKEN;
|
||||
in_sec_buff.pvBuffer = in;
|
||||
|
||||
sec_status = (sft->AcceptSecurityContext)( cred_handle,
|
||||
*new_conn ? NULL : ctxt_handle, /* maybe use an if here? */
|
||||
&in_sec_buff_desc, 0, SECURITY_NATIVE_DREP,
|
||||
ctxt_handle, &out_sec_buff_desc, &ctxt_attr, &ttl);
|
||||
|
||||
ok((sec_status == SEC_E_OK) || (sec_status == SEC_I_CONTINUE_NEEDED),
|
||||
"AcceptSecurityContext returned %s\n",
|
||||
getSecStatusError(sec_status));
|
||||
|
||||
if( (sec_status == SEC_I_COMPLETE_NEEDED) ||
|
||||
(sec_status == SEC_I_COMPLETE_AND_CONTINUE)){
|
||||
if(sft->CompleteAuthToken != NULL){
|
||||
sec_status = (sft->CompleteAuthToken)( ctxt_handle,
|
||||
&out_sec_buff_desc);
|
||||
|
||||
ok((sec_status ==SEC_E_OK) || (sec_status ==SEC_I_CONTINUE_NEEDED),
|
||||
"CompleteAuthToken should not return %s\n",
|
||||
getSecStatusError(sec_status));
|
||||
}
|
||||
trace("Running setupServer\n");
|
||||
|
||||
if((ret = pAcquireCredentialsHandleA(NULL, provider, SECPKG_CRED_INBOUND,
|
||||
NULL, NULL, NULL, NULL, cred, &ttl)) != SEC_E_OK)
|
||||
{
|
||||
trace("AcquireCredentialsHandle() returned %s\n", getSecError(ret));
|
||||
}
|
||||
|
||||
*out_count = out_sec_buff.cbBuffer;
|
||||
*done = !( (sec_status == SEC_I_CONTINUE_NEEDED) ||
|
||||
(sec_status == SEC_I_COMPLETE_AND_CONTINUE));
|
||||
ok(ret == SEC_E_OK, "AcquireCredentialsHande() returned %s\n",
|
||||
getSecError(ret));
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
SECURITY_STATUS setupBuffers(PSecBufferDesc *new_in_buf,
|
||||
PSecBufferDesc *new_out_buf)
|
||||
{
|
||||
int size = MAX_MESSAGE;
|
||||
PBYTE buffer = NULL;
|
||||
PSecBufferDesc in_buf = HeapAlloc(GetProcessHeap(), 0,
|
||||
sizeof(SecBufferDesc));
|
||||
PSecBufferDesc out_buf = HeapAlloc(GetProcessHeap(), 0,
|
||||
sizeof(PSecBufferDesc));
|
||||
|
||||
if(in_buf != NULL)
|
||||
{
|
||||
PSecBuffer sec_buffer = HeapAlloc(GetProcessHeap(), 0,
|
||||
sizeof(SecBuffer));
|
||||
if(sec_buffer == NULL){
|
||||
trace("in_buf: sec_buffer == NULL");
|
||||
return SEC_E_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
|
||||
buffer = HeapAlloc(GetProcessHeap(), 0, size);
|
||||
|
||||
if(buffer == NULL){
|
||||
trace("in_buf: buffer == NULL");
|
||||
return SEC_E_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
|
||||
in_buf->ulVersion = SECBUFFER_VERSION;
|
||||
in_buf->cBuffers = 1;
|
||||
in_buf->pBuffers = sec_buffer;
|
||||
|
||||
sec_buffer->cbBuffer = size;
|
||||
sec_buffer->BufferType = SECBUFFER_TOKEN;
|
||||
sec_buffer->pvBuffer = buffer;
|
||||
*new_in_buf = in_buf;
|
||||
}
|
||||
else
|
||||
{
|
||||
trace("HeapAlloc in_buf returned NULL\n");
|
||||
return SEC_E_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
|
||||
if(out_buf != NULL)
|
||||
{
|
||||
PSecBuffer sec_buffer = HeapAlloc(GetProcessHeap(), 0,
|
||||
sizeof(SecBuffer));
|
||||
PBYTE buffer = NULL;
|
||||
|
||||
if(sec_buffer == NULL){
|
||||
trace("out_buf: sec_buffer == NULL");
|
||||
return SEC_E_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
|
||||
buffer = HeapAlloc(GetProcessHeap(), 0, size);
|
||||
|
||||
if(buffer == NULL){
|
||||
trace("out_buf: buffer == NULL");
|
||||
return SEC_E_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
|
||||
out_buf->ulVersion = SECBUFFER_VERSION;
|
||||
out_buf->cBuffers = 1;
|
||||
out_buf->pBuffers = sec_buffer;
|
||||
|
||||
sec_buffer->cbBuffer = 0;
|
||||
sec_buffer->BufferType = SECBUFFER_TOKEN;
|
||||
sec_buffer->pvBuffer = buffer;
|
||||
*new_out_buf = out_buf;
|
||||
}
|
||||
else
|
||||
{
|
||||
trace("HeapAlloc out_buf returned NULL\n");
|
||||
return SEC_E_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
|
||||
return SEC_E_OK;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
void cleanupBuffers(PSecBufferDesc in_buf, PSecBufferDesc out_buf)
|
||||
{
|
||||
int i;
|
||||
|
||||
if(in_buf != NULL)
|
||||
{
|
||||
for(i = 0; i < in_buf->cBuffers; ++i)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, in_buf->pBuffers[i].pvBuffer);
|
||||
}
|
||||
HeapFree(GetProcessHeap(), 0, in_buf->pBuffers);
|
||||
HeapFree(GetProcessHeap(), 0, in_buf);
|
||||
}
|
||||
|
||||
if(out_buf != NULL)
|
||||
{
|
||||
for(i = 0; i < out_buf->cBuffers; ++i)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, out_buf->pBuffers[i].pvBuffer);
|
||||
}
|
||||
HeapFree(GetProcessHeap(), 0, out_buf->pBuffers);
|
||||
HeapFree(GetProcessHeap(), 0, out_buf);
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
SECURITY_STATUS runClient(PCredHandle cred, PCtxtHandle ctxt,
|
||||
PSecBufferDesc in_buf, PSecBufferDesc out_buf, BOOL first)
|
||||
{
|
||||
SECURITY_STATUS ret;
|
||||
ULONG req_attr = ISC_REQ_CONNECTION;
|
||||
ULONG ctxt_attr;
|
||||
TimeStamp ttl;
|
||||
|
||||
trace("Running the client the %s time.\n", first?"first":"second");
|
||||
|
||||
ret = pInitializeSecurityContextA(cred, first?NULL:ctxt, NULL, req_attr,
|
||||
0, SECURITY_NATIVE_DREP, first?NULL:in_buf, 0, ctxt, out_buf,
|
||||
&ctxt_attr, &ttl);
|
||||
|
||||
if(ret == SEC_I_COMPLETE_AND_CONTINUE || ret == SEC_I_COMPLETE_NEEDED)
|
||||
{
|
||||
pCompleteAuthToken(ctxt, out_buf);
|
||||
if(ret == SEC_I_COMPLETE_AND_CONTINUE)
|
||||
ret = SEC_I_CONTINUE_NEEDED;
|
||||
else if(ret == SEC_I_COMPLETE_NEEDED)
|
||||
ret = SEC_E_OK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
SECURITY_STATUS runServer(PCredHandle cred, PCtxtHandle ctxt,
|
||||
PSecBufferDesc in_buf, PSecBufferDesc out_buf, BOOL first)
|
||||
{
|
||||
SECURITY_STATUS ret;
|
||||
ULONG ctxt_attr;
|
||||
TimeStamp ttl;
|
||||
|
||||
trace("Running the server the %s time\n", first?"first":"second");
|
||||
|
||||
ret = pAcceptSecurityContext(cred, first?NULL:ctxt, in_buf, 0,
|
||||
SECURITY_NATIVE_DREP, ctxt, out_buf, &ctxt_attr, &ttl);
|
||||
|
||||
if(ret == SEC_I_COMPLETE_AND_CONTINUE || ret == SEC_I_COMPLETE_NEEDED)
|
||||
{
|
||||
pCompleteAuthToken(ctxt, out_buf);
|
||||
if(ret == SEC_I_COMPLETE_AND_CONTINUE)
|
||||
ret = SEC_I_CONTINUE_NEEDED;
|
||||
else if(ret == SEC_I_COMPLETE_NEEDED)
|
||||
ret = SEC_E_OK;
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
void communicate(PSecBufferDesc in_buf, PSecBufferDesc out_buf)
|
||||
{
|
||||
if(in_buf != NULL && out_buf != NULL)
|
||||
{
|
||||
trace("Running communicate.\n");
|
||||
if((in_buf->cBuffers >= 1) && (out_buf->cBuffers >= 1))
|
||||
{
|
||||
if((in_buf->pBuffers[0].pvBuffer != NULL) &&
|
||||
(out_buf->pBuffers[0].pvBuffer != NULL))
|
||||
{
|
||||
memset(out_buf->pBuffers[0].pvBuffer, 0, MAX_MESSAGE);
|
||||
|
||||
memcpy(out_buf->pBuffers[0].pvBuffer,
|
||||
in_buf->pBuffers[0].pvBuffer,
|
||||
in_buf->pBuffers[0].cbBuffer);
|
||||
|
||||
out_buf->pBuffers[0].cbBuffer = in_buf->pBuffers[0].cbBuffer;
|
||||
|
||||
memset(in_buf->pBuffers[0].pvBuffer, 0, MAX_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
/*--------------------------------------------------------- */
|
||||
/* The test functions */
|
||||
|
@ -301,30 +459,30 @@ static void testQuerySecurityPackageInfo(void)
|
|||
|
||||
/* Test with an existing package. Test should pass */
|
||||
|
||||
lstrcpy(sec_pkg_name, "Negotiate");
|
||||
lstrcpy(sec_pkg_name, "NTLM");
|
||||
|
||||
sec_status = setupPackageA(sec_pkg_name, &pkg_info);
|
||||
|
||||
ok(sec_status == SEC_E_OK,
|
||||
ok((sec_status == SEC_E_OK) || (sec_status == SEC_E_SECPKG_NOT_FOUND),
|
||||
"Return value of QuerySecurityPackageInfo() shouldn't be %s\n",
|
||||
getSecStatusError(sec_status) );
|
||||
ok(pkg_info != NULL,
|
||||
"QuerySecurityPackageInfo should give struct SecPkgInfo, but is NULL\n");
|
||||
|
||||
getSecError(sec_status) );
|
||||
|
||||
if(pkg_info != NULL){
|
||||
max_token = pkg_info->cbMaxToken;
|
||||
version = pkg_info->wVersion;
|
||||
ok(version == 1, "wVersion always should be 1, but is %d\n", version);
|
||||
todo_wine{
|
||||
ok(max_token == 12000, "cbMaxToken for NTLM is %ld, not 12000.\n",
|
||||
max_token);
|
||||
}
|
||||
}
|
||||
|
||||
ok(version == 1, "wVersion always should be 1, but is %d\n", version);
|
||||
ok(max_token == 12000, "cbMaxToken for Negotiate is %ld, not 12000.\n",
|
||||
max_token);
|
||||
|
||||
|
||||
sec_status = pFreeContextBuffer(&pkg_info);
|
||||
|
||||
ok( sec_status == SEC_E_OK,
|
||||
"Return value of FreeContextBuffer() shouldn't be %s\n",
|
||||
getSecStatusError(sec_status) );
|
||||
getSecError(sec_status) );
|
||||
|
||||
/* Test with a nonexistent package, test should fail */
|
||||
|
||||
|
@ -333,67 +491,133 @@ static void testQuerySecurityPackageInfo(void)
|
|||
sec_status = pQuerySecurityPackageInfoA( sec_pkg_name, &pkg_info);
|
||||
|
||||
ok( sec_status != SEC_E_OK,
|
||||
"Return value of QuerySecurityPackageInfo() should not be %s for a nonexistent package\n", getSecStatusError(SEC_E_OK));
|
||||
"Return value of QuerySecurityPackageInfo() should not be %s for a nonexistent package\n", getSecError(SEC_E_OK));
|
||||
|
||||
sec_status = pFreeContextBuffer(&pkg_info);
|
||||
|
||||
ok( sec_status == SEC_E_OK,
|
||||
"Return value of FreeContextBuffer() shouldn't be %s\n",
|
||||
getSecStatusError(sec_status) );
|
||||
getSecError(sec_status) );
|
||||
|
||||
|
||||
}
|
||||
|
||||
void testAuthentication(void)
|
||||
void testAuth(const char* sec_pkg, const char* domain)
|
||||
{
|
||||
CredHandle server_cred, client_cred;
|
||||
CtxtHandle server_ctxt, client_ctxt;
|
||||
BYTE server_buff[MAX_MESSAGE];
|
||||
BYTE client_buff[MAX_MESSAGE];
|
||||
SECURITY_STATUS sec_status;
|
||||
DWORD count_server = MAX_MESSAGE;
|
||||
DWORD count_client = MAX_MESSAGE;
|
||||
BOOL done = FALSE, new_conn = TRUE;
|
||||
TimeStamp server_ttl;
|
||||
PSecurityFunctionTable sft = NULL;
|
||||
SECURITY_STATUS sec_status;
|
||||
PSecPkgInfo pkg_info = NULL;
|
||||
CredHandle server_cred;
|
||||
CredHandle client_cred;
|
||||
CtxtHandle server_ctxt;
|
||||
CtxtHandle client_ctxt;
|
||||
SEC_CHAR sec_pkg_name[256];
|
||||
|
||||
trace("Running testAuthentication\n");
|
||||
PSecBufferDesc client_in = NULL, client_out = NULL;
|
||||
PSecBufferDesc server_in = NULL, server_out = NULL;
|
||||
|
||||
sft = pInitSecurityInterfaceA();
|
||||
BOOL continue_client = FALSE, continue_server = FALSE;
|
||||
|
||||
ok(sft != NULL, "InitSecurityInterface() returned NULL!\n");
|
||||
lstrcpy(sec_pkg_name, sec_pkg);
|
||||
if(setupPackageA(sec_pkg_name, &pkg_info) == SEC_E_OK)
|
||||
{
|
||||
pFreeContextBuffer(&pkg_info);
|
||||
sec_status = setupClient(&client_cred, "testuser", "testpass", domain,
|
||||
sec_pkg_name);
|
||||
|
||||
memset(&server_cred, 0, sizeof(CredHandle));
|
||||
memset(&client_cred, 0, sizeof(CredHandle));
|
||||
memset(&server_ctxt, 0, sizeof(CtxtHandle));
|
||||
memset(&client_ctxt, 0, sizeof(CtxtHandle));
|
||||
|
||||
sec_status = (sft->AcquireCredentialsHandle)(NULL, "Negotiate",
|
||||
SECPKG_CRED_INBOUND, NULL, NULL, NULL, NULL, &server_cred,
|
||||
&server_ttl);
|
||||
if(sec_status != SEC_E_OK)
|
||||
{
|
||||
trace("Error: Setting up the client returned %s, exiting test!\n",
|
||||
getSecError(sec_status));
|
||||
pFreeCredentialsHandle(&client_cred);
|
||||
return;
|
||||
}
|
||||
|
||||
ok(sec_status == SEC_E_OK,
|
||||
"Server's AcquireCredentialsHandle returned %s.\n",
|
||||
getSecStatusError(sec_status) );
|
||||
sec_status = setupServer(&server_cred, sec_pkg_name);
|
||||
|
||||
|
||||
genClientContext(NULL, 0, server_buff, &count_server, &done, "foo",
|
||||
&client_cred, &client_ctxt, sft);
|
||||
if(sec_status != SEC_E_OK)
|
||||
{
|
||||
trace("Error: Setting up the server returned %s, exiting test!\n",
|
||||
getSecError(sec_status));
|
||||
pFreeCredentialsHandle(&server_cred);
|
||||
pFreeCredentialsHandle(&client_cred);
|
||||
return;
|
||||
}
|
||||
|
||||
while(!done){
|
||||
genServerContext(server_buff, count_server, client_buff,
|
||||
&count_client, &done, &new_conn, &server_cred, &server_ctxt,
|
||||
sft);
|
||||
new_conn = FALSE;
|
||||
genClientContext(client_buff, count_client, server_buff,
|
||||
&count_server, &done, "foo", &client_cred, &client_ctxt, sft);
|
||||
setupBuffers(&client_in, &client_out);
|
||||
setupBuffers(&server_in, &server_out);
|
||||
|
||||
sec_status = runClient(&client_cred, &client_ctxt, client_in, client_out,
|
||||
TRUE);
|
||||
|
||||
ok(sec_status == SEC_E_OK || sec_status == SEC_I_CONTINUE_NEEDED,
|
||||
"Running the client returned %s, more tests will fail from now.\n",
|
||||
getSecError(sec_status));
|
||||
|
||||
if(sec_status == SEC_I_CONTINUE_NEEDED)
|
||||
continue_client = TRUE;
|
||||
|
||||
communicate(client_out, server_in);
|
||||
|
||||
sec_status = runServer(&server_cred, &server_ctxt, server_in, server_out,
|
||||
TRUE);
|
||||
|
||||
ok(sec_status == SEC_E_OK || sec_status == SEC_I_CONTINUE_NEEDED,
|
||||
"Running the server returned %s, more tests will fail from now.\n",
|
||||
getSecError(sec_status));
|
||||
|
||||
if(sec_status == SEC_I_CONTINUE_NEEDED)
|
||||
{
|
||||
continue_server = TRUE;
|
||||
communicate(server_out, client_in);
|
||||
}
|
||||
|
||||
if(continue_client)
|
||||
{
|
||||
sec_status = runClient(&client_cred, &client_ctxt, client_in, client_out,
|
||||
FALSE);
|
||||
|
||||
ok(sec_status == SEC_E_OK,
|
||||
"Running the client returned %s, more tests will fail from now.\n",
|
||||
getSecError(sec_status));
|
||||
|
||||
communicate(client_out, server_in);
|
||||
}
|
||||
|
||||
if(continue_server)
|
||||
{
|
||||
sec_status = runServer(&server_cred, &server_ctxt, server_in, server_out,
|
||||
FALSE);
|
||||
ok(sec_status == SEC_E_OK || SEC_E_LOGON_DENIED,
|
||||
"Running the server returned %s.\n", getSecError(sec_status));
|
||||
}
|
||||
|
||||
cleanupBuffers(client_in, client_out);
|
||||
cleanupBuffers(server_in, server_out);
|
||||
|
||||
sec_status = pDeleteSecurityContext(&server_ctxt);
|
||||
ok(sec_status == SEC_E_OK, "DeleteSecurityContext(server) returned %s\n",
|
||||
getSecError(sec_status));
|
||||
|
||||
sec_status = pDeleteSecurityContext(&client_ctxt);
|
||||
ok(sec_status == SEC_E_OK, "DeleteSecurityContext(client) returned %s\n",
|
||||
getSecError(sec_status));
|
||||
|
||||
sec_status = pFreeCredentialsHandle(&server_cred);
|
||||
ok(sec_status == SEC_E_OK, "FreeCredentialsHandle(server) returned %s\n",
|
||||
getSecError(sec_status));
|
||||
|
||||
sec_status = pFreeCredentialsHandle(&client_cred);
|
||||
ok(sec_status == SEC_E_OK, "FreeCredentialsHandle(client) returned %s\n",
|
||||
getSecError(sec_status));
|
||||
}
|
||||
|
||||
pFreeContextBuffer(&client_buff);
|
||||
pFreeContextBuffer(&server_buff);
|
||||
|
||||
else
|
||||
{
|
||||
trace("Package not installed, skipping test.\n");
|
||||
}
|
||||
pFreeContextBuffer(&pkg_info);
|
||||
}
|
||||
|
||||
|
||||
START_TEST(main)
|
||||
{
|
||||
InitFunctionPtrs();
|
||||
|
@ -404,9 +628,11 @@ START_TEST(main)
|
|||
if(pEnumerateSecurityPackagesA)
|
||||
testEnumerateSecurityPackages();
|
||||
if(pQuerySecurityPackageInfoA)
|
||||
{
|
||||
testQuerySecurityPackageInfo();
|
||||
if(pInitSecurityInterfaceA)
|
||||
testAuthentication();
|
||||
if(pInitSecurityInterfaceA)
|
||||
testAuth("NTLM", "WORKGROUP");
|
||||
}
|
||||
}
|
||||
if(secdll)
|
||||
FreeLibrary(secdll);
|
||||
|
|
Loading…
Reference in New Issue