2 * Credential Function Tests
4 * Copyright 2007 Robert Shearman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/test.h"
30 static BOOL (WINAPI
*pCredDeleteA
)(LPCSTR
,DWORD
,DWORD
);
31 static BOOL (WINAPI
*pCredEnumerateA
)(LPCSTR
,DWORD
,DWORD
*,PCREDENTIALA
**);
32 static VOID (WINAPI
*pCredFree
)(PVOID
);
33 static BOOL (WINAPI
*pCredGetSessionTypes
)(DWORD
,LPDWORD
);
34 static BOOL (WINAPI
*pCredReadA
)(LPCSTR
,DWORD
,DWORD
,PCREDENTIALA
*);
35 static BOOL (WINAPI
*pCredRenameA
)(LPCSTR
,LPCSTR
,DWORD
,DWORD
);
36 static BOOL (WINAPI
*pCredWriteA
)(PCREDENTIALA
,DWORD
);
37 static BOOL (WINAPI
*pCredReadDomainCredentialsA
)(PCREDENTIAL_TARGET_INFORMATIONA
,DWORD
,DWORD
*,PCREDENTIALA
**);
38 static BOOL (WINAPI
*pCredMarshalCredentialA
)(CRED_MARSHAL_TYPE
,PVOID
,LPSTR
*);
39 static BOOL (WINAPI
*pCredUnmarshalCredentialA
)(LPCSTR
,PCRED_MARSHAL_TYPE
,PVOID
);
41 #define TEST_TARGET_NAME "credtest.winehq.org"
42 #define TEST_TARGET_NAME2 "credtest2.winehq.org"
43 static const WCHAR TEST_PASSWORD
[] = {'p','4','$','$','w','0','r','d','!',0};
45 static void test_CredReadA(void)
50 SetLastError(0xdeadbeef);
51 ret
= pCredReadA(TEST_TARGET_NAME
, -1, 0, &cred
);
52 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
53 "CredReadA should have failed with ERROR_INVALID_PARAMETER instead of %d\n",
56 SetLastError(0xdeadbeef);
57 ret
= pCredReadA(TEST_TARGET_NAME
, CRED_TYPE_GENERIC
, 0xdeadbeef, &cred
);
58 ok(!ret
&& ( GetLastError() == ERROR_INVALID_FLAGS
|| GetLastError() == ERROR_INVALID_PARAMETER
),
59 "CredReadA should have failed with ERROR_INVALID_FLAGS or ERROR_INVALID_PARAMETER instead of %d\n",
62 SetLastError(0xdeadbeef);
63 ret
= pCredReadA(NULL
, CRED_TYPE_GENERIC
, 0, &cred
);
64 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
65 "CredReadA should have failed with ERROR_INVALID_PARAMETER instead of %d\n",
69 static void test_CredWriteA(void)
74 SetLastError(0xdeadbeef);
75 ret
= pCredWriteA(NULL
, 0);
76 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
77 "CredWriteA should have failed with ERROR_INVALID_PARAMETER instead of %d\n",
81 new_cred
.Type
= CRED_TYPE_GENERIC
;
82 new_cred
.TargetName
= NULL
;
83 new_cred
.Comment
= (char *)"Comment";
84 new_cred
.CredentialBlobSize
= 0;
85 new_cred
.CredentialBlob
= NULL
;
86 new_cred
.Persist
= CRED_PERSIST_ENTERPRISE
;
87 new_cred
.AttributeCount
= 0;
88 new_cred
.Attributes
= NULL
;
89 new_cred
.TargetAlias
= NULL
;
90 new_cred
.UserName
= (char *)"winetest";
92 SetLastError(0xdeadbeef);
93 ret
= pCredWriteA(&new_cred
, 0);
94 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
95 "CredWriteA should have failed with ERROR_INVALID_PARAMETER instead of %d\n",
98 new_cred
.TargetName
= (char *)TEST_TARGET_NAME
;
99 new_cred
.Type
= CRED_TYPE_DOMAIN_PASSWORD
;
101 SetLastError(0xdeadbeef);
102 ret
= pCredWriteA(&new_cred
, 0);
105 ok(GetLastError() == ERROR_SUCCESS
||
106 GetLastError() == ERROR_IO_PENDING
, /* Vista */
107 "Expected ERROR_IO_PENDING, got %d\n", GetLastError());
111 ok(GetLastError() == ERROR_BAD_USERNAME
||
112 GetLastError() == ERROR_NO_SUCH_LOGON_SESSION
, /* Vista */
113 "CredWrite with username without domain should return ERROR_BAD_USERNAME"
114 "or ERROR_NO_SUCH_LOGON_SESSION not %d\n", GetLastError());
117 new_cred
.UserName
= NULL
;
118 SetLastError(0xdeadbeef);
119 ret
= pCredWriteA(&new_cred
, 0);
120 ok(!ret
&& GetLastError() == ERROR_BAD_USERNAME
,
121 "CredWriteA with NULL username should have failed with ERROR_BAD_USERNAME instead of %d\n",
125 static void test_CredDeleteA(void)
129 SetLastError(0xdeadbeef);
130 ret
= pCredDeleteA(TEST_TARGET_NAME
, -1, 0);
131 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
132 "CredDeleteA should have failed with ERROR_INVALID_PARAMETER instead of %d\n",
135 SetLastError(0xdeadbeef);
136 ret
= pCredDeleteA(TEST_TARGET_NAME
, CRED_TYPE_GENERIC
, 0xdeadbeef);
137 ok(!ret
&& ( GetLastError() == ERROR_INVALID_FLAGS
|| GetLastError() == ERROR_INVALID_PARAMETER
/* Vista */ ),
138 "CredDeleteA should have failed with ERROR_INVALID_FLAGS or ERROR_INVALID_PARAMETER instead of %d\n",
142 static void test_CredReadDomainCredentialsA(void)
145 char target_name
[] = "no_such_target";
146 CREDENTIAL_TARGET_INFORMATIONA info
= {target_name
, NULL
, target_name
, NULL
, NULL
, NULL
, NULL
, 0, 0, NULL
};
150 if (!pCredReadDomainCredentialsA
)
152 win_skip("CredReadDomainCredentialsA() is not implemented\n");
156 /* these two tests would crash on both native and Wine. Implementations
157 * does not check for NULL output pointers and try to zero them out early */
160 ret
= pCredReadDomainCredentialsA(&info
, 0, NULL
, &creds
);
161 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
, "!\n");
162 ret
= pCredReadDomainCredentialsA(&info
, 0, &count
, NULL
);
163 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
, "!\n");
166 SetLastError(0xdeadbeef);
167 ret
= pCredReadDomainCredentialsA(NULL
, 0, &count
, &creds
);
168 ok(!ret
&& GetLastError() == ERROR_INVALID_PARAMETER
,
169 "CredReadDomainCredentialsA should have failed with ERROR_INVALID_PARAMETER instead of %d\n",
172 SetLastError(0xdeadbeef);
173 creds
= (void*)0x12345;
175 ret
= pCredReadDomainCredentialsA(&info
, 0, &count
, &creds
);
176 ok(!ret
&& GetLastError() == ERROR_NOT_FOUND
,
177 "CredReadDomainCredentialsA should have failed with ERROR_NOT_FOUND instead of %d\n",
179 ok(count
==0 && creds
== NULL
, "CredReadDomainCredentialsA must not return any result\n");
181 info
.TargetName
= NULL
;
183 SetLastError(0xdeadbeef);
184 ret
= pCredReadDomainCredentialsA(&info
, 0, &count
, &creds
);
185 ok(!ret
, "CredReadDomainCredentialsA should have failed\n");
186 ok(GetLastError() == ERROR_NOT_FOUND
||
187 GetLastError() == ERROR_INVALID_PARAMETER
, /* Vista, W2K8 */
188 "Expected ERROR_NOT_FOUND or ERROR_INVALID_PARAMETER instead of %d\n",
191 info
.DnsServerName
= NULL
;
193 SetLastError(0xdeadbeef);
194 ret
= pCredReadDomainCredentialsA(&info
, 0, &count
, &creds
);
195 ok(!ret
, "CredReadDomainCredentialsA should have failed\n");
196 ok(GetLastError() == ERROR_NOT_FOUND
||
197 GetLastError() == ERROR_INVALID_PARAMETER
, /* Vista, W2K8 */
198 "Expected ERROR_NOT_FOUND or ERROR_INVALID_PARAMETER instead of %d\n",
202 static void check_blob(int line
, DWORD cred_type
, PCREDENTIALA cred
)
204 if (cred_type
== CRED_TYPE_DOMAIN_PASSWORD
)
207 ok_(__FILE__
, line
)(cred
->CredentialBlobSize
== 0, "expected CredentialBlobSize of 0 but got %d\n", cred
->CredentialBlobSize
);
209 ok_(__FILE__
, line
)(!cred
->CredentialBlob
, "expected NULL credentials but got %p\n", cred
->CredentialBlob
);
213 DWORD size
=sizeof(TEST_PASSWORD
);
214 ok_(__FILE__
, line
)(cred
->CredentialBlobSize
== size
, "expected CredentialBlobSize of %u but got %u\n", size
, cred
->CredentialBlobSize
);
215 ok_(__FILE__
, line
)(cred
->CredentialBlob
!= NULL
, "CredentialBlob should be present\n");
216 if (cred
->CredentialBlob
)
217 ok_(__FILE__
, line
)(!memcmp(cred
->CredentialBlob
, TEST_PASSWORD
, size
), "wrong CredentialBlob\n");
221 static void test_generic(void)
226 CREDENTIALA new_cred
;
231 new_cred
.Type
= CRED_TYPE_GENERIC
;
232 new_cred
.TargetName
= (char *)TEST_TARGET_NAME
;
233 new_cred
.Comment
= (char *)"Comment";
234 new_cred
.CredentialBlobSize
= sizeof(TEST_PASSWORD
);
235 new_cred
.CredentialBlob
= (LPBYTE
)TEST_PASSWORD
;
236 new_cred
.Persist
= CRED_PERSIST_ENTERPRISE
;
237 new_cred
.AttributeCount
= 0;
238 new_cred
.Attributes
= NULL
;
239 new_cred
.TargetAlias
= NULL
;
240 new_cred
.UserName
= (char *)"winetest";
242 ret
= pCredWriteA(&new_cred
, 0);
243 ok(ret
|| broken(GetLastError() == ERROR_NO_SUCH_LOGON_SESSION
),
244 "CredWriteA failed with error %d\n", GetLastError());
247 skip("couldn't write generic credentials, skipping tests\n");
251 ret
= pCredEnumerateA(NULL
, 0, &count
, &creds
);
252 ok(ret
, "CredEnumerateA failed with error %d\n", GetLastError());
254 for (i
= 0; i
< count
; i
++)
256 if (!strcmp(creds
[i
]->TargetName
, TEST_TARGET_NAME
))
258 ok(creds
[i
]->Type
== CRED_TYPE_GENERIC
||
259 creds
[i
]->Type
== CRED_TYPE_DOMAIN_PASSWORD
, /* Vista */
260 "expected creds[%d]->Type CRED_TYPE_GENERIC or CRED_TYPE_DOMAIN_PASSWORD but got %d\n", i
, creds
[i
]->Type
);
261 ok(!creds
[i
]->Flags
, "expected creds[%d]->Flags 0 but got 0x%x\n", i
, creds
[i
]->Flags
);
262 ok(!strcmp(creds
[i
]->Comment
, "Comment"), "expected creds[%d]->Comment \"Comment\" but got \"%s\"\n", i
, creds
[i
]->Comment
);
263 check_blob(__LINE__
, creds
[i
]->Type
, creds
[i
]);
264 ok(creds
[i
]->Persist
, "expected creds[%d]->Persist CRED_PERSIST_ENTERPRISE but got %d\n", i
, creds
[i
]->Persist
);
265 ok(!strcmp(creds
[i
]->UserName
, "winetest"), "expected creds[%d]->UserName \"winetest\" but got \"%s\"\n", i
, creds
[i
]->UserName
);
270 ok(found
, "credentials not found\n");
272 ret
= pCredReadA(TEST_TARGET_NAME
, CRED_TYPE_GENERIC
, 0, &cred
);
273 ok(ret
, "CredReadA failed with error %d\n", GetLastError());
276 ret
= pCredDeleteA(TEST_TARGET_NAME
, CRED_TYPE_GENERIC
, 0);
277 ok(ret
, "CredDeleteA failed with error %d\n", GetLastError());
280 static void test_domain_password(DWORD cred_type
)
285 CREDENTIALA new_cred
;
290 new_cred
.Type
= cred_type
;
291 new_cred
.TargetName
= (char *)TEST_TARGET_NAME
;
292 new_cred
.Comment
= (char *)"Comment";
293 new_cred
.CredentialBlobSize
= sizeof(TEST_PASSWORD
);
294 new_cred
.CredentialBlob
= (LPBYTE
)TEST_PASSWORD
;
295 new_cred
.Persist
= CRED_PERSIST_ENTERPRISE
;
296 new_cred
.AttributeCount
= 0;
297 new_cred
.Attributes
= NULL
;
298 new_cred
.TargetAlias
= NULL
;
299 new_cred
.UserName
= (char *)"test\\winetest";
300 ret
= pCredWriteA(&new_cred
, 0);
301 if (!ret
&& GetLastError() == ERROR_NO_SUCH_LOGON_SESSION
)
303 skip("CRED_TYPE_DOMAIN_PASSWORD credentials are not supported "
304 "or are disabled. Skipping\n");
307 ok(ret
, "CredWriteA failed with error %d\n", GetLastError());
309 ret
= pCredEnumerateA(NULL
, 0, &count
, &creds
);
310 ok(ret
, "CredEnumerateA failed with error %d\n", GetLastError());
312 for (i
= 0; i
< count
; i
++)
314 if (!strcmp(creds
[i
]->TargetName
, TEST_TARGET_NAME
))
316 ok(creds
[i
]->Type
== cred_type
, "expected creds[%d]->Type CRED_TYPE_DOMAIN_PASSWORD but got %d\n", i
, creds
[i
]->Type
);
317 ok(!creds
[i
]->Flags
, "expected creds[%d]->Flags 0 but got 0x%x\n", i
, creds
[i
]->Flags
);
318 ok(!strcmp(creds
[i
]->Comment
, "Comment"), "expected creds[%d]->Comment \"Comment\" but got \"%s\"\n", i
, creds
[i
]->Comment
);
319 check_blob(__LINE__
, cred_type
, creds
[i
]);
320 ok(creds
[i
]->Persist
, "expected creds[%d]->Persist CRED_PERSIST_ENTERPRISE but got %d\n", i
, creds
[i
]->Persist
);
321 ok(!strcmp(creds
[i
]->UserName
, "test\\winetest"), "expected creds[%d]->UserName \"winetest\" but got \"%s\"\n", i
, creds
[i
]->UserName
);
326 ok(found
, "credentials not found\n");
328 ret
= pCredReadA(TEST_TARGET_NAME
, cred_type
, 0, &cred
);
329 ok(ret
, "CredReadA failed with error %d\n", GetLastError());
330 if (ret
) /* don't check the values of cred, if CredReadA failed. */
332 check_blob(__LINE__
, cred_type
, cred
);
336 ret
= pCredDeleteA(TEST_TARGET_NAME
, cred_type
, 0);
337 ok(ret
, "CredDeleteA failed with error %d\n", GetLastError());
340 static void test_CredMarshalCredentialA(void)
342 static WCHAR emptyW
[] = {0};
343 static WCHAR tW
[] = {'t',0};
344 static WCHAR teW
[] = {'t','e',0};
345 static WCHAR tesW
[] = {'t','e','s',0};
346 static WCHAR testW
[] = {'t','e','s','t',0};
347 static WCHAR test1W
[] = {'t','e','s','t','1',0};
348 CERT_CREDENTIAL_INFO cert
;
349 USERNAME_TARGET_CREDENTIAL_INFO username
;
354 SetLastError( 0xdeadbeef );
355 ret
= pCredMarshalCredentialA( 0, NULL
, NULL
);
356 error
= GetLastError();
357 ok( !ret
, "unexpected success\n" );
358 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
360 memset( cert
.rgbHashOfCert
, 0, sizeof(cert
.rgbHashOfCert
) );
361 cert
.cbSize
= sizeof(cert
);
362 SetLastError( 0xdeadbeef );
363 ret
= pCredMarshalCredentialA( 0, &cert
, NULL
);
364 error
= GetLastError();
365 ok( !ret
, "unexpected success\n" );
366 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
368 str
= (char *)0xdeadbeef;
369 SetLastError( 0xdeadbeef );
370 ret
= pCredMarshalCredentialA( 0, &cert
, &str
);
371 error
= GetLastError();
372 ok( !ret
, "unexpected success\n" );
373 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
374 ok( str
== (char *)0xdeadbeef, "got %p\n", str
);
376 SetLastError( 0xdeadbeef );
377 ret
= pCredMarshalCredentialA( CertCredential
, NULL
, NULL
);
378 error
= GetLastError();
379 ok( !ret
, "unexpected success\n" );
380 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
383 SetLastError( 0xdeadbeef );
384 ret
= pCredMarshalCredentialA( CertCredential
, &cert
, NULL
);
385 error
= GetLastError();
386 ok( !ret
, "unexpected success\n" );
387 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
391 str
= (char *)0xdeadbeef;
392 SetLastError( 0xdeadbeef );
393 ret
= pCredMarshalCredentialA( CertCredential
, &cert
, &str
);
394 error
= GetLastError();
395 ok( !ret
, "unexpected success\n" );
396 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
397 ok( str
== (char *)0xdeadbeef, "got %p\n", str
);
399 cert
.cbSize
= sizeof(cert
) + 4;
401 ret
= pCredMarshalCredentialA( CertCredential
, &cert
, &str
);
402 ok( ret
, "unexpected failure %u\n", GetLastError() );
403 ok( str
!= NULL
, "str not set\n" );
404 ok( !lstrcmpA( str
, "@@BAAAAAAAAAAAAAAAAAAAAAAAAAAA" ), "got %s\n", str
);
407 cert
.cbSize
= sizeof(cert
);
408 cert
.rgbHashOfCert
[0] = 2;
410 ret
= pCredMarshalCredentialA( CertCredential
, &cert
, &str
);
411 ok( ret
, "unexpected failure %u\n", GetLastError() );
412 ok( str
!= NULL
, "str not set\n" );
413 ok( !lstrcmpA( str
, "@@BCAAAAAAAAAAAAAAAAAAAAAAAAAA" ), "got %s\n", str
);
416 cert
.rgbHashOfCert
[0] = 255;
418 ret
= pCredMarshalCredentialA( CertCredential
, &cert
, &str
);
419 ok( ret
, "unexpected failure %u\n", GetLastError() );
420 ok( str
!= NULL
, "str not set\n" );
421 ok( !lstrcmpA( str
, "@@B-DAAAAAAAAAAAAAAAAAAAAAAAAA" ), "got %s\n", str
);
424 cert
.rgbHashOfCert
[0] = 1;
425 cert
.rgbHashOfCert
[1] = 1;
427 ret
= pCredMarshalCredentialA( CertCredential
, &cert
, &str
);
428 ok( ret
, "unexpected failure %u\n", GetLastError() );
429 ok( str
!= NULL
, "str not set\n" );
430 ok( !lstrcmpA( str
, "@@BBEAAAAAAAAAAAAAAAAAAAAAAAAA" ), "got %s\n", str
);
433 cert
.rgbHashOfCert
[0] = 1;
434 cert
.rgbHashOfCert
[1] = 1;
435 cert
.rgbHashOfCert
[2] = 1;
437 ret
= pCredMarshalCredentialA( CertCredential
, &cert
, &str
);
438 ok( ret
, "unexpected failure %u\n", GetLastError() );
439 ok( str
!= NULL
, "str not set\n" );
440 ok( !lstrcmpA( str
, "@@BBEQAAAAAAAAAAAAAAAAAAAAAAAA" ), "got %s\n", str
);
443 memset( cert
.rgbHashOfCert
, 0, sizeof(cert
.rgbHashOfCert
) );
444 cert
.rgbHashOfCert
[0] = 'W';
445 cert
.rgbHashOfCert
[1] = 'i';
446 cert
.rgbHashOfCert
[2] = 'n';
447 cert
.rgbHashOfCert
[3] = 'e';
449 ret
= pCredMarshalCredentialA( CertCredential
, &cert
, &str
);
450 ok( ret
, "unexpected failure %u\n", GetLastError() );
451 ok( str
!= NULL
, "str not set\n" );
452 ok( !lstrcmpA( str
, "@@BXlmblBAAAAAAAAAAAAAAAAAAAAA" ), "got %s\n", str
);
455 memset( cert
.rgbHashOfCert
, 0xff, sizeof(cert
.rgbHashOfCert
) );
457 ret
= pCredMarshalCredentialA( CertCredential
, &cert
, &str
);
458 ok( ret
, "unexpected failure %u\n", GetLastError() );
459 ok( str
!= NULL
, "str not set\n" );
460 ok( !lstrcmpA( str
, "@@B--------------------------P" ), "got %s\n", str
);
463 username
.UserName
= NULL
;
464 str
= (char *)0xdeadbeef;
465 SetLastError( 0xdeadbeef );
466 ret
= pCredMarshalCredentialA( UsernameTargetCredential
, &username
, &str
);
467 error
= GetLastError();
468 ok( !ret
, "unexpected success\n" );
469 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
470 ok( str
== (char *)0xdeadbeef, "got %p\n", str
);
472 username
.UserName
= emptyW
;
473 str
= (char *)0xdeadbeef;
474 SetLastError( 0xdeadbeef );
475 ret
= pCredMarshalCredentialA( UsernameTargetCredential
, &username
, &str
);
476 error
= GetLastError();
477 ok( !ret
, "unexpected success\n" );
478 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
479 ok( str
== (char *)0xdeadbeef, "got %p\n", str
);
481 username
.UserName
= tW
;
483 ret
= pCredMarshalCredentialA( UsernameTargetCredential
, &username
, &str
);
484 ok( ret
, "unexpected failure %u\n", GetLastError() );
485 ok( str
!= NULL
, "str not set\n" );
486 ok( !lstrcmpA( str
, "@@CCAAAAA0BA" ), "got %s\n", str
);
489 username
.UserName
= teW
;
491 ret
= pCredMarshalCredentialA( UsernameTargetCredential
, &username
, &str
);
492 ok( ret
, "unexpected failure %u\n", GetLastError() );
493 ok( str
!= NULL
, "str not set\n" );
494 ok( !lstrcmpA( str
, "@@CEAAAAA0BQZAA" ), "got %s\n", str
);
497 username
.UserName
= tesW
;
499 ret
= pCredMarshalCredentialA( UsernameTargetCredential
, &username
, &str
);
500 ok( ret
, "unexpected failure %u\n", GetLastError() );
501 ok( str
!= NULL
, "str not set\n" );
502 ok( !lstrcmpA( str
, "@@CGAAAAA0BQZAMHA" ), "got %s\n", str
);
505 username
.UserName
= testW
;
507 ret
= pCredMarshalCredentialA( UsernameTargetCredential
, &username
, &str
);
508 ok( ret
, "unexpected failure %u\n", GetLastError() );
509 ok( str
!= NULL
, "str not set\n" );
510 ok( !lstrcmpA( str
, "@@CIAAAAA0BQZAMHA0BA" ), "got %s\n", str
);
513 username
.UserName
= test1W
;
515 ret
= pCredMarshalCredentialA( UsernameTargetCredential
, &username
, &str
);
516 ok( ret
, "unexpected failure %u\n", GetLastError() );
517 ok( str
!= NULL
, "str not set\n" );
518 ok( !lstrcmpA( str
, "@@CKAAAAA0BQZAMHA0BQMAA" ), "got %s\n", str
);
522 static void test_CredUnmarshalCredentialA(void)
524 static WCHAR tW
[] = {'t',0};
525 static WCHAR testW
[] = {'t','e','s','t',0};
526 CERT_CREDENTIAL_INFO
*cert
;
527 USERNAME_TARGET_CREDENTIAL_INFO
*username
;
528 CRED_MARSHAL_TYPE type
;
533 SetLastError( 0xdeadbeef );
534 ret
= pCredUnmarshalCredentialA( NULL
, NULL
, NULL
);
535 error
= GetLastError();
536 ok( !ret
, "unexpected success\n" );
537 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
540 SetLastError( 0xdeadbeef );
541 ret
= pCredUnmarshalCredentialA( NULL
, NULL
, (void **)&cert
);
542 error
= GetLastError();
543 ok( !ret
, "unexpected success\n" );
544 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
548 SetLastError( 0xdeadbeef );
549 ret
= pCredUnmarshalCredentialA( NULL
, &type
, (void **)&cert
);
550 error
= GetLastError();
551 ok( !ret
, "unexpected success\n" );
552 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
556 SetLastError( 0xdeadbeef );
557 ret
= pCredUnmarshalCredentialA( "", &type
, (void **)&cert
);
558 error
= GetLastError();
559 ok( !ret
, "unexpected success\n" );
560 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
563 SetLastError( 0xdeadbeef );
564 ret
= pCredUnmarshalCredentialA( "@@BAAAAAAAAAAAAAAAAAAAAAAAAAAA", &type
, NULL
);
565 error
= GetLastError();
566 ok( !ret
, "unexpected success\n" );
567 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
569 SetLastError( 0xdeadbeef );
570 ret
= pCredUnmarshalCredentialA( "@@BAAAAAAAAAAAAAAAAAAAAAAAAAAA", NULL
, (void **)&cert
);
571 error
= GetLastError();
572 ok( !ret
, "unexpected success\n" );
573 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
578 ret
= pCredUnmarshalCredentialA( "@@BAAAAAAAAAAAAAAAAAAAAAAAAAAA", &type
, (void **)&cert
);
579 ok( ret
, "unexpected failure %u\n", GetLastError() );
580 ok( type
== CertCredential
, "got %u\n", type
);
581 ok( cert
!= NULL
, "cert is NULL\n" );
582 ok( cert
->cbSize
== sizeof(*cert
), "wrong size %u\n", cert
->cbSize
);
583 for (i
= 0; i
< sizeof(cert
->rgbHashOfCert
); i
++) ok( !cert
->rgbHashOfCert
[i
], "wrong data\n" );
588 ret
= pCredUnmarshalCredentialA( "@@BXlmblBAAAAAAAAAAAAAAAAAAAAA", &type
, (void **)&cert
);
589 ok( ret
, "unexpected failure %u\n", GetLastError() );
590 ok( type
== CertCredential
, "got %u\n", type
);
591 ok( cert
!= NULL
, "cert is NULL\n" );
592 ok( cert
->cbSize
== sizeof(*cert
), "wrong size %u\n", cert
->cbSize
);
593 ok( cert
->rgbHashOfCert
[0] == 'W', "wrong data)\n" );
594 ok( cert
->rgbHashOfCert
[1] == 'i', "wrong data\n" );
595 ok( cert
->rgbHashOfCert
[2] == 'n', "wrong data\n" );
596 ok( cert
->rgbHashOfCert
[3] == 'e', "wrong data\n" );
597 for (i
= 4; i
< sizeof(cert
->rgbHashOfCert
); i
++) ok( !cert
->rgbHashOfCert
[i
], "wrong data\n" );
600 SetLastError( 0xdeadbeef );
601 ret
= pCredUnmarshalCredentialA( "@@CAAAAAA", &type
, (void **)&username
);
602 error
= GetLastError();
603 ok( !ret
, "unexpected success\n" );
604 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
606 SetLastError( 0xdeadbeef );
607 ret
= pCredUnmarshalCredentialA( "@@CAAAAAA0BA", &type
, (void **)&username
);
608 error
= GetLastError();
609 ok( !ret
, "unexpected success\n" );
610 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
614 ret
= pCredUnmarshalCredentialA( "@@CCAAAAA0BA", &type
, (void **)&username
);
615 ok( ret
, "unexpected failure %u\n", GetLastError() );
616 ok( type
== UsernameTargetCredential
, "got %u\n", type
);
617 ok( username
!= NULL
, "username is NULL\n" );
618 ok( username
->UserName
!= NULL
, "UserName is NULL\n" );
619 ok( !lstrcmpW( username
->UserName
, tW
), "got %s\n", wine_dbgstr_w(username
->UserName
) );
620 pCredFree( username
);
624 ret
= pCredUnmarshalCredentialA( "@@CIAAAAA0BQZAMHA0BA", &type
, (void **)&username
);
625 ok( ret
, "unexpected failure %u\n", GetLastError() );
626 ok( type
== UsernameTargetCredential
, "got %u\n", type
);
627 ok( username
!= NULL
, "username is NULL\n" );
628 ok( username
->UserName
!= NULL
, "UserName is NULL\n" );
629 ok( !lstrcmpW( username
->UserName
, testW
), "got %s\n", wine_dbgstr_w(username
->UserName
) );
630 pCredFree( username
);
635 DWORD persists
[CRED_TYPE_MAXIMUM
];
637 pCredEnumerateA
= (void *)GetProcAddress(GetModuleHandle("advapi32.dll"), "CredEnumerateA");
638 pCredFree
= (void *)GetProcAddress(GetModuleHandle("advapi32.dll"), "CredFree");
639 pCredGetSessionTypes
= (void *)GetProcAddress(GetModuleHandle("advapi32.dll"), "CredGetSessionTypes");
640 pCredWriteA
= (void *)GetProcAddress(GetModuleHandle("advapi32.dll"), "CredWriteA");
641 pCredDeleteA
= (void *)GetProcAddress(GetModuleHandle("advapi32.dll"), "CredDeleteA");
642 pCredReadA
= (void *)GetProcAddress(GetModuleHandle("advapi32.dll"), "CredReadA");
643 pCredRenameA
= (void *)GetProcAddress(GetModuleHandle("advapi32.dll"), "CredRenameA");
644 pCredReadDomainCredentialsA
= (void *)GetProcAddress(GetModuleHandle("advapi32.dll"), "CredReadDomainCredentialsA");
645 pCredMarshalCredentialA
= (void *)GetProcAddress(GetModuleHandle("advapi32.dll"), "CredMarshalCredentialA");
646 pCredUnmarshalCredentialA
= (void *)GetProcAddress(GetModuleHandle("advapi32.dll"), "CredUnmarshalCredentialA");
648 if (!pCredEnumerateA
|| !pCredFree
|| !pCredWriteA
|| !pCredDeleteA
|| !pCredReadA
)
650 win_skip("credentials functions not present in advapi32.dll\n");
654 if (pCredGetSessionTypes
)
658 ret
= pCredGetSessionTypes(CRED_TYPE_MAXIMUM
, persists
);
659 ok(ret
, "CredGetSessionTypes failed with error %d\n", GetLastError());
660 ok(persists
[0] == CRED_PERSIST_NONE
, "persists[0] = %u instead of CRED_PERSIST_NONE\n", persists
[0]);
661 for (i
=0; i
< CRED_TYPE_MAXIMUM
; i
++)
662 ok(persists
[i
] <= CRED_PERSIST_ENTERPRISE
, "bad value for persists[%u]: %u\n", i
, persists
[i
]);
665 memset(persists
, CRED_PERSIST_ENTERPRISE
, sizeof(persists
));
671 test_CredReadDomainCredentialsA();
674 if (persists
[CRED_TYPE_GENERIC
] == CRED_PERSIST_NONE
)
675 skip("CRED_TYPE_GENERIC credentials are not supported or are disabled. Skipping\n");
679 trace("domain password:\n");
680 if (persists
[CRED_TYPE_DOMAIN_PASSWORD
] == CRED_PERSIST_NONE
)
681 skip("CRED_TYPE_DOMAIN_PASSWORD credentials are not supported or are disabled. Skipping\n");
683 test_domain_password(CRED_TYPE_DOMAIN_PASSWORD
);
685 trace("domain visible password:\n");
686 if (persists
[CRED_TYPE_DOMAIN_VISIBLE_PASSWORD
] == CRED_PERSIST_NONE
)
687 skip("CRED_TYPE_DOMAIN_VISIBLE_PASSWORD credentials are not supported or are disabled. Skipping\n");
689 test_domain_password(CRED_TYPE_DOMAIN_VISIBLE_PASSWORD
);
691 test_CredMarshalCredentialA();
692 test_CredUnmarshalCredentialA();