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.

314 lines
8.0 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. setutl.c
  5. Abstract:
  6. Miscellaneous helper functions
  7. Author:
  8. Mac McLain (MacM) Feb 10, 1997
  9. Environment:
  10. User Mode
  11. Revision History:
  12. --*/
  13. #include <setpch.h>
  14. #include <dssetp.h>
  15. #include <lsarpc.h>
  16. #include <samrpc.h>
  17. #include <samisrv.h>
  18. #include <db.h>
  19. #include <confname.h>
  20. #define NTDSSET_ALLOCATE // Cause extern allocations to happen here
  21. #include "loadfn.h"
  22. #include <ntdsa.h>
  23. #include <dsconfig.h>
  24. #include <attids.h>
  25. #include <dsp.h>
  26. #include <lsaisrv.h>
  27. #include <malloc.h>
  28. #include <dsgetdc.h>
  29. #include <lmcons.h>
  30. #include <lmaccess.h>
  31. #include <lmapibuf.h>
  32. #include <lmerr.h>
  33. #include <netsetp.h>
  34. #include <winsock2.h>
  35. #include <nspapi.h>
  36. #include <dsgetdcp.h>
  37. #include <lmremutl.h>
  38. #include <spmgr.h> // For SetupPhase definition
  39. #include "secure.h"
  40. //
  41. // Global data
  42. //
  43. HANDLE NtDsSetupDllHandle = NULL;
  44. HANDLE SceSetupDllHandle = NULL;
  45. HANDLE NtfrsApiDllHandle = NULL;
  46. HANDLE W32TimeDllHandle = NULL;
  47. #define DSROLE_LOAD_FPTR( status, handle, fbase ) \
  48. if ( status == ERROR_SUCCESS ) { \
  49. \
  50. Dsr##fbase = ( DSR_##fbase)GetProcAddress( handle, #fbase ); \
  51. \
  52. if ( Dsr##fbase == NULL ) { \
  53. \
  54. status = ERROR_PROC_NOT_FOUND; \
  55. } \
  56. }
  57. DWORD
  58. DsRolepLoadSetupFunctions(
  59. VOID
  60. )
  61. /*++
  62. Routine Description:
  63. This function will load all of the function pointers as utilized from Ntdsetup.dll
  64. N.B. This routine must be called when the global op handle lock is held.
  65. Arguments:
  66. VOID
  67. Returns:
  68. ERROR_SUCCESS - Success
  69. --*/
  70. {
  71. DWORD Win32Err = ERROR_SUCCESS;
  72. HANDLE DllHandle = NULL;
  73. ASSERT( DsRolepCurrentThreadOwnsLock() );
  74. if ( NtDsSetupDllHandle == NULL ) {
  75. DllHandle = LoadLibraryA( "Ntdsetup" );
  76. if ( DllHandle == NULL ) {
  77. DsRolepLogPrint(( DEB_ERROR, "Failed to load NTDSETUP.DLL\n" ));
  78. Win32Err = ERROR_MOD_NOT_FOUND;
  79. } else {
  80. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtdsInstall );
  81. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtdsInstallShutdown );
  82. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtdsInstallUndo );
  83. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtdsGetDefaultDnsName );
  84. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtdsPrepareForDemotion );
  85. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtdsPrepareForDemotionUndo );
  86. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtdsDemote );
  87. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtdsSetReplicaMachineAccount );
  88. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtdsInstallCancel );
  89. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtdsInstallReplicateFull );
  90. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtdsFreeDnsRRInfo );
  91. NtDsSetupDllHandle = DllHandle;
  92. }
  93. //
  94. // Load the ones for secsetup
  95. //
  96. if ( Win32Err == ERROR_SUCCESS ) {
  97. DllHandle = LoadLibraryA( "scecli" );
  98. if ( DllHandle == NULL ) {
  99. DsRolepLogPrint(( DEB_ERROR, "Failed to load SCECLI.DLL\n" ));
  100. Win32Err = ERROR_MOD_NOT_FOUND;
  101. } else {
  102. DSROLE_LOAD_FPTR( Win32Err, DllHandle, SceDcPromoteSecurityEx );
  103. DSROLE_LOAD_FPTR( Win32Err, DllHandle, SceDcPromoCreateGPOsInSysvolEx );
  104. DSROLE_LOAD_FPTR( Win32Err, DllHandle, SceSetupSystemByInfName );
  105. SceSetupDllHandle = DllHandle;
  106. }
  107. }
  108. //
  109. // Load the ones for ntfrsapi
  110. //
  111. if ( Win32Err == ERROR_SUCCESS ) {
  112. DllHandle = LoadLibraryA( "ntfrsapi" );
  113. if ( DllHandle == NULL ) {
  114. DsRolepLogPrint(( DEB_ERROR, "Failed to load NTFRSAPI.DLL\n" ));
  115. Win32Err = ERROR_MOD_NOT_FOUND;
  116. } else {
  117. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtFrsApi_PrepareForPromotionW );
  118. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtFrsApi_PrepareForDemotionW );
  119. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtFrsApi_PrepareForDemotionUsingCredW );
  120. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtFrsApi_StartPromotionW );
  121. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtFrsApi_StartDemotionW );
  122. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtFrsApi_WaitForPromotionW );
  123. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtFrsApi_WaitForDemotionW );
  124. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtFrsApi_CommitPromotionW );
  125. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtFrsApi_CommitDemotionW );
  126. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtFrsApi_AbortPromotionW );
  127. DSROLE_LOAD_FPTR( Win32Err, DllHandle, NtFrsApi_AbortDemotionW );
  128. NtfrsApiDllHandle = DllHandle;
  129. }
  130. }
  131. if ( Win32Err == ERROR_SUCCESS ) {
  132. DllHandle = LoadLibraryA( "w32time" );
  133. if ( DllHandle == NULL ) {
  134. DsRolepLogPrint(( DEB_ERROR, "Failed to load W32TIME.DLL\n" ));
  135. Win32Err = ERROR_MOD_NOT_FOUND;
  136. } else {
  137. DSROLE_LOAD_FPTR( Win32Err, DllHandle, W32TimeDcPromo );
  138. W32TimeDllHandle = DllHandle;
  139. }
  140. }
  141. }
  142. if ( Win32Err != ERROR_SUCCESS ) {
  143. DsRolepUnloadSetupFunctions();
  144. }
  145. ASSERT( DsRolepCurrentThreadOwnsLock() );
  146. return( Win32Err );
  147. }
  148. VOID
  149. DsRolepUnloadSetupFunctions(
  150. VOID
  151. )
  152. /*++
  153. Routine Description:
  154. This function will unload the dll handles loaded by DsRolepLoadSetupFunctions
  155. N.B. This routine must be called when the global op handle lock is held.
  156. Arguments:
  157. VOID
  158. Returns:
  159. VOID
  160. --*/
  161. {
  162. DWORD Win32Err = ERROR_SUCCESS;
  163. ASSERT( DsRolepCurrentThreadOwnsLock() );
  164. if ( NtDsSetupDllHandle != NULL ) {
  165. FreeLibrary( NtDsSetupDllHandle );
  166. NtDsSetupDllHandle = NULL;
  167. }
  168. if ( SceSetupDllHandle != NULL ) {
  169. FreeLibrary( SceSetupDllHandle );
  170. SceSetupDllHandle = NULL;
  171. }
  172. if ( NtfrsApiDllHandle != NULL ) {
  173. FreeLibrary( NtfrsApiDllHandle );
  174. NtfrsApiDllHandle = NULL;
  175. }
  176. if ( W32TimeDllHandle != NULL ) {
  177. FreeLibrary( W32TimeDllHandle );
  178. W32TimeDllHandle = NULL;
  179. }
  180. DsRolepInitSetupFunctions();
  181. ASSERT( DsRolepCurrentThreadOwnsLock() );
  182. return;
  183. }
  184. VOID
  185. DsRolepInitSetupFunctions(
  186. VOID
  187. )
  188. /*++
  189. Routine Description:
  190. This function will initialize the setup function pointers to NULL
  191. Arguments:
  192. VOID
  193. Returns:
  194. VOID
  195. --*/
  196. {
  197. DsrNtdsInstall = NULL;
  198. DsrNtdsInstallShutdown = NULL;
  199. DsrNtdsInstallUndo = NULL;
  200. DsrNtdsGetDefaultDnsName = NULL;
  201. DsrNtdsPrepareForDemotion = NULL;
  202. DsrNtdsPrepareForDemotionUndo = NULL;
  203. DsrNtdsDemote = NULL;
  204. DsrNtdsSetReplicaMachineAccount = NULL;
  205. DsrNtdsInstallCancel = NULL;
  206. DsrNtdsFreeDnsRRInfo = NULL;
  207. DsrSceDcPromoteSecurityEx = NULL;
  208. DsrSceDcPromoCreateGPOsInSysvolEx = NULL;
  209. DsrNtFrsApi_PrepareForPromotionW = NULL;
  210. DsrNtFrsApi_PrepareForDemotionW = NULL;
  211. DsrNtFrsApi_StartPromotionW = NULL;
  212. DsrNtFrsApi_StartDemotionW = NULL;
  213. DsrNtFrsApi_WaitForPromotionW = NULL;
  214. DsrNtFrsApi_WaitForDemotionW = NULL;
  215. DsrNtFrsApi_CommitPromotionW = NULL;
  216. DsrNtFrsApi_CommitDemotionW = NULL;
  217. DsrNtFrsApi_AbortPromotionW = NULL;
  218. DsrNtFrsApi_AbortDemotionW = NULL;
  219. DsrW32TimeDcPromo = NULL;
  220. }