Add AppDefaults app selection to control panel
[wine/gsoc-2012-control.git] / dlls / secur32 / tests / secur32.c
blob6e67784ce4025a62166e50a4c2c53e01a474e58c
1 /*
2 * tests
4 * Copyright 2006 Robert Reif
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
20 #include <stdio.h>
21 #include <stdarg.h>
22 #include <windef.h>
23 #include <winbase.h>
24 #include <winnls.h>
25 #define SECURITY_WIN32
26 #include <security.h>
27 #include <schannel.h>
29 #include "wine/test.h"
31 static HMODULE secdll;
33 static BOOLEAN (WINAPI * pGetComputerObjectNameA)(EXTENDED_NAME_FORMAT NameFormat, LPSTR lpNameBuffer, PULONG lpnSize);
34 static BOOLEAN (WINAPI * pGetComputerObjectNameW)(EXTENDED_NAME_FORMAT NameFormat, LPWSTR lpNameBuffer, PULONG lpnSize);
35 static BOOLEAN (WINAPI * pGetUserNameExA)(EXTENDED_NAME_FORMAT NameFormat, LPSTR lpNameBuffer, PULONG lpnSize);
36 static BOOLEAN (WINAPI * pGetUserNameExW)(EXTENDED_NAME_FORMAT NameFormat, LPWSTR lpNameBuffer, PULONG lpnSize);
37 static PSecurityFunctionTableA (SEC_ENTRY * pInitSecurityInterfaceA)(void);
38 static PSecurityFunctionTableW (SEC_ENTRY * pInitSecurityInterfaceW)(void);
40 static EXTENDED_NAME_FORMAT formats[] = {
41 NameUnknown, NameFullyQualifiedDN, NameSamCompatible, NameDisplay,
42 NameUniqueId, NameCanonical, NameUserPrincipal, NameCanonicalEx,
43 NameServicePrincipal, NameDnsDomain
46 static void testGetComputerObjectNameA(void)
48 char name[256];
49 ULONG size;
50 BOOLEAN rc;
51 UINT i;
53 for (i = 0; i < (sizeof(formats) / sizeof(formats[0])); i++) {
54 size = sizeof(name);
55 ZeroMemory(name, sizeof(name));
56 rc = pGetComputerObjectNameA(formats[i], name, &size);
57 ok(rc || ((formats[i] == NameUnknown) &&
58 (GetLastError() == ERROR_INVALID_PARAMETER)) ||
59 (GetLastError() == ERROR_CANT_ACCESS_DOMAIN_INFO) ||
60 (GetLastError() == ERROR_NO_SUCH_DOMAIN) ||
61 (GetLastError() == ERROR_NO_SUCH_USER) ||
62 (GetLastError() == ERROR_NONE_MAPPED) ||
63 (GetLastError() == ERROR_ACCESS_DENIED),
64 "GetComputerObjectNameA(%d) failed: %d\n",
65 formats[i], GetLastError());
66 if (rc)
67 trace("GetComputerObjectNameA() returned %s\n", name);
71 static void testGetComputerObjectNameW(void)
73 WCHAR nameW[256];
74 ULONG size;
75 BOOLEAN rc;
76 UINT i;
78 for (i = 0; i < (sizeof(formats) / sizeof(formats[0])); i++) {
79 size = sizeof(nameW)/sizeof(nameW[0]);
80 ZeroMemory(nameW, sizeof(nameW));
81 rc = pGetComputerObjectNameW(formats[i], nameW, &size);
82 ok(rc || ((formats[i] == NameUnknown) &&
83 (GetLastError() == ERROR_INVALID_PARAMETER)) ||
84 (GetLastError() == ERROR_CANT_ACCESS_DOMAIN_INFO) ||
85 (GetLastError() == ERROR_NO_SUCH_DOMAIN) ||
86 (GetLastError() == ERROR_NO_SUCH_USER) ||
87 (GetLastError() == ERROR_NONE_MAPPED) ||
88 (GetLastError() == ERROR_ACCESS_DENIED),
89 "GetComputerObjectNameW(%d) failed: %d\n",
90 formats[i], GetLastError());
91 if (rc) {
92 char name[256];
93 WideCharToMultiByte( CP_ACP, 0, nameW, -1, name, sizeof(name), NULL, NULL );
94 trace("GetComputerObjectNameW() returned %s\n", name);
99 static void testGetUserNameExA(void)
101 char name[256];
102 ULONG size;
103 BOOLEAN rc;
104 UINT i;
106 for (i = 0; i < (sizeof(formats) / sizeof(formats[0])); i++) {
107 size = sizeof(name);
108 ZeroMemory(name, sizeof(name));
109 rc = pGetUserNameExA(formats[i], name, &size);
110 ok(rc ||
111 (formats[i] == NameUnknown &&
112 GetLastError() == ERROR_NO_SUCH_USER) ||
113 GetLastError() == ERROR_NONE_MAPPED ||
114 broken(formats[i] == NameDnsDomain &&
115 GetLastError() == ERROR_INVALID_PARAMETER),
116 "GetUserNameExW(%d) failed: %d\n",
117 formats[i], GetLastError());
120 if (0) /* Crashes on Windows */
121 pGetUserNameExA(NameSamCompatible, NULL, NULL);
123 size = 0;
124 rc = pGetUserNameExA(NameSamCompatible, NULL, &size);
125 ok(! rc && GetLastError() == ERROR_MORE_DATA, "Expected fail with ERROR_MORE_DATA, got %d with %u\n", rc, GetLastError());
126 ok(size != 0, "Expected size to be set to required size\n");
128 if (0) /* Crashes on Windows with big enough size */
130 /* Returned size is already big enough */
131 pGetUserNameExA(NameSamCompatible, NULL, &size);
134 size = 0;
135 rc = pGetUserNameExA(NameSamCompatible, name, &size);
136 ok(! rc && GetLastError() == ERROR_MORE_DATA, "Expected fail with ERROR_MORE_DATA, got %d with %u\n", rc, GetLastError());
137 ok(size != 0, "Expected size to be set to required size\n");
138 size = 1;
139 name[0] = 0xff;
140 rc = pGetUserNameExA(NameSamCompatible, name, &size);
141 ok(! rc && GetLastError() == ERROR_MORE_DATA, "Expected fail with ERROR_MORE_DATA, got %d with %u\n", rc, GetLastError());
142 ok(1 < size, "Expected size to be set to required size\n");
143 ok(name[0] == (char) 0xff, "Expected unchanged buffer\n");
146 static void testGetUserNameExW(void)
148 WCHAR nameW[256];
149 ULONG size;
150 BOOLEAN rc;
151 UINT i;
153 for (i = 0; i < (sizeof(formats) / sizeof(formats[0])); i++) {
154 size = sizeof(nameW);
155 ZeroMemory(nameW, sizeof(nameW));
156 rc = pGetUserNameExW(formats[i], nameW, &size);
157 ok(rc ||
158 (formats[i] == NameUnknown &&
159 GetLastError() == ERROR_NO_SUCH_USER) ||
160 GetLastError() == ERROR_NONE_MAPPED ||
161 broken(formats[i] == NameDnsDomain &&
162 GetLastError() == ERROR_INVALID_PARAMETER),
163 "GetUserNameExW(%d) failed: %d\n",
164 formats[i], GetLastError());
167 if (0) /* Crashes on Windows */
168 pGetUserNameExW(NameSamCompatible, NULL, NULL);
170 size = 0;
171 rc = pGetUserNameExW(NameSamCompatible, NULL, &size);
172 ok(! rc && GetLastError() == ERROR_MORE_DATA, "Expected fail with ERROR_MORE_DATA, got %d with %u\n", rc, GetLastError());
173 ok(size != 0, "Expected size to be set to required size\n");
175 if (0) /* Crashes on Windows with big enough size */
177 /* Returned size is already big enough */
178 pGetUserNameExW(NameSamCompatible, NULL, &size);
181 size = 0;
182 rc = pGetUserNameExW(NameSamCompatible, nameW, &size);
183 ok(! rc && GetLastError() == ERROR_MORE_DATA, "Expected fail with ERROR_MORE_DATA, got %d with %u\n", rc, GetLastError());
184 ok(size != 0, "Expected size to be set to required size\n");
185 size = 1;
186 nameW[0] = 0xff;
187 rc = pGetUserNameExW(NameSamCompatible, nameW, &size);
188 ok(! rc && GetLastError() == ERROR_MORE_DATA, "Expected fail with ERROR_MORE_DATA, got %d with %u\n", rc, GetLastError());
189 ok(1 < size, "Expected size to be set to required size\n");
190 ok(nameW[0] == (WCHAR) 0xff, "Expected unchanged buffer\n");
193 static void test_InitSecurityInterface(void)
195 PSecurityFunctionTableA sftA;
196 PSecurityFunctionTableW sftW;
198 sftA = pInitSecurityInterfaceA();
199 ok(sftA != NULL, "pInitSecurityInterfaceA failed\n");
200 ok(sftA->dwVersion == SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION, "wrong dwVersion %d in security function table\n", sftA->dwVersion);
201 ok(!sftA->Reserved2,
202 "Reserved2 should be NULL instead of %p in security function table\n",
203 sftA->Reserved2);
204 ok(sftA->Reserved3 == sftA->EncryptMessage,
205 "Reserved3 should be equal to EncryptMessage in the security function table\n");
206 ok(sftA->Reserved4 == sftA->DecryptMessage,
207 "Reserved4 should be equal to DecryptMessage in the security function table\n");
209 if (!pInitSecurityInterfaceW)
211 win_skip("InitSecurityInterfaceW not exported by secur32.dll\n");
212 return;
215 sftW = pInitSecurityInterfaceW();
216 ok(sftW != NULL, "pInitSecurityInterfaceW failed\n");
217 ok(sftW->dwVersion == SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION, "wrong dwVersion %d in security function table\n", sftW->dwVersion);
218 ok(!sftW->Reserved2, "Reserved2 should be NULL instead of %p in security function table\n", sftW->Reserved2);
219 ok(sftW->Reserved3 == sftW->EncryptMessage, "Reserved3 should be equal to EncryptMessage in the security function table\n");
220 ok(sftW->Reserved4 == sftW->DecryptMessage, "Reserved4 should be equal to DecryptMessage in the security function table\n");
223 START_TEST(secur32)
225 secdll = LoadLibraryA("secur32.dll");
227 if (!secdll)
228 secdll = LoadLibraryA("security.dll");
230 if (secdll)
232 pGetComputerObjectNameA = (PVOID)GetProcAddress(secdll, "GetComputerObjectNameA");
233 pGetComputerObjectNameW = (PVOID)GetProcAddress(secdll, "GetComputerObjectNameW");
234 pGetUserNameExA = (PVOID)GetProcAddress(secdll, "GetUserNameExA");
235 pGetUserNameExW = (PVOID)GetProcAddress(secdll, "GetUserNameExW");
236 pInitSecurityInterfaceA = (PVOID)GetProcAddress(secdll, "InitSecurityInterfaceA");
237 pInitSecurityInterfaceW = (PVOID)GetProcAddress(secdll, "InitSecurityInterfaceW");
239 if (pGetComputerObjectNameA)
240 testGetComputerObjectNameA();
241 else
242 win_skip("GetComputerObjectNameA not exported by secur32.dll\n");
244 if (pGetComputerObjectNameW)
245 testGetComputerObjectNameW();
246 else
247 win_skip("GetComputerObjectNameW not exported by secur32.dll\n");
249 if (pGetUserNameExA)
250 testGetUserNameExA();
251 else
252 win_skip("GetUserNameExA not exported by secur32.dll\n");
254 if (pGetUserNameExW)
255 testGetUserNameExW();
256 else
257 win_skip("GetUserNameExW not exported by secur32.dll\n");
259 test_InitSecurityInterface();
261 FreeLibrary(secdll);