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.

456 lines
16 KiB

  1. //#pragma title ("SDStat.hpp -- Statistical information for SDResolve")
  2. /*
  3. Copyright (c) 1995-1998, Mission Critical Software, Inc. All rights reserved.
  4. ===============================================================================
  5. Module - sdstat.hpp
  6. System - SDResolve
  7. Author - Christy Boles
  8. Created - 97/06/27
  9. Description - Statistical information for SDResolve
  10. Updates -
  11. ===============================================================================
  12. */
  13. #include "stdafx.h"
  14. #include <stdio.h>
  15. #include "common.hpp"
  16. #include "ErrDct.hpp"
  17. #include "sidcache.hpp"
  18. #include "sd.hpp"
  19. #include "SecObj.hpp"
  20. #include "enumvols.hpp"
  21. #include "sdstat.hpp"
  22. #include "Mcs.h"
  23. extern TErrorDct err;
  24. TSDResolveStats::TSDResolveStats(
  25. TSDRidCache * cache, // in - cache containing mapping of accounts for the translation
  26. const TPathList * plist, // in - list of paths being translated
  27. IVarSet * pVarSet // in - varset to store stats in
  28. )
  29. {
  30. memset(&unit,0,sizeof TSDFileActions);
  31. memset(&part,0,sizeof TSDPartStats);
  32. pPList = plist;
  33. len = 0;
  34. frame_foreground =FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN ;
  35. background = BACKGROUND_BLUE ;
  36. data_foreground =frame_foreground | FOREGROUND_INTENSITY ;
  37. message_foreground = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
  38. pCache = cache;
  39. m_pVarSet = pVarSet;
  40. }
  41. TSDResolveStats::TSDResolveStats(
  42. TSDRidCache * cache // in - cache containing mapping of accounts for translation
  43. )
  44. {
  45. memset(&unit,0,sizeof TSDFileActions);
  46. memset(&part,0,sizeof TSDPartStats);
  47. pPList = NULL;
  48. len = 0;
  49. frame_foreground =FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN ;
  50. background = BACKGROUND_BLUE ;
  51. data_foreground =frame_foreground | FOREGROUND_INTENSITY ;
  52. message_foreground = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
  53. pCache = cache;
  54. //Added by Sham : Initialize m_pVarSet
  55. IVarSetPtr pVarSet(__uuidof(VarSet));
  56. m_pVarSet = pVarSet;
  57. // Need to add code to release this interface once we are done. In the destructor maybe
  58. m_pVarSet->AddRef();
  59. }
  60. void
  61. TSDResolveStats::IncrementOwnerChange(
  62. TAcctNode * acct, // in -account changed
  63. objectType type, // in -type of object
  64. TSecurableObject * file // in -file changed
  65. )
  66. {
  67. acct->AddOwnerChange(type);
  68. if ( acct->IsValidOnTgt() )
  69. {
  70. part.owner.changed++;
  71. // DisplayStatItem(OWNER_ROW,CHANGED_COL,part.owner.changed);
  72. }
  73. else
  74. {
  75. part.owner.notarget++;
  76. // DisplayStatItem(OWNER_ROW,SKIPPED_COL,part.owner.skipped);
  77. // TODO log an error message
  78. }
  79. if ( file )
  80. file->LogOwnerChange(acct);
  81. }
  82. void
  83. TSDResolveStats::IncrementGroupChange(
  84. TAcctNode * acct, // in -account changed
  85. objectType type, // in -type of object
  86. TSecurableObject * file // in -file changed
  87. )
  88. {
  89. acct->AddGroupChange(type);
  90. if ( acct->IsValidOnTgt() )
  91. {
  92. part.group.changed++;
  93. // DisplayStatItem(GROUP_ROW,CHANGED_COL,part.group.changed);
  94. }
  95. else
  96. {
  97. part.group.notarget++;
  98. // DisplayStatItem(GROUP_ROW,SKIPPED_COL,part.group.skipped);
  99. }
  100. if ( file )
  101. file->LogGroupChange(acct);
  102. }
  103. void
  104. TSDResolveStats::IncrementDACEChange(
  105. TAcctNode * acct, // in -account changed
  106. objectType type, // in -type of object
  107. TSecurableObject * file // in -file changed
  108. )
  109. {
  110. acct->AddAceChange(type);
  111. if ( acct->IsValidOnTgt() )
  112. {
  113. part.dace.changed++;
  114. // DisplayStatItem(DACE_ROW,CHANGED_COL,part.dace.changed);
  115. }
  116. else
  117. {
  118. part.dace.notarget++;
  119. // DisplayStatItem(DACE_ROW,SKIPPED_COL,part.dace.skipped);
  120. }
  121. if ( file )
  122. file->LogDACEChange(acct);
  123. }
  124. void
  125. TSDResolveStats::IncrementSACEChange(
  126. TAcctNode * acct, // in -account changed
  127. objectType type, // in -type of object
  128. TSecurableObject * file // in -file changed
  129. )
  130. {
  131. acct->AddSaceChange(type);
  132. if ( acct->IsValidOnTgt() )
  133. {
  134. part.sace.changed++;
  135. // DisplayStatItem(SACE_ROW,CHANGED_COL,part.sace.changed);
  136. }
  137. else
  138. {
  139. part.sace.notarget++;
  140. // DisplayStatItem(SACE_ROW,SKIPPED_COL,part.sace.skipped);
  141. }
  142. if ( file )
  143. file->LogSACEChange(acct);
  144. }
  145. void
  146. TSDResolveStats::IncrementDACENotSelected(
  147. TSecurableObject *file // in - object to increment stats for
  148. )
  149. {
  150. file->daceNS++;
  151. part.dace.notselected++;
  152. }
  153. void
  154. TSDResolveStats::IncrementSACENotSelected(
  155. TSecurableObject *file // in - object to increment stats for
  156. )
  157. {
  158. if ( file )
  159. file->saceNS++;
  160. part.sace.notselected++;
  161. }
  162. void
  163. TSDResolveStats::IncrementDACEUnknown(
  164. TSecurableObject *file // in - object to increment stats for
  165. )
  166. {
  167. if ( file )
  168. file->daceU++;
  169. part.dace.unknown++;
  170. }
  171. void
  172. TSDResolveStats::IncrementSACEUnknown(
  173. TSecurableObject *file // in - object to increment stats for
  174. )
  175. {
  176. if ( file )
  177. file->saceU++;
  178. part.sace.unknown++;
  179. }
  180. void
  181. TSDResolveStats::IncrementDACENoTarget(
  182. TSecurableObject *file // in - object to increment stats for
  183. )
  184. {
  185. if ( file )
  186. file->daceNT++;
  187. part.dace.notarget++;
  188. }
  189. void
  190. TSDResolveStats::IncrementSACENoTarget(
  191. TSecurableObject *file // in - object to increment stats for
  192. )
  193. {
  194. if ( file )
  195. file->saceNT++;
  196. part.sace.notarget++;
  197. }
  198. /***************************************************************************************************/
  199. /* IncrementLastFileChanges: used in conjunction with last-seen heuristic. When a SD matches the
  200. last-seen SD, this routine repeats all the stat-updates
  201. that were done for the last-seen SD, so that we have accurate stats
  202. (especially ACE changes per account)
  203. /**************************************************************************************************/
  204. void
  205. TSDResolveStats::IncrementLastFileChanges(
  206. const TSecurableObject * lastfile, // in -file to repeat change stats from
  207. objectType objType // in -type of object
  208. )
  209. {
  210. TNodeListEnum tenum;
  211. TStatNode * snode;
  212. // make modifications except changes
  213. // owner
  214. IncrementOwnerExamined();
  215. IncrementGroupExamined();
  216. if ( lastfile->UnknownOwner() )
  217. part.owner.unknown++;
  218. // group
  219. if ( lastfile->UnknownGroup() )
  220. part.group.unknown++;
  221. // dacl
  222. if ( lastfile->HasDacl() )
  223. IncrementDACLExamined();
  224. // sacl
  225. if ( lastfile->HasSacl() )
  226. IncrementSACLExamined();
  227. // aces
  228. part.dace.notarget+=lastfile->daceNT;
  229. part.sace.notarget+=lastfile->saceNT;
  230. part.dace.unknown+=lastfile->daceU;
  231. part.sace.unknown+=lastfile->saceU;
  232. part.dace.notselected+=lastfile->daceNS;
  233. part.sace.notselected+=lastfile->saceNS;
  234. if ( lastfile->Changed() )
  235. {
  236. IncrementChanged(objType);
  237. }
  238. if ( lastfile->Changed() || (lastfile->GetChangeLog())->Count() )
  239. {
  240. if ( lastfile->IsDaclChanged() )
  241. {
  242. IncrementDACLChanged();
  243. }
  244. if ( lastfile->IsSaclChanged() )
  245. {
  246. IncrementSACLChanged();
  247. }
  248. for ( snode = (TStatNode *)tenum.OpenFirst(lastfile->GetChangeLog()) ;
  249. snode ;
  250. snode = (TStatNode *)tenum.Next()
  251. )
  252. {
  253. switch ( snode->changetype )
  254. {
  255. case TStatNode::owner:
  256. IncrementOwnerChange(snode->acctnode,objType,NULL);
  257. break;
  258. case TStatNode::group:
  259. IncrementGroupChange(snode->acctnode,objType,NULL);
  260. break;
  261. case TStatNode::dace:
  262. IncrementDACEChange(snode->acctnode,objType,NULL);
  263. break;
  264. case TStatNode::sace:
  265. IncrementSACEChange(snode->acctnode,objType,NULL);
  266. break;
  267. default:
  268. MCSASSERT( false );
  269. }
  270. }
  271. tenum.Close();
  272. }
  273. }
  274. void
  275. TSDResolveStats::ReportToVarSet(
  276. IVarSet * pVarSet, // in -varset to write data to
  277. DWORD verbnum // in -which info to log
  278. ) const
  279. {
  280. BOOL summary = verbnum & SUMMARYSTATS;
  281. BOOL accts = verbnum & ACCOUNTSTATS;
  282. // BOOL file = verbnum & FILESTATS;
  283. BOOL paths = verbnum & PATHSTATS;
  284. if ( summary )
  285. {
  286. if ( paths && pPList )
  287. {
  288. pVarSet->put(GET_BSTR(DCTVS_Stats_Paths),(LONG)pPList->GetNumPaths() );
  289. pVarSet->put(GET_BSTR(DCTVS_Stats_Servers),(LONG)pPList->GetNumServers() );
  290. }
  291. pVarSet->put(GET_BSTR(DCTVS_Stats_Files_Examined),(LONG)unit.examined.file);
  292. pVarSet->put(GET_BSTR(DCTVS_Stats_Directories_Examined),(LONG)unit.examined.dir);
  293. pVarSet->put(GET_BSTR(DCTVS_Stats_Shares_Examined),(LONG)unit.examined.share);
  294. pVarSet->put(GET_BSTR(DCTVS_Stats_Mailboxes_Examined),(LONG)unit.examined.mailbox);
  295. pVarSet->put(GET_BSTR(DCTVS_Stats_Containers_Examined),(LONG)unit.examined.container);
  296. pVarSet->put(GET_BSTR(DCTVS_Stats_Files_CacheHits),(LONG)unit.cachehit.file);
  297. pVarSet->put(GET_BSTR(DCTVS_Stats_Directories_CacheHits),(LONG)unit.cachehit.dir);
  298. pVarSet->put(GET_BSTR(DCTVS_Stats_Files_Skipped),(LONG)unit.skipped.file);
  299. pVarSet->put(GET_BSTR(DCTVS_Stats_Directories_Skipped),(LONG)unit.skipped.dir);
  300. pVarSet->put(GET_BSTR(DCTVS_Stats_Shares_Skipped),(LONG)unit.skipped.share);
  301. pVarSet->put(GET_BSTR(DCTVS_Stats_Mailboxes_Skipped),(LONG)unit.skipped.mailbox);
  302. pVarSet->put(GET_BSTR(DCTVS_Stats_Containers_Skipped),(LONG)unit.skipped.container);
  303. pVarSet->put(GET_BSTR(DCTVS_Stats_Files_Changed),(LONG)unit.changed.file);
  304. pVarSet->put(GET_BSTR(DCTVS_Stats_Directories_Changed),(LONG)unit.changed.dir);
  305. pVarSet->put(GET_BSTR(DCTVS_Stats_Shares_Changed),(LONG)unit.changed.share);
  306. pVarSet->put(GET_BSTR(DCTVS_Stats_Mailboxes_Changed),(LONG)unit.changed.mailbox);
  307. pVarSet->put(GET_BSTR(DCTVS_Stats_Containers_Changed),(LONG)unit.changed.container);
  308. pVarSet->put(GET_BSTR(DCTVS_Stats_Owners_Examined),(LONG)part.owner.examined);
  309. pVarSet->put(GET_BSTR(DCTVS_Stats_Groups_Examined),(LONG)part.group.examined);
  310. pVarSet->put(GET_BSTR(DCTVS_Stats_DACL_Examined),(LONG)part.dacl.examined);
  311. pVarSet->put(GET_BSTR(DCTVS_Stats_SACL_Examined),(LONG)part.sacl.examined);
  312. pVarSet->put(GET_BSTR(DCTVS_Stats_DACE_Examined),(LONG)part.dace.examined);
  313. pVarSet->put(GET_BSTR(DCTVS_Stats_SACE_Examined),(LONG)part.sace.examined);
  314. pVarSet->put(GET_BSTR(DCTVS_Stats_Owners_Changed),(LONG)part.owner.changed);
  315. pVarSet->put(GET_BSTR(DCTVS_Stats_Groups_Changed),(LONG)part.group.changed);
  316. pVarSet->put(GET_BSTR(DCTVS_Stats_DACL_Changed),(LONG)part.dacl.changed);
  317. pVarSet->put(GET_BSTR(DCTVS_Stats_SACL_Changed),(LONG)part.sacl.changed);
  318. pVarSet->put(GET_BSTR(DCTVS_Stats_DACE_Changed),(LONG)part.dace.changed);
  319. pVarSet->put(GET_BSTR(DCTVS_Stats_SACE_Changed),(LONG)part.sace.changed);
  320. pVarSet->put(GET_BSTR(DCTVS_Stats_Owners_NoTarget),(LONG)part.owner.notarget);
  321. pVarSet->put(GET_BSTR(DCTVS_Stats_Groups_NoTarget),(LONG)part.group.notarget);
  322. pVarSet->put(GET_BSTR(DCTVS_Stats_DACE_NoTarget),(LONG)part.dace.notarget);
  323. pVarSet->put(GET_BSTR(DCTVS_Stats_SACE_NoTarget),(LONG)part.sace.notarget);
  324. pVarSet->put(GET_BSTR(DCTVS_Stats_Owners_Unknown),(LONG)part.owner.unknown);
  325. pVarSet->put(GET_BSTR(DCTVS_Stats_Groups_Unknown),(LONG)part.group.unknown);
  326. pVarSet->put(GET_BSTR(DCTVS_Stats_DACE_Unknown),(LONG)part.dace.unknown);
  327. pVarSet->put(GET_BSTR(DCTVS_Stats_SACE_Unknown),(LONG)part.sace.unknown);
  328. }
  329. if ( accts )
  330. pCache->ReportToVarSet(pVarSet,false, true);
  331. }
  332. void
  333. TSDResolveStats::Report(
  334. BOOL summary, // in -flag, whether to report summary information
  335. BOOL accts, // in -flag, whether to report account detail information
  336. BOOL paths // in -flag, whether to report path detail information
  337. ) const
  338. {
  339. if ( accts )
  340. pCache->Display(summary!=0, accts!=0);
  341. #ifdef FST
  342. if ( paths & pPList )
  343. pPList->Display();
  344. #endif
  345. if ( summary )
  346. {
  347. err.MsgWrite(0,DCT_MSG_SUMMARY_REPORT_HEADER);
  348. err.MsgWrite(0,DCT_MSG_SUMMARY_REPORT_FILES_DDD,unit.examined.file, unit.changed.file, unit.examined.file - unit.changed.file);
  349. err.MsgWrite(0,DCT_MSG_SUMMARY_REPORT_DIRS_DDD,unit.examined.dir, unit.changed.dir, unit.examined.dir - unit.changed.dir);
  350. err.MsgWrite(0,DCT_MSG_SUMMARY_REPORT_SHARES_DDD,unit.examined.share, unit.changed.share, unit.examined.share - unit.changed.share);
  351. err.MsgWrite(0,DCT_MSG_SUMMARY_REPORT_MEMBERS_DDD,unit.examined.member, unit.changed.member, unit.examined.member - unit.changed.member);
  352. err.MsgWrite(0,DCT_MSG_SUMMARY_REPORT_RIGHTS_DDD,unit.examined.userright, unit.changed.userright, unit.examined.userright - unit.changed.userright);
  353. err.MsgWrite(0,DCT_MSG_SUMMARY_REPORT_MAILBOXES_DDD,unit.examined.mailbox, unit.changed.mailbox, unit.examined.mailbox - unit.changed.mailbox);
  354. err.MsgWrite(0,DCT_MSG_SUMMARY_REPORT_CONTAINERS_DDD,unit.examined.container, unit.changed.container, unit.examined.container - unit.changed.container);
  355. err.MsgWrite(0,DCT_MSG_SUMMARY_REPORT_DACLS_DDD,part.dacl.examined, part.dacl.changed, part.dacl.examined - part.dacl.changed);
  356. err.MsgWrite(0,DCT_MSG_SUMMARY_REPORT_SACLS_DDD,part.sacl.examined, part.sacl.changed, part.sacl.examined - part.sacl.changed);
  357. err.MsgWrite(0,DCT_MSG_SUMMARY_PARTS_REPORT_HEADER);
  358. err.MsgWrite(0,DCT_MSG_SUMMARY_PARTS_REPORT_OWNERS_DDDDD,part.owner.examined, part.owner.changed, part.owner.notarget, part.owner.examined - part.owner.changed - part.owner.notarget - part.owner.unknown, part.owner.unknown);
  359. err.MsgWrite(0,DCT_MSG_SUMMARY_PARTS_REPORT_GROUPS_DDDDD,part.group.examined, part.group.changed, part.group.notarget, part.group.examined - part.group.changed - part.group.notarget - part.group.unknown ,part.group.unknown);
  360. err.MsgWrite(0,DCT_MSG_SUMMARY_PARTS_REPORT_DACES_DDDDD,part.dace.examined, part.dace.changed, part.dace.notarget,part.dace.notselected,part.dace.unknown);
  361. err.MsgWrite(0,DCT_MSG_SUMMARY_PARTS_REPORT_SACES_DDDDD,part.sace.examined, part.sace.changed, part.sace.notarget,part.sace.notselected,part.sace.unknown);
  362. }
  363. }
  364. #define HDR1ITEMS 2
  365. #define HDRCOL1 8
  366. #define HDRROW1 4
  367. #define COLWIDTH 12
  368. #define HDRCOL2 ( HDRCOL1 + COLWIDTH )
  369. #define HDRROW2 ( HDRROW1 + ( 2 * HDR1ITEMS + 1) + 1)
  370. void
  371. TSDResolveStats::InitDisplay(
  372. BOOL nochange
  373. )
  374. {
  375. }
  376. // no longer used
  377. void
  378. TSDResolveStats::DisplayStatFrame(
  379. BOOL nochange
  380. )
  381. {
  382. }
  383. // no longer used
  384. void TSDResolveStats::DisplayStatItem(SHORT row, SHORT col, DWORD val, BOOL forceUpdate)
  385. {
  386. }
  387. DWORD dwLastUpdate = 0;
  388. void
  389. TSDResolveStats::DisplayPath(LPWSTR str,BOOL forceUpdate)
  390. {
  391. DWORD now = GetTickCount();
  392. if ( m_pVarSet )
  393. {
  394. m_pVarSet->put(GET_BSTR(DCTVS_CurrentPath),str);
  395. if ( now - dwLastUpdate > 1000 )
  396. {
  397. ReportToVarSet(m_pVarSet,SUMMARYSTATS);
  398. dwLastUpdate = GetTickCount();
  399. }
  400. }
  401. }
  402. void
  403. TSDResolveStats::DisplayBox(SHORT x1, SHORT y1, SHORT x2, SHORT y2)
  404. {
  405. }
  406. void
  407. TSDResolveStats::SetFrameText(WCHAR * msg)
  408. {
  409. }