secur32: Fix some wrong assumptions in the NTLM test case, make it pass in XP SP2...
[wine/wine-kai.git] / dlls / secur32 / tests / main.c
blob44d83011e5f8dfad0456bd0c62ac73af8b71cb1a
1 /*
2 * Miscellaneous secur32 tests
4 * Copyright 2005 Kai Blin
5 * Copyright 2006 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define SECURITY_WIN32
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <assert.h>
27 #include <windef.h>
28 #include <winbase.h>
29 #include <sspi.h>
31 #include "wine/test.h"
33 #define BUFF_SIZE 2048
34 #define MAX_MESSAGE 12000
36 static HMODULE secdll;
37 static PSecurityFunctionTableA (SEC_ENTRY * pInitSecurityInterfaceA)(void);
38 static SECURITY_STATUS (SEC_ENTRY * pEnumerateSecurityPackagesA)(PULONG, PSecPkgInfoA*);
39 static SECURITY_STATUS (SEC_ENTRY * pFreeContextBuffer)(PVOID pv);
40 static SECURITY_STATUS (SEC_ENTRY * pQuerySecurityPackageInfoA)(SEC_CHAR*, PSecPkgInfoA*);
41 static SECURITY_STATUS (SEC_ENTRY * pAcquireCredentialsHandleA)(SEC_CHAR*, SEC_CHAR*,
42 ULONG, PLUID, PVOID, SEC_GET_KEY_FN, PVOID, PCredHandle, PTimeStamp);
43 static SECURITY_STATUS (SEC_ENTRY * pInitializeSecurityContextA)(PCredHandle, PCtxtHandle,
44 SEC_CHAR*, ULONG, ULONG, ULONG, PSecBufferDesc, ULONG,
45 PCtxtHandle, PSecBufferDesc, PULONG, PTimeStamp);
46 static SECURITY_STATUS (SEC_ENTRY * pCompleteAuthToken)(PCtxtHandle, PSecBufferDesc);
47 static SECURITY_STATUS (SEC_ENTRY * pAcceptSecurityContext)(PCredHandle, PCtxtHandle,
48 PSecBufferDesc, ULONG, ULONG, PCtxtHandle, PSecBufferDesc,
49 PULONG, PTimeStamp);
50 static SECURITY_STATUS (SEC_ENTRY * pFreeCredentialsHandle)(PCredHandle);
51 static SECURITY_STATUS (SEC_ENTRY * pDeleteSecurityContext)(PCtxtHandle);
53 void InitFunctionPtrs(void)
55 secdll = LoadLibraryA("secur32.dll");
56 if(!secdll)
57 secdll = LoadLibraryA("security.dll");
58 if(secdll)
60 pInitSecurityInterfaceA = (PVOID)GetProcAddress(secdll, "InitSecurityInterfaceA");
61 pEnumerateSecurityPackagesA = (PVOID)GetProcAddress(secdll, "EnumerateSecurityPackagesA");
62 pFreeContextBuffer = (PVOID)GetProcAddress(secdll, "FreeContextBuffer");
63 pQuerySecurityPackageInfoA = (PVOID)GetProcAddress(secdll, "QuerySecurityPackageInfoA");
64 pAcquireCredentialsHandleA = (PVOID)GetProcAddress(secdll, "AcquireCredentialsHandleA");
65 pInitializeSecurityContextA = (PVOID)GetProcAddress(secdll, "InitializeSecurityContextA");
66 pCompleteAuthToken = (PVOID)GetProcAddress(secdll, "CompleteAuthToken");
67 pAcceptSecurityContext = (PVOID)GetProcAddress(secdll, "AcceptSecurityContext");
68 pFreeCredentialsHandle = (PVOID)GetProcAddress(secdll, "FreeCredentialsHandle");
69 pDeleteSecurityContext = (PVOID)GetProcAddress(secdll, "DeleteSecurityContext");
73 /*---------------------------------------------------------*/
74 /* General helper functions */
76 static const char* getSecError(SECURITY_STATUS status)
78 static char buf[20];
80 #define _SEC_ERR(x) case (x): return #x;
81 switch(status)
83 _SEC_ERR(SEC_E_OK);
84 _SEC_ERR(SEC_E_INSUFFICIENT_MEMORY);
85 _SEC_ERR(SEC_E_INVALID_HANDLE);
86 _SEC_ERR(SEC_E_UNSUPPORTED_FUNCTION);
87 _SEC_ERR(SEC_E_TARGET_UNKNOWN);
88 _SEC_ERR(SEC_E_INTERNAL_ERROR);
89 _SEC_ERR(SEC_E_SECPKG_NOT_FOUND);
90 _SEC_ERR(SEC_E_NOT_OWNER);
91 _SEC_ERR(SEC_E_CANNOT_INSTALL);
92 _SEC_ERR(SEC_E_INVALID_TOKEN);
93 _SEC_ERR(SEC_E_CANNOT_PACK);
94 _SEC_ERR(SEC_E_QOP_NOT_SUPPORTED);
95 _SEC_ERR(SEC_E_NO_IMPERSONATION);
96 _SEC_ERR(SEC_I_CONTINUE_NEEDED);
97 _SEC_ERR(SEC_E_BUFFER_TOO_SMALL);
98 _SEC_ERR(SEC_E_ILLEGAL_MESSAGE);
99 _SEC_ERR(SEC_E_LOGON_DENIED);
100 _SEC_ERR(SEC_E_NO_CREDENTIALS);
101 _SEC_ERR(SEC_E_OUT_OF_SEQUENCE);
102 default:
103 sprintf(buf, "%08lx\n", status);
104 return buf;
106 #undef _SEC_ERR
109 /*---------------------------------------------------------*/
110 /* Helper for testQuerySecurityPagageInfo */
112 static SECURITY_STATUS setupPackageA(SEC_CHAR *p_package_name,
113 PSecPkgInfo *p_pkg_info)
115 SECURITY_STATUS ret;
117 ret = pQuerySecurityPackageInfoA( p_package_name, p_pkg_info);
118 return ret;
121 /*---------------------------------------------------------*/
122 /* Helper for testAuth* */
124 SECURITY_STATUS setupClient(PCredHandle cred, const char *user,
125 const char *pass, const char *domain, char *provider)
127 SECURITY_STATUS ret;
128 PSEC_WINNT_AUTH_IDENTITY identity = NULL;
129 TimeStamp ttl;
131 trace("Running setupClient\n");
133 if(user != NULL)
135 identity = HeapAlloc(GetProcessHeap(), 0,
136 sizeof(SEC_WINNT_AUTH_IDENTITY_A));
138 memset( identity, 0, sizeof(identity));
139 identity->Domain = HeapAlloc(GetProcessHeap(), 0,
140 lstrlenA( domain ? domain :"") + 1);
141 lstrcpyA((char*)identity->Domain, domain ? domain :"");
142 identity->DomainLength = domain ? lstrlenA(domain): 0;
143 identity->User = HeapAlloc(GetProcessHeap(), 0,
144 lstrlenA( user ? user :"") + 1);
145 lstrcpyA((char*)identity->User, user ? user :"");
146 identity->UserLength = user ? lstrlenA(user) : 0;
147 identity->Password = HeapAlloc(GetProcessHeap(), 0,
148 lstrlenA( pass ? pass :"") + 1);
149 lstrcpyA((char*)identity->Password, pass ? pass : "");
150 identity->PasswordLength = pass ? lstrlenA(pass): 0;
151 identity->Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
154 if((ret = pAcquireCredentialsHandleA(NULL, provider, SECPKG_CRED_OUTBOUND,
155 NULL, identity, NULL, NULL, cred, &ttl)) != SEC_E_OK)
157 trace("AcquireCredentialsHandle() returned %s\n", getSecError(ret));
160 ok(ret == SEC_E_OK, "AcquireCredentialsHande() returned %s\n",
161 getSecError(ret));
163 if( identity != NULL)
165 if(identity->Domain != 0)
166 HeapFree(GetProcessHeap(), 0, identity->Domain);
167 if(identity->User != 0)
168 HeapFree(GetProcessHeap(), 0, identity->User);
169 if(identity->Password != 0)
170 HeapFree(GetProcessHeap(), 0, identity->Password);
171 HeapFree(GetProcessHeap(), 0, identity);
174 return ret;
177 /**********************************************************************/
179 SECURITY_STATUS setupServer(PCredHandle cred, char *provider)
181 SECURITY_STATUS ret;
182 TimeStamp ttl;
184 trace("Running setupServer\n");
186 if((ret = pAcquireCredentialsHandleA(NULL, provider, SECPKG_CRED_INBOUND,
187 NULL, NULL, NULL, NULL, cred, &ttl)) != SEC_E_OK)
189 trace("AcquireCredentialsHandle() returned %s\n", getSecError(ret));
192 ok(ret == SEC_E_OK, "AcquireCredentialsHande() returned %s\n",
193 getSecError(ret));
195 return ret;
198 /**********************************************************************/
200 SECURITY_STATUS setupBuffers(PSecBufferDesc *new_in_buf,
201 PSecBufferDesc *new_out_buf)
203 int size = MAX_MESSAGE;
204 PBYTE buffer = NULL;
205 PSecBufferDesc in_buf = HeapAlloc(GetProcessHeap(), 0,
206 sizeof(SecBufferDesc));
207 PSecBufferDesc out_buf = HeapAlloc(GetProcessHeap(), 0,
208 sizeof(SecBufferDesc));
210 if(in_buf != NULL)
212 PSecBuffer sec_buffer = HeapAlloc(GetProcessHeap(), 0,
213 sizeof(SecBuffer));
214 if(sec_buffer == NULL){
215 trace("in_buf: sec_buffer == NULL\n");
216 return SEC_E_INSUFFICIENT_MEMORY;
219 buffer = HeapAlloc(GetProcessHeap(), 0, size);
221 if(buffer == NULL){
222 trace("in_buf: buffer == NULL\n");
223 return SEC_E_INSUFFICIENT_MEMORY;
226 in_buf->ulVersion = SECBUFFER_VERSION;
227 in_buf->cBuffers = 1;
228 in_buf->pBuffers = sec_buffer;
230 sec_buffer->cbBuffer = size;
231 sec_buffer->BufferType = SECBUFFER_TOKEN;
232 sec_buffer->pvBuffer = buffer;
233 *new_in_buf = in_buf;
235 else
237 trace("HeapAlloc in_buf returned NULL\n");
238 return SEC_E_INSUFFICIENT_MEMORY;
241 if(out_buf != NULL)
243 PSecBuffer sec_buffer = HeapAlloc(GetProcessHeap(), 0,
244 sizeof(SecBuffer));
245 PBYTE buffer = NULL;
247 if(sec_buffer == NULL){
248 trace("out_buf: sec_buffer == NULL\n");
249 return SEC_E_INSUFFICIENT_MEMORY;
252 buffer = HeapAlloc(GetProcessHeap(), 0, size);
254 if(buffer == NULL){
255 trace("out_buf: buffer == NULL\n");
256 return SEC_E_INSUFFICIENT_MEMORY;
259 out_buf->ulVersion = SECBUFFER_VERSION;
260 out_buf->cBuffers = 1;
261 out_buf->pBuffers = sec_buffer;
263 sec_buffer->cbBuffer = size;
264 sec_buffer->BufferType = SECBUFFER_TOKEN;
265 sec_buffer->pvBuffer = buffer;
266 *new_out_buf = out_buf;
268 else
270 trace("HeapAlloc out_buf returned NULL\n");
271 return SEC_E_INSUFFICIENT_MEMORY;
274 return SEC_E_OK;
277 /**********************************************************************/
279 void cleanupBuffers(PSecBufferDesc in_buf, PSecBufferDesc out_buf)
281 ULONG i;
283 if(in_buf != NULL)
285 for(i = 0; i < in_buf->cBuffers; ++i)
287 HeapFree(GetProcessHeap(), 0, in_buf->pBuffers[i].pvBuffer);
289 HeapFree(GetProcessHeap(), 0, in_buf->pBuffers);
290 HeapFree(GetProcessHeap(), 0, in_buf);
293 if(out_buf != NULL)
295 for(i = 0; i < out_buf->cBuffers; ++i)
297 HeapFree(GetProcessHeap(), 0, out_buf->pBuffers[i].pvBuffer);
299 HeapFree(GetProcessHeap(), 0, out_buf->pBuffers);
300 HeapFree(GetProcessHeap(), 0, out_buf);
304 /**********************************************************************/
306 SECURITY_STATUS runClient(PCredHandle cred, PCtxtHandle ctxt,
307 PSecBufferDesc in_buf, PSecBufferDesc out_buf, BOOL first)
309 SECURITY_STATUS ret;
310 ULONG req_attr = ISC_REQ_CONNECTION;
311 ULONG ctxt_attr;
312 TimeStamp ttl;
314 assert(in_buf->cBuffers >= 1);
315 assert(in_buf->pBuffers[0].pvBuffer != NULL);
316 assert(in_buf->pBuffers[0].cbBuffer != 0);
318 assert(out_buf->cBuffers >= 1);
319 assert(out_buf->pBuffers[0].pvBuffer != NULL);
320 assert(out_buf->pBuffers[0].cbBuffer != 0);
322 trace("Running the client the %s time.\n", first?"first":"second");
324 /* We can either use ISC_REQ_ALLOCATE_MEMORY flag to ask the provider
325 * always allocate output buffers for us, or initialize cbBuffer
326 * before each call because the API changes it to represent actual
327 * amount of data in the buffer.
330 /* test a failing call only the first time, otherwise we get
331 * SEC_E_OUT_OF_SEQUENCE
333 if (first)
335 void *old_buf;
337 /* pass NULL as an output buffer */
338 ret = pInitializeSecurityContextA(cred, NULL, NULL, req_attr,
339 0, SECURITY_NATIVE_DREP, NULL, 0, ctxt, NULL,
340 &ctxt_attr, &ttl);
342 ok(ret == SEC_E_BUFFER_TOO_SMALL, "expected SEC_E_BUFFER_TOO_SMALL, got %s\n", getSecError(ret));
344 /* pass NULL as an output buffer */
345 old_buf = out_buf->pBuffers[0].pvBuffer;
346 out_buf->pBuffers[0].pvBuffer = NULL;
348 ret = pInitializeSecurityContextA(cred, NULL, NULL, req_attr,
349 0, SECURITY_NATIVE_DREP, NULL, 0, ctxt, out_buf,
350 &ctxt_attr, &ttl);
352 ok(ret == SEC_E_INTERNAL_ERROR, "expected SEC_E_INTERNAL_ERROR, got %s\n", getSecError(ret));
354 out_buf->pBuffers[0].pvBuffer = old_buf;
356 /* pass an output buffer of 0 size */
357 out_buf->pBuffers[0].cbBuffer = 0;
359 ret = pInitializeSecurityContextA(cred, NULL, NULL, req_attr,
360 0, SECURITY_NATIVE_DREP, NULL, 0, ctxt, out_buf,
361 &ctxt_attr, &ttl);
363 ok(ret == SEC_E_BUFFER_TOO_SMALL, "expected SEC_E_BUFFER_TOO_SMALL, got %s\n", getSecError(ret));
365 ok(out_buf->pBuffers[0].cbBuffer == 0,
366 "InitializeSecurityContext set buffer size to %lu\n", out_buf->pBuffers[0].cbBuffer);
369 out_buf->pBuffers[0].cbBuffer = MAX_MESSAGE;
371 ret = pInitializeSecurityContextA(cred, first?NULL:ctxt, NULL, req_attr,
372 0, SECURITY_NATIVE_DREP, first?NULL:in_buf, 0, ctxt, out_buf,
373 &ctxt_attr, &ttl);
375 if(ret == SEC_I_COMPLETE_AND_CONTINUE || ret == SEC_I_COMPLETE_NEEDED)
377 pCompleteAuthToken(ctxt, out_buf);
378 if(ret == SEC_I_COMPLETE_AND_CONTINUE)
379 ret = SEC_I_CONTINUE_NEEDED;
380 else if(ret == SEC_I_COMPLETE_NEEDED)
381 ret = SEC_E_OK;
384 ok(out_buf->pBuffers[0].cbBuffer < MAX_MESSAGE,
385 "InitializeSecurityContext set buffer size to %lu\n", out_buf->pBuffers[0].cbBuffer);
387 return ret;
390 /**********************************************************************/
392 SECURITY_STATUS runServer(PCredHandle cred, PCtxtHandle ctxt,
393 PSecBufferDesc in_buf, PSecBufferDesc out_buf, BOOL first)
395 SECURITY_STATUS ret;
396 ULONG ctxt_attr;
397 TimeStamp ttl;
399 trace("Running the server the %s time\n", first?"first":"second");
401 ret = pAcceptSecurityContext(cred, first?NULL:ctxt, in_buf, 0,
402 SECURITY_NATIVE_DREP, ctxt, out_buf, &ctxt_attr, &ttl);
404 if(ret == SEC_I_COMPLETE_AND_CONTINUE || ret == SEC_I_COMPLETE_NEEDED)
406 pCompleteAuthToken(ctxt, out_buf);
407 if(ret == SEC_I_COMPLETE_AND_CONTINUE)
408 ret = SEC_I_CONTINUE_NEEDED;
409 else if(ret == SEC_I_COMPLETE_NEEDED)
410 ret = SEC_E_OK;
413 return ret;
416 /**********************************************************************/
418 void communicate(PSecBufferDesc in_buf, PSecBufferDesc out_buf)
420 if(in_buf != NULL && out_buf != NULL)
422 trace("Running communicate.\n");
423 if((in_buf->cBuffers >= 1) && (out_buf->cBuffers >= 1))
425 if((in_buf->pBuffers[0].pvBuffer != NULL) &&
426 (out_buf->pBuffers[0].pvBuffer != NULL))
428 memset(out_buf->pBuffers[0].pvBuffer, 0, MAX_MESSAGE);
430 memcpy(out_buf->pBuffers[0].pvBuffer,
431 in_buf->pBuffers[0].pvBuffer,
432 in_buf->pBuffers[0].cbBuffer);
434 out_buf->pBuffers[0].cbBuffer = in_buf->pBuffers[0].cbBuffer;
436 memset(in_buf->pBuffers[0].pvBuffer, 0, MAX_MESSAGE);
442 /**********************************************************************/
444 /*--------------------------------------------------------- */
445 /* The test functions */
447 static void testInitSecurityInterface(void)
449 PSecurityFunctionTable sec_fun_table = NULL;
451 sec_fun_table = pInitSecurityInterfaceA();
452 ok(sec_fun_table != NULL, "InitSecurityInterface() returned NULL.\n");
456 static void testEnumerateSecurityPackages(void)
459 SECURITY_STATUS sec_status;
460 ULONG num_packages, i;
461 PSecPkgInfo pkg_info = NULL;
463 trace("Running testEnumerateSecurityPackages\n");
465 sec_status = pEnumerateSecurityPackagesA(&num_packages, &pkg_info);
467 ok(sec_status == SEC_E_OK,
468 "EnumerateSecurityPackages() should return %ld, not %08lx\n",
469 (LONG)SEC_E_OK, (LONG)sec_status);
471 ok(num_packages > 0, "Number of sec packages should be > 0 ,but is %ld\n",
472 num_packages);
474 ok(pkg_info != NULL,
475 "pkg_info should not be NULL after EnumerateSecurityPackages\n");
477 trace("Number of packages: %ld\n", num_packages);
478 for(i = 0; i < num_packages; ++i){
479 trace("%ld: Package \"%s\"\n", i, pkg_info[i].Name);
480 trace("Supported flags:\n");
481 if(pkg_info[i].fCapabilities & SECPKG_FLAG_INTEGRITY)
482 trace("\tSECPKG_FLAG_INTEGRITY\n");
483 if(pkg_info[i].fCapabilities & SECPKG_FLAG_PRIVACY)
484 trace("\tSECPKG_FLAG_PRIVACY\n");
485 if(pkg_info[i].fCapabilities & SECPKG_FLAG_TOKEN_ONLY)
486 trace("\tSECPKG_FLAG_TOKEN_ONLY\n");
487 if(pkg_info[i].fCapabilities & SECPKG_FLAG_DATAGRAM)
488 trace("\tSECPKG_FLAG_DATAGRAM\n");
489 if(pkg_info[i].fCapabilities & SECPKG_FLAG_CONNECTION)
490 trace("\tSECPKG_FLAG_CONNECTION\n");
491 if(pkg_info[i].fCapabilities & SECPKG_FLAG_MULTI_REQUIRED)
492 trace("\tSECPKG_FLAG_MULTI_REQUIRED\n");
493 if(pkg_info[i].fCapabilities & SECPKG_FLAG_CLIENT_ONLY)
494 trace("\tSECPKG_FLAG_CLIENT_ONLY\n");
495 if(pkg_info[i].fCapabilities & SECPKG_FLAG_EXTENDED_ERROR)
496 trace("\tSECPKG_FLAG_EXTENDED_ERROR\n");
497 if(pkg_info[i].fCapabilities & SECPKG_FLAG_IMPERSONATION)
498 trace("\tSECPKG_FLAG_IMPERSONATION\n");
499 if(pkg_info[i].fCapabilities & SECPKG_FLAG_ACCEPT_WIN32_NAME)
500 trace("\tSECPKG_FLAG_ACCEPT_WIN32_NAME\n");
501 if(pkg_info[i].fCapabilities & SECPKG_FLAG_STREAM)
502 trace("\tSECPKG_FLAG_STREAM\n");
503 if(pkg_info[i].fCapabilities & SECPKG_FLAG_READONLY_WITH_CHECKSUM)
504 trace("\tSECPKG_FLAG_READONLY_WITH_CHECKSUM\n");
505 trace("Comment: %s\n", pkg_info[i].Comment);
506 trace("\n");
509 pFreeContextBuffer(pkg_info);
513 static void testQuerySecurityPackageInfo(void)
515 SECURITY_STATUS sec_status;
516 PSecPkgInfo pkg_info;
518 trace("Running testQuerySecurityPackageInfo\n");
520 /* Test with an existing package. Test should pass */
522 pkg_info = (void *)0xdeadbeef;
523 sec_status = setupPackageA("NTLM", &pkg_info);
525 ok((sec_status == SEC_E_OK) || (sec_status == SEC_E_SECPKG_NOT_FOUND),
526 "Return value of QuerySecurityPackageInfo() shouldn't be %s\n",
527 getSecError(sec_status) );
529 if (sec_status == SEC_E_OK)
531 ok(pkg_info != (void *)0xdeadbeef, "wrong pkg_info address %p\n", pkg_info);
532 ok(pkg_info->wVersion == 1, "wVersion always should be 1, but is %d\n", pkg_info->wVersion);
533 /* there is no point in testing pkg_info->cbMaxToken since it varies
534 * between implementations.
538 sec_status = pFreeContextBuffer(pkg_info);
540 ok( sec_status == SEC_E_OK,
541 "Return value of FreeContextBuffer() shouldn't be %s\n",
542 getSecError(sec_status) );
544 /* Test with a nonexistent package, test should fail */
546 pkg_info = (void *)0xdeadbeef;
547 sec_status = pQuerySecurityPackageInfoA("Winetest", &pkg_info);
549 ok( sec_status != SEC_E_OK,
550 "Return value of QuerySecurityPackageInfo() should not be %s for a nonexistent package\n", getSecError(SEC_E_OK));
552 ok(pkg_info == (void *)0xdeadbeef, "wrong pkg_info address %p\n", pkg_info);
554 sec_status = pFreeContextBuffer(pkg_info);
556 ok( sec_status == SEC_E_OK,
557 "Return value of FreeContextBuffer() shouldn't be %s\n",
558 getSecError(sec_status) );
561 void testAuth(char* sec_pkg_name, const char* domain)
563 SECURITY_STATUS sec_status;
564 PSecPkgInfo pkg_info = NULL;
565 CredHandle server_cred;
566 CredHandle client_cred;
567 CtxtHandle server_ctxt;
568 CtxtHandle client_ctxt;
570 PSecBufferDesc client_in = NULL, client_out = NULL;
571 PSecBufferDesc server_in = NULL, server_out = NULL;
573 BOOL continue_client = FALSE, continue_server = FALSE;
575 if(setupPackageA(sec_pkg_name, &pkg_info) == SEC_E_OK)
577 pFreeContextBuffer(pkg_info);
578 sec_status = setupClient(&client_cred, "testuser", "testpass", domain,
579 sec_pkg_name);
581 if(sec_status != SEC_E_OK)
583 trace("Error: Setting up the client returned %s, exiting test!\n",
584 getSecError(sec_status));
585 pFreeCredentialsHandle(&client_cred);
586 return;
589 sec_status = setupServer(&server_cred, sec_pkg_name);
591 if(sec_status != SEC_E_OK)
593 trace("Error: Setting up the server returned %s, exiting test!\n",
594 getSecError(sec_status));
595 pFreeCredentialsHandle(&server_cred);
596 pFreeCredentialsHandle(&client_cred);
597 return;
600 setupBuffers(&client_in, &client_out);
601 setupBuffers(&server_in, &server_out);
603 sec_status = runClient(&client_cred, &client_ctxt, client_in, client_out,
604 TRUE);
606 ok(sec_status == SEC_E_OK || sec_status == SEC_I_CONTINUE_NEEDED,
607 "Running the client returned %s, more tests will fail from now.\n",
608 getSecError(sec_status));
610 if(sec_status == SEC_I_CONTINUE_NEEDED)
611 continue_client = TRUE;
613 communicate(client_out, server_in);
615 sec_status = runServer(&server_cred, &server_ctxt, server_in, server_out,
616 TRUE);
618 ok(sec_status == SEC_E_OK || sec_status == SEC_I_CONTINUE_NEEDED,
619 "Running the server returned %s, more tests will fail from now.\n",
620 getSecError(sec_status));
622 if(sec_status == SEC_I_CONTINUE_NEEDED)
624 continue_server = TRUE;
625 communicate(server_out, client_in);
628 if(continue_client)
630 sec_status = runClient(&client_cred, &client_ctxt, client_in, client_out,
631 FALSE);
633 ok(sec_status == SEC_E_OK,
634 "Running the client returned %s, more tests will fail from now.\n",
635 getSecError(sec_status));
637 communicate(client_out, server_in);
640 if(continue_server)
642 sec_status = runServer(&server_cred, &server_ctxt, server_in, server_out,
643 FALSE);
644 ok(sec_status == SEC_E_OK || SEC_E_LOGON_DENIED,
645 "Running the server returned %s.\n", getSecError(sec_status));
648 cleanupBuffers(client_in, client_out);
649 cleanupBuffers(server_in, server_out);
651 sec_status = pDeleteSecurityContext(&server_ctxt);
652 ok(sec_status == SEC_E_OK, "DeleteSecurityContext(server) returned %s\n",
653 getSecError(sec_status));
655 sec_status = pDeleteSecurityContext(&client_ctxt);
656 ok(sec_status == SEC_E_OK, "DeleteSecurityContext(client) returned %s\n",
657 getSecError(sec_status));
659 sec_status = pFreeCredentialsHandle(&server_cred);
660 ok(sec_status == SEC_E_OK, "FreeCredentialsHandle(server) returned %s\n",
661 getSecError(sec_status));
663 sec_status = pFreeCredentialsHandle(&client_cred);
664 ok(sec_status == SEC_E_OK, "FreeCredentialsHandle(client) returned %s\n",
665 getSecError(sec_status));
667 else
669 trace("Package not installed, skipping test.\n");
674 START_TEST(main)
676 InitFunctionPtrs();
677 if(pInitSecurityInterfaceA)
678 testInitSecurityInterface();
679 if(pFreeContextBuffer)
681 if(pEnumerateSecurityPackagesA)
682 testEnumerateSecurityPackages();
683 if(pQuerySecurityPackageInfoA)
685 testQuerySecurityPackageInfo();
686 if(pInitSecurityInterfaceA)
687 testAuth("NTLM", "WORKGROUP");
690 if(secdll)
691 FreeLibrary(secdll);