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.

3038 lines
72 KiB

  1. /******************************************************************
  2. CIPRouteTable.CPP -- WMI provider class implementation
  3. Generated by Microsoft WMI Code Generation Engine
  4. TO DO: - See individual function headers
  5. - When linking, make sure you link to framedyd.lib &
  6. msvcrtd.lib (debug) or framedyn.lib & msvcrt.lib (retail).
  7. Description:
  8. ******************************************************************/
  9. #include "precomp.h"
  10. #include <ntddtcp.h>
  11. #include <ipinfo.h>
  12. #include <tdiinfo.h>
  13. #include <winsock2.h>
  14. #include <provexpt.h>
  15. #include <provtempl.h>
  16. #include <provmt.h>
  17. #include <typeinfo.h>
  18. #include <provcont.h>
  19. #include <provval.h>
  20. #include <provtype.h>
  21. #include <provtree.h>
  22. #include <provdnf.h>
  23. #include "CIPRouteTable.h"
  24. #include "CIpRouteEvent.h"
  25. // TO DO: Replace "NameSpace" with the appropriate namespace for your
  26. // provider instance. For instance: "root\\default or "root\\cimv2".
  27. //===================================================================
  28. CIPRouteTable MyCIPRouteTableSet (
  29. PROVIDER_NAME_CIPROUTETABLE ,
  30. L"root\\cimv2"
  31. ) ;
  32. // Property names
  33. //===============
  34. const WCHAR *RouteAge = L"Age" ;
  35. const WCHAR *RouteDestination = L"Destination" ;
  36. const WCHAR *RouteInterfaceIndex = L"InterfaceIndex" ;
  37. const WCHAR *RouteInformation = L"Information" ;
  38. const WCHAR *RouteMask = L"Mask" ;
  39. const WCHAR *RouteMetric1 = L"Metric1" ;
  40. const WCHAR *RouteMetric2 = L"Metric2" ;
  41. const WCHAR *RouteMetric3 = L"Metric3" ;
  42. const WCHAR *RouteMetric4 = L"Metric4" ;
  43. const WCHAR *RouteMetric5 = L"Metric5" ;
  44. const WCHAR *RouteNextHop = L"NextHop" ;
  45. const WCHAR *RouteProtocol = L"Protocol" ;
  46. const WCHAR *RouteType = L"Type" ;
  47. // Inherited properties populated
  48. //===============================
  49. const WCHAR *RouteName = L"Name" ;
  50. const WCHAR *RouteCaption = L"Caption" ;
  51. const WCHAR *RouteDescription = L"Description" ;
  52. #define SYSTEM_PROPERTY_CLASS L"__CLASS"
  53. #define SYSTEM_PROPERTY_SUPERCLASS L"__SUPERCLASS"
  54. #define SYSTEM_PROPERTY_DYNASTY L"__DYNASTY"
  55. #define SYSTEM_PROPERTY_DERIVATION L"__DERIVATION"
  56. #define SYSTEM_PROPERTY_GENUS L"__GENUS"
  57. #define SYSTEM_PROPERTY_NAMESPACE L"__NAMESPACE"
  58. #define SYSTEM_PROPERTY_PROPERTY_COUNT L"__PROPERTY_COUNT"
  59. #define SYSTEM_PROPERTY_SERVER L"__SERVER"
  60. #define SYSTEM_PROPERTY_RELPATH L"__RELPATH"
  61. #define SYSTEM_PROPERTY_PATH L"__PATH"
  62. #define ROUTE_DESCRIPTION_SEP L" - "
  63. _COM_SMARTPTR_TYPEDEF(IWbemClassObject, __uuidof(IWbemClassObject));
  64. class CDeleteString
  65. {
  66. private:
  67. wchar_t * m_ptr;
  68. CDeleteString ( const CDeleteString& p ) ;
  69. CDeleteString & operator= ( const CDeleteString & p ) ;
  70. public:
  71. CDeleteString ( wchar_t *ptr = NULL ) : m_ptr( ptr )
  72. {
  73. }
  74. ~CDeleteString ( )
  75. {
  76. if ( m_ptr )
  77. {
  78. delete [] m_ptr ;
  79. m_ptr = NULL ;
  80. }
  81. }
  82. operator LPCWSTR ( ) const { return ( (LPCWSTR) m_ptr ) ; }
  83. };
  84. /*****************************************************************************
  85. *
  86. * FUNCTION : CIPRouteTable::CIPRouteTable
  87. *
  88. * DESCRIPTION : Constructor
  89. *
  90. * INPUTS : none
  91. *
  92. * RETURNS : nothing
  93. *
  94. * COMMENTS : Calls the Provider constructor.
  95. *
  96. *****************************************************************************/
  97. CIPRouteTable :: CIPRouteTable (
  98. LPCWSTR lpwszName,
  99. LPCWSTR lpwszNameSpace
  100. ) : Provider ( lpwszName , lpwszNameSpace ), m_ClassCInst( NULL )
  101. {
  102. InitializeCriticalSection( &m_CS ) ;
  103. }
  104. /*****************************************************************************
  105. *
  106. * FUNCTION : CIPRouteTable::~CIPRouteTable
  107. *
  108. * DESCRIPTION : Destructor
  109. *
  110. * INPUTS : none
  111. *
  112. * RETURNS : nothing
  113. *
  114. * COMMENTS :
  115. *
  116. *****************************************************************************/
  117. CIPRouteTable :: ~CIPRouteTable ()
  118. {
  119. DeleteCriticalSection( &m_CS ) ;
  120. if ( m_ClassCInst != NULL )
  121. {
  122. m_ClassCInst->Release();
  123. }
  124. }
  125. /*****************************************************************************
  126. *
  127. * FUNCTION : CIPRouteTable::EnumerateInstances
  128. *
  129. * DESCRIPTION : Returns all the instances of this class.
  130. *
  131. * INPUTS : A pointer to the MethodContext for communication with WinMgmt.
  132. * A long that contains the flags described in
  133. * IWbemServices::CreateInstanceEnumAsync. Note that the following
  134. * flags are handled by (and filtered out by) WinMgmt:
  135. * WBEM_FLAG_DEEP
  136. * WBEM_FLAG_SHALLOW
  137. * WBEM_FLAG_RETURN_IMMEDIATELY
  138. * WBEM_FLAG_FORWARD_ONLY
  139. * WBEM_FLAG_BIDIRECTIONAL
  140. *
  141. * RETURNS : WBEM_S_NO_ERROR if successful
  142. *
  143. * COMMENTS : TO DO: All instances on the machine should be returned here and
  144. * all properties that this class knows how to populate must
  145. * be filled in. If there are no instances, return
  146. * WBEM_S_NO_ERROR. It is not an error to have no instances.
  147. * If you are implementing a 'method only' provider, you
  148. * should remove this method.
  149. *
  150. *****************************************************************************/
  151. HRESULT CIPRouteTable :: RangeQuery (
  152. MethodContext *pMethodContext,
  153. PartitionSet &a_PartitionSet ,
  154. long lFlags
  155. )
  156. {
  157. HRESULT hRes = WBEM_S_NO_ERROR ;
  158. SmartCloseNtHandle t_StackHandle ;
  159. SmartCloseNtHandle t_CompleteEventHandle ;
  160. NTSTATUS t_NtStatus = OpenQuerySource (
  161. t_StackHandle ,
  162. t_CompleteEventHandle
  163. ) ;
  164. if ( NT_SUCCESS ( t_NtStatus ) )
  165. {
  166. ulong t_RouteTableSize = 0 ;
  167. IPRouteEntry *t_InformationBlock = NULL ;
  168. t_NtStatus = QueryInformation_IpRouteInfo (
  169. t_StackHandle ,
  170. t_CompleteEventHandle ,
  171. t_RouteTableSize ,
  172. t_InformationBlock
  173. ) ;
  174. if ( NT_SUCCESS ( t_NtStatus ) )
  175. {
  176. try
  177. {
  178. ULONG t_PartitionCount = a_PartitionSet.GetPartitionCount () ;
  179. for ( ulong t_RouteIndex = 0 ; t_RouteIndex < t_RouteTableSize ; t_RouteIndex ++ )
  180. {
  181. IPRouteEntry &t_Entry = t_InformationBlock [ t_RouteIndex ] ;
  182. ProvIpAddressType t_DestinationIpAddress ( ntohl ( t_Entry.ire_dest ) ) ;
  183. CDeleteString t_DestinationIpAddressString(t_DestinationIpAddress.GetStringValue ());
  184. BOOL t_Create = FALSE ;
  185. for ( ulong t_Partition = 0 ; t_Partition < t_PartitionCount ; t_Partition ++ )
  186. {
  187. PartitionSet *t_PropertyPartition = a_PartitionSet.GetPartition ( t_Partition ) ;
  188. WmiStringRangeNode *t_Node = ( WmiStringRangeNode * ) t_PropertyPartition->GetRange () ;
  189. if ( t_Node->InfiniteLowerBound () )
  190. {
  191. if ( t_Node->InfiniteUpperBound () )
  192. {
  193. t_Create = TRUE ;
  194. }
  195. else
  196. {
  197. int t_Compare = wcscmp ( t_DestinationIpAddressString , t_Node->UpperBound () ) ;
  198. if ( t_Node->ClosedUpperBound () )
  199. {
  200. if ( t_Compare <= 0 )
  201. {
  202. t_Create = TRUE ;
  203. }
  204. }
  205. else
  206. {
  207. if ( t_Compare < 0 )
  208. {
  209. t_Create = TRUE ;
  210. }
  211. }
  212. }
  213. }
  214. else
  215. {
  216. int t_Compare = wcscmp ( t_DestinationIpAddressString , t_Node->LowerBound () ) ;
  217. if ( t_Node->ClosedLowerBound () )
  218. {
  219. if ( t_Compare >= 0 )
  220. {
  221. if ( t_Node->InfiniteUpperBound () )
  222. {
  223. t_Create = TRUE ;
  224. }
  225. else
  226. {
  227. t_Compare = wcscmp ( t_DestinationIpAddressString , t_Node->UpperBound () ) ;
  228. if ( t_Node->ClosedUpperBound () )
  229. {
  230. if ( t_Compare <= 0 )
  231. {
  232. t_Create = TRUE ;
  233. }
  234. }
  235. else
  236. {
  237. if ( t_Compare < 0 )
  238. {
  239. t_Create = TRUE ;
  240. }
  241. }
  242. }
  243. }
  244. }
  245. else
  246. {
  247. if ( t_Compare > 0 )
  248. {
  249. if ( t_Node->InfiniteUpperBound () )
  250. {
  251. t_Create = TRUE ;
  252. }
  253. else
  254. {
  255. t_Compare = wcscmp ( t_DestinationIpAddressString , t_Node->UpperBound () ) ;
  256. if ( t_Node->ClosedUpperBound () )
  257. {
  258. if ( t_Compare <= 0 )
  259. {
  260. t_Create = TRUE ;
  261. }
  262. }
  263. else
  264. {
  265. if ( t_Compare < 0 )
  266. {
  267. t_Create = TRUE ;
  268. }
  269. }
  270. }
  271. }
  272. }
  273. }
  274. }
  275. if( t_Create )
  276. {
  277. /*
  278. * Create a new instance based on the passed-in MethodContext.
  279. * Note that CreateNewInstance may throw, but will never return NULL.
  280. */
  281. CInstance *pInstance = CreateNewInstance ( pMethodContext ) ;
  282. /*
  283. * Set the keys for the instance
  284. */
  285. pInstance->SetCHString ( RouteDestination, t_DestinationIpAddressString ) ;
  286. ProvIpAddressType t_NextHopIpAddress ( ntohl ( t_Entry.ire_nexthop ) ) ;
  287. CDeleteString t_NextHopIpAddressString (t_NextHopIpAddress.GetStringValue () ) ;
  288. pInstance->SetCHString( RouteNextHop, t_NextHopIpAddressString ) ;
  289. /*
  290. * Initialize the instance
  291. */
  292. ProvIpAddressType t_DestinationMaskIpAddress ( ntohl ( t_Entry.ire_mask ) ) ;
  293. CDeleteString t_DestinationMaskIpAddressString (t_DestinationMaskIpAddress.GetStringValue () ) ;
  294. pInstance->SetCHString( RouteMask, t_DestinationMaskIpAddressString ) ;
  295. pInstance->SetDWORD ( RouteAge, t_Entry.ire_age ) ;
  296. pInstance->SetDWORD ( RouteInterfaceIndex, t_Entry.ire_index ) ;
  297. pInstance->SetCHString ( RouteInformation, "0.0" ) ;
  298. pInstance->SetDWORD ( RouteProtocol, t_Entry.ire_proto ) ;
  299. pInstance->SetDWORD ( RouteType, t_Entry.ire_type ) ;
  300. pInstance->SetDWORD ( RouteMetric1, t_Entry.ire_metric1 ) ;
  301. pInstance->SetDWORD ( RouteMetric2, t_Entry.ire_metric2 ) ;
  302. pInstance->SetDWORD ( RouteMetric3, t_Entry.ire_metric3 ) ;
  303. pInstance->SetDWORD ( RouteMetric4, t_Entry.ire_metric4 ) ;
  304. pInstance->SetDWORD ( RouteMetric5, t_Entry.ire_metric5 ) ;
  305. //set the inherited properties that are sensible
  306. SetInheritedProperties (
  307. t_DestinationIpAddressString ,
  308. t_NextHopIpAddressString ,
  309. t_DestinationMaskIpAddressString ,
  310. *pInstance
  311. ) ;
  312. /*
  313. * Forward the instance onto the core wmi service
  314. */
  315. hRes = Commit ( pInstance ) ;
  316. }
  317. }
  318. }
  319. catch(...)
  320. {
  321. HeapFree ( GetProcessHeap () , 0, t_InformationBlock ) ;
  322. throw ;
  323. }
  324. HeapFree ( GetProcessHeap () , 0, t_InformationBlock ) ;
  325. }
  326. else
  327. {
  328. if ( STATUS_ACCESS_DENIED == t_NtStatus )
  329. {
  330. hRes = WBEM_E_ACCESS_DENIED ;
  331. }
  332. else
  333. {
  334. hRes = WBEM_E_FAILED ;
  335. }
  336. }
  337. }
  338. else
  339. {
  340. if ( STATUS_ACCESS_DENIED == t_NtStatus )
  341. {
  342. hRes = WBEM_E_ACCESS_DENIED ;
  343. }
  344. else
  345. {
  346. hRes = WBEM_E_FAILED ;
  347. }
  348. }
  349. return hRes ;
  350. }
  351. HRESULT CIPRouteTable :: EnumerateInstances (
  352. MethodContext *pMethodContext,
  353. long lFlags
  354. )
  355. {
  356. HRESULT hRes = WBEM_S_NO_ERROR ;
  357. SmartCloseNtHandle t_StackHandle ;
  358. SmartCloseNtHandle t_CompleteEventHandle ;
  359. NTSTATUS t_NtStatus = OpenQuerySource (
  360. t_StackHandle ,
  361. t_CompleteEventHandle
  362. ) ;
  363. if ( NT_SUCCESS ( t_NtStatus ) )
  364. {
  365. ulong t_RouteTableSize = 0 ;
  366. IPRouteEntry *t_InformationBlock = NULL ;
  367. t_NtStatus = QueryInformation_IpRouteInfo (
  368. t_StackHandle ,
  369. t_CompleteEventHandle ,
  370. t_RouteTableSize ,
  371. t_InformationBlock
  372. ) ;
  373. if ( NT_SUCCESS ( t_NtStatus ) )
  374. {
  375. try
  376. {
  377. for ( ulong t_RouteIndex = 0 ; t_RouteIndex < t_RouteTableSize ; t_RouteIndex ++ )
  378. {
  379. IPRouteEntry &t_Entry = t_InformationBlock [ t_RouteIndex ] ;
  380. /*
  381. * Create a new instance based on the passed-in MethodContext.
  382. * Note that CreateNewInstance may throw, but will never return NULL.
  383. */
  384. CInstance *pInstance = CreateNewInstance ( pMethodContext ) ;
  385. /*
  386. * Set the keys for the instance
  387. */
  388. ProvIpAddressType t_DestinationIpAddress ( ntohl ( t_Entry.ire_dest ) ) ;
  389. CDeleteString t_DestinationIpAddressString(t_DestinationIpAddress.GetStringValue ());
  390. pInstance->SetCHString ( RouteDestination, t_DestinationIpAddressString ) ;
  391. ProvIpAddressType t_NextHopIpAddress ( ntohl ( t_Entry.ire_nexthop ) ) ;
  392. CDeleteString t_NextHopIpAddressString (t_NextHopIpAddress.GetStringValue () ) ;
  393. pInstance->SetCHString( RouteNextHop, t_NextHopIpAddressString ) ;
  394. /*
  395. * Initialize the instance
  396. */
  397. ProvIpAddressType t_DestinationMaskIpAddress ( ntohl ( t_Entry.ire_mask ) ) ;
  398. CDeleteString t_DestinationMaskIpAddressString (t_DestinationMaskIpAddress.GetStringValue () ) ;
  399. pInstance->SetCHString( RouteMask, t_DestinationMaskIpAddressString ) ;
  400. pInstance->SetDWORD ( RouteAge, t_Entry.ire_age ) ;
  401. pInstance->SetDWORD ( RouteInterfaceIndex, t_Entry.ire_index ) ;
  402. pInstance->SetCHString ( RouteInformation, "0.0" ) ;
  403. pInstance->SetDWORD ( RouteProtocol, t_Entry.ire_proto ) ;
  404. pInstance->SetDWORD ( RouteType, t_Entry.ire_type ) ;
  405. pInstance->SetDWORD ( RouteMetric1, t_Entry.ire_metric1 ) ;
  406. pInstance->SetDWORD ( RouteMetric2, t_Entry.ire_metric2 ) ;
  407. pInstance->SetDWORD ( RouteMetric3, t_Entry.ire_metric3 ) ;
  408. pInstance->SetDWORD ( RouteMetric4, t_Entry.ire_metric4 ) ;
  409. pInstance->SetDWORD ( RouteMetric5, t_Entry.ire_metric5 ) ;
  410. //set the inherited properties that are sensible
  411. SetInheritedProperties (
  412. t_DestinationIpAddressString ,
  413. t_NextHopIpAddressString ,
  414. t_DestinationMaskIpAddressString ,
  415. *pInstance
  416. ) ;
  417. /*
  418. * Forward the instance onto the core wmi service
  419. */
  420. hRes = Commit ( pInstance ) ;
  421. }
  422. }
  423. catch ( ... )
  424. {
  425. HeapFree ( GetProcessHeap () , 0, t_InformationBlock ) ;
  426. throw ;
  427. }
  428. HeapFree ( GetProcessHeap () , 0, t_InformationBlock ) ;
  429. }
  430. else
  431. {
  432. if ( STATUS_ACCESS_DENIED == t_NtStatus )
  433. {
  434. hRes = WBEM_E_ACCESS_DENIED ;
  435. }
  436. else
  437. {
  438. hRes = WBEM_E_FAILED ;
  439. }
  440. }
  441. }
  442. else
  443. {
  444. if ( STATUS_ACCESS_DENIED == t_NtStatus )
  445. {
  446. hRes = WBEM_E_ACCESS_DENIED ;
  447. }
  448. else
  449. {
  450. hRes = WBEM_E_FAILED ;
  451. }
  452. }
  453. return hRes ;
  454. }
  455. /*****************************************************************************
  456. *
  457. * FUNCTION : CIPRouteTable::GetObject
  458. *
  459. * DESCRIPTION : Find a single instance based on the key properties for the
  460. * class.
  461. *
  462. * INPUTS : A pointer to a CInstance object containing the key properties.
  463. * A long that contains the flags described in
  464. * IWbemServices::GetObjectAsync.
  465. *
  466. * RETURNS : WBEM_S_NO_ERROR if the instance can be found
  467. * WBEM_E_NOT_FOUND if the instance described by the key properties
  468. * could not be found
  469. * WBEM_E_FAILED if the instance could be found but another error
  470. * occurred.
  471. *
  472. * COMMENTS : If you are implementing a 'method only' provider, you should
  473. * remove this method.
  474. *
  475. *****************************************************************************/
  476. HRESULT CIPRouteTable :: GetObject (
  477. CInstance *pInstance,
  478. long lFlags
  479. )
  480. {
  481. HRESULT hr = WBEM_E_NOT_FOUND;
  482. CHString t_KeyDest ;
  483. pInstance->GetCHString ( RouteDestination , t_KeyDest ) ;
  484. ProvIpAddressType t_IpAddress ( t_KeyDest ) ;
  485. CHString t_KeyHop ;
  486. pInstance->GetCHString ( RouteNextHop , t_KeyHop ) ;
  487. ProvIpAddressType t_NextHop ( t_KeyHop ) ;
  488. if ( t_IpAddress.IsValid () && t_NextHop.IsValid () )
  489. {
  490. IPRouteEntry t_RouteEntry ;
  491. hr = QueryInformation_GetRouteEntry (
  492. t_IpAddress ,
  493. t_NextHop ,
  494. t_RouteEntry
  495. ) ;
  496. if ( SUCCEEDED ( hr ) )
  497. {
  498. /*
  499. * Initialize the instance
  500. */
  501. ProvIpAddressType t_DestinationMaskIpAddress ( ntohl ( t_RouteEntry.ire_mask ) ) ;
  502. CDeleteString t_DestinationMaskIpAddressString (t_DestinationMaskIpAddress.GetStringValue () ) ;
  503. pInstance->SetCHString( RouteMask, t_DestinationMaskIpAddressString ) ;
  504. pInstance->SetDWORD ( RouteAge, t_RouteEntry.ire_age ) ;
  505. pInstance->SetDWORD ( RouteInterfaceIndex, t_RouteEntry.ire_index ) ;
  506. pInstance->SetCHString ( RouteInformation, "0.0" ) ;
  507. pInstance->SetDWORD ( RouteProtocol, t_RouteEntry.ire_proto ) ;
  508. pInstance->SetDWORD ( RouteType, t_RouteEntry.ire_type ) ;
  509. pInstance->SetDWORD ( RouteMetric1, t_RouteEntry.ire_metric1 ) ;
  510. pInstance->SetDWORD ( RouteMetric2, t_RouteEntry.ire_metric2 ) ;
  511. pInstance->SetDWORD ( RouteMetric3, t_RouteEntry.ire_metric3 ) ;
  512. pInstance->SetDWORD ( RouteMetric4, t_RouteEntry.ire_metric4 ) ;
  513. pInstance->SetDWORD ( RouteMetric5, t_RouteEntry.ire_metric5 ) ;
  514. //set the inherited properties that are sensible
  515. SetInheritedProperties (
  516. t_KeyDest ,
  517. t_KeyHop ,
  518. t_DestinationMaskIpAddressString ,
  519. *pInstance
  520. ) ;
  521. }
  522. }
  523. return hr ;
  524. }
  525. /*****************************************************************************
  526. *
  527. * FUNCTION : CIPRouteTable::ExecQuery
  528. *
  529. * DESCRIPTION : You are passed a method context to use in the creation of
  530. * instances that satisfy the query, and a CFrameworkQuery
  531. * which describes the query. Create and populate all
  532. * instances which satisfy the query. You may return more
  533. * instances or more properties than are requested and WinMgmt
  534. * will post filter out any that do not apply.
  535. *
  536. * INPUTS : A pointer to the MethodContext for communication with WinMgmt.
  537. * A query object describing the query to satisfy.
  538. * A long that contains the flags described in
  539. * IWbemServices::CreateInstanceEnumAsync. Note that the following
  540. * flags are handled by (and filtered out by) WinMgmt:
  541. * WBEM_FLAG_FORWARD_ONLY
  542. * WBEM_FLAG_BIDIRECTIONAL
  543. * WBEM_FLAG_ENSURE_LOCATABLE
  544. *
  545. * RETURNS : WBEM_E_PROVIDER_NOT_CAPABLE if queries not supported for
  546. * this class or if the query is too complex for this class
  547. * to interpret. The framework will call the EnumerateInstances
  548. * function instead and let Winmgmt post filter.
  549. * WBEM_E_FAILED if the query failed
  550. * WBEM_S_NO_ERROR if query was successful
  551. *
  552. * COMMENTS : TO DO: Most providers will not need to implement this method. If you don't, WinMgmt
  553. * will call your enumerate function to get all the instances and perform the
  554. * filtering for you. Unless you expect SIGNIFICANT savings from implementing
  555. * queries, you should remove this method. You should also remove this method
  556. * if you are implementing a 'method only' provider.
  557. *
  558. *****************************************************************************/
  559. HRESULT CIPRouteTable :: ExecQuery (
  560. MethodContext *pMethodContext,
  561. CFrameworkQuery &Query,
  562. long lFlags
  563. )
  564. {
  565. HRESULT t_Result = S_OK ;
  566. CHString t_QueryString ;
  567. SQL_LEVEL_1_RPN_EXPRESSION *t_RpnExpression = NULL ;
  568. QueryPreprocessor :: QuadState t_State = QueryPreprocessor :: QuadState :: State_False;
  569. try
  570. {
  571. t_QueryString = Query.GetQuery () ;
  572. t_State = CIPRouteTable :: Query (
  573. t_QueryString.GetBuffer ( 0 ) ,
  574. t_RpnExpression
  575. ) ;
  576. }
  577. catch ( ... )
  578. {
  579. if ( t_RpnExpression )
  580. {
  581. delete t_RpnExpression;
  582. t_RpnExpression = NULL;
  583. }
  584. throw;
  585. }
  586. if ( t_State == QueryPreprocessor :: QuadState :: State_True )
  587. {
  588. WmiTreeNode *t_Root = NULL ;
  589. try
  590. {
  591. t_State = PreProcess (
  592. pMethodContext ,
  593. t_RpnExpression ,
  594. t_Root
  595. ) ;
  596. switch ( t_State )
  597. {
  598. case QueryPreprocessor :: QuadState :: State_True:
  599. {
  600. PartitionSet *t_Partition = NULL ;
  601. BSTR t_PropertyContainer [ 1 ] ;
  602. t_PropertyContainer [ 0 ] = SysAllocString ( RouteDestination ) ;
  603. if ( NULL == t_PropertyContainer [ 0 ] )
  604. {
  605. throw Heap_Exception(Heap_Exception::HEAP_ERROR::E_ALLOCATION_ERROR);
  606. }
  607. try
  608. {
  609. t_State = PreProcess (
  610. pMethodContext ,
  611. t_RpnExpression ,
  612. t_Root ,
  613. 1 ,
  614. t_PropertyContainer ,
  615. t_Partition
  616. ) ;
  617. }
  618. catch(...)
  619. {
  620. if ( t_Partition )
  621. {
  622. delete t_Partition;
  623. t_Partition = NULL;
  624. }
  625. if ( t_PropertyContainer [ 0 ] )
  626. {
  627. SysFreeString ( t_PropertyContainer [ 0 ] ) ;
  628. t_PropertyContainer [ 0 ] = NULL;
  629. }
  630. throw;
  631. }
  632. SysFreeString ( t_PropertyContainer [ 0 ] ) ;
  633. switch ( t_State )
  634. {
  635. case QueryPreprocessor :: QuadState :: State_True :
  636. {
  637. t_Result = EnumerateInstances ( pMethodContext , lFlags ) ;
  638. }
  639. break ;
  640. case QueryPreprocessor :: QuadState :: State_False :
  641. {
  642. /*
  643. * Empty set
  644. */
  645. }
  646. break ;
  647. case QueryPreprocessor :: QuadState :: State_Undefined :
  648. {
  649. t_Result = RangeQuery ( pMethodContext , *t_Partition , lFlags ) ;
  650. delete t_Partition ;
  651. t_Partition = NULL ;
  652. }
  653. break ;
  654. default:
  655. {
  656. //couldn't understand this query
  657. t_Result = WBEM_E_PROVIDER_NOT_CAPABLE ;
  658. }
  659. break ;
  660. }
  661. //this is allocated on PreProcess(pctx, rpn, root) success
  662. delete t_Root ;
  663. t_Root = NULL ;
  664. }
  665. break ;
  666. default:
  667. {
  668. //couldn't understand this query
  669. t_Result = WBEM_E_PROVIDER_NOT_CAPABLE ;
  670. }
  671. break ;
  672. }
  673. delete t_RpnExpression ;
  674. t_RpnExpression = NULL ;
  675. }
  676. catch ( ... )
  677. {
  678. if ( t_Root )
  679. {
  680. delete t_Root;
  681. t_Root = NULL;
  682. }
  683. if ( t_RpnExpression )
  684. {
  685. delete t_RpnExpression;
  686. t_RpnExpression = NULL;
  687. }
  688. throw;
  689. }
  690. }
  691. else
  692. {
  693. //couldn't understand this query
  694. t_Result = WBEM_E_PROVIDER_NOT_CAPABLE ;
  695. }
  696. return t_Result ;
  697. }
  698. /*****************************************************************************
  699. *
  700. * FUNCTION : CIPRouteTable::PutInstance
  701. *
  702. * DESCRIPTION : PutInstance should be used in provider classes that can
  703. * write instance information back to the hardware or
  704. * software. For example: Win32_Environment will allow a
  705. * PutInstance to create or update an environment variable.
  706. * However, a class like MotherboardDevice will not allow
  707. * editing of the number of slots, since it is difficult for
  708. * a provider to affect that number.
  709. *
  710. * INPUTS : A pointer to a CInstance object containing the key properties.
  711. * A long that contains the flags described in
  712. * IWbemServices::PutInstanceAsync.
  713. *
  714. * RETURNS : WBEM_E_PROVIDER_NOT_CAPABLE if PutInstance is not available
  715. * WBEM_E_FAILED if there is an error delivering the instance
  716. * WBEM_E_INVALID_PARAMETER if any of the instance properties
  717. * are incorrect.
  718. * WBEM_S_NO_ERROR if instance is properly delivered
  719. *
  720. * COMMENTS : TO DO: If you don't intend to support writing to your provider,
  721. * or are creating a 'method only' provider, remove this
  722. * method.
  723. *
  724. *****************************************************************************/
  725. HRESULT CIPRouteTable :: PutInstance (
  726. const CInstance &Instance,
  727. long lFlags
  728. )
  729. {
  730. HRESULT hr = WBEM_E_FAILED ;
  731. switch ( lFlags & (WBEM_FLAG_CREATE_OR_UPDATE | WBEM_FLAG_CREATE_ONLY | WBEM_FLAG_UPDATE_ONLY) )
  732. {
  733. case WBEM_FLAG_CREATE_OR_UPDATE:
  734. case WBEM_FLAG_UPDATE_ONLY:
  735. case WBEM_FLAG_CREATE_ONLY:
  736. {
  737. CHString t_KeyDest ;
  738. Instance.GetCHString ( RouteDestination , t_KeyDest ) ;
  739. ProvIpAddressType t_IpAddress ( t_KeyDest ) ;
  740. CHString t_KeyHop ;
  741. Instance.GetCHString ( RouteNextHop , t_KeyHop ) ;
  742. ProvIpAddressType t_NextHop ( t_KeyHop ) ;
  743. if ( t_IpAddress.IsValid () && t_NextHop.IsValid () )
  744. {
  745. IPRouteEntry t_RouteEntry ;
  746. hr = QueryInformation_GetRouteEntry (
  747. t_IpAddress ,
  748. t_NextHop ,
  749. t_RouteEntry
  750. ) ;
  751. switch ( lFlags & (WBEM_FLAG_CREATE_OR_UPDATE | WBEM_FLAG_CREATE_ONLY | WBEM_FLAG_UPDATE_ONLY) )
  752. {
  753. case WBEM_FLAG_CREATE_OR_UPDATE:
  754. {
  755. hr = ( hr == WBEM_E_NOT_FOUND || hr == WBEM_S_NO_ERROR ) ? WBEM_S_NO_ERROR : hr ;
  756. }
  757. break;
  758. case WBEM_FLAG_UPDATE_ONLY:
  759. {
  760. }
  761. break;
  762. case WBEM_FLAG_CREATE_ONLY:
  763. {
  764. if ( hr == WBEM_S_NO_ERROR )
  765. {
  766. hr = WBEM_E_ALREADY_EXISTS ;
  767. }
  768. else if ( hr == WBEM_E_NOT_FOUND )
  769. {
  770. hr = WBEM_S_NO_ERROR ;
  771. }
  772. }
  773. break;
  774. }
  775. if ( SUCCEEDED ( hr ) )
  776. {
  777. hr = CheckParameters (
  778. Instance ,
  779. t_RouteEntry
  780. ) ;
  781. }
  782. if ( SUCCEEDED ( hr ) )
  783. {
  784. //reset to an error which will be cleared on success...
  785. hr = WBEM_E_FAILED;
  786. SmartCloseNtHandle t_StackHandle;
  787. SmartCloseNtHandle t_CompleteEventHandle;
  788. NTSTATUS t_NtStatus = OpenSetSource (
  789. t_StackHandle ,
  790. t_CompleteEventHandle
  791. ) ;
  792. if ( NT_SUCCESS ( t_NtStatus ) )
  793. {
  794. t_NtStatus = SetInformation_IpRouteInfo (
  795. t_StackHandle ,
  796. t_CompleteEventHandle ,
  797. t_RouteEntry
  798. ) ;
  799. if ( NT_SUCCESS ( t_NtStatus ) )
  800. {
  801. hr = WBEM_S_NO_ERROR ;
  802. }
  803. }
  804. }
  805. }
  806. else
  807. {
  808. hr = WBEM_E_INVALID_PARAMETER ;
  809. }
  810. }
  811. break ;
  812. default:
  813. {
  814. hr = WBEM_E_PROVIDER_NOT_CAPABLE ;
  815. }
  816. break ;
  817. }
  818. return hr ;
  819. }
  820. HRESULT CIPRouteTable :: CheckParameters (
  821. const CInstance &a_Instance ,
  822. IPRouteEntry &a_RouteEntry
  823. )
  824. {
  825. HRESULT hr = WBEM_S_NO_ERROR ;
  826. ZeroMemory ( & a_RouteEntry , sizeof ( a_RouteEntry ) ) ;
  827. a_RouteEntry.ire_metric2 = -1 ;
  828. a_RouteEntry.ire_metric3 = -1 ;
  829. a_RouteEntry.ire_metric4 = -1 ;
  830. a_RouteEntry.ire_metric5 = -1 ;
  831. bool t_Exists ;
  832. VARTYPE t_Type ;
  833. CHString t_RouteDestinationString ;
  834. if ( a_Instance.GetStatus ( RouteDestination , t_Exists , t_Type ) )
  835. {
  836. if ( t_Exists && ( t_Type == VT_BSTR ) )
  837. {
  838. if ( a_Instance.GetCHString ( RouteDestination , t_RouteDestinationString ) && ! t_RouteDestinationString.IsEmpty () )
  839. {
  840. ProvIpAddressType t_Address ( t_RouteDestinationString ) ;
  841. if ( t_Address.IsValid () )
  842. {
  843. a_RouteEntry.ire_dest = htonl ( t_Address.GetValue () ) ;
  844. }
  845. else
  846. {
  847. return WBEM_E_INVALID_PARAMETER ;
  848. }
  849. }
  850. else
  851. {
  852. // Zero Length string
  853. return WBEM_E_INVALID_PARAMETER ;
  854. }
  855. }
  856. else
  857. {
  858. return WBEM_E_INVALID_PARAMETER ;
  859. }
  860. }
  861. else
  862. {
  863. return WBEM_E_FAILED ;
  864. }
  865. CHString t_RouteDestinationMaskString ;
  866. if ( a_Instance.GetStatus ( RouteMask , t_Exists , t_Type ) )
  867. {
  868. if ( t_Exists && ( t_Type == VT_BSTR ) )
  869. {
  870. if ( a_Instance.GetCHString ( RouteMask , t_RouteDestinationMaskString ) && ! t_RouteDestinationMaskString.IsEmpty () )
  871. {
  872. ProvIpAddressType t_Address ( t_RouteDestinationMaskString ) ;
  873. if ( t_Address.IsValid () )
  874. {
  875. a_RouteEntry.ire_mask = htonl ( t_Address.GetValue () ) ;
  876. }
  877. else
  878. {
  879. return WBEM_E_INVALID_PARAMETER ;
  880. }
  881. }
  882. else
  883. {
  884. // Zero Length string
  885. return WBEM_E_INVALID_PARAMETER ;
  886. }
  887. }
  888. else
  889. {
  890. return WBEM_E_INVALID_PARAMETER ;
  891. }
  892. }
  893. else
  894. {
  895. return WBEM_E_FAILED ;
  896. }
  897. CHString t_RouteNextHopString ;
  898. if ( a_Instance.GetStatus ( RouteNextHop, t_Exists , t_Type ) )
  899. {
  900. if ( t_Exists && ( t_Type == VT_BSTR ) )
  901. {
  902. if ( a_Instance.GetCHString ( RouteNextHop , t_RouteNextHopString ) && ! t_RouteNextHopString.IsEmpty () )
  903. {
  904. ProvIpAddressType t_Address ( t_RouteNextHopString ) ;
  905. if ( t_Address.IsValid () )
  906. {
  907. a_RouteEntry.ire_nexthop = htonl ( t_Address.GetValue () ) ;
  908. }
  909. else
  910. {
  911. return WBEM_E_INVALID_PARAMETER ;
  912. }
  913. }
  914. else
  915. {
  916. // Zero Length string
  917. return WBEM_E_INVALID_PARAMETER ;
  918. }
  919. }
  920. else
  921. {
  922. return WBEM_E_INVALID_PARAMETER ;
  923. }
  924. }
  925. else
  926. {
  927. return WBEM_E_FAILED ;
  928. }
  929. if ( a_Instance.GetStatus ( RouteInterfaceIndex , t_Exists , t_Type ) )
  930. {
  931. if ( t_Exists && ( t_Type == VT_I4 ) )
  932. {
  933. DWORD t_InterfaceIndex = 0 ;
  934. if ( a_Instance.GetDWORD ( RouteInterfaceIndex , t_InterfaceIndex ) )
  935. {
  936. a_RouteEntry.ire_index = t_InterfaceIndex ;
  937. }
  938. else
  939. {
  940. return WBEM_E_INVALID_PARAMETER ;
  941. }
  942. }
  943. else
  944. {
  945. return WBEM_E_INVALID_PARAMETER ;
  946. }
  947. }
  948. else
  949. {
  950. return WBEM_E_FAILED ;
  951. }
  952. if ( a_Instance.GetStatus ( RouteProtocol , t_Exists , t_Type ) )
  953. {
  954. if ( t_Exists && ( t_Type == VT_I4 ) )
  955. {
  956. DWORD t_Protocol = 0 ;
  957. if ( a_Instance.GetDWORD ( RouteProtocol , t_Protocol ) )
  958. {
  959. a_RouteEntry.ire_proto = t_Protocol ;
  960. }
  961. else
  962. {
  963. return WBEM_E_INVALID_PARAMETER ;
  964. }
  965. }
  966. else
  967. {
  968. return WBEM_E_INVALID_PARAMETER ;
  969. }
  970. }
  971. else
  972. {
  973. return WBEM_E_FAILED ;
  974. }
  975. if ( a_Instance.GetStatus ( RouteType , t_Exists , t_Type ) )
  976. {
  977. if ( t_Exists && ( t_Type == VT_I4 ) )
  978. {
  979. DWORD t_Type = 0 ;
  980. if ( a_Instance.GetDWORD ( RouteType , t_Type ) )
  981. {
  982. a_RouteEntry.ire_type = t_Type ;
  983. }
  984. else
  985. {
  986. return WBEM_E_INVALID_PARAMETER ;
  987. }
  988. }
  989. else
  990. {
  991. return WBEM_E_INVALID_PARAMETER ;
  992. }
  993. }
  994. else
  995. {
  996. return WBEM_E_FAILED ;
  997. }
  998. #if 0
  999. if ( a_Instance.GetStatus ( RouteAge , t_Exists , t_Type ) )
  1000. {
  1001. if ( t_Exists && ( t_Type == VT_I4 ) )
  1002. {
  1003. DWORD t_Age = 0 ;
  1004. if ( a_Instance.GetDWORD ( RouteAge , t_Age ) )
  1005. {
  1006. a_RouteEntry.ire_age = t_Age ;
  1007. }
  1008. else
  1009. {
  1010. return WBEM_E_INVALID_PARAMETER ;
  1011. }
  1012. }
  1013. else
  1014. {
  1015. return WBEM_E_INVALID_PARAMETER ;
  1016. }
  1017. }
  1018. else
  1019. {
  1020. return WBEM_E_FAILED ;
  1021. }
  1022. #endif
  1023. if ( a_Instance.GetStatus ( RouteMetric1 , t_Exists , t_Type ) )
  1024. {
  1025. if ( t_Exists && ( t_Type == VT_I4 ) )
  1026. {
  1027. DWORD t_Metric = 0 ;
  1028. if ( a_Instance.GetDWORD ( RouteMetric1 , t_Metric ) )
  1029. {
  1030. a_RouteEntry.ire_metric1 = t_Metric ;
  1031. }
  1032. else
  1033. {
  1034. return WBEM_E_INVALID_PARAMETER ;
  1035. }
  1036. }
  1037. else
  1038. {
  1039. return WBEM_E_INVALID_PARAMETER ;
  1040. }
  1041. }
  1042. else
  1043. {
  1044. return WBEM_E_FAILED ;
  1045. }
  1046. if ( a_Instance.GetStatus ( RouteMetric2 , t_Exists , t_Type ) )
  1047. {
  1048. if ( t_Exists && ( t_Type == VT_I4 || t_Type == VT_NULL ) )
  1049. {
  1050. if ( t_Type == VT_NULL )
  1051. {
  1052. }
  1053. else
  1054. {
  1055. DWORD t_Metric = 0 ;
  1056. if ( a_Instance.GetDWORD ( RouteMetric2 , t_Metric ) )
  1057. {
  1058. a_RouteEntry.ire_metric2 = t_Metric ;
  1059. }
  1060. else
  1061. {
  1062. return WBEM_E_INVALID_PARAMETER ;
  1063. }
  1064. }
  1065. }
  1066. else
  1067. {
  1068. return WBEM_E_INVALID_PARAMETER ;
  1069. }
  1070. }
  1071. else
  1072. {
  1073. return WBEM_E_FAILED ;
  1074. }
  1075. if ( a_Instance.GetStatus ( RouteMetric3 , t_Exists , t_Type ) )
  1076. {
  1077. if ( t_Exists && ( t_Type == VT_I4 || t_Type == VT_NULL ) )
  1078. {
  1079. if ( t_Type == VT_NULL )
  1080. {
  1081. }
  1082. else
  1083. {
  1084. DWORD t_Metric = 0 ;
  1085. if ( a_Instance.GetDWORD ( RouteMetric3 , t_Metric ) )
  1086. {
  1087. a_RouteEntry.ire_metric3 = t_Metric ;
  1088. }
  1089. else
  1090. {
  1091. return WBEM_E_INVALID_PARAMETER ;
  1092. }
  1093. }
  1094. }
  1095. else
  1096. {
  1097. return WBEM_E_INVALID_PARAMETER ;
  1098. }
  1099. }
  1100. else
  1101. {
  1102. return WBEM_E_FAILED ;
  1103. }
  1104. if ( a_Instance.GetStatus ( RouteMetric5 , t_Exists , t_Type ) )
  1105. {
  1106. if ( t_Exists && ( t_Type == VT_I4 || t_Type == VT_NULL ) )
  1107. {
  1108. if ( t_Type == VT_NULL )
  1109. {
  1110. }
  1111. else
  1112. {
  1113. DWORD t_Metric = 0 ;
  1114. if ( a_Instance.GetDWORD ( RouteMetric5 , t_Metric ) )
  1115. {
  1116. a_RouteEntry.ire_metric5 = t_Metric ;
  1117. }
  1118. else
  1119. {
  1120. return WBEM_E_INVALID_PARAMETER ;
  1121. }
  1122. }
  1123. }
  1124. else
  1125. {
  1126. return WBEM_E_INVALID_PARAMETER ;
  1127. }
  1128. }
  1129. else
  1130. {
  1131. return WBEM_E_FAILED ;
  1132. }
  1133. if ( a_Instance.GetStatus ( RouteMetric4 , t_Exists , t_Type ) )
  1134. {
  1135. if ( t_Exists && ( t_Type == VT_I4 || t_Type == VT_NULL ) )
  1136. {
  1137. if ( t_Type == VT_NULL )
  1138. {
  1139. }
  1140. else
  1141. {
  1142. DWORD t_Metric = 0 ;
  1143. if ( a_Instance.GetDWORD ( RouteMetric4 , t_Metric ) )
  1144. {
  1145. a_RouteEntry.ire_metric4 = t_Metric ;
  1146. }
  1147. else
  1148. {
  1149. return WBEM_E_INVALID_PARAMETER ;
  1150. }
  1151. }
  1152. }
  1153. else
  1154. {
  1155. return WBEM_E_INVALID_PARAMETER ;
  1156. }
  1157. }
  1158. else
  1159. {
  1160. return WBEM_E_FAILED ;
  1161. }
  1162. return hr ;
  1163. }
  1164. /*****************************************************************************
  1165. *
  1166. * FUNCTION : CIPRouteTable::DeleteInstance
  1167. *
  1168. * DESCRIPTION : DeleteInstance, like PutInstance, actually writes information
  1169. * to the software or hardware. For most hardware devices,
  1170. * DeleteInstance should not be implemented, but for software
  1171. * configuration, DeleteInstance implementation is plausible.
  1172. *
  1173. * INPUTS : A pointer to a CInstance object containing the key properties.
  1174. * A long that contains the flags described in
  1175. * IWbemServices::DeleteInstanceAsync.
  1176. *
  1177. * RETURNS : WBEM_E_PROVIDER_NOT_CAPABLE if DeleteInstance is not available.
  1178. * WBEM_E_FAILED if there is an error deleting the instance.
  1179. * WBEM_E_INVALID_PARAMETER if any of the instance properties
  1180. * are incorrect.
  1181. * WBEM_S_NO_ERROR if instance is properly deleted.
  1182. *
  1183. * COMMENTS : TO DO: If you don't intend to support deleting instances or are
  1184. * creating a 'method only' provider, remove this method.
  1185. *
  1186. *****************************************************************************/
  1187. HRESULT CIPRouteTable :: DeleteInstance (
  1188. const CInstance &Instance,
  1189. long lFlags
  1190. )
  1191. {
  1192. HRESULT hr = WBEM_E_FAILED ;
  1193. CHString t_KeyDest ;
  1194. Instance.GetCHString ( RouteDestination , t_KeyDest ) ;
  1195. ProvIpAddressType t_IpAddress ( t_KeyDest ) ;
  1196. CHString t_KeyHop ;
  1197. Instance.GetCHString ( RouteNextHop , t_KeyHop ) ;
  1198. ProvIpAddressType t_NextHop ( t_KeyHop ) ;
  1199. if ( t_IpAddress.IsValid () && t_NextHop.IsValid () )
  1200. {
  1201. IPRouteEntry t_RouteEntry ;
  1202. hr = QueryInformation_GetRouteEntry (
  1203. t_IpAddress ,
  1204. t_NextHop ,
  1205. t_RouteEntry
  1206. ) ;
  1207. if ( SUCCEEDED ( hr ) )
  1208. {
  1209. SmartCloseNtHandle t_StackHandle ;
  1210. SmartCloseNtHandle t_CompleteEventHandle ;
  1211. NTSTATUS t_NtStatus = OpenSetSource (
  1212. t_StackHandle ,
  1213. t_CompleteEventHandle
  1214. ) ;
  1215. if ( NT_SUCCESS ( t_NtStatus ) )
  1216. {
  1217. t_NtStatus = DeleteInformation_IpRouteInfo (
  1218. t_StackHandle ,
  1219. t_CompleteEventHandle ,
  1220. t_RouteEntry
  1221. ) ;
  1222. if ( NT_SUCCESS ( t_NtStatus ) )
  1223. {
  1224. hr = WBEM_S_NO_ERROR ;
  1225. }
  1226. }
  1227. }
  1228. }
  1229. return hr ;
  1230. }
  1231. /*****************************************************************************
  1232. *
  1233. * FUNCTION : CIPRouteTable::ExecMethod
  1234. *
  1235. * DESCRIPTION : Override this function to provide support for methods.
  1236. * A method is an entry point for the user of your provider
  1237. * to request your class perform some function above and
  1238. * beyond a change of state. (A change of state should be
  1239. * handled by PutInstance() )
  1240. *
  1241. * INPUTS : A pointer to a CInstance containing the instance the method was executed against.
  1242. * A string containing the method name
  1243. * A pointer to the CInstance which contains the IN parameters.
  1244. * A pointer to the CInstance to contain the OUT parameters.
  1245. * A set of specialized method flags
  1246. *
  1247. * RETURNS : WBEM_E_PROVIDER_NOT_CAPABLE if not implemented for this class
  1248. * WBEM_S_NO_ERROR if method executes successfully
  1249. * WBEM_E_FAILED if error occurs executing method
  1250. *
  1251. * COMMENTS : TO DO: If you don't intend to support Methods, remove this method.
  1252. *
  1253. *****************************************************************************/
  1254. HRESULT CIPRouteTable :: ExecMethod (
  1255. const CInstance &Instance,
  1256. const BSTR bstrMethodName,
  1257. CInstance *pInParams,
  1258. CInstance *pOutParams,
  1259. long lFlags
  1260. )
  1261. {
  1262. // For non-static methods, use the CInstance Get functions (for example,
  1263. // call GetCHString(L"Name", sTemp)) against Instance to see the key
  1264. // values the client requested.
  1265. return WBEM_E_PROVIDER_NOT_CAPABLE ;
  1266. }
  1267. NTSTATUS CIPRouteTable :: OpenQuerySource (
  1268. HANDLE &a_StackHandle ,
  1269. HANDLE &a_CompleteEventHandle
  1270. )
  1271. {
  1272. UNICODE_STRING t_Stack ;
  1273. RtlInitUnicodeString ( & t_Stack , DD_TCP_DEVICE_NAME ) ;
  1274. OBJECT_ATTRIBUTES t_Attributes;
  1275. InitializeObjectAttributes (
  1276. &t_Attributes,
  1277. &t_Stack ,
  1278. OBJ_CASE_INSENSITIVE,
  1279. NULL,
  1280. NULL
  1281. ) ;
  1282. IO_STATUS_BLOCK t_IoStatusBlock ;
  1283. NTSTATUS t_NtStatus = NtOpenFile (
  1284. &a_StackHandle,
  1285. GENERIC_EXECUTE,
  1286. &t_Attributes,
  1287. &t_IoStatusBlock,
  1288. FILE_SHARE_READ,
  1289. 0
  1290. );
  1291. if ( NT_SUCCESS ( t_NtStatus ) )
  1292. {
  1293. t_NtStatus = NtCreateEvent (
  1294. &a_CompleteEventHandle,
  1295. EVENT_ALL_ACCESS,
  1296. NULL,
  1297. SynchronizationEvent,
  1298. FALSE
  1299. ) ;
  1300. if ( ! NT_SUCCESS ( t_NtStatus ) )
  1301. {
  1302. NtClose ( a_StackHandle ) ;
  1303. a_StackHandle = INVALID_HANDLE_VALUE ;
  1304. }
  1305. }
  1306. return t_NtStatus ;
  1307. }
  1308. HRESULT CIPRouteTable :: QueryInformation_GetRouteEntry (
  1309. const ProvIpAddressType &a_DestinationIpAddress ,
  1310. const ProvIpAddressType &a_NextHopIpAddress ,
  1311. IPRouteEntry &a_RouteEntry
  1312. )
  1313. {
  1314. HRESULT hRes = WBEM_E_NOT_FOUND ;
  1315. SmartCloseNtHandle t_StackHandle ;
  1316. SmartCloseNtHandle t_CompleteEventHandle ;
  1317. NTSTATUS t_NtStatus = OpenQuerySource (
  1318. t_StackHandle ,
  1319. t_CompleteEventHandle
  1320. ) ;
  1321. if ( NT_SUCCESS ( t_NtStatus ) )
  1322. {
  1323. ulong t_RouteTableSize = 0 ;
  1324. IPRouteEntry *t_InformationBlock = NULL ;
  1325. t_NtStatus = QueryInformation_IpRouteInfo (
  1326. t_StackHandle ,
  1327. t_CompleteEventHandle ,
  1328. t_RouteTableSize ,
  1329. t_InformationBlock
  1330. ) ;
  1331. if ( NT_SUCCESS ( t_NtStatus ) )
  1332. {
  1333. try
  1334. {
  1335. for ( ulong t_RouteIndex = 0 ; t_RouteIndex < t_RouteTableSize ; t_RouteIndex ++ )
  1336. {
  1337. IPRouteEntry &t_Entry = t_InformationBlock [ t_RouteIndex ] ;
  1338. ProvIpAddressType t_DestinationIpAddress ( ntohl ( t_Entry.ire_dest ) ) ;
  1339. ProvIpAddressType t_NextHopIpAddress ( ntohl ( t_Entry.ire_nexthop ) ) ;
  1340. if ( ( t_DestinationIpAddress == a_DestinationIpAddress ) &&
  1341. ( t_NextHopIpAddress == a_NextHopIpAddress ) )
  1342. {
  1343. a_RouteEntry = t_InformationBlock [ t_RouteIndex ] ;
  1344. hRes = WBEM_S_NO_ERROR ;
  1345. break ;
  1346. }
  1347. }
  1348. }
  1349. catch ( ... )
  1350. {
  1351. HeapFree ( GetProcessHeap () , 0, t_InformationBlock ) ;
  1352. throw ;
  1353. }
  1354. HeapFree ( GetProcessHeap () , 0, t_InformationBlock ) ;
  1355. }
  1356. else
  1357. {
  1358. if ( STATUS_ACCESS_DENIED == t_NtStatus )
  1359. {
  1360. hRes = WBEM_E_ACCESS_DENIED ;
  1361. }
  1362. else
  1363. {
  1364. hRes = WBEM_E_FAILED ;
  1365. }
  1366. }
  1367. }
  1368. return hRes ;
  1369. }
  1370. NTSTATUS CIPRouteTable :: QueryInformation_IpRouteInfo (
  1371. HANDLE a_StackHandle ,
  1372. HANDLE a_CompleteEventHandle ,
  1373. ulong &a_RouteTableSize ,
  1374. IPRouteEntry *&a_InformationBlock
  1375. )
  1376. {
  1377. IPSNMPInfo a_Information ;
  1378. NTSTATUS t_NtStatus = QueryInformation_IpSnmpInfo (
  1379. a_StackHandle ,
  1380. a_CompleteEventHandle ,
  1381. a_Information
  1382. ) ;
  1383. if ( NT_SUCCESS ( t_NtStatus ) )
  1384. {
  1385. TCP_REQUEST_QUERY_INFORMATION_EX InBuf;
  1386. ulong InBufLen = sizeof( TCP_REQUEST_QUERY_INFORMATION_EX );
  1387. ulong OutBufLen = ( a_Information.ipsi_numroutes + 16 ) * sizeof ( IPRouteEntry ) ;
  1388. a_InformationBlock = ( IPRouteEntry * ) HeapAlloc ( GetProcessHeap (), 0, OutBufLen ) ;
  1389. if ( a_InformationBlock )
  1390. {
  1391. TDIObjectID *ID = & ( InBuf.ID ) ;
  1392. ID = &(InBuf.ID);
  1393. ID->toi_entity.tei_entity = CL_NL_ENTITY;
  1394. ID->toi_entity.tei_instance = 0;
  1395. ID->toi_class = INFO_CLASS_PROTOCOL;
  1396. ID->toi_type = INFO_TYPE_PROVIDER;
  1397. ID->toi_id = IP_MIB_RTTABLE_ENTRY_ID;
  1398. uchar *Context = ( uchar * ) & ( InBuf.Context [ 0 ] ) ;
  1399. ZeroMemory ( Context, CONTEXT_SIZE ) ;
  1400. IO_STATUS_BLOCK t_IoStatusBlock ;
  1401. t_NtStatus = NtDeviceIoControlFile (
  1402. a_StackHandle ,
  1403. a_CompleteEventHandle ,
  1404. NULL ,
  1405. NULL ,
  1406. &t_IoStatusBlock ,
  1407. IOCTL_TCP_QUERY_INFORMATION_EX,
  1408. ( void * ) & InBuf,
  1409. InBufLen,
  1410. ( void * ) ( a_InformationBlock ) ,
  1411. OutBufLen
  1412. );
  1413. if ( t_NtStatus == STATUS_PENDING )
  1414. {
  1415. t_NtStatus = NtWaitForSingleObject ( a_CompleteEventHandle , FALSE, NULL ) ;
  1416. }
  1417. if ( SUCCEEDED ( t_NtStatus ) )
  1418. {
  1419. a_RouteTableSize = ( t_IoStatusBlock.Information / sizeof ( IPRouteEntry ) ) ;
  1420. }
  1421. }
  1422. else
  1423. {
  1424. return ERROR_NOT_ENOUGH_MEMORY ;
  1425. }
  1426. }
  1427. return t_NtStatus ;
  1428. }
  1429. NTSTATUS CIPRouteTable :: QueryInformation_IpSnmpInfo (
  1430. HANDLE a_StackHandle ,
  1431. HANDLE a_CompleteEventHandle ,
  1432. IPSNMPInfo &a_Information
  1433. )
  1434. {
  1435. TCP_REQUEST_QUERY_INFORMATION_EX InBuf;
  1436. ulong InBufLen = sizeof( TCP_REQUEST_QUERY_INFORMATION_EX );
  1437. ulong OutBufLen = sizeof ( IPSNMPInfo ) ;
  1438. TDIObjectID *ID = & ( InBuf.ID ) ;
  1439. ID->toi_entity.tei_entity = CL_NL_ENTITY;
  1440. ID->toi_entity.tei_instance = 0;
  1441. ID->toi_class = INFO_CLASS_PROTOCOL;
  1442. ID->toi_type = INFO_TYPE_PROVIDER;
  1443. ID->toi_id = IP_MIB_STATS_ID;
  1444. uchar *Context = ( uchar * ) & ( InBuf.Context [ 0 ] ) ;
  1445. ZeroMemory ( Context, CONTEXT_SIZE ) ;
  1446. IO_STATUS_BLOCK t_IoStatusBlock ;
  1447. NTSTATUS t_NtStatus = NtDeviceIoControlFile (
  1448. a_StackHandle ,
  1449. a_CompleteEventHandle ,
  1450. NULL ,
  1451. NULL ,
  1452. &t_IoStatusBlock ,
  1453. IOCTL_TCP_QUERY_INFORMATION_EX,
  1454. ( void * ) & InBuf,
  1455. InBufLen,
  1456. ( void * ) ( & a_Information ) ,
  1457. OutBufLen
  1458. );
  1459. if ( t_NtStatus == STATUS_PENDING )
  1460. {
  1461. t_NtStatus = NtWaitForSingleObject ( a_CompleteEventHandle , FALSE, NULL ) ;
  1462. }
  1463. if ( SUCCEEDED ( t_NtStatus ) )
  1464. {
  1465. }
  1466. return t_NtStatus ;
  1467. }
  1468. NTSTATUS CIPRouteTable :: OpenSetSource (
  1469. HANDLE &a_StackHandle ,
  1470. HANDLE &a_CompleteEventHandle
  1471. )
  1472. {
  1473. UNICODE_STRING t_Stack ;
  1474. RtlInitUnicodeString ( & t_Stack , DD_TCP_DEVICE_NAME ) ;
  1475. OBJECT_ATTRIBUTES t_Attributes;
  1476. InitializeObjectAttributes (
  1477. &t_Attributes,
  1478. &t_Stack ,
  1479. OBJ_CASE_INSENSITIVE,
  1480. NULL,
  1481. NULL
  1482. ) ;
  1483. IO_STATUS_BLOCK t_IoStatusBlock ;
  1484. NTSTATUS t_NtStatus = NtOpenFile (
  1485. &a_StackHandle,
  1486. GENERIC_WRITE,
  1487. &t_Attributes,
  1488. &t_IoStatusBlock,
  1489. FILE_SHARE_READ,
  1490. 0
  1491. );
  1492. if ( NT_SUCCESS ( t_NtStatus ) )
  1493. {
  1494. t_NtStatus = NtCreateEvent (
  1495. &a_CompleteEventHandle,
  1496. EVENT_ALL_ACCESS,
  1497. NULL,
  1498. SynchronizationEvent,
  1499. FALSE
  1500. ) ;
  1501. if ( ! NT_SUCCESS ( t_NtStatus ) )
  1502. {
  1503. NtClose ( a_StackHandle ) ;
  1504. a_StackHandle = INVALID_HANDLE_VALUE ;
  1505. }
  1506. }
  1507. return t_NtStatus ;
  1508. }
  1509. NTSTATUS CIPRouteTable :: SetInformation_IpRouteInfo (
  1510. HANDLE a_StackHandle ,
  1511. HANDLE a_CompleteEventHandle ,
  1512. IPRouteEntry &a_RouteEntry
  1513. )
  1514. {
  1515. NTSTATUS t_NtStatus = STATUS_SUCCESS ;
  1516. ulong InBufLen = sizeof ( TCP_REQUEST_SET_INFORMATION_EX ) + sizeof ( IPSNMPInfo ) - 1 ;
  1517. TCP_REQUEST_SET_INFORMATION_EX *InBuf = ( TCP_REQUEST_SET_INFORMATION_EX * ) HeapAlloc ( GetProcessHeap(), 0, InBufLen ) ;
  1518. if ( InBuf )
  1519. {
  1520. try
  1521. {
  1522. IPRouteEntry *t_Entry = ( IPRouteEntry * ) &(InBuf->Buffer[0]) ;
  1523. *t_Entry = a_RouteEntry ;
  1524. TDIObjectID *ID = &(InBuf->ID);
  1525. ID->toi_entity.tei_entity = CL_NL_ENTITY;
  1526. ID->toi_entity.tei_instance = 0;
  1527. ID->toi_class = INFO_CLASS_PROTOCOL;
  1528. ID->toi_type = INFO_TYPE_PROVIDER;
  1529. ID->toi_id = IP_MIB_RTTABLE_ENTRY_ID;
  1530. InBuf->BufferSize = sizeof ( IPRouteEntry );
  1531. IO_STATUS_BLOCK t_IoStatusBlock ;
  1532. t_NtStatus = NtDeviceIoControlFile (
  1533. a_StackHandle ,
  1534. a_CompleteEventHandle ,
  1535. NULL ,
  1536. NULL ,
  1537. &t_IoStatusBlock ,
  1538. IOCTL_TCP_SET_INFORMATION_EX ,
  1539. ( void * ) InBuf,
  1540. InBufLen,
  1541. NULL ,
  1542. 0
  1543. );
  1544. if ( t_NtStatus == STATUS_PENDING )
  1545. {
  1546. t_NtStatus = NtWaitForSingleObject ( a_CompleteEventHandle , FALSE, NULL ) ;
  1547. }
  1548. }
  1549. catch ( ... )
  1550. {
  1551. HeapFree ( GetProcessHeap () , 0, InBuf ) ;
  1552. throw ;
  1553. }
  1554. HeapFree ( GetProcessHeap () , 0, InBuf ) ;
  1555. }
  1556. else
  1557. {
  1558. t_NtStatus = ERROR_NOT_ENOUGH_MEMORY ;
  1559. }
  1560. return t_NtStatus ;
  1561. }
  1562. NTSTATUS CIPRouteTable :: DeleteInformation_IpRouteInfo (
  1563. HANDLE a_StackHandle ,
  1564. HANDLE a_CompleteEventHandle ,
  1565. IPRouteEntry &a_RouteEntry
  1566. )
  1567. {
  1568. NTSTATUS t_NtStatus = STATUS_SUCCESS ;
  1569. ulong InBufLen = sizeof ( TCP_REQUEST_SET_INFORMATION_EX ) + sizeof ( IPSNMPInfo ) - 1 ;
  1570. TCP_REQUEST_SET_INFORMATION_EX *InBuf = ( TCP_REQUEST_SET_INFORMATION_EX * ) HeapAlloc ( GetProcessHeap(), 0, InBufLen ) ;
  1571. if ( InBuf )
  1572. {
  1573. try
  1574. {
  1575. IPRouteEntry *t_Entry = ( IPRouteEntry * ) &(InBuf->Buffer[0]) ;
  1576. *t_Entry = a_RouteEntry ;
  1577. /*
  1578. * Invalidate the route
  1579. */
  1580. t_Entry->ire_type = 2 ;
  1581. TDIObjectID *ID = &(InBuf->ID);
  1582. ID->toi_entity.tei_entity = CL_NL_ENTITY;
  1583. ID->toi_entity.tei_instance = 0;
  1584. ID->toi_class = INFO_CLASS_PROTOCOL;
  1585. ID->toi_type = INFO_TYPE_PROVIDER;
  1586. ID->toi_id = IP_MIB_RTTABLE_ENTRY_ID;
  1587. InBuf->BufferSize = sizeof ( IPRouteEntry );
  1588. IO_STATUS_BLOCK t_IoStatusBlock ;
  1589. t_NtStatus = NtDeviceIoControlFile (
  1590. a_StackHandle ,
  1591. a_CompleteEventHandle ,
  1592. NULL ,
  1593. NULL ,
  1594. &t_IoStatusBlock ,
  1595. IOCTL_TCP_SET_INFORMATION_EX ,
  1596. ( void * ) InBuf,
  1597. InBufLen,
  1598. NULL ,
  1599. 0
  1600. );
  1601. if ( t_NtStatus == STATUS_PENDING )
  1602. {
  1603. t_NtStatus = NtWaitForSingleObject ( a_CompleteEventHandle , FALSE, NULL ) ;
  1604. }
  1605. }
  1606. catch ( ... )
  1607. {
  1608. HeapFree ( GetProcessHeap () , 0, InBuf ) ;
  1609. throw ;
  1610. }
  1611. HeapFree ( GetProcessHeap () , 0, InBuf ) ;
  1612. }
  1613. else
  1614. {
  1615. t_NtStatus = ERROR_NOT_ENOUGH_MEMORY ;
  1616. }
  1617. return t_NtStatus ;
  1618. }
  1619. DWORD CIPRouteTable :: GetPriority ( BSTR a_PropertyName )
  1620. {
  1621. return 0xFFFFFFFF ;
  1622. }
  1623. QueryPreprocessor :: QuadState CIPRouteTable :: Compare (
  1624. LONG a_Operand1 ,
  1625. LONG a_Operand2 ,
  1626. DWORD a_Operand1Func ,
  1627. DWORD a_Operand2Func ,
  1628. WmiTreeNode &a_OperatorType
  1629. )
  1630. {
  1631. QueryPreprocessor :: QuadState t_Status = QueryPreprocessor :: QuadState :: State_True ;
  1632. switch ( a_Operand1Func )
  1633. {
  1634. case WmiValueNode :: WmiValueFunction :: Function_None:
  1635. {
  1636. }
  1637. break ;
  1638. default:
  1639. {
  1640. }
  1641. break ;
  1642. }
  1643. switch ( a_Operand2Func )
  1644. {
  1645. case WmiValueNode :: WmiValueFunction :: Function_None:
  1646. {
  1647. }
  1648. break ;
  1649. default:
  1650. {
  1651. }
  1652. break ;
  1653. }
  1654. if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorEqualNode ) )
  1655. {
  1656. t_Status = a_Operand1 == a_Operand2
  1657. ? QueryPreprocessor :: QuadState :: State_True
  1658. : QueryPreprocessor :: QuadState :: State_False ;
  1659. }
  1660. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorNotEqualNode ) )
  1661. {
  1662. t_Status = a_Operand1 != a_Operand2
  1663. ? QueryPreprocessor :: QuadState :: State_True
  1664. : QueryPreprocessor :: QuadState :: State_False ;
  1665. }
  1666. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorEqualOrGreaterNode ) )
  1667. {
  1668. t_Status = a_Operand1 >= a_Operand2
  1669. ? QueryPreprocessor :: QuadState :: State_True
  1670. : QueryPreprocessor :: QuadState :: State_False ;
  1671. }
  1672. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorEqualOrLessNode ) )
  1673. {
  1674. t_Status = a_Operand1 <= a_Operand2
  1675. ? QueryPreprocessor :: QuadState :: State_True
  1676. : QueryPreprocessor :: QuadState :: State_False ;
  1677. }
  1678. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorLessNode ) )
  1679. {
  1680. t_Status = a_Operand1 < a_Operand2
  1681. ? QueryPreprocessor :: QuadState :: State_True
  1682. : QueryPreprocessor :: QuadState :: State_False ;
  1683. }
  1684. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorGreaterNode ) )
  1685. {
  1686. t_Status = a_Operand1 > a_Operand2
  1687. ? QueryPreprocessor :: QuadState :: State_True
  1688. : QueryPreprocessor :: QuadState :: State_False ;
  1689. }
  1690. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorLikeNode ) )
  1691. {
  1692. }
  1693. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorNotLikeNode ) )
  1694. {
  1695. }
  1696. return t_Status ;
  1697. }
  1698. QueryPreprocessor :: QuadState CIPRouteTable :: Compare (
  1699. wchar_t *a_Operand1 ,
  1700. wchar_t *a_Operand2 ,
  1701. DWORD a_Operand1Func ,
  1702. DWORD a_Operand2Func ,
  1703. WmiTreeNode &a_OperatorType
  1704. )
  1705. {
  1706. QueryPreprocessor :: QuadState t_Status = QueryPreprocessor :: QuadState :: State_True ;
  1707. CHString a_Operand1AfterFunc ;
  1708. CHString a_Operand2AfterFunc ;
  1709. switch ( a_Operand1Func )
  1710. {
  1711. case WmiValueNode :: WmiValueFunction :: Function_None:
  1712. {
  1713. }
  1714. break ;
  1715. case WmiValueNode :: WmiValueFunction :: Function_Upper:
  1716. {
  1717. a_Operand1AfterFunc = a_Operand1 ;
  1718. a_Operand1AfterFunc.MakeUpper () ;
  1719. }
  1720. break ;
  1721. case WmiValueNode :: WmiValueFunction :: Function_Lower:
  1722. {
  1723. a_Operand1AfterFunc = a_Operand1 ;
  1724. a_Operand1AfterFunc.MakeLower () ;
  1725. }
  1726. break ;
  1727. default:
  1728. {
  1729. }
  1730. break ;
  1731. }
  1732. switch ( a_Operand2Func )
  1733. {
  1734. case WmiValueNode :: WmiValueFunction :: Function_None:
  1735. {
  1736. }
  1737. break ;
  1738. case WmiValueNode :: WmiValueFunction :: Function_Upper:
  1739. {
  1740. a_Operand2AfterFunc = a_Operand2 ;
  1741. a_Operand2AfterFunc.MakeUpper () ;
  1742. }
  1743. break ;
  1744. case WmiValueNode :: WmiValueFunction :: Function_Lower:
  1745. {
  1746. a_Operand2AfterFunc = a_Operand2 ;
  1747. a_Operand2AfterFunc.MakeLower () ;
  1748. }
  1749. break ;
  1750. default:
  1751. {
  1752. }
  1753. break ;
  1754. }
  1755. const wchar_t *t_Arg1 = a_Operand1AfterFunc.IsEmpty () ? a_Operand1 : (LPCWSTR)a_Operand1AfterFunc ;
  1756. const wchar_t *t_Arg2 = a_Operand2AfterFunc.IsEmpty () ? a_Operand2 : (LPCWSTR)a_Operand2AfterFunc ;
  1757. if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorEqualNode ) )
  1758. {
  1759. if ( ( t_Arg1 ) && ( t_Arg2 ) )
  1760. {
  1761. t_Status = wcscmp ( t_Arg1 , t_Arg2 ) == 0
  1762. ? QueryPreprocessor :: QuadState :: State_True
  1763. : QueryPreprocessor :: QuadState :: State_False ;
  1764. }
  1765. else
  1766. {
  1767. if ( ( t_Arg1 ) || ( t_Arg2 ) )
  1768. {
  1769. t_Status = QueryPreprocessor :: QuadState :: State_False ;
  1770. }
  1771. else
  1772. {
  1773. t_Status = QueryPreprocessor :: QuadState :: State_True ;
  1774. }
  1775. }
  1776. }
  1777. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorNotEqualNode ) )
  1778. {
  1779. if ( ( t_Arg1 ) && ( t_Arg2 ) )
  1780. {
  1781. t_Status = wcscmp ( t_Arg1 , t_Arg2 ) != 0
  1782. ? QueryPreprocessor :: QuadState :: State_True
  1783. : QueryPreprocessor :: QuadState :: State_False ;
  1784. }
  1785. else
  1786. {
  1787. if ( ( t_Arg1 ) || ( t_Arg2 ) )
  1788. {
  1789. t_Status = QueryPreprocessor :: QuadState :: State_True ;
  1790. }
  1791. else
  1792. {
  1793. t_Status = QueryPreprocessor :: QuadState :: State_False ;
  1794. }
  1795. }
  1796. }
  1797. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorEqualOrGreaterNode ) )
  1798. {
  1799. if ( ( t_Arg1 ) && ( t_Arg2 ) )
  1800. {
  1801. t_Status = wcscmp ( t_Arg1 , t_Arg2 ) >= 0
  1802. ? QueryPreprocessor :: QuadState :: State_True
  1803. : QueryPreprocessor :: QuadState :: State_False ;
  1804. }
  1805. else
  1806. {
  1807. if ( t_Arg1 )
  1808. {
  1809. t_Status = QueryPreprocessor :: QuadState :: State_True ;
  1810. }
  1811. else
  1812. {
  1813. if ( t_Arg2 )
  1814. {
  1815. t_Status = QueryPreprocessor :: QuadState :: State_False ;
  1816. }
  1817. else
  1818. {
  1819. t_Status = QueryPreprocessor :: QuadState :: State_True ;
  1820. }
  1821. }
  1822. }
  1823. }
  1824. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorEqualOrLessNode ) )
  1825. {
  1826. if ( ( t_Arg1 ) && ( t_Arg2 ) )
  1827. {
  1828. t_Status = wcscmp ( t_Arg1 , t_Arg2 ) <= 0
  1829. ? QueryPreprocessor :: QuadState :: State_True
  1830. : QueryPreprocessor :: QuadState :: State_False ;
  1831. }
  1832. else
  1833. {
  1834. if ( ( t_Arg1 ) )
  1835. {
  1836. t_Status = QueryPreprocessor :: QuadState :: State_False ;
  1837. }
  1838. else
  1839. {
  1840. if ( t_Arg2 )
  1841. {
  1842. t_Status = QueryPreprocessor :: QuadState :: State_True ;
  1843. }
  1844. else
  1845. {
  1846. t_Status = QueryPreprocessor :: QuadState :: State_True ;
  1847. }
  1848. }
  1849. }
  1850. }
  1851. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorLessNode ) )
  1852. {
  1853. if ( ( t_Arg1 ) && ( t_Arg2 ) )
  1854. {
  1855. t_Status = wcscmp ( t_Arg1 , t_Arg2 ) < 0
  1856. ? QueryPreprocessor :: QuadState :: State_True
  1857. : QueryPreprocessor :: QuadState :: State_False ;
  1858. }
  1859. else
  1860. {
  1861. if ( ( ! t_Arg1 ) && ( ! t_Arg2 ) )
  1862. {
  1863. t_Status = QueryPreprocessor :: QuadState :: State_False ;
  1864. }
  1865. else if ( t_Arg1 )
  1866. {
  1867. t_Status = QueryPreprocessor :: QuadState :: State_False ;
  1868. }
  1869. else
  1870. {
  1871. t_Status = QueryPreprocessor :: QuadState :: State_True ;
  1872. }
  1873. }
  1874. }
  1875. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorGreaterNode ) )
  1876. {
  1877. if ( ( t_Arg1 ) && ( t_Arg2 ) )
  1878. {
  1879. t_Status = wcscmp ( t_Arg1 , t_Arg2 ) > 0
  1880. ? QueryPreprocessor :: QuadState :: State_True
  1881. : QueryPreprocessor :: QuadState :: State_False ;
  1882. }
  1883. else
  1884. {
  1885. if ( ( ! t_Arg1 ) && ( ! t_Arg2 ) )
  1886. {
  1887. t_Status = QueryPreprocessor :: QuadState :: State_False ;
  1888. }
  1889. else if ( t_Arg1 )
  1890. {
  1891. t_Status = QueryPreprocessor :: QuadState :: State_True ;
  1892. }
  1893. else
  1894. {
  1895. t_Status = QueryPreprocessor :: QuadState :: State_False ;
  1896. }
  1897. }
  1898. }
  1899. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorLikeNode ) )
  1900. {
  1901. }
  1902. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorNotLikeNode ) )
  1903. {
  1904. }
  1905. return t_Status ;
  1906. }
  1907. QueryPreprocessor :: QuadState CIPRouteTable :: CompareString (
  1908. IWbemClassObject *a_ClassObject ,
  1909. BSTR a_PropertyName ,
  1910. WmiTreeNode *a_Operator ,
  1911. WmiTreeNode *a_Operand
  1912. )
  1913. {
  1914. QueryPreprocessor :: QuadState t_Status = QueryPreprocessor :: QuadState :: State_True ;
  1915. WmiStringNode *t_StringNode = ( WmiStringNode * ) a_Operand ;
  1916. VARIANT t_Variant ;
  1917. VariantInit ( & t_Variant ) ;
  1918. HRESULT t_Result = a_ClassObject->Get ( a_PropertyName , 0 , &t_Variant , NULL , NULL ) ;
  1919. if ( SUCCEEDED ( t_Result ) )
  1920. {
  1921. t_Status = Compare (
  1922. t_StringNode->GetValue () ,
  1923. t_Variant.bstrVal ,
  1924. t_StringNode->GetPropertyFunction () ,
  1925. t_StringNode->GetConstantFunction () ,
  1926. *a_Operator
  1927. ) ;
  1928. }
  1929. VariantClear ( & t_Variant ) ;
  1930. return t_Status ;
  1931. }
  1932. QueryPreprocessor :: QuadState CIPRouteTable :: CompareInteger (
  1933. IWbemClassObject *a_ClassObject ,
  1934. BSTR a_PropertyName ,
  1935. WmiTreeNode *a_Operator ,
  1936. WmiTreeNode *a_Operand
  1937. )
  1938. {
  1939. QueryPreprocessor :: QuadState t_Status = QueryPreprocessor :: QuadState :: State_True ;
  1940. WmiSignedIntegerNode *t_IntegerNode = ( WmiSignedIntegerNode * ) a_Operand ;
  1941. VARIANT t_Variant ;
  1942. VariantInit ( & t_Variant ) ;
  1943. HRESULT t_Result = a_ClassObject->Get ( a_PropertyName , 0 , &t_Variant , NULL , NULL ) ;
  1944. if ( SUCCEEDED ( t_Result ) )
  1945. {
  1946. t_Status = Compare (
  1947. t_IntegerNode->GetValue () ,
  1948. t_Variant.lVal ,
  1949. t_IntegerNode->GetPropertyFunction () ,
  1950. t_IntegerNode->GetConstantFunction () ,
  1951. *a_Operator
  1952. ) ;
  1953. }
  1954. VariantClear ( & t_Variant ) ;
  1955. return t_Status ;
  1956. }
  1957. WmiTreeNode *CIPRouteTable :: AllocTypeNode (
  1958. void *a_Context ,
  1959. BSTR a_PropertyName ,
  1960. VARIANT &a_Variant ,
  1961. WmiValueNode :: WmiValueFunction a_PropertyFunction ,
  1962. WmiValueNode :: WmiValueFunction a_ConstantFunction ,
  1963. WmiTreeNode *a_Parent
  1964. )
  1965. {
  1966. WmiTreeNode *t_Node = NULL ;
  1967. VARTYPE t_VarType = VT_NULL ;
  1968. if ( *a_PropertyName == L'_' )
  1969. {
  1970. // System property
  1971. if ( _wcsicmp ( a_PropertyName , SYSTEM_PROPERTY_CLASS ) == 0 &&
  1972. (V_VT(&a_Variant) == VT_BSTR))
  1973. {
  1974. t_Node = new WmiStringNode (
  1975. a_PropertyName ,
  1976. a_Variant.bstrVal ,
  1977. a_PropertyFunction ,
  1978. a_ConstantFunction ,
  1979. 0xFFFFFFFF ,
  1980. a_Parent
  1981. ) ;
  1982. }
  1983. else if ( _wcsicmp ( a_PropertyName , SYSTEM_PROPERTY_SUPERCLASS ) == 0 &&
  1984. (V_VT(&a_Variant) == VT_BSTR))
  1985. {
  1986. t_Node = new WmiStringNode (
  1987. a_PropertyName ,
  1988. a_Variant.bstrVal ,
  1989. a_PropertyFunction ,
  1990. a_ConstantFunction ,
  1991. 0xFFFFFFFF ,
  1992. a_Parent
  1993. ) ;
  1994. }
  1995. else if ( _wcsicmp ( a_PropertyName , SYSTEM_PROPERTY_GENUS ) == 0 &&
  1996. (V_VT(&a_Variant) == VT_I4))
  1997. {
  1998. t_Node = new WmiSignedIntegerNode (
  1999. a_PropertyName ,
  2000. a_Variant.lVal,
  2001. 0xFFFFFFFF ,
  2002. a_Parent
  2003. ) ;
  2004. }
  2005. else if ( _wcsicmp ( a_PropertyName , SYSTEM_PROPERTY_SERVER ) == 0 &&
  2006. (V_VT(&a_Variant) == VT_BSTR))
  2007. {
  2008. t_Node = new WmiStringNode (
  2009. a_PropertyName ,
  2010. a_Variant.bstrVal ,
  2011. a_PropertyFunction ,
  2012. a_ConstantFunction ,
  2013. 0xFFFFFFFF ,
  2014. a_Parent
  2015. ) ;
  2016. }
  2017. else if ( _wcsicmp ( a_PropertyName , SYSTEM_PROPERTY_NAMESPACE ) == 0 &&
  2018. (V_VT(&a_Variant) == VT_BSTR))
  2019. {
  2020. t_Node = new WmiStringNode (
  2021. a_PropertyName ,
  2022. a_Variant.bstrVal ,
  2023. a_PropertyFunction ,
  2024. a_ConstantFunction ,
  2025. 0xFFFFFFFF ,
  2026. a_Parent
  2027. ) ;
  2028. }
  2029. else if ( _wcsicmp ( a_PropertyName , SYSTEM_PROPERTY_PROPERTY_COUNT ) == 0 &&
  2030. (V_VT(&a_Variant) == VT_I4))
  2031. {
  2032. t_Node = new WmiSignedIntegerNode (
  2033. a_PropertyName ,
  2034. a_Variant.lVal ,
  2035. 0xFFFFFFFF ,
  2036. a_Parent
  2037. ) ;
  2038. }
  2039. else if ( _wcsicmp ( a_PropertyName , SYSTEM_PROPERTY_DYNASTY ) == 0 &&
  2040. (V_VT(&a_Variant) == VT_BSTR))
  2041. {
  2042. t_Node = new WmiStringNode (
  2043. a_PropertyName ,
  2044. a_Variant.bstrVal ,
  2045. a_PropertyFunction ,
  2046. a_ConstantFunction ,
  2047. 0xFFFFFFFF ,
  2048. a_Parent
  2049. ) ;
  2050. }
  2051. else if ( _wcsicmp ( a_PropertyName , SYSTEM_PROPERTY_RELPATH ) == 0 &&
  2052. (V_VT(&a_Variant) == VT_BSTR))
  2053. {
  2054. t_Node = new WmiStringNode (
  2055. a_PropertyName ,
  2056. a_Variant.bstrVal ,
  2057. a_PropertyFunction ,
  2058. a_ConstantFunction ,
  2059. 0xFFFFFFFF ,
  2060. a_Parent
  2061. ) ;
  2062. }
  2063. else if ( _wcsicmp ( a_PropertyName , SYSTEM_PROPERTY_PATH ) == 0 &&
  2064. (V_VT(&a_Variant) == VT_BSTR))
  2065. {
  2066. t_Node = new WmiStringNode (
  2067. a_PropertyName ,
  2068. a_Variant.bstrVal ,
  2069. a_PropertyFunction ,
  2070. a_ConstantFunction ,
  2071. 0xFFFFFFFF ,
  2072. a_Parent
  2073. ) ;
  2074. }
  2075. else if ( _wcsicmp ( a_PropertyName , SYSTEM_PROPERTY_DERIVATION ) == 0 )
  2076. {
  2077. }
  2078. }
  2079. else
  2080. {
  2081. CInstance *t_ClassObject = NULL ;
  2082. HRESULT t_Result = GetClassObject ( t_ClassObject, (MethodContext *)a_Context ) ;
  2083. if ( SUCCEEDED ( t_Result ) )
  2084. {
  2085. IWbemClassObjectPtr t_pClas ( t_ClassObject->GetClassObjectInterface () , false ) ;
  2086. if ( t_pClas != NULL )
  2087. {
  2088. CIMTYPE t_VarType ;
  2089. long t_Flavour ;
  2090. VARIANT t_Variant ;
  2091. VariantInit ( & t_Variant ) ;
  2092. HRESULT t_Result = t_pClas->Get (
  2093. a_PropertyName ,
  2094. 0 ,
  2095. & t_Variant ,
  2096. & t_VarType ,
  2097. & t_Flavour
  2098. );
  2099. if ( SUCCEEDED ( t_Result ) )
  2100. {
  2101. if ( t_VarType & CIM_FLAG_ARRAY )
  2102. {
  2103. }
  2104. else
  2105. {
  2106. switch ( t_VarType & ( ~ CIM_FLAG_ARRAY ) )
  2107. {
  2108. case CIM_BOOLEAN:
  2109. {
  2110. if(V_VT(&a_Variant) == VT_I4)
  2111. {
  2112. t_Node = new WmiSignedIntegerNode (
  2113. a_PropertyName ,
  2114. a_Variant.lVal ,
  2115. GetPriority ( a_PropertyName ) ,
  2116. a_Parent
  2117. ) ;
  2118. }
  2119. else if (V_VT(&a_Variant) == VT_BOOL)
  2120. {
  2121. t_Node = new WmiSignedIntegerNode (
  2122. a_PropertyName ,
  2123. (a_Variant.lVal == VARIANT_FALSE) ? 0 : 1,
  2124. GetPriority ( a_PropertyName ) ,
  2125. a_Parent
  2126. ) ;
  2127. }
  2128. else if (V_VT(&a_Variant) == VT_NULL)
  2129. {
  2130. t_Node = new WmiNullNode (
  2131. a_PropertyName ,
  2132. GetPriority ( a_PropertyName ) ,
  2133. a_Parent
  2134. );
  2135. }
  2136. }
  2137. break ;
  2138. case CIM_SINT8:
  2139. case CIM_SINT16:
  2140. case CIM_CHAR16:
  2141. case CIM_SINT32:
  2142. {
  2143. if(V_VT(&a_Variant) == VT_I4)
  2144. {
  2145. t_Node = new WmiSignedIntegerNode (
  2146. a_PropertyName ,
  2147. a_Variant.lVal ,
  2148. GetPriority ( a_PropertyName ) ,
  2149. a_Parent
  2150. ) ;
  2151. }
  2152. else if (V_VT(&a_Variant) == VT_NULL)
  2153. {
  2154. t_Node = new WmiNullNode (
  2155. a_PropertyName ,
  2156. GetPriority ( a_PropertyName ) ,
  2157. a_Parent
  2158. );
  2159. }
  2160. }
  2161. break ;
  2162. case CIM_UINT8:
  2163. case CIM_UINT16:
  2164. case CIM_UINT32:
  2165. {
  2166. if(V_VT(&a_Variant) == VT_I4)
  2167. {
  2168. t_Node = new WmiUnsignedIntegerNode (
  2169. a_PropertyName ,
  2170. a_Variant.lVal ,
  2171. GetPriority ( a_PropertyName ) ,
  2172. a_Parent
  2173. ) ;
  2174. }
  2175. else if (V_VT(&a_Variant) == VT_NULL)
  2176. {
  2177. t_Node = new WmiNullNode (
  2178. a_PropertyName ,
  2179. GetPriority ( a_PropertyName ) ,
  2180. a_Parent
  2181. );
  2182. }
  2183. }
  2184. break ;
  2185. case CIM_SINT64:
  2186. case CIM_UINT64:
  2187. {
  2188. if(V_VT(&a_Variant) == VT_BSTR)
  2189. {
  2190. t_Node = new WmiStringNode (
  2191. a_PropertyName ,
  2192. a_Variant.bstrVal ,
  2193. a_PropertyFunction ,
  2194. a_ConstantFunction ,
  2195. GetPriority ( a_PropertyName ) ,
  2196. a_Parent
  2197. ) ;
  2198. }
  2199. else if(V_VT(&a_Variant) == VT_I4)
  2200. {
  2201. _variant_t t_uintBuff (&a_Variant);
  2202. t_Node = new WmiStringNode (
  2203. a_PropertyName ,
  2204. (BSTR)((_bstr_t) t_uintBuff),
  2205. a_PropertyFunction ,
  2206. a_ConstantFunction ,
  2207. GetPriority ( a_PropertyName ) ,
  2208. a_Parent
  2209. ) ;
  2210. }
  2211. else if (V_VT(&a_Variant) == VT_NULL)
  2212. {
  2213. t_Node = new WmiNullNode (
  2214. a_PropertyName ,
  2215. GetPriority ( a_PropertyName ) ,
  2216. a_Parent
  2217. );
  2218. }
  2219. }
  2220. break ;
  2221. case CIM_STRING:
  2222. case CIM_DATETIME:
  2223. case CIM_REFERENCE:
  2224. {
  2225. if(V_VT(&a_Variant) == VT_BSTR)
  2226. {
  2227. t_Node = new WmiStringNode (
  2228. a_PropertyName ,
  2229. a_Variant.bstrVal ,
  2230. a_PropertyFunction ,
  2231. a_ConstantFunction ,
  2232. GetPriority ( a_PropertyName ) ,
  2233. a_Parent
  2234. ) ;
  2235. }
  2236. else if (V_VT(&a_Variant) == VT_NULL)
  2237. {
  2238. t_Node = new WmiNullNode (
  2239. a_PropertyName ,
  2240. GetPriority ( a_PropertyName ) ,
  2241. a_Parent
  2242. );
  2243. }
  2244. }
  2245. break ;
  2246. case CIM_REAL32:
  2247. case CIM_REAL64:
  2248. {
  2249. }
  2250. break ;
  2251. case CIM_OBJECT:
  2252. case CIM_EMPTY:
  2253. {
  2254. }
  2255. break ;
  2256. default:
  2257. {
  2258. }
  2259. break ;
  2260. }
  2261. }
  2262. }
  2263. VariantClear ( & t_Variant ) ;
  2264. }
  2265. t_ClassObject->Release () ;
  2266. }
  2267. }
  2268. return t_Node ;
  2269. }
  2270. QueryPreprocessor :: QuadState CIPRouteTable :: InvariantEvaluate (
  2271. void *a_Context ,
  2272. WmiTreeNode *a_Operator ,
  2273. WmiTreeNode *a_Operand
  2274. )
  2275. {
  2276. /*
  2277. * If property and value are invariant i.e. will never change for all instances then return State_True.
  2278. * If property is not indexable or keyed then return State_True to define an unknown number of possible values which we cannot optimise against.
  2279. * If property and value can never occur then return State_False to imply empty set
  2280. * If property and value do not infer anything then return State_Undefined.
  2281. * If property and value are in error then return State_Error
  2282. * Never return State_ReEvaluate.
  2283. */
  2284. QueryPreprocessor :: QuadState t_State = QueryPreprocessor :: QuadState :: State_Error ;
  2285. CInstance *t_ClassObject = NULL ;
  2286. HRESULT t_Result = GetClassObject ( t_ClassObject, (MethodContext *)a_Context ) ;
  2287. if ( SUCCEEDED ( t_Result ) )
  2288. {
  2289. IWbemClassObjectPtr t_pClas(t_ClassObject->GetClassObjectInterface (), false );
  2290. if (t_pClas != NULL)
  2291. {
  2292. WmiValueNode *t_Node = ( WmiValueNode * ) a_Operand ;
  2293. BSTR t_PropertyName = t_Node->GetPropertyName () ;
  2294. if ( t_PropertyName != NULL )
  2295. {
  2296. if ( *t_PropertyName == L'_' )
  2297. {
  2298. // System property, must check values
  2299. if ( _wcsicmp ( t_PropertyName , SYSTEM_PROPERTY_CLASS ) == 0 )
  2300. {
  2301. t_State = CompareString (
  2302. t_pClas ,
  2303. SYSTEM_PROPERTY_CLASS ,
  2304. a_Operator ,
  2305. a_Operand
  2306. ) ;
  2307. }
  2308. else if ( _wcsicmp ( t_PropertyName , SYSTEM_PROPERTY_SUPERCLASS ) == 0 )
  2309. {
  2310. t_State = CompareString (
  2311. t_pClas ,
  2312. SYSTEM_PROPERTY_SUPERCLASS ,
  2313. a_Operator ,
  2314. a_Operand
  2315. ) ;
  2316. }
  2317. else if ( _wcsicmp ( t_PropertyName , SYSTEM_PROPERTY_GENUS ) == 0 )
  2318. {
  2319. t_State = CompareInteger (
  2320. t_pClas ,
  2321. SYSTEM_PROPERTY_GENUS ,
  2322. a_Operator ,
  2323. a_Operand
  2324. ) ;
  2325. }
  2326. else if ( _wcsicmp ( t_PropertyName , SYSTEM_PROPERTY_SERVER ) == 0 )
  2327. {
  2328. t_State = CompareString (
  2329. t_pClas ,
  2330. SYSTEM_PROPERTY_SERVER ,
  2331. a_Operator ,
  2332. a_Operand
  2333. ) ;
  2334. }
  2335. else if ( _wcsicmp ( t_PropertyName , SYSTEM_PROPERTY_NAMESPACE ) == 0 )
  2336. {
  2337. t_State = CompareString (
  2338. t_pClas ,
  2339. SYSTEM_PROPERTY_NAMESPACE ,
  2340. a_Operator ,
  2341. a_Operand
  2342. ) ;
  2343. }
  2344. else if ( _wcsicmp ( t_PropertyName , SYSTEM_PROPERTY_PROPERTY_COUNT ) == 0 )
  2345. {
  2346. t_State = CompareInteger (
  2347. t_pClas ,
  2348. SYSTEM_PROPERTY_PROPERTY_COUNT ,
  2349. a_Operator ,
  2350. a_Operand
  2351. ) ;
  2352. }
  2353. else if ( _wcsicmp ( t_PropertyName , SYSTEM_PROPERTY_DYNASTY ) == 0 )
  2354. {
  2355. t_State = CompareString (
  2356. t_pClas ,
  2357. SYSTEM_PROPERTY_DYNASTY ,
  2358. a_Operator ,
  2359. a_Operand
  2360. ) ;
  2361. }
  2362. else if ( _wcsicmp ( t_PropertyName , SYSTEM_PROPERTY_RELPATH ) == 0 )
  2363. {
  2364. t_State = CompareString (
  2365. t_pClas ,
  2366. SYSTEM_PROPERTY_RELPATH ,
  2367. a_Operator ,
  2368. a_Operand
  2369. ) ;
  2370. }
  2371. else if ( _wcsicmp ( t_PropertyName , SYSTEM_PROPERTY_PATH ) == 0 )
  2372. {
  2373. t_State = CompareString (
  2374. t_pClas ,
  2375. SYSTEM_PROPERTY_PATH ,
  2376. a_Operator ,
  2377. a_Operand
  2378. ) ;
  2379. }
  2380. else if ( _wcsicmp ( t_PropertyName , SYSTEM_PROPERTY_DERIVATION ) == 0 )
  2381. {
  2382. t_State = QueryPreprocessor :: QuadState :: State_Undefined ;
  2383. }
  2384. else
  2385. {
  2386. t_State = QueryPreprocessor :: QuadState :: State_Undefined ;
  2387. }
  2388. }
  2389. else
  2390. {
  2391. if ( typeid ( *a_Operand ) == typeid ( WmiNullNode ) )
  2392. {
  2393. t_State = QueryPreprocessor :: QuadState :: State_True ;
  2394. }
  2395. else
  2396. {
  2397. t_State = QueryPreprocessor :: QuadState :: State_Undefined ;
  2398. }
  2399. #if 0
  2400. else if ( typeid ( *a_Operand ) == typeid ( WmiStringNode ) )
  2401. {
  2402. t_State = QueryPreprocessor :: QuadState :: State_Undefined ;
  2403. }
  2404. else if ( typeid ( *a_Operand ) == typeid ( WmiUnsignedIntegerNode ) )
  2405. {
  2406. t_State = QueryPreprocessor :: QuadState :: State_Undefined ;
  2407. }
  2408. else if ( typeid ( *a_Operand ) == typeid ( WmiSignedIntegerNode ) )
  2409. {
  2410. t_State = QueryPreprocessor :: QuadState :: State_Undefined ;
  2411. }
  2412. if ( typeid ( *a_Operator ) == typeid ( WmiOperatorEqualNode ) )
  2413. {
  2414. t_State = QueryPreprocessor :: QuadState :: State_Undefined ;
  2415. }
  2416. else if ( typeid ( *a_Operator ) == typeid ( WmiOperatorNotEqualNode ) )
  2417. {
  2418. t_State = QueryPreprocessor :: QuadState :: State_Undefined ;
  2419. }
  2420. else if ( typeid ( *a_Operator ) == typeid ( WmiOperatorEqualOrGreaterNode ) )
  2421. {
  2422. t_State = QueryPreprocessor :: QuadState :: State_Undefined ;
  2423. }
  2424. else if ( typeid ( *a_Operator ) == typeid ( WmiOperatorEqualOrLessNode ) )
  2425. {
  2426. t_State = QueryPreprocessor :: QuadState :: State_Undefined ;
  2427. }
  2428. else if ( typeid ( *a_Operator ) == typeid ( WmiOperatorLessNode ) )
  2429. {
  2430. t_State = QueryPreprocessor :: QuadState :: State_Undefined ;
  2431. }
  2432. else if ( typeid ( *a_Operator ) == typeid ( WmiOperatorGreaterNode ) )
  2433. {
  2434. t_State = QueryPreprocessor :: QuadState :: State_Undefined ;
  2435. }
  2436. else if ( typeid ( *a_Operator ) == typeid ( WmiOperatorLikeNode ) )
  2437. {
  2438. t_State = QueryPreprocessor :: QuadState :: State_Undefined ;
  2439. }
  2440. else if ( typeid ( *a_Operator ) == typeid ( WmiOperatorNotLikeNode ) )
  2441. {
  2442. t_State = QueryPreprocessor :: QuadState :: State_Undefined ;
  2443. }
  2444. #endif
  2445. }
  2446. }
  2447. else
  2448. {
  2449. t_State = QueryPreprocessor :: QuadState :: State_Undefined ;
  2450. }
  2451. }
  2452. t_ClassObject->Release();
  2453. }
  2454. return t_State ;
  2455. }
  2456. WmiRangeNode *CIPRouteTable :: AllocInfiniteRangeNode (
  2457. void *a_Context ,
  2458. BSTR a_PropertyName
  2459. )
  2460. {
  2461. WmiRangeNode *t_RangeNode = NULL ;
  2462. CInstance *t_ClassObject = NULL ;
  2463. HRESULT t_Result = GetClassObject ( t_ClassObject, (MethodContext *)a_Context ) ;
  2464. if ( SUCCEEDED ( t_Result ) )
  2465. {
  2466. IWbemClassObjectPtr t_pClas ( t_ClassObject->GetClassObjectInterface () , false ) ;
  2467. if ( t_pClas != NULL )
  2468. {
  2469. CIMTYPE t_VarType ;
  2470. long t_Flavour ;
  2471. VARIANT t_Variant ;
  2472. VariantInit ( & t_Variant ) ;
  2473. HRESULT t_Result = t_pClas->Get (
  2474. a_PropertyName ,
  2475. 0 ,
  2476. & t_Variant ,
  2477. & t_VarType ,
  2478. & t_Flavour
  2479. );
  2480. if ( SUCCEEDED ( t_Result ) )
  2481. {
  2482. if ( t_VarType & CIM_FLAG_ARRAY )
  2483. {
  2484. }
  2485. else
  2486. {
  2487. switch ( t_VarType & ( ~ CIM_FLAG_ARRAY ) )
  2488. {
  2489. case CIM_BOOLEAN:
  2490. case CIM_SINT8:
  2491. case CIM_SINT16:
  2492. case CIM_CHAR16:
  2493. case CIM_SINT32:
  2494. {
  2495. t_RangeNode = new WmiSignedIntegerRangeNode (
  2496. a_PropertyName ,
  2497. 0xFFFFFFFF ,
  2498. TRUE ,
  2499. TRUE ,
  2500. FALSE ,
  2501. FALSE ,
  2502. 0 ,
  2503. 0 ,
  2504. NULL ,
  2505. NULL
  2506. ) ;
  2507. }
  2508. break ;
  2509. case CIM_UINT8:
  2510. case CIM_UINT16:
  2511. case CIM_UINT32:
  2512. {
  2513. t_RangeNode = new WmiUnsignedIntegerRangeNode (
  2514. a_PropertyName ,
  2515. 0xFFFFFFFF ,
  2516. TRUE ,
  2517. TRUE ,
  2518. FALSE ,
  2519. FALSE ,
  2520. 0 ,
  2521. 0 ,
  2522. NULL ,
  2523. NULL
  2524. ) ;
  2525. }
  2526. break ;
  2527. case CIM_SINT64:
  2528. case CIM_UINT64:
  2529. case CIM_STRING:
  2530. case CIM_DATETIME:
  2531. case CIM_REFERENCE:
  2532. {
  2533. t_RangeNode = new WmiStringRangeNode (
  2534. a_PropertyName ,
  2535. 0x0 ,
  2536. TRUE ,
  2537. TRUE ,
  2538. FALSE ,
  2539. FALSE ,
  2540. NULL ,
  2541. NULL ,
  2542. NULL ,
  2543. NULL
  2544. ) ;
  2545. }
  2546. break ;
  2547. case CIM_REAL32:
  2548. case CIM_REAL64:
  2549. {
  2550. }
  2551. break ;
  2552. case CIM_OBJECT:
  2553. case CIM_EMPTY:
  2554. {
  2555. }
  2556. break ;
  2557. default:
  2558. {
  2559. }
  2560. break ;
  2561. }
  2562. }
  2563. }
  2564. VariantClear ( & t_Variant ) ;
  2565. }
  2566. t_ClassObject->Release () ;
  2567. }
  2568. return t_RangeNode ;
  2569. }
  2570. HRESULT CIPRouteTable :: GetClassObject ( CInstance *&a_ClassObject, MethodContext *a_Context )
  2571. {
  2572. HRESULT t_Result = S_OK ;
  2573. EnterCriticalSection( &m_CS ) ;
  2574. try
  2575. {
  2576. if ( m_ClassCInst == NULL )
  2577. {
  2578. t_Result = WBEM_E_FAILED ;
  2579. }
  2580. }
  2581. catch(...)
  2582. {
  2583. LeaveCriticalSection( &m_CS );
  2584. throw;
  2585. }
  2586. LeaveCriticalSection( &m_CS );
  2587. if (t_Result == WBEM_E_FAILED)
  2588. {
  2589. CHString t_Namespace ( GetNamespace () ) ;
  2590. CHString t_ComputerName ( GetLocalComputerName () ) ;
  2591. CHString t_ClassName ( GetProviderName () ) ;
  2592. CHString t_AbsPath = L"\\\\" + t_ComputerName + L"\\" + t_Namespace + L":" + t_ClassName ;
  2593. t_Result = CWbemProviderGlue :: GetInstanceByPath ( ( LPCTSTR ) t_AbsPath.GetBuffer ( 0 ) , & a_ClassObject, a_Context ) ;
  2594. if ( SUCCEEDED (t_Result) )
  2595. {
  2596. EnterCriticalSection( &m_CS ) ;
  2597. try
  2598. {
  2599. if ( m_ClassCInst == NULL )
  2600. {
  2601. m_ClassCInst = a_ClassObject ;
  2602. m_ClassCInst->AddRef();
  2603. }
  2604. }
  2605. catch(...)
  2606. {
  2607. LeaveCriticalSection( &m_CS );
  2608. throw;
  2609. }
  2610. LeaveCriticalSection( &m_CS );
  2611. }
  2612. }
  2613. else
  2614. {
  2615. a_ClassObject = m_ClassCInst;
  2616. a_ClassObject->AddRef();
  2617. }
  2618. return t_Result ;
  2619. }
  2620. void CIPRouteTable :: SetInheritedProperties (
  2621. LPCWSTR a_dest ,
  2622. LPCWSTR a_gateway ,
  2623. LPCWSTR a_mask ,
  2624. CInstance &a_Instance
  2625. )
  2626. {
  2627. CHString t_temp( a_dest ) ;
  2628. a_Instance.SetCHString ( RouteName, t_temp ) ;
  2629. a_Instance.SetCHString ( RouteCaption, t_temp ) ;
  2630. t_temp = t_temp + ROUTE_DESCRIPTION_SEP + a_mask + ROUTE_DESCRIPTION_SEP + a_gateway;
  2631. a_Instance.SetCHString ( RouteDescription, t_temp ) ;
  2632. }