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.

226 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. init.cxx
  5. Abstract:
  6. Provider initialization
  7. Author:
  8. Cliff Van Dyke (cliffv) 12-Dec-2001
  9. --*/
  10. #include "pch.hxx"
  11. DWORD
  12. WINAPI
  13. AzPersistProviderInitialize(
  14. IN PAZPE_AZROLES_INFO AzrolesInfo,
  15. OUT PAZPE_PROVIDER_INFO *ProviderInfo
  16. )
  17. /*++
  18. Routine Description
  19. Routine to initialize the provider
  20. Memory allocator
  21. Arguments
  22. Size - Size (in bytes) to allocate
  23. Return Value
  24. Returns a pointer to the allocated memory.
  25. NULL - Not enough memory
  26. --*/
  27. {
  28. return XmlProviderInitialize( AzrolesInfo, ProviderInfo );
  29. }
  30. #ifdef AZROLESDBG
  31. BOOL LogFileCritSectInitialized = FALSE;
  32. DWORD
  33. myatolx(
  34. char const *psz)
  35. {
  36. DWORD dw = 0;
  37. while (isxdigit(*psz))
  38. {
  39. char ch = *psz++;
  40. if (isdigit(ch))
  41. {
  42. ch -= '0';
  43. }
  44. else if (isupper(ch))
  45. {
  46. ch += 10 - 'A';
  47. }
  48. else
  49. {
  50. ch += 10 - 'a';
  51. }
  52. dw = (dw << 4) | ch;
  53. }
  54. return(dw);
  55. }
  56. #endif //AZROLESDBG
  57. BOOL
  58. AzDllUnInitialize(VOID)
  59. /*++
  60. Routine Description
  61. This uninitializes global events and variables for the DLL.
  62. Arguments
  63. none
  64. Return Value
  65. Boolean: TRUE on success, FALSE on fail.
  66. --*/
  67. {
  68. BOOL RetVal = TRUE;
  69. //
  70. // Don't call back on thread start/stop
  71. //
  72. // Handle detaching from a process.
  73. //
  74. #ifdef AZROLESDBG
  75. //
  76. // Done with debugging
  77. //
  78. if ( LogFileCritSectInitialized ) {
  79. SafeDeleteCriticalSection ( &AzGlLogFileCritSect );
  80. LogFileCritSectInitialized = FALSE;
  81. }
  82. #endif // AZROLESDBG
  83. return RetVal;
  84. }
  85. BOOL
  86. AzDllInitialize(VOID)
  87. /*++
  88. Routine Description
  89. This initializes global events and variables for the DLL.
  90. Arguments
  91. none
  92. Return Value
  93. Boolean: TRUE on success, FALSE on fail.
  94. --*/
  95. {
  96. #ifdef DBG
  97. NTSTATUS Status;
  98. #endif // DBG
  99. BOOL RetVal = TRUE;
  100. //
  101. // Initialize global constants
  102. //
  103. RtlZeroMemory( &AzGlZeroGuid, sizeof(AzGlZeroGuid) );
  104. //
  105. // Initialize the safe lock subsystem
  106. #ifdef DBG
  107. Status = SafeLockInit();
  108. if ( !NT_SUCCESS( Status )) {
  109. RetVal = FALSE;
  110. KdPrint(("AzRoles.dll: SafeLockInit failed: 0x%lx\n",
  111. Status ));
  112. goto Cleanup;
  113. }
  114. #endif
  115. #ifdef AZROLESDBG
  116. //
  117. // Initialize debugging
  118. //
  119. #define SAFE_LOGFILE 1
  120. Status = SafeInitializeCriticalSection( &AzGlLogFileCritSect, SAFE_LOGFILE );
  121. if ( !NT_SUCCESS( Status )) {
  122. RetVal = FALSE;
  123. KdPrint(("AzRoles.dll: InitializCriticalSection (AzGlLogFileCritSect) failed: 0x%lx\n",
  124. Status ));
  125. goto Cleanup;
  126. }
  127. LogFileCritSectInitialized = TRUE;
  128. //
  129. // Get debug flag from environment variable AZDBG
  130. //
  131. char const *pszAzDbg;
  132. pszAzDbg = getenv("AZDBG");
  133. if (NULL != pszAzDbg)
  134. {
  135. AzGlDbFlag |= myatolx(pszAzDbg);
  136. }
  137. #endif // AZROLESDBG
  138. Cleanup:
  139. if ( !RetVal ) {
  140. AzDllUnInitialize();
  141. }
  142. return RetVal;
  143. }
  144. /////////////////////////////////////////////////////////////////////////////
  145. // DLL Entry Point
  146. extern "C"
  147. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  148. {
  149. BOOL ret = TRUE;
  150. if (dwReason == DLL_PROCESS_ATTACH)
  151. {
  152. DisableThreadLibraryCalls(hInstance);
  153. ret = AzDllInitialize();
  154. }
  155. else if (dwReason == DLL_PROCESS_DETACH)
  156. {
  157. ret = AzDllUnInitialize();
  158. }
  159. return ret; // ok
  160. }