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.

317 lines
8.7 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // serverprop.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Defines the classes that make up the RADIUS Server property sheet.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 02/27/2000 Original version.
  16. // 04/19/2000 Marshall SDOs across apartments.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <proxypch.h>
  20. #include <serverprop.h>
  21. #include <resolver.h>
  22. // Fake secret used for populating the edit control.
  23. const WCHAR FAKE_SECRET[] = L"\b\b\b\b\b\b\b\b";
  24. ServerNamePage::ServerNamePage(Sdo& serverSdo)
  25. : SnapInPropertyPage(IDD_SERVER_NAME),
  26. server(serverSdo)
  27. {
  28. server.getValue(PROPERTY_RADIUSSERVER_ADDRESS, address, L"");
  29. }
  30. void ServerNamePage::onResolve()
  31. {
  32. // Get the address.
  33. getValue(IDC_EDIT_NAME, address);
  34. // Pass it to the resolver.
  35. ServerResolver resolver(address);
  36. if (resolver.DoModal() == IDOK)
  37. {
  38. // The user clicked OK, so save his choice.
  39. setValue(IDC_EDIT_NAME, resolver.getChoice());
  40. }
  41. }
  42. void ServerNamePage::getData()
  43. {
  44. // Get the address.
  45. getValue(IDC_EDIT_NAME, address);
  46. // The address can't be empty.
  47. if (address.Length() == 0)
  48. {
  49. fail(IDC_EDIT_NAME, IDS_SERVER_E_NAME_EMPTY);
  50. }
  51. }
  52. void ServerNamePage::setData()
  53. {
  54. setValue(IDC_EDIT_NAME, address);
  55. }
  56. void ServerNamePage::saveChanges()
  57. {
  58. server.setValue(PROPERTY_RADIUSSERVER_ADDRESS, address);
  59. }
  60. BEGIN_MESSAGE_MAP(ServerNamePage, SnapInPropertyPage)
  61. ON_EN_CHANGE(IDC_EDIT_NAME, onChange)
  62. ON_BN_CLICKED(IDC_BUTTON_VERIFY, onResolve)
  63. END_MESSAGE_MAP()
  64. ServerAuthPage::ServerAuthPage(Sdo& serverSdo)
  65. : SnapInPropertyPage(IDD_SERVER_AUTH),
  66. server(serverSdo),
  67. authSecretDirty(false),
  68. acctSecretDirty(false)
  69. {
  70. server.getValue(PROPERTY_RADIUSSERVER_AUTH_PORT, authPort, 1812);
  71. server.getValue(PROPERTY_RADIUSSERVER_AUTH_SECRET, authSecret, L"");
  72. server.getValue(PROPERTY_RADIUSSERVER_ACCT_PORT, acctPort, 1813);
  73. server.getValue(PROPERTY_RADIUSSERVER_ACCT_SECRET, acctSecret, NULL);
  74. useSameSecret = !acctSecret;
  75. server.getValue(PROPERTY_RADIUSSERVER_FORWARD_ACCT_ONOFF, acctOnOff, true);
  76. }
  77. void ServerAuthPage::onChangeAuthSecret()
  78. {
  79. authSecretDirty = true;
  80. SetModified();
  81. }
  82. void ServerAuthPage::onChangeAcctSecret()
  83. {
  84. acctSecretDirty = true;
  85. SetModified();
  86. }
  87. void ServerAuthPage::onCheckSameSecret()
  88. {
  89. // Get the checkbox state.
  90. getValue(IDC_CHECK_SAME_SECRET, useSameSecret);
  91. // Update the edit box accordingly.
  92. enableControl(IDC_EDIT_ACCT_SECRET1, !useSameSecret);
  93. enableControl(IDC_EDIT_ACCT_SECRET2, !useSameSecret);
  94. // We've been modified.
  95. SetModified();
  96. }
  97. void ServerAuthPage::getData()
  98. {
  99. getValue(IDC_EDIT_AUTH_PORT, authPort, IDS_SERVER_E_PORT_RANGE);
  100. if (authPort <= 0 || authPort > 65535)
  101. {
  102. fail(IDC_EDIT_AUTH_PORT, IDS_SERVER_E_PORT_RANGE);
  103. }
  104. if (authSecretDirty)
  105. {
  106. // Get the authentication secret ...
  107. getValue(IDC_EDIT_AUTH_SECRET1, authSecret, false);
  108. // ... and make sure it matches the confirmation.
  109. CComBSTR confirm;
  110. getValue(IDC_EDIT_AUTH_SECRET2, confirm, false);
  111. if (wcscmp(confirm, authSecret))
  112. {
  113. fail(IDC_EDIT_AUTH_SECRET1, IDS_SERVER_E_SECRET_MATCH);
  114. }
  115. authSecretDirty = false;
  116. }
  117. getValue(IDC_EDIT_ACCT_PORT, acctPort, IDS_SERVER_E_PORT_RANGE);
  118. if (acctPort <= 0 || acctPort > 65535)
  119. {
  120. fail(IDC_EDIT_ACCT_PORT, IDS_SERVER_E_PORT_RANGE);
  121. }
  122. getValue(IDC_CHECK_SAME_SECRET, useSameSecret);
  123. if (!useSameSecret && acctSecretDirty)
  124. {
  125. // Get the accounting secret ...
  126. getValue(IDC_EDIT_ACCT_SECRET1, acctSecret);
  127. // ... and make sure it matches the confirmation.
  128. CComBSTR confirm;
  129. getValue(IDC_EDIT_ACCT_SECRET2, confirm);
  130. if (wcscmp(confirm, acctSecret))
  131. {
  132. fail(IDC_EDIT_ACCT_SECRET1, IDS_SERVER_E_SECRET_MATCH);
  133. }
  134. acctSecretDirty = false;
  135. }
  136. getValue(IDC_CHECK_ACCT_ONOFF, acctOnOff);
  137. }
  138. void ServerAuthPage::setData()
  139. {
  140. setValue(IDC_EDIT_AUTH_PORT, authPort);
  141. setValue(IDC_EDIT_AUTH_SECRET1, FAKE_SECRET);
  142. setValue(IDC_EDIT_AUTH_SECRET2, FAKE_SECRET);
  143. setValue(IDC_EDIT_ACCT_PORT, acctPort);
  144. setValue(IDC_CHECK_SAME_SECRET, useSameSecret);
  145. setValue(IDC_EDIT_ACCT_SECRET1, FAKE_SECRET);
  146. setValue(IDC_EDIT_ACCT_SECRET2, FAKE_SECRET);
  147. setValue(IDC_CHECK_ACCT_ONOFF, acctOnOff);
  148. // Update the edit box state.
  149. enableControl(IDC_EDIT_ACCT_SECRET1, !useSameSecret);
  150. enableControl(IDC_EDIT_ACCT_SECRET2, !useSameSecret);
  151. }
  152. void ServerAuthPage::saveChanges()
  153. {
  154. server.setValue(PROPERTY_RADIUSSERVER_AUTH_PORT, authPort);
  155. server.setValue(PROPERTY_RADIUSSERVER_AUTH_SECRET, authSecret);
  156. server.setValue(PROPERTY_RADIUSSERVER_ACCT_PORT, acctPort);
  157. if (useSameSecret)
  158. {
  159. server.clearValue(PROPERTY_RADIUSSERVER_ACCT_SECRET);
  160. }
  161. else
  162. {
  163. server.setValue(PROPERTY_RADIUSSERVER_ACCT_SECRET, acctSecret);
  164. }
  165. server.setValue(PROPERTY_RADIUSSERVER_FORWARD_ACCT_ONOFF, acctOnOff);
  166. }
  167. BEGIN_MESSAGE_MAP(ServerAuthPage, SnapInPropertyPage)
  168. ON_EN_CHANGE(IDC_EDIT_AUTH_PORT, onChange)
  169. ON_EN_CHANGE(IDC_EDIT_AUTH_SECRET1, onChangeAuthSecret)
  170. ON_EN_CHANGE(IDC_EDIT_AUTH_SECRET2, onChangeAuthSecret)
  171. ON_BN_CLICKED(IDC_CHECK_SAME_SECRET, onCheckSameSecret)
  172. ON_BN_CLICKED(IDC_CHECK_ACCT_ONOFF, onChange)
  173. ON_EN_CHANGE(IDC_EDIT_ACCT_PORT, onChange)
  174. ON_EN_CHANGE(IDC_EDIT_ACCT_SECRET1, onChangeAcctSecret)
  175. ON_EN_CHANGE(IDC_EDIT_ACCT_SECRET2, onChangeAcctSecret)
  176. END_MESSAGE_MAP()
  177. ServerFTLBPage::ServerFTLBPage(Sdo& serverSdo)
  178. : SnapInPropertyPage(IDD_SERVER_FTLB),
  179. server(serverSdo)
  180. {
  181. server.getValue(PROPERTY_RADIUSSERVER_PRIORITY, priority, 1);
  182. server.getValue(PROPERTY_RADIUSSERVER_WEIGHT, weight, 50);
  183. server.getValue(PROPERTY_RADIUSSERVER_TIMEOUT, timeout, 3);
  184. server.getValue(PROPERTY_RADIUSSERVER_MAX_LOST, maxLost, 5);
  185. server.getValue(PROPERTY_RADIUSSERVER_BLACKOUT, blackout, 10 * timeout);
  186. }
  187. void ServerFTLBPage::getData()
  188. {
  189. getValue(IDC_EDIT_PRIORITY, priority, IDS_SERVER_E_PRIORITY_EMPTY);
  190. if (priority < 1 || priority > 65535)
  191. {
  192. fail(IDC_EDIT_PRIORITY, IDS_SERVER_E_PRIORITY_RANGE);
  193. }
  194. getValue(IDC_EDIT_WEIGHT, weight, IDS_SERVER_E_WEIGHT_EMPTY);
  195. if (weight < 1 || weight > 65535)
  196. {
  197. fail(IDC_EDIT_WEIGHT, IDS_SERVER_E_WEIGHT_RANGE);
  198. }
  199. getValue(IDC_EDIT_TIMEOUT, timeout, IDS_SERVER_E_TIMEOUT_EMPTY);
  200. if (timeout < 1)
  201. {
  202. fail(IDC_EDIT_TIMEOUT, IDS_SERVER_E_TIMEOUT_RANGE);
  203. }
  204. getValue(IDC_EDIT_MAX_LOST, maxLost, IDS_SERVER_E_MAXLOST_EMPTY);
  205. if (maxLost < 1)
  206. {
  207. fail(IDC_EDIT_MAX_LOST, IDS_SERVER_E_MAXLOST_RANGE);
  208. }
  209. getValue(IDC_EDIT_BLACKOUT, blackout, IDS_SERVER_E_BLACKOUT_EMPTY);
  210. if (blackout < timeout)
  211. {
  212. fail(IDC_EDIT_BLACKOUT, IDS_SERVER_E_BLACKOUT_RANGE);
  213. }
  214. }
  215. void ServerFTLBPage::setData()
  216. {
  217. setValue(IDC_EDIT_PRIORITY, priority);
  218. setValue(IDC_EDIT_WEIGHT, weight);
  219. setValue(IDC_EDIT_TIMEOUT, timeout);
  220. setValue(IDC_EDIT_MAX_LOST, maxLost);
  221. setValue(IDC_EDIT_BLACKOUT, blackout);
  222. }
  223. void ServerFTLBPage::saveChanges()
  224. {
  225. server.setValue(PROPERTY_RADIUSSERVER_PRIORITY, priority);
  226. server.setValue(PROPERTY_RADIUSSERVER_WEIGHT, weight);
  227. server.setValue(PROPERTY_RADIUSSERVER_TIMEOUT, timeout);
  228. server.setValue(PROPERTY_RADIUSSERVER_MAX_LOST, maxLost);
  229. server.setValue(PROPERTY_RADIUSSERVER_BLACKOUT, blackout);
  230. }
  231. BEGIN_MESSAGE_MAP(ServerFTLBPage, SnapInPropertyPage)
  232. ON_EN_CHANGE(IDC_EDIT_PRIORITY, onChange)
  233. ON_EN_CHANGE(IDC_EDIT_WEIGHT, onChange)
  234. ON_EN_CHANGE(IDC_EDIT_TIMEOUT, onChange)
  235. ON_EN_CHANGE(IDC_EDIT_MAX_LOST, onChange)
  236. ON_EN_CHANGE(IDC_EDIT_BLACKOUT, onChange)
  237. END_MESSAGE_MAP()
  238. ServerProperties::ServerProperties(Sdo& sdo, UINT nIDCaption, CWnd* parent)
  239. : CPropertySheet(nIDCaption, parent),
  240. server(sdo),
  241. serverStream(server),
  242. name(sdo),
  243. auth(sdo),
  244. ftlb(sdo)
  245. {
  246. // Add the property pages.
  247. AddPage(&name);
  248. AddPage(&auth);
  249. AddPage(&ftlb);
  250. }
  251. INT_PTR ServerProperties::DoModal()
  252. {
  253. CPropertySheet::DoModal();
  254. if (name.hasApplied() ||
  255. auth.hasApplied() ||
  256. ftlb.hasApplied())
  257. {
  258. return IDOK;
  259. }
  260. else
  261. {
  262. return IDCANCEL;
  263. }
  264. }
  265. BOOL ServerProperties::OnInitDialog()
  266. {
  267. // Unmarshal the SDOs.
  268. serverStream.get(server);
  269. BOOL bResult = CPropertySheet::OnInitDialog();
  270. ModifyStyleEx(0, WS_EX_CONTEXTHELP);
  271. return bResult;
  272. }