20 #include <winpr/platform.h>
21 #include <winpr/config.h>
23 WINPR_PRAGMA_DIAG_PUSH
24 WINPR_PRAGMA_DIAG_IGNORED_RESERVED_ID_MACRO
25 WINPR_PRAGMA_DIAG_IGNORED_UNUSED_MACRO
27 #define _NO_KSECDD_IMPORT_ 1
31 #include <winpr/sspi.h>
33 #include <winpr/crt.h>
34 #include <winpr/synch.h>
35 #include <winpr/wlog.h>
36 #include <winpr/library.h>
37 #include <winpr/environment.h>
41 WINPR_PRAGMA_DIAG_PUSH
42 WINPR_PRAGMA_DIAG_IGNORED_MISSING_PROTOTYPES
44 static wLog* g_Log = NULL;
46 static INIT_ONCE g_Initialized = INIT_ONCE_STATIC_INIT;
47 #if defined(WITH_NATIVE_SSPI)
48 static HMODULE g_SspiModule = NULL;
56 #if defined(WITH_NATIVE_SSPI)
57 static BOOL ShouldUseNativeSspi(
void);
58 static BOOL InitializeSspiModule_Native(
void);
61 #if defined(WITH_NATIVE_SSPI)
62 BOOL ShouldUseNativeSspi(
void)
66 LPCSTR sspi =
"WINPR_NATIVE_SSPI";
69 nSize = GetEnvironmentVariableA(sspi, NULL, 0);
74 env = (LPSTR)malloc(nSize);
79 if (GetEnvironmentVariableA(sspi, env, nSize) != nSize - 1)
85 if (strcmp(env,
"0") == 0)
96 #if defined(WITH_NATIVE_SSPI)
97 BOOL InitializeSspiModule_Native(
void)
101 INIT_SECURITY_INTERFACE_W pInitSecurityInterfaceW;
102 INIT_SECURITY_INTERFACE_A pInitSecurityInterfaceA;
103 g_SspiModule = LoadLibraryA(
"secur32.dll");
106 g_SspiModule = LoadLibraryA(
"sspicli.dll");
111 pInitSecurityInterfaceW =
112 GetProcAddressAs(g_SspiModule,
"InitSecurityInterfaceW", INIT_SECURITY_INTERFACE_W);
113 pInitSecurityInterfaceA =
114 GetProcAddressAs(g_SspiModule,
"InitSecurityInterfaceA", INIT_SECURITY_INTERFACE_A);
116 if (pInitSecurityInterfaceW)
118 pSspiW = pInitSecurityInterfaceW();
122 g_SspiW = &windows_SecurityFunctionTableW;
123 CopyMemory(g_SspiW, pSspiW,
126 g_SspiW->dwVersion = SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION_3;
128 g_SspiW->SetContextAttributesW = GetProcAddressAs(g_SspiModule,
"SetContextAttributesW",
129 SET_CONTEXT_ATTRIBUTES_FN_W);
131 g_SspiW->SetCredentialsAttributesW = GetProcAddressAs(
132 g_SspiModule,
"SetCredentialsAttributesW", SET_CREDENTIALS_ATTRIBUTES_FN_W);
136 if (pInitSecurityInterfaceA)
138 pSspiA = pInitSecurityInterfaceA();
142 g_SspiA = &windows_SecurityFunctionTableA;
143 CopyMemory(g_SspiA, pSspiA,
146 g_SspiA->dwVersion = SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION_3;
148 g_SspiA->SetContextAttributesA = GetProcAddressAs(g_SspiModule,
"SetContextAttributesA",
149 SET_CONTEXT_ATTRIBUTES_FN_W);
151 g_SspiA->SetCredentialsAttributesA = GetProcAddressAs(
152 g_SspiModule,
"SetCredentialsAttributesA", SET_CREDENTIALS_ATTRIBUTES_FN_W);
160 static BOOL CALLBACK InitializeSspiModuleInt(
PINIT_ONCE once, PVOID param, PVOID* context)
163 #if defined(WITH_NATIVE_SSPI)
167 flags = *(DWORD*)param;
171 g_Log = WLog_Get(
"com.winpr.sspi");
172 #if defined(WITH_NATIVE_SSPI)
174 if (flags && (flags & SSPI_INTERFACE_NATIVE))
176 status = InitializeSspiModule_Native();
178 else if (flags && (flags & SSPI_INTERFACE_WINPR))
180 g_SspiW = winpr_InitSecurityInterfaceW();
181 g_SspiA = winpr_InitSecurityInterfaceA();
185 if (!status && ShouldUseNativeSspi())
187 status = InitializeSspiModule_Native();
194 g_SspiW = winpr_InitSecurityInterfaceW();
195 g_SspiA = winpr_InitSecurityInterfaceA();
201 const char* GetSecurityStatusString(SECURITY_STATUS status)
208 case SEC_E_INSUFFICIENT_MEMORY:
209 return "SEC_E_INSUFFICIENT_MEMORY";
211 case SEC_E_INVALID_HANDLE:
212 return "SEC_E_INVALID_HANDLE";
214 case SEC_E_UNSUPPORTED_FUNCTION:
215 return "SEC_E_UNSUPPORTED_FUNCTION";
217 case SEC_E_TARGET_UNKNOWN:
218 return "SEC_E_TARGET_UNKNOWN";
220 case SEC_E_INTERNAL_ERROR:
221 return "SEC_E_INTERNAL_ERROR";
223 case SEC_E_SECPKG_NOT_FOUND:
224 return "SEC_E_SECPKG_NOT_FOUND";
226 case SEC_E_NOT_OWNER:
227 return "SEC_E_NOT_OWNER";
229 case SEC_E_CANNOT_INSTALL:
230 return "SEC_E_CANNOT_INSTALL";
232 case SEC_E_INVALID_TOKEN:
233 return "SEC_E_INVALID_TOKEN";
235 case SEC_E_CANNOT_PACK:
236 return "SEC_E_CANNOT_PACK";
238 case SEC_E_QOP_NOT_SUPPORTED:
239 return "SEC_E_QOP_NOT_SUPPORTED";
241 case SEC_E_NO_IMPERSONATION:
242 return "SEC_E_NO_IMPERSONATION";
244 case SEC_E_LOGON_DENIED:
245 return "SEC_E_LOGON_DENIED";
247 case SEC_E_UNKNOWN_CREDENTIALS:
248 return "SEC_E_UNKNOWN_CREDENTIALS";
250 case SEC_E_NO_CREDENTIALS:
251 return "SEC_E_NO_CREDENTIALS";
253 case SEC_E_MESSAGE_ALTERED:
254 return "SEC_E_MESSAGE_ALTERED";
256 case SEC_E_OUT_OF_SEQUENCE:
257 return "SEC_E_OUT_OF_SEQUENCE";
259 case SEC_E_NO_AUTHENTICATING_AUTHORITY:
260 return "SEC_E_NO_AUTHENTICATING_AUTHORITY";
262 case SEC_E_BAD_PKGID:
263 return "SEC_E_BAD_PKGID";
265 case SEC_E_CONTEXT_EXPIRED:
266 return "SEC_E_CONTEXT_EXPIRED";
268 case SEC_E_INCOMPLETE_MESSAGE:
269 return "SEC_E_INCOMPLETE_MESSAGE";
271 case SEC_E_INCOMPLETE_CREDENTIALS:
272 return "SEC_E_INCOMPLETE_CREDENTIALS";
274 case SEC_E_BUFFER_TOO_SMALL:
275 return "SEC_E_BUFFER_TOO_SMALL";
277 case SEC_E_WRONG_PRINCIPAL:
278 return "SEC_E_WRONG_PRINCIPAL";
280 case SEC_E_TIME_SKEW:
281 return "SEC_E_TIME_SKEW";
283 case SEC_E_UNTRUSTED_ROOT:
284 return "SEC_E_UNTRUSTED_ROOT";
286 case SEC_E_ILLEGAL_MESSAGE:
287 return "SEC_E_ILLEGAL_MESSAGE";
289 case SEC_E_CERT_UNKNOWN:
290 return "SEC_E_CERT_UNKNOWN";
292 case SEC_E_CERT_EXPIRED:
293 return "SEC_E_CERT_EXPIRED";
295 case SEC_E_ENCRYPT_FAILURE:
296 return "SEC_E_ENCRYPT_FAILURE";
298 case SEC_E_DECRYPT_FAILURE:
299 return "SEC_E_DECRYPT_FAILURE";
301 case SEC_E_ALGORITHM_MISMATCH:
302 return "SEC_E_ALGORITHM_MISMATCH";
304 case SEC_E_SECURITY_QOS_FAILED:
305 return "SEC_E_SECURITY_QOS_FAILED";
307 case SEC_E_UNFINISHED_CONTEXT_DELETED:
308 return "SEC_E_UNFINISHED_CONTEXT_DELETED";
310 case SEC_E_NO_TGT_REPLY:
311 return "SEC_E_NO_TGT_REPLY";
313 case SEC_E_NO_IP_ADDRESSES:
314 return "SEC_E_NO_IP_ADDRESSES";
316 case SEC_E_WRONG_CREDENTIAL_HANDLE:
317 return "SEC_E_WRONG_CREDENTIAL_HANDLE";
319 case SEC_E_CRYPTO_SYSTEM_INVALID:
320 return "SEC_E_CRYPTO_SYSTEM_INVALID";
322 case SEC_E_MAX_REFERRALS_EXCEEDED:
323 return "SEC_E_MAX_REFERRALS_EXCEEDED";
325 case SEC_E_MUST_BE_KDC:
326 return "SEC_E_MUST_BE_KDC";
328 case SEC_E_STRONG_CRYPTO_NOT_SUPPORTED:
329 return "SEC_E_STRONG_CRYPTO_NOT_SUPPORTED";
331 case SEC_E_TOO_MANY_PRINCIPALS:
332 return "SEC_E_TOO_MANY_PRINCIPALS";
334 case SEC_E_NO_PA_DATA:
335 return "SEC_E_NO_PA_DATA";
337 case SEC_E_PKINIT_NAME_MISMATCH:
338 return "SEC_E_PKINIT_NAME_MISMATCH";
340 case SEC_E_SMARTCARD_LOGON_REQUIRED:
341 return "SEC_E_SMARTCARD_LOGON_REQUIRED";
343 case SEC_E_SHUTDOWN_IN_PROGRESS:
344 return "SEC_E_SHUTDOWN_IN_PROGRESS";
346 case SEC_E_KDC_INVALID_REQUEST:
347 return "SEC_E_KDC_INVALID_REQUEST";
349 case SEC_E_KDC_UNABLE_TO_REFER:
350 return "SEC_E_KDC_UNABLE_TO_REFER";
352 case SEC_E_KDC_UNKNOWN_ETYPE:
353 return "SEC_E_KDC_UNKNOWN_ETYPE";
355 case SEC_E_UNSUPPORTED_PREAUTH:
356 return "SEC_E_UNSUPPORTED_PREAUTH";
358 case SEC_E_DELEGATION_REQUIRED:
359 return "SEC_E_DELEGATION_REQUIRED";
361 case SEC_E_BAD_BINDINGS:
362 return "SEC_E_BAD_BINDINGS";
364 case SEC_E_MULTIPLE_ACCOUNTS:
365 return "SEC_E_MULTIPLE_ACCOUNTS";
367 case SEC_E_NO_KERB_KEY:
368 return "SEC_E_NO_KERB_KEY";
370 case SEC_E_CERT_WRONG_USAGE:
371 return "SEC_E_CERT_WRONG_USAGE";
373 case SEC_E_DOWNGRADE_DETECTED:
374 return "SEC_E_DOWNGRADE_DETECTED";
376 case SEC_E_SMARTCARD_CERT_REVOKED:
377 return "SEC_E_SMARTCARD_CERT_REVOKED";
379 case SEC_E_ISSUING_CA_UNTRUSTED:
380 return "SEC_E_ISSUING_CA_UNTRUSTED";
382 case SEC_E_REVOCATION_OFFLINE_C:
383 return "SEC_E_REVOCATION_OFFLINE_C";
385 case SEC_E_PKINIT_CLIENT_FAILURE:
386 return "SEC_E_PKINIT_CLIENT_FAILURE";
388 case SEC_E_SMARTCARD_CERT_EXPIRED:
389 return "SEC_E_SMARTCARD_CERT_EXPIRED";
391 case SEC_E_NO_S4U_PROT_SUPPORT:
392 return "SEC_E_NO_S4U_PROT_SUPPORT";
394 case SEC_E_CROSSREALM_DELEGATION_FAILURE:
395 return "SEC_E_CROSSREALM_DELEGATION_FAILURE";
397 case SEC_E_REVOCATION_OFFLINE_KDC:
398 return "SEC_E_REVOCATION_OFFLINE_KDC";
400 case SEC_E_ISSUING_CA_UNTRUSTED_KDC:
401 return "SEC_E_ISSUING_CA_UNTRUSTED_KDC";
403 case SEC_E_KDC_CERT_EXPIRED:
404 return "SEC_E_KDC_CERT_EXPIRED";
406 case SEC_E_KDC_CERT_REVOKED:
407 return "SEC_E_KDC_CERT_REVOKED";
409 case SEC_E_INVALID_PARAMETER:
410 return "SEC_E_INVALID_PARAMETER";
412 case SEC_E_DELEGATION_POLICY:
413 return "SEC_E_DELEGATION_POLICY";
415 case SEC_E_POLICY_NLTM_ONLY:
416 return "SEC_E_POLICY_NLTM_ONLY";
418 case SEC_E_NO_CONTEXT:
419 return "SEC_E_NO_CONTEXT";
421 case SEC_E_PKU2U_CERT_FAILURE:
422 return "SEC_E_PKU2U_CERT_FAILURE";
424 case SEC_E_MUTUAL_AUTH_FAILED:
425 return "SEC_E_MUTUAL_AUTH_FAILED";
427 case SEC_I_CONTINUE_NEEDED:
428 return "SEC_I_CONTINUE_NEEDED";
430 case SEC_I_COMPLETE_NEEDED:
431 return "SEC_I_COMPLETE_NEEDED";
433 case SEC_I_COMPLETE_AND_CONTINUE:
434 return "SEC_I_COMPLETE_AND_CONTINUE";
436 case SEC_I_LOCAL_LOGON:
437 return "SEC_I_LOCAL_LOGON";
439 case SEC_I_CONTEXT_EXPIRED:
440 return "SEC_I_CONTEXT_EXPIRED";
442 case SEC_I_INCOMPLETE_CREDENTIALS:
443 return "SEC_I_INCOMPLETE_CREDENTIALS";
445 case SEC_I_RENEGOTIATE:
446 return "SEC_I_RENEGOTIATE";
448 case SEC_I_NO_LSA_CONTEXT:
449 return "SEC_I_NO_LSA_CONTEXT";
451 case SEC_I_SIGNATURE_NEEDED:
452 return "SEC_I_SIGNATURE_NEEDED";
454 case SEC_I_NO_RENEGOTIATION:
455 return "SEC_I_NO_RENEGOTIATION";
460 return NtStatus2Tag((DWORD)status);
463 BOOL IsSecurityStatusError(SECURITY_STATUS status)
470 case SEC_I_CONTINUE_NEEDED:
471 case SEC_I_COMPLETE_NEEDED:
472 case SEC_I_COMPLETE_AND_CONTINUE:
473 case SEC_I_LOCAL_LOGON:
474 case SEC_I_CONTEXT_EXPIRED:
475 case SEC_I_INCOMPLETE_CREDENTIALS:
476 case SEC_I_RENEGOTIATE:
477 case SEC_I_NO_LSA_CONTEXT:
478 case SEC_I_SIGNATURE_NEEDED:
479 case SEC_I_NO_RENEGOTIATION:
491 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, &flags, NULL);
492 WLog_Print(g_Log, WLOG_DEBUG,
"InitSecurityInterfaceExW");
498 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, &flags, NULL);
499 WLog_Print(g_Log, WLOG_DEBUG,
"InitSecurityInterfaceExA");
509 SECURITY_STATUS SEC_ENTRY sspi_EnumerateSecurityPackagesW(ULONG* pcPackages,
512 SECURITY_STATUS status = 0;
513 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
515 if (!(g_SspiW && g_SspiW->EnumerateSecurityPackagesW))
517 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
519 return SEC_E_UNSUPPORTED_FUNCTION;
522 status = g_SspiW->EnumerateSecurityPackagesW(pcPackages, ppPackageInfo);
523 WLog_Print(g_Log, WLOG_DEBUG,
"EnumerateSecurityPackagesW: %s (0x%08" PRIX32
")",
524 GetSecurityStatusString(status), status);
528 SECURITY_STATUS SEC_ENTRY sspi_EnumerateSecurityPackagesA(ULONG* pcPackages,
531 SECURITY_STATUS status = 0;
532 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
534 if (!(g_SspiA && g_SspiA->EnumerateSecurityPackagesA))
536 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
538 return SEC_E_UNSUPPORTED_FUNCTION;
541 status = g_SspiA->EnumerateSecurityPackagesA(pcPackages, ppPackageInfo);
542 WLog_Print(g_Log, WLOG_DEBUG,
"EnumerateSecurityPackagesA: %s (0x%08" PRIX32
")",
543 GetSecurityStatusString(status), status);
549 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
550 WLog_Print(g_Log, WLOG_DEBUG,
"InitSecurityInterfaceW");
556 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
557 WLog_Print(g_Log, WLOG_DEBUG,
"InitSecurityInterfaceA");
561 SECURITY_STATUS SEC_ENTRY sspi_QuerySecurityPackageInfoW(SEC_WCHAR* pszPackageName,
564 SECURITY_STATUS status = 0;
565 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
567 if (!(g_SspiW && g_SspiW->QuerySecurityPackageInfoW))
569 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
571 return SEC_E_UNSUPPORTED_FUNCTION;
574 status = g_SspiW->QuerySecurityPackageInfoW(pszPackageName, ppPackageInfo);
575 WLog_Print(g_Log, WLOG_DEBUG,
"QuerySecurityPackageInfoW: %s (0x%08" PRIX32
")",
576 GetSecurityStatusString(status), status);
580 SECURITY_STATUS SEC_ENTRY sspi_QuerySecurityPackageInfoA(SEC_CHAR* pszPackageName,
583 SECURITY_STATUS status = 0;
584 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
586 if (!(g_SspiA && g_SspiA->QuerySecurityPackageInfoA))
588 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
590 return SEC_E_UNSUPPORTED_FUNCTION;
593 status = g_SspiA->QuerySecurityPackageInfoA(pszPackageName, ppPackageInfo);
594 WLog_Print(g_Log, WLOG_DEBUG,
"QuerySecurityPackageInfoA: %s (0x%08" PRIX32
")",
595 GetSecurityStatusString(status), status);
601 SECURITY_STATUS SEC_ENTRY sspi_AcquireCredentialsHandleW(
602 SEC_WCHAR* pszPrincipal, SEC_WCHAR* pszPackage, ULONG fCredentialUse,
void* pvLogonID,
603 void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument,
PCredHandle phCredential,
606 SECURITY_STATUS status = 0;
607 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
609 if (!(g_SspiW && g_SspiW->AcquireCredentialsHandleW))
611 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
613 return SEC_E_UNSUPPORTED_FUNCTION;
616 status = g_SspiW->AcquireCredentialsHandleW(pszPrincipal, pszPackage, fCredentialUse, pvLogonID,
617 pAuthData, pGetKeyFn, pvGetKeyArgument,
618 phCredential, ptsExpiry);
619 WLog_Print(g_Log, WLOG_DEBUG,
"AcquireCredentialsHandleW: %s (0x%08" PRIX32
")",
620 GetSecurityStatusString(status), status);
624 SECURITY_STATUS SEC_ENTRY sspi_AcquireCredentialsHandleA(
625 SEC_CHAR* pszPrincipal, SEC_CHAR* pszPackage, ULONG fCredentialUse,
void* pvLogonID,
626 void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument,
PCredHandle phCredential,
629 SECURITY_STATUS status = 0;
630 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
632 if (!(g_SspiA && g_SspiA->AcquireCredentialsHandleA))
634 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
636 return SEC_E_UNSUPPORTED_FUNCTION;
639 status = g_SspiA->AcquireCredentialsHandleA(pszPrincipal, pszPackage, fCredentialUse, pvLogonID,
640 pAuthData, pGetKeyFn, pvGetKeyArgument,
641 phCredential, ptsExpiry);
642 WLog_Print(g_Log, WLOG_DEBUG,
"AcquireCredentialsHandleA: %s (0x%08" PRIX32
")",
643 GetSecurityStatusString(status), status);
647 SECURITY_STATUS SEC_ENTRY sspi_ExportSecurityContext(
PCtxtHandle phContext, ULONG fFlags,
650 SECURITY_STATUS status = 0;
651 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
653 if (!(g_SspiW && g_SspiW->ExportSecurityContext))
655 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
657 return SEC_E_UNSUPPORTED_FUNCTION;
660 status = g_SspiW->ExportSecurityContext(phContext, fFlags, pPackedContext, pToken);
661 WLog_Print(g_Log, WLOG_DEBUG,
"ExportSecurityContext: %s (0x%08" PRIX32
")",
662 GetSecurityStatusString(status), status);
666 SECURITY_STATUS SEC_ENTRY sspi_FreeCredentialsHandle(
PCredHandle phCredential)
668 SECURITY_STATUS status = 0;
669 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
671 if (!(g_SspiW && g_SspiW->FreeCredentialsHandle))
673 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
675 return SEC_E_UNSUPPORTED_FUNCTION;
678 status = g_SspiW->FreeCredentialsHandle(phCredential);
679 WLog_Print(g_Log, WLOG_DEBUG,
"FreeCredentialsHandle: %s (0x%08" PRIX32
")",
680 GetSecurityStatusString(status), status);
684 SECURITY_STATUS SEC_ENTRY sspi_ImportSecurityContextW(SEC_WCHAR* pszPackage,
688 SECURITY_STATUS status = 0;
689 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
691 if (!(g_SspiW && g_SspiW->ImportSecurityContextW))
693 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
695 return SEC_E_UNSUPPORTED_FUNCTION;
698 status = g_SspiW->ImportSecurityContextW(pszPackage, pPackedContext, pToken, phContext);
699 WLog_Print(g_Log, WLOG_DEBUG,
"ImportSecurityContextW: %s (0x%08" PRIX32
")",
700 GetSecurityStatusString(status), status);
704 SECURITY_STATUS SEC_ENTRY sspi_ImportSecurityContextA(SEC_CHAR* pszPackage,
708 SECURITY_STATUS status = 0;
709 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
711 if (!(g_SspiA && g_SspiA->ImportSecurityContextA))
713 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
715 return SEC_E_UNSUPPORTED_FUNCTION;
718 status = g_SspiA->ImportSecurityContextA(pszPackage, pPackedContext, pToken, phContext);
719 WLog_Print(g_Log, WLOG_DEBUG,
"ImportSecurityContextA: %s (0x%08" PRIX32
")",
720 GetSecurityStatusString(status), status);
724 SECURITY_STATUS SEC_ENTRY sspi_QueryCredentialsAttributesW(
PCredHandle phCredential,
725 ULONG ulAttribute,
void* pBuffer)
727 SECURITY_STATUS status = 0;
728 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
730 if (!(g_SspiW && g_SspiW->QueryCredentialsAttributesW))
732 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
734 return SEC_E_UNSUPPORTED_FUNCTION;
737 status = g_SspiW->QueryCredentialsAttributesW(phCredential, ulAttribute, pBuffer);
738 WLog_Print(g_Log, WLOG_DEBUG,
"QueryCredentialsAttributesW: %s (0x%08" PRIX32
")",
739 GetSecurityStatusString(status), status);
743 SECURITY_STATUS SEC_ENTRY sspi_QueryCredentialsAttributesA(
PCredHandle phCredential,
744 ULONG ulAttribute,
void* pBuffer)
746 SECURITY_STATUS status = 0;
747 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
749 if (!(g_SspiA && g_SspiA->QueryCredentialsAttributesA))
751 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
753 return SEC_E_UNSUPPORTED_FUNCTION;
756 status = g_SspiA->QueryCredentialsAttributesA(phCredential, ulAttribute, pBuffer);
757 WLog_Print(g_Log, WLOG_DEBUG,
"QueryCredentialsAttributesA: %s (0x%08" PRIX32
")",
758 GetSecurityStatusString(status), status);
764 SECURITY_STATUS SEC_ENTRY sspi_AcceptSecurityContext(
PCredHandle phCredential,
766 ULONG fContextReq, ULONG TargetDataRep,
771 SECURITY_STATUS status = 0;
772 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
774 if (!(g_SspiW && g_SspiW->AcceptSecurityContext))
776 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
778 return SEC_E_UNSUPPORTED_FUNCTION;
782 g_SspiW->AcceptSecurityContext(phCredential, phContext, pInput, fContextReq, TargetDataRep,
783 phNewContext, pOutput, pfContextAttr, ptsTimeStamp);
784 WLog_Print(g_Log, WLOG_DEBUG,
"AcceptSecurityContext: %s (0x%08" PRIX32
")",
785 GetSecurityStatusString(status), status);
791 SECURITY_STATUS status = 0;
792 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
794 if (!(g_SspiW && g_SspiW->ApplyControlToken))
796 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
798 return SEC_E_UNSUPPORTED_FUNCTION;
801 status = g_SspiW->ApplyControlToken(phContext, pInput);
802 WLog_Print(g_Log, WLOG_DEBUG,
"ApplyControlToken: %s (0x%08" PRIX32
")",
803 GetSecurityStatusString(status), status);
809 SECURITY_STATUS status = 0;
810 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
812 if (!(g_SspiW && g_SspiW->CompleteAuthToken))
814 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
816 return SEC_E_UNSUPPORTED_FUNCTION;
819 status = g_SspiW->CompleteAuthToken(phContext, pToken);
820 WLog_Print(g_Log, WLOG_DEBUG,
"CompleteAuthToken: %s (0x%08" PRIX32
")",
821 GetSecurityStatusString(status), status);
825 SECURITY_STATUS SEC_ENTRY sspi_DeleteSecurityContext(
PCtxtHandle phContext)
827 SECURITY_STATUS status = 0;
828 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
830 if (!(g_SspiW && g_SspiW->DeleteSecurityContext))
832 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
834 return SEC_E_UNSUPPORTED_FUNCTION;
837 status = g_SspiW->DeleteSecurityContext(phContext);
838 WLog_Print(g_Log, WLOG_DEBUG,
"DeleteSecurityContext: %s (0x%08" PRIX32
")",
839 GetSecurityStatusString(status), status);
843 SECURITY_STATUS SEC_ENTRY sspi_FreeContextBuffer(
void* pvContextBuffer)
845 SECURITY_STATUS status = 0;
846 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
848 if (!(g_SspiW && g_SspiW->FreeContextBuffer))
850 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
852 return SEC_E_UNSUPPORTED_FUNCTION;
855 status = g_SspiW->FreeContextBuffer(pvContextBuffer);
856 WLog_Print(g_Log, WLOG_DEBUG,
"FreeContextBuffer: %s (0x%08" PRIX32
")",
857 GetSecurityStatusString(status), status);
861 SECURITY_STATUS SEC_ENTRY sspi_ImpersonateSecurityContext(
PCtxtHandle phContext)
863 SECURITY_STATUS status = 0;
864 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
866 if (!(g_SspiW && g_SspiW->ImpersonateSecurityContext))
868 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
870 return SEC_E_UNSUPPORTED_FUNCTION;
873 status = g_SspiW->ImpersonateSecurityContext(phContext);
874 WLog_Print(g_Log, WLOG_DEBUG,
"ImpersonateSecurityContext: %s (0x%08" PRIX32
")",
875 GetSecurityStatusString(status), status);
879 SECURITY_STATUS SEC_ENTRY sspi_InitializeSecurityContextW(
881 ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2,
884 SECURITY_STATUS status = 0;
885 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
887 if (!(g_SspiW && g_SspiW->InitializeSecurityContextW))
889 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
891 return SEC_E_UNSUPPORTED_FUNCTION;
894 status = g_SspiW->InitializeSecurityContextW(
895 phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput,
896 Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry);
897 WLog_Print(g_Log, WLOG_DEBUG,
"InitializeSecurityContextW: %s (0x%08" PRIX32
")",
898 GetSecurityStatusString(status), status);
902 SECURITY_STATUS SEC_ENTRY sspi_InitializeSecurityContextA(
904 ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2,
907 SECURITY_STATUS status = 0;
908 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
910 if (!(g_SspiA && g_SspiA->InitializeSecurityContextA))
912 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
914 return SEC_E_UNSUPPORTED_FUNCTION;
917 status = g_SspiA->InitializeSecurityContextA(
918 phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput,
919 Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry);
920 WLog_Print(g_Log, WLOG_DEBUG,
"InitializeSecurityContextA: %s (0x%08" PRIX32
")",
921 GetSecurityStatusString(status), status);
925 SECURITY_STATUS SEC_ENTRY sspi_QueryContextAttributesW(
PCtxtHandle phContext, ULONG ulAttribute,
928 SECURITY_STATUS status = 0;
929 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
931 if (!(g_SspiW && g_SspiW->QueryContextAttributesW))
933 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
935 return SEC_E_UNSUPPORTED_FUNCTION;
938 status = g_SspiW->QueryContextAttributesW(phContext, ulAttribute, pBuffer);
939 WLog_Print(g_Log, WLOG_DEBUG,
"QueryContextAttributesW: %s (0x%08" PRIX32
")",
940 GetSecurityStatusString(status), status);
944 SECURITY_STATUS SEC_ENTRY sspi_QueryContextAttributesA(
PCtxtHandle phContext, ULONG ulAttribute,
947 SECURITY_STATUS status = 0;
948 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
950 if (!(g_SspiA && g_SspiA->QueryContextAttributesA))
952 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
954 return SEC_E_UNSUPPORTED_FUNCTION;
957 status = g_SspiA->QueryContextAttributesA(phContext, ulAttribute, pBuffer);
958 WLog_Print(g_Log, WLOG_DEBUG,
"QueryContextAttributesA: %s (0x%08" PRIX32
")",
959 GetSecurityStatusString(status), status);
963 SECURITY_STATUS SEC_ENTRY sspi_QuerySecurityContextToken(
PCtxtHandle phContext, HANDLE* phToken)
965 SECURITY_STATUS status = 0;
966 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
968 if (!(g_SspiW && g_SspiW->QuerySecurityContextToken))
970 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
972 return SEC_E_UNSUPPORTED_FUNCTION;
975 status = g_SspiW->QuerySecurityContextToken(phContext, phToken);
976 WLog_Print(g_Log, WLOG_DEBUG,
"QuerySecurityContextToken: %s (0x%08" PRIX32
")",
977 GetSecurityStatusString(status), status);
981 SECURITY_STATUS SEC_ENTRY sspi_SetContextAttributesW(
PCtxtHandle phContext, ULONG ulAttribute,
982 void* pBuffer, ULONG cbBuffer)
984 SECURITY_STATUS status = 0;
985 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
987 if (!(g_SspiW && g_SspiW->SetContextAttributesW))
989 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
991 return SEC_E_UNSUPPORTED_FUNCTION;
994 status = g_SspiW->SetContextAttributesW(phContext, ulAttribute, pBuffer, cbBuffer);
995 WLog_Print(g_Log, WLOG_DEBUG,
"SetContextAttributesW: %s (0x%08" PRIX32
")",
996 GetSecurityStatusString(status), status);
1000 SECURITY_STATUS SEC_ENTRY sspi_SetContextAttributesA(
PCtxtHandle phContext, ULONG ulAttribute,
1001 void* pBuffer, ULONG cbBuffer)
1003 SECURITY_STATUS status = 0;
1004 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
1006 if (!(g_SspiA && g_SspiA->SetContextAttributesA))
1008 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
1010 return SEC_E_UNSUPPORTED_FUNCTION;
1013 status = g_SspiA->SetContextAttributesA(phContext, ulAttribute, pBuffer, cbBuffer);
1014 WLog_Print(g_Log, WLOG_DEBUG,
"SetContextAttributesA: %s (0x%08" PRIX32
")",
1015 GetSecurityStatusString(status), status);
1019 SECURITY_STATUS SEC_ENTRY sspi_RevertSecurityContext(
PCtxtHandle phContext)
1021 SECURITY_STATUS status = 0;
1022 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
1024 if (!(g_SspiW && g_SspiW->RevertSecurityContext))
1026 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
1028 return SEC_E_UNSUPPORTED_FUNCTION;
1031 status = g_SspiW->RevertSecurityContext(phContext);
1032 WLog_Print(g_Log, WLOG_DEBUG,
"RevertSecurityContext: %s (0x%08" PRIX32
")",
1033 GetSecurityStatusString(status), status);
1040 ULONG MessageSeqNo, PULONG pfQOP)
1042 SECURITY_STATUS status = 0;
1043 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
1045 if (!(g_SspiW && g_SspiW->DecryptMessage))
1047 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
1049 return SEC_E_UNSUPPORTED_FUNCTION;
1052 status = g_SspiW->DecryptMessage(phContext, pMessage, MessageSeqNo, pfQOP);
1053 WLog_Print(g_Log, WLOG_DEBUG,
"DecryptMessage: %s (0x%08" PRIX32
")",
1054 GetSecurityStatusString(status), status);
1058 SECURITY_STATUS SEC_ENTRY sspi_EncryptMessage(
PCtxtHandle phContext, ULONG fQOP,
1061 SECURITY_STATUS status = 0;
1062 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
1064 if (!(g_SspiW && g_SspiW->EncryptMessage))
1066 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
1068 return SEC_E_UNSUPPORTED_FUNCTION;
1071 status = g_SspiW->EncryptMessage(phContext, fQOP, pMessage, MessageSeqNo);
1072 WLog_Print(g_Log, WLOG_DEBUG,
"EncryptMessage: %s (0x%08" PRIX32
")",
1073 GetSecurityStatusString(status), status);
1077 SECURITY_STATUS SEC_ENTRY sspi_MakeSignature(
PCtxtHandle phContext, ULONG fQOP,
1080 SECURITY_STATUS status = 0;
1081 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
1083 if (!(g_SspiW && g_SspiW->MakeSignature))
1085 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
1087 return SEC_E_UNSUPPORTED_FUNCTION;
1090 status = g_SspiW->MakeSignature(phContext, fQOP, pMessage, MessageSeqNo);
1091 WLog_Print(g_Log, WLOG_DEBUG,
"MakeSignature: %s (0x%08" PRIX32
")",
1092 GetSecurityStatusString(status), status);
1097 ULONG MessageSeqNo, PULONG pfQOP)
1099 SECURITY_STATUS status = 0;
1100 InitOnceExecuteOnce(&g_Initialized, InitializeSspiModuleInt, NULL, NULL);
1102 if (!(g_SspiW && g_SspiW->VerifySignature))
1104 WLog_Print(g_Log, WLOG_WARN,
"Security module does not provide an implementation");
1106 return SEC_E_UNSUPPORTED_FUNCTION;
1109 status = g_SspiW->VerifySignature(phContext, pMessage, MessageSeqNo, pfQOP);
1110 WLog_Print(g_Log, WLOG_DEBUG,
"VerifySignature: %s (0x%08" PRIX32
")",
1111 GetSecurityStatusString(status), status);
1115 WINPR_PRAGMA_DIAG_POP
1117 void sspi_FreeAuthIdentity(SEC_WINNT_AUTH_IDENTITY* identity)
1121 free(identity->User);
1122 identity->UserLength = (UINT32)0;
1123 identity->User = NULL;
1125 free(identity->Domain);
1126 identity->DomainLength = (UINT32)0;
1127 identity->Domain = NULL;
1129 if (identity->PasswordLength > 0)
1130 memset(identity->Password, 0, identity->PasswordLength);
1131 free(identity->Password);
1132 identity->Password = NULL;
1133 identity->PasswordLength = (UINT32)0;