2005-08-03 15:08:49 +02:00
|
|
|
/*
|
|
|
|
* Miscellaneous secur32 tests
|
|
|
|
*
|
|
|
|
* Copyright 2005 Kai Blin
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2005-08-11 19:08:06 +02:00
|
|
|
#define SECURITY_WIN32
|
|
|
|
|
2005-08-03 15:08:49 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include <winbase.h>
|
|
|
|
#include <sspi.h>
|
|
|
|
|
|
|
|
#define BUFF_SIZE 2048
|
2005-08-11 19:08:06 +02:00
|
|
|
#define MAX_MESSAGE 12000
|
2005-08-03 15:08:49 +02:00
|
|
|
|
2005-10-26 12:09:53 +02:00
|
|
|
static HMODULE secdll;
|
|
|
|
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*);
|
2006-01-03 12:06:21 +01:00
|
|
|
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);
|
2005-10-26 12:09:53 +02:00
|
|
|
|
|
|
|
void InitFunctionPtrs(void)
|
|
|
|
{
|
|
|
|
secdll = LoadLibraryA("secur32.dll");
|
|
|
|
if(!secdll)
|
|
|
|
secdll = LoadLibraryA("security.dll");
|
|
|
|
if(secdll)
|
|
|
|
{
|
|
|
|
pInitSecurityInterfaceA = (PVOID)GetProcAddress(secdll, "InitSecurityInterfaceA");
|
|
|
|
pEnumerateSecurityPackagesA = (PVOID)GetProcAddress(secdll, "EnumerateSecurityPackagesA");
|
|
|
|
pFreeContextBuffer = (PVOID)GetProcAddress(secdll, "FreeContextBuffer");
|
2006-01-03 12:06:21 +01:00
|
|
|
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");
|
2005-10-26 12:09:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-11 19:08:06 +02:00
|
|
|
/*---------------------------------------------------------*/
|
|
|
|
/* General helper functions */
|
2005-08-03 15:08:49 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
static const char* getSecError(SECURITY_STATUS status)
|
2005-08-11 19:08:06 +02:00
|
|
|
{
|
|
|
|
#define _SEC_ERR(x) case (x): return #x;
|
|
|
|
switch(status)
|
|
|
|
{
|
|
|
|
_SEC_ERR(SEC_E_OK);
|
|
|
|
_SEC_ERR(SEC_E_INSUFFICIENT_MEMORY);
|
|
|
|
_SEC_ERR(SEC_E_INVALID_HANDLE);
|
|
|
|
_SEC_ERR(SEC_E_UNSUPPORTED_FUNCTION);
|
|
|
|
_SEC_ERR(SEC_E_TARGET_UNKNOWN);
|
|
|
|
_SEC_ERR(SEC_E_INTERNAL_ERROR);
|
|
|
|
_SEC_ERR(SEC_E_SECPKG_NOT_FOUND);
|
|
|
|
_SEC_ERR(SEC_E_NOT_OWNER);
|
|
|
|
_SEC_ERR(SEC_E_CANNOT_INSTALL);
|
|
|
|
_SEC_ERR(SEC_E_INVALID_TOKEN);
|
|
|
|
_SEC_ERR(SEC_E_CANNOT_PACK);
|
|
|
|
_SEC_ERR(SEC_E_QOP_NOT_SUPPORTED);
|
|
|
|
_SEC_ERR(SEC_E_NO_IMPERSONATION);
|
|
|
|
_SEC_ERR(SEC_I_CONTINUE_NEEDED);
|
2006-01-03 12:06:21 +01:00
|
|
|
_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);
|
2005-08-11 19:08:06 +02:00
|
|
|
default:
|
|
|
|
trace("Error = %ld\n", status);
|
|
|
|
return "Unknown error";
|
|
|
|
}
|
|
|
|
#undef _SEC_ERR
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------*/
|
|
|
|
/* Helper for testQuerySecurityPagageInfo */
|
|
|
|
|
|
|
|
static SECURITY_STATUS setupPackageA(SEC_CHAR *p_package_name,
|
|
|
|
PSecPkgInfo *p_pkg_info)
|
|
|
|
{
|
|
|
|
SECURITY_STATUS ret = SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
2005-10-26 12:09:53 +02:00
|
|
|
ret = pQuerySecurityPackageInfoA( p_package_name, p_pkg_info);
|
2005-08-11 19:08:06 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------*/
|
2006-01-03 12:06:21 +01:00
|
|
|
/* Helper for testAuth* */
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
SECURITY_STATUS setupClient(PCredHandle cred, const char *user,
|
|
|
|
const char *pass, const char *domain, char *provider)
|
2005-08-11 19:08:06 +02:00
|
|
|
{
|
2006-01-03 12:06:21 +01:00
|
|
|
SECURITY_STATUS ret;
|
|
|
|
PSEC_WINNT_AUTH_IDENTITY identity = NULL;
|
|
|
|
TimeStamp ttl;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((ret = pAcquireCredentialsHandleA(NULL, provider, SECPKG_CRED_OUTBOUND,
|
|
|
|
NULL, identity, NULL, NULL, cred, &ttl)) != SEC_E_OK)
|
|
|
|
{
|
|
|
|
trace("AcquireCredentialsHandle() returned %s\n", getSecError(ret));
|
2005-08-11 19:08:06 +02:00
|
|
|
}
|
2006-01-03 12:06:21 +01:00
|
|
|
|
|
|
|
ok(ret == SEC_E_OK, "AcquireCredentialsHande() returned %s\n",
|
|
|
|
getSecError(ret));
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
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);
|
|
|
|
}
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
/**********************************************************************/
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
SECURITY_STATUS setupServer(PCredHandle cred, char *provider)
|
|
|
|
{
|
|
|
|
SECURITY_STATUS ret;
|
|
|
|
TimeStamp ttl;
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
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));
|
2005-08-11 19:08:06 +02:00
|
|
|
}
|
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
ok(ret == SEC_E_OK, "AcquireCredentialsHande() returned %s\n",
|
|
|
|
getSecError(ret));
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
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;
|
2005-08-11 19:08:06 +02:00
|
|
|
}
|
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
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;
|
2005-08-11 19:08:06 +02:00
|
|
|
}
|
2006-01-03 12:06:21 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
out_buf->ulVersion = SECBUFFER_VERSION;
|
|
|
|
out_buf->cBuffers = 1;
|
|
|
|
out_buf->pBuffers = sec_buffer;
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
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;
|
|
|
|
}
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
return SEC_E_OK;
|
2005-08-11 19:08:06 +02:00
|
|
|
}
|
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
/**********************************************************************/
|
|
|
|
|
|
|
|
void cleanupBuffers(PSecBufferDesc in_buf, PSecBufferDesc out_buf)
|
2005-08-11 19:08:06 +02:00
|
|
|
{
|
2006-01-03 12:06:21 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if(in_buf != NULL)
|
|
|
|
{
|
|
|
|
for(i = 0; i < in_buf->cBuffers; ++i)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, in_buf->pBuffers[i].pvBuffer);
|
2005-08-11 19:08:06 +02:00
|
|
|
}
|
2006-01-03 12:06:21 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, in_buf->pBuffers);
|
|
|
|
HeapFree(GetProcessHeap(), 0, in_buf);
|
2005-08-11 19:08:06 +02:00
|
|
|
}
|
2006-01-03 12:06:21 +01:00
|
|
|
|
|
|
|
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");
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
ret = pAcceptSecurityContext(cred, first?NULL:ctxt, in_buf, 0,
|
|
|
|
SECURITY_NATIVE_DREP, ctxt, out_buf, &ctxt_attr, &ttl);
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
return ret;
|
2005-10-26 12:09:53 +02:00
|
|
|
}
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
/**********************************************************************/
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************/
|
2005-08-11 19:08:06 +02:00
|
|
|
|
|
|
|
/*--------------------------------------------------------- */
|
|
|
|
/* The test functions */
|
|
|
|
|
|
|
|
static void testInitSecurityInterface(void)
|
|
|
|
{
|
|
|
|
PSecurityFunctionTable sec_fun_table = NULL;
|
|
|
|
|
2005-10-26 12:09:53 +02:00
|
|
|
sec_fun_table = pInitSecurityInterfaceA();
|
2005-08-11 19:08:06 +02:00
|
|
|
ok(sec_fun_table != NULL, "InitSecurityInterface() returned NULL.\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testEnumerateSecurityPackages(void)
|
2005-08-03 15:08:49 +02:00
|
|
|
{
|
|
|
|
|
2005-08-11 19:08:06 +02:00
|
|
|
SECURITY_STATUS sec_status;
|
|
|
|
ULONG num_packages, i;
|
|
|
|
PSecPkgInfo pkg_info = NULL;
|
2005-08-30 10:55:20 +02:00
|
|
|
|
2005-08-11 19:08:06 +02:00
|
|
|
trace("Running testEnumerateSecurityPackages\n");
|
|
|
|
|
2005-10-26 12:09:53 +02:00
|
|
|
sec_status = pEnumerateSecurityPackagesA(&num_packages, &pkg_info);
|
2005-08-11 19:08:06 +02:00
|
|
|
|
|
|
|
ok(sec_status == SEC_E_OK,
|
2005-08-30 10:55:20 +02:00
|
|
|
"EnumerateSecurityPackages() should return %ld, not %08lx\n",
|
2005-08-11 19:08:06 +02:00
|
|
|
(LONG)SEC_E_OK, (LONG)sec_status);
|
2005-08-30 10:55:20 +02:00
|
|
|
|
2005-08-11 19:08:06 +02:00
|
|
|
ok(num_packages > 0, "Number of sec packages should be > 0 ,but is %ld\n",
|
|
|
|
num_packages);
|
|
|
|
|
|
|
|
ok(pkg_info != NULL,
|
|
|
|
"pkg_info should not be NULL after EnumerateSecurityPackages\n");
|
|
|
|
|
|
|
|
trace("Number of packages: %ld\n", num_packages);
|
|
|
|
for(i = 0; i < num_packages; ++i){
|
2005-09-26 11:52:25 +02:00
|
|
|
trace("%ld: Package \"%s\"\n", i, pkg_info[i].Name);
|
|
|
|
trace("Supported flags:\n");
|
2005-08-11 19:08:06 +02:00
|
|
|
if(pkg_info[i].fCapabilities & SECPKG_FLAG_INTEGRITY)
|
|
|
|
trace("\tSECPKG_FLAG_INTEGRITY\n");
|
|
|
|
if(pkg_info[i].fCapabilities & SECPKG_FLAG_PRIVACY)
|
|
|
|
trace("\tSECPKG_FLAG_PRIVACY\n");
|
|
|
|
if(pkg_info[i].fCapabilities & SECPKG_FLAG_TOKEN_ONLY)
|
|
|
|
trace("\tSECPKG_FLAG_TOKEN_ONLY\n");
|
|
|
|
if(pkg_info[i].fCapabilities & SECPKG_FLAG_DATAGRAM)
|
|
|
|
trace("\tSECPKG_FLAG_DATAGRAM\n");
|
|
|
|
if(pkg_info[i].fCapabilities & SECPKG_FLAG_CONNECTION)
|
|
|
|
trace("\tSECPKG_FLAG_CONNECTION\n");
|
|
|
|
if(pkg_info[i].fCapabilities & SECPKG_FLAG_MULTI_REQUIRED)
|
|
|
|
trace("\tSECPKG_FLAG_MULTI_REQUIRED\n");
|
|
|
|
if(pkg_info[i].fCapabilities & SECPKG_FLAG_CLIENT_ONLY)
|
|
|
|
trace("\tSECPKG_FLAG_CLIENT_ONLY\n");
|
|
|
|
if(pkg_info[i].fCapabilities & SECPKG_FLAG_EXTENDED_ERROR)
|
|
|
|
trace("\tSECPKG_FLAG_EXTENDED_ERROR\n");
|
|
|
|
if(pkg_info[i].fCapabilities & SECPKG_FLAG_IMPERSONATION)
|
|
|
|
trace("\tSECPKG_FLAG_IMPERSONATION\n");
|
|
|
|
if(pkg_info[i].fCapabilities & SECPKG_FLAG_ACCEPT_WIN32_NAME)
|
|
|
|
trace("\tSECPKG_FLAG_ACCEPT_WIN32_NAME\n");
|
|
|
|
if(pkg_info[i].fCapabilities & SECPKG_FLAG_STREAM)
|
|
|
|
trace("\tSECPKG_FLAG_STREAM\n");
|
|
|
|
if(pkg_info[i].fCapabilities & SECPKG_FLAG_READONLY_WITH_CHECKSUM)
|
|
|
|
trace("\tSECPKG_FLAG_READONLY_WITH_CHECKSUM\n");
|
|
|
|
trace("Comment: %s\n", pkg_info[i].Comment);
|
|
|
|
trace("\n");
|
|
|
|
}
|
|
|
|
|
2005-10-26 12:09:53 +02:00
|
|
|
pFreeContextBuffer(pkg_info);
|
2005-08-11 19:08:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void testQuerySecurityPackageInfo(void)
|
|
|
|
{
|
|
|
|
SECURITY_STATUS sec_status;
|
|
|
|
SEC_CHAR sec_pkg_name[256];
|
|
|
|
PSecPkgInfo pkg_info = NULL;
|
|
|
|
ULONG max_token = 0;
|
|
|
|
USHORT version = 0;
|
|
|
|
|
|
|
|
trace("Running testQuerySecurityPackageInfo\n");
|
|
|
|
|
|
|
|
/* Test with an existing package. Test should pass */
|
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
lstrcpy(sec_pkg_name, "NTLM");
|
2005-08-11 19:08:06 +02:00
|
|
|
|
|
|
|
sec_status = setupPackageA(sec_pkg_name, &pkg_info);
|
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
ok((sec_status == SEC_E_OK) || (sec_status == SEC_E_SECPKG_NOT_FOUND),
|
2005-08-15 22:52:18 +02:00
|
|
|
"Return value of QuerySecurityPackageInfo() shouldn't be %s\n",
|
2006-01-03 12:06:21 +01:00
|
|
|
getSecError(sec_status) );
|
|
|
|
|
2005-08-11 19:08:06 +02:00
|
|
|
if(pkg_info != NULL){
|
|
|
|
max_token = pkg_info->cbMaxToken;
|
|
|
|
version = pkg_info->wVersion;
|
2006-01-03 12:06:21 +01:00
|
|
|
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);
|
|
|
|
}
|
2005-08-11 19:08:06 +02:00
|
|
|
}
|
2005-08-15 22:52:18 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
|
2005-10-26 12:09:53 +02:00
|
|
|
sec_status = pFreeContextBuffer(&pkg_info);
|
2005-08-11 19:08:06 +02:00
|
|
|
|
|
|
|
ok( sec_status == SEC_E_OK,
|
|
|
|
"Return value of FreeContextBuffer() shouldn't be %s\n",
|
2006-01-03 12:06:21 +01:00
|
|
|
getSecError(sec_status) );
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2005-08-17 11:56:24 +02:00
|
|
|
/* Test with a nonexistent package, test should fail */
|
2005-08-11 19:08:06 +02:00
|
|
|
|
|
|
|
lstrcpy(sec_pkg_name, "Winetest");
|
2005-08-03 15:08:49 +02:00
|
|
|
|
2005-10-26 12:09:53 +02:00
|
|
|
sec_status = pQuerySecurityPackageInfoA( sec_pkg_name, &pkg_info);
|
2005-08-03 15:08:49 +02:00
|
|
|
|
2005-08-11 19:08:06 +02:00
|
|
|
ok( sec_status != SEC_E_OK,
|
2006-01-03 12:06:21 +01:00
|
|
|
"Return value of QuerySecurityPackageInfo() should not be %s for a nonexistent package\n", getSecError(SEC_E_OK));
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2005-10-26 12:09:53 +02:00
|
|
|
sec_status = pFreeContextBuffer(&pkg_info);
|
2005-08-11 19:08:06 +02:00
|
|
|
|
|
|
|
ok( sec_status == SEC_E_OK,
|
|
|
|
"Return value of FreeContextBuffer() shouldn't be %s\n",
|
2006-01-03 12:06:21 +01:00
|
|
|
getSecError(sec_status) );
|
2005-08-11 19:08:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
void testAuth(const char* sec_pkg, const char* domain)
|
2005-08-11 19:08:06 +02:00
|
|
|
{
|
2006-01-03 12:06:21 +01:00
|
|
|
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];
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
PSecBufferDesc client_in = NULL, client_out = NULL;
|
|
|
|
PSecBufferDesc server_in = NULL, server_out = NULL;
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
BOOL continue_client = FALSE, continue_server = FALSE;
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
if(sec_status != SEC_E_OK)
|
|
|
|
{
|
|
|
|
trace("Error: Setting up the client returned %s, exiting test!\n",
|
|
|
|
getSecError(sec_status));
|
|
|
|
pFreeCredentialsHandle(&client_cred);
|
|
|
|
return;
|
|
|
|
}
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
sec_status = setupServer(&server_cred, sec_pkg_name);
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
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;
|
|
|
|
}
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
setupBuffers(&client_in, &client_out);
|
|
|
|
setupBuffers(&server_in, &server_out);
|
|
|
|
|
|
|
|
sec_status = runClient(&client_cred, &client_ctxt, client_in, client_out,
|
|
|
|
TRUE);
|
2005-08-11 19:08:06 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
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;
|
2005-08-03 15:08:49 +02:00
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trace("Package not installed, skipping test.\n");
|
|
|
|
}
|
|
|
|
pFreeContextBuffer(&pkg_info);
|
2005-08-03 15:08:49 +02:00
|
|
|
}
|
|
|
|
|
2006-01-03 12:06:21 +01:00
|
|
|
|
2005-08-03 15:08:49 +02:00
|
|
|
START_TEST(main)
|
|
|
|
{
|
2005-10-26 12:09:53 +02:00
|
|
|
InitFunctionPtrs();
|
|
|
|
if(pInitSecurityInterfaceA)
|
|
|
|
testInitSecurityInterface();
|
|
|
|
if(pFreeContextBuffer)
|
|
|
|
{
|
|
|
|
if(pEnumerateSecurityPackagesA)
|
|
|
|
testEnumerateSecurityPackages();
|
|
|
|
if(pQuerySecurityPackageInfoA)
|
2006-01-03 12:06:21 +01:00
|
|
|
{
|
2005-10-26 12:09:53 +02:00
|
|
|
testQuerySecurityPackageInfo();
|
2006-01-03 12:06:21 +01:00
|
|
|
if(pInitSecurityInterfaceA)
|
|
|
|
testAuth("NTLM", "WORKGROUP");
|
|
|
|
}
|
2005-10-26 12:09:53 +02:00
|
|
|
}
|
|
|
|
if(secdll)
|
|
|
|
FreeLibrary(secdll);
|
2005-08-03 15:08:49 +02:00
|
|
|
}
|