1 /* Copyright (C) 2004 Juan Lang
3 * This file implements loading of SSP DLLs.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define WIN32_NO_STATUS
31 #include "secur32_priv.h"
36 #include "wine/list.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(secur32
);
45 typedef struct _SecurePackageTable
52 typedef struct _SecureProviderTable
57 } SecureProviderTable
;
63 /* Tries to load moduleName as a provider. If successful, enumerates what
64 * packages it can and adds them to the package and provider tables. Resizes
65 * tables as necessary.
67 static void _tryLoadProvider(PWSTR moduleName
);
69 /* Initialization: read securityproviders value and attempt to open each dll
70 * there. For each DLL, call _tryLoadProvider to see if it's really an SSP.
71 * Two undocumented functions, AddSecurityPackage(A/W) and
72 * DeleteSecurityPackage(A/W), seem suspiciously like they'd register or
73 * unregister a dll, but I'm not sure.
75 static void SECUR32_initializeProviders(void);
77 /* Frees all loaded packages and providers */
78 static void SECUR32_freeProviders(void);
84 static CRITICAL_SECTION cs
;
85 static SecurePackageTable
*packageTable
= NULL
;
86 static SecureProviderTable
*providerTable
= NULL
;
88 static SecurityFunctionTableA securityFunctionTableA
= {
89 SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION_2
,
90 EnumerateSecurityPackagesA
,
91 QueryCredentialsAttributesA
,
92 AcquireCredentialsHandleA
,
93 FreeCredentialsHandle
,
95 InitializeSecurityContextA
,
96 AcceptSecurityContext
,
98 DeleteSecurityContext
,
100 QueryContextAttributesA
,
101 ImpersonateSecurityContext
,
102 RevertSecurityContext
,
106 QuerySecurityPackageInfoA
,
107 NULL
, /* Reserved3 */
108 NULL
, /* Reserved4 */
109 ExportSecurityContext
,
110 ImportSecurityContextA
,
112 NULL
, /* Reserved8 */
113 QuerySecurityContextToken
,
116 SetContextAttributesA
119 static SecurityFunctionTableW securityFunctionTableW
= {
120 SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION_2
,
121 EnumerateSecurityPackagesW
,
122 QueryCredentialsAttributesW
,
123 AcquireCredentialsHandleW
,
124 FreeCredentialsHandle
,
125 NULL
, /* Reserved2 */
126 InitializeSecurityContextW
,
127 AcceptSecurityContext
,
129 DeleteSecurityContext
,
131 QueryContextAttributesW
,
132 ImpersonateSecurityContext
,
133 RevertSecurityContext
,
137 QuerySecurityPackageInfoW
,
138 NULL
, /* Reserved3 */
139 NULL
, /* Reserved4 */
140 ExportSecurityContext
,
141 ImportSecurityContextW
,
143 NULL
, /* Reserved8 */
144 QuerySecurityContextToken
,
147 SetContextAttributesW
150 /***********************************************************************
151 * InitSecurityInterfaceA (SECUR32.@)
153 PSecurityFunctionTableA WINAPI
InitSecurityInterfaceA(void)
155 return &securityFunctionTableA
;
158 /***********************************************************************
159 * InitSecurityInterfaceW (SECUR32.@)
161 PSecurityFunctionTableW WINAPI
InitSecurityInterfaceW(void)
163 return &securityFunctionTableW
;
166 PWSTR
SECUR32_strdupW(PCWSTR str
)
172 ret
= (PWSTR
)SECUR32_ALLOC((lstrlenW(str
) + 1) * sizeof(WCHAR
));
181 PWSTR
SECUR32_AllocWideFromMultiByte(PCSTR str
)
187 int charsNeeded
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
191 ret
= (PWSTR
)SECUR32_ALLOC(charsNeeded
* sizeof(WCHAR
));
193 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, charsNeeded
);
203 PSTR
SECUR32_AllocMultiByteFromWide(PCWSTR str
)
209 int charsNeeded
= WideCharToMultiByte(CP_ACP
, 0, str
, -1, NULL
, 0,
214 ret
= (PSTR
)SECUR32_ALLOC(charsNeeded
);
216 WideCharToMultiByte(CP_ACP
, 0, str
, -1, ret
, charsNeeded
,
227 static void _makeFnTableA(PSecurityFunctionTableA fnTableA
,
228 const SecurityFunctionTableA
*inFnTableA
,
229 const SecurityFunctionTableW
*inFnTableW
)
235 /* The size of the version 1 table is based on platform sdk's
236 * sspi.h, though the sample ssp also provided with platform sdk
237 * implies only functions through QuerySecurityPackageInfoA are
238 * implemented (yikes)
240 size_t tableSize
= inFnTableA
->dwVersion
== 1 ?
241 (const BYTE
*)&inFnTableA
->SetContextAttributesA
-
242 (const BYTE
*)inFnTableA
: sizeof(SecurityFunctionTableA
);
244 memcpy(fnTableA
, inFnTableA
, tableSize
);
245 /* override this, since we can do it internally anyway */
246 fnTableA
->QuerySecurityPackageInfoA
=
247 QuerySecurityPackageInfoA
;
251 /* functions with thunks */
252 if (inFnTableW
->AcquireCredentialsHandleW
)
253 fnTableA
->AcquireCredentialsHandleA
=
254 thunk_AcquireCredentialsHandleA
;
255 if (inFnTableW
->InitializeSecurityContextW
)
256 fnTableA
->InitializeSecurityContextA
=
257 thunk_InitializeSecurityContextA
;
258 if (inFnTableW
->ImportSecurityContextW
)
259 fnTableA
->ImportSecurityContextA
=
260 thunk_ImportSecurityContextA
;
261 if (inFnTableW
->AddCredentialsW
)
262 fnTableA
->AddCredentialsA
=
263 thunk_AddCredentialsA
;
264 if (inFnTableW
->QueryCredentialsAttributesW
)
265 fnTableA
->QueryCredentialsAttributesA
=
266 thunk_QueryCredentialsAttributesA
;
267 if (inFnTableW
->QueryContextAttributesW
)
268 fnTableA
->QueryContextAttributesA
=
269 thunk_QueryContextAttributesA
;
270 if (inFnTableW
->SetContextAttributesW
)
271 fnTableA
->SetContextAttributesA
=
272 thunk_SetContextAttributesA
;
273 /* this can't be thunked, there's no extra param to know which
274 * package to forward to */
275 fnTableA
->EnumerateSecurityPackagesA
= NULL
;
276 /* functions with no thunks needed */
277 fnTableA
->AcceptSecurityContext
= inFnTableW
->AcceptSecurityContext
;
278 fnTableA
->CompleteAuthToken
= inFnTableW
->CompleteAuthToken
;
279 fnTableA
->DeleteSecurityContext
= inFnTableW
->DeleteSecurityContext
;
280 fnTableA
->ImpersonateSecurityContext
=
281 inFnTableW
->ImpersonateSecurityContext
;
282 fnTableA
->RevertSecurityContext
= inFnTableW
->RevertSecurityContext
;
283 fnTableA
->MakeSignature
= inFnTableW
->MakeSignature
;
284 fnTableA
->VerifySignature
= inFnTableW
->VerifySignature
;
285 fnTableA
->FreeContextBuffer
= inFnTableW
->FreeContextBuffer
;
286 fnTableA
->QuerySecurityPackageInfoA
=
287 QuerySecurityPackageInfoA
;
288 fnTableA
->ExportSecurityContext
=
289 inFnTableW
->ExportSecurityContext
;
290 fnTableA
->QuerySecurityContextToken
=
291 inFnTableW
->QuerySecurityContextToken
;
292 fnTableA
->EncryptMessage
= inFnTableW
->EncryptMessage
;
293 fnTableA
->DecryptMessage
= inFnTableW
->DecryptMessage
;
298 static void _makeFnTableW(PSecurityFunctionTableW fnTableW
,
299 const SecurityFunctionTableA
*inFnTableA
,
300 const SecurityFunctionTableW
*inFnTableW
)
306 /* The size of the version 1 table is based on platform sdk's
307 * sspi.h, though the sample ssp also provided with platform sdk
308 * implies only functions through QuerySecurityPackageInfoA are
309 * implemented (yikes)
311 size_t tableSize
= inFnTableW
->dwVersion
== 1 ?
312 (const BYTE
*)&inFnTableW
->SetContextAttributesW
-
313 (const BYTE
*)inFnTableW
: sizeof(SecurityFunctionTableW
);
315 memcpy(fnTableW
, inFnTableW
, tableSize
);
316 /* override this, since we can do it internally anyway */
317 fnTableW
->QuerySecurityPackageInfoW
=
318 QuerySecurityPackageInfoW
;
322 /* functions with thunks */
323 if (inFnTableA
->AcquireCredentialsHandleA
)
324 fnTableW
->AcquireCredentialsHandleW
=
325 thunk_AcquireCredentialsHandleW
;
326 if (inFnTableA
->InitializeSecurityContextA
)
327 fnTableW
->InitializeSecurityContextW
=
328 thunk_InitializeSecurityContextW
;
329 if (inFnTableA
->ImportSecurityContextA
)
330 fnTableW
->ImportSecurityContextW
=
331 thunk_ImportSecurityContextW
;
332 if (inFnTableA
->AddCredentialsA
)
333 fnTableW
->AddCredentialsW
=
334 thunk_AddCredentialsW
;
335 if (inFnTableA
->QueryCredentialsAttributesA
)
336 fnTableW
->QueryCredentialsAttributesW
=
337 thunk_QueryCredentialsAttributesW
;
338 if (inFnTableA
->QueryContextAttributesA
)
339 fnTableW
->QueryContextAttributesW
=
340 thunk_QueryContextAttributesW
;
341 if (inFnTableA
->SetContextAttributesA
)
342 fnTableW
->SetContextAttributesW
=
343 thunk_SetContextAttributesW
;
344 /* this can't be thunked, there's no extra param to know which
345 * package to forward to */
346 fnTableW
->EnumerateSecurityPackagesW
= NULL
;
347 /* functions with no thunks needed */
348 fnTableW
->AcceptSecurityContext
= inFnTableA
->AcceptSecurityContext
;
349 fnTableW
->CompleteAuthToken
= inFnTableA
->CompleteAuthToken
;
350 fnTableW
->DeleteSecurityContext
= inFnTableA
->DeleteSecurityContext
;
351 fnTableW
->ImpersonateSecurityContext
=
352 inFnTableA
->ImpersonateSecurityContext
;
353 fnTableW
->RevertSecurityContext
= inFnTableA
->RevertSecurityContext
;
354 fnTableW
->MakeSignature
= inFnTableA
->MakeSignature
;
355 fnTableW
->VerifySignature
= inFnTableA
->VerifySignature
;
356 fnTableW
->FreeContextBuffer
= inFnTableA
->FreeContextBuffer
;
357 fnTableW
->QuerySecurityPackageInfoW
=
358 QuerySecurityPackageInfoW
;
359 fnTableW
->ExportSecurityContext
=
360 inFnTableA
->ExportSecurityContext
;
361 fnTableW
->QuerySecurityContextToken
=
362 inFnTableA
->QuerySecurityContextToken
;
363 fnTableW
->EncryptMessage
= inFnTableA
->EncryptMessage
;
364 fnTableW
->DecryptMessage
= inFnTableA
->DecryptMessage
;
369 static void _copyPackageInfo(PSecPkgInfoW info
, const SecPkgInfoA
*inInfoA
,
370 const SecPkgInfoW
*inInfoW
)
372 if (info
&& (inInfoA
|| inInfoW
))
374 /* odd, I know, but up until Name and Comment the structures are
377 memcpy(info
, inInfoW
? inInfoW
: (const SecPkgInfoW
*)inInfoA
, sizeof(*info
));
380 info
->Name
= SECUR32_strdupW(inInfoW
->Name
);
381 info
->Comment
= SECUR32_strdupW(inInfoW
->Comment
);
385 info
->Name
= SECUR32_AllocWideFromMultiByte(inInfoA
->Name
);
386 info
->Comment
= SECUR32_AllocWideFromMultiByte(inInfoA
->Comment
);
391 SecureProvider
*SECUR32_addProvider(const SecurityFunctionTableA
*fnTableA
,
392 const SecurityFunctionTableW
*fnTableW
, const PWSTR moduleName
)
396 EnterCriticalSection(&cs
);
400 providerTable
= HeapAlloc(GetProcessHeap(), 0, sizeof(SecureProviderTable
));
403 LeaveCriticalSection(&cs
);
407 list_init(&providerTable
->table
);
410 ret
= HeapAlloc(GetProcessHeap(), 0, sizeof(SecureProvider
));
413 LeaveCriticalSection(&cs
);
417 list_add_tail(&providerTable
->table
, &ret
->entry
);
420 if (fnTableA
|| fnTableW
)
422 ret
->moduleName
= NULL
;
423 _makeFnTableA(&ret
->fnTableA
, fnTableA
, fnTableW
);
424 _makeFnTableW(&ret
->fnTableW
, fnTableA
, fnTableW
);
429 ret
->moduleName
= SECUR32_strdupW(moduleName
);
433 LeaveCriticalSection(&cs
);
437 void SECUR32_addPackages(SecureProvider
*provider
, ULONG toAdd
,
438 const SecPkgInfoA
*infoA
, const SecPkgInfoW
*infoW
)
443 assert(infoA
|| infoW
);
445 EnterCriticalSection(&cs
);
449 packageTable
= HeapAlloc(GetProcessHeap(), 0, sizeof(SecurePackageTable
));
452 LeaveCriticalSection(&cs
);
456 packageTable
->numPackages
= 0;
457 list_init(&packageTable
->table
);
460 for (i
= 0; i
< toAdd
; i
++)
462 SecurePackage
*package
= HeapAlloc(GetProcessHeap(), 0, sizeof(SecurePackage
));
466 list_add_tail(&packageTable
->table
, &package
->entry
);
468 package
->provider
= provider
;
469 _copyPackageInfo(&package
->infoW
,
470 infoA
? &infoA
[i
] : NULL
,
471 infoW
? &infoW
[i
] : NULL
);
473 packageTable
->numPackages
+= toAdd
;
475 LeaveCriticalSection(&cs
);
478 static void _tryLoadProvider(PWSTR moduleName
)
480 HMODULE lib
= LoadLibraryW(moduleName
);
484 INIT_SECURITY_INTERFACE_W pInitSecurityInterfaceW
=
485 (INIT_SECURITY_INTERFACE_W
)GetProcAddress(lib
,
486 SECURITY_ENTRYPOINT_ANSIW
);
487 INIT_SECURITY_INTERFACE_A pInitSecurityInterfaceA
=
488 (INIT_SECURITY_INTERFACE_A
)GetProcAddress(lib
,
489 SECURITY_ENTRYPOINT_ANSIA
);
491 TRACE("loaded %s, InitSecurityInterfaceA is %p, InitSecurityInterfaceW is %p\n",
492 debugstr_w(moduleName
), pInitSecurityInterfaceA
,
493 pInitSecurityInterfaceW
);
494 if (pInitSecurityInterfaceW
|| pInitSecurityInterfaceA
)
496 PSecurityFunctionTableA fnTableA
= NULL
;
497 PSecurityFunctionTableW fnTableW
= NULL
;
499 PSecPkgInfoA infoA
= NULL
;
500 PSecPkgInfoW infoW
= NULL
;
501 SECURITY_STATUS ret
= SEC_E_OK
;
503 if (pInitSecurityInterfaceA
)
504 fnTableA
= pInitSecurityInterfaceA();
505 if (pInitSecurityInterfaceW
)
506 fnTableW
= pInitSecurityInterfaceW();
507 if (fnTableW
&& fnTableW
->EnumerateSecurityPackagesW
)
508 ret
= fnTableW
->EnumerateSecurityPackagesW(&toAdd
, &infoW
);
509 else if (fnTableA
&& fnTableA
->EnumerateSecurityPackagesA
)
510 ret
= fnTableA
->EnumerateSecurityPackagesA(&toAdd
, &infoA
);
511 if (ret
== SEC_E_OK
&& toAdd
> 0 && (infoW
|| infoA
))
513 SecureProvider
*provider
= SECUR32_addProvider(NULL
, NULL
,
517 SECUR32_addPackages(provider
, toAdd
, infoA
, infoW
);
519 fnTableW
->FreeContextBuffer(infoW
);
521 fnTableA
->FreeContextBuffer(infoA
);
527 WARN("failed to load %s\n", debugstr_w(moduleName
));
530 static const WCHAR securityProvidersKeyW
[] = {
531 'S','Y','S','T','E','M','\\','C','u','r','r','e','n','t','C','o','n','t','r',
532 'o','l','S','e','t','\\','C','o','n','t','r','o','l','\\','S','e','c','u','r',
533 'i','t','y','P','r','o','v','i','d','e','r','s','\0'
535 static const WCHAR securityProvidersW
[] = {
536 'S','e','c','u','r','i','t','y','P','r','o','v','i','d','e','r','s',0
539 static void SECUR32_initializeProviders(void)
545 InitializeCriticalSection(&cs
);
546 /* First load built-in providers */
547 SECUR32_initSchannelSP();
548 /* Do not load Negotiate yet. This breaks for some user on the wine-users
549 * mailing list as of 2006-09-12. Without Negotiate, applications should
550 * fall back to NTLM and that should work.*/
552 SECUR32_initNegotiateSP();
554 SECUR32_initNTLMSP();
555 /* Now load providers from registry */
556 apiRet
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, securityProvidersKeyW
, 0,
558 if (apiRet
== ERROR_SUCCESS
)
560 WCHAR securityPkgNames
[MAX_PATH
]; /* arbitrary len */
561 DWORD size
= sizeof(securityPkgNames
) / sizeof(WCHAR
), type
;
563 apiRet
= RegQueryValueExW(key
, securityProvidersW
, NULL
, &type
,
564 (PBYTE
)securityPkgNames
, &size
);
565 if (apiRet
== ERROR_SUCCESS
&& type
== REG_SZ
)
569 for (ptr
= securityPkgNames
;
570 ptr
< (PWSTR
)((PBYTE
)securityPkgNames
+ size
); )
574 for (comma
= ptr
; *comma
&& *comma
!= ','; comma
++)
578 for (; *ptr
&& isspace(*ptr
) && ptr
< securityPkgNames
+ size
;
582 _tryLoadProvider(ptr
);
583 ptr
+= lstrlenW(ptr
) + 1;
590 SecurePackage
*SECUR32_findPackageW(PWSTR packageName
)
592 SecurePackage
*ret
= NULL
;
593 BOOL matched
= FALSE
;
595 if (packageTable
&& packageName
)
597 LIST_FOR_EACH_ENTRY(ret
, &packageTable
->table
, SecurePackage
, entry
)
599 matched
= !lstrcmpiW(ret
->infoW
.Name
, packageName
);
607 if (ret
->provider
&& !ret
->provider
->loaded
)
609 ret
->provider
->lib
= LoadLibraryW(ret
->provider
->moduleName
);
610 if (ret
->provider
->lib
)
612 INIT_SECURITY_INTERFACE_W pInitSecurityInterfaceW
=
613 (INIT_SECURITY_INTERFACE_W
)GetProcAddress(ret
->provider
->lib
,
614 SECURITY_ENTRYPOINT_ANSIW
);
615 INIT_SECURITY_INTERFACE_A pInitSecurityInterfaceA
=
616 (INIT_SECURITY_INTERFACE_A
)GetProcAddress(ret
->provider
->lib
,
617 SECURITY_ENTRYPOINT_ANSIA
);
618 PSecurityFunctionTableA fnTableA
= NULL
;
619 PSecurityFunctionTableW fnTableW
= NULL
;
621 if (pInitSecurityInterfaceA
)
622 fnTableA
= pInitSecurityInterfaceA();
623 if (pInitSecurityInterfaceW
)
624 fnTableW
= pInitSecurityInterfaceW();
625 _makeFnTableA(&ret
->provider
->fnTableA
, fnTableA
, fnTableW
);
626 _makeFnTableW(&ret
->provider
->fnTableW
, fnTableA
, fnTableW
);
627 ret
->provider
->loaded
= TRUE
;
636 SecurePackage
*SECUR32_findPackageA(PSTR packageName
)
640 if (packageTable
&& packageName
)
642 UNICODE_STRING package
;
644 RtlCreateUnicodeStringFromAsciiz(&package
, packageName
);
645 ret
= SECUR32_findPackageW(package
.Buffer
);
646 RtlFreeUnicodeString(&package
);
653 static void SECUR32_freeProviders(void)
655 SecurePackage
*package
;
656 SecureProvider
*provider
;
659 EnterCriticalSection(&cs
);
663 LIST_FOR_EACH_ENTRY(package
, &packageTable
->table
, SecurePackage
, entry
)
665 SECUR32_FREE(package
->infoW
.Name
);
666 SECUR32_FREE(package
->infoW
.Comment
);
669 HeapFree(GetProcessHeap(), 0, packageTable
);
675 LIST_FOR_EACH_ENTRY(provider
, &providerTable
->table
, SecureProvider
, entry
)
677 SECUR32_FREE(provider
->moduleName
);
679 FreeLibrary(provider
->lib
);
682 HeapFree(GetProcessHeap(), 0, providerTable
);
683 providerTable
= NULL
;
686 LeaveCriticalSection(&cs
);
687 DeleteCriticalSection(&cs
);
690 /***********************************************************************
691 * FreeContextBuffer (SECUR32.@)
693 * Doh--if pv was allocated by a crypto package, this may not be correct.
694 * The sample ssp seems to use LocalAlloc/LocalFee, but there doesn't seem to
695 * be any guarantee, nor is there an alloc function in secur32.
697 SECURITY_STATUS WINAPI
FreeContextBuffer(PVOID pv
)
704 /***********************************************************************
705 * EnumerateSecurityPackagesW (SECUR32.@)
707 SECURITY_STATUS WINAPI
EnumerateSecurityPackagesW(PULONG pcPackages
,
708 PSecPkgInfoW
*ppPackageInfo
)
710 SECURITY_STATUS ret
= SEC_E_OK
;
712 TRACE("(%p, %p)\n", pcPackages
, ppPackageInfo
);
714 /* windows just crashes if pcPackages or ppPackageInfo is NULL, so will I */
716 EnterCriticalSection(&cs
);
719 SecurePackage
*package
;
722 bytesNeeded
= packageTable
->numPackages
* sizeof(SecPkgInfoW
);
723 LIST_FOR_EACH_ENTRY(package
, &packageTable
->table
, SecurePackage
, entry
)
725 if (package
->infoW
.Name
)
726 bytesNeeded
+= (lstrlenW(package
->infoW
.Name
) + 1) * sizeof(WCHAR
);
727 if (package
->infoW
.Comment
)
728 bytesNeeded
+= (lstrlenW(package
->infoW
.Comment
) + 1) * sizeof(WCHAR
);
732 *ppPackageInfo
= (PSecPkgInfoW
)SECUR32_ALLOC(bytesNeeded
);
738 *pcPackages
= packageTable
->numPackages
;
739 nextString
= (PWSTR
)((PBYTE
)*ppPackageInfo
+
740 packageTable
->numPackages
* sizeof(SecPkgInfoW
));
741 LIST_FOR_EACH_ENTRY(package
, &packageTable
->table
, SecurePackage
, entry
)
743 PSecPkgInfoW pkgInfo
= *ppPackageInfo
+ i
++;
745 memcpy(pkgInfo
, &package
->infoW
, sizeof(SecPkgInfoW
));
746 if (package
->infoW
.Name
)
748 TRACE("Name[%d] = %s\n", i
- 1, debugstr_w(package
->infoW
.Name
));
749 pkgInfo
->Name
= nextString
;
750 lstrcpyW(nextString
, package
->infoW
.Name
);
751 nextString
+= lstrlenW(nextString
) + 1;
754 pkgInfo
->Name
= NULL
;
755 if (package
->infoW
.Comment
)
757 TRACE("Comment[%d] = %s\n", i
- 1, debugstr_w(package
->infoW
.Comment
));
758 pkgInfo
->Comment
= nextString
;
759 lstrcpyW(nextString
, package
->infoW
.Comment
);
760 nextString
+= lstrlenW(nextString
) + 1;
763 pkgInfo
->Comment
= NULL
;
767 ret
= SEC_E_INSUFFICIENT_MEMORY
;
770 LeaveCriticalSection(&cs
);
771 TRACE("<-- 0x%08x\n", ret
);
775 /* Converts info (which is assumed to be an array of cPackages SecPkgInfoW
776 * structures) into an array of SecPkgInfoA structures, which it returns.
778 static PSecPkgInfoA
thunk_PSecPkgInfoWToA(ULONG cPackages
,
779 const PSecPkgInfoW info
)
785 size_t bytesNeeded
= cPackages
* sizeof(SecPkgInfoA
);
788 for (i
= 0; i
< cPackages
; i
++)
791 bytesNeeded
+= WideCharToMultiByte(CP_ACP
, 0, info
[i
].Name
,
792 -1, NULL
, 0, NULL
, NULL
);
794 bytesNeeded
+= WideCharToMultiByte(CP_ACP
, 0, info
[i
].Comment
,
795 -1, NULL
, 0, NULL
, NULL
);
797 ret
= (PSecPkgInfoA
)SECUR32_ALLOC(bytesNeeded
);
802 nextString
= (PSTR
)((PBYTE
)ret
+ cPackages
* sizeof(SecPkgInfoA
));
803 for (i
= 0; i
< cPackages
; i
++)
805 PSecPkgInfoA pkgInfo
= ret
+ i
;
808 memcpy(pkgInfo
, &info
[i
], sizeof(SecPkgInfoA
));
811 pkgInfo
->Name
= nextString
;
812 /* just repeat back to WideCharToMultiByte how many bytes
813 * it requires, since we asked it earlier
815 bytes
= WideCharToMultiByte(CP_ACP
, 0, info
[i
].Name
, -1,
816 NULL
, 0, NULL
, NULL
);
817 WideCharToMultiByte(CP_ACP
, 0, info
[i
].Name
, -1,
818 pkgInfo
->Name
, bytes
, NULL
, NULL
);
819 nextString
+= lstrlenA(nextString
) + 1;
822 pkgInfo
->Name
= NULL
;
825 pkgInfo
->Comment
= nextString
;
826 /* just repeat back to WideCharToMultiByte how many bytes
827 * it requires, since we asked it earlier
829 bytes
= WideCharToMultiByte(CP_ACP
, 0, info
[i
].Comment
, -1,
830 NULL
, 0, NULL
, NULL
);
831 WideCharToMultiByte(CP_ACP
, 0, info
[i
].Comment
, -1,
832 pkgInfo
->Comment
, bytes
, NULL
, NULL
);
833 nextString
+= lstrlenA(nextString
) + 1;
836 pkgInfo
->Comment
= NULL
;
845 /***********************************************************************
846 * EnumerateSecurityPackagesA (SECUR32.@)
848 SECURITY_STATUS WINAPI
EnumerateSecurityPackagesA(PULONG pcPackages
,
849 PSecPkgInfoA
*ppPackageInfo
)
854 ret
= EnumerateSecurityPackagesW(pcPackages
, &info
);
855 if (ret
== SEC_E_OK
&& *pcPackages
&& info
)
857 *ppPackageInfo
= thunk_PSecPkgInfoWToA(*pcPackages
, info
);
858 if (*pcPackages
&& !*ppPackageInfo
)
861 ret
= SEC_E_INSUFFICIENT_MEMORY
;
863 FreeContextBuffer(info
);
868 /***********************************************************************
869 * GetComputerObjectNameA (SECUR32.@)
871 * Get the local computer's name using the format specified.
874 * NameFormat [I] The format for the name.
875 * lpNameBuffer [O] Pointer to buffer to receive the name.
876 * nSize [I/O] Size in characters of buffer.
879 * TRUE If the name was written to lpNameBuffer.
880 * FALSE If the name couldn't be written.
883 * If lpNameBuffer is NULL, then the size of the buffer needed to hold the
884 * name will be returned in *nSize.
886 * nSize returns the number of characters written when lpNameBuffer is not
887 * NULL or the size of the buffer needed to hold the name when the buffer
888 * is too short or lpNameBuffer is NULL.
890 * It the buffer is too short, ERROR_INSUFFICIENT_BUFFER error will be set.
892 BOOLEAN WINAPI
GetComputerObjectNameA(
893 EXTENDED_NAME_FORMAT NameFormat
, LPSTR lpNameBuffer
, PULONG nSize
)
896 LPWSTR bufferW
= NULL
;
897 ULONG sizeW
= *nSize
;
898 TRACE("(%d %p %p)\n", NameFormat
, lpNameBuffer
, nSize
);
900 bufferW
= HeapAlloc(GetProcessHeap(), 0, sizeW
* sizeof(WCHAR
));
901 if (bufferW
== NULL
) {
902 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
906 rc
= GetComputerObjectNameW(NameFormat
, bufferW
, &sizeW
);
908 ULONG len
= WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
909 WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, lpNameBuffer
, *nSize
, NULL
, NULL
);
914 HeapFree(GetProcessHeap(), 0, bufferW
);
918 /***********************************************************************
919 * GetComputerObjectNameW (SECUR32.@)
921 BOOLEAN WINAPI
GetComputerObjectNameW(
922 EXTENDED_NAME_FORMAT NameFormat
, LPWSTR lpNameBuffer
, PULONG nSize
)
924 LSA_HANDLE policyHandle
;
925 LSA_OBJECT_ATTRIBUTES objectAttributes
;
926 PPOLICY_DNS_DOMAIN_INFO domainInfo
;
929 TRACE("(%d %p %p)\n", NameFormat
, lpNameBuffer
, nSize
);
931 if (NameFormat
== NameUnknown
)
933 SetLastError(ERROR_INVALID_PARAMETER
);
937 ZeroMemory(&objectAttributes
, sizeof(objectAttributes
));
938 objectAttributes
.Length
= sizeof(objectAttributes
);
940 ntStatus
= LsaOpenPolicy(NULL
, &objectAttributes
,
941 POLICY_VIEW_LOCAL_INFORMATION
,
943 if (ntStatus
!= STATUS_SUCCESS
)
945 SetLastError(LsaNtStatusToWinError(ntStatus
));
946 WARN("LsaOpenPolicy failed with NT status %x\n", GetLastError());
950 ntStatus
= LsaQueryInformationPolicy(policyHandle
,
951 PolicyDnsDomainInformation
,
952 (PVOID
*)&domainInfo
);
953 if (ntStatus
!= STATUS_SUCCESS
)
955 SetLastError(LsaNtStatusToWinError(ntStatus
));
956 WARN("LsaQueryInformationPolicy failed with NT status %x\n",
958 LsaClose(policyHandle
);
966 case NameSamCompatible
:
968 WCHAR name
[MAX_COMPUTERNAME_LENGTH
+ 1];
969 DWORD size
= sizeof(name
);
970 if (GetComputerNameW(name
, &size
))
972 int len
= domainInfo
->Name
.Length
+ size
+ 3;
978 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
983 WCHAR bs
[] = { '\\', 0 };
984 WCHAR ds
[] = { '$', 0 };
985 lstrcpyW(lpNameBuffer
, domainInfo
->Name
.Buffer
);
986 lstrcatW(lpNameBuffer
, bs
);
987 lstrcatW(lpNameBuffer
, name
);
988 lstrcatW(lpNameBuffer
, ds
);
992 else /* just requesting length required */
1000 SetLastError(ERROR_INTERNAL_ERROR
);
1005 case NameFullyQualifiedDN
:
1009 case NameUserPrincipal
:
1010 case NameCanonicalEx
:
1011 case NameServicePrincipal
:
1013 FIXME("NameFormat %d not implemented\n", NameFormat
);
1014 SetLastError(ERROR_CANT_ACCESS_DOMAIN_INFO
);
1018 SetLastError(ERROR_INVALID_PARAMETER
);
1024 SetLastError(ERROR_CANT_ACCESS_DOMAIN_INFO
);
1028 LsaFreeMemory(domainInfo
);
1029 LsaClose(policyHandle
);
1034 BOOLEAN WINAPI
GetUserNameExA(
1035 EXTENDED_NAME_FORMAT NameFormat
, LPSTR lpNameBuffer
, PULONG nSize
)
1037 FIXME("%d %p %p\n", NameFormat
, lpNameBuffer
, nSize
);
1041 BOOLEAN WINAPI
GetUserNameExW(
1042 EXTENDED_NAME_FORMAT NameFormat
, LPWSTR lpNameBuffer
, PULONG nSize
)
1044 FIXME("%d %p %p\n", NameFormat
, lpNameBuffer
, nSize
);
1048 NTSTATUS WINAPI
LsaCallAuthenticationPackage(
1049 HANDLE LsaHandle
, ULONG AuthenticationPackage
, PVOID ProtocolSubmitBuffer
,
1050 ULONG SubmitBufferLength
, PVOID
* ProtocolReturnBuffer
, PULONG ReturnBufferLength
,
1051 PNTSTATUS ProtocolStatus
)
1053 FIXME("%p %d %p %d %p %p %p\n", LsaHandle
, AuthenticationPackage
,
1054 ProtocolSubmitBuffer
, SubmitBufferLength
, ProtocolReturnBuffer
,
1055 ReturnBufferLength
, ProtocolStatus
);
1059 NTSTATUS WINAPI
LsaConnectUntrusted(PHANDLE LsaHandle
)
1061 FIXME("%p\n", LsaHandle
);
1065 NTSTATUS WINAPI
LsaDeregisterLogonProcess(HANDLE LsaHandle
)
1067 FIXME("%p\n", LsaHandle
);
1071 BOOLEAN WINAPI
TranslateNameA(
1072 LPCSTR lpAccountName
, EXTENDED_NAME_FORMAT AccountNameFormat
,
1073 EXTENDED_NAME_FORMAT DesiredNameFormat
, LPSTR lpTranslatedName
,
1076 FIXME("%p %d %d %p %p\n", lpAccountName
, AccountNameFormat
,
1077 DesiredNameFormat
, lpTranslatedName
, nSize
);
1081 BOOLEAN WINAPI
TranslateNameW(
1082 LPCWSTR lpAccountName
, EXTENDED_NAME_FORMAT AccountNameFormat
,
1083 EXTENDED_NAME_FORMAT DesiredNameFormat
, LPWSTR lpTranslatedName
,
1086 FIXME("%p %d %d %p %p\n", lpAccountName
, AccountNameFormat
,
1087 DesiredNameFormat
, lpTranslatedName
, nSize
);
1091 /***********************************************************************
1092 * DllMain (SECUR32.0)
1094 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
1096 if (fdwReason
== DLL_PROCESS_ATTACH
)
1098 DisableThreadLibraryCalls(hinstDLL
);
1099 SECUR32_initializeProviders();
1101 else if (fdwReason
== DLL_PROCESS_DETACH
)
1103 SECUR32_freeProviders();