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.

297 lines
6.7 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. init.c
  5. Abstract:
  6. AdvApi32.dll initialization
  7. Author:
  8. Robert Reichel (RobertRe) 8-12-92
  9. Revision History:
  10. --*/
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windows.h>
  15. #include <marta.h>
  16. #include <winsvcp.h>
  17. #include "advapi.h"
  18. #include "tsappcmp.h"
  19. extern CRITICAL_SECTION FeClientLoadCritical;
  20. extern CRITICAL_SECTION SddlSidLookupCritical;
  21. extern CRITICAL_SECTION MSChapChangePassword;
  22. extern BOOL gbDllHasThreadState;
  23. //
  24. // Local prototypes for functions that seem to have no prototypes.
  25. //
  26. BOOLEAN
  27. RegInitialize (
  28. IN HANDLE Handle,
  29. IN DWORD Reason,
  30. IN PVOID Reserved
  31. );
  32. BOOLEAN
  33. Sys003Initialize (
  34. IN HANDLE Handle,
  35. IN DWORD Reason,
  36. IN PVOID Reserved
  37. );
  38. BOOLEAN
  39. AppmgmtInitialize (
  40. IN HANDLE Handle,
  41. IN DWORD Reason,
  42. IN PVOID Reserved
  43. );
  44. BOOLEAN
  45. WmiDllInitialize (
  46. IN HANDLE Handle,
  47. IN DWORD Reason,
  48. IN PVOID Reserved
  49. );
  50. BOOLEAN
  51. CodeAuthzInitialize (
  52. IN HANDLE Handle,
  53. IN DWORD Reason,
  54. IN PVOID Reserved
  55. );
  56. BOOLEAN AdvApi_InitializeTermsrvFpns( BOOLEAN *pIsInRelaxedSecurityMode , DWORD *pdwCompatFlags ); // app server has two modes for app compat
  57. #define ADVAPI_PROCESS_ATTACH ( 1 << DLL_PROCESS_ATTACH )
  58. #define ADVAPI_PROCESS_DETACH ( 1 << DLL_PROCESS_DETACH )
  59. #define ADVAPI_THREAD_ATTACH ( 1 << DLL_THREAD_ATTACH )
  60. #define ADVAPI_THREAD_DETACH ( 1 << DLL_THREAD_DETACH )
  61. typedef struct _ADVAPI_INIT_ROUTINE {
  62. PDLL_INIT_ROUTINE InitRoutine ;
  63. ULONG Flags ;
  64. } ADVAPI_INIT_ROUTINE, * PADVAPI_INIT_ROUTINE ;
  65. //
  66. // Place all ADVAPI32 initialization hooks in this
  67. // table.
  68. //
  69. ADVAPI_INIT_ROUTINE AdvapiInitRoutines[] = {
  70. { (PDLL_INIT_ROUTINE) RegInitialize,
  71. ADVAPI_PROCESS_ATTACH |
  72. ADVAPI_PROCESS_DETACH |
  73. ADVAPI_THREAD_DETACH },
  74. { (PDLL_INIT_ROUTINE) Sys003Initialize,
  75. ADVAPI_PROCESS_ATTACH |
  76. ADVAPI_PROCESS_DETACH },
  77. { (PDLL_INIT_ROUTINE) MartaDllInitialize,
  78. ADVAPI_PROCESS_ATTACH |
  79. ADVAPI_PROCESS_DETACH },
  80. { (PDLL_INIT_ROUTINE) AppmgmtInitialize,
  81. ADVAPI_PROCESS_ATTACH |
  82. ADVAPI_PROCESS_DETACH },
  83. { (PDLL_INIT_ROUTINE) WmiDllInitialize,
  84. ADVAPI_PROCESS_ATTACH |
  85. ADVAPI_PROCESS_DETACH },
  86. { (PDLL_INIT_ROUTINE) CodeAuthzInitialize,
  87. ADVAPI_PROCESS_ATTACH |
  88. ADVAPI_PROCESS_DETACH }
  89. };
  90. //
  91. // Place all critical sections used in advapi32 here:
  92. //
  93. PRTL_CRITICAL_SECTION AdvapiCriticalSections[] = {
  94. &FeClientLoadCritical,
  95. &SddlSidLookupCritical,
  96. &Logon32Lock,
  97. &MSChapChangePassword
  98. };
  99. BOOLEAN
  100. DllInitialize(
  101. IN PVOID hmod,
  102. IN ULONG Reason,
  103. IN PCONTEXT Context
  104. )
  105. {
  106. BOOLEAN Result = TRUE;
  107. int i ;
  108. NTSTATUS Status ;
  109. ULONG ReasonMask ;
  110. //
  111. // First, handle all the critical sections
  112. //
  113. if ( Reason == DLL_PROCESS_ATTACH ) {
  114. //
  115. // Note -- we no longer call DisableThreadLibraryCalls
  116. // because we need these so win32 local registry
  117. // can clean up its state
  118. //
  119. Result = TRUE ;
  120. for ( i = 0 ;
  121. i < sizeof( AdvapiCriticalSections ) / sizeof ( PRTL_CRITICAL_SECTION ) ;
  122. i++ )
  123. {
  124. Status = RtlInitializeCriticalSection( AdvapiCriticalSections[ i ] );
  125. if ( !NT_SUCCESS( Status ) )
  126. {
  127. #if DBG
  128. DbgPrint("ADVAPI: Failed to initialize critical section %p\n",
  129. AdvapiCriticalSections[ i ] );
  130. #endif
  131. Result = FALSE ;
  132. break;
  133. }
  134. }
  135. if ( !Result )
  136. {
  137. i-- ;
  138. while ( i )
  139. {
  140. RtlDeleteCriticalSection( AdvapiCriticalSections[ i ] );
  141. i-- ;
  142. }
  143. return FALSE ;
  144. }
  145. if (IsTerminalServer()) {
  146. BOOLEAN isInRelaxedSecurityMode = FALSE ; // app server is in standard or relaxed security mode
  147. DWORD dwCompatFlags=0;
  148. if( AdvApi_InitializeTermsrvFpns( & isInRelaxedSecurityMode , &dwCompatFlags) )
  149. {
  150. if ( isInRelaxedSecurityMode )
  151. {
  152. // If TS reg key redirection is enabled, then get our special reg key extention flag for this app
  153. // called "gdwRegistryExtensionFlags" which is used in screg\winreg\server\ files.
  154. // This flag control HKCR per user virtualization and HKLM\SW\Classes per user virtualization and
  155. // also modification to access mask.
  156. //
  157. // Basically, only non-system, non-ts-aware apps on the app server will have this enabled.
  158. // Also, we only provide this feature in the relaxed security mode.
  159. //
  160. // Future work, add DISABLE mask support on per app basis, so that we can turn off this
  161. // reg extenion feature on per app basis (just in case).
  162. //
  163. GetRegistryExtensionFlags( dwCompatFlags );
  164. }
  165. }
  166. }
  167. }
  168. //
  169. // Now, run the subcomponents initialization routines
  170. //
  171. ReasonMask = 1 << Reason ;
  172. for ( i = 0 ;
  173. i < sizeof( AdvapiInitRoutines ) / sizeof( ADVAPI_INIT_ROUTINE ) ;
  174. i++ )
  175. {
  176. if ( ( AdvapiInitRoutines[i].Flags & ReasonMask ) != 0 )
  177. {
  178. Result = AdvapiInitRoutines[i].InitRoutine( hmod, Reason, Context );
  179. if ( !Result )
  180. {
  181. #if DBG
  182. DbgPrint( "ADVAPI: sub init routine %p failed\n",
  183. AdvapiInitRoutines[ i ].InitRoutine );
  184. #endif
  185. break;
  186. }
  187. }
  188. }
  189. if ( !Result )
  190. {
  191. if ( Reason == DLL_PROCESS_ATTACH )
  192. {
  193. i-- ;
  194. while ( i )
  195. {
  196. RtlDeleteCriticalSection( AdvapiCriticalSections[ i ] );
  197. i-- ;
  198. }
  199. }
  200. return Result ;
  201. }
  202. //
  203. // If this is the process detach, clean up all the critical sections
  204. // after the hooks are run.
  205. //
  206. if ( Reason == DLL_PROCESS_DETACH )
  207. {
  208. for ( i = 0 ;
  209. i < sizeof( AdvapiCriticalSections ) / sizeof ( PRTL_CRITICAL_SECTION ) ;
  210. i++ )
  211. {
  212. Status = RtlDeleteCriticalSection( AdvapiCriticalSections[ i ] );
  213. if ( !NT_SUCCESS( Status ) )
  214. {
  215. Result = FALSE ;
  216. break;
  217. }
  218. }
  219. }
  220. #if DBG
  221. SccInit(Reason);
  222. #endif // DBG
  223. return( Result );
  224. }