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.

1959 lines
52 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. nodes.h
  7. This file contains all of the implementation for the DHCP
  8. objects that appear in the result pane of the MMC framework.
  9. The objects are:
  10. CDhcpActiveLease
  11. CDhcpConflicAddress
  12. CDhcpAllocationRange
  13. CDhcpExclusionRange
  14. CDhcpBootpTableEntry
  15. CDhcpOption
  16. FILE HISTORY:
  17. */
  18. #include "stdafx.h"
  19. #include "nodes.h"
  20. #include "server.h"
  21. #include "scope.h"
  22. #include "bootppp.h"
  23. #include "optcfg.h"
  24. #include "intltime.h"
  25. CString g_szClientTypeUnspecified;
  26. CString g_szClientTypeNone;
  27. CString g_szClientTypeUnknown;
  28. const TCHAR g_szClientTypeDhcp[] = _T("DHCP");
  29. const TCHAR g_szClientTypeBootp[] = _T("BOOTP");
  30. const TCHAR g_szClientTypeBoth[] = _T("DHCP/BOOTP");
  31. /*---------------------------------------------------------------------------
  32. Class CDhcpActiveLease implementation
  33. ---------------------------------------------------------------------------*/
  34. DEBUG_DECLARE_INSTANCE_COUNTER(CDhcpActiveLease);
  35. /*---------------------------------------------------------------------------
  36. CDhcpActiveLease constructor/destructor
  37. Takes the NT5 client info struct
  38. Author: EricDav
  39. ---------------------------------------------------------------------------*/
  40. CDhcpActiveLease::CDhcpActiveLease
  41. (
  42. ITFSComponentData * pTFSCompData,
  43. LPDHCP_CLIENT_INFO_V5 pDhcpClientInfo
  44. ) : CDhcpHandler(pTFSCompData)
  45. {
  46. DEBUG_INCREMENT_INSTANCE_COUNTER(CDhcpActiveLease);
  47. if (g_szClientTypeUnspecified.IsEmpty())
  48. {
  49. g_szClientTypeUnspecified.LoadString(IDS_UNSPECIFIED);
  50. g_szClientTypeNone.LoadString(IDS_NONE);
  51. g_szClientTypeUnknown.LoadString(IDS_UNKNOWN);
  52. }
  53. //
  54. // Reset our flags for this lease
  55. //
  56. m_dwTypeFlags = 0;
  57. //
  58. // Intialize our client type variable
  59. //
  60. m_bClientType = pDhcpClientInfo->bClientType;
  61. //
  62. // Initialize does everything but initialize the client type
  63. // since there are two versions of the client info struct, one
  64. // contains the type, the other doesn't. So we need to save it
  65. // away after the call.
  66. //
  67. InitInfo((LPDHCP_CLIENT_INFO) pDhcpClientInfo);
  68. // now check NT5 specific flags
  69. if (pDhcpClientInfo->AddressState & V5_ADDRESS_BIT_UNREGISTERED)
  70. {
  71. if (pDhcpClientInfo->AddressState & V5_ADDRESS_BIT_DELETED)
  72. {
  73. // this lease is pending DNS unregistration
  74. m_dwTypeFlags |= TYPE_FLAG_DNS_UNREG;
  75. }
  76. else
  77. {
  78. // this lease is pending DNS registration
  79. m_dwTypeFlags |= TYPE_FLAG_DNS_REG;
  80. }
  81. }
  82. else
  83. if ((pDhcpClientInfo->AddressState & 0x03) == V5_ADDRESS_STATE_DOOM)
  84. {
  85. m_dwTypeFlags |= TYPE_FLAG_DOOMED;
  86. }
  87. }
  88. /*---------------------------------------------------------------------------
  89. CDhcpActiveLease constructor/destructor
  90. Takes the NT4 SP2 client info struct
  91. Author: EricDav
  92. ---------------------------------------------------------------------------*/
  93. CDhcpActiveLease::CDhcpActiveLease
  94. (
  95. ITFSComponentData * pTFSCompData,
  96. LPDHCP_CLIENT_INFO_V4 pDhcpClientInfo
  97. ) : CDhcpHandler(pTFSCompData)
  98. {
  99. DEBUG_INCREMENT_INSTANCE_COUNTER(CDhcpActiveLease);
  100. //
  101. // Reset our flags for this lease
  102. //
  103. m_dwTypeFlags = 0;
  104. //
  105. // Intialize our client type variable
  106. //
  107. m_bClientType = pDhcpClientInfo->bClientType;
  108. //
  109. // Initialize does everything but initialize the client type
  110. // since there are two versions of the client info struct, one
  111. // contains the type, the other doesn't. So we need to save it
  112. // away after the call.
  113. //
  114. InitInfo((LPDHCP_CLIENT_INFO) pDhcpClientInfo);
  115. }
  116. /*---------------------------------------------------------------------------
  117. CDhcpActiveLease constructor/destructor
  118. Takes the pre-NT4 SP2 client info struct
  119. Author: EricDav
  120. ---------------------------------------------------------------------------*/
  121. CDhcpActiveLease::CDhcpActiveLease
  122. (
  123. ITFSComponentData * pTFSCompData,
  124. LPDHCP_CLIENT_INFO pDhcpClientInfo
  125. ) : CDhcpHandler(pTFSCompData)
  126. {
  127. DEBUG_INCREMENT_INSTANCE_COUNTER(CDhcpActiveLease);
  128. //m_verbDefault = MMC_VERB_PROPERTIES;
  129. //
  130. // Reset our flags for this lease
  131. //
  132. m_dwTypeFlags = 0;
  133. //
  134. // Intialize our client type variable
  135. //
  136. m_bClientType = CLIENT_TYPE_DHCP;
  137. InitInfo((LPDHCP_CLIENT_INFO) pDhcpClientInfo);
  138. }
  139. CDhcpActiveLease::CDhcpActiveLease
  140. (
  141. ITFSComponentData * pTFSCompData,
  142. CDhcpClient & dhcpClient
  143. ) : CDhcpHandler(pTFSCompData)
  144. {
  145. DEBUG_INCREMENT_INSTANCE_COUNTER(CDhcpActiveLease);
  146. //
  147. // Reset our flags for this lease
  148. //
  149. m_dwTypeFlags = 0;
  150. //
  151. // Intialize our client type variable
  152. //
  153. m_bClientType = CLIENT_TYPE_NONE;
  154. m_dhcpClientIpAddress = dhcpClient.QueryIpAddress();
  155. m_strClientName = dhcpClient.QueryName();
  156. m_strComment = dhcpClient.QueryComment();
  157. //
  158. // Check to see if this lease has an infinite expiration. If so, it's
  159. // an active reservation. If the expiration is zero, then it's an inactive reservation.
  160. //
  161. DATE_TIME dt = dhcpClient.QueryExpiryDateTime();
  162. m_leaseExpires.dwLowDateTime = dt.dwLowDateTime;
  163. m_leaseExpires.dwHighDateTime = dt.dwHighDateTime;
  164. if ( (dhcpClient.QueryExpiryDateTime().dwLowDateTime == DHCP_DATE_TIME_INFINIT_LOW) &&
  165. (dhcpClient.QueryExpiryDateTime().dwHighDateTime == DHCP_DATE_TIME_INFINIT_HIGH) )
  166. {
  167. CString strBadAddress;
  168. strBadAddress.LoadString(IDS_DHCP_BAD_ADDRESS);
  169. //
  170. // Bad addresses show up as active reservations, so we need to do the right thing.
  171. //
  172. if (strBadAddress.Compare(m_strClientName) == 0)
  173. {
  174. m_dwTypeFlags |= TYPE_FLAG_RESERVATION;
  175. m_dwTypeFlags |= TYPE_FLAG_BAD_ADDRESS;
  176. m_strLeaseExpires.LoadString(IDS_DHCP_LEASE_NOT_APPLICABLE);
  177. }
  178. else
  179. {
  180. //
  181. // Assume infinite lease clients
  182. //
  183. m_strLeaseExpires.LoadString(IDS_INFINTE);
  184. }
  185. }
  186. else
  187. if ( (dhcpClient.QueryExpiryDateTime().dwLowDateTime == 0) &&
  188. (dhcpClient.QueryExpiryDateTime().dwHighDateTime == 0) )
  189. {
  190. //
  191. // This is an inactive reservation
  192. //
  193. m_dwTypeFlags |= TYPE_FLAG_RESERVATION;
  194. m_strLeaseExpires.LoadString(IDS_DHCP_INFINITE_LEASE_INACTIVE);
  195. }
  196. else
  197. {
  198. //
  199. // Generate the time the lease expires in a nicely formatted string
  200. //
  201. CTime timeTemp(m_leaseExpires);
  202. m_timeLeaseExpires = timeTemp;
  203. FormatDateTime(m_strLeaseExpires, &m_leaseExpires);
  204. SYSTEMTIME st;
  205. GetLocalTime(&st);
  206. CTime systemTime(st);
  207. if (systemTime > m_timeLeaseExpires)
  208. m_dwTypeFlags |= TYPE_FLAG_GHOST;
  209. }
  210. if (dhcpClient.QueryHardwareAddress().GetSize() >= 3 &&
  211. dhcpClient.QueryHardwareAddress()[0] == 'R' &&
  212. dhcpClient.QueryHardwareAddress()[1] == 'A' &&
  213. dhcpClient.QueryHardwareAddress()[2] == 'S')
  214. {
  215. m_dwTypeFlags |= TYPE_FLAG_RAS;
  216. m_strUID = RAS_UID;
  217. }
  218. else
  219. {
  220. // build the client UID string
  221. UtilCvtByteArrayToString(dhcpClient.QueryHardwareAddress(), m_strUID);
  222. }
  223. }
  224. CDhcpActiveLease::~CDhcpActiveLease()
  225. {
  226. DEBUG_DECREMENT_INSTANCE_COUNTER(CDhcpActiveLease);
  227. }
  228. /*!--------------------------------------------------------------------------
  229. CDhcpActiveLease::InitializeNode
  230. Initializes node specific data
  231. Author: EricDav
  232. ---------------------------------------------------------------------------*/
  233. HRESULT
  234. CDhcpActiveLease::InitializeNode
  235. (
  236. ITFSNode * pNode
  237. )
  238. {
  239. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  240. CString strTemp;
  241. BOOL bIsRes, bActive, bBad;
  242. UtilCvtIpAddrToWstr (m_dhcpClientIpAddress,
  243. &strTemp);
  244. SetDisplayName(strTemp);
  245. bIsRes = IsReservation(&bActive, &bBad);
  246. // Make the node immediately visible
  247. pNode->SetVisibilityState(TFS_VIS_SHOW);
  248. pNode->SetData(TFS_DATA_COOKIE, (LPARAM) pNode);
  249. pNode->SetData(TFS_DATA_USER, (LPARAM) this);
  250. pNode->SetData(TFS_DATA_TYPE, DHCPSNAP_ACTIVE_LEASE);
  251. int nImage = ICON_IDX_CLIENT;
  252. // Figure out if we need a different icon for this lease
  253. if (m_dwTypeFlags & TYPE_FLAG_RAS)
  254. {
  255. nImage = ICON_IDX_CLIENT_RAS;
  256. }
  257. else
  258. if (m_dwTypeFlags & TYPE_FLAG_DNS_REG)
  259. {
  260. nImage = ICON_IDX_CLIENT_DNS_REGISTERING;
  261. }
  262. else
  263. if (m_dwTypeFlags & TYPE_FLAG_DNS_UNREG)
  264. {
  265. nImage = ICON_IDX_CLIENT_EXPIRED;
  266. }
  267. else
  268. if (m_dwTypeFlags & TYPE_FLAG_DOOMED)
  269. {
  270. nImage = ICON_IDX_CLIENT_EXPIRED;
  271. }
  272. else
  273. if (bIsRes)
  274. {
  275. nImage = ICON_IDX_RES_CLIENT;
  276. }
  277. else
  278. if (m_dwTypeFlags & TYPE_FLAG_GHOST)
  279. {
  280. nImage = ICON_IDX_CLIENT_EXPIRED;
  281. }
  282. pNode->SetData(TFS_DATA_IMAGEINDEX, nImage);
  283. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, nImage);
  284. //SetColumnStringIDs(&aColumns[DHCPSNAP_ACTIVE_LEASES][0]);
  285. //SetColumnWidths(&aColumnWidths[DHCPSNAP_ACTIVE_LEASES][0]);
  286. return hrOK;
  287. }
  288. /*!--------------------------------------------------------------------------
  289. CDhcpActiveLease::InitInfo
  290. Helper to initialize data
  291. Author: EricDav
  292. ---------------------------------------------------------------------------*/
  293. void
  294. CDhcpActiveLease::InitInfo(LPDHCP_CLIENT_INFO pDhcpClientInfo)
  295. {
  296. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  297. m_dhcpClientIpAddress = pDhcpClientInfo->ClientIpAddress;
  298. //
  299. // Copy the client name if it has one
  300. //
  301. if (pDhcpClientInfo->ClientName)
  302. {
  303. m_strClientName = pDhcpClientInfo->ClientName;
  304. //m_strClientName.MakeLower();
  305. }
  306. if (pDhcpClientInfo->ClientComment)
  307. {
  308. m_strComment = pDhcpClientInfo->ClientComment;
  309. }
  310. //
  311. // Check to see if this lease has an infinite expiration. If so, it's
  312. // an active reservation. If the expiration is zero, then it's an inactive reservation.
  313. //
  314. DATE_TIME dt = pDhcpClientInfo->ClientLeaseExpires;
  315. m_leaseExpires.dwLowDateTime = dt.dwLowDateTime;
  316. m_leaseExpires.dwHighDateTime = dt.dwHighDateTime;
  317. if ( (pDhcpClientInfo->ClientLeaseExpires.dwLowDateTime == DHCP_DATE_TIME_INFINIT_LOW) &&
  318. (pDhcpClientInfo->ClientLeaseExpires.dwHighDateTime == DHCP_DATE_TIME_INFINIT_HIGH) )
  319. {
  320. CString strBadAddress;
  321. strBadAddress.LoadString(IDS_DHCP_BAD_ADDRESS);
  322. //
  323. // Bad addresses show up as active reservations, so we need to do the right thing.
  324. //
  325. if (strBadAddress.Compare(m_strClientName) == 0)
  326. {
  327. m_dwTypeFlags |= TYPE_FLAG_RESERVATION;
  328. m_dwTypeFlags |= TYPE_FLAG_BAD_ADDRESS;
  329. m_strLeaseExpires.LoadString(IDS_DHCP_LEASE_NOT_APPLICABLE);
  330. }
  331. else
  332. {
  333. //
  334. // Assume infinite lease clients
  335. //
  336. m_strLeaseExpires.LoadString(IDS_INFINTE);
  337. }
  338. }
  339. else
  340. if ( (pDhcpClientInfo->ClientLeaseExpires.dwLowDateTime == 0) &&
  341. (pDhcpClientInfo->ClientLeaseExpires.dwHighDateTime == 0) )
  342. {
  343. //
  344. // This is an inactive reservation
  345. //
  346. m_dwTypeFlags |= TYPE_FLAG_RESERVATION;
  347. m_strLeaseExpires.LoadString(IDS_DHCP_INFINITE_LEASE_INACTIVE);
  348. }
  349. else
  350. {
  351. //
  352. // Generate the time the lease expires in a nicely formatted string
  353. //
  354. CTime timeTemp(m_leaseExpires);
  355. m_timeLeaseExpires = timeTemp;
  356. FormatDateTime(m_strLeaseExpires, &m_leaseExpires);
  357. CTime timeCurrent = CTime::GetCurrentTime();
  358. if (timeCurrent > m_timeLeaseExpires)
  359. m_dwTypeFlags |= TYPE_FLAG_GHOST;
  360. }
  361. if (pDhcpClientInfo->ClientHardwareAddress.DataLength >= 3 &&
  362. pDhcpClientInfo->ClientHardwareAddress.Data[0] == 'R' &&
  363. pDhcpClientInfo->ClientHardwareAddress.Data[1] == 'A' &&
  364. pDhcpClientInfo->ClientHardwareAddress.Data[2] == 'S')
  365. {
  366. m_dwTypeFlags |= TYPE_FLAG_RAS;
  367. m_strUID = RAS_UID;
  368. }
  369. else
  370. {
  371. // build the client UID string
  372. CByteArray baUID;
  373. for (DWORD i = 0; i < pDhcpClientInfo->ClientHardwareAddress.DataLength; i++)
  374. {
  375. baUID.Add(pDhcpClientInfo->ClientHardwareAddress.Data[i]);
  376. }
  377. UtilCvtByteArrayToString(baUID, m_strUID);
  378. }
  379. }
  380. /*!--------------------------------------------------------------------------
  381. CDhcpActiveLease::AddMenuItems
  382. Implementation of ITFSResultHandler::AddMenuItems
  383. Author: EricDav
  384. ---------------------------------------------------------------------------*/
  385. STDMETHODIMP
  386. CDhcpActiveLease::AddMenuItems
  387. (
  388. ITFSComponent * pComponent,
  389. MMC_COOKIE cookie,
  390. LPDATAOBJECT pDataObject,
  391. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  392. long * pInsertionAllowed
  393. )
  394. {
  395. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  396. HRESULT hr;
  397. return hrOK;
  398. }
  399. /*!--------------------------------------------------------------------------
  400. CDhcpActiveLease::Command
  401. Implementation of ITFSResultHandler::Command
  402. Author: EricDav
  403. ---------------------------------------------------------------------------*/
  404. STDMETHODIMP
  405. CDhcpActiveLease::Command
  406. (
  407. ITFSComponent * pComponent,
  408. MMC_COOKIE cookie,
  409. int nCommandID,
  410. LPDATAOBJECT pDataObject
  411. )
  412. {
  413. return hrOK;
  414. }
  415. /*!--------------------------------------------------------------------------
  416. CDhcpActiveLease::CreatePropertyPages
  417. Description
  418. Author: EricDav
  419. ---------------------------------------------------------------------------*/
  420. STDMETHODIMP
  421. CDhcpActiveLease::CreatePropertyPages
  422. (
  423. ITFSComponent * pComponent,
  424. MMC_COOKIE cookie,
  425. LPPROPERTYSHEETCALLBACK lpProvider,
  426. LPDATAOBJECT pDataObject,
  427. LONG_PTR handle
  428. )
  429. {
  430. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  431. HRESULT hr = hrOK;
  432. SPITFSNode spNode;
  433. m_spNodeMgr->FindNode(cookie, &spNode);
  434. hr = DoPropSheet(spNode, lpProvider, handle);
  435. return hr;
  436. }
  437. /*!--------------------------------------------------------------------------
  438. Function
  439. Description
  440. Author: EricDav
  441. ---------------------------------------------------------------------------*/
  442. STDMETHODIMP_(LPCTSTR)
  443. CDhcpActiveLease::GetString
  444. (
  445. ITFSComponent * pComponent,
  446. MMC_COOKIE cookie,
  447. int nCol
  448. )
  449. {
  450. switch (nCol)
  451. {
  452. case 0:
  453. return GetDisplayName();
  454. case 1:
  455. return m_strClientName;
  456. case 2:
  457. return (LPCWSTR)m_strLeaseExpires;
  458. case 3:
  459. return GetClientType();
  460. case 4:
  461. return m_strUID;
  462. case 5:
  463. return m_strComment;
  464. }
  465. return NULL;
  466. }
  467. /*!--------------------------------------------------------------------------
  468. Function
  469. Description
  470. Author: EricDav
  471. ---------------------------------------------------------------------------*/
  472. LPCTSTR
  473. CDhcpActiveLease::GetClientType()
  474. {
  475. // set the default return value
  476. LPCTSTR pszReturn = g_szClientTypeUnknown;
  477. // this one must come before the check for DHCP or BOOTP
  478. // because it is a combination of both flags
  479. if ((m_bClientType & CLIENT_TYPE_BOTH) == CLIENT_TYPE_BOTH)
  480. {
  481. pszReturn = g_szClientTypeBoth;
  482. }
  483. else
  484. if (m_bClientType & CLIENT_TYPE_DHCP)
  485. {
  486. pszReturn = g_szClientTypeDhcp;
  487. }
  488. else
  489. if (m_bClientType & CLIENT_TYPE_BOOTP)
  490. {
  491. pszReturn = g_szClientTypeBootp;
  492. }
  493. else
  494. if (m_bClientType & CLIENT_TYPE_NONE)
  495. {
  496. pszReturn = g_szClientTypeNone;
  497. }
  498. else
  499. if (m_bClientType & CLIENT_TYPE_UNSPECIFIED)
  500. {
  501. pszReturn = g_szClientTypeUnspecified;
  502. }
  503. else
  504. {
  505. Assert1(FALSE, "CDhcpActiveLease::GetClientType - Unknown client type %d", m_bClientType);
  506. }
  507. return pszReturn;
  508. }
  509. /*!--------------------------------------------------------------------------
  510. Function
  511. Description
  512. Author: EricDav
  513. ---------------------------------------------------------------------------*/
  514. void
  515. CDhcpActiveLease::GetLeaseExpirationTime
  516. (
  517. CTime & time
  518. )
  519. {
  520. time = m_timeLeaseExpires;
  521. }
  522. /*!--------------------------------------------------------------------------
  523. Function
  524. Description
  525. Author: EricDav
  526. ---------------------------------------------------------------------------*/
  527. BOOL
  528. CDhcpActiveLease::IsReservation
  529. (
  530. BOOL * pbIsActive,
  531. BOOL * pbIsBad
  532. )
  533. {
  534. BOOL bIsReservation = FALSE;
  535. *pbIsBad = FALSE;
  536. /* if ( (m_dhcpClientInfo.ClientLeaseExpires.dwLowDateTime == DHCP_DATE_TIME_INFINIT_LOW) &&
  537. (m_dhcpClientInfo.ClientLeaseExpires.dwHighDateTime == DHCP_DATE_TIME_INFINIT_HIGH) )
  538. {
  539. //
  540. // This is an active reservation
  541. //
  542. bIsReservation = TRUE;
  543. *pbIsActive = TRUE;
  544. *pbIsBad = IsBadAddress();
  545. }
  546. else
  547. if ( (m_dhcpClientInfo.ClientLeaseExpires.dwLowDateTime == 0) &&
  548. (m_dhcpClientInfo.ClientLeaseExpires.dwHighDateTime == 0) )
  549. {
  550. //
  551. // This is an inactive reservation
  552. //
  553. bIsReservation = TRUE;
  554. *pbIsActive = FALSE;
  555. }
  556. */
  557. *pbIsActive = m_dwTypeFlags & TYPE_FLAG_ACTIVE;
  558. *pbIsBad = m_dwTypeFlags & TYPE_FLAG_BAD_ADDRESS;
  559. return bIsReservation = m_dwTypeFlags & TYPE_FLAG_RESERVATION;
  560. }
  561. /*!--------------------------------------------------------------------------
  562. Function
  563. Description
  564. Author: EricDav
  565. ---------------------------------------------------------------------------*/
  566. HRESULT
  567. CDhcpActiveLease::DoPropSheet
  568. (
  569. ITFSNode * pNode,
  570. LPPROPERTYSHEETCALLBACK lpProvider,
  571. LONG_PTR handle
  572. )
  573. {
  574. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  575. HRESULT hr = hrOK;
  576. return hr;
  577. }
  578. /*!--------------------------------------------------------------------------
  579. Function
  580. Description
  581. Author: EricDav
  582. ---------------------------------------------------------------------------*/
  583. HRESULT
  584. CDhcpActiveLease::SetClientName
  585. (
  586. LPCTSTR pName
  587. )
  588. {
  589. if (pName != NULL)
  590. {
  591. m_strClientName = pName;
  592. }
  593. else
  594. {
  595. m_strClientName.Empty();
  596. }
  597. return hrOK;
  598. }
  599. /*!--------------------------------------------------------------------------
  600. CDhcpActiveLease::SetReservation
  601. Description
  602. Author: EricDav
  603. ---------------------------------------------------------------------------*/
  604. void
  605. CDhcpActiveLease::SetReservation(BOOL fReservation)
  606. {
  607. if (fReservation)
  608. {
  609. if ( (m_leaseExpires.dwLowDateTime == DHCP_DATE_TIME_INFINIT_LOW) &&
  610. (m_leaseExpires.dwHighDateTime == DHCP_DATE_TIME_INFINIT_HIGH) )
  611. {
  612. //
  613. // This is an active reservation
  614. //
  615. m_dwTypeFlags |= TYPE_FLAG_RESERVATION;
  616. m_dwTypeFlags |= TYPE_FLAG_ACTIVE;
  617. m_strLeaseExpires.LoadString(IDS_DHCP_INFINITE_LEASE_ACTIVE);
  618. }
  619. else
  620. if ( (m_leaseExpires.dwLowDateTime == 0) &&
  621. (m_leaseExpires.dwHighDateTime == 0) )
  622. {
  623. m_dwTypeFlags |= TYPE_FLAG_RESERVATION;
  624. m_strLeaseExpires.LoadString(IDS_DHCP_INFINITE_LEASE_INACTIVE);
  625. }
  626. else
  627. {
  628. Trace1("CDhcpActiveLease::SetReservation - %lx does not have a valid reservation lease time!", m_dhcpClientIpAddress);
  629. }
  630. }
  631. else
  632. {
  633. m_dwTypeFlags &= ~TYPE_FLAG_RESERVATION;
  634. m_dwTypeFlags &= ~TYPE_FLAG_ACTIVE;
  635. }
  636. }
  637. /*!--------------------------------------------------------------------------
  638. CDhcpActiveLease::OnResultRefresh
  639. Forwards refresh to parent to handle
  640. Author: EricDav
  641. ---------------------------------------------------------------------------*/
  642. HRESULT CDhcpActiveLease::OnResultRefresh(ITFSComponent * pComponent, LPDATAOBJECT pDataObject, MMC_COOKIE cookie, LPARAM arg, LPARAM lParam)
  643. {
  644. HRESULT hr = hrOK;
  645. SPITFSNode spNode, spParent;
  646. SPITFSResultHandler spParentRH;
  647. m_spNodeMgr->FindNode(cookie, &spNode);
  648. // forward this command to the parent to handle
  649. CORg (spNode->GetParent(&spParent));
  650. CORg (spParent->GetResultHandler(&spParentRH));
  651. CORg (spParentRH->Notify(pComponent, spParent->GetData(TFS_DATA_COOKIE), pDataObject, MMCN_REFRESH, arg, lParam));
  652. Error:
  653. return hrOK;
  654. }
  655. /*---------------------------------------------------------------------------
  656. Class CDhcpAllocationRange implementation
  657. ---------------------------------------------------------------------------*/
  658. /*!--------------------------------------------------------------------------
  659. Function
  660. Description
  661. Author: EricDav
  662. ---------------------------------------------------------------------------*/
  663. CDhcpAllocationRange::CDhcpAllocationRange
  664. (
  665. ITFSComponentData * pTFSCompData,
  666. DHCP_IP_RANGE * pdhcpIpRange
  667. ) : CDhcpHandler(pTFSCompData)
  668. {
  669. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  670. SetAddr (pdhcpIpRange->StartAddress, TRUE);
  671. SetAddr (pdhcpIpRange->EndAddress, FALSE);
  672. // now do the ending IP address
  673. //
  674. UtilCvtIpAddrToWstr (pdhcpIpRange->EndAddress,
  675. &m_strEndIpAddress);
  676. // and finally the description
  677. //
  678. m_strDescription.LoadString(IDS_ALLOCATION_RANGE_DESCRIPTION);
  679. }
  680. /*!--------------------------------------------------------------------------
  681. Function
  682. Description
  683. Author: EricDav
  684. ---------------------------------------------------------------------------*/
  685. CDhcpAllocationRange::CDhcpAllocationRange
  686. (
  687. ITFSComponentData * pTFSCompData,
  688. DHCP_BOOTP_IP_RANGE * pdhcpIpRange
  689. ) : CDhcpHandler(pTFSCompData)
  690. {
  691. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  692. SetAddr (pdhcpIpRange->StartAddress, TRUE);
  693. SetAddr (pdhcpIpRange->EndAddress, FALSE);
  694. m_BootpAllocated = pdhcpIpRange->BootpAllocated;
  695. m_MaxBootpAllowed = pdhcpIpRange->MaxBootpAllowed;
  696. // now do the ending IP address
  697. //
  698. UtilCvtIpAddrToWstr (pdhcpIpRange->EndAddress,
  699. &m_strEndIpAddress);
  700. // and finally the description
  701. //
  702. m_strDescription.LoadString(IDS_ALLOCATION_RANGE_DESCRIPTION);
  703. }
  704. /*!--------------------------------------------------------------------------
  705. CDhcpAllocationRange::InitializeNode
  706. Initializes node specific data
  707. Author: EricDav
  708. ---------------------------------------------------------------------------*/
  709. HRESULT
  710. CDhcpAllocationRange::InitializeNode
  711. (
  712. ITFSNode * pNode
  713. )
  714. {
  715. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  716. CString strTemp;
  717. UtilCvtIpAddrToWstr (QueryAddr(TRUE), &strTemp);
  718. SetDisplayName(strTemp);
  719. // Make the node immediately visible
  720. pNode->SetVisibilityState(TFS_VIS_SHOW);
  721. pNode->SetData(TFS_DATA_COOKIE, (LPARAM) pNode);
  722. pNode->SetData(TFS_DATA_IMAGEINDEX, ICON_IDX_ALLOCATION_RANGE);
  723. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, ICON_IDX_ALLOCATION_RANGE);
  724. pNode->SetData(TFS_DATA_USER, (LPARAM) this);
  725. pNode->SetData(TFS_DATA_TYPE, DHCPSNAP_ALLOCATION_RANGE);
  726. //SetColumnStringIDs(&aColumns[DHCPSNAP_ACTIVE_LEASES][0]);
  727. //SetColumnWidths(&aColumnWidths[DHCPSNAP_ACTIVE_LEASES][0]);
  728. return hrOK;
  729. }
  730. /*!--------------------------------------------------------------------------
  731. Function
  732. Description
  733. Author: EricDav
  734. ---------------------------------------------------------------------------*/
  735. STDMETHODIMP_(LPCTSTR)
  736. CDhcpAllocationRange::GetString
  737. (
  738. ITFSComponent * pComponent,
  739. MMC_COOKIE cookie,
  740. int nCol
  741. )
  742. {
  743. switch (nCol)
  744. {
  745. case 0:
  746. return GetDisplayName();
  747. case 1:
  748. return (LPCWSTR)m_strEndIpAddress;
  749. case 2:
  750. return (LPCWSTR)m_strDescription;
  751. }
  752. return NULL;
  753. }
  754. /*!--------------------------------------------------------------------------
  755. CDhcpAllocationRange::OnResultRefresh
  756. Forwards refresh to parent to handle
  757. Author: EricDav
  758. ---------------------------------------------------------------------------*/
  759. HRESULT CDhcpAllocationRange::OnResultRefresh(ITFSComponent * pComponent, LPDATAOBJECT pDataObject, MMC_COOKIE cookie, LPARAM arg, LPARAM lParam)
  760. {
  761. HRESULT hr = hrOK;
  762. SPITFSNode spNode, spParent;
  763. SPITFSResultHandler spParentRH;
  764. m_spNodeMgr->FindNode(cookie, &spNode);
  765. // forward this command to the parent to handle
  766. CORg (spNode->GetParent(&spParent));
  767. CORg (spParent->GetResultHandler(&spParentRH));
  768. CORg (spParentRH->Notify(pComponent, spParent->GetData(TFS_DATA_COOKIE), pDataObject, MMCN_REFRESH, arg, lParam));
  769. Error:
  770. return hrOK;
  771. }
  772. /*---------------------------------------------------------------------------
  773. Class CDhcpExclusionRange implementation
  774. ---------------------------------------------------------------------------*/
  775. /*!--------------------------------------------------------------------------
  776. Function
  777. Description
  778. Author: EricDav
  779. ---------------------------------------------------------------------------*/
  780. CDhcpExclusionRange::CDhcpExclusionRange
  781. (
  782. ITFSComponentData * pTFSCompData,
  783. DHCP_IP_RANGE * pdhcpIpRange
  784. ) : CDhcpHandler(pTFSCompData)
  785. {
  786. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  787. SetAddr (pdhcpIpRange->StartAddress, TRUE);
  788. SetAddr (pdhcpIpRange->EndAddress, FALSE);
  789. // now do the ending IP address
  790. //
  791. UtilCvtIpAddrToWstr (pdhcpIpRange->EndAddress,
  792. &m_strEndIpAddress);
  793. // and finally the description
  794. //
  795. m_strDescription.LoadString(IDS_EXCLUSION_RANGE_DESCRIPTION);
  796. }
  797. /*!--------------------------------------------------------------------------
  798. CDhcpExclusionRange::InitializeNode
  799. Initializes node specific data
  800. Author: EricDav
  801. ---------------------------------------------------------------------------*/
  802. HRESULT
  803. CDhcpExclusionRange::InitializeNode
  804. (
  805. ITFSNode * pNode
  806. )
  807. {
  808. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  809. CString strTemp;
  810. UtilCvtIpAddrToWstr (QueryAddr(TRUE), &strTemp);
  811. SetDisplayName(strTemp);
  812. // Make the node immediately visible
  813. pNode->SetVisibilityState(TFS_VIS_SHOW);
  814. pNode->SetData(TFS_DATA_COOKIE, (LPARAM) pNode);
  815. pNode->SetData(TFS_DATA_IMAGEINDEX, ICON_IDX_EXCLUSION_RANGE);
  816. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, ICON_IDX_EXCLUSION_RANGE);
  817. pNode->SetData(TFS_DATA_USER, (LPARAM) this);
  818. pNode->SetData(TFS_DATA_TYPE, DHCPSNAP_EXCLUSION_RANGE);
  819. //SetColumnStringIDs(&aColumns[DHCPSNAP_ACTIVE_LEASES][0]);
  820. //SetColumnWidths(&aColumnWidths[DHCPSNAP_ACTIVE_LEASES][0]);
  821. return hrOK;
  822. }
  823. /*!--------------------------------------------------------------------------
  824. CDhcpExclusionRange::OnResultSelect
  825. Description
  826. Author: EricDav
  827. ---------------------------------------------------------------------------*/
  828. HRESULT
  829. CDhcpExclusionRange::OnResultSelect
  830. (
  831. ITFSComponent * pComponent,
  832. LPDATAOBJECT pDataObject,
  833. MMC_COOKIE cookie,
  834. LPARAM arg,
  835. LPARAM lParam
  836. )
  837. {
  838. HRESULT hr = hrOK;
  839. SPIConsoleVerb spConsoleVerb;
  840. SPITFSNode spNode;
  841. CTFSNodeList listSelectedNodes;
  842. BOOL bEnable = FALSE;
  843. BOOL bStates[ARRAYLEN(g_ConsoleVerbs)];
  844. int i;
  845. CORg (pComponent->GetConsoleVerb(&spConsoleVerb));
  846. CORg (m_spNodeMgr->FindNode(cookie, &spNode));
  847. // build the list of selected nodes
  848. hr = BuildSelectedItemList(pComponent, &listSelectedNodes);
  849. // walk the list of selected items. Make sure an allocation range isn't
  850. // selected. If it is, don't enable the delete key
  851. if (listSelectedNodes.GetCount() > 0)
  852. {
  853. BOOL bAllocRangeSelected = FALSE;
  854. POSITION pos;
  855. ITFSNode * pNode;
  856. pos = listSelectedNodes.GetHeadPosition();
  857. while (pos)
  858. {
  859. pNode = listSelectedNodes.GetNext(pos);
  860. if (pNode->GetData(TFS_DATA_TYPE) == DHCPSNAP_ALLOCATION_RANGE)
  861. {
  862. bAllocRangeSelected = TRUE;
  863. break;
  864. }
  865. }
  866. if (!bAllocRangeSelected)
  867. bEnable = TRUE;
  868. }
  869. for (i = 0; i < ARRAYLEN(g_ConsoleVerbs); bStates[i++] = bEnable);
  870. EnableVerbs(spConsoleVerb, g_ConsoleVerbStates[spNode->GetData(TFS_DATA_TYPE)], bStates);
  871. Error:
  872. return hr;
  873. }
  874. /*!--------------------------------------------------------------------------
  875. Function
  876. Description
  877. Author: EricDav
  878. ---------------------------------------------------------------------------*/
  879. STDMETHODIMP_(LPCTSTR)
  880. CDhcpExclusionRange::GetString
  881. (
  882. ITFSComponent * pComponent,
  883. MMC_COOKIE cookie,
  884. int nCol
  885. )
  886. {
  887. switch (nCol)
  888. {
  889. case 0:
  890. return GetDisplayName();
  891. case 1:
  892. return (LPCWSTR)m_strEndIpAddress;
  893. case 2:
  894. return (LPCWSTR)m_strDescription;
  895. }
  896. return NULL;
  897. }
  898. /*!--------------------------------------------------------------------------
  899. CDhcpExclusionRange::OnResultRefresh
  900. Forwards refresh to parent to handle
  901. Author: EricDav
  902. ---------------------------------------------------------------------------*/
  903. HRESULT CDhcpExclusionRange::OnResultRefresh(ITFSComponent * pComponent, LPDATAOBJECT pDataObject, MMC_COOKIE cookie, LPARAM arg, LPARAM lParam)
  904. {
  905. HRESULT hr = hrOK;
  906. SPITFSNode spNode, spParent;
  907. SPITFSResultHandler spParentRH;
  908. m_spNodeMgr->FindNode(cookie, &spNode);
  909. // forward this command to the parent to handle
  910. CORg (spNode->GetParent(&spParent));
  911. CORg (spParent->GetResultHandler(&spParentRH));
  912. CORg (spParentRH->Notify(pComponent, spParent->GetData(TFS_DATA_COOKIE), pDataObject, MMCN_REFRESH, arg, lParam));
  913. Error:
  914. return hrOK;
  915. }
  916. /*---------------------------------------------------------------------------
  917. Class CDhcpBootpEntry implementation
  918. ---------------------------------------------------------------------------*/
  919. /*!--------------------------------------------------------------------------
  920. Constructor
  921. Description
  922. Author: EricDav
  923. ---------------------------------------------------------------------------*/
  924. CDhcpBootpEntry::CDhcpBootpEntry
  925. (
  926. ITFSComponentData * pTFSCompData
  927. ) : CDhcpHandler(pTFSCompData)
  928. {
  929. }
  930. /*!--------------------------------------------------------------------------
  931. CDhcpBootpEntry::InitializeNode
  932. Initializes node specific data
  933. Author: EricDav
  934. ---------------------------------------------------------------------------*/
  935. HRESULT
  936. CDhcpBootpEntry::InitializeNode
  937. (
  938. ITFSNode * pNode
  939. )
  940. {
  941. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  942. SetDisplayName(m_strBootImage);
  943. // Make the node immediately visible
  944. pNode->SetVisibilityState(TFS_VIS_SHOW);
  945. pNode->SetData(TFS_DATA_COOKIE, (LPARAM) pNode);
  946. pNode->SetData(TFS_DATA_IMAGEINDEX, ICON_IDX_BOOTP_ENTRY);
  947. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, ICON_IDX_BOOTP_ENTRY);
  948. pNode->SetData(TFS_DATA_USER, (LPARAM) this);
  949. pNode->SetData(TFS_DATA_TYPE, DHCPSNAP_BOOTP_ENTRY);
  950. //SetColumnStringIDs(&aColumns[DHCPSNAP_ACTIVE_LEASES][0]);
  951. //SetColumnWidths(&aColumnWidths[DHCPSNAP_ACTIVE_LEASES][0]);
  952. return hrOK;
  953. }
  954. /*!--------------------------------------------------------------------------
  955. Function
  956. Description
  957. Author: EricDav
  958. ---------------------------------------------------------------------------*/
  959. STDMETHODIMP
  960. CDhcpBootpEntry::CreatePropertyPages
  961. (
  962. ITFSComponent * pComponent,
  963. MMC_COOKIE cookie,
  964. LPPROPERTYSHEETCALLBACK lpProvider,
  965. LPDATAOBJECT pDataObject,
  966. LONG_PTR handle
  967. )
  968. {
  969. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  970. //
  971. // Create the property page
  972. //
  973. SPITFSNode spNode;
  974. m_spNodeMgr->FindNode(cookie, &spNode);
  975. SPIComponentData spComponentData;
  976. m_spNodeMgr->GetComponentData(&spComponentData);
  977. CBootpProperties * pBootpProp =
  978. new CBootpProperties(spNode, spComponentData, m_spTFSCompData, NULL);
  979. pBootpProp->m_pageGeneral.m_strFileName = QueryFileName();
  980. pBootpProp->m_pageGeneral.m_strFileServer = QueryFileServer();
  981. pBootpProp->m_pageGeneral.m_strImageName = QueryBootImage();
  982. //
  983. // Object gets deleted when the page is destroyed
  984. //
  985. Assert(lpProvider != NULL);
  986. return pBootpProp->CreateModelessSheet(lpProvider, handle);
  987. }
  988. /*---------------------------------------------------------------------------
  989. CDhcpBootpEntry::OnPropertyChange
  990. Description
  991. Author: EricDav
  992. ---------------------------------------------------------------------------*/
  993. HRESULT
  994. CDhcpBootpEntry::OnResultPropertyChange
  995. (
  996. ITFSComponent * pComponent,
  997. LPDATAOBJECT pDataObject,
  998. MMC_COOKIE cookie,
  999. LPARAM arg,
  1000. LPARAM param
  1001. )
  1002. {
  1003. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  1004. SPITFSNode spNode;
  1005. m_spNodeMgr->FindNode(cookie, &spNode);
  1006. CBootpProperties * pBootpProp = reinterpret_cast<CBootpProperties *>(param);
  1007. LONG_PTR changeMask = 0;
  1008. // tell the property page to do whatever now that we are back on the
  1009. // main thread
  1010. pBootpProp->OnPropertyChange(TRUE, &changeMask);
  1011. pBootpProp->AcknowledgeNotify();
  1012. if (changeMask)
  1013. spNode->ChangeNode(changeMask);
  1014. return hrOK;
  1015. }
  1016. /*!--------------------------------------------------------------------------
  1017. CDhcpBootpEntry::GetString
  1018. Description
  1019. Author: EricDav
  1020. ---------------------------------------------------------------------------*/
  1021. STDMETHODIMP_(LPCTSTR)
  1022. CDhcpBootpEntry::GetString
  1023. (
  1024. ITFSComponent * pComponent,
  1025. MMC_COOKIE cookie,
  1026. int nCol
  1027. )
  1028. {
  1029. switch (nCol)
  1030. {
  1031. case 0:
  1032. return QueryBootImage();
  1033. case 1:
  1034. return QueryFileName();
  1035. case 2:
  1036. return QueryFileServer();
  1037. }
  1038. return NULL;
  1039. }
  1040. /*!--------------------------------------------------------------------------
  1041. CDhcpBootpEntry::OnResultRefresh
  1042. Forwards refresh to parent to handle
  1043. Author: EricDav
  1044. ---------------------------------------------------------------------------*/
  1045. HRESULT CDhcpBootpEntry::OnResultRefresh(ITFSComponent * pComponent, LPDATAOBJECT pDataObject, MMC_COOKIE cookie, LPARAM arg, LPARAM lParam)
  1046. {
  1047. HRESULT hr = hrOK;
  1048. SPITFSNode spNode, spParent;
  1049. SPITFSResultHandler spParentRH;
  1050. m_spNodeMgr->FindNode(cookie, &spNode);
  1051. // forward this command to the parent to handle
  1052. CORg (spNode->GetParent(&spParent));
  1053. CORg (spParent->GetResultHandler(&spParentRH));
  1054. CORg (spParentRH->Notify(pComponent, spParent->GetData(TFS_DATA_COOKIE), pDataObject, MMCN_REFRESH, arg, lParam));
  1055. Error:
  1056. return hrOK;
  1057. }
  1058. /*!--------------------------------------------------------------------------
  1059. CDhcpBootpEntry::operator ==
  1060. Description
  1061. Author: EricDav
  1062. ---------------------------------------------------------------------------*/
  1063. BOOL
  1064. CDhcpBootpEntry::operator ==
  1065. (
  1066. CDhcpBootpEntry & bootpEntry
  1067. )
  1068. {
  1069. CString strBootImage, strFileName, strFileServer;
  1070. strBootImage = bootpEntry.QueryBootImage();
  1071. strFileName = bootpEntry.QueryFileName();
  1072. strFileServer = bootpEntry.QueryFileServer();
  1073. if ( (m_strBootImage.CompareNoCase(strBootImage) == 0) &&
  1074. (m_strFileName.CompareNoCase(strFileName) == 0) &&
  1075. (m_strFileServer.CompareNoCase(strFileServer) == 0) )
  1076. {
  1077. return TRUE;
  1078. }
  1079. else
  1080. {
  1081. return FALSE;
  1082. }
  1083. }
  1084. /*!--------------------------------------------------------------------------
  1085. CDhcpBootpEntry::InitData
  1086. Description
  1087. Author: EricDav
  1088. ---------------------------------------------------------------------------*/
  1089. WCHAR *
  1090. CDhcpBootpEntry::InitData
  1091. (
  1092. CONST WCHAR grszwBootTable[], // IN: Group of strings for the boot table
  1093. DWORD dwLength
  1094. )
  1095. {
  1096. ASSERT(grszwBootTable != NULL);
  1097. CONST WCHAR * pszw;
  1098. pszw = PchParseUnicodeString(IN grszwBootTable, dwLength, OUT m_strBootImage);
  1099. ASSERT(*pszw == BOOT_FILE_STRING_DELIMITER_W);
  1100. dwLength -= ((m_strBootImage.GetLength() + 1) * sizeof(TCHAR));
  1101. pszw = PchParseUnicodeString(IN pszw + 1, dwLength, OUT m_strFileServer);
  1102. ASSERT(*pszw == BOOT_FILE_STRING_DELIMITER_W);
  1103. dwLength -= ((m_strFileServer.GetLength() + 1) * sizeof(TCHAR));
  1104. pszw = PchParseUnicodeString(IN pszw + 1, dwLength, OUT m_strFileName);
  1105. ASSERT(*pszw == '\0');
  1106. dwLength -= (m_strFileName.GetLength() * sizeof(TCHAR));
  1107. Assert(dwLength >= 0);
  1108. return const_cast<WCHAR *>(pszw + 1);
  1109. }
  1110. /*!--------------------------------------------------------------------------
  1111. Function
  1112. Compute the length (number of characters) necessary
  1113. to store the BOOTP entry. Additional characters
  1114. are added for extra security.
  1115. Author: EricDav
  1116. ---------------------------------------------------------------------------*/
  1117. int
  1118. CDhcpBootpEntry::CchGetDataLength()
  1119. {
  1120. return 16 + m_strBootImage.GetLength() + m_strFileName.GetLength() + m_strFileServer.GetLength();
  1121. }
  1122. /*!--------------------------------------------------------------------------
  1123. Function
  1124. Write the data into a formatted string.
  1125. Author: EricDav
  1126. ---------------------------------------------------------------------------*/
  1127. WCHAR *
  1128. CDhcpBootpEntry::PchStoreData
  1129. (
  1130. OUT WCHAR szwBuffer[]
  1131. )
  1132. {
  1133. int cch;
  1134. cch = wsprintfW(OUT szwBuffer, L"%s,%s,%s",
  1135. (LPCTSTR)m_strBootImage,
  1136. (LPCTSTR)m_strFileServer,
  1137. (LPCTSTR)m_strFileName);
  1138. ASSERT(cch > 0);
  1139. ASSERT(cch + 4 < CchGetDataLength());
  1140. return const_cast<WCHAR *>(szwBuffer + cch + 1);
  1141. }
  1142. /*---------------------------------------------------------------------------
  1143. Class CDhcpOptionItem implementation
  1144. ---------------------------------------------------------------------------*/
  1145. DEBUG_DECLARE_INSTANCE_COUNTER(CDhcpOptionItem);
  1146. /*!--------------------------------------------------------------------------
  1147. Function
  1148. Description
  1149. Author: EricDav
  1150. ---------------------------------------------------------------------------*/
  1151. CDhcpOptionItem::CDhcpOptionItem
  1152. (
  1153. ITFSComponentData * pTFSCompData,
  1154. LPDHCP_OPTION_VALUE pOptionValue,
  1155. int nOptionImage
  1156. ) : CDhcpOptionValue(*pOptionValue),
  1157. CDhcpHandler(pTFSCompData)
  1158. {
  1159. DEBUG_INCREMENT_INSTANCE_COUNTER(CDhcpOptionItem);
  1160. //
  1161. // initialize this node
  1162. //
  1163. m_nOptionImage = nOptionImage;
  1164. m_dhcpOptionId = pOptionValue->OptionID;
  1165. // assume non-vendor option
  1166. SetVendor(NULL);
  1167. m_verbDefault = MMC_VERB_PROPERTIES;
  1168. }
  1169. /*!--------------------------------------------------------------------------
  1170. Function
  1171. Description
  1172. Author: EricDav
  1173. ---------------------------------------------------------------------------*/
  1174. CDhcpOptionItem::CDhcpOptionItem
  1175. (
  1176. ITFSComponentData * pTFSCompData,
  1177. CDhcpOption * pOption,
  1178. int nOptionImage
  1179. ) : CDhcpOptionValue(pOption->QueryValue()),
  1180. CDhcpHandler(pTFSCompData)
  1181. {
  1182. DEBUG_INCREMENT_INSTANCE_COUNTER(CDhcpOptionItem);
  1183. //
  1184. // initialize this node
  1185. //
  1186. m_nOptionImage = nOptionImage;
  1187. m_dhcpOptionId = pOption->QueryId();
  1188. // assume non-vendor option
  1189. if (pOption->IsVendor())
  1190. SetVendor(pOption->GetVendor());
  1191. else
  1192. SetVendor(NULL);
  1193. SetClassName(pOption->GetClassName());
  1194. m_verbDefault = MMC_VERB_PROPERTIES;
  1195. }
  1196. CDhcpOptionItem::~CDhcpOptionItem()
  1197. {
  1198. DEBUG_DECREMENT_INSTANCE_COUNTER(CDhcpOptionItem);
  1199. }
  1200. /*!--------------------------------------------------------------------------
  1201. CDhcpOptionItem::InitializeNode
  1202. Initializes node specific data
  1203. Author: EricDav
  1204. ---------------------------------------------------------------------------*/
  1205. HRESULT
  1206. CDhcpOptionItem::InitializeNode
  1207. (
  1208. ITFSNode * pNode
  1209. )
  1210. {
  1211. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  1212. // Make the node immediately visible
  1213. pNode->SetVisibilityState(TFS_VIS_SHOW);
  1214. pNode->SetData(TFS_DATA_COOKIE, (LPARAM) pNode);
  1215. pNode->SetData(TFS_DATA_IMAGEINDEX, m_nOptionImage);
  1216. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, m_nOptionImage);
  1217. pNode->SetData(TFS_DATA_USER, (LPARAM) this);
  1218. pNode->SetData(TFS_DATA_TYPE, DHCPSNAP_OPTION_ITEM);
  1219. //SetColumnStringIDs(&aColumns[DHCPSNAP_ACTIVE_LEASES][0]);
  1220. //SetColumnWidths(&aColumnWidths[DHCPSNAP_ACTIVE_LEASES][0]);
  1221. return hrOK;
  1222. }
  1223. /*!--------------------------------------------------------------------------
  1224. Function
  1225. Description
  1226. Author: EricDav
  1227. ---------------------------------------------------------------------------*/
  1228. STDMETHODIMP_(LPCTSTR)
  1229. CDhcpOptionItem::GetString
  1230. (
  1231. ITFSComponent * pComponent,
  1232. MMC_COOKIE cookie,
  1233. int nCol
  1234. )
  1235. {
  1236. SPITFSNode spNode;
  1237. m_spNodeMgr->FindNode(cookie, &spNode);
  1238. CDhcpOption * pOptionInfo = FindOptionDefinition(pComponent, spNode);
  1239. switch (nCol)
  1240. {
  1241. case 0:
  1242. {
  1243. if (pOptionInfo)
  1244. pOptionInfo->QueryDisplayName(m_strName);
  1245. else
  1246. m_strName.LoadString(IDS_UNKNOWN);
  1247. return m_strName;
  1248. }
  1249. case 1:
  1250. return m_strVendorDisplay;
  1251. case 2:
  1252. {
  1253. if (pOptionInfo)
  1254. {
  1255. // special case the CSR option
  1256. BOOL fRouteArray = (
  1257. !pOptionInfo->IsClassOption() &&
  1258. (DHCP_OPTION_ID_CSR == pOptionInfo->QueryId()) &&
  1259. DhcpUnaryElementTypeOption ==
  1260. pOptionInfo->QueryOptType() &&
  1261. DhcpBinaryDataOption == pOptionInfo->QueryDataType()
  1262. );
  1263. if( !fRouteArray )
  1264. QueryDisplayString(m_strValue, FALSE);
  1265. else
  1266. QueryRouteArrayDisplayString(m_strValue);
  1267. }
  1268. else
  1269. m_strName.LoadString(IDS_UNKNOWN);
  1270. return m_strValue;
  1271. }
  1272. case 3:
  1273. if (IsClassOption())
  1274. return m_strClassName;
  1275. else
  1276. {
  1277. if (g_szClientTypeNone.IsEmpty())
  1278. g_szClientTypeNone.LoadString(IDS_NONE);
  1279. return g_szClientTypeNone;
  1280. }
  1281. }
  1282. return NULL;
  1283. }
  1284. /*!--------------------------------------------------------------------------
  1285. Function
  1286. Description
  1287. Author: EricDav
  1288. ---------------------------------------------------------------------------*/
  1289. STDMETHODIMP
  1290. CDhcpOptionItem::CreatePropertyPages
  1291. (
  1292. ITFSComponent * pComponent,
  1293. MMC_COOKIE cookie,
  1294. LPPROPERTYSHEETCALLBACK lpProvider,
  1295. LPDATAOBJECT pDataObject,
  1296. LONG_PTR handle
  1297. )
  1298. {
  1299. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1300. //
  1301. // Create the property page
  1302. //
  1303. CPropertyPageHolderBase * pPropSheet;
  1304. SPITFSNode spSelectedNode, spNode, spOptCfgNode, spServerNode;
  1305. CString strOptCfgTitle, strOptType;
  1306. COptionValueEnum * pOptionValueEnum = NULL;
  1307. m_spNodeMgr->FindNode(cookie, &spNode);
  1308. SPIComponentData spComponentData;
  1309. m_spNodeMgr->GetComponentData(&spComponentData);
  1310. pComponent->GetSelectedNode(&spSelectedNode);
  1311. switch (spSelectedNode->GetData(TFS_DATA_TYPE))
  1312. {
  1313. case DHCPSNAP_GLOBAL_OPTIONS:
  1314. {
  1315. SPITFSNode spGlobalOptions;
  1316. // get some node information
  1317. spNode->GetParent(&spGlobalOptions);
  1318. spGlobalOptions->GetParent(&spServerNode);
  1319. CDhcpGlobalOptions * pGlobalOptions = GETHANDLER(CDhcpGlobalOptions, spGlobalOptions);
  1320. if (pGlobalOptions->HasPropSheetsOpen())
  1321. {
  1322. pGlobalOptions->GetOpenPropSheet(0, &pPropSheet);
  1323. pPropSheet->SetActiveWindow();
  1324. ::PostMessage(PropSheet_GetCurrentPageHwnd(pPropSheet->GetSheetWindow()), WM_SELECTOPTION, (WPARAM) this, 0);
  1325. return E_FAIL;
  1326. }
  1327. // get some context info
  1328. pOptionValueEnum = pGlobalOptions->GetServerObject(spGlobalOptions)->GetOptionValueEnum();
  1329. spOptCfgNode.Set(spGlobalOptions);
  1330. // setup the page title
  1331. strOptType.LoadString(IDS_CONFIGURE_OPTIONS_GLOBAL);
  1332. AfxFormatString1(strOptCfgTitle, IDS_CONFIGURE_OPTIONS_TITLE, strOptType);
  1333. }
  1334. break;
  1335. case DHCPSNAP_SCOPE_OPTIONS:
  1336. {
  1337. // only the option type of this node can be configured here...
  1338. if (spNode->GetData(TFS_DATA_IMAGEINDEX) != ICON_IDX_SCOPE_OPTION_LEAF)
  1339. {
  1340. AfxMessageBox(IDS_CONNOT_CONFIGURE_OPTION_SCOPE);
  1341. return E_FAIL;
  1342. }
  1343. SPITFSNode spScopeOptions;
  1344. spNode->GetParent(&spScopeOptions);
  1345. // check to see if the page is already open, if so just activate it and
  1346. // set the current option to this one.
  1347. CDhcpScopeOptions * pScopeOptions = GETHANDLER(CDhcpScopeOptions, spScopeOptions);
  1348. spServerNode = pScopeOptions->GetServerNode(spScopeOptions);
  1349. if (pScopeOptions->HasPropSheetsOpen())
  1350. {
  1351. // found it, activate
  1352. pScopeOptions->GetOpenPropSheet(0, &pPropSheet);
  1353. pPropSheet->SetActiveWindow();
  1354. ::PostMessage(PropSheet_GetCurrentPageHwnd(pPropSheet->GetSheetWindow()), WM_SELECTOPTION, (WPARAM) this, 0);
  1355. return E_FAIL;
  1356. }
  1357. // prepare to create a new page
  1358. pOptionValueEnum = pScopeOptions->GetScopeObject(spScopeOptions)->GetOptionValueEnum();
  1359. spOptCfgNode.Set(spScopeOptions);
  1360. strOptType.LoadString(IDS_CONFIGURE_OPTIONS_SCOPE);
  1361. AfxFormatString1(strOptCfgTitle, IDS_CONFIGURE_OPTIONS_TITLE, strOptType);
  1362. }
  1363. break;
  1364. case DHCPSNAP_RESERVATION_CLIENT:
  1365. {
  1366. // only the option type of this node can be configured here...
  1367. if (spNode->GetData(TFS_DATA_IMAGEINDEX) != ICON_IDX_CLIENT_OPTION_LEAF)
  1368. {
  1369. AfxMessageBox(IDS_CONNOT_CONFIGURE_OPTION_RES);
  1370. return E_FAIL;
  1371. }
  1372. SPITFSNode spResClient;
  1373. spNode->GetParent(&spResClient);
  1374. CDhcpReservationClient * pResClient = GETHANDLER(CDhcpReservationClient, spResClient);
  1375. spServerNode = pResClient->GetServerNode(spResClient, TRUE);
  1376. strOptType.LoadString(IDS_CONFIGURE_OPTIONS_CLIENT);
  1377. AfxFormatString1(strOptCfgTitle, IDS_CONFIGURE_OPTIONS_TITLE, strOptType);
  1378. // search the open prop pages to see if the option config page is up
  1379. // since the option config page is technically a property sheet for the node.
  1380. for (int i = 0; i < pResClient->HasPropSheetsOpen(); i++)
  1381. {
  1382. pResClient->GetOpenPropSheet(i, &pPropSheet);
  1383. HWND hwnd = pPropSheet->GetSheetWindow();
  1384. CString strTitle;
  1385. ::GetWindowText(hwnd, strTitle.GetBuffer(256), 256);
  1386. strTitle.ReleaseBuffer();
  1387. if (strTitle == strOptCfgTitle)
  1388. {
  1389. // found it, activate
  1390. pPropSheet->SetActiveWindow();
  1391. ::PostMessage(PropSheet_GetCurrentPageHwnd(pPropSheet->GetSheetWindow()), WM_SELECTOPTION, (WPARAM) this, 0);
  1392. return E_FAIL;
  1393. }
  1394. }
  1395. // no page up, get ready to create one
  1396. pOptionValueEnum = pResClient->GetOptionValueEnum();
  1397. spOptCfgNode.Set(spResClient);
  1398. }
  1399. break;
  1400. }
  1401. COptionsConfig * pOptionsConfig =
  1402. new COptionsConfig(spOptCfgNode, spServerNode, spComponentData, m_spTFSCompData, pOptionValueEnum, strOptCfgTitle, this);
  1403. //
  1404. // Object gets deleted when the page is destroyed
  1405. //
  1406. Assert(lpProvider != NULL);
  1407. return pOptionsConfig->CreateModelessSheet(lpProvider, handle);
  1408. }
  1409. /*!--------------------------------------------------------------------------
  1410. Function
  1411. Description
  1412. Author: EricDav
  1413. ---------------------------------------------------------------------------*/
  1414. CDhcpOption *
  1415. CDhcpOptionItem::FindOptionDefinition
  1416. (
  1417. ITFSComponent * pComponent,
  1418. ITFSNode * pNode
  1419. )
  1420. {
  1421. SPITFSNode spSelectedNode;
  1422. CDhcpServer * pServer = NULL;
  1423. pComponent->GetSelectedNode(&spSelectedNode);
  1424. switch (spSelectedNode->GetData(TFS_DATA_TYPE))
  1425. {
  1426. case DHCPSNAP_GLOBAL_OPTIONS:
  1427. {
  1428. SPITFSNode spServer;
  1429. spSelectedNode->GetParent(&spServer);
  1430. pServer = GETHANDLER(CDhcpServer, spServer);
  1431. }
  1432. break;
  1433. case DHCPSNAP_SCOPE_OPTIONS:
  1434. {
  1435. CDhcpScopeOptions * pScopeOptions = GETHANDLER(CDhcpScopeOptions, spSelectedNode);
  1436. CDhcpScope * pScopeObject = pScopeOptions->GetScopeObject(spSelectedNode);
  1437. pServer = pScopeObject->GetServerObject();
  1438. }
  1439. break;
  1440. case DHCPSNAP_RESERVATION_CLIENT:
  1441. {
  1442. CDhcpReservationClient * pResClient = GETHANDLER(CDhcpReservationClient, spSelectedNode);
  1443. CDhcpScope * pScopeObject = pResClient->GetScopeObject(spSelectedNode, TRUE);
  1444. pServer = pScopeObject->GetServerObject();
  1445. }
  1446. break;
  1447. default:
  1448. //ASSERT(FALSE);
  1449. break;
  1450. }
  1451. if (pServer)
  1452. {
  1453. return pServer->FindOption(m_dhcpOptionId, GetVendor());
  1454. }
  1455. else
  1456. {
  1457. return NULL;
  1458. }
  1459. }
  1460. void
  1461. CDhcpOptionItem::SetVendor
  1462. (
  1463. LPCTSTR pszVendor
  1464. )
  1465. {
  1466. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  1467. if (pszVendor == NULL)
  1468. m_strVendorDisplay.LoadString (IDS_VENDOR_STANDARD);
  1469. else
  1470. m_strVendorDisplay = pszVendor;
  1471. m_strVendor = pszVendor;
  1472. }
  1473. /*!--------------------------------------------------------------------------
  1474. CDhcpOptionItem::OnResultRefresh
  1475. Forwards refresh to parent to handle
  1476. Author: EricDav
  1477. ---------------------------------------------------------------------------*/
  1478. HRESULT CDhcpOptionItem::OnResultRefresh(ITFSComponent * pComponent, LPDATAOBJECT pDataObject, MMC_COOKIE cookie, LPARAM arg, LPARAM lParam)
  1479. {
  1480. HRESULT hr = hrOK;
  1481. SPITFSNode spNode, spParent;
  1482. SPITFSResultHandler spParentRH;
  1483. m_spNodeMgr->FindNode(cookie, &spNode);
  1484. // forward this command to the parent to handle
  1485. CORg (spNode->GetParent(&spParent));
  1486. CORg (spParent->GetResultHandler(&spParentRH));
  1487. CORg (spParentRH->Notify(pComponent, spParent->GetData(TFS_DATA_COOKIE), pDataObject, MMCN_REFRESH, arg, lParam));
  1488. Error:
  1489. return hrOK;
  1490. }
  1491. /*---------------------------------------------------------------------------
  1492. Class CDhcpMCastLease implementation
  1493. ---------------------------------------------------------------------------*/
  1494. /*!--------------------------------------------------------------------------
  1495. Function
  1496. Description
  1497. Author: EricDav
  1498. ---------------------------------------------------------------------------*/
  1499. CDhcpMCastLease::CDhcpMCastLease
  1500. (
  1501. ITFSComponentData * pTFSCompData
  1502. ) : CDhcpHandler(pTFSCompData)
  1503. {
  1504. //m_verbDefault = MMC_VERB_PROPERTIES;
  1505. m_dwTypeFlags = 0;
  1506. }
  1507. /*!--------------------------------------------------------------------------
  1508. CDhcpMCastLease::InitializeNode
  1509. Initializes node specific data
  1510. Author: EricDav
  1511. ---------------------------------------------------------------------------*/
  1512. HRESULT
  1513. CDhcpMCastLease::InitializeNode
  1514. (
  1515. ITFSNode * pNode
  1516. )
  1517. {
  1518. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  1519. int nImageIndex = ICON_IDX_CLIENT;
  1520. // Make the node immediately visible
  1521. pNode->SetVisibilityState(TFS_VIS_SHOW);
  1522. pNode->SetData(TFS_DATA_COOKIE, (LPARAM) pNode);
  1523. pNode->SetData(TFS_DATA_USER, (LPARAM) this);
  1524. pNode->SetData(TFS_DATA_TYPE, DHCPSNAP_MCAST_LEASE);
  1525. if (m_dwTypeFlags & TYPE_FLAG_GHOST)
  1526. {
  1527. nImageIndex = ICON_IDX_CLIENT_EXPIRED;
  1528. }
  1529. pNode->SetData(TFS_DATA_IMAGEINDEX, nImageIndex);
  1530. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, nImageIndex);
  1531. return hrOK;
  1532. }
  1533. /*!--------------------------------------------------------------------------
  1534. CDhcpMCastLease::InitMCastInfo
  1535. Initializes node specific data
  1536. Author: EricDav
  1537. ---------------------------------------------------------------------------*/
  1538. HRESULT
  1539. CDhcpMCastLease::InitMCastInfo
  1540. (
  1541. LPDHCP_MCLIENT_INFO pMClientInfo
  1542. )
  1543. {
  1544. HRESULT hr = hrOK;
  1545. BOOL fInfinite = FALSE;
  1546. m_dhcpClientIpAddress = pMClientInfo->ClientIpAddress;
  1547. UtilCvtIpAddrToWstr(m_dhcpClientIpAddress, &m_strIp);
  1548. m_strName = pMClientInfo->ClientName;
  1549. if ( (pMClientInfo->ClientLeaseEnds.dwLowDateTime == DHCP_DATE_TIME_INFINIT_LOW) &&
  1550. (pMClientInfo->ClientLeaseEnds.dwHighDateTime == DHCP_DATE_TIME_INFINIT_HIGH) )
  1551. {
  1552. fInfinite = TRUE;
  1553. }
  1554. CTime timeStart( (FILETIME&) pMClientInfo->ClientLeaseStarts );
  1555. FILETIME ft = {0};
  1556. if (!fInfinite)
  1557. {
  1558. ft.dwLowDateTime = pMClientInfo->ClientLeaseEnds.dwLowDateTime;
  1559. ft.dwHighDateTime = pMClientInfo->ClientLeaseEnds.dwHighDateTime;
  1560. }
  1561. CTime timeStop( ft );
  1562. m_timeStart = timeStart;
  1563. FormatDateTime(m_strLeaseStart, (FILETIME *) &pMClientInfo->ClientLeaseStarts);
  1564. m_timeStop = timeStop;
  1565. if (!fInfinite)
  1566. {
  1567. FormatDateTime(m_strLeaseStop, (FILETIME *) &pMClientInfo->ClientLeaseEnds);
  1568. }
  1569. else
  1570. {
  1571. m_strLeaseStop.LoadString(IDS_INFO_TIME_INFINITE);
  1572. }
  1573. // build the UID string
  1574. if (pMClientInfo->ClientId.DataLength >= 3 &&
  1575. pMClientInfo->ClientId.Data[0] == 'R' &&
  1576. pMClientInfo->ClientId.Data[1] == 'A' &&
  1577. pMClientInfo->ClientId.Data[2] == 'S')
  1578. {
  1579. m_strUID = RAS_UID;
  1580. }
  1581. else
  1582. {
  1583. // build the client UID string
  1584. CByteArray baUID;
  1585. for (DWORD i = 0; i < pMClientInfo->ClientId.DataLength; i++)
  1586. {
  1587. baUID.Add(pMClientInfo->ClientId.Data[i]);
  1588. }
  1589. UtilCvtByteArrayToString(baUID, m_strUID);
  1590. }
  1591. // check to see if this lease has expired
  1592. SYSTEMTIME st;
  1593. GetLocalTime(&st);
  1594. CTime systemTime(st);
  1595. if ( (systemTime > timeStop) &&
  1596. (!fInfinite) )
  1597. {
  1598. Trace2("CDhcpMCastLease::InitMCastInfo - expired lease SysTime %s, StopTime %s\n", systemTime.Format(_T("%#c")), m_strLeaseStop);
  1599. m_dwTypeFlags |= TYPE_FLAG_GHOST;
  1600. }
  1601. return hr;
  1602. }
  1603. /*!--------------------------------------------------------------------------
  1604. CDhcpMCastLease::GetString
  1605. Description
  1606. Author: EricDav
  1607. ---------------------------------------------------------------------------*/
  1608. STDMETHODIMP_(LPCTSTR)
  1609. CDhcpMCastLease::GetString
  1610. (
  1611. ITFSComponent * pComponent,
  1612. MMC_COOKIE cookie,
  1613. int nCol
  1614. )
  1615. {
  1616. SPITFSNode spNode;
  1617. m_spNodeMgr->FindNode(cookie, &spNode);
  1618. switch (nCol)
  1619. {
  1620. case 0:
  1621. return m_strIp;
  1622. case 1:
  1623. return m_strName;
  1624. case 2:
  1625. return m_strLeaseStart;
  1626. case 3:
  1627. return m_strLeaseStop;
  1628. case 4:
  1629. return m_strUID;
  1630. }
  1631. return NULL;
  1632. }
  1633. /*!--------------------------------------------------------------------------
  1634. CDhcpMCastLease::OnResultRefresh
  1635. Forwards refresh to parent to handle
  1636. Author: EricDav
  1637. ---------------------------------------------------------------------------*/
  1638. HRESULT CDhcpMCastLease::OnResultRefresh(ITFSComponent * pComponent, LPDATAOBJECT pDataObject, MMC_COOKIE cookie, LPARAM arg, LPARAM lParam)
  1639. {
  1640. HRESULT hr = hrOK;
  1641. SPITFSNode spNode, spParent;
  1642. SPITFSResultHandler spParentRH;
  1643. m_spNodeMgr->FindNode(cookie, &spNode);
  1644. // forward this command to the parent to handle
  1645. CORg (spNode->GetParent(&spParent));
  1646. CORg (spParent->GetResultHandler(&spParentRH));
  1647. CORg (spParentRH->Notify(pComponent, spParent->GetData(TFS_DATA_COOKIE), pDataObject, MMCN_REFRESH, arg, lParam));
  1648. Error:
  1649. return hrOK;
  1650. }