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.

987 lines
27 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: ANumber.cpp
  7. //
  8. // Contents: Implementation of CAttrNumber
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "wsecmgr.h"
  13. #include "snapmgr.h"
  14. #include "util.h"
  15. #include "ANumber.h"
  16. #include "DDWarn.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /*--------------------------------------------------------------------------------------
  23. The constant values below are used to retrieve the string ID of the description for
  24. a range of values.
  25. struct {
  26. int iMin - >= The value must be greater than or equal to this value.
  27. int iMax - <= The value must be less than or equale to this value.
  28. WORD uResource - The resource id of the item.
  29. WORD uMask - Flag that describes which memebers are valid. The Resource
  30. ID must always be valid. If a flag is not set for the
  31. coorisponding item, then the point is not checked against
  32. the value.
  33. RDIF_MIN - The [iMin] member is valid.
  34. RDIF_MAX - [iMax] member is valid.
  35. RDIF_END - This is the end of the array. The last
  36. item in all declarations must set this
  37. flag.
  38. --------------------------------------------------------------------------------------*/
  39. //
  40. // Minimum password description for number attribute.
  41. //
  42. RANGEDESCRIPTION g_rdMinPassword[] =
  43. {
  44. { 0, 0, IDS_CHANGE_IMMEDIATELY, RDIF_MIN | RDIF_MAX },
  45. { 1, 0, IDS_PASSWORD_CHANGE, RDIF_MIN | RDIF_END }
  46. };
  47. //
  48. // Maximum password description for number attribute.
  49. //
  50. RANGEDESCRIPTION g_rdMaxPassword[] =
  51. {
  52. { 1, 999, IDS_PASSWORD_EXPIRE, RDIF_MIN | RDIF_MAX },
  53. { 0, 0, IDS_PASSWORD_FOREVER, RDIF_MIN | RDIF_END},
  54. };
  55. //
  56. // Password len descriptions.
  57. //
  58. RANGEDESCRIPTION g_rdPasswordLen[] =
  59. {
  60. {0, 0, IDS_PERMIT_BLANK, RDIF_MIN | RDIF_MAX },
  61. {1, 0, IDS_PASSWORD_LEN, RDIF_MIN | RDIF_END }
  62. };
  63. //
  64. // Password histroy description.
  65. //
  66. RANGEDESCRIPTION g_rdPasswordHistory[] =
  67. {
  68. {0, 0, IDS_NO_HISTORY, RDIF_MIN | RDIF_MAX },
  69. {1, 0, IDS_PASSWORD_REMEMBER, RDIF_MIN | RDIF_END }
  70. };
  71. //
  72. // Password lockout descriptions
  73. //
  74. RANGEDESCRIPTION g_rdLockoutAccount[] =
  75. {
  76. {0, 0, IDS_NO_LOCKOUT, RDIF_MIN | RDIF_MAX },
  77. {1, 0, IDS_LOCKOUT_AFTER, RDIF_MIN | RDIF_END }
  78. };
  79. //
  80. // Lockout duration description.
  81. //
  82. RANGEDESCRIPTION g_rdLockoutFor[] =
  83. {
  84. {1, 0, IDS_DURATION, RDIF_MIN },
  85. {0, 0, IDS_LOCKOUT_FOREVER, RDIF_MAX | RDIF_END}
  86. };
  87. RANGEDESCRIPTION g_rdAutoDisconnect[] =
  88. {
  89. { 1, 0, IDS_RNH_AUTODISCONNECT_STATIC, RDIF_MIN },
  90. { 0, 0, IDS_RNH_AUTODISCONNECT_SPECIAL, RDIF_MAX | RDIF_END}
  91. };
  92. RANGEDESCRIPTION g_rdPasswordWarnings[] =
  93. {
  94. { 0, 0, IDS_RNH_PASSWORD_WARNINGS_SPECIAL, RDIF_MIN | RDIF_MAX},
  95. { 1, 0, IDS_RNH_PASSWORD_WARNINGS_STATIC, RDIF_MIN | RDIF_END}
  96. };
  97. RANGEDESCRIPTION g_rdCachedLogons[] =
  98. {
  99. { 0, 0, IDS_RNH_CACHED_LOGONS_SPECIAL, RDIF_MIN | RDIF_MAX},
  100. { 1, 0, IDS_RNH_CACHED_LOGONS_STATIC, RDIF_MIN | RDIF_END}
  101. };
  102. /*--------------------------------------------------------------------------------------
  103. Method: GetRangeDescription
  104. Synopsis: This function was specifically created for SCE. Call this function if the
  105. Item ID to, and current range value to retrieve the corrisponding string.
  106. Arguments: [uType] - [in] ID of the point you want the description for.
  107. [i] - [in] The point you want the description for.
  108. [pstrRet] - [out] The return value.
  109. Returns: ERROR_SUCCESS - The operation was successfull.
  110. ERROR_INVALID_DATA - The id may not be supported or [pstrRet] is NULL.
  111. Other Win32 errors if resource loading was not successful.
  112. --------------------------------------------------------------------------------------*/
  113. DWORD
  114. GetRangeDescription(
  115. IN UINT uType,
  116. IN int i,
  117. OUT CString *pstrRet
  118. )
  119. {
  120. switch(uType){
  121. case IDS_LOCK_DURATION:
  122. uType = GetRangeDescription(g_rdLockoutFor, i);
  123. break;
  124. case IDS_MAX_PAS_AGE:
  125. uType = GetRangeDescription(g_rdMaxPassword, i);
  126. break;
  127. case IDS_LOCK_COUNT:
  128. uType = GetRangeDescription(g_rdLockoutAccount, i);
  129. break;
  130. case IDS_MIN_PAS_AGE:
  131. uType = GetRangeDescription(g_rdMinPassword, i);
  132. break;
  133. case IDS_MIN_PAS_LEN:
  134. uType = GetRangeDescription(g_rdPasswordLen, i);
  135. break;
  136. case IDS_PAS_UNIQUENESS:
  137. uType = GetRangeDescription(g_rdPasswordHistory, i);
  138. break;
  139. case IDS_LOCK_RESET_COUNT:
  140. uType = 0;
  141. break;
  142. default:
  143. uType = 0;
  144. }
  145. if(uType && pstrRet){
  146. //
  147. // Try to load the resource string.
  148. //
  149. __try {
  150. if( pstrRet->LoadString(uType) ){
  151. return ERROR_SUCCESS;
  152. }
  153. } __except(EXCEPTION_CONTINUE_EXECUTION) {
  154. return (DWORD)E_POINTER;
  155. }
  156. return GetLastError();
  157. }
  158. return ERROR_INVALID_DATA;
  159. }
  160. /*--------------------------------------------------------------------------------------
  161. Method: GetRangeDescription
  162. Synopsis: This function works directly with the RANGEDESCRIPTION structure. Tests
  163. to see which string resource ID to return. This is determined by testing [i]
  164. with the [iMin] and [iMax] value of a RANGEDESCRIPTION structure. RDIF_MIN
  165. or/and RDIF_MAX must be set in the [uMask] member for this function to
  166. perform any comparisons
  167. Arguments: [pDesc] - [in] An array of RANGEDESCRIPTIONS, the last member of this
  168. array must set RDIF_END flag in the [uMask] member.
  169. [i] - [in] The point to test.
  170. Returns: A String resource ID if successfull. Otherwise 0.
  171. --------------------------------------------------------------------------------------*/
  172. UINT
  173. GetRangeDescription(
  174. RANGEDESCRIPTION *pDesc,
  175. int i
  176. )
  177. {
  178. RANGEDESCRIPTION *pCur = pDesc;
  179. if(!pDesc){
  180. return 0;
  181. }
  182. //
  183. // The uMask member of the description tells us wich members
  184. // of the structure is valid.
  185. //
  186. while( 1 ){
  187. if( (pCur->uMask & RDIF_MIN) ) {
  188. //
  189. // Test the minimum.
  190. //
  191. if(i >= pCur->iMin){
  192. if(pCur->uMask & RDIF_MAX){
  193. //
  194. // Test the maximum.
  195. //
  196. if( i <= pCur->iMax) {
  197. return pCur->uResource;
  198. }
  199. } else {
  200. return pCur->uResource;
  201. }
  202. }
  203. } else if(pCur->uMask & RDIF_MAX) {
  204. //
  205. // Test only the maximum.
  206. //
  207. if(i <= pCur->iMax){
  208. return pCur->uResource;
  209. }
  210. }
  211. if(pCur->uMask & RDIF_END){
  212. //
  213. // This is the last element of the array, so end the loop.
  214. //
  215. break;
  216. }
  217. pCur++;
  218. }
  219. return 0;
  220. }
  221. /////////////////////////////////////////////////////////////////////////////
  222. // CAttrNumber dialog
  223. CAttrNumber::CAttrNumber(UINT nTemplateID)
  224. : CAttribute(nTemplateID ? nTemplateID : IDD),
  225. m_cMinutes(0),
  226. m_nLow(0),
  227. m_nHigh(999),
  228. m_nSave(0),
  229. m_pRDescription(NULL)
  230. {
  231. //{{AFX_DATA_INIT(CAttrNumber)
  232. m_strUnits = _T("");
  233. m_strSetting = _T("");
  234. m_strBase = _T("");
  235. m_strTemplateTitle = _T("");
  236. m_strLastInspectTitle = _T("");
  237. //}}AFX_DATA_INIT
  238. m_pHelpIDs = (DWORD_PTR)a168HelpIDs;
  239. m_uTemplateResID = IDD;
  240. }
  241. void CAttrNumber::DoDataExchange(CDataExchange* pDX)
  242. {
  243. CAttribute::DoDataExchange(pDX);
  244. //{{AFX_DATA_MAP(CAttrNumber)
  245. DDX_Control(pDX, IDC_SPIN, m_SpinValue);
  246. DDX_Text(pDX, IDC_UNITS, m_strUnits);
  247. DDX_Text(pDX, IDC_CURRENT, m_strSetting);
  248. DDX_Text(pDX, IDC_NEW, m_strBase);
  249. DDX_Text(pDX, IDC_TEMPLATE_TITLE, m_strTemplateTitle);
  250. DDX_Text(pDX, IDC_LI_TITLE, m_strLastInspectTitle);
  251. DDX_Text(pDX, IDC_RANGEERROR,m_strError);
  252. //}}AFX_DATA_MAP
  253. }
  254. BEGIN_MESSAGE_MAP(CAttrNumber, CAttribute)
  255. //{{AFX_MSG_MAP(CAttrNumber)
  256. ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN, OnDeltaposSpin)
  257. ON_EN_KILLFOCUS(IDC_NEW, OnKillFocusNew)
  258. ON_BN_CLICKED(IDC_CONFIGURE, OnConfigure)
  259. ON_EN_UPDATE(IDC_NEW, OnUpdateNew)
  260. //}}AFX_MSG_MAP
  261. END_MESSAGE_MAP()
  262. /////////////////////////////////////////////////////////////////////////////
  263. // CAttrNumber message handlers
  264. void CAttrNumber::OnDeltaposSpin( NMHDR* pNMHDR, LRESULT* pResult )
  265. {
  266. NM_UPDOWN FAR *pnmud = (NM_UPDOWN FAR *)pNMHDR;
  267. if ( pnmud ) {
  268. //
  269. // get current value
  270. //
  271. long lVal = CurrentEditValue();
  272. if (SCE_FOREVER_VALUE == lVal) {
  273. if (pnmud->iDelta > 0) {
  274. if (m_cMinutes & DW_VALUE_OFF) {
  275. lVal = SCE_KERBEROS_OFF_VALUE;
  276. } else {
  277. lVal = m_nHigh;
  278. }
  279. } else {
  280. lVal = m_nLow;
  281. }
  282. } else if (SCE_KERBEROS_OFF_VALUE == lVal) {
  283. if (pnmud->iDelta < 0) {
  284. if (m_cMinutes & DW_VALUE_FOREVER) {
  285. lVal = SCE_FOREVER_VALUE;
  286. } else {
  287. lVal = m_nLow;
  288. }
  289. } else {
  290. lVal = m_nHigh;
  291. }
  292. } else {
  293. lVal -= (LONG)(m_iAccRate*pnmud->iDelta);
  294. if ( lVal > m_nHigh ) {
  295. // if it is overflow, go back to low
  296. if ( m_cMinutes & DW_VALUE_OFF ) {
  297. lVal = SCE_KERBEROS_OFF_VALUE;
  298. } else if (m_cMinutes & DW_VALUE_FOREVER) {
  299. lVal = SCE_FOREVER_VALUE;
  300. } else {
  301. lVal = m_nLow;
  302. }
  303. } else if ( (lVal < m_nLow) &&
  304. ((lVal != SCE_KERBEROS_OFF_VALUE) || !(m_cMinutes & DW_VALUE_OFF)) &&
  305. ((lVal != SCE_FOREVER_VALUE) || !(m_cMinutes & DW_VALUE_FOREVER))) {
  306. // if it is underflow, go back to high
  307. if ( (m_cMinutes & DW_VALUE_FOREVER) && (lVal != SCE_FOREVER_VALUE)) {
  308. lVal = SCE_FOREVER_VALUE;
  309. } else if ((m_cMinutes & DW_VALUE_OFF) && (lVal != SCE_KERBEROS_OFF_VALUE)) {
  310. lVal = SCE_KERBEROS_OFF_VALUE;
  311. } else {
  312. lVal = m_nHigh;
  313. }
  314. }
  315. if ( 0 == lVal && (m_cMinutes & DW_VALUE_NOZERO) ) {
  316. // zero is not allowed
  317. if ( m_nLow > 0 ) {
  318. lVal = m_nLow;
  319. } else {
  320. lVal = 1;
  321. }
  322. }
  323. }
  324. SetValueToEdit(lVal);
  325. }
  326. *pResult = 0;
  327. }
  328. void CAttrNumber::OnKillFocusNew()
  329. {
  330. LONG lVal = CurrentEditValue();
  331. SetValueToEdit(lVal);
  332. }
  333. void CAttrNumber::SetValueToEdit(LONG lVal)
  334. {
  335. CString strNew;
  336. if ( m_iStaticId )
  337. m_strTemplateTitle.LoadString(m_iStaticId);
  338. else
  339. m_strTemplateTitle = _T("");
  340. if ( 0 == lVal ) {
  341. strNew.Format(TEXT("%d"),lVal);
  342. if ( m_cMinutes & DW_VALUE_NEVER &&
  343. m_iNeverId > 0 ) {
  344. // change to never
  345. m_strTemplateTitle.LoadString(m_iNeverId);
  346. }
  347. } else if ( SCE_FOREVER_VALUE == lVal ) {
  348. strNew.LoadString(IDS_FOREVER);
  349. if ( m_iNeverId )
  350. m_strTemplateTitle.LoadString(m_iNeverId);
  351. } else if (SCE_KERBEROS_OFF_VALUE == lVal) {
  352. strNew.LoadString(IDS_OFF);
  353. if ( m_iNeverId ) {
  354. m_strTemplateTitle.LoadString(m_iNeverId);
  355. }
  356. } else {
  357. strNew.Format(TEXT("%d"),lVal);
  358. }
  359. m_nSave = lVal;
  360. SetDlgItemText(IDC_NEW,strNew);
  361. SetDlgItemText(IDC_TEMPLATE_TITLE,m_strTemplateTitle);
  362. SetModified(TRUE);
  363. }
  364. LONG CAttrNumber::CurrentEditValue()
  365. {
  366. UINT uiVal = 0;
  367. LONG lVal = 0;
  368. BOOL bTrans = FALSE;
  369. int length = m_strBase.GetLength(); //Raid 471645, Yang Gao
  370. while( lVal < length && m_strBase.GetAt(lVal) == L'0' )
  371. {
  372. lVal++;
  373. }
  374. if( lVal > 0 && lVal < length )
  375. {
  376. m_strBase.Delete(0, lVal);
  377. SetDlgItemText(IDC_NEW, m_strBase);
  378. }
  379. uiVal = GetDlgItemInt(IDC_NEW,&bTrans,FALSE);
  380. lVal = uiVal;
  381. if (!bTrans ) {
  382. // if ( 0 == lVal && !bTrans ) {
  383. // errored, overflow, or nonnumeric
  384. CString str;
  385. if(m_cMinutes & DW_VALUE_FOREVER){
  386. str.LoadString(IDS_FOREVER);
  387. if(str == m_strBase){
  388. return SCE_FOREVER_VALUE;
  389. }
  390. }
  391. lVal = _ttol((LPCTSTR)m_strBase);
  392. if ( lVal == 0 ) {
  393. //
  394. // nonnumeric
  395. //
  396. lVal = (LONG) m_nSave;
  397. return lVal;
  398. }
  399. }
  400. if ( m_iAccRate > 1 && lVal > 0 ) {
  401. //
  402. // for log max size, make it multiples of m_iAccRate
  403. //
  404. int nCount = lVal % m_iAccRate;
  405. if ( nCount > 0 ) {
  406. lVal = ((LONG)(lVal/m_iAccRate))*m_iAccRate;
  407. }
  408. }
  409. if ( lVal > m_nHigh ) {
  410. // if it is overflow, go back to low
  411. if ( m_cMinutes & DW_VALUE_FOREVER ) {
  412. lVal = SCE_FOREVER_VALUE;
  413. } else if (m_cMinutes & DW_VALUE_OFF) {
  414. lVal = SCE_KERBEROS_OFF_VALUE;
  415. } else {
  416. // Leave alone and let the OnKillActive catch it
  417. }
  418. }
  419. if ( (lVal < m_nLow) &&
  420. (lVal != SCE_KERBEROS_OFF_VALUE) &&
  421. (lVal != SCE_FOREVER_VALUE) ) {
  422. // if it is underflow, go back to high
  423. if (m_cMinutes & DW_VALUE_OFF) {
  424. lVal = SCE_KERBEROS_OFF_VALUE;
  425. } else if ( m_cMinutes & DW_VALUE_FOREVER) {
  426. lVal = SCE_FOREVER_VALUE;
  427. } else {
  428. // Leave alone and let the OnKillActive catch it
  429. }
  430. }
  431. if ( 0 == lVal && (m_cMinutes & DW_VALUE_NOZERO) ) {
  432. // zero is not allowed
  433. if ( m_nLow > 0 ) {
  434. lVal = m_nLow;
  435. } else {
  436. lVal = 1;
  437. }
  438. }
  439. return lVal;
  440. }
  441. void CAttrNumber::OnConfigure()
  442. {
  443. CWnd *cwnd;
  444. CAttribute::OnConfigure();
  445. //
  446. // Enable disable OK button depending on the state of the other controls.
  447. //
  448. cwnd = GetDlgItem(IDOK);
  449. if(cwnd){
  450. if(!m_bConfigure){
  451. cwnd->EnableWindow(TRUE);
  452. } else {
  453. OnUpdateNew();
  454. }
  455. }
  456. }
  457. BOOL CAttrNumber::OnInitDialog()
  458. {
  459. CAttribute::OnInitDialog();
  460. UpdateData(TRUE);
  461. /*
  462. if (m_bMinutes) {
  463. m_SpinValue.SetRange(-1,UD_MAXVAL-1);
  464. } else {
  465. m_SpinValue.SetRange(0,UD_MAXVAL);
  466. }
  467. */
  468. AddUserControl(IDC_NEW);
  469. AddUserControl(IDC_SPIN);
  470. OnConfigure();
  471. return TRUE; // return TRUE unless you set the focus to a control
  472. // EXCEPTION: OCX Property Pages should return FALSE
  473. }
  474. BOOL CAttrNumber::OnApply()
  475. {
  476. if ( !m_bReadOnly )
  477. {
  478. BOOL bUpdateAll = FALSE;
  479. DWORD dw = 0;
  480. CString strForever,strOff;
  481. int status = 0;
  482. UpdateData(TRUE);
  483. if (!m_bConfigure)
  484. dw = SCE_NO_VALUE;
  485. else
  486. dw = CurrentEditValue();
  487. bUpdateAll = FALSE;
  488. CEditTemplate *pet = m_pSnapin->GetTemplate(GT_COMPUTER_TEMPLATE,AREA_SECURITY_POLICY);
  489. //
  490. // Check the numbers dependencies if a dependency fails then the dialog
  491. // will return ERROR_MORE_DATA and we can display more information for the user
  492. // to see.
  493. //
  494. if(DDWarn.CheckDependencies( dw ) == ERROR_MORE_DATA )
  495. {
  496. //
  497. // If the user presses cancel then we won't let them set this item's information
  498. // until they have set the configurion for the other items.
  499. //
  500. CThemeContextActivator activator;
  501. if( DDWarn.DoModal() != IDOK)
  502. return FALSE;
  503. //
  504. // The user pressed Auto set so we can set the other items. They are automatically set
  505. // to the correct values.
  506. //
  507. for(int i = 0; i < DDWarn.GetFailedCount(); i++)
  508. {
  509. PDEPENDENCYFAILED pItem = DDWarn.GetFailedInfo(i);
  510. if(pItem && pItem->pResult )
  511. {
  512. pItem->pResult->SetBase( pItem->dwSuggested );
  513. status = m_pSnapin->SetAnalysisInfo(
  514. pItem->pResult->GetID(),
  515. pItem->dwSuggested,
  516. pItem->pResult);
  517. pItem->pResult->SetStatus( status );
  518. pItem->pResult->Update(m_pSnapin, FALSE);
  519. }
  520. }
  521. }
  522. //
  523. // Update the items security profile.
  524. // and redraw.
  525. //
  526. m_pData->SetBase((LONG_PTR)ULongToPtr(dw));
  527. status = m_pSnapin->SetAnalysisInfo(m_pData->GetID(),(LONG_PTR)ULongToPtr(dw), m_pData);
  528. m_pData->SetStatus(status);
  529. m_pData->Update(m_pSnapin, FALSE);
  530. }
  531. return CAttribute::OnApply();
  532. }
  533. void CAttrNumber::Initialize(CResult * pResult)
  534. {
  535. LONG_PTR dw=0;
  536. CAttribute::Initialize(pResult);
  537. DDWarn.InitializeDependencies(m_pSnapin,pResult);
  538. m_strUnits = pResult->GetUnits();
  539. m_cMinutes = DW_VALUE_NOZERO;
  540. m_nLow = 0;
  541. m_nHigh = 999;
  542. m_nSave = 0;
  543. m_iNeverId = 0;
  544. m_iAccRate = 1;
  545. m_iStaticId = 0;
  546. CEditTemplate *pTemplate = pResult->GetBaseProfile();
  547. switch (pResult->GetID()) {
  548. // below no zero value
  549. case IDS_LOCK_DURATION:
  550. m_cMinutes = DW_VALUE_FOREVER | DW_VALUE_NOZERO;
  551. m_nHigh = 99999;
  552. m_iStaticId = IDS_DURATION;
  553. m_iNeverId = IDS_LOCKOUT_FOREVER;
  554. m_pRDescription = g_rdLockoutAccount;
  555. break;
  556. case IDS_MAX_PAS_AGE:
  557. m_cMinutes = DW_VALUE_FOREVER | DW_VALUE_NOZERO;
  558. m_iStaticId = IDS_PASSWORD_EXPIRE;
  559. m_iNeverId = IDS_PASSWORD_FOREVER;
  560. break;
  561. // below zero value means differently
  562. case IDS_LOCK_COUNT:
  563. m_cMinutes = DW_VALUE_NEVER;
  564. m_iNeverId = IDS_NO_LOCKOUT;
  565. m_iStaticId = IDS_LOCKOUT_AFTER;
  566. break;
  567. case IDS_MIN_PAS_AGE:
  568. m_cMinutes = DW_VALUE_NEVER;
  569. m_iNeverId = IDS_CHANGE_IMMEDIATELY;
  570. m_iStaticId = IDS_PASSWORD_CHANGE;
  571. m_nHigh = 998;
  572. m_pRDescription = g_rdMinPassword;
  573. break;
  574. case IDS_MIN_PAS_LEN:
  575. m_cMinutes = DW_VALUE_NEVER;
  576. m_nHigh = 14;
  577. m_iNeverId = IDS_PERMIT_BLANK;
  578. m_iStaticId = IDS_PASSWORD_LEN;
  579. m_pRDescription = g_rdPasswordLen;
  580. break;
  581. case IDS_PAS_UNIQUENESS:
  582. m_cMinutes = DW_VALUE_NEVER;
  583. m_nHigh = 24;
  584. m_iNeverId = IDS_NO_HISTORY;
  585. m_iStaticId = IDS_PASSWORD_REMEMBER;
  586. break;
  587. // below there is no zero values
  588. case IDS_LOCK_RESET_COUNT:
  589. m_nLow = 1;
  590. m_nHigh = 99999;
  591. m_iStaticId = IDS_LOCK_RESET_COUNT;
  592. break;
  593. case IDS_SYS_LOG_MAX:
  594. case IDS_SEC_LOG_MAX:
  595. case IDS_APP_LOG_MAX:
  596. m_nLow = 64;
  597. m_nHigh = 4194240;
  598. m_iAccRate = 64;
  599. // no static text
  600. break;
  601. case IDS_SYS_LOG_DAYS:
  602. case IDS_SEC_LOG_DAYS:
  603. case IDS_APP_LOG_DAYS:
  604. m_nHigh = 365;
  605. m_nLow = 1;
  606. m_iStaticId = IDS_OVERWRITE_EVENT;
  607. break;
  608. case IDS_KERBEROS_MAX_AGE:
  609. m_cMinutes = DW_VALUE_FOREVER | DW_VALUE_NOZERO;
  610. m_nHigh = 99999;
  611. m_iStaticId = IDS_TICKET_EXPIRE;
  612. m_iNeverId = IDS_TICKET_FOREVER;
  613. break;
  614. case IDS_KERBEROS_RENEWAL:
  615. m_cMinutes = DW_VALUE_FOREVER | DW_VALUE_NOZERO; // | DW_VALUE_OFF;
  616. m_nHigh = 99999;
  617. m_iStaticId = IDS_TICKET_RENEWAL_EXPIRE;
  618. m_iNeverId = IDS_TICKET_RENEWAL_FOREVER;
  619. break;
  620. case IDS_KERBEROS_MAX_SERVICE:
  621. m_nLow = 10;
  622. m_cMinutes = DW_VALUE_FOREVER | DW_VALUE_NOZERO;
  623. m_iStaticId = IDS_TICKET_EXPIRE;
  624. m_iNeverId = IDS_TICKET_FOREVER;
  625. m_nHigh = 99999;
  626. break;
  627. case IDS_KERBEROS_MAX_CLOCK:
  628. m_cMinutes = DW_VALUE_FOREVER;
  629. m_nHigh = 99999;
  630. m_iStaticId = IDS_MAX_TOLERANCE;
  631. m_iNeverId = IDS_NO_MAX_TOLERANCE;
  632. break;
  633. }
  634. if ((m_cMinutes & DW_VALUE_NOZERO) && (0 == m_nLow)) {
  635. m_nLow = 1;
  636. }
  637. m_strTemplateTitle = _T("");
  638. m_strLastInspectTitle = _T("");
  639. m_strBase.Empty();
  640. m_strSetting.Empty();
  641. dw = pResult->GetBase();
  642. if ((LONG_PTR)ULongToPtr(SCE_NO_VALUE) == dw)
  643. {
  644. m_bConfigure = FALSE;
  645. }
  646. else
  647. {
  648. m_bConfigure = TRUE;
  649. SetInitialValue(PtrToUlong((PVOID)dw));
  650. }
  651. pResult->GetDisplayName( NULL, m_strSetting, 2 );
  652. dw = pResult->GetSetting();
  653. if ((LONG_PTR)ULongToPtr(SCE_NO_VALUE) != dw) {
  654. if ((LONG_PTR)ULongToPtr(SCE_FOREVER_VALUE) == dw) {
  655. if ( (m_cMinutes & DW_VALUE_FOREVER) &&
  656. m_iNeverId > 0 ) {
  657. m_strLastInspectTitle.LoadString(m_iNeverId);
  658. }
  659. } else {
  660. if ( 0 == dw && (m_cMinutes & DW_VALUE_NEVER) &&
  661. m_iNeverId > 0 ) {
  662. // zero means different values
  663. m_strLastInspectTitle.LoadString(m_iNeverId);
  664. } else if ( m_iStaticId > 0 ) {
  665. m_strLastInspectTitle.LoadString(m_iStaticId);
  666. }
  667. }
  668. }
  669. }
  670. void CAttrNumber::SetInitialValue(DWORD_PTR dw)
  671. {
  672. //
  673. // Don't overwrite an already set value.
  674. //
  675. if (!m_strBase.IsEmpty())
  676. {
  677. return;
  678. }
  679. if (SCE_FOREVER_VALUE == dw) {
  680. m_strBase.LoadString(IDS_FOREVER);
  681. if ( (m_cMinutes & DW_VALUE_FOREVER) &&
  682. m_iNeverId > 0 ) {
  683. m_strTemplateTitle.LoadString(m_iNeverId);
  684. }
  685. m_nSave = SCE_FOREVER_VALUE;
  686. } else if (SCE_KERBEROS_OFF_VALUE == dw) {
  687. m_strBase.LoadString(IDS_OFF);
  688. if ( (m_cMinutes & DW_VALUE_OFF) &&
  689. m_iNeverId > 0 ) {
  690. m_strTemplateTitle.LoadString(m_iNeverId);
  691. }
  692. m_nSave = SCE_KERBEROS_OFF_VALUE;
  693. }
  694. else
  695. {
  696. m_nSave = dw;
  697. if ( 0 == dw && (m_cMinutes & DW_VALUE_NEVER) &&
  698. m_iNeverId > 0 ) {
  699. // zero means different values
  700. m_strTemplateTitle.LoadString(m_iNeverId);
  701. } else if ( m_iStaticId > 0 ) {
  702. m_strTemplateTitle.LoadString(m_iStaticId);
  703. }
  704. m_strBase.Format(TEXT("%d"),dw);
  705. }
  706. }
  707. void CAttrNumber::OnUpdateNew()
  708. {
  709. DWORD dwRes = 0;
  710. UpdateData(TRUE);
  711. CString sNum;
  712. CEdit *pEdit = (CEdit *)GetDlgItem(IDC_NEW);
  713. CWnd *pOK = GetDlgItem(IDOK);
  714. DWORD dwValue = _ttoi(m_strBase);
  715. //
  716. // Don't do anything if the string is equal to predefined strings.
  717. //
  718. sNum.LoadString(IDS_FOREVER);
  719. if (m_strBase.IsEmpty()) {
  720. if (pOK) {
  721. pOK->EnableWindow(FALSE);
  722. }
  723. } else if (m_strBase == sNum) {
  724. if (pOK) {
  725. pOK->EnableWindow(TRUE);
  726. }
  727. } else {
  728. if ((long)dwValue < m_nLow) {
  729. //
  730. // Disable the OK button.
  731. //
  732. if ( pOK ) {
  733. pOK->EnableWindow(FALSE);
  734. }
  735. if (pEdit) {
  736. //
  737. // We will only force a select if edit text length >=
  738. // minimum text length
  739. //
  740. sNum.Format(TEXT("%d"), m_nLow);
  741. dwValue = m_nLow;
  742. if (sNum.GetLength() < m_strBase.GetLength()) {
  743. pEdit->SetSel(0, -1);
  744. }
  745. }
  746. } else if ( (long)dwValue > m_nHigh ) {
  747. if (pOK) {
  748. pOK->EnableWindow(TRUE);
  749. }
  750. if (pEdit) {
  751. if (m_cMinutes & DW_VALUE_FOREVER) {
  752. sNum.LoadString(IDS_FOREVER);
  753. dwValue = 0;
  754. } else {
  755. sNum.Format(TEXT("%d"), m_nHigh);
  756. dwValue = m_nHigh;
  757. }
  758. m_strBase = sNum;
  759. UpdateData(FALSE);
  760. pEdit->SetSel(0, -1);
  761. }
  762. } else {
  763. //
  764. // Enable the OK button.
  765. //
  766. if (pOK) {
  767. pOK->EnableWindow(TRUE);
  768. }
  769. }
  770. }
  771. //
  772. // Load the description for this string.
  773. //
  774. if ((dwValue <= 0) && (m_iNeverId != 0)) {
  775. m_strTemplateTitle.LoadString(m_iNeverId);
  776. } else {
  777. m_strTemplateTitle.LoadString(m_iStaticId);
  778. }
  779. GetDlgItem(IDC_TEMPLATE_TITLE)->SetWindowText(m_strTemplateTitle);
  780. SetModified(TRUE); //Raid #404145
  781. }
  782. BOOL CAttrNumber::OnKillActive()
  783. {
  784. UINT uiVal = 0;
  785. LONG lVal = 0;
  786. BOOL bTrans = FALSE;
  787. CString strRange;
  788. int lMin = m_nLow;
  789. UpdateData(TRUE);
  790. if (!m_bConfigure) //Raid 472956, Yang Gao
  791. {
  792. return TRUE;
  793. }
  794. if (m_cMinutes & DW_VALUE_NOZERO &&
  795. !(m_cMinutes & DW_VALUE_FOREVER) &&
  796. lMin == 0) {
  797. lMin = 1;
  798. }
  799. CString strFormat;
  800. strFormat.LoadString(IDS_RANGE);
  801. strRange.Format(strFormat,lMin,m_nHigh);
  802. uiVal = GetDlgItemInt(IDC_NEW,&bTrans,TRUE);
  803. lVal = uiVal;
  804. if ( !bTrans ) {
  805. CString str;
  806. if (m_cMinutes & DW_VALUE_FOREVER) {
  807. str.LoadString(IDS_FOREVER);
  808. if (str == m_strBase) {
  809. return TRUE;;
  810. }
  811. }
  812. lVal = _ttol((LPCTSTR)m_strBase);
  813. if ( lVal == 0 )
  814. {
  815. // nonnumeric
  816. lVal = (LONG) m_nSave;
  817. m_strError = strRange;
  818. UpdateData(FALSE);
  819. return FALSE;
  820. }
  821. }
  822. if ( m_iAccRate > 1 && lVal > 0 ) {
  823. // for log max size, make it multiples of m_iAccRate
  824. int nCount = lVal % m_iAccRate;
  825. if ( nCount > 0 ) {
  826. lVal = ((LONG)(lVal/m_iAccRate))*m_iAccRate;
  827. }
  828. }
  829. if ( lVal > m_nHigh ) {
  830. m_strError = strRange;
  831. UpdateData(FALSE);
  832. return FALSE;
  833. }
  834. if ( (lVal < m_nLow) &&
  835. (lVal != SCE_KERBEROS_OFF_VALUE) &&
  836. (lVal != SCE_FOREVER_VALUE) ) {
  837. // if it is underflow, go back to high
  838. if (m_cMinutes & DW_VALUE_OFF) {
  839. lVal = SCE_KERBEROS_OFF_VALUE;
  840. } else if ( m_cMinutes & DW_VALUE_FOREVER) {
  841. lVal = SCE_FOREVER_VALUE;
  842. } else {
  843. // Leave alone and let the OnKillActive catch it
  844. }
  845. }
  846. if ( (lVal < m_nLow) &&
  847. (lVal != SCE_KERBEROS_OFF_VALUE) &&
  848. (lVal != SCE_FOREVER_VALUE) ) {
  849. // if it is underflow, go back to high
  850. m_strError = strRange;
  851. UpdateData(FALSE);
  852. return FALSE;
  853. }
  854. if ( 0 == lVal && (m_cMinutes & DW_VALUE_NOZERO) ) {
  855. // zero is not allowed
  856. m_strError = strRange;
  857. UpdateData(FALSE);
  858. return FALSE;
  859. }
  860. return CAttribute::OnKillActive();
  861. }