ReactOS 0.4.17-dev-806-gffa4164
credui.c
Go to the documentation of this file.
1/*
2 * Credentials User Interface Tests
3 *
4 * Copyright 2007 Robert Shearman for CodeWeavers
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include <stdarg.h>
22
23#include "windef.h"
24#include "winbase.h"
25#include "wincred.h"
26#include "sspi.h"
27
28#include "wine/test.h"
29
30static SECURITY_STATUS (SEC_ENTRY *pSspiEncodeAuthIdentityAsStrings)
32static void (SEC_ENTRY *pSspiFreeAuthIdentity)
34static ULONG (SEC_ENTRY *pSspiPromptForCredentialsW)
36
38{
39 static const WCHAR wszServerName[] = L"WineTest";
40 DWORD ret;
41 WCHAR username[256];
42 WCHAR password[256];
43 CREDUI_INFOW credui_info;
44 BOOL save = FALSE;
45
46 credui_info.cbSize = sizeof(credui_info);
47 credui_info.hwndParent = NULL;
48 credui_info.pszMessageText = NULL;
49 credui_info.hbmBanner = NULL;
50
52 ok(ret == ERROR_INVALID_PARAMETER /* 2003 + */ || ret == ERROR_NOT_FOUND /* XP */,
53 "CredUIConfirmCredentials should have returned ERROR_INVALID_PARAMETER or ERROR_NOT_FOUND instead of %ld\n", ret);
54
55 ret = CredUIConfirmCredentialsW(wszServerName, TRUE);
56 ok(ret == ERROR_NOT_FOUND, "CredUIConfirmCredentials should have returned ERROR_NOT_FOUND instead of %ld\n", ret);
57
58 username[0] = '\0';
59 password[0] = '\0';
64 ok(ret == ERROR_INVALID_FLAGS, "CredUIPromptForCredentials should have returned ERROR_INVALID_FLAGS instead of %ld\n", ret);
65
70 ok(ret == ERROR_INVALID_PARAMETER, "CredUIPromptForCredentials should have returned ERROR_INVALID_PARAMETER instead of %ld\n", ret);
71
72 ret = CredUIPromptForCredentialsW(NULL, wszServerName, NULL, 0, username,
76 ok(ret == ERROR_INVALID_PARAMETER, "CredUIPromptForCredentials should have returned ERROR_INVALID_PARAMETER instead of %ld\n", ret);
77
79 {
80 ret = CredUIPromptForCredentialsW(NULL, wszServerName, NULL, 0, username,
84 ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %ld\n", ret);
85 if (ret == ERROR_SUCCESS)
86 {
87 ret = CredUIConfirmCredentialsW(wszServerName, FALSE);
88 ok(ret == ERROR_SUCCESS, "CredUIConfirmCredentials failed with error %ld\n", ret);
89 }
90
91 credui_info.pszCaptionText = L"CREDUI_FLAGS_EXPECT_CONFIRMATION";
92 ret = CredUIPromptForCredentialsW(&credui_info, wszServerName, NULL, ERROR_ACCESS_DENIED,
96 ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %ld\n", ret);
97 if (ret == ERROR_SUCCESS)
98 {
99 ret = CredUIConfirmCredentialsW(wszServerName, FALSE);
100 ok(ret == ERROR_SUCCESS, "CredUIConfirmCredentials failed with error %ld\n", ret);
101 }
102
103 credui_info.pszCaptionText = L"CREDUI_FLAGS_INCORRECT_PASSWORD|CREDUI_FLAGS_EXPECT_CONFIRMATION";
104 ret = CredUIPromptForCredentialsW(&credui_info, wszServerName, NULL, 0,
108 ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %ld\n", ret);
109 if (ret == ERROR_SUCCESS)
110 {
111 ret = CredUIConfirmCredentialsW(wszServerName, FALSE);
112 ok(ret == ERROR_SUCCESS, "CredUIConfirmCredentials failed with error %ld\n", ret);
113 }
114
115
116 save = TRUE;
117 credui_info.pszCaptionText = L"CREDUI_FLAGS_DO_NOT_PERSIST|CREDUI_FLAGS_EXPECT_CONFIRMATION";
118 ret = CredUIPromptForCredentialsW(&credui_info, wszServerName, NULL, 0,
122 ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %ld\n", ret);
123 ok(save, "save flag should have been untouched\n");
124
125 save = FALSE;
126 credui_info.pszCaptionText = L"CREDUI_FLAGS_PERSIST|CREDUI_FLAGS_EXPECT_CONFIRMATION";
127 ret = CredUIPromptForCredentialsW(&credui_info, wszServerName, NULL, 0,
131 ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %ld\n", ret);
132 ok(!save, "save flag should have been untouched\n");
133 if (ret == ERROR_SUCCESS)
134 {
135 ret = CredUIConfirmCredentialsW(wszServerName, FALSE);
136 ok(ret == ERROR_SUCCESS, "CredUIConfirmCredentials failed with error %ld\n", ret);
137 }
138
139 }
140}
141
143{
144 ULONG ret;
148 const WCHAR *username, *domain, *creds;
149 int save;
150
151 if (!pSspiPromptForCredentialsW || !pSspiFreeAuthIdentity)
152 {
153 win_skip( "SspiPromptForCredentialsW is missing\n" );
154 return;
155 }
156
157 info.cbSize = sizeof(info);
158 info.hwndParent = NULL;
159 info.pszMessageText = L"SspiTest";
160 info.pszCaptionText = L"basic";
161 info.hbmBanner = NULL;
162 ret = pSspiPromptForCredentialsW( NULL, &info, 0, L"basic", NULL, &id, &save, 0 );
163 ok( ret == ERROR_INVALID_PARAMETER, "got %lu\n", ret );
164
165 ret = pSspiPromptForCredentialsW( L"SspiTest", &info, 0, NULL, NULL, &id, &save, 0 );
166 ok( ret == ERROR_NO_SUCH_PACKAGE, "got %lu\n", ret );
167
169 {
170 id = NULL;
171 save = -1;
172 ret = pSspiPromptForCredentialsW( L"SspiTest", &info, 0, L"basic", NULL, &id, &save, 0 );
173 ok( ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "got %lu\n", ret );
174 if (ret == ERROR_SUCCESS)
175 {
176 ok( id != NULL, "id not set\n" );
177 ok( save == TRUE || save == FALSE, "got %d\n", save );
178
179 username = creds = NULL;
180 domain = (const WCHAR *)0xdeadbeef;
181 status = pSspiEncodeAuthIdentityAsStrings( id, &username, &domain, &creds );
182 ok( status == SEC_E_OK, "got %lu\n", status );
183 ok( username != NULL, "username not set\n" );
184 ok( domain == NULL, "domain not set\n" );
185 ok( creds != NULL, "creds not set\n" );
186 pSspiFreeAuthIdentity( id );
187 }
188 }
189}
190
192{
193 HMODULE hcredui = GetModuleHandleA( "credui.dll" ), hsecur32 = LoadLibraryA( "secur32.dll" );
194
195 if (hcredui)
196 pSspiPromptForCredentialsW = (void *)GetProcAddress( hcredui, "SspiPromptForCredentialsW" );
197 if (hsecur32)
198 {
199 pSspiEncodeAuthIdentityAsStrings = (void *)GetProcAddress( hsecur32, "SspiEncodeAuthIdentityAsStrings" );
200 pSspiFreeAuthIdentity = (void *)GetProcAddress( hsecur32, "SspiFreeAuthIdentity" );
201 }
202
205
206 FreeLibrary( hsecur32 );
207}
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define ARRAY_SIZE(A)
Definition: main.h:20
static UCHAR password[]
Definition: bcrypt.c:520
static void test_SspiPromptForCredentials(void)
Definition: credui.c:142
static void PSEC_WINNT_AUTH_IDENTITY_OPAQUE
Definition: credui.c:35
static void PCWSTR
Definition: credui.c:35
static void test_CredUIPromptForCredentials(void)
Definition: credui.c:37
static void ULONG
Definition: credui.c:35
DWORD WINAPI CredUIPromptForCredentialsW(PCREDUI_INFOW pUIInfo, PCWSTR pszTargetName, PCtxtHandle Reserved, DWORD dwAuthError, PWSTR pszUsername, ULONG ulUsernameMaxChars, PWSTR pszPassword, ULONG ulPasswordMaxChars, PBOOL pfSave, DWORD dwFlags)
Definition: credui_main.c:593
DWORD WINAPI CredUIConfirmCredentialsW(PCWSTR pszTargetName, BOOL bConfirm)
Definition: credui_main.c:713
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define SEC_ENTRY
Definition: stubs.c:6
return ret
Definition: mutex.c:147
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint id
Definition: glext.h:5910
#define win_skip
Definition: minitest.h:67
int winetest_interactive
static WCHAR username[]
Definition: url.c:32
short WCHAR
Definition: pedump.c:58
LONG SECURITY_STATUS
Definition: sspi.h:34
HWND hwndParent
Definition: wincred.h:144
PCWSTR pszMessageText
Definition: wincred.h:145
DWORD cbSize
Definition: wincred.h:143
PCWSTR pszCaptionText
Definition: wincred.h:146
HBITMAP hbmBanner
Definition: wincred.h:147
Definition: cookie.c:42
Definition: ps.c:97
const uint16_t * PCWSTR
Definition: typedefs.h:57
uint32_t ULONG
Definition: typedefs.h:59
#define CREDUI_FLAGS_EXPECT_CONFIRMATION
Definition: wincred.h:236
#define CREDUI_FLAGS_ALWAYS_SHOW_UI
Definition: wincred.h:229
#define CREDUI_FLAGS_GENERIC_CREDENTIALS
Definition: wincred.h:237
#define CREDUI_FLAGS_INCORRECT_PASSWORD
Definition: wincred.h:223
#define CREDUI_FLAGS_PERSIST
Definition: wincred.h:234
#define CREDUI_FLAGS_DO_NOT_PERSIST
Definition: wincred.h:224
#define CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX
Definition: wincred.h:228
#define SEC_E_OK
Definition: winerror.h:3450
#define ERROR_NO_SUCH_PACKAGE
Definition: winerror.h:1190
#define ERROR_CANCELLED
Definition: winerror.h:1055
#define ERROR_INVALID_FLAGS
Definition: winerror.h:907
#define ERROR_NOT_FOUND
Definition: winerror.h:1014