Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
4.0 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996
  5. //
  6. // File: globals.cxx
  7. //
  8. // Contents:
  9. //
  10. // History:
  11. //----------------------------------------------------------------------------
  12. #include "ldap.hxx"
  13. #pragma hdrstop
  14. TCHAR *szProviderName = TEXT("LDAP");
  15. TCHAR *szLDAPNamespaceName = TEXT("LDAP");
  16. TCHAR *szGCNamespaceName = TEXT("GC");
  17. //
  18. // Support routines for dynamically loading functions.
  19. //
  20. BOOL g_fDllsLoaded = FALSE;
  21. extern HANDLE g_hDllSecur32 = NULL;
  22. //
  23. // Loads all the dynamic libs we need.
  24. //
  25. void BindToDlls()
  26. {
  27. DWORD dwErr = 0;
  28. if (g_fDllsLoaded) {
  29. return;
  30. }
  31. ENTER_SERVERLIST_CRITICAL_SECTION();
  32. if (g_fDllsLoaded) {
  33. LEAVE_SERVERLIST_CRITICAL_SECTION();
  34. return;
  35. }
  36. g_hDllSecur32 = LoadLibrary(L"SECUR32.DLL");
  37. g_fDllsLoaded = TRUE;
  38. LEAVE_SERVERLIST_CRITICAL_SECTION();
  39. return;
  40. }
  41. //
  42. // Loads the appropriate secur32 fn.
  43. //
  44. PVOID LoadSecur32Function(CHAR *function)
  45. {
  46. if (!g_fDllsLoaded) {
  47. BindToDlls();
  48. }
  49. if (g_hDllSecur32) {
  50. return((PVOID*) GetProcAddress((HMODULE) g_hDllSecur32, function));
  51. }
  52. return NULL;
  53. }
  54. //
  55. // QueryContextAttributesWrapper.
  56. //
  57. SECURITY_STATUS
  58. AcquireCredentialsHandleWrapper(
  59. #if ISSP_MODE == 0 // For Kernel mode
  60. PSECURITY_STRING pPrincipal,
  61. PSECURITY_STRING pPackage,
  62. #else
  63. SEC_WCHAR SEC_FAR * pszPrincipal, // Name of principal
  64. SEC_WCHAR SEC_FAR * pszPackage, // Name of package
  65. #endif
  66. unsigned long fCredentialUse, // Flags indicating use
  67. void SEC_FAR * pvLogonId, // Pointer to logon ID
  68. void SEC_FAR * pAuthData, // Package specific data
  69. SEC_GET_KEY_FN pGetKeyFn, // Pointer to GetKey() func
  70. void SEC_FAR * pvGetKeyArgument, // Value to pass to GetKey()
  71. PCredHandle phCredential, // (out) Cred Handle
  72. PTimeStamp ptsExpiry // (out) Lifetime (optional)
  73. )
  74. {
  75. static PF_AcquireCredentialsHandleW pfAcquireCred = NULL;
  76. static BOOL f_LoadAttempted = FALSE;
  77. //
  78. // Load the fn and set the variables accordingly.
  79. //
  80. if (!f_LoadAttempted && pfAcquireCred == NULL) {
  81. pfAcquireCred = (PF_AcquireCredentialsHandleW)
  82. LoadSecur32Function(ACQUIRECREDENTIALSHANDLE_API);
  83. f_LoadAttempted = TRUE;
  84. }
  85. if (pfAcquireCred != NULL) {
  86. return ((*pfAcquireCred)(
  87. #if ISSP_MODE == 0 // For Kernel mode
  88. pPrincipal,
  89. pPackage,
  90. #else
  91. pszPrincipal, // Name of principal
  92. pszPackage, // Name of package
  93. #endif
  94. fCredentialUse, // Flags indicating use
  95. pvLogonId, // Pointer to logon ID
  96. pAuthData, // Package specific data
  97. pGetKeyFn, // Pointer to GetKey() func
  98. pvGetKeyArgument, // Value to pass to GetKey()
  99. phCredential, // (out) Cred Handle
  100. ptsExpiry // (out) Lifetime (optional)
  101. )
  102. );
  103. }
  104. else {
  105. return (ERROR_GEN_FAILURE);
  106. }
  107. }
  108. SECURITY_STATUS
  109. FreeCredentialsHandleWrapper(
  110. PCredHandle phCredential // Handle to free
  111. )
  112. {
  113. static PF_FreeCredentialsHandle pfFreeCredHandle = NULL;
  114. static BOOL f_LoadAttempted = FALSE;
  115. //
  116. // Load the fn and set the variables accordingly.
  117. //
  118. if (!f_LoadAttempted && pfFreeCredHandle == NULL) {
  119. pfFreeCredHandle = (PF_FreeCredentialsHandle)
  120. LoadSecur32Function(FREECREDENTIALSHANDLE_API);
  121. f_LoadAttempted = TRUE;
  122. }
  123. if (pfFreeCredHandle != NULL) {
  124. return ((*pfFreeCredHandle)(
  125. phCredential
  126. )
  127. );
  128. }
  129. else {
  130. return (ERROR_GEN_FAILURE);
  131. }
  132. }