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.

250 lines
6.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: cname.cpp
  7. //
  8. // Contents: implementation of CConfigName
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "wsecmgr.h"
  13. #include "CName.h"
  14. #include "util.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. PCWSTR g_pcszNEWLINE = L"\x00d\x00a";
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CConfigName dialog
  23. CConfigName::CConfigName(UINT nTemplateID)
  24. : CAttribute(nTemplateID ? nTemplateID : IDD),
  25. m_bNoBlanks(FALSE)
  26. {
  27. //{{AFX_DATA_INIT(CConfigName)
  28. m_strName = _T("");
  29. m_bConfigure = TRUE;
  30. //}}AFX_DATA_INIT
  31. m_pHelpIDs = (DWORD_PTR)a183HelpIDs;
  32. m_uTemplateResID = IDD;
  33. }
  34. CConfigName::~CConfigName ()
  35. {
  36. }
  37. void CConfigName::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CAttribute::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CConfigName)
  41. // DDX_Radio(pDX, IDC_ACCEPT, m_nAcceptCurrentRadio);
  42. DDX_Text(pDX, IDC_NAME, m_strName);
  43. //}}AFX_DATA_MAP
  44. }
  45. BEGIN_MESSAGE_MAP(CConfigName, CAttribute)
  46. //{{AFX_MSG_MAP(CConfigName)
  47. ON_BN_CLICKED(IDC_CONFIGURE, OnConfigure)
  48. ON_EN_CHANGE(IDC_NAME, OnChangeName)
  49. ON_MESSAGE(WM_CLOSE, OnClose)
  50. //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CConfigName message handlers
  54. void CConfigName::OnClose() //Raid #487527, Yanggao. Add handler for WM_CLOSE.
  55. {
  56. GetParent()->PostMessage(WM_CLOSE);
  57. CPropertyPage::OnClose();
  58. }
  59. void CConfigName::Initialize(CResult * pResult)
  60. {
  61. CAttribute::Initialize(pResult);
  62. if ((LONG_PTR)ULongToPtr(SCE_NO_VALUE) == pResult->GetBase() ||
  63. 0 == pResult->GetBase() )
  64. {
  65. m_strName = _T("");
  66. m_bConfigure = FALSE;
  67. }
  68. else
  69. {
  70. m_bConfigure = TRUE;
  71. m_strName = (LPTSTR) pResult->GetBase();
  72. }
  73. if (m_pData->GetID() == IDS_NEW_ADMIN ||
  74. m_pData->GetID() == IDS_NEW_GUEST)
  75. {
  76. m_bNoBlanks = TRUE;
  77. }
  78. else
  79. m_bNoBlanks = FALSE;
  80. }
  81. BOOL CConfigName::OnApply()
  82. {
  83. if ( !m_bReadOnly )
  84. {
  85. LONG_PTR dw = 0;
  86. CString szDoubleNewLine (g_pcszNEWLINE);
  87. szDoubleNewLine += g_pcszNEWLINE;
  88. UpdateData(TRUE);
  89. m_strName.TrimLeft();
  90. m_strName.TrimRight();
  91. // 249188 SCE UI: allows adding empty lines to REG_MULTI_SZ fields
  92. // Replace all double newlines with single newlines. This has the effect
  93. // of deleting empty lines.
  94. while (m_strName.Replace (szDoubleNewLine, g_pcszNEWLINE) != 0);
  95. UpdateData (FALSE);
  96. if (!m_bConfigure)
  97. dw = (LONG_PTR)ULongToPtr(SCE_NO_VALUE);
  98. else
  99. dw = (LONG_PTR)(LPCTSTR)m_strName;
  100. if ( SetProfileInfo(m_pData->GetID(),dw,m_pData->GetBaseProfile()) )
  101. {
  102. switch ( m_pData->GetID() )
  103. {
  104. case IDS_NEW_ADMIN:
  105. dw = (LONG_PTR)(m_pData->GetBaseProfile()->pTemplate->NewAdministratorName);
  106. break;
  107. case IDS_NEW_GUEST:
  108. dw = (LONG_PTR)(m_pData->GetBaseProfile()->pTemplate->NewGuestName);
  109. break;
  110. default:
  111. dw = 0;
  112. break;
  113. }
  114. m_pData->SetBase(dw);
  115. m_pData->Update(m_pSnapin);
  116. }
  117. }
  118. return CAttribute::OnApply();
  119. }
  120. void CConfigName::OnConfigure()
  121. {
  122. CAttribute::OnConfigure();
  123. if(m_bConfigure && m_pData) //Raid #367756, 4/13/2001
  124. {
  125. UpdateData(TRUE);
  126. if( m_strName.IsEmpty() )
  127. {
  128. switch(m_pData->GetType())
  129. {
  130. case ITEM_PROF_REGVALUE:
  131. {
  132. DWORD_PTR dw = (DWORD_PTR)m_pData->GetRegDefault();
  133. LPTSTR sz = SZToMultiSZ((PCWSTR)dw);
  134. m_strName = sz;
  135. if(sz)
  136. {
  137. LocalFree(sz);
  138. }
  139. ((CWnd*)(GetDlgItem(IDC_NAME)))->SetWindowText(m_strName);
  140. break;
  141. }
  142. default:
  143. break;
  144. }
  145. }
  146. }
  147. CWnd *cwnd = 0;
  148. if (m_bNoBlanks)
  149. {
  150. cwnd = GetDlgItem(IDOK);
  151. if (cwnd)
  152. {
  153. if (m_bConfigure)
  154. cwnd->EnableWindow(!m_strName.IsEmpty());
  155. else
  156. cwnd->EnableWindow(TRUE);
  157. }
  158. }
  159. }
  160. BOOL CConfigName::OnInitDialog()
  161. {
  162. CAttribute::OnInitDialog();
  163. AddUserControl(IDC_NAME);
  164. OnConfigure();
  165. if(m_pData->GetID() == IDS_NEW_ADMIN || m_pData->GetID() == IDS_NEW_GUEST) //Raid #490548, yanggao
  166. {
  167. GetDlgItem(IDC_NAME)->SendMessage(EM_LIMITTEXT, MAX_USERNAME, 0);
  168. }
  169. return TRUE; // return TRUE unless you set the focus to a control
  170. // EXCEPTION: OCX Property Pages should return FALSE
  171. }
  172. void CConfigName::OnChangeName()
  173. {
  174. CWnd *cwnd = 0;
  175. SetModified(TRUE);
  176. if (m_bNoBlanks)
  177. {
  178. UpdateData(TRUE);
  179. cwnd = GetDlgItem(IDOK);
  180. if (cwnd)
  181. cwnd->EnableWindow(!m_strName.IsEmpty());
  182. }
  183. }
  184. BOOL CConfigName::OnKillActive()
  185. {
  186. if (m_bNoBlanks && !m_bReadOnly && m_bConfigure ) //Raid #406748
  187. {
  188. UpdateData(TRUE);
  189. m_strName.TrimLeft(); //Raid #406738
  190. m_strName.TrimRight();
  191. UpdateData(FALSE);
  192. PCWSTR szInvalidCharSet = INVALID_ACCOUNT_NAME_CHARS; //Raid #498448, yanggao, 11/21/2001
  193. if (m_strName.IsEmpty() || -1 != m_strName.FindOneOf(szInvalidCharSet) )
  194. {
  195. //Raid #313721, Yang Gao, 3/29/2001
  196. CString str;
  197. CString charsWithSpaces;
  198. int nIndex = 0;
  199. while (szInvalidCharSet[nIndex])
  200. {
  201. charsWithSpaces += szInvalidCharSet[nIndex];
  202. charsWithSpaces += L" ";
  203. nIndex++;
  204. }
  205. str.FormatMessage (IDS_EMPTY_NAME_STRING, charsWithSpaces);
  206. AfxMessageBox(str);
  207. GetDlgItem(IDC_NAME)->SetFocus();
  208. return FALSE;
  209. }
  210. }
  211. return TRUE;
  212. }