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.

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