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.

1264 lines
33 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. SetZeroValueFlag(false); //Raid 509322, Yanggao, 1/3/2002, make sure zero is a useful value.
  269. m_strStatic = _T("");
  270. dw = pResult->GetBase();
  271. PSCE_REGISTRY_VALUE_INFO prv=(PSCE_REGISTRY_VALUE_INFO)dw;
  272. //
  273. // HACKHACK: since we don't have a way to specify these values
  274. // in the inf file to get them to the registry where we could
  275. // read and use them here we need to hard code the limits and
  276. // strings for the values we know about.
  277. //
  278. // For the next version we really need this in the inf file &
  279. // registry
  280. //
  281. // Prefast warning: Yields unexpected results in non-English locales.
  282. // Comments: These three constant strings are not localizable.
  283. if (0 == _wcsicmp(prv->FullValueName,RNH_AUTODISCONNECT_NAME))
  284. {
  285. m_nLow = RNH_AUTODISCONNECT_LOW;
  286. m_nHigh = RNH_AUTODISCONNECT_HIGH;
  287. m_cMinutes = RNH_AUTODISCONNECT_FLAGS;
  288. m_iNeverId = RNH_AUTODISCONNECT_SPECIAL_STRING;
  289. m_iStaticId = RNH_AUTODISCONNECT_STATIC_STRING;
  290. SetZeroValueFlag(true); //Raid 509322, Yanggao, 1/3/2002, make sure zero is a useful value.
  291. }
  292. if (0 == _wcsicmp(prv->FullValueName,RNH_CACHED_LOGONS_NAME))
  293. {
  294. m_nLow = RNH_CACHED_LOGONS_LOW;
  295. m_nHigh = RNH_CACHED_LOGONS_HIGH;
  296. m_cMinutes = RNH_CACHED_LOGONS_FLAGS;
  297. m_iNeverId = RNH_CACHED_LOGONS_SPECIAL_STRING;
  298. m_iStaticId = RNH_CACHED_LOGONS_STATIC_STRING;
  299. }
  300. if (0 == _wcsicmp(prv->FullValueName,RNH_PASSWORD_WARNINGS_NAME))
  301. {
  302. m_nLow = RNH_PASSWORD_WARNINGS_LOW;
  303. m_nHigh = RNH_PASSWORD_WARNINGS_HIGH;
  304. m_cMinutes = RNH_PASSWORD_WARNINGS_FLAGS;
  305. m_iNeverId = RNH_PASSWORD_WARNINGS_SPECIAL_STRING;
  306. m_iStaticId = RNH_PASSWORD_WARNINGS_STATIC_STRING;
  307. }
  308. //
  309. // End HACKHACK
  310. //
  311. if ( prv && prv->Value )
  312. {
  313. m_bConfigure = TRUE;
  314. //Raid #702113, yanggao, 9/12/2002
  315. if( prv->ValueType != REG_MULTI_SZ && prv->ValueType != REG_SZ &&
  316. prv->ValueType != REG_EXPAND_SZ )
  317. {
  318. m_nSave = _wtol(prv->Value);
  319. }
  320. else
  321. {
  322. m_nSave = (DWORD_PTR)(prv->Value);
  323. }
  324. SetInitialValue(m_nSave);
  325. }
  326. else
  327. m_bConfigure = FALSE;
  328. }
  329. BOOL CConfigRegNumber::OnApply()
  330. {
  331. if ( !m_bReadOnly )
  332. {
  333. UpdateData(TRUE);
  334. DWORD dw = 0;
  335. if (!m_bConfigure)
  336. dw = SCE_NO_VALUE;
  337. else
  338. dw = CurrentEditValue();
  339. PWSTR sz = NULL;
  340. if ( dw != SCE_NO_VALUE )
  341. {
  342. CString strTmp;
  343. // allocate buffer
  344. strTmp.Format(TEXT("%d"), dw);
  345. sz = (PWSTR)LocalAlloc(0, (strTmp.GetLength()+1)*sizeof(WCHAR));
  346. if (!sz)
  347. {
  348. //
  349. // Display a message?
  350. //
  351. return FALSE;
  352. }
  353. //This may not be a safe usage. sz is PWSTR. Consider fix.
  354. lstrcpy(sz,strTmp);
  355. }
  356. PSCE_REGISTRY_VALUE_INFO prv=(PSCE_REGISTRY_VALUE_INFO)(m_pData->GetBase());
  357. //
  358. // this address should never be NULL
  359. //
  360. ASSERT(prv);
  361. if (prv)
  362. {
  363. if ( prv->Value )
  364. LocalFree(prv->Value);
  365. prv->Value = sz;
  366. }
  367. else if (sz)
  368. LocalFree(sz);
  369. UpdateProfile();
  370. }
  371. // Class hieirarchy is bad - call CAttribute base method directly
  372. return CAttribute::OnApply();
  373. }
  374. void CConfigRegNumber::UpdateProfile()
  375. {
  376. m_pData->Update(m_pSnapin);
  377. }
  378. /////////////////////////////////////////////////////////////////////////////
  379. // CAttrRegNumber message handlers
  380. CAttrRegNumber::CAttrRegNumber() :
  381. CAttrNumber(IDD)
  382. {
  383. };
  384. void CAttrRegNumber::Initialize(CResult * pResult)
  385. {
  386. // Class hieirarchy is bad - call CAttribute base method directly
  387. CAttribute::Initialize(pResult);
  388. m_strUnits = pResult->GetUnits();
  389. m_strTemplateTitle = _T("");
  390. m_strLastInspectTitle = _T("");
  391. m_cMinutes = 0;
  392. m_nLow = 0;
  393. m_nHigh = 999;
  394. m_nSave = 0;
  395. m_iNeverId = 0;
  396. m_iAccRate = 1;
  397. m_iStaticId = 0;
  398. LONG_PTR dw = pResult->GetBase();
  399. PSCE_REGISTRY_VALUE_INFO prv=(PSCE_REGISTRY_VALUE_INFO)dw;
  400. //
  401. // HACKHACK: since we don't have a way to specify these values
  402. // in the inf file to get them to the registry where we could
  403. // read and use them here we need to hard code the limits and
  404. // strings for the values we know about.
  405. //
  406. // For the next version we really need this in the inf file &
  407. // registry
  408. // Prefast warning: Yields unexpected results in non-English locales.
  409. // Comments: These three constant strings are not localizable.
  410. if (0 == _wcsicmp(prv->FullValueName,RNH_AUTODISCONNECT_NAME))
  411. {
  412. m_nLow = RNH_AUTODISCONNECT_LOW;
  413. m_nHigh = RNH_AUTODISCONNECT_HIGH;
  414. m_cMinutes = RNH_AUTODISCONNECT_FLAGS;
  415. m_iNeverId = RNH_AUTODISCONNECT_SPECIAL_STRING;
  416. m_iStaticId = RNH_AUTODISCONNECT_STATIC_STRING;
  417. }
  418. if (0 == _wcsicmp(prv->FullValueName,RNH_CACHED_LOGONS_NAME))
  419. {
  420. m_nLow = RNH_CACHED_LOGONS_LOW;
  421. m_nHigh = RNH_CACHED_LOGONS_HIGH;
  422. m_cMinutes = RNH_CACHED_LOGONS_FLAGS;
  423. m_iNeverId = RNH_CACHED_LOGONS_SPECIAL_STRING;
  424. m_iStaticId = RNH_CACHED_LOGONS_STATIC_STRING;
  425. }
  426. if (0 == _wcsicmp(prv->FullValueName,RNH_PASSWORD_WARNINGS_NAME))
  427. {
  428. m_nLow = RNH_PASSWORD_WARNINGS_LOW;
  429. m_nHigh = RNH_PASSWORD_WARNINGS_HIGH;
  430. m_cMinutes = RNH_PASSWORD_WARNINGS_FLAGS;
  431. m_iNeverId = RNH_PASSWORD_WARNINGS_SPECIAL_STRING;
  432. m_iStaticId = RNH_PASSWORD_WARNINGS_STATIC_STRING;
  433. }
  434. //
  435. // End HACKHACK
  436. //
  437. if ( prv && prv->Value )
  438. {
  439. m_bConfigure = TRUE;
  440. m_nSave = _wtol(prv->Value);
  441. SetInitialValue(m_nSave);
  442. }
  443. else
  444. m_bConfigure = FALSE;
  445. pResult->GetDisplayName( NULL, m_strSetting, 2 );
  446. }
  447. BOOL CAttrRegNumber::OnApply()
  448. {
  449. if ( !m_bReadOnly )
  450. {
  451. DWORD dw = 0;
  452. int status = 0;
  453. UpdateData(TRUE);
  454. if (!m_bConfigure)
  455. {
  456. dw = SCE_NO_VALUE;
  457. }
  458. else
  459. {
  460. dw = CurrentEditValue();
  461. }
  462. PSCE_REGISTRY_VALUE_INFO prv=(PSCE_REGISTRY_VALUE_INFO)(m_pData->GetBase());
  463. PSCE_REGISTRY_VALUE_INFO prv2=(PSCE_REGISTRY_VALUE_INFO)(m_pData->GetSetting());
  464. //
  465. // this address should never be NULL
  466. //
  467. if ( prv )
  468. {
  469. DWORD dw2=SCE_NO_VALUE;
  470. if ( prv2 )
  471. {
  472. //
  473. // if there is analysis setting (should always have)
  474. //
  475. if (prv2->Value )
  476. {
  477. dw2 = _wtol(prv2->Value);
  478. }
  479. else
  480. {
  481. dw2 = SCE_NO_VALUE;
  482. }
  483. }
  484. if ( prv->Value )
  485. LocalFree(prv->Value);
  486. prv->Value = NULL;
  487. if ( dw != SCE_NO_VALUE )
  488. {
  489. CString strTmp;
  490. // allocate buffer
  491. strTmp.Format(TEXT("%d"), dw);
  492. prv->Value = (PWSTR)LocalAlloc(0, (strTmp.GetLength()+1)*sizeof(TCHAR));
  493. if ( prv->Value )
  494. //This may not be a safe usage. prv->Value is LPTSTR. Consider fix.
  495. wcscpy(prv->Value,(LPCTSTR)strTmp);
  496. else
  497. {
  498. // can't allocate buffer, error!!
  499. }
  500. }
  501. status = CEditTemplate::ComputeStatus (prv, prv2);
  502. UpdateProfile( status );
  503. }
  504. }
  505. // Class hieirarchy is bad - call CAttribute base method directly
  506. return CAttribute::OnApply();
  507. }
  508. void CAttrRegNumber::UpdateProfile( DWORD status )
  509. {
  510. if ( m_pData->GetBaseProfile() )
  511. m_pData->GetBaseProfile()->SetDirty(AREA_SECURITY_POLICY);
  512. m_pData->SetStatus(status);
  513. m_pData->Update(m_pSnapin);
  514. }
  515. /////////////////////////////////////////////////////////////////////////////
  516. // CLocalPolRegNumber message handlers
  517. CLocalPolRegNumber::CLocalPolRegNumber() :
  518. CConfigRegNumber(IDD), m_bInitialValueSet(FALSE)
  519. {
  520. m_pHelpIDs = (DWORD_PTR)a228HelpIDs;
  521. m_uTemplateResID = IDD;
  522. }
  523. void CLocalPolRegNumber::UpdateProfile()
  524. {
  525. m_pSnapin->UpdateLocalPolRegValue(m_pData);
  526. }
  527. void CLocalPolRegNumber::Initialize(CResult * pResult)
  528. {
  529. CConfigRegNumber::Initialize(pResult);
  530. if (!m_bConfigure)
  531. {
  532. //
  533. // Since we don't have a UI to change configuration
  534. // fake it by "configuring" with an invalid setting
  535. //
  536. m_bConfigure = TRUE;
  537. m_bInitialValueSet = TRUE;
  538. m_nSave = 0;
  539. }
  540. }
  541. void CLocalPolRegNumber::SetInitialValue(DWORD_PTR dw)
  542. {
  543. if (m_bConfigure && !m_bInitialValueSet)
  544. {
  545. CConfigRegNumber::SetInitialValue(dw);
  546. m_bInitialValueSet = TRUE;
  547. }
  548. }
  549. /////////////////////////////////////////////////////////////////////////////
  550. // CConfigRegString message handlers
  551. void CConfigRegString::Initialize(CResult * pResult)
  552. {
  553. // Class hieirarchy is bad - call CAttribute base method directly
  554. CAttribute::Initialize(pResult);
  555. PSCE_REGISTRY_VALUE_INFO prv = (PSCE_REGISTRY_VALUE_INFO)(pResult->GetBase());
  556. if ( prv && prv->Value )
  557. {
  558. m_bConfigure = TRUE;
  559. if (QueryMultiSZ())
  560. {
  561. LPTSTR sz = SZToMultiSZ(prv->Value);
  562. m_strName = sz;
  563. LocalFree(sz);
  564. if( REG_SZ == prv->ValueType ) //Raid #376218, 4/25/2001
  565. {
  566. prv->ValueType = REG_MULTI_SZ;
  567. }
  568. }
  569. else
  570. {
  571. m_strName = (LPTSTR) prv->Value;
  572. }
  573. }
  574. else
  575. {
  576. m_strName = _T("");
  577. m_bConfigure = FALSE;
  578. }
  579. }
  580. BOOL CConfigRegString::OnApply()
  581. {
  582. if ( !m_bReadOnly )
  583. {
  584. DWORD dw = 0;
  585. UpdateData(TRUE);
  586. m_strName.TrimRight();
  587. UpdateData (FALSE); // put the corrected string back in the control
  588. PSCE_REGISTRY_VALUE_INFO prv = (PSCE_REGISTRY_VALUE_INFO)(m_pData->GetBase());
  589. if ( prv )
  590. {
  591. if (!m_bConfigure)
  592. {
  593. if ( prv->Value )
  594. LocalFree(prv->Value);
  595. prv->Value = NULL;
  596. this->UpdateProfile();
  597. }
  598. else
  599. {
  600. LPTSTR prvpt = NULL;
  601. LPTSTR pt = 0;
  602. if (QueryMultiSZ())
  603. pt = MultiSZToSZ(m_strName);
  604. else
  605. {
  606. pt = (PWSTR)LocalAlloc(0, (m_strName.GetLength()+1)*sizeof(TCHAR));
  607. if ( pt )
  608. //This may not be a safe usage. pt is LPTSTR. Consider fix.
  609. wcscpy(pt, (LPCTSTR)m_strName);
  610. }
  611. if ( pt )
  612. {
  613. if ( prv->Value )
  614. prvpt = prv->Value;
  615. prv->Value = pt;
  616. if( QueryMultiSZ() ) //Raid #686565, yanggao, 8/22/2002
  617. {
  618. //Raid #506090, 12/14/2001, yanggao
  619. //Delete space and empty newlines
  620. UpdateData(TRUE);
  621. LPTSTR sz = SZToMultiSZ(pt);
  622. if( sz )
  623. {
  624. m_strName = sz;
  625. LocalFree(sz);
  626. }
  627. UpdateData(FALSE);
  628. }
  629. }
  630. else
  631. {
  632. // can't allocate buffer error!!
  633. }
  634. if( !(this->UpdateProfile()) )
  635. {
  636. if ( prv->Value )
  637. LocalFree(prv->Value);
  638. prv->Value = prvpt;
  639. }
  640. else
  641. {
  642. if( prvpt)
  643. LocalFree(prvpt);
  644. }
  645. }
  646. }
  647. }
  648. // Class hieirarchy is bad - call CAttribute base method directly
  649. return CAttribute::OnApply();
  650. }
  651. BOOL CConfigRegString::UpdateProfile()
  652. {
  653. if ( m_pData->GetBaseProfile() )
  654. {
  655. if( !(m_pData->GetBaseProfile()->SetDirty(AREA_SECURITY_POLICY)) )
  656. {
  657. m_pData->Update(m_pSnapin);
  658. return FALSE;
  659. }
  660. else
  661. {
  662. m_pData->Update(m_pSnapin);
  663. return TRUE;
  664. }
  665. }
  666. m_pData->Update(m_pSnapin);
  667. return FALSE;
  668. }
  669. /////////////////////////////////////////////////////////////////////////////
  670. // CAttrString message handlers
  671. void CAttrRegString::Initialize(CResult * pResult)
  672. {
  673. // Class hieirarchy is bad - call CAttribute base method directly
  674. CAttribute::Initialize(pResult);
  675. m_strBase.Empty();
  676. m_strSetting.Empty();
  677. PSCE_REGISTRY_VALUE_INFO prv;
  678. prv = (PSCE_REGISTRY_VALUE_INFO)(pResult->GetSetting());
  679. pResult->GetDisplayName( NULL, m_strSetting, 2 );
  680. prv = (PSCE_REGISTRY_VALUE_INFO)(pResult->GetBase());
  681. if ( prv && prv->Value )
  682. {
  683. m_bConfigure = TRUE;
  684. if (QueryMultiSZ())
  685. {
  686. LPTSTR sz = SZToMultiSZ(prv->Value);
  687. m_strBase = sz;
  688. LocalFree(sz);
  689. }
  690. else
  691. {
  692. m_strBase = (LPTSTR) prv->Value;
  693. }
  694. }
  695. else
  696. m_bConfigure = FALSE;
  697. }
  698. BOOL CAttrRegString::OnApply()
  699. {
  700. if ( !m_bReadOnly )
  701. {
  702. DWORD dw = 0;
  703. UpdateData(TRUE);
  704. int status=SCE_STATUS_GOOD;
  705. PSCE_REGISTRY_VALUE_INFO prv = (PSCE_REGISTRY_VALUE_INFO)(m_pData->GetBase());
  706. PSCE_REGISTRY_VALUE_INFO prv2 = (PSCE_REGISTRY_VALUE_INFO)(m_pData->GetSetting());
  707. m_strBase.TrimRight();
  708. if ( prv )
  709. {
  710. if (!m_bConfigure)
  711. {
  712. if ( prv->Value )
  713. LocalFree(prv->Value);
  714. prv->Value = NULL;
  715. }
  716. else
  717. {
  718. LPTSTR pt = 0;
  719. if (QueryMultiSZ())
  720. pt = MultiSZToSZ(m_strBase);
  721. else
  722. {
  723. pt = (PWSTR)LocalAlloc(0, (m_strBase.GetLength()+1)*sizeof(TCHAR));
  724. if ( pt )
  725. //This may not be a safe usage. pt is a LPTSTR. Consider fix.
  726. wcscpy(pt, (LPCTSTR)m_strBase);
  727. }
  728. if ( pt )
  729. {
  730. if ( prv->Value )
  731. LocalFree(prv->Value);
  732. prv->Value = pt;
  733. //Raid #506090, 12/14/2001, yanggao
  734. //Delete space and empty newlines
  735. UpdateData(TRUE);
  736. LPTSTR sz = SZToMultiSZ(pt);
  737. if( sz )
  738. {
  739. m_strBase = sz;
  740. LocalFree(sz);
  741. }
  742. UpdateData(FALSE);
  743. }
  744. else
  745. {
  746. // can't allocate buffer error!!
  747. }
  748. }
  749. status = CEditTemplate::ComputeStatus(prv, prv2);
  750. UpdateProfile( status );
  751. }
  752. }
  753. // Class hieirarchy is bad - call CAttribute base method directly
  754. return CAttribute::OnApply();
  755. }
  756. //+----------------------------------------------------------------------------------------------
  757. // CAttrRegString::UpdateProfile
  758. //
  759. // This function is called by OnApply after all the data has been retrieved from the dialog.
  760. // Inherited classes can overload this function to update the data as needed.
  761. //
  762. // Arguments: [status] - The status of [m_pData] from OnApply();
  763. //
  764. //----------------------------------------------------------------------------------------------
  765. void CAttrRegString::UpdateProfile( DWORD status )
  766. {
  767. if ( m_pData->GetBaseProfile() )
  768. m_pData->GetBaseProfile()->SetDirty(AREA_SECURITY_POLICY);
  769. m_pData->SetStatus(status);
  770. m_pData->Update(m_pSnapin);
  771. }
  772. /////////////////////////////////////////////////////////////////////////////
  773. // CLocalPolRegString message handlers
  774. //+----------------------------------------------------------------------------------------------
  775. // CLocalPolRegString::UpdateProfile
  776. //
  777. // This function is called by OnApply after all the data has been retrieved from the dialog.
  778. // Inherited classes can overload this function to update the data as needed.
  779. //
  780. // Arguments: [status] - The status of [m_pData] from OnApply();
  781. //
  782. //----------------------------------------------------------------------------------------------
  783. BOOL CLocalPolRegString::UpdateProfile( )
  784. {
  785. return m_pSnapin->UpdateLocalPolRegValue(m_pData);
  786. }
  787. void CLocalPolRegString::Initialize(CResult * pResult)
  788. {
  789. CConfigRegString::Initialize(pResult);
  790. if (!m_bConfigure)
  791. {
  792. //
  793. // Since we don't have a UI to change configuration
  794. // fake it by "configuring" with an invalid setting
  795. //
  796. m_bConfigure = TRUE;
  797. m_strName = _T("");
  798. }
  799. }
  800. /////////////////////////////////////////////////////////////////////////////
  801. // CConfigRegChoice message handlers
  802. void CConfigRegChoice::Initialize(CResult * pResult)
  803. {
  804. // Class hieirarchy is bad - call CAttribute base method directly
  805. CAttribute::Initialize(pResult);
  806. m_strAttrName = pResult->GetAttrPretty();
  807. m_StartIds=IDS_LM_FULL;
  808. PSCE_REGISTRY_VALUE_INFO prv = (PSCE_REGISTRY_VALUE_INFO)(pResult->GetBase());
  809. if ( prv && prv->Value )
  810. {
  811. m_bConfigure = TRUE;
  812. switch(_wtol(prv->Value))
  813. {
  814. case SCE_RETAIN_ALWAYS:
  815. m_rabRetention = 0;
  816. break;
  817. case SCE_RETAIN_AS_REQUEST:
  818. m_rabRetention = 1;
  819. break;
  820. case SCE_RETAIN_NC:
  821. m_rabRetention = 2;
  822. break;
  823. }
  824. }
  825. else
  826. m_bConfigure = FALSE;
  827. }
  828. BOOL CConfigRegChoice::OnInitDialog()
  829. {
  830. CConfigRet::OnInitDialog();
  831. //
  832. // load static text for the radio buttons
  833. //
  834. CString strText;
  835. strText.LoadString(m_StartIds);
  836. SetDlgItemText( IDC_RETENTION, strText );
  837. strText.LoadString(m_StartIds+1);
  838. SetDlgItemText( IDC_RADIO2, strText );
  839. strText.LoadString(m_StartIds+2);
  840. SetDlgItemText( IDC_RADIO3, strText );
  841. OnConfigure();
  842. return TRUE; // return TRUE unless you set the focus to a control
  843. // EXCEPTION: OCX Property Pages should return FALSE
  844. }
  845. BOOL CConfigRegChoice::OnApply()
  846. {
  847. if ( !m_bReadOnly )
  848. {
  849. DWORD dw = 0;
  850. UpdateData(TRUE);
  851. PSCE_REGISTRY_VALUE_INFO prv = (PSCE_REGISTRY_VALUE_INFO)(m_pData->GetBase());
  852. if ( prv )
  853. {
  854. if (!m_bConfigure)
  855. {
  856. if ( prv->Value )
  857. LocalFree(prv->Value);
  858. prv->Value = NULL;
  859. }
  860. else
  861. {
  862. switch(m_rabRetention)
  863. {
  864. case 0:
  865. dw = SCE_RETAIN_ALWAYS;
  866. break;
  867. case 1:
  868. dw = SCE_RETAIN_AS_REQUEST;
  869. break;
  870. case 2:
  871. dw = SCE_RETAIN_NC;
  872. break;
  873. }
  874. if ( prv->Value == NULL )
  875. {
  876. // allocate buffer
  877. prv->Value = (PWSTR)LocalAlloc(0, 4);
  878. }
  879. if ( prv->Value )
  880. {
  881. prv->Value[0] = (int)dw + L'0';
  882. prv->Value[1] = L'\0';
  883. }
  884. else
  885. {
  886. // can't allocate buffer, error!!
  887. }
  888. }
  889. m_pData->Update(m_pSnapin);
  890. }
  891. }
  892. // Class hieirarchy is bad - call CAttribute base method directly
  893. return CAttribute::OnApply();
  894. }
  895. /////////////////////////////////////////////////////////////////////////////
  896. // CAttrRegChoice message handlers
  897. void CAttrRegChoice::Initialize(CResult * pData)
  898. {
  899. DWORD dw = 0;
  900. // Class hieirarchy is bad - call CAttribute base method directly
  901. CAttribute::Initialize(pData);
  902. // Display the last inspected setting in its static box
  903. pData->GetDisplayName( NULL, m_strLastInspect, 2 );
  904. // Set the template setting radio button appropriately
  905. m_strAttrName = pData->GetAttrPretty();
  906. m_StartIds=IDS_LM_FULL;
  907. PSCE_REGISTRY_VALUE_INFO prv = (PSCE_REGISTRY_VALUE_INFO)(pData->GetBase());
  908. if ( prv && prv->Value )
  909. {
  910. m_bConfigure = TRUE;
  911. switch(_wtol(prv->Value))
  912. {
  913. case SCE_RETAIN_ALWAYS:
  914. m_rabRetention = 0;
  915. break;
  916. case SCE_RETAIN_AS_REQUEST:
  917. m_rabRetention = 1;
  918. break;
  919. case SCE_RETAIN_NC:
  920. m_rabRetention = 2;
  921. break;
  922. }
  923. }
  924. else
  925. {
  926. m_bConfigure = FALSE;
  927. }
  928. }
  929. BOOL CAttrRegChoice::OnInitDialog()
  930. {
  931. CAttrRet::OnInitDialog();
  932. //
  933. // load static text for the radio buttons
  934. //
  935. CString strText;
  936. strText.LoadString(m_StartIds);
  937. SetDlgItemText( IDC_RETENTION, strText );
  938. strText.LoadString(m_StartIds+1);
  939. SetDlgItemText( IDC_RADIO2, strText );
  940. strText.LoadString(m_StartIds+2);
  941. SetDlgItemText( IDC_RADIO3, strText );
  942. CAttrRet::OnInitDialog();
  943. return TRUE; // return TRUE unless you set the focus to a control
  944. // EXCEPTION: OCX Property Pages should return FALSE
  945. }
  946. BOOL CAttrRegChoice::OnApply()
  947. {
  948. if ( !m_bReadOnly )
  949. {
  950. DWORD dw = 0;
  951. int status = 0;
  952. UpdateData(TRUE);
  953. if (!m_bConfigure)
  954. dw = SCE_NO_VALUE;
  955. else
  956. {
  957. switch(m_rabRetention)
  958. {
  959. case 0:
  960. dw = SCE_RETAIN_ALWAYS;
  961. break;
  962. case 1:
  963. dw = SCE_RETAIN_AS_REQUEST;
  964. break;
  965. case 2:
  966. dw = SCE_RETAIN_NC;
  967. break;
  968. }
  969. }
  970. PSCE_REGISTRY_VALUE_INFO prv=(PSCE_REGISTRY_VALUE_INFO)(m_pData->GetBase());
  971. PSCE_REGISTRY_VALUE_INFO prv2=(PSCE_REGISTRY_VALUE_INFO)(m_pData->GetSetting());
  972. //
  973. // this address should never be NULL
  974. //
  975. if ( prv )
  976. {
  977. DWORD dw2=SCE_NO_VALUE;
  978. if ( prv2 )
  979. {
  980. //
  981. // if there is analysis setting (should always have)
  982. //
  983. if (prv2->Value )
  984. dw2 = _wtol(prv2->Value);
  985. else
  986. dw2 = SCE_NO_VALUE;
  987. }
  988. status = CEditTemplate::ComputeStatus (prv, prv2);
  989. if ( dw == SCE_NO_VALUE )
  990. {
  991. if ( prv->Value )
  992. LocalFree(prv->Value);
  993. prv->Value = NULL;
  994. }
  995. else
  996. {
  997. if ( prv->Value == NULL )
  998. {
  999. // allocate buffer
  1000. prv->Value = (PWSTR)LocalAlloc(0, 4);
  1001. }
  1002. if ( prv->Value )
  1003. {
  1004. prv->Value[0] = (int)dw + L'0';
  1005. prv->Value[1] = L'\0';
  1006. }
  1007. else
  1008. {
  1009. // can't allocate buffer, error!!
  1010. }
  1011. }
  1012. UpdateProfile( status );
  1013. }
  1014. }
  1015. // Class hieirarchy is bad - call CAttribute base method directly
  1016. return CAttribute::OnApply();
  1017. }
  1018. void CAttrRegChoice::UpdateProfile( DWORD status )
  1019. {
  1020. if ( m_pData->GetBaseProfile() )
  1021. m_pData->GetBaseProfile()->SetDirty(AREA_SECURITY_POLICY);
  1022. m_pData->SetStatus(status);
  1023. m_pData->Update(m_pSnapin);
  1024. }
  1025. /////////////////////////////////////////////////////////////////////////////
  1026. // CLocalPolRegChoice message handlers
  1027. void CLocalPolRegChoice::UpdateProfile(DWORD status)
  1028. {
  1029. m_pSnapin->UpdateLocalPolRegValue(m_pData);
  1030. }
  1031. void CLocalPolRegChoice::Initialize(CResult * pResult)
  1032. {
  1033. CConfigRegChoice::Initialize(pResult);
  1034. if (!m_bConfigure)
  1035. {
  1036. //
  1037. // Since we don't have a UI to change configuration
  1038. // fake it by "configuring" with an invalid setting
  1039. //
  1040. m_bConfigure = TRUE;
  1041. m_rabRetention = 0;
  1042. }
  1043. }
  1044. BOOL CSnapin::UpdateLocalPolRegValue( CResult *pResult ) {
  1045. if ( !pResult)
  1046. return FALSE;
  1047. PEDITTEMPLATE pLocalDeltaTemplate = GetTemplate(GT_LOCAL_POLICY_DELTA,AREA_SECURITY_POLICY);
  1048. if (!pLocalDeltaTemplate)
  1049. return FALSE;
  1050. PSCE_PROFILE_INFO pLocalDelta = pLocalDeltaTemplate->pTemplate;
  1051. pLocalDelta->RegValueCount = 1;
  1052. pLocalDelta->aRegValues = (PSCE_REGISTRY_VALUE_INFO)pResult->GetBase();
  1053. if( pLocalDeltaTemplate->SetDirty(AREA_SECURITY_POLICY) )
  1054. {
  1055. //
  1056. // Set the status of the item.
  1057. //
  1058. PSCE_REGISTRY_VALUE_INFO pRviEffective = (PSCE_REGISTRY_VALUE_INFO)pResult->GetSetting();
  1059. DWORD status = pResult->GetStatus();
  1060. if(!pRviEffective || !pRviEffective->Value)
  1061. status = SCE_STATUS_NOT_ANALYZED;
  1062. else
  1063. status = CEditTemplate::ComputeStatus( (PSCE_REGISTRY_VALUE_INFO)pResult->GetBase(), pRviEffective );
  1064. pResult->SetStatus(status);
  1065. pResult->Update(this);
  1066. return TRUE;
  1067. }
  1068. return FALSE;
  1069. }