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.

1567 lines
36 KiB

  1. /******************************************************************
  2. Session.CPP -- C provider class implementation
  3. Copyright (c) 2000-2001 Microsoft Corporation, All Rights Reserved
  4. Description: Session Provider
  5. ******************************************************************/
  6. #include "precomp.h"
  7. #include "Session.h"
  8. CSession MyCSession (
  9. PROVIDER_NAME_SESSION ,
  10. Namespace
  11. ) ;
  12. /*****************************************************************************
  13. *
  14. * FUNCTION : CSession::CSession
  15. *
  16. * DESCRIPTION : Constructor
  17. *
  18. *****************************************************************************/
  19. CSession :: CSession (
  20. LPCWSTR lpwszName,
  21. LPCWSTR lpwszNameSpace
  22. ) : Provider ( lpwszName , lpwszNameSpace )
  23. {
  24. }
  25. /*****************************************************************************
  26. *
  27. * FUNCTION : CSession::~CSession
  28. *
  29. * DESCRIPTION : Destructor
  30. *
  31. *****************************************************************************/
  32. CSession :: ~CSession ()
  33. {
  34. }
  35. /*****************************************************************************
  36. *
  37. * FUNCTION : CSession::EnumerateInstances
  38. *
  39. * DESCRIPTION : Returns all the instances of this class.
  40. *
  41. *****************************************************************************/
  42. HRESULT CSession :: EnumerateInstances (
  43. MethodContext *pMethodContext,
  44. long lFlags
  45. )
  46. {
  47. HRESULT hRes = WBEM_S_NO_ERROR ;
  48. DWORD dwPropertiesReq = SESSION_ALL_PROPS;
  49. #ifdef NTONLY
  50. hRes = EnumNTSessionInfo (
  51. NULL,
  52. NULL,
  53. 502,
  54. pMethodContext,
  55. dwPropertiesReq
  56. );
  57. #endif
  58. #if 0
  59. #ifdef WIN9XONLY
  60. hRes = Enum9XSessionInfo (
  61. 50,
  62. pMethodContext,
  63. dwPropertiesReq
  64. );
  65. #endif
  66. #endif // #if 0
  67. return hRes ;
  68. }
  69. /*****************************************************************************
  70. *
  71. * FUNCTION : CSession::GetObject
  72. *
  73. * DESCRIPTION : Find a single instance based on the key properties for the
  74. * class.
  75. *
  76. *****************************************************************************/
  77. HRESULT CSession :: GetObject (
  78. CInstance *pInstance,
  79. long lFlags ,
  80. CFrameworkQuery &Query
  81. )
  82. {
  83. HRESULT hRes = WBEM_S_NO_ERROR;
  84. CHString t_ComputerName ;
  85. CHString t_UserName;
  86. if ( pInstance->GetCHString ( IDS_ComputerName , t_ComputerName ) == FALSE )
  87. {
  88. hRes = WBEM_E_INVALID_PARAMETER ;
  89. }
  90. if ( SUCCEEDED ( hRes ) )
  91. {
  92. if ( pInstance->GetCHString ( IDS_UserName , t_UserName ) == FALSE )
  93. {
  94. hRes = WBEM_E_INVALID_PARAMETER ;
  95. }
  96. }
  97. if ( SUCCEEDED ( hRes ) )
  98. {
  99. DWORD dwPropertiesReq = 0;
  100. if ( Query.AllPropertiesAreRequired () )
  101. {
  102. dwPropertiesReq = SESSION_ALL_PROPS;
  103. }
  104. else
  105. {
  106. SetPropertiesReq ( Query,dwPropertiesReq );
  107. }
  108. short t_Level;
  109. #ifdef NTONLY
  110. GetNTLevelInfo ( dwPropertiesReq, &t_Level );
  111. hRes = FindAndSetNTSession ( t_ComputerName, t_UserName.GetBuffer(0), t_Level, dwPropertiesReq, pInstance, Get );
  112. #endif
  113. #if 0
  114. #ifdef WIN9XONLY
  115. Get9XLevelInfo ( dwPropertiesReq, &t_Level );
  116. hRes = FindAndSet9XSession ( t_ComputerName, t_UserName, t_Level, dwPropertiesReq, pInstance, Get );
  117. #endif
  118. #endif // #if 0
  119. }
  120. return hRes ;
  121. }
  122. /*****************************************************************************
  123. *
  124. * FUNCTION : CSession:: DeleteInstance
  125. *
  126. * DESCRIPTION : Deletes an Session if it exists
  127. *
  128. *****************************************************************************/
  129. HRESULT CSession :: DeleteInstance (
  130. const CInstance &Instance,
  131. long lFlags
  132. )
  133. {
  134. HRESULT hRes = WBEM_S_NO_ERROR;
  135. CHString t_ComputerName ;
  136. CHString t_UserName;
  137. if ( Instance.GetCHString ( IDS_ComputerName , t_ComputerName ) == FALSE )
  138. {
  139. hRes = WBEM_E_INVALID_PARAMETER ;
  140. }
  141. if ( SUCCEEDED ( hRes ) )
  142. {
  143. if ( Instance.GetCHString ( IDS_UserName , t_UserName ) == FALSE )
  144. {
  145. hRes = WBEM_E_INVALID_PARAMETER ;
  146. }
  147. }
  148. if ( SUCCEEDED ( hRes ) )
  149. {
  150. CInstancePtr pInstance; // This will not be used in this method.
  151. #ifdef NTONLY
  152. hRes = FindAndSetNTSession ( t_ComputerName, t_UserName.GetBuffer(0), 10, 0, pInstance, Delete );
  153. #endif
  154. #if 0
  155. #ifdef WIN9XONLY
  156. hRes = FindAndSet9XSession ( t_ComputerName, t_UserName, 50, 0, pInstance, Delete );
  157. #endif
  158. #endif // #if 0
  159. }
  160. return hRes ;
  161. }
  162. /*****************************************************************************
  163. *
  164. * FUNCTION : CSession::ExecQuery
  165. *
  166. * DESCRIPTION : Optimizing a query on filtering Properties and the Key value
  167. *
  168. *****************************************************************************/
  169. HRESULT CSession :: ExecQuery (
  170. MethodContext *pMethodContext,
  171. CFrameworkQuery &Query,
  172. long lFlags
  173. )
  174. {
  175. HRESULT hRes = WBEM_S_NO_ERROR;
  176. DWORD dwPropertiesReq;
  177. short t_Level;
  178. if ( Query.AllPropertiesAreRequired () )
  179. {
  180. dwPropertiesReq = SESSION_ALL_PROPS;
  181. }
  182. else
  183. {
  184. SetPropertiesReq ( Query,dwPropertiesReq );
  185. }
  186. #ifdef NTONLY
  187. GetNTLevelInfo ( dwPropertiesReq, &t_Level );
  188. #endif
  189. #if 0
  190. #ifdef WIN9XONLY
  191. Get9XLevelInfo ( dwPropertiesReq, &t_Level );
  192. #endif
  193. #endif // #if 0
  194. CHStringArray t_ComputerValues;
  195. CHStringArray t_UserValues;
  196. hRes = Query.GetValuesForProp(
  197. IDS_ComputerName,
  198. t_ComputerValues
  199. );
  200. hRes = Query.GetValuesForProp(
  201. IDS_UserName,
  202. t_UserValues
  203. );
  204. if ( SUCCEEDED ( hRes ) )
  205. {
  206. short t_Level;
  207. #ifdef NTONLY
  208. GetNTLevelInfo ( dwPropertiesReq, &t_Level );
  209. hRes = OptimizeNTQuery ( t_ComputerValues, t_UserValues, t_Level, pMethodContext, dwPropertiesReq );
  210. #endif
  211. #if 0
  212. #ifdef WIN9XONLY
  213. Get9XLevelInfo ( dwPropertiesReq, &t_Level );
  214. hRes = Optimize9XQuery ( t_ComputerValues, t_UserValues, t_Level, pMethodContext, dwPropertiesReq );
  215. #endif
  216. #endif // #if 0
  217. }
  218. return hRes;
  219. }
  220. #ifdef NTONLY
  221. /*****************************************************************************
  222. *
  223. * FUNCTION : CSession::EnumNTSessionInfo
  224. *
  225. * DESCRIPTION : Enumerating all the Sessions
  226. *
  227. *****************************************************************************/
  228. HRESULT CSession :: EnumNTSessionInfo (
  229. LPWSTR lpComputerName,
  230. LPWSTR lpUserName,
  231. short a_Level,
  232. MethodContext *pMethodContext,
  233. DWORD dwPropertiesReq
  234. )
  235. {
  236. NET_API_STATUS t_Status = NERR_Success;
  237. HRESULT hRes = WBEM_S_NO_ERROR;
  238. DWORD dwNoOfEntriesRead = 0;
  239. DWORD dwTotalSessions = 0;
  240. DWORD dwResumeHandle = 0;
  241. void *pBuf = NULL;
  242. void *pTmpBuf = NULL;
  243. while ( ( t_Status == NERR_Success ) || ( t_Status == ERROR_MORE_DATA ) )
  244. {
  245. t_Status = NetSessionEnum(
  246. NULL,
  247. lpComputerName,
  248. lpUserName,
  249. a_Level,
  250. (LPBYTE *) &pBuf,
  251. -1,
  252. &dwNoOfEntriesRead,
  253. &dwTotalSessions,
  254. &dwResumeHandle
  255. );
  256. if ( t_Status == NERR_Success )
  257. {
  258. if ( dwNoOfEntriesRead == 0 )
  259. {
  260. break;
  261. }
  262. else
  263. {
  264. try
  265. {
  266. pTmpBuf = pBuf;
  267. for ( int i = 0; i < dwNoOfEntriesRead; i++ )
  268. {
  269. CInstancePtr pInstance ( CreateNewInstance ( pMethodContext ), FALSE );
  270. hRes = LoadData ( a_Level, pBuf, dwPropertiesReq, pInstance );
  271. if ( SUCCEEDED ( hRes ) )
  272. {
  273. hRes = pInstance->Commit();
  274. if ( FAILED ( hRes ) )
  275. {
  276. break;
  277. }
  278. }
  279. // here need to go to the next structure based on the level, we will typecast with the apropriate structure
  280. // and then increment by one
  281. switch ( a_Level )
  282. {
  283. case 502 : SESSION_INFO_502 *pTmpTmpBuf502;
  284. pTmpTmpBuf502 = ( SESSION_INFO_502 *) pTmpBuf;
  285. pTmpTmpBuf502 ++;
  286. pTmpBuf = ( void * ) pTmpTmpBuf502;
  287. break;
  288. case 2: SESSION_INFO_2 *pTmpTmpBuf2;
  289. pTmpTmpBuf2 = (SESSION_INFO_2 *) pTmpBuf;
  290. pTmpTmpBuf2 ++;
  291. pTmpBuf = ( void * ) pTmpTmpBuf2;
  292. break;
  293. case 1: SESSION_INFO_1 *pTmpTmpBuf1;
  294. pTmpTmpBuf1 = ( SESSION_INFO_1 *) pTmpBuf;
  295. pTmpTmpBuf1 ++;
  296. pTmpBuf = ( void * ) pTmpTmpBuf1;
  297. break;
  298. case 10: SESSION_INFO_10 *pTmpTmpBuf10;
  299. pTmpTmpBuf10 = ( SESSION_INFO_10 *) pTmpBuf;
  300. pTmpTmpBuf10 ++;
  301. pTmpBuf = ( void * ) pTmpTmpBuf10;
  302. break;
  303. }
  304. }
  305. if ( FAILED ( hRes ) )
  306. {
  307. break;
  308. }
  309. }
  310. catch ( ... )
  311. {
  312. NetApiBufferFree ( pBuf );
  313. pBuf = NULL;
  314. throw;
  315. }
  316. NetApiBufferFree ( pBuf );
  317. pBuf = NULL;
  318. }
  319. }
  320. else
  321. {
  322. if ( t_Status == ERROR_ACCESS_DENIED )
  323. {
  324. hRes = WBEM_E_ACCESS_DENIED;
  325. }
  326. else
  327. {
  328. if ( t_Status == ERROR_NOT_ENOUGH_MEMORY )
  329. {
  330. hRes = WBEM_E_OUT_OF_MEMORY;
  331. }
  332. else
  333. {
  334. hRes = WBEM_E_FAILED;
  335. }
  336. }
  337. }
  338. }
  339. return hRes;
  340. }
  341. /*****************************************************************************
  342. *
  343. * FUNCTION : CSession::FindAndSetNTSession
  344. *
  345. * DESCRIPTION : Find a single instance based on the key properties for the
  346. * class.
  347. *
  348. *****************************************************************************/
  349. HRESULT CSession::FindAndSetNTSession ( LPCWSTR a_ComputerName, LPWSTR a_UserName, short a_Level, DWORD dwPropertiesReq,
  350. CInstance *pInstance, DWORD eOperation )
  351. {
  352. HRESULT hRes = WBEM_S_NO_ERROR;
  353. NET_API_STATUS t_Status = NERR_Success;
  354. CHString t_TempKey;
  355. t_TempKey.Format ( L"%s%s",L"\\\\", a_ComputerName );
  356. DWORD dwNoOfEntriesRead = 0;
  357. DWORD dwTotalSessions = 0;
  358. DWORD dwResumeHandle = 0;
  359. void *pBuf = NULL;
  360. // since it will be only one structure
  361. t_Status = NetSessionEnum(
  362. NULL,
  363. t_TempKey.GetBuffer ( 0 ),
  364. a_UserName,
  365. a_Level,
  366. (LPBYTE *) &pBuf,
  367. -1,
  368. &dwNoOfEntriesRead,
  369. &dwTotalSessions,
  370. &dwResumeHandle
  371. );
  372. hRes = ( t_Status != NERR_Success ) && ( dwNoOfEntriesRead == 0 ) ? WBEM_E_NOT_FOUND : hRes;
  373. if ( SUCCEEDED ( hRes ) )
  374. {
  375. try
  376. {
  377. switch ( eOperation )
  378. {
  379. case Get: hRes = LoadData ( a_Level, pBuf, dwPropertiesReq, pInstance );
  380. break;
  381. case Delete: hRes = t_Status = NetSessionDel (
  382. NULL,
  383. t_TempKey.GetBuffer ( 0 ),
  384. a_UserName
  385. );
  386. if ( t_Status == NERR_Success )
  387. {
  388. hRes = WBEM_S_NO_ERROR;
  389. }
  390. else
  391. {
  392. if ( t_Status == ERROR_ACCESS_DENIED )
  393. {
  394. hRes = WBEM_E_ACCESS_DENIED;
  395. }
  396. else
  397. {
  398. if ( t_Status == ERROR_NOT_ENOUGH_MEMORY )
  399. {
  400. hRes = WBEM_E_OUT_OF_MEMORY;
  401. }
  402. else
  403. {
  404. hRes = WBEM_E_FAILED;
  405. }
  406. }
  407. }
  408. break;
  409. default: hRes = WBEM_E_PROVIDER_NOT_CAPABLE;
  410. break;
  411. }
  412. }
  413. catch ( ... )
  414. {
  415. if ( pBuf != NULL )
  416. {
  417. NetApiBufferFree(pBuf);
  418. pBuf = NULL;
  419. }
  420. throw;
  421. }
  422. if ( pBuf != NULL )
  423. {
  424. NetApiBufferFree(pBuf);
  425. pBuf = NULL;
  426. }
  427. }
  428. return hRes ;
  429. }
  430. /*****************************************************************************
  431. *
  432. * FUNCTION : Session::OptimizeNTQuery
  433. *
  434. * DESCRIPTION : Optimizes a query based on the key values.
  435. *
  436. *****************************************************************************/
  437. HRESULT CSession::OptimizeNTQuery (
  438. CHStringArray& a_ComputerValues,
  439. CHStringArray& a_UserValues,
  440. short a_Level,
  441. MethodContext *pMethodContext,
  442. DWORD dwPropertiesReq
  443. )
  444. {
  445. HRESULT hRes = WBEM_S_NO_ERROR;
  446. NET_API_STATUS t_Status = NERR_Success;
  447. if ( ( a_ComputerValues.GetSize() == 0 ) && ( a_UserValues.GetSize() == 0 ) )
  448. {
  449. // This is a query for which there is no where clause, so it means only a few Properties are requested
  450. // hence we need to deliver only those properties of instances to the WinMgmt while enumerating Sessions
  451. hRes = EnumNTSessionInfo (
  452. NULL,
  453. NULL,
  454. a_Level,
  455. pMethodContext,
  456. dwPropertiesReq
  457. );
  458. }
  459. else
  460. if ( a_UserValues.GetSize() != 0 )
  461. {
  462. for ( int i = 0; i < a_UserValues.GetSize(); i++ )
  463. {
  464. hRes = EnumNTSessionInfo (
  465. NULL,
  466. a_UserValues.GetAt( i ).GetBuffer ( 0 ),
  467. a_Level,
  468. pMethodContext,
  469. dwPropertiesReq
  470. );
  471. }
  472. }
  473. else
  474. if ( a_ComputerValues.GetSize() != 0 )
  475. {
  476. CHString t_ComputerName;
  477. for ( int i = 0; i < a_ComputerValues.GetSize(); i++ )
  478. {
  479. t_ComputerName.Format ( L"%s%s", L"\\\\", (LPCWSTR)a_ComputerValues.GetAt(i) );
  480. hRes = EnumNTSessionInfo (
  481. t_ComputerName.GetBuffer(0),
  482. NULL,
  483. a_Level,
  484. pMethodContext,
  485. dwPropertiesReq
  486. );
  487. }
  488. }
  489. else
  490. {
  491. hRes = WBEM_E_PROVIDER_NOT_CAPABLE;
  492. }
  493. return hRes;
  494. }
  495. /*****************************************************************************
  496. *
  497. * FUNCTION : CSession::GetNTLevelInfo
  498. *
  499. * DESCRIPTION : Getting the level info, so that the appropriate structure
  500. * Can be passed to make a call.
  501. *
  502. *****************************************************************************/
  503. void CSession :: GetNTLevelInfo (
  504. DWORD dwPropertiesReq,
  505. short *a_Level
  506. )
  507. {
  508. //
  509. // enuminstances uses level 502
  510. //
  511. // as NetSessionEnum is going to fail for non-admin user for level 502
  512. // we cannot be specific about level as ordinary user can obtain some
  513. // values for some properties when using downgrading level
  514. //
  515. // decision was taken to make all call with 502 level then !
  516. //
  517. *a_Level = 502;
  518. /*
  519. if ( ( dwPropertiesReq == SESSION_ALL_PROPS ) ||
  520. ( (dwPropertiesReq & SESSION_PROP_TransportName) == SESSION_PROP_TransportName )
  521. )
  522. {
  523. *a_Level = 502;
  524. }
  525. else
  526. if ( (dwPropertiesReq & SESSION_PROP_ClientType) == SESSION_PROP_ClientType )
  527. {
  528. *a_Level = 2;
  529. }
  530. else
  531. if ( ( (dwPropertiesReq & SESSION_PROP_NumOpens) == SESSION_PROP_NumOpens ) ||
  532. ( (dwPropertiesReq & SESSION_PROP_SessionType) == SESSION_PROP_SessionType )
  533. )
  534. {
  535. *a_Level = 1;
  536. }
  537. else
  538. {
  539. // Since keys will be always required we need to atleast use Level 10 structure and level 0 cannot be used since,
  540. // it gives only username, where as computername is also a key.
  541. *a_Level = 10;
  542. }
  543. */
  544. }
  545. #endif
  546. /*****************************************************************************
  547. *
  548. * FUNCTION : CSession::LoadData
  549. * DESCRIPTION : Loading an instance with the obtained information
  550. *
  551. *****************************************************************************/
  552. HRESULT CSession :: LoadData (
  553. short a_Level,
  554. void *pTmpBuf,
  555. DWORD dwPropertiesReq ,
  556. CInstance *pInstance
  557. )
  558. {
  559. HRESULT hRes = WBEM_S_NO_ERROR;
  560. // every property is to be set based on the level and then typecasting that buffer with that level.
  561. if ( dwPropertiesReq & SESSION_PROP_Computer)
  562. {
  563. CHString t_ComputerName;
  564. switch ( a_Level )
  565. {
  566. #ifdef NTONLY
  567. case 502 : t_ComputerName = ( (SESSION_INFO_502 *) pTmpBuf )->sesi502_cname;
  568. break;
  569. #endif
  570. case 2: t_ComputerName = ( (SESSION_INFO_2 *) pTmpBuf )->sesi2_cname;
  571. break;
  572. case 1: t_ComputerName = ( (SESSION_INFO_1 *) pTmpBuf )->sesi1_cname;
  573. break;
  574. case 10: t_ComputerName = ( (SESSION_INFO_10 *) pTmpBuf )->sesi10_cname;
  575. break;
  576. #if 0
  577. #ifdef WIN9XONLY
  578. case 50: t_ComputerName = ( (SESSION_INFO_50 *) pTmpBuf )->sesi50_cname;
  579. break;
  580. #endif
  581. #endif // #if 0
  582. }
  583. if ( SUCCEEDED ( hRes ) )
  584. {
  585. if ( pInstance->SetCHString ( IDS_ComputerName, t_ComputerName ) == FALSE )
  586. {
  587. hRes = WBEM_E_PROVIDER_FAILURE ;
  588. }
  589. }
  590. }
  591. if ( SUCCEEDED ( hRes ) )
  592. {
  593. if ( dwPropertiesReq & SESSION_PROP_User )
  594. {
  595. CHString t_User;
  596. switch ( a_Level )
  597. {
  598. #ifdef NTONLY
  599. case 502 : t_User = ( (SESSION_INFO_502 *) pTmpBuf )->sesi502_username;
  600. break;
  601. #endif
  602. case 2: t_User = ( (SESSION_INFO_2 *) pTmpBuf )->sesi2_username;
  603. break;
  604. case 1: t_User = ( (SESSION_INFO_1 *) pTmpBuf )->sesi1_username;
  605. break;
  606. case 10: t_User = ( (SESSION_INFO_10 *) pTmpBuf )->sesi10_username;
  607. break;
  608. #if 0
  609. #ifdef WIN9XONLY
  610. case 50: t_User = ( (SESSION_INFO_50 *) pTmpBuf )->sesi50_username;
  611. break;
  612. #endif
  613. #endif // #if 0
  614. }
  615. if ( SUCCEEDED ( hRes ) )
  616. {
  617. if ( pInstance->SetCHString ( IDS_UserName, t_User ) == FALSE )
  618. {
  619. hRes = WBEM_E_PROVIDER_FAILURE ;
  620. }
  621. }
  622. }
  623. }
  624. if ( SUCCEEDED ( hRes ) )
  625. {
  626. if ( dwPropertiesReq & SESSION_PROP_ActiveTime )
  627. {
  628. DWORD t_ActiveTime;
  629. switch ( a_Level )
  630. {
  631. #ifdef NTONLY
  632. case 502 : t_ActiveTime = ( (SESSION_INFO_502 *) pTmpBuf )->sesi502_time;
  633. break;
  634. #endif
  635. case 2: t_ActiveTime = ( (SESSION_INFO_2 *) pTmpBuf )->sesi2_time;
  636. break;
  637. case 1: t_ActiveTime = ( (SESSION_INFO_1 *) pTmpBuf )->sesi1_time;
  638. break;
  639. case 10: t_ActiveTime = ( (SESSION_INFO_10 *) pTmpBuf )->sesi10_time;
  640. break;
  641. #if 0
  642. #ifdef WIN9XONLY
  643. case 50: t_ActiveTime = ( (SESSION_INFO_50 *) pTmpBuf )->sesi50_time;
  644. break;
  645. #endif
  646. #endif // #if 0
  647. }
  648. if ( SUCCEEDED ( hRes ) )
  649. {
  650. if ( pInstance->SetWORD ( IDS_ActiveTime, t_ActiveTime ) == FALSE )
  651. {
  652. hRes = WBEM_E_PROVIDER_FAILURE ;
  653. }
  654. }
  655. }
  656. }
  657. if ( SUCCEEDED ( hRes ) )
  658. {
  659. if ( dwPropertiesReq & SESSION_PROP_IdleTime )
  660. {
  661. DWORD t_IdleTime;
  662. switch ( a_Level )
  663. {
  664. #ifdef NTONLY
  665. case 502 : t_IdleTime = ( (SESSION_INFO_502 *) pTmpBuf )->sesi502_idle_time;
  666. break;
  667. #endif
  668. case 2: t_IdleTime = ( (SESSION_INFO_2 *) pTmpBuf )->sesi2_idle_time;
  669. break;
  670. case 1: t_IdleTime = ( (SESSION_INFO_1 *) pTmpBuf )->sesi1_idle_time;
  671. break;
  672. case 10: t_IdleTime = ( (SESSION_INFO_10 *) pTmpBuf )->sesi10_idle_time;
  673. break;
  674. #if 0
  675. #ifdef WIN9XONLY
  676. case 50: t_IdleTime = ( (SESSION_INFO_50 *) pTmpBuf )->sesi50_idle_time;
  677. break;
  678. #endif
  679. #endif
  680. }
  681. if ( SUCCEEDED ( hRes ) )
  682. {
  683. if ( pInstance->SetWORD ( IDS_IdleTime, t_IdleTime ) == FALSE )
  684. {
  685. hRes = WBEM_E_PROVIDER_FAILURE ;
  686. }
  687. }
  688. }
  689. }
  690. if ( SUCCEEDED ( hRes ) )
  691. {
  692. if ( dwPropertiesReq & SESSION_PROP_NumOpens )
  693. {
  694. DWORD t_NumOpens;
  695. switch ( a_Level )
  696. {
  697. #ifdef NTONLY
  698. case 502 : t_NumOpens = ( (SESSION_INFO_502 *) pTmpBuf )->sesi502_num_opens;
  699. break;
  700. #endif
  701. case 2: t_NumOpens = ( (SESSION_INFO_2 *) pTmpBuf )->sesi2_num_opens;
  702. break;
  703. case 1: t_NumOpens = ( (SESSION_INFO_1 *) pTmpBuf )->sesi1_num_opens;
  704. break;
  705. #if 0
  706. #ifdef WIN9XONLY
  707. case 50: t_NumOpens = ( (SESSION_INFO_50 *) pTmpBuf )->sesi50_num_opens;
  708. break;
  709. #endif
  710. #endif
  711. }
  712. if ( SUCCEEDED ( hRes ) )
  713. {
  714. if ( pInstance->SetWORD ( IDS_ResourcesOpened, t_NumOpens ) == FALSE )
  715. {
  716. hRes = WBEM_E_PROVIDER_FAILURE ;
  717. }
  718. }
  719. }
  720. }
  721. if ( SUCCEEDED ( hRes ) )
  722. {
  723. if ( dwPropertiesReq & SESSION_PROP_TransportName )
  724. {
  725. CHString t_TransportName;
  726. #ifdef NTONLY
  727. if ( a_Level == 502 )
  728. {
  729. t_TransportName = ( (SESSION_INFO_502 *) pTmpBuf )->sesi502_transport;
  730. }
  731. #endif
  732. #if 0
  733. #ifdef WIN9XONLY
  734. if ( a_Level == 50 )
  735. {
  736. WCHAR w_TName[100];
  737. w_TName[0] = ( (SESSION_INFO_50 *) pTmpBuf )->sesi50_protocol;
  738. w_TName [ 1 ] = _T('\0');
  739. t_TransportName = w_TName;
  740. }
  741. #endif
  742. #endif
  743. if ( SUCCEEDED ( hRes ) )
  744. {
  745. if ( pInstance->SetCHString ( IDS_TransportName, t_TransportName ) == FALSE )
  746. {
  747. hRes = WBEM_E_PROVIDER_FAILURE ;
  748. }
  749. }
  750. }
  751. }
  752. if ( SUCCEEDED ( hRes ) )
  753. {
  754. if ( dwPropertiesReq & SESSION_PROP_ClientType )
  755. {
  756. CHString t_ClientType;
  757. switch ( a_Level )
  758. {
  759. #ifdef NTONLY
  760. case 502 : t_ClientType = ( (SESSION_INFO_502 *) pTmpBuf)->sesi502_cltype_name;
  761. break;
  762. #endif
  763. #if 0
  764. #ifdef WIN9XONLY
  765. case 2: t_ClientType = ( (SESSION_INFO_2 *) pTmpBuf )->sesi2_cltype_name;
  766. break;
  767. #endif
  768. #endif // #if 0
  769. }
  770. if ( SUCCEEDED ( hRes ) )
  771. {
  772. if ( pInstance->SetCHString ( IDS_ClientType, t_ClientType ) == FALSE )
  773. {
  774. hRes = WBEM_E_PROVIDER_FAILURE ;
  775. }
  776. }
  777. }
  778. }
  779. #ifdef NTONLY
  780. if ( SUCCEEDED ( hRes ) )
  781. {
  782. if ( dwPropertiesReq & SESSION_PROP_SessionType )
  783. {
  784. DWORD dwflags;
  785. DWORD dwSessionType;
  786. switch ( a_Level )
  787. {
  788. case 502 : dwflags = ( (SESSION_INFO_502 *) pTmpBuf )->sesi502_user_flags;
  789. break;
  790. }
  791. switch ( dwflags )
  792. {
  793. case SESS_GUEST: dwSessionType = 0;
  794. break;
  795. case SESS_NOENCRYPTION: dwSessionType = 1;
  796. break;
  797. default : dwSessionType = dwSessionType = 2;
  798. }
  799. if ( SUCCEEDED ( hRes ) )
  800. {
  801. if ( pInstance->SetDWORD ( IDS_SessionType, dwSessionType ) == FALSE )
  802. {
  803. hRes = WBEM_E_PROVIDER_FAILURE ;
  804. }
  805. }
  806. }
  807. }
  808. #endif
  809. return hRes;
  810. }
  811. #if 0
  812. #ifdef WIN9XONLY
  813. /*****************************************************************************
  814. *
  815. * FUNCTION : CSession::Enum9XSessionInfo
  816. *
  817. * DESCRIPTION : Enumerating all the Sessions on 9X
  818. *
  819. *****************************************************************************/
  820. HRESULT CSession :: Enum9XSessionInfo (
  821. short a_Level,
  822. MethodContext *pMethodContext,
  823. DWORD dwPropertiesReq
  824. )
  825. {
  826. NET_API_STATUS t_Status = NERR_Success;
  827. HRESULT hRes = WBEM_S_NO_ERROR;
  828. unsigned short dwNoOfEntriesRead = 0;
  829. unsigned short dwTotalSessions = 0;
  830. void *pBuf = NULL;
  831. void *pTmpBuf = NULL;
  832. DWORD dwSize = 0;
  833. // Determine the size of the structure, for the level passed.
  834. switch ( a_Level )
  835. {
  836. case 1: dwSize = sizeof ( SESSION_INFO_1 );
  837. break;
  838. case 2: dwSize = sizeof ( SESSION_INFO_2 );
  839. break;
  840. case 10: dwSize = sizeof ( SESSION_INFO_10 );
  841. break;
  842. case 50: dwSize = sizeof ( SESSION_INFO_50 );
  843. break;
  844. }
  845. unsigned short cbBuffer = MAX_ENTRIES * dwSize;
  846. pBuf = ( char FAR * ) malloc ( cbBuffer );
  847. if ( pBuf != NULL )
  848. {
  849. try
  850. {
  851. t_Status = NetSessionEnum(
  852. NULL,
  853. a_Level,
  854. (char FAR *) pBuf,
  855. cbBuffer,
  856. &dwNoOfEntriesRead,
  857. &dwTotalSessions
  858. );
  859. if ( ( t_Status == ERROR_MORE_DATA ) || ( dwTotalSessions > dwNoOfEntriesRead ) )
  860. {
  861. // Free the buffer and make a API call again by allocating a buffer of the required size.
  862. free ( pBuf );
  863. pBuf = NULL;
  864. cbBuffer = ( dwTotalSessions * dwSize );
  865. pBuf = ( char FAR * ) malloc ( cbBuffer );
  866. if ( pBuf != NULL )
  867. {
  868. try
  869. {
  870. t_Status = NetSessionEnum(
  871. NULL,
  872. a_Level,
  873. ( char FAR *) pBuf,
  874. cbBuffer,
  875. &dwNoOfEntriesRead,
  876. &dwTotalSessions
  877. );
  878. if ( t_Status != NERR_Success )
  879. {
  880. hRes = WBEM_E_FAILED;
  881. }
  882. }
  883. catch ( ... )
  884. {
  885. if ( pBuf != NULL )
  886. {
  887. free ( pBuf );
  888. }
  889. pBuf = NULL;
  890. }
  891. }
  892. else
  893. {
  894. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  895. }
  896. }
  897. }
  898. catch ( ... )
  899. {
  900. if ( pBuf != NULL )
  901. {
  902. free ( pBuf );
  903. pBuf = NULL;
  904. }
  905. throw;
  906. }
  907. }
  908. else
  909. {
  910. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  911. }
  912. if ( SUCCEEDED ( hRes ) )
  913. {
  914. if ( ( dwNoOfEntriesRead > 0 ) && ( pBuf != NULL ) )
  915. {
  916. try
  917. {
  918. pTmpBuf = pBuf;
  919. for ( int i = 0; i < dwNoOfEntriesRead; i++ )
  920. {
  921. CInstancePtr pInstance ( CreateNewInstance ( pMethodContext ), FALSE );
  922. hRes = LoadData ( a_Level, pBuf, dwPropertiesReq, pInstance );
  923. if ( SUCCEEDED ( hRes ) )
  924. {
  925. hRes = pInstance->Commit();
  926. if ( FAILED ( hRes ) )
  927. {
  928. break;
  929. }
  930. }
  931. // here need to go to the next structure based on the level, we will typecast with the apropriate structure
  932. // and then increment by one
  933. switch ( a_Level )
  934. {
  935. case 2: SESSION_INFO_2 *pTmpTmpBuf2;
  936. pTmpTmpBuf2 = (SESSION_INFO_2 *) pTmpBuf;
  937. pTmpTmpBuf2 ++;
  938. pTmpBuf = ( void * ) pTmpTmpBuf2;
  939. break;
  940. case 1: SESSION_INFO_1 *pTmpTmpBuf1;
  941. pTmpTmpBuf1 = ( SESSION_INFO_1 *) pTmpBuf;
  942. pTmpTmpBuf1 ++;
  943. pTmpBuf = ( void * ) pTmpTmpBuf1;
  944. break;
  945. case 10: SESSION_INFO_10 *pTmpTmpBuf10;
  946. pTmpTmpBuf10 = ( SESSION_INFO_10 *) pTmpBuf;
  947. pTmpTmpBuf10 ++;
  948. pTmpBuf = ( void * ) pTmpTmpBuf10;
  949. break;
  950. case 50: SESSION_INFO_50 *pTmpTmpBuf50;
  951. pTmpTmpBuf50 = ( SESSION_INFO_50 *) pTmpBuf;
  952. pTmpTmpBuf50 ++;
  953. pTmpBuf = ( void * ) pTmpTmpBuf50;
  954. break;
  955. default: hRes = WBEM_E_FAILED;
  956. }
  957. }
  958. }
  959. catch ( ... )
  960. {
  961. free ( pBuf );
  962. pBuf = NULL;
  963. throw;
  964. }
  965. free ( pBuf );
  966. pBuf = NULL;
  967. }
  968. }
  969. return hRes;
  970. }
  971. /*****************************************************************************
  972. *
  973. * FUNCTION : CSession::FindAndSet9XSession
  974. *
  975. * DESCRIPTION : Find a single instance based on the key properties for the
  976. * class.
  977. *
  978. *****************************************************************************/
  979. HRESULT CSession::FindAndSet9XSession (
  980. LPCWSTR a_ComputerName,
  981. LPWSTR a_UserName,
  982. short a_Level,
  983. DWORD dwPropertiesReq,
  984. CInstance *pInstance,
  985. DWORD eOperation
  986. )
  987. {
  988. HRESULT hRes = WBEM_S_NO_ERROR;
  989. NET_API_STATUS t_Status = NERR_Success;
  990. CHString t_TempKey;
  991. t_TempKey.Format ( L"%s%s",L"\\\\", a_ComputerName );
  992. unsigned short dwNoOfEntriesRead = 0;
  993. unsigned short dwTotalSessions = 0;
  994. void *pBuf = NULL;
  995. void *pTmpBuf = NULL;
  996. DWORD dwSize = 0;
  997. // Determine the size of the structure, for the level passed.
  998. switch ( a_Level )
  999. {
  1000. case 1: dwSize = sizeof ( SESSION_INFO_1 );
  1001. break;
  1002. case 2: dwSize = sizeof ( SESSION_INFO_2 );
  1003. break;
  1004. case 10: dwSize = sizeof ( SESSION_INFO_10 );
  1005. break;
  1006. case 50: dwSize = sizeof ( SESSION_INFO_50 );
  1007. break;
  1008. }
  1009. unsigned short cbBuffer = 0;
  1010. t_Status = NetSessionGetInfo(
  1011. NULL,
  1012. (const char FAR *) ( a_UserName.GetBuffer ( 0 ) ),
  1013. a_Level,
  1014. ( char FAR * ) pBuf,
  1015. cbBuffer,
  1016. &dwTotalSessions
  1017. );
  1018. hRes = dwTotalSessions == 0 ? WBEM_E_NOT_FOUND : hRes;
  1019. if ( SUCCEEDED ( hRes ) )
  1020. {
  1021. // here we need to read all the entries associated with the user, and then
  1022. // search from this list for a given computer
  1023. if ( t_Status != NERR_BufTooSmall )
  1024. {
  1025. cbBuffer = dwTotalSessions * dwSize;
  1026. pBuf = ( char FAR * ) malloc ( cbBuffer );
  1027. if ( pBuf != NULL )
  1028. {
  1029. t_Status = NetSessionGetInfo(
  1030. NULL,
  1031. (const char FAR *) ( a_UserName.GetBuffer ( 0 ) ),
  1032. a_Level,
  1033. ( char FAR * ) pBuf,
  1034. cbBuffer,
  1035. &dwTotalSessions
  1036. );
  1037. try
  1038. {
  1039. // now search for a given computer
  1040. void *pTempBuf = pBuf;
  1041. int i = 0;
  1042. for ( i = 0; i < dwTotalSessions; i ++ )
  1043. {
  1044. CHString t_CompName;
  1045. switch ( a_Level )
  1046. {
  1047. case 2: SESSION_INFO_2 *pTmpTmpBuf2;
  1048. pTmpTmpBuf2 = (SESSION_INFO_2 *) pTmpBuf;
  1049. t_CompName = pTmpTmpBuf2->sesi2_cname;
  1050. break;
  1051. case 1: SESSION_INFO_1 *pTmpTmpBuf1;
  1052. pTmpTmpBuf1 = (SESSION_INFO_1 *) pTmpBuf;
  1053. t_CompName = pTmpTmpBuf1->sesi1_cname;
  1054. break;
  1055. case 10: SESSION_INFO_10 *pTmpTmpBuf10;
  1056. pTmpTmpBuf10 = (SESSION_INFO_10 *) pTmpBuf;
  1057. t_CompName = pTmpTmpBuf10->sesi10_cname;
  1058. break;
  1059. case 50: SESSION_INFO_50 *pTmpTmpBuf50;
  1060. pTmpTmpBuf50 = (SESSION_INFO_50 *) pTmpBuf;
  1061. t_CompName = pTmpTmpBuf50->sesi50_cname;
  1062. break;
  1063. }
  1064. if ( a_ComputerName.CompareNoCase ( t_TempKey ) == 0 )
  1065. {
  1066. break;
  1067. }
  1068. // otherwise need to go to the next entry;
  1069. switch ( a_Level )
  1070. {
  1071. case 2: SESSION_INFO_2 *pTmpTmpBuf2;
  1072. pTmpTmpBuf2 = (SESSION_INFO_2 *) pTmpBuf;
  1073. pTmpTmpBuf2++;
  1074. pTmpBuf = ( void * ) pTmpTmpBuf2;
  1075. break;
  1076. case 1: SESSION_INFO_1 *pTmpTmpBuf1;
  1077. pTmpTmpBuf1 = (SESSION_INFO_1 *) pTmpBuf;
  1078. pTmpTmpBuf1++;
  1079. pTmpBuf = ( void * ) pTmpTmpBuf1;
  1080. break;
  1081. case 10: SESSION_INFO_10 *pTmpTmpBuf10;
  1082. pTmpTmpBuf10 = (SESSION_INFO_10 *) pTmpBuf;
  1083. pTmpTmpBuf10++;
  1084. pTmpBuf = ( void * ) pTmpTmpBuf10;
  1085. break;
  1086. case 50: SESSION_INFO_50 *pTmpTmpBuf50;
  1087. pTmpTmpBuf50 = (SESSION_INFO_50 *) pTmpBuf;
  1088. pTmpTmpBuf50++;
  1089. pTmpBuf = ( void * ) pTmpTmpBuf50;
  1090. break;
  1091. }
  1092. }
  1093. if ( i >= dwTotalSessions )
  1094. {
  1095. hRes = WBEM_E_NOT_FOUND;
  1096. }
  1097. }
  1098. catch ( ... )
  1099. {
  1100. free ( pBuf );
  1101. throw;
  1102. }
  1103. }
  1104. else
  1105. {
  1106. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  1107. }
  1108. }
  1109. else
  1110. {
  1111. hRes = WBEM_E_FAILED;
  1112. }
  1113. }
  1114. if ( SUCCEEDED ( hRes ) )
  1115. {
  1116. try
  1117. {
  1118. switch ( eOperation )
  1119. {
  1120. case Get: hRes = LoadData ( a_Level, pBuf, dwPropertiesReq, pInstance );
  1121. break;
  1122. // Expects a Session Key as a parameter and as a result we need to read more than one structure for every instance.
  1123. // but the documents say it requires a sharename.
  1124. /* case Delete: hRes = t_Status = NetSessionDel(
  1125. NULL,
  1126. (LPTSTR) t_TempKey.GetBuffer ( 0 ),
  1127. (LPTSTR) a_UserName.GetBuffer ( 0 ) ;
  1128. );
  1129. hRes = t_Status == NERR_Success ? hRes : WBEM_E_FAILED;
  1130. break;*/
  1131. default: hRes = WBEM_E_PROVIDER_NOT_CAPABLE;
  1132. break;
  1133. }
  1134. }
  1135. catch ( ... )
  1136. {
  1137. free ( pBuf );
  1138. pBuf = NULL;
  1139. throw;
  1140. }
  1141. free ( pBuf );
  1142. pBuf = NULL;
  1143. }
  1144. return hRes ;
  1145. }
  1146. /*****************************************************************************
  1147. *
  1148. * FUNCTION : Session::Optimize9XQuery
  1149. *
  1150. * DESCRIPTION : Optimizes a query based on the key values.
  1151. *
  1152. *****************************************************************************/
  1153. HRESULT CSession::Optimize9XQuery (
  1154. CHStringArray &a_ComputerValues,
  1155. CHStringArray &a_UserValues,
  1156. short a_Level,
  1157. MethodContext *pMethodContext,
  1158. DWORD dwPropertiesReq
  1159. )
  1160. {
  1161. HRESULT hRes = WBEM_S_NO_ERROR;
  1162. NET_API_STATUS t_Status = NERR_Success;
  1163. if ( a_ComputerValues.GetSize() == 0 )
  1164. {
  1165. // This is a query for which there is no where clause, so it means only a few Properties are requested
  1166. // hence we need to deliver only those properties of instances to the WinMgmt while enumerating Sessions
  1167. hRes = Enum9XSessionInfo (
  1168. a_Level,
  1169. pMethodContext,
  1170. dwPropertiesReq
  1171. );
  1172. }
  1173. else
  1174. if ( a_UserValues.GetSize() != 0 )
  1175. {
  1176. DWORD dwNoOfEntriesRead = 0;
  1177. DWORD dwTotalSessions = 0;
  1178. void *pBuf = NULL;
  1179. void *pTmpBuf = NULL;
  1180. DWORD dwSize = 0;
  1181. BOOL bNoMoreEnums = FALSE;
  1182. // Determine the size of the structure, for the level passed.
  1183. switch ( a_Level )
  1184. {
  1185. case 1: dwSize = sizeof ( SESSION_INFO_1 );
  1186. break;
  1187. case 2: dwSize = sizeof ( SESSION_INFO_2 );
  1188. break;
  1189. case 10: dwSize = sizeof ( SESSION_INFO_10 );
  1190. break;
  1191. case 50: dwSize = sizeof ( SESSION_INFO_50 );
  1192. break;
  1193. }
  1194. for ( int i = 0; i < a_UserValues.GetSize(); i++ )
  1195. {
  1196. unsigned short cbBuffer = 0;
  1197. t_Status = NetSessionGetInfo(
  1198. NULL,
  1199. (const char FAR *) ( a_UserValues.GetAt ( i ).GetBuffer ( 0 ) ),
  1200. a_Level,
  1201. ( char FAR * ) pBuf,
  1202. cbBuffer,
  1203. (unsigned short FAR *) dwTotalSessions
  1204. );
  1205. if ( dwTotalSessions == 0 )
  1206. {
  1207. continue;
  1208. }
  1209. if ( SUCCEEDED ( hRes ) )
  1210. {
  1211. // here we need to read all the entries associated with the user, and then
  1212. // search from this list for a given computer
  1213. if ( t_Status != NERR_BufTooSmall )
  1214. {
  1215. cbBuffer = dwTotalSessions * dwSize;
  1216. pBuf = ( char FAR * ) malloc ( cbBuffer );
  1217. if ( pBuf != NULL )
  1218. {
  1219. t_Status = NetSessionGetInfo(
  1220. NULL,
  1221. (const char FAR *) ( a_UserValues.GetAt ( i ).GetBuffer ( 0 ) ),
  1222. a_Level,
  1223. ( char FAR * ) pBuf,
  1224. cbBuffer,
  1225. (unsigned short FAR *) dwTotalSessions
  1226. );
  1227. try
  1228. {
  1229. void *pTempBuf = pBuf;
  1230. int i = 0;
  1231. for ( i = 0; i < dwTotalSessions; i ++ )
  1232. {
  1233. CInstancePtr pInstance ( CreateNewInstance ( pMethodContext ), FALSE );
  1234. hRes = LoadData ( a_Level, pBuf, dwPropertiesReq, pInstance );
  1235. if ( SUCCEEDED ( hRes ) )
  1236. {
  1237. hRes = pInstance->Commit();
  1238. if ( FAILED ( hRes ) )
  1239. {
  1240. bNoMoreEnums = TRUE;
  1241. break;
  1242. }
  1243. }
  1244. if ( bNoMoreEnums )
  1245. {
  1246. break;
  1247. }
  1248. // otherwise need to go to the next entry;
  1249. switch ( a_Level )
  1250. {
  1251. case 2: SESSION_INFO_2 *pTmpTmpBuf2;
  1252. pTmpTmpBuf2 = (SESSION_INFO_2 *) pTmpBuf;
  1253. pTmpTmpBuf2++;
  1254. pTmpBuf = ( void * ) pTmpTmpBuf2;
  1255. break;
  1256. case 1: SESSION_INFO_1 *pTmpTmpBuf1;
  1257. pTmpTmpBuf1 = (SESSION_INFO_1 *) pTmpBuf;
  1258. pTmpTmpBuf1++;
  1259. pTmpBuf = ( void * ) pTmpTmpBuf1;
  1260. break;
  1261. case 10: SESSION_INFO_10 *pTmpTmpBuf10;
  1262. pTmpTmpBuf10 = (SESSION_INFO_10 *) pTmpBuf;
  1263. pTmpTmpBuf10++;
  1264. pTmpBuf = ( void * ) pTmpTmpBuf10;
  1265. break;
  1266. case 50: SESSION_INFO_50 *pTmpTmpBuf50;
  1267. pTmpTmpBuf50 = (SESSION_INFO_50 *) pTmpBuf;
  1268. pTmpTmpBuf50++;
  1269. pTmpBuf = ( void * ) pTmpTmpBuf50;
  1270. break;
  1271. }
  1272. }
  1273. }
  1274. catch ( ... )
  1275. {
  1276. free ( pBuf );
  1277. pBuf = NULL;
  1278. throw;
  1279. }
  1280. free ( pBuf );
  1281. pBuf = NULL;
  1282. }
  1283. else
  1284. {
  1285. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  1286. }
  1287. }
  1288. }
  1289. }
  1290. }
  1291. else
  1292. {
  1293. hRes = WBEM_E_PROVIDER_NOT_CAPABLE;
  1294. }
  1295. return hRes;
  1296. }
  1297. /*****************************************************************************
  1298. *
  1299. * FUNCTION : CSession::Get9XLevelInfo
  1300. *
  1301. * DESCRIPTION : Getting the level info, so that the appropriate structure
  1302. * Can be passed to make a call.
  1303. *
  1304. *****************************************************************************/
  1305. void CSession :: Get9XLevelInfo (
  1306. DWORD dwPropertiesReq,
  1307. short *a_Level
  1308. )
  1309. {
  1310. // Right now making an assumption that Transport/Protocol name is not required
  1311. // as otherwise we will need to make 2 api calls if we need to get Protocol and Clienttype.
  1312. // There is no support for the other levels other than level 50.
  1313. *a_Level = 50;
  1314. /*if ( dwPropertiesReq == SESSION_ALL_PROPS )
  1315. {
  1316. *a_Level = 2;
  1317. }
  1318. else
  1319. if (dwPropertiesReq & SESSION_PROP_NumOpens)
  1320. {
  1321. *a_Level = 1;
  1322. }
  1323. else
  1324. {
  1325. *a_Level = 10;
  1326. }*/
  1327. }
  1328. #endif
  1329. #endif // #if 0
  1330. /*****************************************************************************
  1331. *
  1332. * FUNCTION : CSession::SetPropertiesReq
  1333. *
  1334. * DESCRIPTION : Setting a bitmap for the required properties
  1335. *
  1336. *****************************************************************************/
  1337. void CSession :: SetPropertiesReq (
  1338. CFrameworkQuery &Query,
  1339. DWORD &dwPropertiesReq
  1340. )
  1341. {
  1342. dwPropertiesReq = 0;
  1343. if ( Query.IsPropertyRequired ( IDS_ComputerName ) )
  1344. {
  1345. dwPropertiesReq |= SESSION_PROP_Computer;
  1346. }
  1347. if ( Query.IsPropertyRequired ( IDS_UserName ) )
  1348. {
  1349. dwPropertiesReq |= SESSION_PROP_User;
  1350. }
  1351. if ( Query.IsPropertyRequired ( IDS_SessionType ) )
  1352. {
  1353. dwPropertiesReq |= SESSION_PROP_SessionType;
  1354. }
  1355. if ( Query.IsPropertyRequired ( IDS_ClientType ) )
  1356. {
  1357. dwPropertiesReq |= SESSION_PROP_ClientType;
  1358. }
  1359. if ( Query.IsPropertyRequired ( IDS_TransportName ) )
  1360. {
  1361. dwPropertiesReq |= SESSION_PROP_TransportName;
  1362. }
  1363. if ( Query.IsPropertyRequired ( IDS_ResourcesOpened ) )
  1364. {
  1365. dwPropertiesReq |= SESSION_PROP_NumOpens;
  1366. }
  1367. if ( Query.IsPropertyRequired ( IDS_ActiveTime ) )
  1368. {
  1369. dwPropertiesReq |= SESSION_PROP_ActiveTime;
  1370. }
  1371. if ( Query.IsPropertyRequired ( IDS_IdleTime ) )
  1372. {
  1373. dwPropertiesReq |= SESSION_PROP_IdleTime;
  1374. }
  1375. }