Leaked source code of windows server 2003
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.

198 lines
5.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. // load library helper
  23. HMODULE LoadLibraryHelper(
  24. LPTSTR pszFileName
  25. )
  26. {
  27. const DWORD iSize = GetSystemDirectory(NULL, 0);
  28. TCHAR* buffer = NULL;
  29. DWORD dwTemp = 0;
  30. HMODULE handle = NULL;
  31. if(iSize == 0)
  32. {
  33. goto error;
  34. }
  35. buffer = new TCHAR[iSize + _tcslen(__TEXT("\\")) + _tcslen(pszFileName)]; // iSize includes the NULL terminiator
  36. if(!buffer)
  37. {
  38. goto error;
  39. }
  40. dwTemp = GetSystemDirectory(buffer, iSize);
  41. if(dwTemp == 0)
  42. {
  43. goto error;
  44. }
  45. _tcscat(buffer, __TEXT("\\"));
  46. _tcscat(buffer, pszFileName);
  47. handle = LoadLibrary(buffer);
  48. error:
  49. if(buffer)
  50. {
  51. delete [] buffer;
  52. buffer = NULL;
  53. }
  54. return handle;
  55. }
  56. //
  57. // Loads all the dynamic libs we need.
  58. //
  59. void BindToDlls()
  60. {
  61. DWORD dwErr = 0;
  62. if (g_fDllsLoaded) {
  63. return;
  64. }
  65. ENTER_SERVERLIST_CRITICAL_SECTION();
  66. if (g_fDllsLoaded) {
  67. LEAVE_SERVERLIST_CRITICAL_SECTION();
  68. return;
  69. }
  70. g_hDllSecur32 = LoadLibraryHelper(L"SECUR32.DLL");
  71. g_fDllsLoaded = TRUE;
  72. LEAVE_SERVERLIST_CRITICAL_SECTION();
  73. return;
  74. }
  75. //
  76. // Loads the appropriate secur32 fn.
  77. //
  78. PVOID LoadSecur32Function(CHAR *function)
  79. {
  80. if (!g_fDllsLoaded) {
  81. BindToDlls();
  82. }
  83. if (g_hDllSecur32) {
  84. return((PVOID*) GetProcAddress((HMODULE) g_hDllSecur32, function));
  85. }
  86. return NULL;
  87. }
  88. //
  89. // QueryContextAttributesWrapper.
  90. //
  91. SECURITY_STATUS
  92. AcquireCredentialsHandleWrapper(
  93. #if ISSP_MODE == 0 // For Kernel mode
  94. PSECURITY_STRING pPrincipal,
  95. PSECURITY_STRING pPackage,
  96. #else
  97. SEC_WCHAR SEC_FAR * pszPrincipal, // Name of principal
  98. SEC_WCHAR SEC_FAR * pszPackage, // Name of package
  99. #endif
  100. unsigned long fCredentialUse, // Flags indicating use
  101. void SEC_FAR * pvLogonId, // Pointer to logon ID
  102. void SEC_FAR * pAuthData, // Package specific data
  103. SEC_GET_KEY_FN pGetKeyFn, // Pointer to GetKey() func
  104. void SEC_FAR * pvGetKeyArgument, // Value to pass to GetKey()
  105. PCredHandle phCredential, // (out) Cred Handle
  106. PTimeStamp ptsExpiry // (out) Lifetime (optional)
  107. )
  108. {
  109. static PF_AcquireCredentialsHandleW pfAcquireCred = NULL;
  110. static BOOL f_LoadAttempted = FALSE;
  111. //
  112. // Load the fn and set the variables accordingly.
  113. //
  114. if (!f_LoadAttempted && pfAcquireCred == NULL) {
  115. pfAcquireCred = (PF_AcquireCredentialsHandleW)
  116. LoadSecur32Function(ACQUIRECREDENTIALSHANDLE_API);
  117. f_LoadAttempted = TRUE;
  118. }
  119. if (pfAcquireCred != NULL) {
  120. return ((*pfAcquireCred)(
  121. #if ISSP_MODE == 0 // For Kernel mode
  122. pPrincipal,
  123. pPackage,
  124. #else
  125. pszPrincipal, // Name of principal
  126. pszPackage, // Name of package
  127. #endif
  128. fCredentialUse, // Flags indicating use
  129. pvLogonId, // Pointer to logon ID
  130. pAuthData, // Package specific data
  131. pGetKeyFn, // Pointer to GetKey() func
  132. pvGetKeyArgument, // Value to pass to GetKey()
  133. phCredential, // (out) Cred Handle
  134. ptsExpiry // (out) Lifetime (optional)
  135. )
  136. );
  137. }
  138. else {
  139. return (ERROR_GEN_FAILURE);
  140. }
  141. }
  142. SECURITY_STATUS
  143. FreeCredentialsHandleWrapper(
  144. PCredHandle phCredential // Handle to free
  145. )
  146. {
  147. static PF_FreeCredentialsHandle pfFreeCredHandle = NULL;
  148. static BOOL f_LoadAttempted = FALSE;
  149. //
  150. // Load the fn and set the variables accordingly.
  151. //
  152. if (!f_LoadAttempted && pfFreeCredHandle == NULL) {
  153. pfFreeCredHandle = (PF_FreeCredentialsHandle)
  154. LoadSecur32Function(FREECREDENTIALSHANDLE_API);
  155. f_LoadAttempted = TRUE;
  156. }
  157. if (pfFreeCredHandle != NULL) {
  158. return ((*pfFreeCredHandle)(
  159. phCredential
  160. )
  161. );
  162. }
  163. else {
  164. return (ERROR_GEN_FAILURE);
  165. }
  166. }