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.

295 lines
5.5 KiB

  1. #include "StdAfx.h"
  2. #include "ADMTScript.h"
  3. #include "ReportGeneration.h"
  4. #include "Error.h"
  5. #include "VarSetOptions.h"
  6. #include "VarSetReports.h"
  7. //---------------------------------------------------------------------------
  8. // Report Class
  9. //---------------------------------------------------------------------------
  10. CReportGeneration::CReportGeneration() :
  11. m_lType(admtReportMigratedAccounts)
  12. {
  13. }
  14. CReportGeneration::~CReportGeneration()
  15. {
  16. }
  17. // IReport Implementation ----------------------------------------
  18. // Type Property
  19. STDMETHODIMP CReportGeneration::put_Type(long lType)
  20. {
  21. HRESULT hr = S_OK;
  22. if (IsReportTypeValid(lType))
  23. {
  24. m_lType = lType;
  25. }
  26. else
  27. {
  28. hr = AdmtSetError(CLSID_Migration, IID_IReportGeneration, E_INVALIDARG, IDS_E_REPORT_TYPE_INVALID);
  29. }
  30. return hr;
  31. }
  32. STDMETHODIMP CReportGeneration::get_Type(long* plType)
  33. {
  34. *plType = m_lType;
  35. return S_OK;
  36. }
  37. // Folder Property
  38. STDMETHODIMP CReportGeneration::put_Folder(BSTR bstrFolder)
  39. {
  40. HRESULT hr = S_OK;
  41. try
  42. {
  43. _bstr_t strFolder = bstrFolder;
  44. if (strFolder.length() > 0)
  45. {
  46. _TCHAR szPath[_MAX_PATH];
  47. LPTSTR pszFilePart;
  48. DWORD cchPath = GetFullPathName(strFolder, _MAX_PATH, szPath, &pszFilePart);
  49. if ((cchPath == 0) || (cchPath >= _MAX_PATH))
  50. {
  51. AdmtThrowError(
  52. GUID_NULL,
  53. GUID_NULL,
  54. HRESULT_FROM_WIN32(GetLastError()),
  55. IDS_E_REPORT_FOLDER,
  56. (LPCTSTR)strFolder
  57. );
  58. }
  59. DWORD dwAttributes = GetFileAttributes(szPath);
  60. if (dwAttributes == DWORD(-1))
  61. {
  62. AdmtThrowError(
  63. GUID_NULL,
  64. GUID_NULL,
  65. HRESULT_FROM_WIN32(GetLastError()),
  66. IDS_E_REPORT_FOLDER,
  67. (LPCTSTR)strFolder
  68. );
  69. }
  70. if (!(dwAttributes & FILE_ATTRIBUTE_DIRECTORY))
  71. {
  72. AdmtThrowError(
  73. GUID_NULL,
  74. GUID_NULL,
  75. HRESULT_FROM_WIN32(ERROR_DIRECTORY),
  76. IDS_E_REPORT_FOLDER,
  77. (LPCTSTR)strFolder
  78. );
  79. }
  80. m_bstrFolder = szPath;
  81. }
  82. else
  83. {
  84. m_bstrFolder = strFolder;
  85. }
  86. }
  87. catch (_com_error& ce)
  88. {
  89. hr = AdmtSetError(CLSID_Migration, IID_IReportGeneration, ce);
  90. }
  91. catch (...)
  92. {
  93. hr = AdmtSetError(CLSID_Migration, IID_IReportGeneration, E_FAIL);
  94. }
  95. return hr;
  96. }
  97. STDMETHODIMP CReportGeneration::get_Folder(BSTR* pbstrFolder)
  98. {
  99. HRESULT hr = S_OK;
  100. try
  101. {
  102. *pbstrFolder = m_bstrFolder.copy();
  103. }
  104. catch (_com_error& ce)
  105. {
  106. hr = AdmtSetError(CLSID_Migration, IID_IReportGeneration, ce);
  107. }
  108. catch (...)
  109. {
  110. hr = AdmtSetError(CLSID_Migration, IID_IReportGeneration, E_FAIL);
  111. }
  112. return hr;
  113. }
  114. // Generate Method
  115. STDMETHODIMP CReportGeneration::Generate(long lOptions, VARIANT vntInclude, VARIANT vntExclude)
  116. {
  117. HRESULT hr = S_OK;
  118. MutexWait();
  119. bool bLogOpen = _Module.OpenLog();
  120. try
  121. {
  122. _Module.Log(ErrI, IDS_STARTED_REPORT_GENERATION);
  123. InitSourceDomainAndContainer();
  124. InitTargetDomainAndContainer();
  125. DoOption(lOptions, vntInclude, vntExclude);
  126. }
  127. catch (_com_error& ce)
  128. {
  129. _Module.Log(ErrE, IDS_E_CANT_GENERATE_REPORT, ce);
  130. hr = AdmtSetError(CLSID_Migration, IID_IReportGeneration, ce, IDS_E_CANT_GENERATE_REPORT);
  131. }
  132. catch (...)
  133. {
  134. _Module.Log(ErrE, IDS_E_CANT_GENERATE_REPORT, _com_error(E_FAIL));
  135. hr = AdmtSetError(CLSID_Migration, IID_IReportGeneration, E_FAIL, IDS_E_CANT_GENERATE_REPORT);
  136. }
  137. if (bLogOpen)
  138. {
  139. _Module.CloseLog();
  140. }
  141. MutexRelease();
  142. return hr;
  143. }
  144. // Implementation -----------------------------------------------------------
  145. // DoNone Method
  146. void CReportGeneration::DoNone()
  147. {
  148. CVarSet aVarSet;
  149. SetOptions(aVarSet);
  150. SetReports(aVarSet);
  151. aVarSet.Put(_T("PlugIn.%ld"), 0, _T("None"));
  152. PerformMigration(aVarSet);
  153. SaveSettings(aVarSet);
  154. }
  155. // DoNames Method
  156. void CReportGeneration::DoNames()
  157. {
  158. CDomainAccounts aComputers;
  159. m_SourceDomain.QueryComputersAcrossDomains(GetSourceContainer(), true, m_setIncludeNames, m_setExcludeNames, aComputers);
  160. DoComputers(aComputers);
  161. }
  162. // DoDomain Method
  163. void CReportGeneration::DoDomain()
  164. {
  165. DoContainers(GetSourceContainer());
  166. }
  167. // DoContainers Method
  168. void CReportGeneration::DoContainers(CContainer& rSource)
  169. {
  170. DoComputers(rSource);
  171. }
  172. // DoComputers Method
  173. void CReportGeneration::DoComputers(CContainer& rSource)
  174. {
  175. CDomainAccounts aComputers;
  176. rSource.QueryComputers(true, m_nRecurseMaintain >= 1, m_setExcludeNames, aComputers);
  177. DoComputers(aComputers);
  178. }
  179. // DoComputers Method
  180. void CReportGeneration::DoComputers(CDomainAccounts& rComputers)
  181. {
  182. if (rComputers.size() > 0)
  183. {
  184. CVarSet aVarSet;
  185. SetOptions(aVarSet);
  186. SetReports(aVarSet);
  187. FillInVarSetForComputers(rComputers, false, false, false, 0, aVarSet);
  188. aVarSet.Put(_T("PlugIn.%ld"), 0, _T("None"));
  189. rComputers.clear();
  190. PerformMigration(aVarSet);
  191. aVarSet.Put(DCTVS_GatherInformation, false);
  192. SaveSettings(aVarSet);
  193. }
  194. }
  195. // SetOptions Method
  196. void CReportGeneration::SetOptions(CVarSet& rVarSet)
  197. {
  198. CVarSetOptions aOptions(rVarSet);
  199. aOptions.SetWizard(_T("reporting"));
  200. aOptions.SetIntraForest(m_spInternal->IntraForest ? true : false);
  201. aOptions.SetSourceDomain(m_SourceDomain.NameFlat(), m_SourceDomain.NameDns());
  202. aOptions.SetTargetDomain(m_TargetDomain.NameFlat(), m_TargetDomain.NameDns());
  203. }
  204. // SetReports Method
  205. void CReportGeneration::SetReports(CVarSet& rVarSet)
  206. {
  207. CVarSetReports aReports(rVarSet);
  208. aReports.SetType(m_lType);
  209. aReports.SetReportsDirectory(m_bstrFolder);
  210. }