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.

213 lines
5.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: attrstring.cpp
  7. //
  8. // Contents: implementation of CAttrString
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "wsecmgr.h"
  13. #include "AString.h"
  14. #include "util.h"
  15. #include "CName.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CAttrString dialog
  23. CAttrString::CAttrString(UINT nTemplateID)
  24. : CAttribute(nTemplateID ? nTemplateID : IDD),
  25. m_bNoBlanks(FALSE)
  26. {
  27. //{{AFX_DATA_INIT(CAttrString)
  28. m_strSetting = _T("");
  29. m_strBase = _T("");
  30. //}}AFX_DATA_INIT
  31. m_pHelpIDs = (DWORD_PTR)a167HelpIDs;
  32. m_uTemplateResID = IDD;
  33. }
  34. void CAttrString::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CAttribute::DoDataExchange(pDX);
  37. //{{AFX_DATA_MAP(CAttrString)
  38. DDX_Text(pDX, IDC_CURRENT, m_strSetting);
  39. DDX_Text(pDX, IDC_NEW, m_strBase);
  40. //}}AFX_DATA_MAP
  41. }
  42. BEGIN_MESSAGE_MAP(CAttrString, CAttribute)
  43. //{{AFX_MSG_MAP(CAttrString)
  44. ON_BN_CLICKED(IDC_CONFIGURE, OnConfigure)
  45. ON_EN_CHANGE(IDC_NEW, OnChangeNew)
  46. //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CAttrString message handlers
  50. BOOL CAttrString::OnInitDialog()
  51. {
  52. CAttribute::OnInitDialog();
  53. AddUserControl(IDC_NEW);
  54. OnConfigure();
  55. if(m_pData && (m_pData->GetID() == IDS_NEW_ADMIN || m_pData->GetID() == IDS_NEW_GUEST)) //Raid #502069, yanggao
  56. {
  57. GetDlgItem(IDC_NEW)->SendMessage(EM_LIMITTEXT, MAX_USERNAME, 0);
  58. }
  59. return TRUE; // return TRUE unless you set the focus to a control
  60. // EXCEPTION: OCX Property Pages should return FALSE
  61. }
  62. void CAttrString::OnConfigure()
  63. {
  64. CAttribute::OnConfigure();
  65. CWnd *item = 0;
  66. if (m_bNoBlanks) {
  67. item = GetDlgItem(IDOK);
  68. if (item) {
  69. if (m_bConfigure) {
  70. item->EnableWindow(!m_strBase.IsEmpty());
  71. } else {
  72. item->EnableWindow(TRUE);
  73. }
  74. }
  75. }
  76. }
  77. void CAttrString::Initialize(CResult * pResult)
  78. {
  79. CAttribute::Initialize(pResult);
  80. pResult->GetDisplayName( NULL, m_strSetting, 2 );
  81. if ((LONG_PTR)ULongToPtr(SCE_NO_VALUE) == pResult->GetBase() ||
  82. NULL == pResult->GetBase() ){
  83. m_bConfigure = FALSE;
  84. } else {
  85. m_bConfigure = TRUE;
  86. pResult->GetDisplayName( NULL, m_strBase, 1 );
  87. }
  88. if (m_pData->GetID() == IDS_NEW_ADMIN ||
  89. m_pData->GetID() == IDS_NEW_GUEST) {
  90. m_bNoBlanks = TRUE;
  91. } else {
  92. m_bNoBlanks = FALSE;
  93. }
  94. }
  95. BOOL CAttrString::OnApply()
  96. {
  97. if ( !m_bReadOnly )
  98. {
  99. LONG_PTR dw = 0;
  100. UpdateData(TRUE);
  101. BOOL bChanged=TRUE;
  102. m_strBase.TrimLeft();
  103. m_strBase.TrimRight();
  104. if (!m_bConfigure)
  105. {
  106. dw = 0;
  107. if ( (LONG_PTR)ULongToPtr(SCE_NO_VALUE) == m_pData->GetBase() ||
  108. 0 == m_pData->GetBase() )
  109. {
  110. bChanged = FALSE;
  111. }
  112. }
  113. else
  114. {
  115. dw = (LONG_PTR)(LPCTSTR)m_strBase;
  116. if ( m_pData->GetBase() && dw &&
  117. (LONG_PTR)ULongToPtr(SCE_NO_VALUE) != m_pData->GetBase() &&
  118. _wcsicmp((LPTSTR)(m_pData->GetBase()), (LPTSTR)dw) == 0 )
  119. {
  120. bChanged = FALSE;
  121. }
  122. }
  123. if ( bChanged )
  124. {
  125. if ( m_pData->GetSetting() == m_pData->GetBase() &&
  126. m_pData->GetSetting() )
  127. {
  128. // a good item, need take the base into setting
  129. m_pSnapin->TransferAnalysisName(m_pData->GetID());
  130. }
  131. m_pData->SetBase(dw);
  132. DWORD dwStatus = m_pSnapin->SetAnalysisInfo(m_pData->GetID(),dw, m_pData);
  133. m_pData->SetStatus(dwStatus);
  134. m_pData->Update(m_pSnapin);
  135. }
  136. }
  137. return CAttribute::OnApply();
  138. }
  139. void CAttrString::OnChangeNew()
  140. {
  141. CWnd *cwnd = 0;
  142. if (m_bNoBlanks) {
  143. UpdateData(TRUE);
  144. cwnd = GetDlgItem(IDOK);
  145. if (cwnd) {
  146. cwnd->EnableWindow(!m_strBase.IsEmpty());
  147. }
  148. }
  149. SetModified(TRUE);
  150. }
  151. BOOL CAttrString::OnKillActive() {
  152. if ( m_bNoBlanks && m_bConfigure ) //Raid #407190
  153. {
  154. UpdateData(TRUE);
  155. m_strBase.TrimLeft();
  156. m_strBase.TrimRight();
  157. UpdateData(FALSE);
  158. PCWSTR szInvalidCharSet = INVALID_ACCOUNT_NAME_CHARS;
  159. if (m_strBase.IsEmpty() || -1 != m_strBase.FindOneOf(szInvalidCharSet) )
  160. {
  161. CString str;
  162. CString charsWithSpaces;
  163. int nIndex = 0;
  164. while (szInvalidCharSet[nIndex])
  165. {
  166. charsWithSpaces += szInvalidCharSet[nIndex];
  167. charsWithSpaces += L" ";
  168. nIndex++;
  169. }
  170. str.FormatMessage (IDS_EMPTY_NAME_STRING, charsWithSpaces);
  171. AfxMessageBox(str);
  172. GetDlgItem(IDC_NEW)->SetFocus();
  173. return FALSE;
  174. }
  175. }
  176. return TRUE;
  177. }