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.

423 lines
11 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*++
  3. Copyright (C) Microsoft Corporation, 1998 - 1999
  4. Module Name: AddPolicyWizardPage1.cpp
  5. Abstract:
  6. Implementation file for the CNewRAPWiz_Name class.
  7. We implement the class needed to handle the first property page for a Policy node.
  8. Revision History:
  9. mmaguire 12/15/97 - created
  10. byao 1/22/98 Modified for Network Access Policy
  11. --*/
  12. //////////////////////////////////////////////////////////////////////////////
  13. #include "Precompiled.h"
  14. #include "rapwz_name.h"
  15. #include "NapUtil.h"
  16. #include "PolicyNode.h"
  17. #include "PoliciesNode.h"
  18. #include "ChangeNotification.h"
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Function: CNewRAPWiz_Name
  22. //
  23. // Class: CNewRAPWiz_Name
  24. //
  25. // Synopsis: class constructor
  26. //
  27. // Arguments: CPolicyNode *pPolicyNode - policy node for this property page
  28. // CIASAttrList *pAttrList -- attribute list
  29. // TCHAR* pTitle = NULL -
  30. //
  31. // Returns: Nothing
  32. //
  33. // History: Created Header byao 2/16/98 4:31:52 PM
  34. //
  35. //+---------------------------------------------------------------------------
  36. CNewRAPWiz_Name::CNewRAPWiz_Name(
  37. CRapWizardData* pWizData,
  38. LONG_PTR hNotificationHandle,
  39. TCHAR* pTitle, BOOL bOwnsNotificationHandle
  40. )
  41. : CIASWizard97Page<CNewRAPWiz_Name, IDS_NEWRAPWIZ_NAME_TITLE, IDS_NEWRAPWIZ_NAME_SUBTITLE> ( hNotificationHandle, pTitle, bOwnsNotificationHandle ),
  42. m_spWizData(pWizData)
  43. {
  44. TRACE_FUNCTION("CNewRAPWiz_Name::CNewRAPWiz_Name");
  45. // Add the help button to the page
  46. // m_psp.dwFlags |= PSP_HASHELP;
  47. }
  48. //+---------------------------------------------------------------------------
  49. //
  50. // Function: CNewRAPWiz_Name
  51. //
  52. // Class: CNewRAPWiz_Name
  53. //
  54. // Synopsis: class destructor
  55. //
  56. // Returns: Nothing
  57. //
  58. // History: Created Header byao 2/16/98 4:31:52 PM
  59. //
  60. //+---------------------------------------------------------------------------
  61. CNewRAPWiz_Name::~CNewRAPWiz_Name()
  62. {
  63. TRACE_FUNCTION("CNewRAPWiz_Name::~CNewRAPWiz_Name");
  64. }
  65. //////////////////////////////////////////////////////////////////////////////
  66. /*++
  67. CNewRAPWiz_Name::OnInitDialog
  68. --*/
  69. //////////////////////////////////////////////////////////////////////////////
  70. LRESULT CNewRAPWiz_Name::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  71. {
  72. TRACE_FUNCTION("CNewRAPWiz_Name::OnInitDialog");
  73. HRESULT hr = S_OK;
  74. BOOL fRet;
  75. CComPtr<IUnknown> spUnknown;
  76. CComPtr<IEnumVARIANT> spEnumVariant;
  77. long ulCount;
  78. ULONG ulCountReceived;
  79. //
  80. // set the policy name on the page
  81. //
  82. SetDlgItemText(IDC_NEWRAPWIZ_NAME_POLICYNAME, m_spWizData->m_pPolicyNode->m_bstrDisplayName);
  83. // check the default selected one
  84. CheckDlgButton(IDC_NEWRAPWIZ_NAME_SCENARIO, BST_CHECKED);
  85. SetModified(FALSE);
  86. return TRUE; // ISSUE: what do we need to be returning here?
  87. }
  88. //////////////////////////////////////////////////////////////////////////////
  89. /*++
  90. CNewRAPWiz_Name::OnWizardNext
  91. --*/
  92. //////////////////////////////////////////////////////////////////////////////
  93. BOOL CNewRAPWiz_Name::OnWizardNext()
  94. {
  95. TRACE_FUNCTION("CNewRAPWiz_Name::OnWizardNext");
  96. HRESULT hr = S_OK;
  97. WCHAR wzName[IAS_MAX_STRING];
  98. // get the new policy name
  99. if ( !GetDlgItemText(IDC_NEWRAPWIZ_NAME_POLICYNAME, wzName, IAS_MAX_STRING) )
  100. {
  101. // We couldn't retrieve a BSTR,
  102. // so we need to initialize this variant to a null BSTR.
  103. ErrorTrace(DEBUG_NAPMMC_POLICYPAGE1, "Couldn't get policy name from UI");
  104. ShowErrorDialog(m_hWnd, IDS_ERROR_INVALID_POLICYNAME, wzName);
  105. return FALSE; // can't apply
  106. }
  107. {
  108. ::CString str = (OLECHAR *) wzName;
  109. str.TrimLeft();
  110. str.TrimRight();
  111. if (str.IsEmpty())
  112. {
  113. ShowErrorDialog( NULL, IDS_ERROR__POLICYNAME_EMPTY);
  114. return FALSE; // can't apply
  115. }
  116. }
  117. // invalid name?
  118. if ( _tcscmp(wzName, m_spWizData->m_pPolicyNode->m_bstrDisplayName ) !=0 &&
  119. !ValidPolicyName(wzName)
  120. )
  121. {
  122. // name is changed, and is invalid
  123. ErrorTrace(DEBUG_NAPMMC_POLICYPAGE1, "Invalid policy name");
  124. ShowErrorDialog(m_hWnd, IDS_ERROR_INVALID_POLICYNAME);
  125. return FALSE;
  126. }
  127. CComVariant var;
  128. V_VT(&var) = VT_BSTR;
  129. V_BSTR(&var) = SysAllocString(wzName);
  130. // Put the policy name -- the DS schema has been changed so that rename works.
  131. hr = m_spWizData->m_spPolicySdo->PutProperty( PROPERTY_SDO_NAME, &var );
  132. if( FAILED( hr ) )
  133. {
  134. ErrorTrace(DEBUG_NAPMMC_POLICYPAGE1, "Couldn't change policy name, err = %x", hr);
  135. if(hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS) || hr == E_INVALIDARG)
  136. ShowErrorDialog( m_hWnd, IDS_ERROR_INVALID_POLICYNAME );
  137. else
  138. ShowErrorDialog( m_hWnd, IDS_ERROR_RENAMEPOLICY );
  139. return FALSE;
  140. }
  141. // Change the profile name to be whatever the policy name is -- the DS schema has been changed so that rename works.
  142. hr = m_spWizData->m_spProfileSdo->PutProperty( PROPERTY_SDO_NAME, &var );
  143. if( FAILED( hr ) )
  144. {
  145. ErrorTrace(DEBUG_NAPMMC_POLICYPAGE1, "Couldn't change profile name, err = %x", hr);
  146. ShowErrorDialog( m_hWnd, IDS_ERROR_RENAMEPOLICY );
  147. return FALSE;
  148. }
  149. // Put the profile name associated with the policy -- the DS schema has been changed so that rename works.
  150. hr = m_spWizData->m_spPolicySdo->PutProperty(PROPERTY_POLICY_PROFILE_NAME, &var);
  151. if( FAILED(hr) )
  152. {
  153. ErrorTrace(DEBUG_NAPMMC_POLICYPAGE1, "Couldn't save profile name for this policy, err = %x", hr);
  154. ShowErrorDialog( m_hWnd
  155. , IDS_ERROR_SDO_ERROR_PUTPROP_POLICY_PROFILENAME
  156. , NULL
  157. , hr
  158. );
  159. return FALSE;
  160. }
  161. var.Clear();
  162. // Policy merit value (the evaluation order).
  163. V_VT(&var) = VT_I4;
  164. V_I4(&var) = m_spWizData->m_pPolicyNode->GetMerit();
  165. hr = m_spWizData->m_spPolicySdo->PutProperty(PROPERTY_POLICY_MERIT, &var);
  166. if( FAILED(hr) )
  167. {
  168. ErrorTrace(DEBUG_NAPMMC_POLICYPAGE1, "Failed to save Merit Value to the policy, err = %x", hr);
  169. ShowErrorDialog( m_hWnd
  170. , IDS_ERROR_SDO_ERROR_PUTPROP_POLICYMERIT
  171. , NULL
  172. , hr
  173. );
  174. return FALSE;
  175. }
  176. DWORD dwScenaro = 0;
  177. if (IsDlgButtonChecked(IDC_NEWRAPWIZ_NAME_SCENARIO))
  178. dwScenaro = IDC_NEWRAPWIZ_NAME_SCENARIO;
  179. else if (IsDlgButtonChecked(IDC_NEWRAPWIZ_NAME_MANUAL))
  180. dwScenaro = IDC_NEWRAPWIZ_NAME_MANUAL;
  181. if (dwScenaro == 0)
  182. return FALSE;
  183. // reset the dirty bit
  184. m_spWizData->SetScenario(dwScenaro);
  185. // reset the dirty bit
  186. SetModified(FALSE);
  187. // store this name with the m_spWizData
  188. m_spWizData->m_strPolicyName = wzName;
  189. return m_spWizData->GetNextPageId(((PROPSHEETPAGE*)(*this))->pszTemplate);
  190. }
  191. //////////////////////////////////////////////////////////////////////////////
  192. /*++
  193. CNewRAPWiz_Name::OnQueryCancel
  194. --*/
  195. //////////////////////////////////////////////////////////////////////////////
  196. BOOL CNewRAPWiz_Name::OnQueryCancel()
  197. {
  198. TRACE_FUNCTION("CNewRAPWiz_Name::OnQueryCancel");
  199. return TRUE;
  200. }
  201. //+---------------------------------------------------------------------------
  202. //
  203. // Function: OnPolicyNameEdit
  204. //
  205. // Class: CConditionPage1
  206. //
  207. // Synopsis: message handler for the policy name edit box -- user
  208. // has done something that might have changed the name
  209. // We need to set the dirty bit
  210. //
  211. // Arguments: UINT uNotifyCode - notification code
  212. // UINT uID - ID of the control
  213. // HWND hWnd - HANDLE of the window
  214. // BOOL &bHandled - whether the handler has processed the msg
  215. //
  216. // Returns: LRESULT - S_OK: succeeded
  217. // S_FALSE: otherwise
  218. //
  219. // History: Created byao 2/22/98 4:51:35 PM
  220. //
  221. //+---------------------------------------------------------------------------
  222. LRESULT CNewRAPWiz_Name::OnPolicyNameEdit(UINT uMsg, WPARAM wParam, HWND hWnd, BOOL& bHandled)
  223. {
  224. TRACE_FUNCTION("CNewRAPWiz_Name::OnPolicyNameEdit");
  225. WCHAR wzName[IAS_MAX_STRING];
  226. // get the new policy name
  227. if ( !GetDlgItemText(IDC_NEWRAPWIZ_NAME_POLICYNAME, wzName, IAS_MAX_STRING) )
  228. {
  229. return 0; // can't apply
  230. }
  231. if ( _tcscmp(wzName, m_spWizData->m_pPolicyNode->m_bstrDisplayName ) !=0 )
  232. {
  233. // set the dirty bit
  234. SetModified(TRUE);
  235. }
  236. bHandled = TRUE;
  237. return 0;
  238. }
  239. //+---------------------------------------------------------------------------
  240. //
  241. // Function: OnPath
  242. //
  243. // Class: CNewRAPWiz_Name
  244. //
  245. // Synopsis: message handler for the policy name edit box -- user
  246. // has done something that might have changed the name
  247. // We need to set the dirty bit
  248. //
  249. // Arguments: UINT uNotifyCode - notification code
  250. // UINT uID - ID of the control
  251. // HWND hWnd - HANDLE of the window
  252. // BOOL &bHandled - whether the handler has processed the msg
  253. //
  254. // Returns: LRESULT - S_OK: succeeded
  255. // S_FALSE: otherwise
  256. //
  257. // History: Created byao 2/22/98 4:51:35 PM
  258. //
  259. //+---------------------------------------------------------------------------
  260. LRESULT CNewRAPWiz_Name::OnPath(UINT uMsg, WPARAM wParam, HWND hWnd, BOOL& bHandled)
  261. {
  262. // set the dirty bit
  263. SetModified(TRUE);
  264. bHandled = TRUE;
  265. return S_OK;
  266. }
  267. //+---------------------------------------------------------------------------
  268. //
  269. // Function: CNewRAPWiz_Name::ValidPolicyName
  270. //
  271. // Synopsis: Check whether this is a valid policy name
  272. //
  273. // Arguments: LPCTSTR pszName - policy name
  274. //
  275. // Returns: BOOL - TRUE: valid name
  276. //
  277. // History: Created Header byao 3/14/98 1:47:05 AM
  278. //
  279. //+---------------------------------------------------------------------------
  280. BOOL CNewRAPWiz_Name::ValidPolicyName(LPCTSTR pszName)
  281. {
  282. TRACE_FUNCTION("CNewRAPWiz_Name::ValidPolicyName");
  283. int iIndex;
  284. int iLen;
  285. // is this an empty string?
  286. iLen = wcslen(pszName);
  287. if ( !iLen )
  288. {
  289. ErrorTrace(ERROR_NAPMMC_POLICYPAGE1, "Empty policy name");
  290. return FALSE;
  291. }
  292. // is this a string that only has white spaces?
  293. for (iIndex=0; iIndex < iLen; iIndex++)
  294. {
  295. if (pszName[iIndex] != _T(' ') &&
  296. pszName[iIndex] != _T('\t') &&
  297. pszName[iIndex] != _T('\n')
  298. )
  299. {
  300. break;
  301. }
  302. }
  303. if ( iIndex == iLen )
  304. {
  305. ErrorTrace(ERROR_NAPMMC_POLICYPAGE1, "This policy name has only white spaces");
  306. return FALSE;
  307. }
  308. //
  309. // does this name already exist?
  310. //
  311. if ( ((CPoliciesNode*)(m_spWizData->m_pPolicyNode->m_pParentNode))->FindChildWithName(pszName) )
  312. {
  313. ErrorTrace(ERROR_NAPMMC_POLICYPAGE1, "This policy name already exists");
  314. return FALSE;
  315. }
  316. return TRUE;
  317. }
  318. //////////////////////////////////////////////////////////////////////////////
  319. /*++
  320. CNewRAPWiz_Name::OnSetActive
  321. Return values:
  322. TRUE if the page can be made active
  323. FALSE if the page should be be skipped and the next page should be looked at.
  324. Remarks:
  325. If you want to change which pages are visited based on a user's
  326. choices in a previous page, return FALSE here as appropriate.
  327. --*/
  328. //////////////////////////////////////////////////////////////////////////////
  329. BOOL CNewRAPWiz_Name::OnSetActive()
  330. {
  331. ATLTRACE(_T("# CNewRAPWiz_Name::OnSetActive\n"));
  332. // MSDN docs say you need to use PostMessage here rather than SendMessage.
  333. ::PropSheet_SetWizButtons(GetParent(), PSWIZB_NEXT | PSWIZB_BACK);
  334. return TRUE;
  335. }