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.

313 lines
6.3 KiB

  1. #pragma once
  2. #include "Parameter.h"
  3. #include <MigrationMutex.h>
  4. #include "MonitorThread.h"
  5. //---------------------------------------------------------------------------
  6. // Migration Class
  7. //---------------------------------------------------------------------------
  8. namespace
  9. {
  10. inline void __stdcall GetString(UINT uId, LPTSTR pszBuffer, int cchBuffer)
  11. {
  12. if (pszBuffer)
  13. {
  14. if (LoadString(GetModuleHandle(NULL), uId, pszBuffer, cchBuffer) == 0)
  15. {
  16. pszBuffer[0] = _T('\0');
  17. }
  18. }
  19. }
  20. }
  21. class CMigration
  22. {
  23. public:
  24. CMigration(CParameterMap& mapParams) :
  25. m_spMigration(__uuidof(Migration))
  26. {
  27. Initialize(mapParams);
  28. }
  29. IUserMigrationPtr CreateUserMigration()
  30. {
  31. return m_spMigration->CreateUserMigration();
  32. }
  33. IGroupMigrationPtr CreateGroupMigration()
  34. {
  35. return m_spMigration->CreateGroupMigration();
  36. }
  37. IComputerMigrationPtr CreateComputerMigration()
  38. {
  39. return m_spMigration->CreateComputerMigration();
  40. }
  41. ISecurityTranslationPtr CreateSecurityTranslation()
  42. {
  43. return m_spMigration->CreateSecurityTranslation();
  44. }
  45. IServiceAccountEnumerationPtr CreateServiceAccountEnumeration()
  46. {
  47. return m_spMigration->CreateServiceAccountEnumeration();
  48. }
  49. IReportGenerationPtr CreateReportGeneration()
  50. {
  51. return m_spMigration->CreateReportGeneration();
  52. }
  53. protected:
  54. CMigration() {}
  55. void Initialize(CParameterMap& mapParams);
  56. protected:
  57. IMigrationPtr m_spMigration;
  58. };
  59. class CCmdMigrationBase
  60. {
  61. public:
  62. bool MutexWait(DWORD dwTimeOut = INFINITE)
  63. {
  64. return m_Mutex.ObtainOwnership(dwTimeOut);
  65. }
  66. void MutexRelease()
  67. {
  68. m_Mutex.ReleaseOwnership();
  69. }
  70. void StartMonitoring()
  71. {
  72. // check if the other admt process is already running (by trying to obtain the mutex), if true, print out
  73. // an error message. This should handle most of the cases
  74. bool bStatus;
  75. _TCHAR szBuffer[512] = _T("");
  76. DWORD dwCharsWritten;
  77. HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  78. bStatus = MutexWait(1);
  79. if(!bStatus)
  80. {
  81. GetString(IDS_E_PROCESS_RUNNING, szBuffer, countof(szBuffer));
  82. WriteConsole(hStdOut, szBuffer, _tcslen(szBuffer), &dwCharsWritten, NULL);
  83. MutexWait();
  84. }
  85. // start the monitoring thread
  86. m_Monitor.Start();
  87. }
  88. void StopMonitoring()
  89. {
  90. m_Monitor.Stop();
  91. MutexRelease();
  92. }
  93. protected:
  94. CCmdMigrationBase() :
  95. m_Mutex(ADMT_MUTEX)
  96. {
  97. }
  98. ~CCmdMigrationBase() {}
  99. protected:
  100. CMigrationMutex m_Mutex;
  101. CMonitorThread m_Monitor;
  102. };
  103. //---------------------------------------------------------------------------
  104. // User Migration Class
  105. //---------------------------------------------------------------------------
  106. class CUserMigration :
  107. public CCmdMigrationBase
  108. {
  109. public:
  110. CUserMigration(CMigration& rMigration, CParameterMap& mapParams) :
  111. m_spUser(rMigration.CreateUserMigration())
  112. {
  113. Initialize(mapParams);
  114. }
  115. protected:
  116. CUserMigration() {}
  117. void Initialize(CParameterMap& mapParams);
  118. protected:
  119. IUserMigrationPtr m_spUser;
  120. };
  121. //---------------------------------------------------------------------------
  122. // Group Migration Class
  123. //---------------------------------------------------------------------------
  124. class CGroupMigration :
  125. public CCmdMigrationBase
  126. {
  127. public:
  128. CGroupMigration(CMigration& rMigration, CParameterMap& mapParams) :
  129. m_spGroup(rMigration.CreateGroupMigration())
  130. {
  131. Initialize(mapParams);
  132. }
  133. protected:
  134. CGroupMigration() {}
  135. void Initialize(CParameterMap& mapParams);
  136. protected:
  137. IGroupMigrationPtr m_spGroup;
  138. };
  139. //---------------------------------------------------------------------------
  140. // Computer Migration Class
  141. //---------------------------------------------------------------------------
  142. class CComputerMigration :
  143. public CCmdMigrationBase
  144. {
  145. public:
  146. CComputerMigration(CMigration& rMigration, CParameterMap& mapParams) :
  147. m_spComputer(rMigration.CreateComputerMigration())
  148. {
  149. Initialize(mapParams);
  150. }
  151. protected:
  152. CComputerMigration() {}
  153. void Initialize(CParameterMap& mapParams);
  154. protected:
  155. IComputerMigrationPtr m_spComputer;
  156. };
  157. //---------------------------------------------------------------------------
  158. // Security Translation Class
  159. //---------------------------------------------------------------------------
  160. class CSecurityTranslation :
  161. public CCmdMigrationBase
  162. {
  163. public:
  164. CSecurityTranslation(CMigration& rMigration, CParameterMap& mapParams) :
  165. m_spSecurity(rMigration.CreateSecurityTranslation())
  166. {
  167. Initialize(mapParams);
  168. }
  169. protected:
  170. CSecurityTranslation() {}
  171. void Initialize(CParameterMap& mapParams);
  172. protected:
  173. ISecurityTranslationPtr m_spSecurity;
  174. };
  175. //---------------------------------------------------------------------------
  176. // Service Enumeration Class
  177. //---------------------------------------------------------------------------
  178. class CServiceEnumeration :
  179. public CCmdMigrationBase
  180. {
  181. public:
  182. CServiceEnumeration(CMigration& rMigration, CParameterMap& mapParams) :
  183. m_spService(rMigration.CreateServiceAccountEnumeration())
  184. {
  185. Initialize(mapParams);
  186. }
  187. protected:
  188. CServiceEnumeration() {}
  189. void Initialize(CParameterMap& mapParams);
  190. protected:
  191. IServiceAccountEnumerationPtr m_spService;
  192. };
  193. //---------------------------------------------------------------------------
  194. // Report Generation Class
  195. //---------------------------------------------------------------------------
  196. class CReportGeneration :
  197. public CCmdMigrationBase
  198. {
  199. public:
  200. CReportGeneration(CMigration& rMigration, CParameterMap& mapParams) :
  201. m_spReport(rMigration.CreateReportGeneration())
  202. {
  203. Initialize(mapParams);
  204. }
  205. protected:
  206. CReportGeneration() {}
  207. void Initialize(CParameterMap& mapParams);
  208. protected:
  209. IReportGenerationPtr m_spReport;
  210. };