ReactOS 0.4.15-dev-5664-g3bf4ef6
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[] = {'W','i','n','e','T','e','s','t',0};
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 %d\n", ret);
54
55 ret = CredUIConfirmCredentialsW(wszServerName, TRUE);
56 ok(ret == ERROR_NOT_FOUND, "CredUIConfirmCredentials should have returned ERROR_NOT_FOUND instead of %d\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 %d\n", ret);
65
70 ok(ret == ERROR_INVALID_PARAMETER, "CredUIPromptForCredentials should have returned ERROR_INVALID_PARAMETER instead of %d\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 %d\n", ret);
77
79 {
80 static const WCHAR wszCaption1[] = {'C','R','E','D','U','I','_','F','L','A','G','S','_','E','X','P','E','C','T','_','C','O','N','F','I','R','M','A','T','I','O','N',0};
81 static const WCHAR wszCaption2[] = {'C','R','E','D','U','I','_','F','L','A','G','S','_','I','N','C','O','R','R','E','C','T','_','P','A','S','S','W','O','R','D','|',
82 'C','R','E','D','U','I','_','F','L','A','G','S','_','E','X','P','E','C','T','_','C','O','N','F','I','R','M','A','T','I','O','N',0};
83 static const WCHAR wszCaption3[] = {'C','R','E','D','U','I','_','F','L','A','G','S','_','D','O','_','N','O','T','_','P','E','R','S','I','S','T','|',
84 'C','R','E','D','U','I','_','F','L','A','G','S','_','E','X','P','E','C','T','_','C','O','N','F','I','R','M','A','T','I','O','N',0};
85 static const WCHAR wszCaption4[] = {'C','R','E','D','U','I','_','F','L','A','G','S','_','P','E','R','S','I','S','T','|',
86 'C','R','E','D','U','I','_','F','L','A','G','S','_','E','X','P','E','C','T','_','C','O','N','F','I','R','M','A','T','I','O','N',0};
87
88 ret = CredUIPromptForCredentialsW(NULL, wszServerName, NULL, 0, username,
92 ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %d\n", ret);
93 if (ret == ERROR_SUCCESS)
94 {
95 ret = CredUIConfirmCredentialsW(wszServerName, FALSE);
96 ok(ret == ERROR_SUCCESS, "CredUIConfirmCredentials failed with error %d\n", ret);
97 }
98
99 credui_info.pszCaptionText = wszCaption1;
100 ret = CredUIPromptForCredentialsW(&credui_info, wszServerName, NULL, ERROR_ACCESS_DENIED,
104 ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %d\n", ret);
105 if (ret == ERROR_SUCCESS)
106 {
107 ret = CredUIConfirmCredentialsW(wszServerName, FALSE);
108 ok(ret == ERROR_SUCCESS, "CredUIConfirmCredentials failed with error %d\n", ret);
109 }
110
111 credui_info.pszCaptionText = wszCaption2;
112 ret = CredUIPromptForCredentialsW(&credui_info, wszServerName, NULL, 0,
116 ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %d\n", ret);
117 if (ret == ERROR_SUCCESS)
118 {
119 ret = CredUIConfirmCredentialsW(wszServerName, FALSE);
120 ok(ret == ERROR_SUCCESS, "CredUIConfirmCredentials failed with error %d\n", ret);
121 }
122
123
124 save = TRUE;
125 credui_info.pszCaptionText = wszCaption3;
126 ret = CredUIPromptForCredentialsW(&credui_info, wszServerName, NULL, 0,
130 ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %d\n", ret);
131 ok(save, "save flag should have been untouched\n");
132
133 save = FALSE;
134 credui_info.pszCaptionText = wszCaption4;
135 ret = CredUIPromptForCredentialsW(&credui_info, wszServerName, NULL, 0,
139 ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %d\n", ret);
140 ok(!save, "save flag should have been untouched\n");
141 if (ret == ERROR_SUCCESS)
142 {
143 ret = CredUIConfirmCredentialsW(wszServerName, FALSE);
144 ok(ret == ERROR_SUCCESS, "CredUIConfirmCredentials failed with error %d\n", ret);
145 }
146
147 }
148}
149
151{
152 static const WCHAR targetW[] = {'S','s','p','i','T','e','s','t',0};
153 static const WCHAR basicW[] = {'b','a','s','i','c',0};
154 ULONG ret;
158 const WCHAR *username, *domain, *creds;
159 int save;
160
161 if (!pSspiPromptForCredentialsW || !pSspiFreeAuthIdentity)
162 {
163 win_skip( "SspiPromptForCredentialsW is missing\n" );
164 return;
165 }
166
167 info.cbSize = sizeof(info);
168 info.hwndParent = NULL;
169 info.pszMessageText = targetW;
170 info.pszCaptionText = basicW;
171 info.hbmBanner = NULL;
172 ret = pSspiPromptForCredentialsW( NULL, &info, 0, basicW, NULL, &id, &save, 0 );
173 ok( ret == ERROR_INVALID_PARAMETER, "got %u\n", ret );
174
175 ret = pSspiPromptForCredentialsW( targetW, &info, 0, NULL, NULL, &id, &save, 0 );
176 ok( ret == ERROR_NO_SUCH_PACKAGE, "got %u\n", ret );
177
179 {
180 id = NULL;
181 save = -1;
182 ret = pSspiPromptForCredentialsW( targetW, &info, 0, basicW, NULL, &id, &save, 0 );
183 ok( ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "got %u\n", ret );
184 if (ret == ERROR_SUCCESS)
185 {
186 ok( id != NULL, "id not set\n" );
187 ok( save == TRUE || save == FALSE, "got %d\n", save );
188
189 username = creds = NULL;
190 domain = (const WCHAR *)0xdeadbeef;
191 status = pSspiEncodeAuthIdentityAsStrings( id, &username, &domain, &creds );
192 ok( status == SEC_E_OK, "got %u\n", status );
193 ok( username != NULL, "username not set\n" );
194 ok( domain == NULL, "domain not set\n" );
195 ok( creds != NULL, "creds not set\n" );
196 pSspiFreeAuthIdentity( id );
197 }
198 }
199}
200
202{
203 HMODULE hcredui = GetModuleHandleA( "credui.dll" ), hsecur32 = LoadLibraryA( "secur32.dll" );
204
205 if (hcredui)
206 pSspiPromptForCredentialsW = (void *)GetProcAddress( hcredui, "SspiPromptForCredentialsW" );
207 if (hsecur32)
208 {
209 pSspiEncodeAuthIdentityAsStrings = (void *)GetProcAddress( hsecur32, "SspiEncodeAuthIdentityAsStrings" );
210 pSspiFreeAuthIdentity = (void *)GetProcAddress( hsecur32, "SspiFreeAuthIdentity" );
211 }
212
215
216 FreeLibrary( hsecur32 );
217}
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define ARRAY_SIZE(a)
Definition: main.h:24
static void test_SspiPromptForCredentials(void)
Definition: credui.c:150
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:599
DWORD WINAPI CredUIConfirmCredentialsW(PCWSTR pszTargetName, BOOL bConfirm)
Definition: credui_main.c:719
#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
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint id
Definition: glext.h:5910
unsigned int ULONG
Definition: retypes.h:1
static WCHAR password[]
Definition: url.c:33
static WCHAR username[]
Definition: url.c:32
LONG SECURITY_STATUS
Definition: sspi.h:34
static const WCHAR basicW[]
#define win_skip
Definition: test.h:160
int winetest_interactive
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
int ret
#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:2356
#define ERROR_NO_SUCH_PACKAGE
Definition: winerror.h:845
#define ERROR_CANCELLED
Definition: winerror.h:726
#define ERROR_INVALID_FLAGS
Definition: winerror.h:583
#define ERROR_NOT_FOUND
Definition: winerror.h:690
__wchar_t WCHAR
Definition: xmlstorage.h:180