ntdll: Fix race in NtRead/WriteFile.
[wine/testsucceed.git] / dlls / secur32 / tests / secur32.c
blob0ad6f0f55237ccb9fe36e87a0ad1b9be004fdcfc
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 rc = 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 rc = 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 rc = 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 rc = 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 || broken(sftA->Reserved2 != NULL) /* WinME */,
202 "Reserved2 should be NULL instead of %p in security function table\n",
203 sftA->Reserved2);
204 ok(sftA->Reserved3 == sftA->EncryptMessage ||
205 broken(sftA->Reserved3 != sftA->EncryptMessage) /* Win9x */,
206 "Reserved3 should be equal to EncryptMessage in the security function table\n");
207 ok(sftA->Reserved4 == sftA->DecryptMessage ||
208 broken(sftA->Reserved4 != sftA->DecryptMessage) /* Win9x */,
209 "Reserved4 should be equal to DecryptMessage in the security function table\n");
211 if (!pInitSecurityInterfaceW)
213 win_skip("InitSecurityInterfaceW not exported by secur32.dll\n");
214 return;
217 sftW = pInitSecurityInterfaceW();
218 ok(sftW != NULL, "pInitSecurityInterfaceW failed\n");
219 ok(sftW->dwVersion == SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION, "wrong dwVersion %d in security function table\n", sftW->dwVersion);
220 ok(!sftW->Reserved2, "Reserved2 should be NULL instead of %p in security function table\n", sftW->Reserved2);
221 ok(sftW->Reserved3 == sftW->EncryptMessage, "Reserved3 should be equal to EncryptMessage in the security function table\n");
222 ok(sftW->Reserved4 == sftW->DecryptMessage, "Reserved4 should be equal to DecryptMessage in the security function table\n");
225 START_TEST(secur32)
227 secdll = LoadLibraryA("secur32.dll");
229 if (!secdll)
230 secdll = LoadLibraryA("security.dll");
232 if (secdll)
234 pGetComputerObjectNameA = (PVOID)GetProcAddress(secdll, "GetComputerObjectNameA");
235 pGetComputerObjectNameW = (PVOID)GetProcAddress(secdll, "GetComputerObjectNameW");
236 pGetUserNameExA = (PVOID)GetProcAddress(secdll, "GetUserNameExA");
237 pGetUserNameExW = (PVOID)GetProcAddress(secdll, "GetUserNameExW");
238 pInitSecurityInterfaceA = (PVOID)GetProcAddress(secdll, "InitSecurityInterfaceA");
239 pInitSecurityInterfaceW = (PVOID)GetProcAddress(secdll, "InitSecurityInterfaceW");
241 if (pGetComputerObjectNameA)
242 testGetComputerObjectNameA();
243 else
244 win_skip("GetComputerObjectNameA not exported by secur32.dll\n");
246 if (pGetComputerObjectNameW)
247 testGetComputerObjectNameW();
248 else
249 win_skip("GetComputerObjectNameW not exported by secur32.dll\n");
251 if (pGetUserNameExA)
252 testGetUserNameExA();
253 else
254 win_skip("GetUserNameExA not exported by secur32.dll\n");
256 if (pGetUserNameExW)
257 testGetUserNameExW();
258 else
259 win_skip("GetUserNameExW not exported by secur32.dll\n");
261 test_InitSecurityInterface();
263 FreeLibrary(secdll);