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.

1476 lines
50 KiB

  1. /*++
  2. Copyright (C) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. proputil.cpp
  5. Abstract:
  6. This file contains all static data related to log and alert properties,
  7. along with routines to access that data.
  8. --*/
  9. //==========================================================================//
  10. // Includes //
  11. //==========================================================================//
  12. #include "stdafx.h"
  13. #include "strings.h"
  14. #include "logmmsg.h"
  15. #include "propbag.h"
  16. #include "utils.h"
  17. #include "proputil.h"
  18. //==========================================================================//
  19. // Constants and Types //
  20. //==========================================================================//
  21. // Property constants represent indexes into the static PropertyDataMap table.
  22. const DWORD IdFirstProp = 0;
  23. // The property constants in this first section have a one-to-one
  24. // correspondence between HTML parameter and registry value
  25. const DWORD IdCommentProp = IdFirstProp + 0;
  26. const DWORD IdLogTypeProp = IdFirstProp + 1;
  27. const DWORD IdCurrentStateProp = IdFirstProp + 2;
  28. const DWORD IdLogFileMaxSizeProp = IdFirstProp + 3;
  29. const DWORD IdLogFileBaseNameProp = IdFirstProp + 4;
  30. const DWORD IdLogFileFolderProp = IdFirstProp + 5;
  31. const DWORD IdLogFileSerialNumberProp = IdFirstProp + 6;
  32. const DWORD IdLogFileAutoFormatProp = IdFirstProp + 7;
  33. const DWORD IdLogFileTypeProp = IdFirstProp + 8;
  34. const DWORD IdEofCommandFileProp = IdFirstProp + 9;
  35. const DWORD IdCommandFileProp = IdFirstProp + 10;
  36. const DWORD IdNetworkNameProp = IdFirstProp + 11;
  37. const DWORD IdUserTextProp = IdFirstProp + 12;
  38. const DWORD IdPerfLogNameProp = IdFirstProp + 13;
  39. const DWORD IdTraceBufferSizeProp = IdFirstProp + 14;
  40. const DWORD IdTraceBufferMinCountProp = IdFirstProp + 15;
  41. const DWORD IdTraceBufferMaxCountProp = IdFirstProp + 16;
  42. const DWORD IdTraceBufferFlushIntProp = IdFirstProp + 17;
  43. const DWORD IdActionFlagsProp = IdFirstProp + 18;
  44. const DWORD IdTraceFlagsProp = IdFirstProp + 19;
  45. // Property constants below require special handling for BagToRegistry,
  46. // because there is not a one-to-one correspondence between HTML
  47. // parameter and registry value.
  48. const DWORD IdRestartProp = IdFirstProp + 20;
  49. const DWORD IdStartProp = IdFirstProp + 21;
  50. const DWORD IdStopProp = IdFirstProp + 22;
  51. const DWORD IdSampleProp = IdFirstProp + 23;
  52. const DWORD IdCounterListProp = IdFirstProp + 24;
  53. const DWORD IdGuidListProp = IdFirstProp + 25;
  54. const DWORD IdLastProp = IdFirstProp + 25;
  55. /*
  56. // Not handled yet, or covered by special values above.
  57. // Some of these might be needed when writing to HTML file from registry.
  58. //
  59. const DWORD IdSysmonVersionProp = IdFirstProp + 29;
  60. const DWORD IdSysmonCounterCountProp = IdFirstProp + 29;
  61. const DWORD IdSysmonCounterPathProp = IdFirstProp + 21;
  62. const DWORD IdAlertThresholdProp = IdFirstProp + 23;
  63. const DWORD IdAlertOverUnderProp = IdFirstProp + 24;
  64. const DWORD IdTraceProviderCountProp = IdFirstProp + 25;
  65. const DWORD IdTraceProviderGuidProp = IdFirstProp + 26;
  66. const DWORD IdLogNameProp = IdFirstProp + 27;
  67. const DWORD IdAlertNameProp = IdFirstProp + 28;
  68. const DWORD IdStartModeProp = SLQ_TT_TTYPE_LAST + ;
  69. const DWORD IdStartAtTimeProp = SLQ_TT_TTYPE_LAST + ;
  70. const DWORD IdStopModeProp = SLQ_TT_TTYPE_LAST + ;
  71. const DWORD IdStopAtTimeProp = SLQ_TT_TTYPE_LAST + ;
  72. const DWORD IdStopAfterUnitTypeProp = SLQ_TT_TTYPE_LAST + ;
  73. const DWORD IdStopAfterValueProp = SLQ_TT_TTYPE_LAST + ;
  74. const DWORD IdSampleIntUnitTypeProp = IdFirstProp + 21;
  75. const DWORD IdSampleIntValueProp = IdFirstProp + 21;
  76. const DWORD IdSysmonUpdateIntervalProp = SLQ_TT_TTYPE_LAST + ;
  77. const DWORD IdSysmonSampleCountProp = IdFirstProp + 20;
  78. const DWORD IdSysmonLogFileNameProp = IdFirstProp + 18;
  79. const DWORD IdExecuteOnlyProp = IdFirstProp + 30;
  80. */
  81. //==========================================================================//
  82. // Local Constants //
  83. //==========================================================================//
  84. const DWORD cdwFortyfiveDays = ((DWORD)(0xE7BE2C00));
  85. const WORD cwFirstValidYear = ((DWORD)(2000));
  86. const DWORD cdwNoMaxSizeLimit = ((DWORD)(0xFFFFFFFF));
  87. const DWORD cdwNoRange = ((DWORD)(0xFFFFFFFF));
  88. const DWORD cdwSeverityMask = ((DWORD)(0xC0000000));
  89. const CPropertyUtils::PROPERTY_DATA_MAP CPropertyUtils::m_PropertyDataMap[] =
  90. {
  91. {IdCommentProp, REG_SZ, cwszHtmlComment, cwszRegComment
  92. ,(ValidationMethod)ValidateString ,FALSE ,NULL ,NULL },
  93. {IdLogTypeProp, REG_DWORD, cwszHtmlLogType, cwszRegLogType
  94. ,(ValidationMethod)ValidateDwordInterval ,TRUE ,SLQ_FIRST_LOG_TYPE ,SLQ_LAST_LOG_TYPE },
  95. {IdCurrentStateProp, REG_DWORD, cwszHtmlCurrentState, cwszRegCurrentState
  96. ,(ValidationMethod)ValidateDwordInterval ,FALSE ,SLQ_QUERY_STOPPED ,SLQ_QUERY_RUNNING },
  97. {IdLogFileMaxSizeProp, REG_DWORD, cwszHtmlLogFileMaxSize, cwszRegLogFileMaxSize
  98. ,(ValidationMethod)ValidateMaxFileSize ,FALSE ,1 ,0x0100000 },
  99. {IdLogFileBaseNameProp, REG_SZ, cwszHtmlLogFileBaseName, cwszRegLogFileBaseName
  100. ,(ValidationMethod)ValidateFileName ,FALSE ,NULL ,NULL },
  101. {IdLogFileFolderProp, REG_SZ, cwszHtmlLogFileFolder, cwszRegLogFileFolder
  102. ,(ValidationMethod)ValidateDirectoryPath ,FALSE ,NULL ,NULL },
  103. {IdLogFileSerialNumberProp, REG_DWORD, cwszHtmlLogFileSerialNumber,cwszRegLogFileSerialNumber
  104. ,(ValidationMethod)ValidateDwordInterval ,FALSE ,0 ,999999 },
  105. {IdLogFileAutoFormatProp, REG_DWORD, cwszHtmlLogFileAutoFormat, cwszRegLogFileAutoFormat
  106. ,(ValidationMethod)ValidateDwordInterval ,FALSE ,0 ,1 },
  107. {IdLogFileTypeProp, REG_DWORD, cwszHtmlLogFileType, cwszRegLogFileType
  108. ,(ValidationMethod)ValidateLogFileType ,FALSE ,cdwNoRange ,cdwNoRange },
  109. {IdEofCommandFileProp, REG_SZ, cwszHtmlEofCommandFile, cwszRegEofCommandFile
  110. ,(ValidationMethod)ValidateFilePath ,FALSE ,NULL ,NULL },
  111. {IdCommandFileProp, REG_SZ, cwszHtmlCommandFile, cwszRegCommandFile
  112. ,(ValidationMethod)ValidateFilePath ,FALSE ,NULL ,NULL },
  113. {IdNetworkNameProp, REG_SZ, cwszHtmlNetworkName, cwszRegNetworkName
  114. ,(ValidationMethod)ValidateString ,TRUE ,NULL ,NULL },
  115. {IdUserTextProp, REG_SZ, cwszHtmlUserText, cwszRegUserText
  116. ,(ValidationMethod)ValidateString ,FALSE ,NULL ,NULL },
  117. {IdPerfLogNameProp, REG_SZ, cwszHtmlPerfLogName, cwszRegPerfLogName
  118. ,(ValidationMethod)ValidateLogExists ,FALSE ,NULL ,NULL },
  119. {IdTraceBufferSizeProp, REG_DWORD, cwszHtmlTraceBufferSize, cwszRegTraceBufferSize
  120. ,(ValidationMethod)ValidateDwordInterval ,FALSE ,1 ,1024 },
  121. {IdTraceBufferMinCountProp, REG_DWORD, cwszHtmlTraceBufferMinCount,cwszRegTraceBufferMinCount
  122. ,(ValidationMethod)ValidateDwordInterval ,FALSE ,2 ,400 },
  123. {IdTraceBufferMaxCountProp, REG_DWORD, cwszHtmlTraceBufferMaxCount,cwszRegTraceBufferMaxCount
  124. ,(ValidationMethod)ValidateTraceBufferMaxCount,FALSE,2 ,400 },
  125. {IdTraceBufferFlushIntProp, REG_DWORD, cwszHtmlTraceBufferFlushInt,cwszRegTraceBufferFlushInt
  126. ,(ValidationMethod)ValidateDwordInterval ,FALSE ,0 ,300 },
  127. {IdActionFlagsProp, REG_DWORD, cwszHtmlActionFlags, cwszRegActionFlags
  128. ,(ValidationMethod)ValidateAlertActions ,FALSE ,cdwNoRange ,cdwNoRange },
  129. {IdTraceFlagsProp, REG_DWORD, cwszHtmlTraceFlags, cwszRegTraceFlags
  130. ,(ValidationMethod)ValidateTraceFlags ,FALSE ,cdwNoRange ,cdwNoRange },
  131. {IdRestartProp, REG_BINARY, cwszHtmlRestartMode, cwszRegRestart
  132. ,(ValidationMethod)ValidateSlqTimeInfo ,FALSE ,0 ,1 },
  133. {IdStartProp, REG_BINARY ,NULL, cwszRegStartTime
  134. ,(ValidationMethod)ValidateSlqTimeInfo ,FALSE ,cdwNoRange ,cdwNoRange },
  135. {IdStopProp, REG_BINARY ,NULL, cwszRegStopTime
  136. ,(ValidationMethod)ValidateSlqTimeInfo ,FALSE ,cdwNoRange ,cdwNoRange },
  137. {IdSampleProp, REG_BINARY ,NULL, cwszRegSampleInterval
  138. ,(ValidationMethod)ValidateSlqTimeInfo ,FALSE ,cdwNoRange ,cdwNoRange },
  139. {IdCounterListProp, REG_MULTI_SZ,NULL, NULL
  140. ,(ValidationMethod)ValidatePrimaryObjectList,TRUE ,cdwNoRange ,cdwNoRange },
  141. {IdGuidListProp, REG_MULTI_SZ,NULL, NULL
  142. ,(ValidationMethod)ValidatePrimaryObjectList,FALSE ,cdwNoRange ,cdwNoRange }
  143. };
  144. const DWORD CPropertyUtils::m_dwPropertyDataMapEntries
  145. = sizeof(CPropertyUtils::m_PropertyDataMap)/sizeof(CPropertyUtils::m_PropertyDataMap[0]);
  146. //==========================================================================//
  147. // Friend Functions //
  148. //==========================================================================//
  149. DWORD
  150. ValidateDwordInterval (
  151. CPropertyUtils* pUtils,
  152. DWORD dwPropId,
  153. DWORD /* dwLogType */)
  154. {
  155. DWORD dwStatus = ERROR_SUCCESS;
  156. HRESULT hr;
  157. DWORD dwValue;
  158. hr = DwordFromPropertyBag (
  159. pUtils->m_pPropBag,
  160. CPropertyUtils::m_PropertyDataMap[dwPropId].cwszHtmlName,
  161. dwValue );
  162. if ( SUCCEEDED ( hr ) ) {
  163. if ( ( dwValue < CPropertyUtils::m_PropertyDataMap[dwPropId].dwMin )
  164. || (dwValue > CPropertyUtils::m_PropertyDataMap[dwPropId].dwMax ) ) {
  165. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  166. }
  167. } else {
  168. dwStatus = pUtils->GetMissingStatus ( dwPropId );
  169. }
  170. if ( pUtils->IsDisplayLevelMessage ( dwStatus ) ) {
  171. if ( pUtils->GetInvalidStatus ( dwPropId ) == dwStatus ) {
  172. WCHAR szBufVal [64];
  173. WCHAR szBufMin [64];
  174. WCHAR szBufMax [64];
  175. swprintf (szBufVal, L"%ld", dwValue );
  176. swprintf (szBufMin, L"%ld", CPropertyUtils::m_PropertyDataMap[dwPropId].dwMin );
  177. swprintf (szBufMax, L"%ld", CPropertyUtils::m_PropertyDataMap[dwPropId].dwMax );
  178. DisplayErrorMessage (
  179. LOGMAN_OUT_OF_RANGE,
  180. szBufVal,
  181. CPropertyUtils::m_PropertyDataMap[dwPropId].cwszHtmlName,
  182. pUtils->GetQueryName(),
  183. szBufMin,
  184. szBufMax );
  185. } else {
  186. assert ( pUtils->GetMissingStatus ( dwPropId ) == dwStatus );
  187. DisplayErrorMessage (
  188. dwStatus,
  189. CPropertyUtils::m_PropertyDataMap[dwPropId].cwszHtmlName,
  190. pUtils->GetQueryName() );
  191. }
  192. }
  193. return dwStatus;
  194. }
  195. DWORD
  196. ValidatePrimaryObjectList (
  197. CPropertyUtils* pUtils,
  198. DWORD dwPropId,
  199. DWORD dwLogType )
  200. {
  201. DWORD dwStatus = ERROR_SUCCESS;
  202. HRESULT hr;
  203. UNICODE_STRING ustrGuid;
  204. GUID guid;
  205. DWORD dwCount = 0;
  206. WCHAR achInfoBufNew[sizeof(PDH_COUNTER_PATH_ELEMENTS_W) + MAX_PATH + 5];
  207. PPDH_COUNTER_PATH_ELEMENTS_W pPathInfoNew = (PPDH_COUNTER_PATH_ELEMENTS_W)achInfoBufNew;
  208. ULONG ulBufSize;
  209. DWORD dwIndex;
  210. WCHAR szPropName [MAX_PATH+1]; // Todo: Remove length restriction
  211. DWORD dwPropBagStringLen = 0;
  212. DWORD dwTemp = 0;
  213. DOUBLE dThreshold = 0;
  214. LPCWSTR szHtmlCountProp = NULL;
  215. LPCWSTR szHtmlPathProp = NULL;
  216. assert ( REG_MULTI_SZ == CPropertyUtils::m_PropertyDataMap[dwPropId].dwRegType );
  217. if ( IdCounterListProp == dwPropId ) {
  218. if ( SLQ_COUNTER_LOG == dwLogType
  219. || SLQ_ALERT == dwLogType ) {
  220. szHtmlCountProp = cwszHtmlSysmonCounterCount;
  221. szHtmlPathProp = cwszHtmlSysmonCounterPath;
  222. } else {
  223. assert ( FALSE );
  224. dwStatus = ERROR_INVALID_PARAMETER;
  225. }
  226. } else if ( IdGuidListProp == dwPropId ) {
  227. if ( SLQ_TRACE_LOG == dwLogType ) {
  228. szHtmlCountProp = cwszHtmlTraceProviderCount;
  229. szHtmlPathProp = cwszHtmlTraceProviderGuid;
  230. } else {
  231. assert ( FALSE );
  232. dwStatus = ERROR_INVALID_PARAMETER;
  233. }
  234. } else {
  235. assert ( FALSE );
  236. dwStatus = ERROR_INVALID_PARAMETER;
  237. }
  238. if ( ERROR_SUCCESS == dwStatus ) {
  239. hr = DwordFromPropertyBag (
  240. pUtils->m_pPropBag,
  241. szHtmlCountProp,
  242. dwCount ); // Todo: Require counter count? Yes for now
  243. if ( SUCCEEDED ( hr ) ) {
  244. // Todo: Add dwCount to properties table?
  245. if ( 0 < dwCount ) {
  246. for ( dwIndex = 1;
  247. dwIndex <= dwCount && SUCCEEDED ( hr );
  248. dwIndex++ ) {
  249. swprintf ( szPropName, szHtmlPathProp, dwIndex );
  250. hr = StringFromPropBagAlloc (
  251. pUtils->m_pPropBag,
  252. szPropName,
  253. &pUtils->m_szPropBagBuffer,
  254. &pUtils->m_dwPropBagBufLen,
  255. &dwPropBagStringLen );
  256. if ( SUCCEEDED (hr ) ) {
  257. if ( SLQ_COUNTER_LOG == dwLogType ) {
  258. // Validate counter path
  259. ulBufSize = sizeof(achInfoBufNew);
  260. ZeroMemory ( achInfoBufNew, ulBufSize );
  261. dwStatus = PdhParseCounterPathW(
  262. pUtils->m_szPropBagBuffer,
  263. pPathInfoNew,
  264. &ulBufSize,
  265. 0);
  266. if ( ERROR_SUCCESS != dwStatus ) {
  267. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  268. }
  269. } else if ( SLQ_TRACE_LOG == dwLogType ) {
  270. // Validate guid
  271. // Check to ensure that the length and form are correct
  272. ustrGuid.Length = (USHORT)(dwPropBagStringLen*sizeof(WCHAR));
  273. ustrGuid.MaximumLength = (USHORT)(dwPropBagStringLen*sizeof(WCHAR));
  274. ustrGuid.Buffer = pUtils->m_szPropBagBuffer;
  275. dwStatus = GuidFromString (&ustrGuid, &guid );
  276. if ( ERROR_SUCCESS != dwStatus ) {
  277. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  278. }
  279. } else if ( SLQ_ALERT == dwLogType ) {
  280. // Alert threshold and threshold log values are required.
  281. swprintf ( szPropName, cwszHtmlAlertOverUnder, dwIndex );
  282. hr = DwordFromPropertyBag (
  283. pUtils->m_pPropBag,
  284. szPropName,
  285. dwTemp );
  286. if ( SUCCEEDED (hr ) ) {
  287. if ( ( dwTemp != AIBF_OVER )
  288. && ( dwTemp != AIBF_UNDER ) ) {
  289. dwStatus = LOGMAN_REQUIRED_PROP_INVALID;
  290. }
  291. } else {
  292. dwStatus = LOGMAN_REQUIRED_PROP_MISSING;
  293. break;
  294. }
  295. if ( ERROR_SUCCESS == dwStatus && SUCCEEDED ( hr ) ) {
  296. swprintf ( szPropName, cwszHtmlAlertThreshold, dwIndex );
  297. hr = DoubleFromPropertyBag (
  298. pUtils->m_pPropBag,
  299. szPropName,
  300. dThreshold );
  301. if ( SUCCEEDED (hr ) ) {
  302. // Validate threshold value
  303. if ( 0.0 >= dThreshold ) {
  304. dwStatus = LOGMAN_REQUIRED_PROP_INVALID;
  305. }
  306. } else {
  307. dwStatus = LOGMAN_REQUIRED_PROP_MISSING;
  308. break;
  309. }
  310. }
  311. } // else invalid log type.
  312. } else {
  313. dwStatus = pUtils->GetMissingStatus ( dwPropId );
  314. break;
  315. }
  316. } // for dwIndex
  317. } else {
  318. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  319. }
  320. if ( ERROR_SUCCESS != dwStatus ) {
  321. // Display error, to include property name
  322. }
  323. } else {
  324. //Todo: Will need to display errors here, in order to include property name
  325. dwStatus = pUtils->GetMissingStatus ( dwPropId );
  326. }
  327. }
  328. // Todo: Display error messages.
  329. return dwStatus;
  330. }
  331. DWORD
  332. ValidateSlqTimeInfo (
  333. CPropertyUtils* pUtils,
  334. DWORD dwPropId,
  335. DWORD dwLogType )
  336. {
  337. DWORD dwStatus = ERROR_SUCCESS;
  338. HRESULT hr = NOERROR;
  339. SLQ_TIME_INFO stiData;
  340. SLQ_TIME_INFO stiDefault;
  341. WORD wTimeType;
  342. LONGLONG llmsecs;
  343. if ( IdRestartProp == dwPropId ) {
  344. dwStatus = ValidateDwordInterval ( pUtils, dwPropId, dwLogType );
  345. } else {
  346. assert ( IdStartProp == dwPropId
  347. || IdStopProp == dwPropId
  348. || IdSampleProp == dwPropId );
  349. if ( IdStartProp == dwPropId ) {
  350. wTimeType = SLQ_TT_TTYPE_START;
  351. } else if ( IdStopProp == dwPropId ) {
  352. wTimeType = SLQ_TT_TTYPE_STOP;
  353. } else {
  354. assert ( IdSampleProp == dwPropId );
  355. wTimeType = SLQ_TT_TTYPE_SAMPLE;
  356. }
  357. // Initialize time structure to default, in case of missing fields.
  358. hr = InitDefaultSlqTimeInfo (
  359. dwLogType,
  360. wTimeType,
  361. &stiDefault );
  362. if ( SUCCEEDED ( hr ) ) {
  363. ZeroMemory ( &stiData, sizeof(stiData) );
  364. hr = SlqTimeFromPropertyBag (
  365. pUtils->m_pPropBag,
  366. wTimeType,
  367. &stiDefault,
  368. &stiData );
  369. if ( SUCCEEDED ( hr ) ) {
  370. if ( IdStartProp == dwPropId ) {
  371. if ( SLQ_AUTO_MODE_AT == stiData.dwAutoMode ) {
  372. if ( !pUtils->IsValidDateTime ( stiData.llDateTime ) ) {
  373. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  374. }
  375. } else if ( SLQ_AUTO_MODE_NONE == stiData.dwAutoMode ) {
  376. if ( MIN_TIME_VALUE != stiData.llDateTime
  377. && MAX_TIME_VALUE != stiData.llDateTime ) {
  378. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  379. }
  380. } else {
  381. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  382. }
  383. } else if ( IdStopProp == dwPropId ) {
  384. if ( SLQ_AUTO_MODE_AT == stiData.dwAutoMode ) {
  385. if ( !pUtils->IsValidDateTime ( stiData.llDateTime ) ) {
  386. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  387. }
  388. // Todo: Ensure stop is after start time.
  389. // Todo: Ensure stop is after current time.
  390. // Todo: Ensure session time is >= Sample time
  391. } else if ( SLQ_AUTO_MODE_NONE == stiData.dwAutoMode ) {
  392. if ( MIN_TIME_VALUE != stiData.llDateTime
  393. && MAX_TIME_VALUE != stiData.llDateTime ) {
  394. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  395. }
  396. } else if ( SLQ_AUTO_MODE_AFTER == stiData.dwAutoMode ) {
  397. if ( SLQ_TT_UTYPE_SECONDS > stiData.dwUnitType
  398. || SLQ_TT_UTYPE_DAYS < stiData.dwUnitType ) {
  399. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  400. } else {
  401. if ( 1 > stiData.dwValue
  402. || 100000 < stiData.dwValue ) {
  403. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  404. }
  405. }
  406. } else {
  407. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  408. }
  409. } else {
  410. assert ( IdSampleProp == dwPropId );
  411. if ( SLQ_TT_UTYPE_SECONDS > stiData.dwUnitType
  412. || SLQ_TT_UTYPE_DAYS < stiData.dwUnitType ) {
  413. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  414. } else {
  415. // Sample time interval must be less than or equal to 45 days.
  416. if ( SlqTimeToMilliseconds ( &stiData, &llmsecs ) ) {
  417. if ( cdwFortyfiveDays < llmsecs ) {
  418. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  419. } else {
  420. // Todo: Ensure session time is >= Sample time
  421. }
  422. } else {
  423. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  424. }
  425. }
  426. }
  427. } else {
  428. dwStatus = pUtils->GetMissingStatus ( dwPropId );
  429. }
  430. }
  431. }
  432. // Todo: Display error messages here.
  433. return dwStatus;
  434. }
  435. DWORD
  436. ValidateMaxFileSize (
  437. CPropertyUtils* pUtils,
  438. DWORD dwPropId,
  439. DWORD /* dwLogType */ )
  440. {
  441. DWORD dwStatus = ERROR_SUCCESS;
  442. HRESULT hr;
  443. DWORD dwValue;
  444. hr = DwordFromPropertyBag (
  445. pUtils->m_pPropBag,
  446. CPropertyUtils::m_PropertyDataMap[dwPropId].cwszHtmlName,
  447. dwValue );
  448. if ( SUCCEEDED ( hr ) ) {
  449. if ( cdwNoMaxSizeLimit != dwValue ) {
  450. if ( ( dwValue < CPropertyUtils::m_PropertyDataMap[dwPropId].dwMin )
  451. || (dwValue > CPropertyUtils::m_PropertyDataMap[dwPropId].dwMax ) ) {
  452. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  453. }
  454. } else {
  455. hr = DwordFromPropertyBag (
  456. pUtils->m_pPropBag,
  457. CPropertyUtils::m_PropertyDataMap[IdLogFileTypeProp].cwszHtmlName,
  458. dwValue );
  459. if ( SUCCEEDED ( hr ) ) {
  460. if ( SLF_BIN_CIRC_FILE == dwValue
  461. || SLF_CIRC_TRACE_FILE == dwValue ) {
  462. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  463. }
  464. } // else, default file type is not circular, so not a problem.
  465. }
  466. } else {
  467. dwStatus = pUtils->GetMissingStatus ( dwPropId );
  468. }
  469. // Todo: Display error messages here.
  470. return dwStatus;
  471. }
  472. DWORD
  473. ValidateLogFileType (
  474. CPropertyUtils* pUtils,
  475. DWORD dwPropId,
  476. DWORD dwLogType )
  477. {
  478. DWORD dwStatus = ERROR_SUCCESS;
  479. HRESULT hr;
  480. DWORD dwValue;
  481. assert ( IdLogFileTypeProp == dwPropId );
  482. hr = DwordFromPropertyBag (
  483. pUtils->m_pPropBag,
  484. CPropertyUtils::m_PropertyDataMap[dwPropId].cwszHtmlName,
  485. dwValue );
  486. if ( SUCCEEDED ( hr ) ) {
  487. if ( SLQ_COUNTER_LOG == dwLogType ) {
  488. if ( SLF_CSV_FILE != dwValue
  489. && SLF_TSV_FILE != dwValue
  490. && SLF_BIN_FILE != dwValue
  491. && SLF_BIN_CIRC_FILE != dwValue ) {
  492. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  493. }
  494. } else if ( SLQ_TRACE_LOG == dwLogType ) {
  495. if ( SLF_CIRC_TRACE_FILE != dwValue
  496. && SLF_SEQ_TRACE_FILE != dwValue ) {
  497. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  498. }
  499. } else {
  500. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  501. }
  502. } else {
  503. dwStatus = pUtils->GetMissingStatus ( dwPropId );
  504. }
  505. // Todo: Display error messages here.
  506. return dwStatus;
  507. }
  508. DWORD
  509. ValidateString (
  510. CPropertyUtils* pUtils,
  511. DWORD dwPropId,
  512. DWORD /* dwLogType */)
  513. {
  514. DWORD dwStatus = ERROR_SUCCESS;
  515. HRESULT hr = NOERROR;
  516. DWORD dwPropBagStringLen = 0;
  517. hr = StringFromPropBagAlloc (
  518. pUtils->m_pPropBag,
  519. CPropertyUtils::m_PropertyDataMap[dwPropId].cwszHtmlName,
  520. &pUtils->m_szPropBagBuffer,
  521. &pUtils->m_dwPropBagBufLen,
  522. &dwPropBagStringLen );
  523. // Just check for missing or empty string.
  524. if ( SUCCEEDED ( hr ) ) {
  525. if ( NULL == pUtils->m_szPropBagBuffer ) {
  526. dwStatus = pUtils->GetMissingStatus ( dwPropId );
  527. } else {
  528. if ( 0 == lstrlenW ( pUtils->m_szPropBagBuffer ) ) {
  529. dwStatus = pUtils->GetMissingStatus ( dwPropId );
  530. }
  531. }
  532. } else {
  533. dwStatus = pUtils->GetMissingStatus ( dwPropId );
  534. }
  535. // Todo: Display error messages here.
  536. return dwStatus;
  537. }
  538. DWORD
  539. ValidateTraceFlags (
  540. CPropertyUtils* pUtils,
  541. DWORD dwPropId,
  542. DWORD dwLogType )
  543. {
  544. DWORD dwStatus = ERROR_SUCCESS;
  545. HRESULT hr;
  546. DWORD dwValue;
  547. if ( IdTraceFlagsProp == dwPropId && SLQ_TRACE_LOG != dwLogType ) {
  548. assert ( FALSE );
  549. dwStatus = ERROR_INVALID_PARAMETER;
  550. } else {
  551. hr = DwordFromPropertyBag (
  552. pUtils->m_pPropBag,
  553. CPropertyUtils::m_PropertyDataMap[dwPropId].cwszHtmlName,
  554. dwValue );
  555. if ( SUCCEEDED ( hr ) ) {
  556. if ( SLQ_TLI_ENABLE_MASK != ( dwValue | SLQ_TLI_ENABLE_MASK ) ) {
  557. // Too many flags specified.
  558. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  559. }
  560. } else {
  561. dwStatus = pUtils->GetMissingStatus ( dwPropId );
  562. }
  563. }
  564. // Todo: Display error messages here.
  565. return dwStatus;
  566. }
  567. DWORD
  568. ValidateAlertActions (
  569. CPropertyUtils* pUtils,
  570. DWORD dwPropId,
  571. DWORD dwLogType )
  572. {
  573. DWORD dwStatus = ERROR_SUCCESS;
  574. HRESULT hr;
  575. DWORD dwValue;
  576. if ( IdActionFlagsProp == dwPropId && SLQ_ALERT != dwLogType ) {
  577. assert ( FALSE );
  578. dwStatus = ERROR_INVALID_PARAMETER;
  579. } else {
  580. hr = DwordFromPropertyBag (
  581. pUtils->m_pPropBag,
  582. CPropertyUtils::m_PropertyDataMap[dwPropId].cwszHtmlName,
  583. dwValue );
  584. if ( SUCCEEDED ( hr ) ) {
  585. if ( IdActionFlagsProp == dwPropId ) {
  586. // Todo: Validate, and check for empty fields. Yes.
  587. if ( (0 == dwValue )
  588. || ( ALRT_ACTION_MASK != ( dwValue | ALRT_ACTION_MASK ) ) ) {
  589. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  590. }
  591. // No validation for ALRT_ACTION_LOG_EVENT
  592. if ( ERROR_SUCCESS == dwStatus ) {
  593. if ( ALRT_ACTION_SEND_MSG & dwValue ) {
  594. dwStatus = pUtils->Validate ( IdNetworkNameProp );
  595. }
  596. if ( ALRT_ACTION_START_LOG & dwValue ) {
  597. /*
  598. // Todo: Validate log existence
  599. dwIndividualStatus =
  600. if ( ERROR_SUCCESS != dwIndividualStatus ) {
  601. dwStatus = general failure status
  602. }
  603. }
  604. */
  605. }
  606. if ( ALRT_ACTION_EXEC_CMD & dwValue ) {
  607. // Todo: Validate command file
  608. if ( 0 == ( dwValue | ALRT_CMD_LINE_MASK ) ) {
  609. //dwLocalStatus = pUtils->GetInvalidStatus ( dwPropId );
  610. // Todo: Display error message here.
  611. }
  612. }
  613. }
  614. } else {
  615. assert ( FALSE );
  616. hr = E_INVALIDARG;
  617. }
  618. } else {
  619. dwStatus = pUtils->GetMissingStatus ( dwPropId );
  620. }
  621. }
  622. // Todo: Display error messages here.
  623. return dwStatus;
  624. }
  625. DWORD
  626. ValidateDirectoryPath (
  627. CPropertyUtils* pUtils,
  628. DWORD dwPropId,
  629. DWORD dwLogType )
  630. {
  631. DWORD dwStatus = ERROR_SUCCESS;
  632. // Todo: Implement
  633. // Validate the existence of the directory path, if local machine?
  634. pUtils;
  635. dwPropId;
  636. dwLogType;
  637. // Todo: Display error messages here.
  638. return dwStatus;
  639. }
  640. DWORD
  641. ValidateTraceBufferMaxCount (
  642. CPropertyUtils* pUtils,
  643. DWORD dwPropId,
  644. DWORD dwLogType )
  645. {
  646. DWORD dwStatus = ERROR_SUCCESS;
  647. HRESULT hr;
  648. DWORD dwMaxValue;
  649. DWORD dwMinValue;
  650. if ( SLQ_TRACE_LOG == dwLogType
  651. && IdTraceBufferMaxCountProp == dwPropId ) {
  652. hr = DwordFromPropertyBag (
  653. pUtils->m_pPropBag,
  654. CPropertyUtils::m_PropertyDataMap[dwPropId].cwszHtmlName,
  655. dwMaxValue );
  656. if ( SUCCEEDED ( hr ) ) {
  657. if ( ( dwMaxValue < CPropertyUtils::m_PropertyDataMap[dwPropId].dwMin )
  658. || (dwMaxValue > CPropertyUtils::m_PropertyDataMap[dwPropId].dwMax ) ) {
  659. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  660. } else {
  661. hr = DwordFromPropertyBag (
  662. pUtils->m_pPropBag,
  663. CPropertyUtils::m_PropertyDataMap[IdTraceBufferMinCountProp].cwszHtmlName,
  664. dwMinValue );
  665. if ( SUCCEEDED ( hr ) ) {
  666. if ( dwMinValue > dwMaxValue ) {
  667. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  668. }
  669. } // else no min value specified, and default min is always <= max
  670. }
  671. } else {
  672. dwStatus = pUtils->GetMissingStatus ( dwPropId );
  673. }
  674. } else {
  675. assert ( FALSE );
  676. hr = E_INVALIDARG;
  677. }
  678. // Todo: Display error messages here.
  679. return dwStatus;
  680. }
  681. DWORD
  682. ValidateFileName (
  683. CPropertyUtils* pUtils,
  684. DWORD dwPropId,
  685. DWORD /* dwLogType */ )
  686. {
  687. DWORD dwStatus = ERROR_SUCCESS;
  688. HRESULT hr = NOERROR;
  689. DWORD dwPropBagStringLen = 0;
  690. if ( NULL != pUtils ) {
  691. hr = StringFromPropBagAlloc (
  692. pUtils->m_pPropBag,
  693. CPropertyUtils::m_PropertyDataMap[dwPropId].cwszHtmlName,
  694. &pUtils->m_szPropBagBuffer,
  695. &pUtils->m_dwPropBagBufLen,
  696. &dwPropBagStringLen );
  697. if ( SUCCEEDED ( hr ) ) {
  698. if ( 0 != dwPropBagStringLen ) {
  699. if ( !IsValidFileName ( pUtils->m_szPropBagBuffer ) ) {
  700. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  701. }
  702. } else {
  703. dwStatus = pUtils->GetMissingStatus ( dwPropId );
  704. }
  705. } else {
  706. dwStatus = pUtils->GetMissingStatus ( dwPropId );
  707. }
  708. } else {
  709. assert ( FALSE );
  710. dwStatus = ERROR_INVALID_PARAMETER;
  711. }
  712. // Todo: Display error messages here.
  713. return dwStatus;
  714. }
  715. DWORD
  716. ValidateFilePath (
  717. CPropertyUtils* pUtils,
  718. DWORD dwPropId,
  719. DWORD /* dwLogType */ )
  720. {
  721. DWORD dwStatus = ERROR_SUCCESS;
  722. HRESULT hr = NOERROR;
  723. DWORD dwPropBagStringLen = 0;
  724. HANDLE hOpenFile = NULL;
  725. if ( NULL != pUtils ) {
  726. hr = StringFromPropBagAlloc (
  727. pUtils->m_pPropBag,
  728. CPropertyUtils::m_PropertyDataMap[dwPropId].cwszHtmlName,
  729. &pUtils->m_szPropBagBuffer,
  730. &pUtils->m_dwPropBagBufLen,
  731. &dwPropBagStringLen );
  732. if ( SUCCEEDED ( hr ) ) {
  733. if ( 0 != dwPropBagStringLen ) {
  734. hOpenFile = CreateFileW (
  735. pUtils->m_szPropBagBuffer,
  736. GENERIC_READ,
  737. 0, // Not shared
  738. NULL, // Security attributes
  739. OPEN_EXISTING, //
  740. FILE_ATTRIBUTE_NORMAL,
  741. NULL );
  742. if ( ( NULL == hOpenFile )
  743. || INVALID_HANDLE_VALUE == hOpenFile ) {
  744. dwStatus = pUtils->GetInvalidStatus ( dwPropId );
  745. } else {
  746. CloseHandle( hOpenFile );
  747. }
  748. } else {
  749. dwStatus = pUtils->GetMissingStatus ( dwPropId );
  750. }
  751. } else {
  752. dwStatus = pUtils->GetMissingStatus ( dwPropId );
  753. }
  754. } else {
  755. assert ( FALSE );
  756. dwStatus = ERROR_INVALID_PARAMETER;
  757. }
  758. // Todo: Display error messages here.
  759. return dwStatus;
  760. }
  761. DWORD
  762. ValidateLogExists (
  763. CPropertyUtils* pUtils,
  764. DWORD dwPropId,
  765. DWORD dwLogType )
  766. {
  767. DWORD dwStatus = ERROR_SUCCESS;
  768. // Todo: Implement. Check via m_hkeyQueries
  769. pUtils;
  770. dwPropId;
  771. dwLogType;
  772. // Todo: Display error messages here.
  773. return dwStatus;
  774. }
  775. /*
  776. * CPropertyUtils::CPropertyUtils
  777. *
  778. * Purpose:
  779. * Constructor.
  780. *
  781. * Return Value:
  782. */
  783. CPropertyUtils::CPropertyUtils (
  784. LPCWSTR cszMachineName,
  785. LPCWSTR cszQueryName,
  786. CPropertyBag* pPropBag,
  787. HKEY hkeyQuery,
  788. HKEY hkeyQueryList )
  789. : m_szPropBagBuffer ( NULL ),
  790. m_dwPropBagBufLen ( 0 ),
  791. m_pPropBag ( pPropBag ),
  792. m_hkeyQuery ( hkeyQuery ),
  793. m_hkeyQueryList ( hkeyQueryList ),
  794. m_eMessageDisplayLevel ( eWarnings )
  795. {
  796. if ( NULL != cszMachineName ) {
  797. lstrcpynW ( m_szMachineName, cszMachineName, sizeof(m_szMachineName) );
  798. } else {
  799. m_szMachineName[0] = NULL_W;
  800. }
  801. if ( NULL != cszQueryName ) {
  802. lstrcpynW ( m_szQueryName, cszQueryName, sizeof(m_szQueryName) );
  803. } else {
  804. m_szQueryName[0] = NULL_W;
  805. }
  806. return;
  807. }
  808. /*
  809. * CPropertyUtils::CPropertyUtils
  810. *
  811. * Purpose:
  812. * Constructor.
  813. *
  814. * Return Value:
  815. */
  816. CPropertyUtils::CPropertyUtils ( LPCWSTR cszMachineName )
  817. : m_szPropBagBuffer ( NULL ),
  818. m_dwPropBagBufLen ( 0 ),
  819. m_pPropBag ( NULL ),
  820. m_hkeyQuery ( NULL ),
  821. m_hkeyQueryList ( NULL ),
  822. m_eMessageDisplayLevel ( eWarnings )
  823. {
  824. if ( NULL != cszMachineName ) {
  825. lstrcpynW ( m_szMachineName, cszMachineName, sizeof(m_szMachineName) );
  826. } else {
  827. m_szMachineName[0] = NULL_W;
  828. }
  829. m_szQueryName[0] = NULL_W;
  830. return;
  831. }
  832. /*
  833. * CPropertyUtils::~CPropertyUtils
  834. *
  835. * Purpose:
  836. * Destructor.
  837. *
  838. * Return Value:
  839. */
  840. CPropertyUtils::~CPropertyUtils ( void )
  841. {
  842. if ( NULL != m_szPropBagBuffer ) {
  843. delete m_szPropBagBuffer;
  844. }
  845. return;
  846. }
  847. //
  848. // Public methods
  849. //
  850. void
  851. CPropertyUtils::SetQueryName ( LPCWSTR szQueryName )
  852. {
  853. assert ( NULL != szQueryName );
  854. if ( NULL != szQueryName ) {
  855. lstrcpynW ( m_szQueryName, szQueryName, sizeof(m_szQueryName) );
  856. }
  857. }
  858. LPCWSTR
  859. CPropertyUtils::GetQueryName ( void )
  860. {
  861. return m_szQueryName;
  862. }
  863. void
  864. CPropertyUtils::SetPropertyBag ( CPropertyBag* pPropBag )
  865. {
  866. m_pPropBag = pPropBag;
  867. }
  868. void
  869. CPropertyUtils::SetQueryKey ( HKEY hkeyQuery )
  870. {
  871. m_hkeyQuery = hkeyQuery;
  872. }
  873. void
  874. CPropertyUtils::SetQueryListKey ( HKEY hkeyQueryList )
  875. {
  876. m_hkeyQueryList = hkeyQueryList;
  877. }
  878. void
  879. CPropertyUtils::SetMessageDisplayLevel ( eMessageDisplayLevel eLevel )
  880. {
  881. m_eMessageDisplayLevel = eLevel;
  882. }
  883. CPropertyUtils::eMessageDisplayLevel
  884. CPropertyUtils::GetMessageDisplayLevel ( void )
  885. {
  886. return m_eMessageDisplayLevel;
  887. }
  888. DWORD
  889. CPropertyUtils::Validate (
  890. DWORD dwPropId,
  891. DWORD dwLogType )
  892. {
  893. DWORD dwStatus = ERROR_INVALID_PARAMETER;
  894. assert ( NULL != m_pPropBag );
  895. assert ( ( IdFirstProp <= dwPropId ) && ( IdLastProp >= dwPropId ) );
  896. if ( NULL != m_pPropBag ) {
  897. if ( ( IdFirstProp <= dwPropId )
  898. && ( IdLastProp >= dwPropId ) ) {
  899. if ( NULL != m_PropertyDataMap[dwPropId].fValidate ) {
  900. dwStatus = m_PropertyDataMap[dwPropId].fValidate ( this, dwPropId, dwLogType );
  901. }
  902. }
  903. }
  904. return dwStatus;
  905. }
  906. HRESULT
  907. CPropertyUtils::BagToRegistry (
  908. DWORD dwPropId,
  909. DWORD dwLogType )
  910. {
  911. HRESULT hr = NOERROR;
  912. if ( ( IdFirstProp > dwPropId )
  913. || ( IdLastProp < dwPropId ) ) {
  914. assert ( FALSE );
  915. hr = E_INVALIDARG;
  916. } else if ( NULL == m_pPropBag || NULL == m_hkeyQuery ) {
  917. assert ( FALSE );
  918. hr = E_POINTER;
  919. } else {
  920. switch ( m_PropertyDataMap[dwPropId].dwRegType ) {
  921. case REG_SZ:
  922. hr = StringBagToRegistry ( dwPropId, dwLogType );
  923. break;
  924. case REG_BINARY:
  925. hr = SlqTimeBagToRegistry ( dwPropId, dwLogType );
  926. break;
  927. case REG_DWORD:
  928. hr = DwordBagToRegistry ( dwPropId, dwLogType );
  929. break;
  930. case REG_MULTI_SZ:
  931. hr = MultiSzBagToRegistry ( dwPropId, dwLogType );
  932. break;
  933. default:
  934. hr = E_FAIL;
  935. }
  936. }
  937. return hr;
  938. }
  939. //
  940. // Private methods
  941. //
  942. HRESULT
  943. CPropertyUtils::MultiSzBagToBufferAlloc (
  944. DWORD dwPropId,
  945. DWORD dwLogType,
  946. LPWSTR* pszMszBuf,
  947. DWORD* pdwMszBufLen,
  948. DWORD* pdwMszStringLen )
  949. {
  950. HRESULT hr = NOERROR;
  951. DWORD dwStatus = ERROR_SUCCESS;
  952. DWORD dwCount = 0;
  953. LPCWSTR szHtmlCountProp = NULL;
  954. LPCWSTR szHtmlPathProp = NULL;
  955. if ( IdCounterListProp == dwPropId ) {
  956. if ( SLQ_COUNTER_LOG == dwLogType
  957. || SLQ_ALERT == dwLogType ) {
  958. szHtmlCountProp = cwszHtmlSysmonCounterCount;
  959. szHtmlPathProp = cwszHtmlSysmonCounterPath;
  960. } else {
  961. assert ( FALSE );
  962. hr = E_INVALIDARG;
  963. }
  964. } else if ( IdGuidListProp == dwPropId ) {
  965. if ( SLQ_TRACE_LOG == dwLogType ) {
  966. szHtmlCountProp = cwszHtmlTraceProviderCount;
  967. szHtmlPathProp = cwszHtmlTraceProviderGuid;
  968. } else {
  969. assert ( FALSE );
  970. hr = E_INVALIDARG;
  971. }
  972. } else {
  973. assert ( FALSE );
  974. hr = E_INVALIDARG;
  975. }
  976. if ( SUCCEEDED ( hr ) ) {
  977. hr = DwordFromPropertyBag (
  978. m_pPropBag,
  979. szHtmlCountProp,
  980. dwCount ); // Todo: Require counter count? Yes for now
  981. if ( SUCCEEDED ( hr ) ) {
  982. DWORD dwIndex;
  983. DWORD dwPropBagStringLen = 0;
  984. assert ( 0 < dwCount );
  985. for ( dwIndex = 1;
  986. dwIndex <= dwCount && SUCCEEDED ( hr );
  987. dwIndex++ ) {
  988. WCHAR szPropName [MAX_PATH+1]; // Todo: Remove length restriction
  989. swprintf ( szPropName, szHtmlPathProp, dwIndex );
  990. hr = StringFromPropBagAlloc (
  991. m_pPropBag,
  992. szPropName,
  993. &m_szPropBagBuffer,
  994. &m_dwPropBagBufLen,
  995. &dwPropBagStringLen );
  996. if ( SUCCEEDED (hr ) ) {
  997. if ( SLQ_ALERT != dwLogType ) {
  998. dwStatus = AddStringToMszBufferAlloc (
  999. m_szPropBagBuffer,
  1000. pszMszBuf,
  1001. pdwMszBufLen,
  1002. pdwMszStringLen );
  1003. if ( ERROR_SUCCESS != dwStatus ) {
  1004. hr = HRESULT_FROM_WIN32 ( dwStatus );
  1005. }
  1006. } else {
  1007. DWORD dwTemp;
  1008. DOUBLE dThreshold = 0;
  1009. WCHAR szAlert [MAX_PATH*2]; // Todo: Remove length restriction
  1010. swprintf ( szPropName, cwszHtmlAlertOverUnder, dwIndex );
  1011. hr = DwordFromPropertyBag (
  1012. m_pPropBag,
  1013. szPropName,
  1014. dwTemp );
  1015. if ( SUCCEEDED (hr ) ) {
  1016. swprintf ( szPropName, cwszHtmlAlertThreshold, dwIndex );
  1017. hr = DoubleFromPropertyBag (
  1018. m_pPropBag,
  1019. szPropName,
  1020. dThreshold );
  1021. if ( SUCCEEDED ( hr ) ) {
  1022. swprintf (
  1023. szAlert,
  1024. cwszAlertFormatString,
  1025. m_szPropBagBuffer,
  1026. ( AIBF_OVER == (dwTemp&AIBF_OVER ) ) ? cwszGreaterThan : cwszLessThan,
  1027. dThreshold );
  1028. dwStatus = AddStringToMszBufferAlloc (
  1029. szAlert,
  1030. pszMszBuf,
  1031. pdwMszBufLen,
  1032. pdwMszStringLen );
  1033. if ( ERROR_SUCCESS != dwStatus ) {
  1034. hr = HRESULT_FROM_WIN32 ( dwStatus );
  1035. }
  1036. }
  1037. }
  1038. }
  1039. }
  1040. }
  1041. }
  1042. }
  1043. return hr;
  1044. }
  1045. HRESULT
  1046. CPropertyUtils::MultiSzBagToRegistry (
  1047. DWORD dwPropId,
  1048. DWORD dwLogType )
  1049. {
  1050. HRESULT hr = NOERROR;
  1051. DWORD dwStatus = ERROR_SUCCESS;
  1052. LPWSTR szMszBuf = NULL;
  1053. DWORD dwMszBufLen = 0;
  1054. DWORD dwMszStringLen = 0;
  1055. LPCWSTR szRegListProp = NULL;
  1056. if ( IdCounterListProp == dwPropId ) {
  1057. if ( SLQ_COUNTER_LOG == dwLogType
  1058. || SLQ_ALERT == dwLogType ) {
  1059. szRegListProp = cwszRegCounterList;
  1060. } else {
  1061. assert ( FALSE );
  1062. hr = E_INVALIDARG;
  1063. }
  1064. } else if ( IdGuidListProp == dwPropId ) {
  1065. if ( SLQ_TRACE_LOG == dwLogType ) {
  1066. szRegListProp = cwszRegTraceProviderList;
  1067. } else {
  1068. assert ( FALSE );
  1069. hr = E_INVALIDARG;
  1070. }
  1071. } else {
  1072. assert ( FALSE );
  1073. hr = E_INVALIDARG;
  1074. }
  1075. if ( SUCCEEDED ( hr ) ) {
  1076. hr = MultiSzBagToBufferAlloc (
  1077. dwPropId,
  1078. dwLogType,
  1079. &szMszBuf,
  1080. &dwMszBufLen,
  1081. &dwMszStringLen );
  1082. if ( SUCCEEDED ( hr ) ) {
  1083. // Write buffer to the registry
  1084. if ( SUCCEEDED ( hr ) ) {
  1085. dwStatus = WriteRegistryStringValue (
  1086. m_hkeyQuery,
  1087. szRegListProp,
  1088. REG_MULTI_SZ,
  1089. szMszBuf,
  1090. dwMszStringLen );
  1091. if ( ERROR_SUCCESS != dwStatus ) {
  1092. hr = HRESULT_FROM_WIN32 ( dwStatus );
  1093. }
  1094. }
  1095. }
  1096. }
  1097. if ( NULL != szMszBuf ) {
  1098. delete szMszBuf;
  1099. }
  1100. return hr;
  1101. }
  1102. HRESULT
  1103. CPropertyUtils::StringBagToRegistry (
  1104. DWORD dwPropId,
  1105. DWORD /* dwLogType */ )
  1106. {
  1107. HRESULT hr = NOERROR;
  1108. DWORD dwStatus = ERROR_SUCCESS;
  1109. DWORD dwStringLen = 0;
  1110. hr = StringFromPropBagAlloc (
  1111. m_pPropBag,
  1112. m_PropertyDataMap[dwPropId].cwszHtmlName,
  1113. &m_szPropBagBuffer,
  1114. &m_dwPropBagBufLen,
  1115. &dwStringLen );
  1116. if ( SUCCEEDED ( hr ) && 0 != m_dwPropBagBufLen ) {
  1117. dwStatus = WriteRegistryStringValue (
  1118. m_hkeyQuery,
  1119. m_PropertyDataMap[dwPropId].cwszRegName,
  1120. m_PropertyDataMap[dwPropId].dwRegType,
  1121. m_szPropBagBuffer,
  1122. dwStringLen );
  1123. if ( ERROR_SUCCESS != dwStatus ) {
  1124. hr = HRESULT_FROM_WIN32 ( dwStatus );
  1125. }
  1126. }
  1127. return hr;
  1128. }
  1129. HRESULT
  1130. CPropertyUtils::DwordBagToRegistry (
  1131. DWORD dwPropId,
  1132. DWORD /* dwLogType */ )
  1133. {
  1134. HRESULT hr = NOERROR;
  1135. DWORD dwValue = 0;
  1136. hr = DwordFromPropertyBag (
  1137. m_pPropBag,
  1138. m_PropertyDataMap[dwPropId].cwszHtmlName,
  1139. dwValue );
  1140. if ( SUCCEEDED ( hr ) ) {
  1141. DWORD dwStatus;
  1142. dwStatus = WriteRegistryDwordValue (
  1143. m_hkeyQuery,
  1144. m_PropertyDataMap[dwPropId].cwszRegName,
  1145. &dwValue,
  1146. m_PropertyDataMap[dwPropId].dwRegType); // Some values, e.g. Restart, are REG_BINARY
  1147. if ( ERROR_SUCCESS != dwStatus ) {
  1148. hr = HRESULT_FROM_WIN32 ( dwStatus );
  1149. }
  1150. }
  1151. return hr;
  1152. }
  1153. HRESULT
  1154. CPropertyUtils::SlqTimeBagToRegistry (
  1155. DWORD dwPropId,
  1156. DWORD dwLogType )
  1157. {
  1158. HRESULT hr = NOERROR;
  1159. DWORD dwStatus = ERROR_SUCCESS;
  1160. SLQ_TIME_INFO stiData;
  1161. SLQ_TIME_INFO stiDefault;
  1162. LPCWSTR cwszRegPropName;
  1163. WORD wTimeType;
  1164. assert ( IdRestartProp == dwPropId
  1165. || IdStartProp == dwPropId
  1166. || IdStopProp == dwPropId
  1167. || IdSampleProp == dwPropId );
  1168. if ( IdRestartProp == dwPropId ) {
  1169. // Dword processing can handle REG_BINARY as well.
  1170. hr = DwordBagToRegistry ( dwPropId, dwLogType );
  1171. } else {
  1172. assert ( IdStartProp == dwPropId
  1173. || IdStopProp == dwPropId
  1174. || IdSampleProp == dwPropId );
  1175. if ( IdStartProp == dwPropId ) {
  1176. wTimeType = SLQ_TT_TTYPE_START;
  1177. cwszRegPropName = cwszRegStartTime;
  1178. } else if ( IdStopProp == dwPropId ) {
  1179. wTimeType = SLQ_TT_TTYPE_STOP;
  1180. cwszRegPropName = cwszRegStopTime;
  1181. } else {
  1182. assert ( IdSampleProp == dwPropId );
  1183. wTimeType = SLQ_TT_TTYPE_SAMPLE;
  1184. cwszRegPropName = cwszRegSampleInterval;
  1185. }
  1186. // Initialize time structure to default, in case of missing fields.
  1187. hr = InitDefaultSlqTimeInfo (
  1188. dwLogType,
  1189. wTimeType,
  1190. &stiDefault );
  1191. if ( SUCCEEDED ( hr ) ) {
  1192. ZeroMemory ( &stiData, sizeof(stiData) );
  1193. hr = SlqTimeFromPropertyBag (
  1194. m_pPropBag,
  1195. wTimeType,
  1196. &stiDefault,
  1197. &stiData );
  1198. if ( SUCCEEDED ( hr ) ) {
  1199. dwStatus = WriteRegistrySlqTime (
  1200. m_hkeyQuery,
  1201. cwszRegPropName,
  1202. &stiData );
  1203. if ( ERROR_SUCCESS != dwStatus ) {
  1204. hr = HRESULT_FROM_WIN32 ( dwStatus );
  1205. }
  1206. }
  1207. }
  1208. }
  1209. return hr;
  1210. }
  1211. DWORD
  1212. CPropertyUtils::GetInvalidStatus (
  1213. DWORD dwPropId )
  1214. {
  1215. DWORD dwStatus;
  1216. if ( CPropertyUtils::m_PropertyDataMap[dwPropId].bRequired ) {
  1217. dwStatus = LOGMAN_REQUIRED_PROP_INVALID;
  1218. } else {
  1219. dwStatus = LOGMAN_NONREQ_PROP_INVALID;
  1220. }
  1221. return dwStatus;
  1222. }
  1223. DWORD
  1224. CPropertyUtils::GetMissingStatus (
  1225. DWORD dwPropId )
  1226. {
  1227. DWORD dwStatus;
  1228. if ( CPropertyUtils::m_PropertyDataMap[dwPropId].bRequired ) {
  1229. dwStatus = LOGMAN_REQUIRED_PROP_MISSING;
  1230. } else {
  1231. dwStatus = LOGMAN_NONREQ_PROP_MISSING;
  1232. }
  1233. return dwStatus;
  1234. }
  1235. BOOL
  1236. CPropertyUtils::IsValidDateTime (
  1237. LONGLONG& rllDateTime )
  1238. {
  1239. BOOL bIsValid = TRUE;
  1240. SYSTEMTIME SystemTime;
  1241. // Make sure that the date is reasonable. That is, not before 10/99
  1242. if (FileTimeToSystemTime((FILETIME*)&rllDateTime, &SystemTime)) {
  1243. if ( cwFirstValidYear > SystemTime.wYear ) {
  1244. bIsValid = FALSE;
  1245. }
  1246. } else {
  1247. bIsValid = FALSE;
  1248. }
  1249. return bIsValid;
  1250. }
  1251. BOOL
  1252. CPropertyUtils::IsKernelTraceMode (
  1253. IN DWORD dwTraceFlags )
  1254. {
  1255. BOOL bReturn;
  1256. bReturn = ( SLQ_TLI_ENABLE_KERNEL_MASK & dwTraceFlags ) ? TRUE : FALSE;
  1257. return bReturn;
  1258. }
  1259. BOOL
  1260. CPropertyUtils::IsDisplayLevelMessage (
  1261. IN DWORD dwStatus )
  1262. {
  1263. BOOL bDisplay = FALSE;
  1264. DWORD dwSeverity = 0;
  1265. dwSeverity = dwStatus >> 30;
  1266. if ( dwSeverity >= (DWORD)m_eMessageDisplayLevel ) {
  1267. bDisplay = TRUE;
  1268. }
  1269. return bDisplay;
  1270. }