Source code of Windows XP (NT5)
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.

436 lines
11 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. RClntPP.cpp
  7. This file contains all of the implementation for the
  8. reserved client property page.
  9. FILE HISTORY:
  10. */
  11. #include "stdafx.h"
  12. #include "rclntpp.h"
  13. #include "scope.h"
  14. #include "nodes.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. #define RADIO_CLIENT_TYPE_BOTH 0
  21. #define RADIO_CLIENT_TYPE_DHCP 1
  22. #define RADIO_CLIENT_TYPE_BOOTP 2
  23. /////////////////////////////////////////////////////////////////////////////
  24. //
  25. // CReservedClientProperties holder
  26. //
  27. /////////////////////////////////////////////////////////////////////////////
  28. CReservedClientProperties::CReservedClientProperties
  29. (
  30. ITFSNode * pNode,
  31. IComponentData * pComponentData,
  32. ITFSComponentData * pTFSCompData,
  33. LPCTSTR pszSheetName
  34. ) : CPropertyPageHolderBase(pNode, pComponentData, pszSheetName)
  35. {
  36. //ASSERT(pFolderNode == GetContainerNode());
  37. m_bAutoDeletePages = FALSE; // we have the pages as embedded members
  38. AddPageToList((CPropertyPageBase*) &m_pageGeneral);
  39. Assert(pTFSCompData != NULL);
  40. m_spTFSCompData.Set(pTFSCompData);
  41. }
  42. CReservedClientProperties::~CReservedClientProperties()
  43. {
  44. RemovePageFromList((CPropertyPageBase*) &m_pageGeneral, FALSE);
  45. if (m_liVersion.QuadPart >= DHCP_NT5_VERSION)
  46. {
  47. RemovePageFromList((CPropertyPageBase*) &m_pageDns, FALSE);
  48. }
  49. }
  50. void
  51. CReservedClientProperties::SetVersion
  52. (
  53. LARGE_INTEGER & liVersion
  54. )
  55. {
  56. m_liVersion = liVersion;
  57. if (m_liVersion.QuadPart >= DHCP_NT5_VERSION)
  58. {
  59. AddPageToList((CPropertyPageBase*) &m_pageDns);
  60. }
  61. }
  62. void
  63. CReservedClientProperties::SetClientType
  64. (
  65. BYTE bClientType
  66. )
  67. {
  68. m_pageGeneral.m_bClientType = bClientType;
  69. // this must come first
  70. if ((bClientType & CLIENT_TYPE_BOTH) == CLIENT_TYPE_BOTH)
  71. {
  72. m_pageGeneral.m_nClientType = RADIO_CLIENT_TYPE_BOTH;
  73. }
  74. else
  75. if (bClientType & CLIENT_TYPE_DHCP)
  76. {
  77. m_pageGeneral.m_nClientType = RADIO_CLIENT_TYPE_DHCP;
  78. }
  79. else
  80. if (bClientType & CLIENT_TYPE_BOOTP)
  81. {
  82. m_pageGeneral.m_nClientType = RADIO_CLIENT_TYPE_BOOTP;
  83. }
  84. else
  85. {
  86. // CLIENT_TYPE_NONE:
  87. // CLIENT_TYPE_UNSPECIFIED:
  88. m_pageGeneral.m_nClientType = -1;
  89. }
  90. }
  91. void
  92. CReservedClientProperties::SetDnsRegistration
  93. (
  94. DWORD dnsRegOption,
  95. DHCP_OPTION_SCOPE_TYPE dhcpOptionType
  96. )
  97. {
  98. m_pageDns.m_dwFlags = dnsRegOption;
  99. m_pageDns.m_dhcpOptionType = dhcpOptionType;
  100. }
  101. /////////////////////////////////////////////////////////////////////////////
  102. // CReservedClientPropGeneral property page
  103. IMPLEMENT_DYNCREATE(CReservedClientPropGeneral, CPropertyPageBase)
  104. CReservedClientPropGeneral::CReservedClientPropGeneral() : CPropertyPageBase(CReservedClientPropGeneral::IDD)
  105. {
  106. //{{AFX_DATA_INIT(CReservedClientPropGeneral)
  107. m_strComment = _T("");
  108. m_strName = _T("");
  109. m_strUID = _T("");
  110. m_nClientType = -1;
  111. //}}AFX_DATA_INIT
  112. }
  113. CReservedClientPropGeneral::~CReservedClientPropGeneral()
  114. {
  115. }
  116. void CReservedClientPropGeneral::DoDataExchange(CDataExchange* pDX)
  117. {
  118. CPropertyPageBase::DoDataExchange(pDX);
  119. //{{AFX_DATA_MAP(CReservedClientPropGeneral)
  120. DDX_Control(pDX, IDC_EDIT_COMMENT, m_editComment);
  121. DDX_Control(pDX, IDC_EDIT_NAME, m_editName);
  122. DDX_Control(pDX, IDC_EDIT_UNIQUE_IDENTIFIER, m_editUID);
  123. DDX_Text(pDX, IDC_EDIT_COMMENT, m_strComment);
  124. DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
  125. DDX_Text(pDX, IDC_EDIT_UNIQUE_IDENTIFIER, m_strUID);
  126. DDX_Radio(pDX, IDC_RADIO_TYPE_BOTH, m_nClientType);
  127. //}}AFX_DATA_MAP
  128. DDX_Control(pDX, IDC_IPADDR_RES_CLIENT_ADDRESS, m_ipaClientIpAddress);
  129. }
  130. BEGIN_MESSAGE_MAP(CReservedClientPropGeneral, CPropertyPageBase)
  131. //{{AFX_MSG_MAP(CReservedClientPropGeneral)
  132. ON_EN_CHANGE(IDC_EDIT_COMMENT, OnChangeEditComment)
  133. ON_EN_CHANGE(IDC_EDIT_NAME, OnChangeEditName)
  134. ON_EN_CHANGE(IDC_EDIT_UNIQUE_IDENTIFIER, OnChangeEditUniqueIdentifier)
  135. ON_BN_CLICKED(IDC_RADIO_TYPE_BOOTP, OnRadioTypeBootp)
  136. ON_BN_CLICKED(IDC_RADIO_TYPE_BOTH, OnRadioTypeBoth)
  137. ON_BN_CLICKED(IDC_RADIO_TYPE_DHCP, OnRadioTypeDhcp)
  138. //}}AFX_MSG_MAP
  139. END_MESSAGE_MAP()
  140. /////////////////////////////////////////////////////////////////////////////
  141. // CReservedClientPropGeneral message handlers
  142. BOOL CReservedClientPropGeneral::OnInitDialog()
  143. {
  144. CPropertyPageBase::OnInitDialog();
  145. m_ipaClientIpAddress.SetAddress(m_dwClientAddress);
  146. m_ipaClientIpAddress.SetReadOnly(TRUE);
  147. m_ipaClientIpAddress.EnableWindow(FALSE);
  148. if (m_nClientType == -1)
  149. {
  150. // no valid client type. Must be running something before
  151. // NT4 SP2. Hide the client type controls.
  152. //
  153. GetDlgItem(IDC_STATIC_CLIENT_TYPE)->ShowWindow(SW_HIDE);
  154. GetDlgItem(IDC_RADIO_TYPE_DHCP)->ShowWindow(SW_HIDE);
  155. GetDlgItem(IDC_RADIO_TYPE_BOOTP)->ShowWindow(SW_HIDE);
  156. GetDlgItem(IDC_RADIO_TYPE_BOTH)->ShowWindow(SW_HIDE);
  157. }
  158. return TRUE; // return TRUE unless you set the focus to a control
  159. // EXCEPTION: OCX Property Pages should return FALSE
  160. }
  161. void CReservedClientPropGeneral::OnChangeEditComment()
  162. {
  163. SetDirty(TRUE);
  164. }
  165. void CReservedClientPropGeneral::OnChangeEditName()
  166. {
  167. SetDirty(TRUE);
  168. }
  169. void CReservedClientPropGeneral::OnChangeEditUniqueIdentifier()
  170. {
  171. SetDirty(TRUE);
  172. }
  173. BOOL CReservedClientPropGeneral::OnApply()
  174. {
  175. UpdateData();
  176. DWORD err = 0;
  177. CString str;
  178. DATE_TIME dt;
  179. DHCP_IP_ADDRESS dhipa;
  180. CByteArray cabUid;
  181. int i;
  182. BOOL fValidUID = TRUE;
  183. CATCH_MEM_EXCEPTION
  184. {
  185. do
  186. {
  187. dt.dwLowDateTime = DHCP_DATE_TIME_ZERO_LOW;
  188. dt.dwHighDateTime = DHCP_DATE_TIME_ZERO_HIGH;
  189. m_dhcpClient.SetExpiryDateTime( dt );
  190. m_ipaClientIpAddress.GetAddress( &dhipa );
  191. if ( dhipa == 0 )
  192. {
  193. err = IDS_ERR_INVALID_CLIENT_IPADDR ;
  194. m_ipaClientIpAddress.SetFocusField(-1);
  195. break ;
  196. }
  197. m_dhcpClient.SetIpAddress(dhipa);
  198. m_editUID.GetWindowText(str);
  199. if (str.IsEmpty())
  200. {
  201. err = IDS_ERR_INVALID_UID ;
  202. m_editUID.SetSel(0,-1);
  203. m_editUID.SetFocus();
  204. break ;
  205. }
  206. //
  207. // Client UIDs should be 48 bits (6 bytes or 12 hex characters)
  208. //
  209. if (str.GetLength() != 6 * 2)
  210. fValidUID = FALSE;
  211. for (i = 0; i < str.GetLength(); i++)
  212. {
  213. if (!wcschr(rgchHex, str[i]))
  214. fValidUID = FALSE;
  215. }
  216. if (!::UtilCvtHexString(str, cabUid) && fValidUID)
  217. {
  218. err = IDS_ERR_INVALID_UID ;
  219. m_editUID.SetSel(0,-1);
  220. m_editUID.SetFocus();
  221. break ;
  222. }
  223. if (!fValidUID)
  224. {
  225. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  226. if (IDYES != AfxMessageBox(IDS_UID_MAY_BE_WRONG, MB_ICONQUESTION | MB_YESNO))
  227. {
  228. m_editUID.SetSel(0,-1);
  229. m_editUID.SetFocus();
  230. err = IDS_UID_MAY_BE_WRONG;
  231. break;
  232. }
  233. }
  234. m_dhcpClient.SetHardwareAddress( cabUid ) ;
  235. m_editName.GetWindowText( str ) ;
  236. if ( str.GetLength() == 0 )
  237. {
  238. err = IDS_ERR_INVALID_CLIENT_NAME ;
  239. m_editName.SetFocus();
  240. break ;
  241. }
  242. //
  243. // Convert client name to oem
  244. //
  245. m_dhcpClient.SetName( str ) ;
  246. m_editComment.GetWindowText( str ) ;
  247. m_dhcpClient.SetComment( str ) ;
  248. // Set the client type
  249. BYTE bClientType;
  250. switch (m_nClientType)
  251. {
  252. case RADIO_CLIENT_TYPE_DHCP:
  253. bClientType = CLIENT_TYPE_DHCP;
  254. break;
  255. case RADIO_CLIENT_TYPE_BOOTP:
  256. bClientType = CLIENT_TYPE_BOOTP;
  257. break;
  258. case RADIO_CLIENT_TYPE_BOTH:
  259. bClientType = CLIENT_TYPE_BOTH;
  260. break;
  261. default:
  262. Assert(FALSE); // should never get here
  263. bClientType = CLIENT_TYPE_UNSPECIFIED;
  264. break;
  265. }
  266. m_dhcpClient.SetClientType(bClientType);
  267. }
  268. while ( FALSE ) ;
  269. }
  270. END_MEM_EXCEPTION( err ) ;
  271. if (err)
  272. {
  273. if (err != IDS_UID_MAY_BE_WRONG)
  274. {
  275. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  276. ::DhcpMessageBox(err);
  277. }
  278. return FALSE;
  279. }
  280. BOOL bRet = CPropertyPageBase::OnApply();
  281. if (bRet == FALSE)
  282. {
  283. // Something bad happened... grab the error code
  284. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  285. ::DhcpMessageBox(GetHolder()->GetError());
  286. }
  287. return bRet;
  288. }
  289. BOOL CReservedClientPropGeneral::OnPropertyChange(BOOL bScope, LONG_PTR *ChangeMask)
  290. {
  291. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  292. SPITFSNode spResClientNode, spActiveLeasesNode;
  293. CDhcpReservationClient * pResClient;
  294. CDhcpScope * pScope;
  295. DWORD err;
  296. spResClientNode = GetHolder()->GetNode();
  297. pResClient = GETHANDLER(CDhcpReservationClient, spResClientNode);
  298. pScope = pResClient->GetScopeObject(spResClientNode, TRUE);
  299. pScope->GetActiveLeasesNode(&spActiveLeasesNode);
  300. // First tell the server to update the client information
  301. BEGIN_WAIT_CURSOR;
  302. err = pScope->UpdateReservation(&m_dhcpClient, pResClient->GetOptionValueEnum());
  303. END_WAIT_CURSOR;
  304. if (err != ERROR_SUCCESS)
  305. {
  306. GetHolder()->SetError(err);
  307. return FALSE;
  308. }
  309. *ChangeMask = SCOPE_PANE_CHANGE_ITEM_DATA;
  310. // now update our reserved client information
  311. pResClient->SetName(m_dhcpClient.QueryName());
  312. pResClient->SetComment(m_dhcpClient.QueryComment());
  313. pResClient->SetUID(m_dhcpClient.QueryHardwareAddress());
  314. pResClient->SetClientType(m_dhcpClient.QueryClientType());
  315. // Now we need to update the active lease record if it exists
  316. SPITFSNodeEnum spNodeEnum;
  317. SPITFSNode spCurrentNode;
  318. ULONG nNumReturned = 0;
  319. CDhcpActiveLease *pActiveLease = NULL;
  320. spActiveLeasesNode->GetEnum(&spNodeEnum);
  321. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  322. while (nNumReturned)
  323. {
  324. pActiveLease = GETHANDLER(CDhcpActiveLease, spCurrentNode);
  325. if (m_dhcpClient.QueryIpAddress() == pActiveLease->GetIpAddress())
  326. {
  327. // Update the name and client type
  328. pActiveLease->SetClientName(m_dhcpClient.QueryName());
  329. spCurrentNode.Release();
  330. break;
  331. }
  332. spCurrentNode.Release();
  333. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  334. }
  335. return FALSE;
  336. }
  337. void CReservedClientPropGeneral::OnRadioTypeBootp()
  338. {
  339. if (!IsDirty() &&
  340. m_bClientType != CLIENT_TYPE_BOOTP)
  341. {
  342. SetDirty(TRUE);
  343. }
  344. }
  345. void CReservedClientPropGeneral::OnRadioTypeBoth()
  346. {
  347. if (!IsDirty() &&
  348. m_bClientType != CLIENT_TYPE_BOTH)
  349. {
  350. SetDirty(TRUE);
  351. }
  352. }
  353. void CReservedClientPropGeneral::OnRadioTypeDhcp()
  354. {
  355. if (!IsDirty() &&
  356. m_bClientType != CLIENT_TYPE_DHCP)
  357. {
  358. SetDirty(TRUE);
  359. }
  360. }