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
25 #define SECURITY_WIN32
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)
53 for (i = 0; i < (sizeof(formats) / sizeof(formats[0])); i++) {
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());
67 trace("GetComputerObjectNameA() returned %s\n", name);
71 static void testGetComputerObjectNameW(void)
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());
93 WideCharToMultiByte( CP_ACP, 0, nameW, -1, name, sizeof(name), NULL, NULL );
94 trace("GetComputerObjectNameW() returned %s\n", name);
99 static void testGetUserNameExA(void)
106 for (i = 0; i < (sizeof(formats) / sizeof(formats[0])); i++) {
108 ZeroMemory(name, sizeof(name));
109 rc = pGetUserNameExA(formats[i], name, &size);
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);
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);
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");
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)
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);
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);
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);
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");
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);
202 "Reserved2 should be NULL instead of %p in security function table\n",
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");
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");
225 secdll = LoadLibraryA("secur32.dll");
228 secdll = LoadLibraryA("security.dll");
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();
242 win_skip("GetComputerObjectNameA not exported by secur32.dll\n");
244 if (pGetComputerObjectNameW)
245 testGetComputerObjectNameW();
247 win_skip("GetComputerObjectNameW not exported by secur32.dll\n");
250 testGetUserNameExA();
252 win_skip("GetUserNameExA not exported by secur32.dll\n");
255 testGetUserNameExW();
257 win_skip("GetUserNameExW not exported by secur32.dll\n");
259 test_InitSecurityInterface();