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.

1032 lines
31 KiB

  1. /*++
  2. Copyright (C) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. smproppg.cpp
  5. Abstract:
  6. Implementation of the property page base class.
  7. --*/
  8. #include "stdafx.h"
  9. #include <wbemidl.h>
  10. #include "smcfgmsg.h"
  11. #include "smlogs.h"
  12. #include "smproppg.h"
  13. #include "dialogs.h"
  14. #include <pdhp.h>
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. USE_HANDLE_MACROS("SMLOGCFG(smproppg.cpp)");
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CSmPropertyPage property page
  23. IMPLEMENT_DYNCREATE ( CSmPropertyPage, CPropertyPage )
  24. CSmPropertyPage::CSmPropertyPage (
  25. UINT nIDTemplate,
  26. LONG_PTR hConsole,
  27. LPDATAOBJECT pDataObject )
  28. : CPropertyPage ( nIDTemplate ),
  29. m_uiIdTemplate (nIDTemplate ),
  30. m_bIsActive ( FALSE ),
  31. m_bIsModifiedPage ( FALSE ),
  32. m_pdwHelpIds ( NULL ),
  33. m_hConsole (hConsole ),
  34. m_pDataObject ( pDataObject ),
  35. m_bCanAccessRemoteWbem ( TRUE),
  36. m_pQuery ( NULL ),
  37. m_bPwdButtonEnabled ( TRUE)
  38. {
  39. //::OutputDebugStringA("\nCSmProperty::CSmPropertyPage");
  40. // Need to save the original callback pointer because we are replacing
  41. // it with our own
  42. m_pfnOriginalCallback = m_psp.pfnCallback;
  43. // This makes sure the MFC module states will work correctly
  44. MMCPropPageCallback( &m_psp );
  45. // EnableAutomation();
  46. //{{AFX_DATA_INIT(CSmPropertyPage)
  47. //}}AFX_DATA_INIT
  48. m_hModule = (HINSTANCE)GetModuleHandleW (_CONFIG_DLL_NAME_W_);
  49. }
  50. CSmPropertyPage::CSmPropertyPage() : CPropertyPage(0xfff) // Unused template IDD
  51. {
  52. ASSERT (FALSE); // the constructor w/ args should be used instead
  53. // //{{AFX_DATA_INIT(CSmPropertyPage)
  54. // //}}AFX_DATA_INIT
  55. }
  56. CSmPropertyPage::~CSmPropertyPage()
  57. {
  58. }
  59. BEGIN_MESSAGE_MAP(CSmPropertyPage, CPropertyPage)
  60. //{{AFX_MSG_MAP(CSmPropertyPage)
  61. ON_WM_HELPINFO()
  62. ON_WM_CONTEXTMENU()
  63. ON_MESSAGE(PSM_QUERYSIBLINGS, OnQuerySiblings)
  64. //}}AFX_MSG_MAP
  65. END_MESSAGE_MAP()
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CSmPropertyPage message handlers
  68. UINT CALLBACK CSmPropertyPage::PropSheetPageProc
  69. (
  70. HWND hWnd, // [in] Window handle - always null
  71. UINT uMsg, // [in,out] Either the create or delete message
  72. LPPROPSHEETPAGE pPsp // [in,out] Pointer to the property sheet struct
  73. )
  74. {
  75. ASSERT( NULL != pPsp );
  76. // We need to recover a pointer to the current instance. We can't just use
  77. // "this" because we are in a static function
  78. CSmPropertyPage* pMe = reinterpret_cast<CSmPropertyPage*>(pPsp->lParam);
  79. ASSERT( NULL != pMe );
  80. if (!pMe) return 0;
  81. switch( uMsg )
  82. {
  83. case PSPCB_CREATE:
  84. break;
  85. case PSPCB_RELEASE:
  86. // Since we are deleting ourselves, save a callback on the stack
  87. // so we can callback the base class
  88. //LPFNPSPCALLBACK pfnOrig = pMe->m_pfnOriginalCallback;
  89. delete pMe;
  90. return 1; //(pfnOrig)(hWnd, uMsg, pPsp);
  91. }
  92. // Must call the base class callback function or none of the MFC
  93. // message map stuff will work
  94. return (pMe->m_pfnOriginalCallback)(hWnd, uMsg, pPsp);
  95. } // end PropSheetPageProc()
  96. BOOL
  97. CSmPropertyPage::Initialize(CSmLogQuery* pQuery)
  98. {
  99. HRESULT hr;
  100. PPDH_PLA_INFO pInfo = NULL;
  101. DWORD dwInfoSize = 0;
  102. CString strMachineName;
  103. LPCWSTR pszMachineName = NULL;
  104. if ( NULL != pQuery ) {
  105. if (!pQuery->GetLogService()->IsLocalMachine()) {
  106. pszMachineName = pQuery->GetLogService()->GetMachineName();
  107. }
  108. hr = PdhPlaGetInfoW( (LPWSTR)(LPCWSTR)pQuery->GetLogName(),
  109. (LPWSTR)pszMachineName,
  110. &dwInfoSize,
  111. pInfo );
  112. if( ERROR_SUCCESS == hr && 0 != dwInfoSize ){
  113. pInfo = (PPDH_PLA_INFO)malloc(dwInfoSize);
  114. if( NULL != pInfo ) {
  115. if ( sizeof(PDH_PLA_INFO) <= dwInfoSize ) {
  116. pInfo->dwMask = PLA_INFO_FLAG_USER;
  117. hr = PdhPlaGetInfoW( (LPWSTR)(LPCWSTR)pQuery->GetLogName(),
  118. (LPWSTR)pszMachineName,
  119. &dwInfoSize,
  120. pInfo );
  121. if( ERROR_SUCCESS == hr ){
  122. pQuery->m_strUser = pInfo->strUser;
  123. }
  124. }
  125. free( pInfo );
  126. }
  127. pQuery->m_fDirtyPassword = PASSWORD_CLEAN;
  128. }
  129. }
  130. return TRUE;
  131. }
  132. BOOL
  133. CSmPropertyPage::OnInitDialog()
  134. {
  135. DWORD dwExStyle = 0;
  136. CWnd* pwndPropSheet;
  137. pwndPropSheet = GetParentOwner();
  138. if ( NULL != pwndPropSheet ) {
  139. dwExStyle = pwndPropSheet->GetExStyle();
  140. pwndPropSheet->ModifyStyleEx ( NULL, WS_EX_CONTEXTHELP );
  141. }
  142. return CPropertyPage::OnInitDialog();
  143. }
  144. BOOL
  145. CSmPropertyPage::OnSetActive()
  146. {
  147. m_bIsActive = TRUE;
  148. return CPropertyPage::OnSetActive();
  149. }
  150. BOOL
  151. CSmPropertyPage::OnApply()
  152. {
  153. BOOL bContinue = TRUE;
  154. if ( NULL != m_hConsole
  155. && NULL != m_pDataObject
  156. && IsModifiedPage() ) {
  157. // Only changes on the schedule page cause notification,
  158. // because only schedule changes cause a state change that is
  159. // visible in the result pane.
  160. MMCPropertyChangeNotify (
  161. m_hConsole, // handle to a notification
  162. (LPARAM) m_pDataObject); // unique identifier
  163. }
  164. bContinue = CPropertyPage::OnApply();
  165. return bContinue;
  166. }
  167. LRESULT
  168. CSmPropertyPage::OnQuerySiblings( WPARAM wParam, LPARAM /*lParam*/ )
  169. {
  170. LRESULT lrReturn = (LRESULT)0;
  171. if ( wParam != m_nIDHelp ) {
  172. lrReturn = (LRESULT)IsModifiedPage();
  173. }
  174. return lrReturn;
  175. }
  176. BOOL
  177. CSmPropertyPage::OnHelpInfo(HELPINFO* pHelpInfo)
  178. {
  179. ASSERT ( NULL != m_pdwHelpIds );
  180. if ( NULL != pHelpInfo ) {
  181. if ( pHelpInfo->iCtrlId >= GetFirstHelpCtrlId() ) {
  182. InvokeWinHelp(
  183. WM_HELP,
  184. NULL,
  185. (LPARAM)pHelpInfo,
  186. GetContextHelpFilePath(),
  187. m_pdwHelpIds ); //s_aulHelpIds);
  188. }
  189. } else {
  190. ASSERT ( FALSE );
  191. }
  192. return TRUE;
  193. }
  194. void
  195. CSmPropertyPage::OnContextMenu(CWnd* pWnd, CPoint /* point */)
  196. {
  197. ASSERT ( NULL != m_pdwHelpIds );
  198. if ( NULL != pWnd ) {
  199. InvokeWinHelp (
  200. WM_CONTEXTMENU,
  201. (WPARAM)(pWnd->m_hWnd),
  202. NULL,
  203. GetContextHelpFilePath(),
  204. m_pdwHelpIds );
  205. }
  206. return;
  207. }
  208. /////////////////////////////////////////////////////////////////////////////
  209. // CSmPropertyPage helper methods
  210. BOOL
  211. CSmPropertyPage::UpdateService( CSmLogQuery* pQuery, BOOL bSyncSerial )
  212. {
  213. DWORD dwStatus = ERROR_SUCCESS;
  214. BOOL bIsValid = FALSE;
  215. BOOL bRegistryUpdated;
  216. CString strMessage;
  217. CString strMachineName;
  218. CString strSysMessage;
  219. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  220. if ( NULL == pQuery ) {
  221. ASSERT ( FALSE );
  222. return bIsValid;
  223. }
  224. if ( (!QuerySiblings(m_nIDHelp, 0)) && IsModifiedPage() ) { // Second parameter not used by called method
  225. {
  226. CWaitCursor WaitCursor;
  227. // Update the service with changes.
  228. // Sync changes made by service to properties not modified by this page.
  229. if ( bSyncSerial ) {
  230. dwStatus = pQuery->SyncSerialNumberWithRegistry();
  231. }
  232. if ( ERROR_SUCCESS == dwStatus ) {
  233. dwStatus = pQuery->UpdateService ( bRegistryUpdated );
  234. }
  235. }
  236. if ( ERROR_SUCCESS == dwStatus ) {
  237. bIsValid = TRUE;
  238. } else {
  239. bIsValid = FALSE;
  240. if ( ERROR_KEY_DELETED == dwStatus ) {
  241. strMessage.LoadString( IDS_ERRMSG_QUERY_DELETED );
  242. } else if ( ERROR_ACCESS_DENIED == dwStatus ) {
  243. pQuery->GetMachineDisplayName( strMachineName );
  244. FormatSmLogCfgMessage (
  245. strMessage,
  246. m_hModule,
  247. SMCFG_NO_MODIFY_ACCESS,
  248. (LPCWSTR)strMachineName);
  249. } else {
  250. FormatMessage (
  251. FORMAT_MESSAGE_FROM_SYSTEM,
  252. NULL,
  253. dwStatus,
  254. 0,
  255. strSysMessage.GetBufferSetLength( MAX_PATH ),
  256. MAX_PATH,
  257. NULL );
  258. strSysMessage.ReleaseBuffer();
  259. if ( strSysMessage.IsEmpty() ) {
  260. strSysMessage.Format ( L"0x%08lX", dwStatus );
  261. }
  262. strMessage.Format( IDS_ERRMSG_SERVICE_ERROR, pQuery->GetLogName() );
  263. strMessage += strSysMessage;
  264. }
  265. MessageBox ( strMessage, pQuery->GetLogName(), MB_OK | MB_ICONERROR );
  266. }
  267. } else {
  268. bIsValid = TRUE;
  269. }
  270. // If valid data, clear the modified page flag because either this page updated
  271. // the service or another page is scheduled to update the service.
  272. if ( bIsValid ) {
  273. SetModifiedPage ( FALSE );
  274. }
  275. return bIsValid;
  276. }
  277. void
  278. CSmPropertyPage::ValidateTextEdit (
  279. CDataExchange* pDX,
  280. int nIDC,
  281. int nMaxChars,
  282. DWORD* pValue,
  283. DWORD /* minValue */,
  284. DWORD /* maxValue */)
  285. {
  286. HWND hWndCtrl = pDX->PrepareEditCtrl(nIDC);
  287. LONG currentValue = INVALID_DWORD;
  288. WCHAR szT[MAXSTR];
  289. CString strTemp;
  290. if ( NULL != pDX && NULL != pValue ) {
  291. if (pDX->m_bSaveAndValidate) {
  292. *pValue = (DWORD) currentValue;
  293. ::GetWindowText(hWndCtrl, szT, MAXSTR);
  294. strTemp = szT;
  295. DDV_MaxChars(pDX, strTemp, nMaxChars);
  296. if (szT[0] >= L'0' && szT[0] <= L'9')
  297. {
  298. currentValue = _wtol(szT);
  299. *pValue = (DWORD) currentValue;
  300. }
  301. } else {
  302. if ( INVALID_DWORD != *pValue ) {
  303. wsprintf(szT, L"%lu", *pValue);
  304. } else {
  305. szT[0] = L'\0';
  306. }
  307. GetDlgItem(nIDC)->SetWindowText(szT);
  308. }
  309. } else {
  310. ASSERT ( FALSE );
  311. }
  312. }
  313. BOOL
  314. CSmPropertyPage::ValidateDWordInterval(
  315. int nIDC,
  316. LPCWSTR strLogName,
  317. long lValue,
  318. DWORD minValue,
  319. DWORD maxValue )
  320. {
  321. CString strMsg;
  322. BOOL bResult = (lValue >= (long) minValue)
  323. && (lValue <= (long) maxValue);
  324. if (! bResult)
  325. {
  326. strMsg.Format ( IDS_ERRMSG_INVALIDDWORD, minValue, maxValue );
  327. MessageBox(strMsg, strLogName, MB_OK | MB_ICONERROR);
  328. SetFocusAnyPage ( nIDC );
  329. strMsg.Empty();
  330. }
  331. return (bResult);
  332. }
  333. void
  334. CSmPropertyPage::OnDeltaposSpin(
  335. NMHDR *pNMHDR,
  336. LRESULT *pResult,
  337. DWORD *pValue,
  338. DWORD dMinValue,
  339. DWORD dMaxValue)
  340. {
  341. NM_UPDOWN* pNMUpDown;
  342. LONG lValue;
  343. BOOL bResult = TRUE;
  344. UpdateData(TRUE);
  345. ASSERT(dMinValue <= dMaxValue);
  346. if ( NULL != pNMHDR
  347. && NULL != pResult
  348. && NULL != pValue )
  349. {
  350. pNMUpDown = (NM_UPDOWN *) pNMHDR;
  351. lValue = (LONG) (*pValue);
  352. if (lValue == INVALID_DWORD) {
  353. lValue = (DWORD) dMinValue;
  354. }
  355. if ( ((lValue >= (LONG) dMinValue + 1) && (pNMUpDown->iDelta > 0))
  356. || ((lValue <= (LONG) dMaxValue - 1) && (pNMUpDown->iDelta < 0)))
  357. {
  358. lValue += (pNMUpDown->iDelta * -1);
  359. if (lValue > (LONG) dMaxValue) {
  360. lValue = (DWORD) dMaxValue;
  361. } else if (lValue < (LONG) dMinValue) {
  362. lValue = (DWORD) dMinValue;
  363. }
  364. } else if (lValue > (LONG) dMaxValue) {
  365. lValue = (DWORD) dMaxValue;
  366. } else if (lValue < (LONG) dMinValue) {
  367. lValue = (DWORD) dMinValue;
  368. } else {
  369. bResult = FALSE;
  370. }
  371. if (bResult) {
  372. *pValue = lValue;
  373. UpdateData(FALSE);
  374. SetModifiedPage(TRUE);
  375. }
  376. *pResult = 0;
  377. } else {
  378. ASSERT ( FALSE );
  379. }
  380. return;
  381. }
  382. BOOL
  383. CSmPropertyPage::SampleTimeIsLessThanSessionTime( CSmLogQuery* pQuery )
  384. {
  385. BOOL bIsValid = TRUE;
  386. SYSTEMTIME stLocalTime;
  387. LONGLONG llMaxStartTime = 0;
  388. LONGLONG llSessionMilliseconds = 0;
  389. LONGLONG llSampleMilliseconds = 0;
  390. CString strMsg;
  391. ResourceStateManager rsm;
  392. if ( NULL != pQuery ) {
  393. if ( SLQ_TRACE_LOG != pQuery->GetLogType() ) {
  394. if ( SLQ_AUTO_MODE_AT == m_SharedData.stiStopTime.dwAutoMode ) {
  395. GetLocalTime (&stLocalTime);
  396. SystemTimeToFileTime (&stLocalTime, (FILETIME *)&llMaxStartTime);
  397. // For Manual Start mode, Now is used to determine session length.
  398. // For Start At mode, the later of Now vs. schedule start time
  399. // is used to determine session length.
  400. if ( SLQ_AUTO_MODE_AT == m_SharedData.stiStartTime.dwAutoMode ) {
  401. if ( m_SharedData.stiStartTime.llDateTime > llMaxStartTime ) {
  402. llMaxStartTime = m_SharedData.stiStartTime.llDateTime;
  403. }
  404. }
  405. // Calc and compare session seconds vs. sample seconds
  406. TimeInfoToMilliseconds ( &m_SharedData.stiSampleTime, &llSampleMilliseconds );
  407. llSessionMilliseconds = m_SharedData.stiStopTime.llDateTime - llMaxStartTime;
  408. llSessionMilliseconds /= FILETIME_TICS_PER_MILLISECOND;
  409. if ( llSessionMilliseconds < llSampleMilliseconds ) {
  410. strMsg.LoadString ( IDS_SCHED_SESSION_TOO_SHORT );
  411. MessageBox(strMsg, pQuery->GetLogName(), MB_OK | MB_ICONERROR);
  412. strMsg.Empty();
  413. bIsValid = FALSE;
  414. }
  415. } else if ( SLQ_AUTO_MODE_AFTER == m_SharedData.stiStopTime.dwAutoMode ) {
  416. TimeInfoToMilliseconds ( &m_SharedData.stiStopTime, &llSessionMilliseconds );
  417. TimeInfoToMilliseconds ( &m_SharedData.stiSampleTime, &llSampleMilliseconds );
  418. if ( llSessionMilliseconds < llSampleMilliseconds ) {
  419. strMsg.LoadString ( IDS_SCHED_SESSION_TOO_SHORT );
  420. MessageBox(strMsg, pQuery->GetLogName(), MB_OK | MB_ICONERROR);
  421. strMsg.Empty();
  422. bIsValid = FALSE;
  423. }
  424. }
  425. }
  426. } else {
  427. ASSERT ( FALSE );
  428. bIsValid = FALSE;
  429. }
  430. return bIsValid;
  431. }
  432. BOOL
  433. CSmPropertyPage::ApplyRunAs ( CSmLogQuery* pQuery )
  434. {
  435. DWORD dwStatus = ERROR_SUCCESS;
  436. WCHAR strComputerName[MAX_COMPUTERNAME_LENGTH + 1];
  437. CString strComputer;
  438. DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
  439. BOOL bReturn = TRUE;
  440. HRESULT hr = NOERROR;
  441. if ( NULL != pQuery ) {
  442. if ( !QuerySiblings(m_nIDHelp, 0)) { // Second parameter not used by called method
  443. //
  444. // If RunAs user/password changed, then we must save RunAs information
  445. //
  446. if( pQuery->m_fDirtyPassword & (PASSWORD_DIRTY|PASSWORD_SET) ){
  447. pQuery->m_fDirtyPassword = PASSWORD_CLEAN;
  448. strComputer = pQuery->GetLogService()->GetMachineName();
  449. if( strComputer.IsEmpty() ){
  450. strComputerName[0] = L'\0';
  451. bReturn = GetComputerName( strComputerName, &dwSize );
  452. if ( !bReturn ) {
  453. dwStatus = GetLastError();
  454. } else {
  455. strComputer = strComputerName;
  456. }
  457. }
  458. pQuery->m_strUser.TrimLeft();
  459. pQuery->m_strUser.TrimRight();
  460. if( pQuery->m_strUser.GetLength() ) {
  461. dwStatus = PdhPlaSetRunAs(
  462. (LPWSTR)(LPCWSTR)pQuery->GetLogName(),
  463. (LPWSTR)(LPCWSTR)strComputer,
  464. (LPWSTR)(LPCWSTR)pQuery->m_strUser,
  465. (LPWSTR)(LPCWSTR)pQuery->m_strPassword
  466. );
  467. } else {
  468. dwStatus = PdhPlaSetRunAs(
  469. (LPWSTR)(LPCWSTR)pQuery->GetLogName(),
  470. (LPWSTR)(LPCWSTR)strComputer,
  471. L"",
  472. L""
  473. );
  474. }
  475. }
  476. if ( ERROR_SUCCESS != dwStatus ) {
  477. bReturn = FALSE;
  478. }
  479. }
  480. } else {
  481. ASSERT ( FALSE );
  482. bReturn = FALSE;
  483. }
  484. return bReturn;
  485. }
  486. void
  487. CSmPropertyPage::SetRunAs( CSmLogQuery* pQuery )
  488. {
  489. CPasswordDlg dlg;
  490. if ( NULL != pQuery ) {
  491. dlg.SetContextHelpFilePath( GetContextHelpFilePath() );
  492. pQuery->m_strUser.TrimLeft();
  493. pQuery->m_strUser.TrimRight();
  494. dlg.m_strUserName = pQuery->m_strUser;
  495. //
  496. // If we want to reset the RunAs information
  497. //
  498. if (pQuery->m_strUser.IsEmpty() || pQuery->m_strUser.GetAt(0) == L'<' ) {
  499. pQuery->m_strPassword = L"";
  500. pQuery->m_strUser = L"";
  501. pQuery->m_fDirtyPassword |= PASSWORD_SET;
  502. } else {
  503. if( dlg.DoModal() != IDCANCEL ){
  504. pQuery->m_strPassword = dlg.m_strPassword1;
  505. pQuery->m_strUser = dlg.m_strUserName;
  506. SetModifiedPage(TRUE);
  507. pQuery->m_fDirtyPassword |= PASSWORD_SET;
  508. }
  509. }
  510. } else {
  511. ASSERT ( FALSE );
  512. }
  513. }
  514. BOOL
  515. CSmPropertyPage::IsValidData( CSmLogQuery* pQuery, DWORD fReason )
  516. {
  517. BOOL bIsValid = TRUE;
  518. CString strTestFileName;
  519. INT iPrevLength = 0;
  520. if ( NULL != pQuery ) {
  521. if ( bIsValid ) {
  522. if ( !IsActive() ) {
  523. pQuery->GetPropPageSharedData ( &m_SharedData );
  524. }
  525. }
  526. if( bIsValid && (fReason & VALIDATE_APPLY ) ){
  527. bIsValid = IsWritableQuery( pQuery );
  528. }
  529. if( bIsValid ){
  530. bIsValid = IsValidLocalData();
  531. }
  532. if( bIsValid ){
  533. //
  534. // RunAs user name changed, but password not set, set it now
  535. //
  536. if( (pQuery->m_fDirtyPassword & PASSWORD_DIRTY) && !(pQuery->m_fDirtyPassword & PASSWORD_SET) ){
  537. // Note: Trimming can be moved to SetRunAs. Left outside
  538. // for clarity.
  539. iPrevLength = m_strUserDisplay.GetLength();
  540. m_strUserDisplay.TrimLeft();
  541. m_strUserDisplay.TrimRight();
  542. SetRunAs( pQuery );
  543. if ( iPrevLength != m_strUserDisplay.GetLength() ) {
  544. SetDlgItemText ( IDC_RUNAS_EDIT, m_strUserDisplay );
  545. }
  546. if( !(pQuery->m_fDirtyPassword & PASSWORD_SET) ){
  547. bIsValid = FALSE;
  548. }
  549. }
  550. }
  551. // Validate log file name and folder for filetypes
  552. if ( bIsValid
  553. && SLQ_ALERT != pQuery->GetLogType()
  554. && (fReason & VALIDATE_APPLY ) ) {
  555. if ( pQuery->GetLogService()->IsLocalMachine() ) {
  556. if ( SLF_SQL_LOG != m_SharedData.dwLogFileType ) {
  557. // bIsValid is returned as FALSE if the user cancels directory creation.
  558. ProcessDirPath (
  559. pQuery->GetLogService()->GetDefaultLogFileFolder(),
  560. m_SharedData.strFolderName,
  561. pQuery->GetLogName(),
  562. this,
  563. bIsValid,
  564. FALSE );
  565. }
  566. }
  567. if ( bIsValid ) {
  568. CreateSampleFileName (
  569. pQuery->GetLogName(),
  570. pQuery->GetLogService()->GetMachineName(),
  571. m_SharedData.strFolderName,
  572. m_SharedData.strFileBaseName,
  573. m_SharedData.strSqlName,
  574. m_SharedData.dwSuffix,
  575. m_SharedData.dwLogFileType,
  576. m_SharedData.dwSerialNumber,
  577. strTestFileName);
  578. if ( MAX_PATH <= strTestFileName.GetLength() ) {
  579. CString strMessage;
  580. strMessage.LoadString ( IDS_FILENAMETOOLONG );
  581. MessageBox ( strMessage, pQuery->GetLogName(), MB_OK | MB_ICONERROR);
  582. bIsValid = FALSE;
  583. }
  584. }
  585. }
  586. } else {
  587. ASSERT ( FALSE );
  588. bIsValid = FALSE;
  589. }
  590. return bIsValid;
  591. }
  592. BOOL
  593. CSmPropertyPage::IsWritableQuery( CSmLogQuery* pQuery )
  594. {
  595. BOOL bIsValid = FALSE;
  596. if ( NULL != pQuery ) {
  597. bIsValid = !pQuery->IsExecuteOnly() && !pQuery->IsReadOnly();
  598. if ( !bIsValid ) {
  599. CString strMessage;
  600. CString strMachineName;
  601. DWORD dwMessageId;
  602. pQuery->GetMachineDisplayName( strMachineName );
  603. dwMessageId = pQuery->IsExecuteOnly() ? SMCFG_NO_MODIFY_DEFAULT_LOG : SMCFG_NO_MODIFY_ACCESS;
  604. FormatSmLogCfgMessage (
  605. strMessage,
  606. m_hModule,
  607. dwMessageId,
  608. (LPCWSTR)strMachineName );
  609. MessageBox ( strMessage, pQuery->GetLogName(), MB_OK | MB_ICONERROR);
  610. }
  611. } else {
  612. ASSERT ( FALSE );
  613. }
  614. return bIsValid;
  615. }
  616. BOOL
  617. CSmPropertyPage::SampleIntervalIsInRange(
  618. SLQ_TIME_INFO& rstiSample,
  619. const CString& rstrQueryName )
  620. {
  621. LONGLONG llMillisecondSampleInt;
  622. BOOL bIsValid = TRUE;
  623. // 45 days in milliseconds = 1000*60*60*24*45
  624. #define FORTYFIVE_DAYS (0xE7BE2C00)
  625. TimeInfoToMilliseconds (&rstiSample, &llMillisecondSampleInt );
  626. bIsValid = ( FORTYFIVE_DAYS >= llMillisecondSampleInt );
  627. if ( !bIsValid ) {
  628. CString strMessage;
  629. strMessage.LoadString ( IDS_ERRMSG_SAMPLEINTTOOLARGE );
  630. MessageBox ( strMessage, rstrQueryName, MB_OK | MB_ICONERROR);
  631. }
  632. return bIsValid;
  633. }
  634. DWORD
  635. CSmPropertyPage::SetContextHelpFilePath( const CString& rstrPath )
  636. {
  637. DWORD dwStatus = ERROR_SUCCESS;
  638. MFC_TRY
  639. m_strContextHelpFilePath = rstrPath;
  640. MFC_CATCH_DWSTATUS
  641. return dwStatus;
  642. }
  643. void
  644. CSmPropertyPage::SetModifiedPage( const BOOL bModified )
  645. {
  646. m_bIsModifiedPage = bModified;
  647. SetModified ( bModified );
  648. return;
  649. }
  650. CSmPropertyPage::eStartType
  651. CSmPropertyPage::DetermineCurrentStartType( void )
  652. {
  653. eStartType eCurrentStartType;
  654. SLQ_TIME_INFO* pstiStart;
  655. SLQ_TIME_INFO* pstiStop;
  656. SYSTEMTIME stLocalTime;
  657. FILETIME ftLocalTime;
  658. LONGLONG llLocalTime;
  659. ResourceStateManager rsm;
  660. ftLocalTime.dwLowDateTime = ftLocalTime.dwHighDateTime = 0;
  661. pstiStart = &m_SharedData.stiStartTime;
  662. ASSERT ( SLQ_TT_TTYPE_START == pstiStart->wTimeType );
  663. if ( SLQ_AUTO_MODE_NONE == pstiStart->dwAutoMode ) {
  664. if ( pstiStart->llDateTime != MIN_TIME_VALUE ) {
  665. eCurrentStartType = eStartManually;
  666. } else {
  667. eCurrentStartType = eStartImmediately;
  668. }
  669. } else {
  670. GetLocalTime (&stLocalTime);
  671. SystemTimeToFileTime (&stLocalTime, &ftLocalTime);
  672. llLocalTime = *((LONGLONG *)(&ftLocalTime));
  673. // Test current time to determine most appropriate text
  674. if (llLocalTime < pstiStart->llDateTime) {
  675. // then the start time is in the future
  676. eCurrentStartType = eStartSched;
  677. } else {
  678. // Start immediately, unless manual or scheduled stop time is already past.
  679. pstiStop = &m_SharedData.stiStopTime;
  680. if ( SLQ_AUTO_MODE_NONE == pstiStop->dwAutoMode
  681. && llLocalTime > pstiStop->llDateTime ) {
  682. eCurrentStartType = eStartManually;
  683. } else {
  684. eCurrentStartType = eStartImmediately;
  685. }
  686. }
  687. }
  688. return eCurrentStartType;
  689. }
  690. DWORD
  691. CSmPropertyPage::AllocInitCounterPath(
  692. const LPWSTR szCounterPath,
  693. PPDH_COUNTER_PATH_ELEMENTS* ppCounter )
  694. {
  695. DWORD dwStatus = ERROR_SUCCESS;
  696. PDH_STATUS pdhStatus = ERROR_SUCCESS;
  697. PPDH_COUNTER_PATH_ELEMENTS pLocalCounter = NULL;
  698. ULONG ulBufSize = 0;
  699. if ( NULL != szCounterPath && NULL != ppCounter ) {
  700. *ppCounter = NULL;
  701. pdhStatus = PdhParseCounterPath(
  702. szCounterPath,
  703. pLocalCounter,
  704. &ulBufSize,
  705. 0 );
  706. if ( 0 < ulBufSize ) {
  707. pLocalCounter = (PPDH_COUNTER_PATH_ELEMENTS) G_ALLOC( ulBufSize);
  708. if ( NULL != pLocalCounter ) {
  709. ZeroMemory ( pLocalCounter, ulBufSize );
  710. dwStatus = pdhStatus = PdhParseCounterPath(
  711. szCounterPath,
  712. pLocalCounter,
  713. &ulBufSize,
  714. 0);
  715. if ( ERROR_SUCCESS != pdhStatus ) {
  716. G_FREE(pLocalCounter);
  717. pLocalCounter = NULL;
  718. }
  719. } else {
  720. dwStatus = ERROR_OUTOFMEMORY;
  721. }
  722. }
  723. if ( ERROR_SUCCESS == dwStatus && NULL != pLocalCounter ) {
  724. *ppCounter = pLocalCounter;
  725. }
  726. } else {
  727. dwStatus = ERROR_INVALID_PARAMETER;
  728. ASSERT ( FALSE );
  729. }
  730. return dwStatus;
  731. }
  732. DWORD
  733. CSmPropertyPage::SetFocusAnyPage (
  734. INT iControlId )
  735. {
  736. DWORD dwStatus = ERROR_SUCCESS;
  737. UINT uiIddPropertyPage;
  738. CSmPropertyPage* pOriginalPage = NULL;
  739. CSmPropertyPage* pNextPage = NULL;
  740. CPropertySheet* pPropSheet;
  741. BOOL bFound = FALSE;
  742. INT iPageCount;
  743. INT iPageIndex;
  744. CWnd* pwndControl = NULL;
  745. if ( 0 != iControlId ) {
  746. pPropSheet = m_pQuery->GetInitialPropertySheet();
  747. if ( NULL == pPropSheet ) {
  748. GetDlgItem ( iControlId )->SetFocus();
  749. } else {
  750. //
  751. // Special check for Create From... case.
  752. //
  753. // Check for the normal case first.
  754. //
  755. uiIddPropertyPage = iControlId - (iControlId % 100 ) ;
  756. pOriginalPage = (CSmPropertyPage*)pPropSheet->GetActivePage();
  757. if ( NULL != pOriginalPage ) {
  758. if ( uiIddPropertyPage == pOriginalPage->m_uiIdTemplate ) {
  759. bFound = TRUE;
  760. GetDlgItem ( iControlId )->SetFocus();
  761. }
  762. }
  763. if ( !bFound ) {
  764. iPageCount = pPropSheet->GetPageCount();
  765. for ( iPageIndex = 0; iPageIndex < iPageCount; iPageIndex++ ) {
  766. pNextPage = dynamic_cast<CSmPropertyPage*>(pPropSheet->GetPage ( iPageIndex )) ;
  767. if ( NULL != pNextPage ) {
  768. if ( uiIddPropertyPage == pNextPage->m_uiIdTemplate ) {
  769. bFound = TRUE;
  770. pPropSheet->SetActivePage ( pNextPage );
  771. pwndControl = GetDlgItem ( iControlId );
  772. if ( NULL != pwndControl ) {
  773. pwndControl->SetFocus();
  774. }
  775. break;
  776. }
  777. }
  778. }
  779. }
  780. }
  781. }
  782. return dwStatus;
  783. }
  784. BOOL
  785. CSmPropertyPage::ConnectRemoteWbemFail(CSmLogQuery* pQuery, BOOL bNotTouchRunAs)
  786. /*++
  787. Routine Description:
  788. The function display an error message telling users they can not
  789. modify the RunAs information.
  790. Arguments:
  791. pQuery - Query structure
  792. bNotTouchRunAs - Don't check/restore RunAs after displaying dialog
  793. Return Value:
  794. Return TRUE if the RunAs need to be restored to its original one,
  795. otherwise return FALSE
  796. --*/
  797. {
  798. CString strMessage;
  799. CString strSysMessage;
  800. IWbemStatusCodeText * pStatus = NULL;
  801. DWORD dwMessageId;
  802. HRESULT hr;
  803. //
  804. // If bNotTouchRunAs is TRUE, don't try to restore the RunAs info.
  805. //
  806. if (!bNotTouchRunAs) {
  807. if (m_strUserDisplay == m_strUserSaved) {
  808. return FALSE;
  809. }
  810. }
  811. //
  812. // If the status code returned when we connect remote WBEM is
  813. // access denied, that means we are not an admin on the remote box
  814. // if the remote box is XP, or we are not an admin or performance log
  815. // user if the remote box is .NET
  816. //
  817. dwMessageId = SMCFG_SYSTEM_MESSAGE;
  818. if (pQuery->GetLogService()->m_hWbemAccessStatus == WBEM_E_ACCESS_DENIED) {
  819. if (pQuery->GetLogService()->TargetOs() == OS_WINXP) {
  820. dwMessageId = SMCFG_ADMIN_ONLY;
  821. } else if (pQuery->GetLogService()->TargetOs() == OS_WINNET) {
  822. dwMessageId = SMCFG_NO_MODIFY_ACCESS;
  823. }
  824. }
  825. FormatSmLogCfgMessage (
  826. strMessage,
  827. m_hModule,
  828. dwMessageId,
  829. (LPCWSTR)pQuery->GetLogName());
  830. hr = CoCreateInstance(CLSID_WbemStatusCodeText,
  831. 0,
  832. CLSCTX_INPROC_SERVER,
  833. IID_IWbemStatusCodeText,
  834. (LPVOID *) &pStatus);
  835. if (hr == S_OK) {
  836. BSTR bstr = 0;
  837. hr = pStatus->GetErrorCodeText(pQuery->GetLogService()->m_hWbemAccessStatus, 0, 0, &bstr);
  838. if (hr == S_OK){
  839. strSysMessage = bstr;
  840. SysFreeString(bstr);
  841. bstr = 0;
  842. }
  843. pStatus->Release();
  844. }
  845. if ( strSysMessage.IsEmpty() ) {
  846. strSysMessage.Format ( L"0x%08lX", pQuery->GetLogService()->m_hWbemAccessStatus);
  847. }
  848. strMessage += strSysMessage;
  849. MessageBox(strMessage, pQuery->GetLogName(), MB_OK);
  850. return TRUE;
  851. }