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
);
110 ok(rc
|| ((formats
[i
] == NameUnknown
) &&
111 (GetLastError() == ERROR_INVALID_PARAMETER
)) ||
112 (GetLastError() == ERROR_CANT_ACCESS_DOMAIN_INFO
) ||
113 (GetLastError() == ERROR_NO_SUCH_DOMAIN
) ||
114 (GetLastError() == ERROR_NO_SUCH_USER
) ||
115 (GetLastError() == ERROR_NONE_MAPPED
) ||
116 (GetLastError() == ERROR_ACCESS_DENIED
),
117 "GetUserNameExA(%d) failed: %d\n",
118 formats
[i
], GetLastError());
121 if (0) /* Crashes on Windows */
122 rc
= pGetUserNameExA(NameSamCompatible
, NULL
, NULL
);
125 rc
= pGetUserNameExA(NameSamCompatible
, NULL
, &size
);
126 ok(! rc
&& GetLastError() == ERROR_MORE_DATA
, "Expected fail with ERROR_MORE_DATA, got %d with %u\n", rc
, GetLastError());
127 ok(size
!= 0, "Expected size to be set to required size\n");
129 if (0) /* Crashes on Windows with big enough size */
131 /* Returned size is already big enough */
132 rc
= pGetUserNameExA(NameSamCompatible
, NULL
, &size
);
136 rc
= pGetUserNameExA(NameSamCompatible
, name
, &size
);
137 ok(! rc
&& GetLastError() == ERROR_MORE_DATA
, "Expected fail with ERROR_MORE_DATA, got %d with %u\n", rc
, GetLastError());
138 ok(size
!= 0, "Expected size to be set to required size\n");
141 rc
= pGetUserNameExA(NameSamCompatible
, name
, &size
);
142 ok(! rc
&& GetLastError() == ERROR_MORE_DATA
, "Expected fail with ERROR_MORE_DATA, got %d with %u\n", rc
, GetLastError());
143 ok(1 < size
, "Expected size to be set to required size\n");
144 ok(name
[0] == (char) 0xff, "Expected unchanged buffer\n");
147 static void testGetUserNameExW(void)
154 for (i
= 0; i
< (sizeof(formats
) / sizeof(formats
[0])); i
++) {
155 size
= sizeof(nameW
);
156 ZeroMemory(nameW
, sizeof(nameW
));
157 rc
= pGetUserNameExW(formats
[i
], nameW
, &size
);
158 ok(rc
|| ((formats
[i
] == NameUnknown
) &&
159 (GetLastError() == ERROR_INVALID_PARAMETER
)) ||
160 (GetLastError() == ERROR_CANT_ACCESS_DOMAIN_INFO
) ||
161 (GetLastError() == ERROR_NO_SUCH_DOMAIN
) ||
162 (GetLastError() == ERROR_NO_SUCH_USER
) ||
163 (GetLastError() == ERROR_NONE_MAPPED
) ||
164 (GetLastError() == ERROR_ACCESS_DENIED
),
165 "GetUserNameExW(%d) failed: %d\n",
166 formats
[i
], GetLastError());
169 if (0) /* Crashes on Windows */
170 rc
= pGetUserNameExW(NameSamCompatible
, NULL
, NULL
);
173 rc
= pGetUserNameExW(NameSamCompatible
, NULL
, &size
);
174 ok(! rc
&& GetLastError() == ERROR_MORE_DATA
, "Expected fail with ERROR_MORE_DATA, got %d with %u\n", rc
, GetLastError());
175 ok(size
!= 0, "Expected size to be set to required size\n");
177 if (0) /* Crashes on Windows with big enough size */
179 /* Returned size is already big enough */
180 rc
= pGetUserNameExW(NameSamCompatible
, NULL
, &size
);
184 rc
= pGetUserNameExW(NameSamCompatible
, nameW
, &size
);
185 ok(! rc
&& GetLastError() == ERROR_MORE_DATA
, "Expected fail with ERROR_MORE_DATA, got %d with %u\n", rc
, GetLastError());
186 ok(size
!= 0, "Expected size to be set to required size\n");
189 rc
= pGetUserNameExW(NameSamCompatible
, nameW
, &size
);
190 ok(! rc
&& GetLastError() == ERROR_MORE_DATA
, "Expected fail with ERROR_MORE_DATA, got %d with %u\n", rc
, GetLastError());
191 ok(1 < size
, "Expected size to be set to required size\n");
192 ok(nameW
[0] == (WCHAR
) 0xff, "Expected unchanged buffer\n");
195 static void test_InitSecurityInterface(void)
197 PSecurityFunctionTableA sftA
;
198 PSecurityFunctionTableW sftW
;
200 sftA
= pInitSecurityInterfaceA();
201 ok(sftA
!= NULL
, "pInitSecurityInterfaceA failed\n");
202 ok(sftA
->dwVersion
== SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION
, "wrong dwVersion %d in security function table\n", sftA
->dwVersion
);
203 ok(!sftA
->Reserved2
|| broken(sftA
->Reserved2
!= NULL
) /* WinME */,
204 "Reserved2 should be NULL instead of %p in security function table\n",
206 ok(sftA
->Reserved3
== sftA
->EncryptMessage
||
207 broken(sftA
->Reserved3
!= sftA
->EncryptMessage
) /* Win9x */,
208 "Reserved3 should be equal to EncryptMessage in the security function table\n");
209 ok(sftA
->Reserved4
== sftA
->DecryptMessage
||
210 broken(sftA
->Reserved4
!= sftA
->DecryptMessage
) /* Win9x */,
211 "Reserved4 should be equal to DecryptMessage in the security function table\n");
213 if (!pInitSecurityInterfaceW
)
215 skip("InitSecurityInterfaceW not exported by secur32.dll\n");
219 sftW
= pInitSecurityInterfaceW();
220 ok(sftW
!= NULL
, "pInitSecurityInterfaceW failed\n");
221 ok(sftW
->dwVersion
== SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION
, "wrong dwVersion %d in security function table\n", sftW
->dwVersion
);
222 ok(!sftW
->Reserved2
, "Reserved2 should be NULL instead of %p in security function table\n", sftW
->Reserved2
);
223 ok(sftW
->Reserved3
== sftW
->EncryptMessage
, "Reserved3 should be equal to EncryptMessage in the security function table\n");
224 ok(sftW
->Reserved4
== sftW
->DecryptMessage
, "Reserved4 should be equal to DecryptMessage in the security function table\n");
229 secdll
= LoadLibraryA("secur32.dll");
232 secdll
= LoadLibraryA("security.dll");
236 pGetComputerObjectNameA
= (PVOID
)GetProcAddress(secdll
, "GetComputerObjectNameA");
237 pGetComputerObjectNameW
= (PVOID
)GetProcAddress(secdll
, "GetComputerObjectNameW");
238 pGetUserNameExA
= (PVOID
)GetProcAddress(secdll
, "GetUserNameExA");
239 pGetUserNameExW
= (PVOID
)GetProcAddress(secdll
, "GetUserNameExW");
240 pInitSecurityInterfaceA
= (PVOID
)GetProcAddress(secdll
, "InitSecurityInterfaceA");
241 pInitSecurityInterfaceW
= (PVOID
)GetProcAddress(secdll
, "InitSecurityInterfaceW");
243 if (pGetComputerObjectNameA
)
244 testGetComputerObjectNameA();
246 if (pGetComputerObjectNameW
)
247 testGetComputerObjectNameW();
250 testGetUserNameExA();
253 testGetUserNameExW();
255 test_InitSecurityInterface();