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.

511 lines
12 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // groupwiz.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Defines the classes that implement the new RADIUS server group wizard.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 03/07/2000 Original version.
  16. // 04/19/2000 Marshall SDOs across apartments.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <proxypch.h>
  20. #include <groupwiz.h>
  21. #include <resolver.h>
  22. #include <iaslimits.h>
  23. NewGroupStartPage::NewGroupStartPage(NewGroupWizard& wizard)
  24. : SnapInPropertyPage(IDD_NEWGROUP_WELCOME, 0, 0, false),
  25. parent(wizard)
  26. {
  27. }
  28. BOOL NewGroupStartPage::OnInitDialog()
  29. {
  30. SnapInPropertyPage::OnInitDialog();
  31. setLargeFont(IDC_STATIC_LARGE);
  32. return TRUE;
  33. }
  34. BOOL NewGroupStartPage::OnSetActive()
  35. {
  36. SnapInPropertyPage::OnSetActive();
  37. parent.SetWizardButtons(PSWIZB_NEXT);
  38. return TRUE;
  39. }
  40. NewGroupNamePage::NewGroupNamePage(NewGroupWizard& wizard)
  41. : SnapInPropertyPage(
  42. IDD_NEWGROUP_NAME,
  43. IDS_NEWGROUP_NAME_TITLE,
  44. IDS_NEWGROUP_NAME_SUBTITLE,
  45. false
  46. ),
  47. parent(wizard)
  48. {
  49. }
  50. LRESULT NewGroupNamePage::OnWizardBack()
  51. {
  52. // Save the state of the radio button.
  53. getRadio(IDC_RADIO_TYPICAL, IDC_RADIO_CUSTOM, parent.advanced);
  54. return 0;
  55. }
  56. LRESULT NewGroupNamePage::OnWizardNext()
  57. {
  58. if (!parent.group.setName(name))
  59. {
  60. failNoThrow(IDC_EDIT_NAME, IDS_GROUP_E_NOT_UNIQUE);
  61. return -1;
  62. }
  63. getRadio(IDC_RADIO_TYPICAL, IDC_RADIO_CUSTOM, parent.advanced);
  64. return parent.advanced ? IDD_NEWGROUP_SERVERS : IDD_NEWGROUP_NOVICE;
  65. }
  66. void NewGroupNamePage::onChangeName()
  67. {
  68. getValue(IDC_EDIT_NAME, name);
  69. setButtons();
  70. }
  71. void NewGroupNamePage::setData()
  72. {
  73. setValue(IDC_EDIT_NAME, name);
  74. setRadio(IDC_RADIO_TYPICAL, IDC_RADIO_CUSTOM, parent.advanced);
  75. setButtons();
  76. }
  77. void NewGroupNamePage::setButtons()
  78. {
  79. parent.SetWizardButtons(
  80. name.Length() ? (PSWIZB_BACK | PSWIZB_NEXT) : PSWIZB_BACK
  81. );
  82. }
  83. BEGIN_MESSAGE_MAP(NewGroupNamePage, SnapInPropertyPage)
  84. ON_EN_CHANGE(IDC_EDIT_NAME, onChangeName)
  85. END_MESSAGE_MAP()
  86. NewGroupNovicePage::NewGroupNovicePage(NewGroupWizard& wizard)
  87. : SnapInPropertyPage(
  88. IDD_NEWGROUP_NOVICE,
  89. IDS_NEWGROUP_NOVICE_TITLE,
  90. IDS_NEWGROUP_NOVICE_SUBTITLE,
  91. false
  92. ),
  93. parent(wizard),
  94. hasBackup(true)
  95. {
  96. }
  97. LRESULT NewGroupNovicePage::OnWizardBack()
  98. {
  99. // Save the secrets.
  100. getValue(IDC_EDIT_AUTH_SECRET1, secret);
  101. getValue(IDC_EDIT_AUTH_SECRET2, confirm);
  102. return 0;
  103. }
  104. LRESULT NewGroupNovicePage::OnWizardNext()
  105. {
  106. // Get the secret.
  107. getValue(IDC_EDIT_AUTH_SECRET1, secret);
  108. // Make sure the confirmation matches the secret.
  109. getValue(IDC_EDIT_AUTH_SECRET2, confirm);
  110. if (wcscmp(secret, confirm))
  111. {
  112. failNoThrow(IDC_EDIT_AUTH_SECRET1, IDS_SERVER_E_SECRET_MATCH);
  113. return -1;
  114. }
  115. // Get the servers collection.
  116. SdoCollection servers;
  117. parent.group.getValue(
  118. PROPERTY_RADIUSSERVERGROUP_SERVERS_COLLECTION,
  119. servers
  120. );
  121. // Remove any exisiting servers.
  122. servers.removeAll();
  123. // Create the primary server.
  124. Sdo primarySdo = servers.create();
  125. primarySdo.setValue(PROPERTY_RADIUSSERVER_ADDRESS, primary);
  126. primarySdo.setValue(PROPERTY_RADIUSSERVER_AUTH_SECRET, secret);
  127. if (hasBackup)
  128. {
  129. // Create the backup server.
  130. Sdo backupSdo = servers.create();
  131. backupSdo.setValue(PROPERTY_RADIUSSERVER_ADDRESS, backup);
  132. backupSdo.setValue(PROPERTY_RADIUSSERVER_AUTH_SECRET, secret);
  133. backupSdo.setValue(PROPERTY_RADIUSSERVER_PRIORITY, 2L);
  134. }
  135. return IDD_NEWGROUP_COMPLETION;
  136. }
  137. void NewGroupNovicePage::onChangePrimary()
  138. {
  139. getValue(IDC_EDIT_PRIMARY, primary);
  140. setControlState();
  141. }
  142. void NewGroupNovicePage::onChangeHasBackup()
  143. {
  144. getValue(IDC_CHECK_BACKUP, hasBackup);
  145. setControlState();
  146. }
  147. void NewGroupNovicePage::onChangeBackup()
  148. {
  149. getValue(IDC_EDIT_BACKUP, backup);
  150. setControlState();
  151. }
  152. void NewGroupNovicePage::onVerifyPrimary()
  153. {
  154. ServerResolver resolver(primary);
  155. if (resolver.DoModal() == IDOK)
  156. {
  157. primary = resolver.getChoice();
  158. setValue(IDC_EDIT_PRIMARY, primary);
  159. setControlState();
  160. }
  161. }
  162. void NewGroupNovicePage::onVerifyBackup()
  163. {
  164. ServerResolver resolver(backup);
  165. if (resolver.DoModal() == IDOK)
  166. {
  167. backup = resolver.getChoice();
  168. setValue(IDC_EDIT_BACKUP, backup);
  169. setControlState();
  170. }
  171. }
  172. void NewGroupNovicePage::setData()
  173. {
  174. setValue(IDC_EDIT_PRIMARY, primary);
  175. setValue(IDC_CHECK_BACKUP, hasBackup);
  176. setValue(IDC_EDIT_BACKUP, backup);
  177. setValue(IDC_EDIT_AUTH_SECRET1, secret);
  178. setValue(IDC_EDIT_AUTH_SECRET2, confirm);
  179. setControlState();
  180. }
  181. void NewGroupNovicePage::setControlState()
  182. {
  183. enableControl(IDC_EDIT_BACKUP, hasBackup);
  184. enableControl(IDC_BUTTON_VERIFY_BACKUP, hasBackup);
  185. DWORD buttons = PSWIZB_BACK;
  186. // We always require a primary. We also require a backup if the box is
  187. // checked.
  188. if (primary.Length() && (!hasBackup || backup.Length()))
  189. {
  190. buttons |= PSWIZB_NEXT;
  191. }
  192. parent.SetWizardButtons(buttons);
  193. }
  194. BEGIN_MESSAGE_MAP(NewGroupNovicePage, SnapInPropertyPage)
  195. ON_EN_CHANGE(IDC_EDIT_PRIMARY, onChangePrimary)
  196. ON_EN_CHANGE(IDC_EDIT_BACKUP, onChangeBackup)
  197. ON_BN_CLICKED(IDC_CHECK_BACKUP, onChangeHasBackup)
  198. ON_BN_CLICKED(IDC_BUTTON_VERIFY_PRIMARY, onVerifyPrimary)
  199. ON_BN_CLICKED(IDC_BUTTON_VERIFY_BACKUP, onVerifyBackup)
  200. END_MESSAGE_MAP()
  201. NewGroupServersPage::NewGroupServersPage(NewGroupWizard& wizard)
  202. : SnapInPropertyPage(
  203. IDD_NEWGROUP_SERVERS,
  204. IDS_NEWGROUP_SERVERS_TITLE,
  205. IDS_NEWGROUP_SERVERS_SUBTITLE,
  206. false
  207. ),
  208. parent(wizard)
  209. {
  210. }
  211. BOOL NewGroupServersPage::OnInitDialog()
  212. {
  213. servers.onInitDialog(m_hWnd, parent.group);
  214. return SnapInPropertyPage::OnInitDialog();
  215. }
  216. void NewGroupServersPage::OnSysColorChange()
  217. {
  218. servers.onSysColorChange();
  219. }
  220. LRESULT NewGroupServersPage::OnWizardBack()
  221. {
  222. return IDD_NEWGROUP_NAME;
  223. }
  224. void NewGroupServersPage::onAdd()
  225. {
  226. if (servers.onAdd())
  227. {
  228. // If the user makes any changes to the server list, we put him in
  229. // advanced mode.
  230. parent.advanced = 1;
  231. setButtons();
  232. }
  233. }
  234. void NewGroupServersPage::onEdit()
  235. {
  236. if (servers.onEdit())
  237. {
  238. // If the user makes any changes to the server list, we put him in
  239. // advanced mode.
  240. parent.advanced = 1;
  241. }
  242. }
  243. void NewGroupServersPage::onRemove()
  244. {
  245. if (servers.onRemove())
  246. {
  247. // If the user makes any changes to the server list, we put him in
  248. // advanced mode.
  249. parent.advanced = 1;
  250. setButtons();
  251. }
  252. }
  253. void NewGroupServersPage::onColumnClick(NMLISTVIEW* listView, LRESULT* result)
  254. {
  255. servers.onColumnClick(listView->iSubItem);
  256. }
  257. void NewGroupServersPage::onItemActivate(
  258. NMITEMACTIVATE* itemActivate,
  259. LRESULT* result
  260. )
  261. {
  262. onEdit();
  263. }
  264. void NewGroupServersPage::onServerChanged(
  265. NMLISTVIEW* listView,
  266. LRESULT* result
  267. )
  268. {
  269. servers.onServerChanged();
  270. }
  271. void NewGroupServersPage::getData()
  272. {
  273. servers.saveChanges(false);
  274. }
  275. void NewGroupServersPage::setData()
  276. {
  277. servers.setData();
  278. setButtons();
  279. }
  280. void NewGroupServersPage::setButtons()
  281. {
  282. parent.SetWizardButtons(
  283. servers.isEmpty() ? PSWIZB_BACK : (PSWIZB_BACK | PSWIZB_NEXT)
  284. );
  285. }
  286. BEGIN_MESSAGE_MAP(NewGroupServersPage, SnapInPropertyPage)
  287. ON_BN_CLICKED(IDC_BUTTON_ADD, onAdd)
  288. ON_BN_CLICKED(IDC_BUTTON_EDIT, onEdit)
  289. ON_BN_CLICKED(IDC_BUTTON_REMOVE, onRemove)
  290. ON_EN_CHANGE(IDC_EDIT_NAME, onChange)
  291. ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST_SERVERS, onColumnClick)
  292. ON_NOTIFY(LVN_ITEMACTIVATE, IDC_LIST_SERVERS, onItemActivate)
  293. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_SERVERS, onServerChanged)
  294. END_MESSAGE_MAP()
  295. NewGroupFinishPage::NewGroupFinishPage(
  296. NewGroupWizard& wizard,
  297. bool promptForNewPolicy
  298. )
  299. : SnapInPropertyPage(IDD_NEWGROUP_COMPLETION, 0, 0, false),
  300. parent(wizard),
  301. allowCreate(promptForNewPolicy),
  302. createPolicy(true)
  303. {
  304. }
  305. BOOL NewGroupFinishPage::OnInitDialog()
  306. {
  307. setLargeFont(IDC_STATIC_LARGE);
  308. initControl(IDC_STATIC_FINISH, text);
  309. showControl(IDC_STATIC_CREATE_POLICY, allowCreate);
  310. showControl(IDC_CHECK_CREATE_POLICY, allowCreate);
  311. return SnapInPropertyPage::OnInitDialog();
  312. }
  313. LRESULT NewGroupFinishPage::OnWizardBack()
  314. {
  315. return parent.advanced ? IDD_NEWGROUP_SERVERS : IDD_NEWGROUP_NOVICE;
  316. }
  317. void NewGroupFinishPage::setData()
  318. {
  319. setValue(IDC_CHECK_CREATE_POLICY, createPolicy);
  320. parent.SetWizardButtons(PSWIZB_BACK | PSWIZB_FINISH);
  321. text.SetWindowText(parent.getFinishText());
  322. }
  323. void NewGroupFinishPage::saveChanges()
  324. {
  325. // This is a good time to get the status of the check box.
  326. getValue(IDC_CHECK_CREATE_POLICY, createPolicy);
  327. // We have to persist the group first. The SDOs won't let you persist a
  328. // child if the parent doesn't exist.
  329. parent.group.apply();
  330. // Get the servers collection.
  331. SdoCollection servers;
  332. parent.group.getValue(
  333. PROPERTY_RADIUSSERVERGROUP_SERVERS_COLLECTION,
  334. servers
  335. );
  336. // Persist each server.
  337. Sdo server;
  338. SdoEnum sdoEnum = servers.getNewEnum();
  339. while (sdoEnum.next(server))
  340. {
  341. server.apply();
  342. }
  343. }
  344. NewGroupWizard::NewGroupWizard(
  345. SdoConnection& connection,
  346. SnapInView* snapInView,
  347. bool promptForNewPolicy
  348. )
  349. : CPropertySheetEx(
  350. (UINT)0,
  351. NULL,
  352. 0,
  353. LoadBitmapW(
  354. AfxGetResourceHandle(),
  355. MAKEINTRESOURCEW(IDB_PROXY_SERVER_WATERMARK)
  356. ),
  357. NULL,
  358. LoadBitmapW(
  359. AfxGetResourceHandle(),
  360. MAKEINTRESOURCEW(IDB_PROXY_SERVER_HEADER)
  361. )
  362. ),
  363. advanced(0),
  364. cxn(connection),
  365. view(snapInView),
  366. start(*this),
  367. name(*this),
  368. novice(*this),
  369. servers(*this),
  370. finish(*this, promptForNewPolicy)
  371. {
  372. m_psh.dwFlags |= PSH_WIZARD97;
  373. AddPage(&start);
  374. AddPage(&name);
  375. AddPage(&novice);
  376. AddPage(&servers);
  377. AddPage(&finish);
  378. }
  379. INT_PTR NewGroupWizard::DoModal()
  380. {
  381. // Create a new group.
  382. Sdo newGroup = cxn.getServerGroups().tryCreate();
  383. if (!newGroup)
  384. {
  385. return IAS_E_LICENSE_VIOLATION;
  386. }
  387. // Save it in a stream, so we can access it from OnInitDialog.
  388. groupStream.marshal(newGroup);
  389. // Invoke the wizard.
  390. int retval = CPropertySheetEx::DoModal();
  391. if (retval == IDCANCEL)
  392. {
  393. // User cancelled, so remove the group.
  394. cxn.getServerGroups().remove(newGroup);
  395. }
  396. else if (view)
  397. {
  398. // User created a group, so send a propertyChanged notification.
  399. cxn.propertyChanged(
  400. *view,
  401. PROPERTY_IAS_RADIUSSERVERGROUPS_COLLECTION
  402. );
  403. }
  404. return retval;
  405. }
  406. CString NewGroupWizard::getFinishText()
  407. {
  408. CString text;
  409. if (!advanced)
  410. {
  411. if (novice.getBackupServer())
  412. {
  413. text.FormatMessage(
  414. IDS_NEWGROUP_FINISH_TYPICAL,
  415. name.getName(),
  416. novice.getPrimaryServer(),
  417. novice.getBackupServer()
  418. );
  419. }
  420. else
  421. {
  422. text.FormatMessage(
  423. IDS_NEWGROUP_FINISH_TYPICAL,
  424. name.getName(),
  425. novice.getPrimaryServer(),
  426. ResourceString(IDS_NEWGROUP_NO_BACKUP)
  427. );
  428. }
  429. }
  430. else
  431. {
  432. text.FormatMessage(
  433. IDS_NEWGROUP_FINISH_CUSTOM,
  434. name.getName()
  435. );
  436. }
  437. return text;
  438. }
  439. BOOL NewGroupWizard::OnInitDialog()
  440. {
  441. // Retrieve the group from the stream.
  442. groupStream.get(group);
  443. return CPropertySheetEx::OnInitDialog();
  444. }