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.

1231 lines
30 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: regvldlg.cpp
  7. //
  8. // Contents: implementation of CSceRegistryValueInfo, CConfigRegEnable,
  9. // CAttrRegEnable, CLocalPolRegEnable, CConfigRegNumber,
  10. // CAttrRegNumber, CLocalPolRegNumber, CConfigRegString,
  11. // CAttrRegString, CLocalPolRegString, CConfigRegChoice
  12. // CAttrRegChoice, CLocalPolRegChoice
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "stdafx.h"
  16. #include "wsecmgr.h"
  17. #include "regvldlg.h"
  18. #include "util.h"
  19. #include "snapmgr.h"
  20. #include "defaults.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. extern PCWSTR g_pcszNEWLINE;
  27. /*-----------------------------------------------------------------------------------------
  28. Method: CRegistryValueInfo::CRegistryValueInfo
  29. Synopsis: Constructor for CRegistryValueInfo, sets m_pRegInfo.
  30. Arguments: [pInfo] - A pointer toa SCE_REGISTRY_VALUE_INFO struct.
  31. -----------------------------------------------------------------------------------------*/
  32. CSceRegistryValueInfo::CSceRegistryValueInfo(
  33. PSCE_REGISTRY_VALUE_INFO pInfo)
  34. {
  35. m_pRegInfo = pInfo;
  36. }
  37. /*-----------------------------------------------------------------------------------------
  38. Method: CRegistryValueInfo::GetBoolValue
  39. Synopsis: Returns a boolean TRUE or false depending on the data and data type of this
  40. object
  41. Returns: TRUE if the data is equal to a TRUE value, FALSE otherwise.
  42. -----------------------------------------------------------------------------------------*/
  43. DWORD CSceRegistryValueInfo::GetBoolValue()
  44. {
  45. if (GetValue() == NULL)
  46. return SCE_NO_VALUE;
  47. return GetValue()[0] == L'1';
  48. }
  49. /*-----------------------------------------------------------------------------------------
  50. Method: CRegistryValueInfo::SetValueBool
  51. Synopsis: Sets the value to the types equivalent boolean value, SCE_NO_VALUE if
  52. [dwVal] is equal to SCE_NO_VALUE.
  53. Arguments: [bVal] - TRUE or FALSE.
  54. Returns: ERROR_SUCCESS - Successfull
  55. E_OUTOFMEMORY - Out of memory.
  56. -----------------------------------------------------------------------------------------*/
  57. DWORD
  58. CSceRegistryValueInfo::SetBoolValue(
  59. DWORD dwVal)
  60. {
  61. if(dwVal == SCE_NO_VALUE)
  62. {
  63. if(m_pRegInfo->Value)
  64. {
  65. LocalFree( m_pRegInfo->Value );
  66. }
  67. m_pRegInfo->Value = NULL;
  68. return ERROR_SUCCESS;
  69. }
  70. //
  71. // Set the length of the string.
  72. //
  73. int nLen = 2;
  74. if ( m_pRegInfo->Value == NULL )
  75. {
  76. // allocate buffer
  77. m_pRegInfo->Value = (PWSTR)LocalAlloc(0, nLen*sizeof(WCHAR));
  78. if(m_pRegInfo->Value == NULL)
  79. return (DWORD)E_OUTOFMEMORY;
  80. }
  81. if ( m_pRegInfo->Value )
  82. {
  83. //
  84. // Convert and set the data.
  85. //
  86. m_pRegInfo->Value[0] = (int)dwVal + L'0';
  87. m_pRegInfo->Value[nLen-1] = L'\0';
  88. }
  89. return ERROR_SUCCESS;
  90. }
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CConfigRegEnable message handlers
  93. void CConfigRegEnable::Initialize(CResult *pResult)
  94. {
  95. // Class hieirarchy is bad - call CAttribute base method directly
  96. CAttribute::Initialize(pResult);
  97. CSceRegistryValueInfo prv( (PSCE_REGISTRY_VALUE_INFO)pResult->GetBase() );
  98. DWORD dw = prv.GetBoolValue();
  99. if ( dw != SCE_NO_VALUE )
  100. {
  101. m_bConfigure = TRUE;
  102. SetInitialValue(dw);
  103. }
  104. else
  105. m_bConfigure = FALSE;
  106. }
  107. BOOL CConfigRegEnable::OnApply()
  108. {
  109. if ( !m_bReadOnly )
  110. {
  111. UpdateData(TRUE);
  112. DWORD dw = 0;
  113. if (!m_bConfigure)
  114. dw = SCE_NO_VALUE;
  115. else
  116. {
  117. switch(m_nEnabledRadio)
  118. {
  119. // ENABLED
  120. case 0:
  121. dw = 1;
  122. break;
  123. // DISABLED
  124. case 1:
  125. dw = 0;
  126. break;
  127. // Not really configured
  128. default:
  129. dw = -1;
  130. break;
  131. }
  132. }
  133. CSceRegistryValueInfo prv( (PSCE_REGISTRY_VALUE_INFO)(m_pData->GetBase()) );
  134. DWORD prvdw = prv.GetBoolValue(); //Bug211219, Yanggao, 3/15/2001
  135. prv.SetBoolValue(dw);
  136. if(!UpdateProfile())
  137. prv.SetBoolValue(prvdw);
  138. }
  139. // Class hieirarchy is bad - call CAttribute base method directly
  140. return CAttribute::OnApply();
  141. }
  142. BOOL CConfigRegEnable::UpdateProfile()
  143. {
  144. if ( m_pData->GetBaseProfile() ) //Bug211219, Yanggao, 3/15/2001
  145. {
  146. if( !(m_pData->GetBaseProfile()->SetDirty(AREA_SECURITY_POLICY)) )
  147. {
  148. m_pData->Update(m_pSnapin);
  149. return FALSE;
  150. }
  151. else
  152. {
  153. m_pData->Update(m_pSnapin);
  154. return TRUE;
  155. }
  156. }
  157. m_pData->Update(m_pSnapin);
  158. return FALSE;
  159. }
  160. /////////////////////////////////////////////////////////////////////////////
  161. // CAttrRegEnable message handlers
  162. void CAttrRegEnable::Initialize(CResult * pResult)
  163. {
  164. // Class hieirarchy is bad - call CAttribute base method directly
  165. CAttribute::Initialize(pResult);
  166. CSceRegistryValueInfo prv(NULL);
  167. //
  168. // Edit template settings.
  169. //
  170. prv.Attach( (PSCE_REGISTRY_VALUE_INFO)pResult->GetBase() );
  171. DWORD dw = prv.GetBoolValue();
  172. if(dw != SCE_NO_VALUE)
  173. {
  174. m_bConfigure = TRUE;
  175. m_EnabledRadio = !dw;
  176. }
  177. else
  178. m_bConfigure = FALSE;
  179. pResult->GetDisplayName( NULL, m_Current, 2 );
  180. }
  181. BOOL CAttrRegEnable::OnApply()
  182. {
  183. if ( !m_bReadOnly )
  184. {
  185. UpdateData(TRUE);
  186. DWORD dw = 0;
  187. if (!m_bConfigure)
  188. dw = SCE_NO_VALUE;
  189. else
  190. {
  191. switch(m_EnabledRadio)
  192. {
  193. // ENABLED
  194. case 0:
  195. dw = 1;
  196. break;
  197. // DISABLED
  198. case 1:
  199. dw = 0;
  200. break;
  201. // Not really configured
  202. default:
  203. dw = -1;
  204. break;
  205. }
  206. }
  207. CSceRegistryValueInfo prv( (PSCE_REGISTRY_VALUE_INFO)(m_pData->GetBase()) );
  208. prv.SetBoolValue(dw);
  209. //
  210. // this address should never be NULL
  211. //
  212. int status = CEditTemplate::ComputeStatus(
  213. (PSCE_REGISTRY_VALUE_INFO)m_pData->GetBase(),
  214. (PSCE_REGISTRY_VALUE_INFO)m_pData->GetSetting()
  215. );
  216. UpdateProfile( status );
  217. }
  218. // Class hieirarchy is bad - call CAttribute base method directly
  219. return CAttribute::OnApply();
  220. }
  221. void CAttrRegEnable::UpdateProfile( DWORD status )
  222. {
  223. if ( m_pData->GetBaseProfile() )
  224. m_pData->GetBaseProfile()->SetDirty(AREA_SECURITY_POLICY);
  225. m_pData->SetStatus(status);
  226. m_pData->Update(m_pSnapin);
  227. }
  228. /////////////////////////////////////////////////////////////////////////////
  229. // CLocalPolRegEnable message handlers
  230. BOOL CLocalPolRegEnable::UpdateProfile( )
  231. {
  232. return m_pSnapin->UpdateLocalPolRegValue(m_pData);
  233. }
  234. void CLocalPolRegEnable::Initialize(CResult * pResult)
  235. {
  236. CConfigRegEnable::Initialize(pResult);
  237. if (!m_bConfigure)
  238. {
  239. //
  240. // Since we don't have a UI to change configuration
  241. // fake it by "configuring" with an invalid setting
  242. //
  243. m_bConfigure = TRUE;
  244. m_nEnabledRadio = -1;
  245. m_fNotDefine = FALSE; //Raid #413225, 6/11/2001, Yanggao
  246. }
  247. }
  248. ////////////////////////////////////////////////////////////
  249. // CConfigRegNumber message handlers
  250. //
  251. CConfigRegNumber::CConfigRegNumber(UINT nTemplateID) :
  252. CConfigNumber(nTemplateID ? nTemplateID : IDD)
  253. {
  254. };
  255. void CConfigRegNumber::Initialize(CResult * pResult)
  256. {
  257. LONG_PTR dw = 0;
  258. // Class hieirarchy is bad - call CAttribute base method directly
  259. CAttribute::Initialize(pResult);
  260. m_strUnits = pResult->GetUnits();
  261. m_cMinutes = 0;
  262. m_nLow = 0;
  263. m_nHigh = 999;
  264. m_nSave = 0;
  265. m_iNeverId = 0;
  266. m_iAccRate = 1;
  267. m_iStaticId = 0;
  268. m_strStatic = _T("");
  269. dw = pResult->GetBase();
  270. PSCE_REGISTRY_VALUE_INFO prv=(PSCE_REGISTRY_VALUE_INFO)dw;
  271. //
  272. // HACKHACK: since we don't have a way to specify these values
  273. // in the inf file to get them to the registry where we could
  274. // read and use them here we need to hard code the limits and
  275. // strings for the values we know about.
  276. //
  277. // For the next version we really need this in the inf file &
  278. // registry
  279. //
  280. if (0 == lstrcmpi(prv->FullValueName,RNH_AUTODISCONNECT_NAME))
  281. {
  282. m_nLow = RNH_AUTODISCONNECT_LOW;
  283. m_nHigh = RNH_AUTODISCONNECT_HIGH;
  284. m_cMinutes = RNH_AUTODISCONNECT_FLAGS;
  285. m_iNeverId = RNH_AUTODISCONNECT_SPECIAL_STRING;
  286. m_iStaticId = RNH_AUTODISCONNECT_STATIC_STRING;
  287. }
  288. if (0 == lstrcmpi(prv->FullValueName,RNH_CACHED_LOGONS_NAME))
  289. {
  290. m_nLow = RNH_CACHED_LOGONS_LOW;
  291. m_nHigh = RNH_CACHED_LOGONS_HIGH;
  292. m_cMinutes = RNH_CACHED_LOGONS_FLAGS;
  293. m_iNeverId = RNH_CACHED_LOGONS_SPECIAL_STRING;
  294. m_iStaticId = RNH_CACHED_LOGONS_STATIC_STRING;
  295. }
  296. if (0 == lstrcmpi(prv->FullValueName,RNH_PASSWORD_WARNINGS_NAME))
  297. {
  298. m_nLow = RNH_PASSWORD_WARNINGS_LOW;
  299. m_nHigh = RNH_PASSWORD_WARNINGS_HIGH;
  300. m_cMinutes = RNH_PASSWORD_WARNINGS_FLAGS;
  301. m_iNeverId = RNH_PASSWORD_WARNINGS_SPECIAL_STRING;
  302. m_iStaticId = RNH_PASSWORD_WARNINGS_STATIC_STRING;
  303. }
  304. //
  305. // End HACKHACK
  306. //
  307. dw = (DWORD)pResult->GetBase();
  308. if ( prv && prv->Value )
  309. {
  310. m_bConfigure = TRUE;
  311. m_nSave = _wtol(prv->Value);
  312. SetInitialValue(m_nSave);
  313. }
  314. else
  315. m_bConfigure = FALSE;
  316. }
  317. BOOL CConfigRegNumber::OnApply()
  318. {
  319. if ( !m_bReadOnly )
  320. {
  321. UpdateData(TRUE);
  322. DWORD dw = 0;
  323. if (!m_bConfigure)
  324. dw = SCE_NO_VALUE;
  325. else
  326. dw = CurrentEditValue();
  327. PWSTR sz = NULL;
  328. if ( dw != SCE_NO_VALUE )
  329. {
  330. CString strTmp;
  331. // allocate buffer
  332. strTmp.Format(TEXT("%d"), dw);
  333. sz = (PWSTR)LocalAlloc(0, (strTmp.GetLength()+1)*sizeof(WCHAR));
  334. if (!sz)
  335. {
  336. //
  337. // Display a message?
  338. //
  339. return FALSE;
  340. }
  341. lstrcpy(sz,strTmp);
  342. }
  343. PSCE_REGISTRY_VALUE_INFO prv=(PSCE_REGISTRY_VALUE_INFO)(m_pData->GetBase());
  344. //
  345. // this address should never be NULL
  346. //
  347. ASSERT(prv);
  348. if (prv)
  349. {
  350. if ( prv->Value )
  351. LocalFree(prv->Value);
  352. prv->Value = sz;
  353. }
  354. else if (sz)
  355. LocalFree(sz);
  356. UpdateProfile();
  357. }
  358. // Class hieirarchy is bad - call CAttribute base method directly
  359. return CAttribute::OnApply();
  360. }
  361. void CConfigRegNumber::UpdateProfile()
  362. {
  363. m_pData->Update(m_pSnapin);
  364. }
  365. /////////////////////////////////////////////////////////////////////////////
  366. // CAttrRegNumber message handlers
  367. CAttrRegNumber::CAttrRegNumber() :
  368. CAttrNumber(IDD)
  369. {
  370. };
  371. void CAttrRegNumber::Initialize(CResult * pResult)
  372. {
  373. // Class hieirarchy is bad - call CAttribute base method directly
  374. CAttribute::Initialize(pResult);
  375. m_strUnits = pResult->GetUnits();
  376. m_strTemplateTitle = _T("");
  377. m_strLastInspectTitle = _T("");
  378. m_cMinutes = 0;
  379. m_nLow = 0;
  380. m_nHigh = 999;
  381. m_nSave = 0;
  382. m_iNeverId = 0;
  383. m_iAccRate = 1;
  384. m_iStaticId = 0;
  385. LONG_PTR dw = pResult->GetBase();
  386. PSCE_REGISTRY_VALUE_INFO prv=(PSCE_REGISTRY_VALUE_INFO)dw;
  387. //
  388. // HACKHACK: since we don't have a way to specify these values
  389. // in the inf file to get them to the registry where we could
  390. // read and use them here we need to hard code the limits and
  391. // strings for the values we know about.
  392. //
  393. // For the next version we really need this in the inf file &
  394. // registry
  395. //
  396. if (0 == lstrcmpi(prv->FullValueName,RNH_AUTODISCONNECT_NAME))
  397. {
  398. m_nLow = RNH_AUTODISCONNECT_LOW;
  399. m_nHigh = RNH_AUTODISCONNECT_HIGH;
  400. m_cMinutes = RNH_AUTODISCONNECT_FLAGS;
  401. m_iNeverId = RNH_AUTODISCONNECT_SPECIAL_STRING;
  402. m_iStaticId = RNH_AUTODISCONNECT_STATIC_STRING;
  403. }
  404. if (0 == lstrcmpi(prv->FullValueName,RNH_CACHED_LOGONS_NAME))
  405. {
  406. m_nLow = RNH_CACHED_LOGONS_LOW;
  407. m_nHigh = RNH_CACHED_LOGONS_HIGH;
  408. m_cMinutes = RNH_CACHED_LOGONS_FLAGS;
  409. m_iNeverId = RNH_CACHED_LOGONS_SPECIAL_STRING;
  410. m_iStaticId = RNH_CACHED_LOGONS_STATIC_STRING;
  411. }
  412. if (0 == lstrcmpi(prv->FullValueName,RNH_PASSWORD_WARNINGS_NAME))
  413. {
  414. m_nLow = RNH_PASSWORD_WARNINGS_LOW;
  415. m_nHigh = RNH_PASSWORD_WARNINGS_HIGH;
  416. m_cMinutes = RNH_PASSWORD_WARNINGS_FLAGS;
  417. m_iNeverId = RNH_PASSWORD_WARNINGS_SPECIAL_STRING;
  418. m_iStaticId = RNH_PASSWORD_WARNINGS_STATIC_STRING;
  419. }
  420. //
  421. // End HACKHACK
  422. //
  423. if ( prv && prv->Value )
  424. {
  425. m_bConfigure = TRUE;
  426. m_nSave = _wtol(prv->Value);
  427. SetInitialValue(m_nSave);
  428. }
  429. else
  430. m_bConfigure = FALSE;
  431. pResult->GetDisplayName( NULL, m_strSetting, 2 );
  432. }
  433. BOOL CAttrRegNumber::OnApply()
  434. {
  435. if ( !m_bReadOnly )
  436. {
  437. DWORD dw = 0;
  438. int status = 0;
  439. UpdateData(TRUE);
  440. if (!m_bConfigure)
  441. {
  442. dw = SCE_NO_VALUE;
  443. }
  444. else
  445. {
  446. dw = CurrentEditValue();
  447. }
  448. PSCE_REGISTRY_VALUE_INFO prv=(PSCE_REGISTRY_VALUE_INFO)(m_pData->GetBase());
  449. PSCE_REGISTRY_VALUE_INFO prv2=(PSCE_REGISTRY_VALUE_INFO)(m_pData->GetSetting());
  450. //
  451. // this address should never be NULL
  452. //
  453. if ( prv )
  454. {
  455. DWORD dw2=SCE_NO_VALUE;
  456. if ( prv2 )
  457. {
  458. //
  459. // if there is analysis setting (should always have)
  460. //
  461. if (prv2->Value )
  462. {
  463. dw2 = _wtol(prv2->Value);
  464. }
  465. else
  466. {
  467. dw2 = SCE_NO_VALUE;
  468. }
  469. }
  470. if ( prv->Value )
  471. LocalFree(prv->Value);
  472. prv->Value = NULL;
  473. if ( dw != SCE_NO_VALUE )
  474. {
  475. CString strTmp;
  476. // allocate buffer
  477. strTmp.Format(TEXT("%d"), dw);
  478. prv->Value = (PWSTR)LocalAlloc(0, (strTmp.GetLength()+1)*sizeof(TCHAR));
  479. if ( prv->Value )
  480. wcscpy(prv->Value,(LPCTSTR)strTmp);
  481. else
  482. {
  483. // can't allocate buffer, error!!
  484. }
  485. }
  486. status = CEditTemplate::ComputeStatus (prv, prv2);
  487. UpdateProfile( status );
  488. }
  489. }
  490. // Class hieirarchy is bad - call CAttribute base method directly
  491. return CAttribute::OnApply();
  492. }
  493. void CAttrRegNumber::UpdateProfile( DWORD status )
  494. {
  495. if ( m_pData->GetBaseProfile() )
  496. m_pData->GetBaseProfile()->SetDirty(AREA_SECURITY_POLICY);
  497. m_pData->SetStatus(status);
  498. m_pData->Update(m_pSnapin);
  499. }
  500. /////////////////////////////////////////////////////////////////////////////
  501. // CLocalPolRegNumber message handlers
  502. CLocalPolRegNumber::CLocalPolRegNumber() :
  503. CConfigRegNumber(IDD), m_bInitialValueSet(FALSE)
  504. {
  505. m_pHelpIDs = (DWORD_PTR)a228HelpIDs;
  506. m_uTemplateResID = IDD;
  507. }
  508. void CLocalPolRegNumber::UpdateProfile()
  509. {
  510. m_pSnapin->UpdateLocalPolRegValue(m_pData);
  511. }
  512. void CLocalPolRegNumber::Initialize(CResult * pResult)
  513. {
  514. CConfigRegNumber::Initialize(pResult);
  515. if (!m_bConfigure)
  516. {
  517. //
  518. // Since we don't have a UI to change configuration
  519. // fake it by "configuring" with an invalid setting
  520. //
  521. m_bConfigure = TRUE;
  522. m_bInitialValueSet = TRUE;
  523. m_nSave = 0;
  524. }
  525. }
  526. void CLocalPolRegNumber::SetInitialValue(DWORD_PTR dw)
  527. {
  528. if (m_bConfigure && !m_bInitialValueSet)
  529. {
  530. CConfigRegNumber::SetInitialValue(dw);
  531. m_bInitialValueSet = TRUE;
  532. }
  533. }
  534. /////////////////////////////////////////////////////////////////////////////
  535. // CConfigRegString message handlers
  536. void CConfigRegString::Initialize(CResult * pResult)
  537. {
  538. // Class hieirarchy is bad - call CAttribute base method directly
  539. CAttribute::Initialize(pResult);
  540. PSCE_REGISTRY_VALUE_INFO prv = (PSCE_REGISTRY_VALUE_INFO)(pResult->GetBase());
  541. if ( prv && prv->Value )
  542. {
  543. m_bConfigure = TRUE;
  544. if (QueryMultiSZ())
  545. {
  546. LPTSTR sz = SZToMultiSZ(prv->Value);
  547. m_strName = sz;
  548. LocalFree(sz);
  549. if( REG_SZ == prv->ValueType ) //Raid #376218, 4/25/2001
  550. {
  551. prv->ValueType = REG_MULTI_SZ;
  552. }
  553. }
  554. else
  555. {
  556. m_strName = (LPTSTR) prv->Value;
  557. }
  558. }
  559. else
  560. {
  561. m_strName = _T("");
  562. m_bConfigure = FALSE;
  563. }
  564. }
  565. BOOL CConfigRegString::OnApply()
  566. {
  567. if ( !m_bReadOnly )
  568. {
  569. DWORD dw = 0;
  570. UpdateData(TRUE);
  571. m_strName.TrimRight();
  572. // 249188 SCE UI: allows adding empty lines to REG_MULTI_SZ fields
  573. // Replace all double newlines with single newlines. This has the effect
  574. // of deleting empty lines.
  575. CString szDoubleNewLine (g_pcszNEWLINE);
  576. szDoubleNewLine += g_pcszNEWLINE;
  577. while (m_strName.Replace (szDoubleNewLine, g_pcszNEWLINE) != 0);
  578. UpdateData (FALSE); // put the corrected string back in the control
  579. PSCE_REGISTRY_VALUE_INFO prv = (PSCE_REGISTRY_VALUE_INFO)(m_pData->GetBase());
  580. if ( prv )
  581. {
  582. if (!m_bConfigure)
  583. {
  584. if ( prv->Value )
  585. LocalFree(prv->Value);
  586. prv->Value = NULL;
  587. this->UpdateProfile();
  588. }
  589. else
  590. {
  591. LPTSTR prvpt = NULL;
  592. LPTSTR pt = 0;
  593. if (QueryMultiSZ())
  594. pt = MultiSZToSZ(m_strName);
  595. else
  596. {
  597. pt = (PWSTR)LocalAlloc(0, (m_strName.GetLength()+1)*sizeof(TCHAR));
  598. if ( pt )
  599. wcscpy(pt, (LPCTSTR)m_strName);
  600. }
  601. if ( pt )
  602. {
  603. if ( prv->Value )
  604. prvpt = prv->Value;
  605. prv->Value = pt;
  606. }
  607. else
  608. {
  609. // can't allocate buffer error!!
  610. }
  611. if( !(this->UpdateProfile()) )
  612. {
  613. if ( prv->Value )
  614. LocalFree(prv->Value);
  615. prv->Value = prvpt;
  616. }
  617. else
  618. {
  619. if( prvpt)
  620. LocalFree(prvpt);
  621. }
  622. }
  623. }
  624. }
  625. // Class hieirarchy is bad - call CAttribute base method directly
  626. return CAttribute::OnApply();
  627. }
  628. BOOL CConfigRegString::UpdateProfile()
  629. {
  630. if ( m_pData->GetBaseProfile() )
  631. {
  632. if( !(m_pData->GetBaseProfile()->SetDirty(AREA_SECURITY_POLICY)) )
  633. {
  634. m_pData->Update(m_pSnapin);
  635. return FALSE;
  636. }
  637. else
  638. {
  639. m_pData->Update(m_pSnapin);
  640. return TRUE;
  641. }
  642. }
  643. m_pData->Update(m_pSnapin);
  644. return FALSE;
  645. }
  646. /////////////////////////////////////////////////////////////////////////////
  647. // CAttrString message handlers
  648. void CAttrRegString::Initialize(CResult * pResult)
  649. {
  650. // Class hieirarchy is bad - call CAttribute base method directly
  651. CAttribute::Initialize(pResult);
  652. m_strBase.Empty();
  653. m_strSetting.Empty();
  654. PSCE_REGISTRY_VALUE_INFO prv;
  655. prv = (PSCE_REGISTRY_VALUE_INFO)(pResult->GetSetting());
  656. pResult->GetDisplayName( NULL, m_strSetting, 2 );
  657. prv = (PSCE_REGISTRY_VALUE_INFO)(pResult->GetBase());
  658. if ( prv && prv->Value )
  659. {
  660. m_bConfigure = TRUE;
  661. if (QueryMultiSZ())
  662. {
  663. LPTSTR sz = SZToMultiSZ(prv->Value);
  664. m_strBase = sz;
  665. LocalFree(sz);
  666. }
  667. else
  668. {
  669. m_strBase = (LPTSTR) prv->Value;
  670. }
  671. }
  672. else
  673. m_bConfigure = FALSE;
  674. }
  675. BOOL CAttrRegString::OnApply()
  676. {
  677. if ( !m_bReadOnly )
  678. {
  679. DWORD dw = 0;
  680. UpdateData(TRUE);
  681. int status=SCE_STATUS_GOOD;
  682. PSCE_REGISTRY_VALUE_INFO prv = (PSCE_REGISTRY_VALUE_INFO)(m_pData->GetBase());
  683. PSCE_REGISTRY_VALUE_INFO prv2 = (PSCE_REGISTRY_VALUE_INFO)(m_pData->GetSetting());
  684. m_strBase.TrimRight();
  685. if ( prv )
  686. {
  687. if (!m_bConfigure)
  688. {
  689. if ( prv->Value )
  690. LocalFree(prv->Value);
  691. prv->Value = NULL;
  692. }
  693. else
  694. {
  695. LPTSTR pt = 0;
  696. if (QueryMultiSZ())
  697. pt = MultiSZToSZ(m_strBase);
  698. else
  699. {
  700. pt = (PWSTR)LocalAlloc(0, (m_strBase.GetLength()+1)*sizeof(TCHAR));
  701. if ( pt )
  702. wcscpy(pt, (LPCTSTR)m_strBase);
  703. }
  704. if ( pt )
  705. {
  706. if ( prv->Value )
  707. LocalFree(prv->Value);
  708. prv->Value = pt;
  709. }
  710. else
  711. {
  712. // can't allocate buffer error!!
  713. }
  714. }
  715. status = CEditTemplate::ComputeStatus(prv, prv2);
  716. UpdateProfile( status );
  717. }
  718. }
  719. // Class hieirarchy is bad - call CAttribute base method directly
  720. return CAttribute::OnApply();
  721. }
  722. //+----------------------------------------------------------------------------------------------
  723. // CAttrRegString::UpdateProfile
  724. //
  725. // This function is called by OnApply after all the data has been retrieved from the dialog.
  726. // Inherited classes can overload this function to update the data as needed.
  727. //
  728. // Arguments: [status] - The status of [m_pData] from OnApply();
  729. //
  730. //----------------------------------------------------------------------------------------------
  731. void CAttrRegString::UpdateProfile( DWORD status )
  732. {
  733. if ( m_pData->GetBaseProfile() )
  734. m_pData->GetBaseProfile()->SetDirty(AREA_SECURITY_POLICY);
  735. m_pData->SetStatus(status);
  736. m_pData->Update(m_pSnapin);
  737. }
  738. /////////////////////////////////////////////////////////////////////////////
  739. // CLocalPolRegString message handlers
  740. //+----------------------------------------------------------------------------------------------
  741. // CLocalPolRegString::UpdateProfile
  742. //
  743. // This function is called by OnApply after all the data has been retrieved from the dialog.
  744. // Inherited classes can overload this function to update the data as needed.
  745. //
  746. // Arguments: [status] - The status of [m_pData] from OnApply();
  747. //
  748. //----------------------------------------------------------------------------------------------
  749. BOOL CLocalPolRegString::UpdateProfile( )
  750. {
  751. return m_pSnapin->UpdateLocalPolRegValue(m_pData);
  752. }
  753. void CLocalPolRegString::Initialize(CResult * pResult)
  754. {
  755. CConfigRegString::Initialize(pResult);
  756. if (!m_bConfigure)
  757. {
  758. //
  759. // Since we don't have a UI to change configuration
  760. // fake it by "configuring" with an invalid setting
  761. //
  762. m_bConfigure = TRUE;
  763. m_strName = _T("");
  764. }
  765. }
  766. /////////////////////////////////////////////////////////////////////////////
  767. // CConfigRegChoice message handlers
  768. void CConfigRegChoice::Initialize(CResult * pResult)
  769. {
  770. // Class hieirarchy is bad - call CAttribute base method directly
  771. CAttribute::Initialize(pResult);
  772. m_strAttrName = pResult->GetAttrPretty();
  773. m_StartIds=IDS_LM_FULL;
  774. PSCE_REGISTRY_VALUE_INFO prv = (PSCE_REGISTRY_VALUE_INFO)(pResult->GetBase());
  775. if ( prv && prv->Value )
  776. {
  777. m_bConfigure = TRUE;
  778. switch(_wtol(prv->Value))
  779. {
  780. case SCE_RETAIN_ALWAYS:
  781. m_rabRetention = 0;
  782. break;
  783. case SCE_RETAIN_AS_REQUEST:
  784. m_rabRetention = 1;
  785. break;
  786. case SCE_RETAIN_NC:
  787. m_rabRetention = 2;
  788. break;
  789. }
  790. }
  791. else
  792. m_bConfigure = FALSE;
  793. }
  794. BOOL CConfigRegChoice::OnInitDialog()
  795. {
  796. CConfigRet::OnInitDialog();
  797. //
  798. // load static text for the radio buttons
  799. //
  800. CString strText;
  801. strText.LoadString(m_StartIds);
  802. SetDlgItemText( IDC_RETENTION, strText );
  803. strText.LoadString(m_StartIds+1);
  804. SetDlgItemText( IDC_RADIO2, strText );
  805. strText.LoadString(m_StartIds+2);
  806. SetDlgItemText( IDC_RADIO3, strText );
  807. OnConfigure();
  808. return TRUE; // return TRUE unless you set the focus to a control
  809. // EXCEPTION: OCX Property Pages should return FALSE
  810. }
  811. BOOL CConfigRegChoice::OnApply()
  812. {
  813. if ( !m_bReadOnly )
  814. {
  815. DWORD dw = 0;
  816. UpdateData(TRUE);
  817. PSCE_REGISTRY_VALUE_INFO prv = (PSCE_REGISTRY_VALUE_INFO)(m_pData->GetBase());
  818. if ( prv )
  819. {
  820. if (!m_bConfigure)
  821. {
  822. if ( prv->Value )
  823. LocalFree(prv->Value);
  824. prv->Value = NULL;
  825. }
  826. else
  827. {
  828. switch(m_rabRetention)
  829. {
  830. case 0:
  831. dw = SCE_RETAIN_ALWAYS;
  832. break;
  833. case 1:
  834. dw = SCE_RETAIN_AS_REQUEST;
  835. break;
  836. case 2:
  837. dw = SCE_RETAIN_NC;
  838. break;
  839. }
  840. if ( prv->Value == NULL )
  841. {
  842. // allocate buffer
  843. prv->Value = (PWSTR)LocalAlloc(0, 4);
  844. }
  845. if ( prv->Value )
  846. {
  847. prv->Value[0] = (int)dw + L'0';
  848. prv->Value[1] = L'\0';
  849. }
  850. else
  851. {
  852. // can't allocate buffer, error!!
  853. }
  854. }
  855. m_pData->Update(m_pSnapin);
  856. }
  857. }
  858. // Class hieirarchy is bad - call CAttribute base method directly
  859. return CAttribute::OnApply();
  860. }
  861. /////////////////////////////////////////////////////////////////////////////
  862. // CAttrRegChoice message handlers
  863. void CAttrRegChoice::Initialize(CResult * pData)
  864. {
  865. DWORD dw = 0;
  866. // Class hieirarchy is bad - call CAttribute base method directly
  867. CAttribute::Initialize(pData);
  868. // Display the last inspected setting in its static box
  869. pData->GetDisplayName( NULL, m_strLastInspect, 2 );
  870. // Set the template setting radio button appropriately
  871. m_strAttrName = pData->GetAttrPretty();
  872. m_StartIds=IDS_LM_FULL;
  873. PSCE_REGISTRY_VALUE_INFO prv = (PSCE_REGISTRY_VALUE_INFO)(pData->GetBase());
  874. if ( prv && prv->Value )
  875. {
  876. m_bConfigure = TRUE;
  877. switch(_wtol(prv->Value))
  878. {
  879. case SCE_RETAIN_ALWAYS:
  880. m_rabRetention = 0;
  881. break;
  882. case SCE_RETAIN_AS_REQUEST:
  883. m_rabRetention = 1;
  884. break;
  885. case SCE_RETAIN_NC:
  886. m_rabRetention = 2;
  887. break;
  888. }
  889. }
  890. else
  891. {
  892. m_bConfigure = FALSE;
  893. }
  894. }
  895. BOOL CAttrRegChoice::OnInitDialog()
  896. {
  897. CAttrRet::OnInitDialog();
  898. //
  899. // load static text for the radio buttons
  900. //
  901. CString strText;
  902. strText.LoadString(m_StartIds);
  903. SetDlgItemText( IDC_RETENTION, strText );
  904. strText.LoadString(m_StartIds+1);
  905. SetDlgItemText( IDC_RADIO2, strText );
  906. strText.LoadString(m_StartIds+2);
  907. SetDlgItemText( IDC_RADIO3, strText );
  908. CAttrRet::OnInitDialog();
  909. return TRUE; // return TRUE unless you set the focus to a control
  910. // EXCEPTION: OCX Property Pages should return FALSE
  911. }
  912. BOOL CAttrRegChoice::OnApply()
  913. {
  914. if ( !m_bReadOnly )
  915. {
  916. DWORD dw = 0;
  917. int status = 0;
  918. UpdateData(TRUE);
  919. if (!m_bConfigure)
  920. dw = SCE_NO_VALUE;
  921. else
  922. {
  923. switch(m_rabRetention)
  924. {
  925. case 0:
  926. dw = SCE_RETAIN_ALWAYS;
  927. break;
  928. case 1:
  929. dw = SCE_RETAIN_AS_REQUEST;
  930. break;
  931. case 2:
  932. dw = SCE_RETAIN_NC;
  933. break;
  934. }
  935. }
  936. PSCE_REGISTRY_VALUE_INFO prv=(PSCE_REGISTRY_VALUE_INFO)(m_pData->GetBase());
  937. PSCE_REGISTRY_VALUE_INFO prv2=(PSCE_REGISTRY_VALUE_INFO)(m_pData->GetSetting());
  938. //
  939. // this address should never be NULL
  940. //
  941. if ( prv )
  942. {
  943. DWORD dw2=SCE_NO_VALUE;
  944. if ( prv2 )
  945. {
  946. //
  947. // if there is analysis setting (should always have)
  948. //
  949. if (prv2->Value )
  950. dw2 = _wtol(prv2->Value);
  951. else
  952. dw2 = SCE_NO_VALUE;
  953. }
  954. status = CEditTemplate::ComputeStatus (prv, prv2);
  955. if ( dw == SCE_NO_VALUE )
  956. {
  957. if ( prv->Value )
  958. LocalFree(prv->Value);
  959. prv->Value = NULL;
  960. }
  961. else
  962. {
  963. if ( prv->Value == NULL )
  964. {
  965. // allocate buffer
  966. prv->Value = (PWSTR)LocalAlloc(0, 4);
  967. }
  968. if ( prv->Value )
  969. {
  970. prv->Value[0] = (int)dw + L'0';
  971. prv->Value[1] = L'\0';
  972. }
  973. else
  974. {
  975. // can't allocate buffer, error!!
  976. }
  977. }
  978. UpdateProfile( status );
  979. }
  980. }
  981. // Class hieirarchy is bad - call CAttribute base method directly
  982. return CAttribute::OnApply();
  983. }
  984. void CAttrRegChoice::UpdateProfile( DWORD status )
  985. {
  986. if ( m_pData->GetBaseProfile() )
  987. m_pData->GetBaseProfile()->SetDirty(AREA_SECURITY_POLICY);
  988. m_pData->SetStatus(status);
  989. m_pData->Update(m_pSnapin);
  990. }
  991. /////////////////////////////////////////////////////////////////////////////
  992. // CLocalPolRegChoice message handlers
  993. void CLocalPolRegChoice::UpdateProfile(DWORD status)
  994. {
  995. m_pSnapin->UpdateLocalPolRegValue(m_pData);
  996. }
  997. void CLocalPolRegChoice::Initialize(CResult * pResult)
  998. {
  999. CConfigRegChoice::Initialize(pResult);
  1000. if (!m_bConfigure)
  1001. {
  1002. //
  1003. // Since we don't have a UI to change configuration
  1004. // fake it by "configuring" with an invalid setting
  1005. //
  1006. m_bConfigure = TRUE;
  1007. m_rabRetention = 0;
  1008. }
  1009. }
  1010. BOOL CSnapin::UpdateLocalPolRegValue( CResult *pResult ) {
  1011. if ( !pResult)
  1012. return FALSE;
  1013. PEDITTEMPLATE pLocalDeltaTemplate = GetTemplate(GT_LOCAL_POLICY_DELTA,AREA_SECURITY_POLICY);
  1014. if (!pLocalDeltaTemplate)
  1015. return FALSE;
  1016. PSCE_PROFILE_INFO pLocalDelta = pLocalDeltaTemplate->pTemplate;
  1017. pLocalDelta->RegValueCount = 1;
  1018. pLocalDelta->aRegValues = (PSCE_REGISTRY_VALUE_INFO)pResult->GetBase();
  1019. if( pLocalDeltaTemplate->SetDirty(AREA_SECURITY_POLICY) )
  1020. {
  1021. //
  1022. // Set the status of the item.
  1023. //
  1024. PSCE_REGISTRY_VALUE_INFO pRviEffective = (PSCE_REGISTRY_VALUE_INFO)pResult->GetSetting();
  1025. DWORD status = pResult->GetStatus();
  1026. if(!pRviEffective || !pRviEffective->Value)
  1027. status = SCE_STATUS_NOT_ANALYZED;
  1028. else
  1029. status = CEditTemplate::ComputeStatus( (PSCE_REGISTRY_VALUE_INFO)pResult->GetBase(), pRviEffective );
  1030. pResult->SetStatus(status);
  1031. pResult->Update(this);
  1032. return TRUE;
  1033. }
  1034. return FALSE;
  1035. }