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.

3639 lines
119 KiB

  1. /******************************************************************
  2. Copyright (C) 2000 Microsoft Corp.
  3. Terminal.CPP -- WMI provider class implementation
  4. Generated by Microsoft WMI Code Generation Engine
  5. TO DO: - See individual function headers
  6. - When linking, make sure you link to framedyd.lib &
  7. msvcrtd.lib (debug) or framedyn.lib & msvcrt.lib (retail).
  8. Description:
  9. ******************************************************************/
  10. #include "stdafx.h"
  11. #include <fwcommon.h>
  12. #include "Terminal.h"
  13. #include "registry.h"
  14. #include "smartptr.h"
  15. #include <windows.h>
  16. #include <Iphlpapi.h>
  17. #include "cfgbkend_i.c"
  18. #define TS_PATH TEXT("SYSTEM\\ControlSet\\Control\\Terminal Server")
  19. #define TS_LOGON_PATH TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon")
  20. #define TS_ACTIVEDESKTOP TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies")
  21. #define TERMINAL_SERVICE_PARAM_DISCOVERY TEXT("SYSTEM\\CurrentControlSet\\Services\\TermService\\Parameters")
  22. #define TERMINAL_SERVICE_PARAM_DISCOVERY_SERVERS TEXT("SYSTEM\\CurrentControlSet\\Services\\TermService\\Parameters\\LicenseServers")
  23. #define GUID_LENGTH 40
  24. extern TCHAR tchErrorMessage[ 80 ];
  25. #define ARRAYSIZE( rg ) sizeof( rg ) / sizeof( rg[0] )
  26. // TO DO: Replace "NameSpace" with the appropriate namespace for your
  27. // provider instance. For instance: "root\\default or "root\\cimv2".
  28. //===================================================================
  29. // Property names
  30. //===============
  31. // Property names
  32. //===============
  33. const static WCHAR* pErrorClass = L"\\\\.\\root\\cimv2:TerminalServiceSettingError";
  34. CStackClass::CStackClass ( )
  35. {
  36. HRESULT hr;
  37. m_pCfg = NULL;
  38. m_pCfgComp = NULL;
  39. hr = CoGetClassObject(CLSID_CfgComp, CLSCTX_INPROC_SERVER, NULL, IID_IClassFactory, (void **)&m_pCfg);
  40. TRC2((TB, "StackClass@Constructor: CoGetClassObject of IClassFactory ret 0x%x", hr));
  41. if( SUCCEEDED ( hr ) && m_pCfg != NULL )
  42. {
  43. hr = m_pCfg->CreateInstance(NULL, IID_ICfgComp, (void **)&m_pCfgComp);
  44. TRC2((TB, "StackClass@Constructor: CoCreateInstance of ICfgComp ret 0x%x", hr));
  45. if( SUCCEEDED ( hr ) && m_pCfgComp != NULL )
  46. {
  47. hr = m_pCfgComp->Initialize( );
  48. }
  49. else
  50. {
  51. m_pCfgComp = NULL;
  52. }
  53. }
  54. else
  55. {
  56. m_pCfgComp = NULL;
  57. m_pCfg = NULL;
  58. }
  59. }
  60. //=--------------------
  61. /******************************************************************************************************
  62. *
  63. *DESCRIPTION : CWin32_TSProvider class is a base class from which all other classes are derived.
  64. * The destructor releases the CfgBkEnd interface pointer.
  65. *
  66. ********************************************************************************************************/
  67. CStackClass::~CStackClass ()
  68. {
  69. if ( NULL != m_pCfgComp )
  70. {
  71. m_pCfgComp->Release();
  72. TRC2((TB, "StackClass@Destructor for ICfgComp: succeeded"));
  73. }
  74. if ( NULL != m_pCfg )
  75. {
  76. m_pCfg->Release();
  77. TRC2((TB, "StackClass@Destructor for IClassFactory: succeeded"));
  78. }
  79. }
  80. //------------------------
  81. /*****************************************************************************
  82. *
  83. * FUNCTION : CWin32_TerminalServiceSetting::CWin32_TerminalServiceSetting
  84. * This class reads and sets the Server Settings such as Terminal
  85. * server mode, license type, active desktop state, temp folders,
  86. * logon and Help.
  87. *
  88. *****************************************************************************/
  89. CWin32_TerminalServiceSetting::CWin32_TerminalServiceSetting (LPCWSTR lpwszName, LPCWSTR lpwszNameSpace ) : Provider( lpwszName, lpwszNameSpace )
  90. {
  91. if ( g_hInstance != NULL)
  92. {
  93. TRC2((TB, "CWin32_TerminalServiceSetting_ctor"));
  94. _tcscpy(m_szServerName, _T("ServerName"));
  95. _tcscpy(m_szMode, _T("TerminalServerMode"));
  96. _tcscpy(m_szLicensingName, _T("LicensingName"));
  97. _tcscpy(m_szLicensingDescription, _T("LicensingDescription"));
  98. _tcscpy(m_szActiveDesktop, _T("ActiveDesktop"));
  99. _tcscpy(m_szUserPerm, _T("UserPermission"));
  100. _tcscpy(m_szDeleteTempFolders, _T("DeleteTempFolders"));
  101. _tcscpy(m_szUseTempFolders, _T("UseTempFolders"));
  102. _tcscpy(m_szLogons, _T("Logons"));
  103. _tcscpy(m_szHelp, _T("Help"));
  104. _tcscpy(m_szValue, _T("Value"));
  105. _tcscpy(m_szPropertyName, _T("PropertyName"));
  106. _tcscpy(m_szChangeMode, _T("ChangeMode"));
  107. _tcscpy(m_szLicensingType, _T("LicensingType"));
  108. _tcscpy(m_szSetPolicyPropertyName, _T("SetPolicyPropertyName"));
  109. _tcscpy(m_szAllowTSConnections, _T("AllowTSConnections"));
  110. _tcscpy(m_szSetAllowTSConnections, _T("SetAllowTSConnections"));
  111. _tcscpy(m_szSingleSession, _T("SingleSession"));
  112. _tcscpy(m_szSetSingleSession, _T("SetSingleSession"));
  113. _tcscpy(m_szProfilePath, _T("ProfilePath"));
  114. _tcscpy(m_szHomeDirectory, _T("HomeDirectory"));
  115. _tcscpy(m_szSetProfilePath, _T("SetProfilePath"));
  116. _tcscpy(m_szSetHomeDirectory, _T("SetHomeDirectory"));
  117. _tcscpy(m_szDirectConnectLicenseServers, _T("DirectConnectLicenseServers"));
  118. _tcscpy(m_szAddDirectConnectLicenseServer, _T("AddDirectConnectLicenseServer"));
  119. _tcscpy(m_szDeleteDirectConnectLicenseServer, _T("DeleteDirectConnectLicenseServer"));
  120. _tcscpy(m_szLicenseServerName, _T("LicenseServerName"));
  121. _tcscpy(m_szTimeZoneRedirection, _T("TimeZoneRedirection"));
  122. _tcscpy(m_szSetTimeZoneRedirection, _T("SetTimeZoneRedirection"));
  123. _tcscpy(m_szDisableForcibleLogoff, _T("DisableForcibleLogoff"));
  124. _tcscpy(m_szSetDisableForcibleLogoff, _T("SetDisableForcibleLogoff"));
  125. }
  126. RegGetMachinePolicy(&m_gpPolicy);
  127. }
  128. //=-------------
  129. /*****************************************************************************
  130. *
  131. * FUNCTION : CWin32_TerminalServiceSetting::~CWin32_TerminalServiceSetting
  132. *****************************************************************************/
  133. CWin32_TerminalServiceSetting::~CWin32_TerminalServiceSetting ()
  134. {
  135. }
  136. //=-------------
  137. /*****************************************************************************
  138. *
  139. * FUNCTION : CWin32_TerminalServiceSetting::EnumerateInstances
  140. *
  141. * DESCRIPTION : Returns all the instances of this class.
  142. *
  143. * INPUTS : A pointer to the MethodContext for communication with WinMgmt.
  144. * A long that contains the flags described in
  145. * IWbemServices::CreateInstanceEnumAsync. Note that the following
  146. * flags are handled by (and filtered out by) WinMgmt:
  147. * WBEM_FLAG_DEEP, WBEM_FLAG_SHALLOW, WBEM_FLAG_RETURN_IMMEDIATELY,
  148. * WBEM_FLAG_FORWARD_ONLY, WBEM_FLAG_BIDIRECTIONAL
  149. *
  150. * RETURNS : WBEM_S_NO_ERROR if successful
  151. *
  152. * COMMENTS : All instances on the machine are returned here and
  153. * all properties that this class knows how to populate must
  154. * be filled in. If there are no instances, return
  155. * WBEM_S_NO_ERROR.
  156. *****************************************************************************/
  157. HRESULT CWin32_TerminalServiceSetting::EnumerateInstances (MethodContext* pMethodContext, long lFlags )
  158. {
  159. HRESULT hr = WBEM_E_INVALID_PARAMETER;
  160. CInstance* pInstance = CreateNewInstance(pMethodContext);
  161. if( pInstance != NULL )
  162. {
  163. TRC2((TB, "TerminalServiceSetting@EnumerateInstances: CreateNewInstance succeeded"));
  164. hr = LoadPropertyValues(pInstance, BIT_ALL_PROPERTIES);
  165. if( SUCCEEDED( hr ))
  166. {
  167. hr = pInstance->Commit();
  168. }
  169. pInstance->Release( );
  170. }
  171. return hr ;
  172. }
  173. //=---------
  174. /*****************************************************************************
  175. *
  176. * FUNCTION : CWin32_TerminalServiceSetting::GetObject
  177. *
  178. * DESCRIPTION : Find a single instance based on the key property, the TerminalName.
  179. *
  180. * INPUTS : A pointer to a CInstance object containing the key properties.
  181. * A long that contains the flags described in
  182. * IWbemServices::GetObjectAsync.
  183. *
  184. * RETURNS : WBEM_S_NO_ERROR if the instance can be found
  185. * WBEM_E_NOT_FOUND if the instance described by the key properties
  186. * could not be found
  187. * WBEM_E_FAILED if the instance could be found but another error
  188. * occurred.
  189. *
  190. *****************************************************************************/
  191. HRESULT CWin32_TerminalServiceSetting::GetObject ( CInstance* pInstance, long lFlags, CFrameworkQuery &Query )
  192. {
  193. HRESULT hr = WBEM_S_NO_ERROR;
  194. DWORD dwMode = 0; // Mode
  195. BOOL bActivate ;
  196. DWORD dwStatus = 0;
  197. CRegistry oRegObject;
  198. DWORD dwData = 0;
  199. DWORD dwRequiredProperties = 0;
  200. if( Query.IsPropertyRequired(m_szServerName))
  201. dwRequiredProperties |= BIT_SERVERNAME;
  202. if (Query.IsPropertyRequired(m_szMode))
  203. dwRequiredProperties |= BIT_MODE;
  204. if (Query.IsPropertyRequired(m_szActiveDesktop))
  205. dwRequiredProperties |= BIT_ACTIVEDESKTOP;
  206. if (Query.IsPropertyRequired(m_szDeleteTempFolders))
  207. dwRequiredProperties |= BIT_DELETETEMPDIRS;
  208. if (Query.IsPropertyRequired(m_szLicensingType))
  209. dwRequiredProperties |= BIT_LICENSING;
  210. if (Query.IsPropertyRequired(m_szLicensingName))
  211. dwRequiredProperties |= BIT_LICENSING;
  212. if (Query.IsPropertyRequired(m_szLicensingDescription))
  213. dwRequiredProperties |= BIT_LICENSING;
  214. if (Query.IsPropertyRequired(m_szLogons))
  215. dwRequiredProperties |= BIT_LOGONS;
  216. if (Query.IsPropertyRequired(m_szUserPerm))
  217. dwRequiredProperties |= BIT_USERPERM;
  218. if (Query.IsPropertyRequired(m_szUseTempFolders))
  219. dwRequiredProperties |= BIT_PERSESSIONTEMPDIR;
  220. if (Query.IsPropertyRequired(m_szHelp))
  221. dwRequiredProperties |= BIT_HELP;
  222. if (Query.IsPropertyRequired(m_szAllowTSConnections))
  223. dwRequiredProperties |= BIT_ALLOWTSCONNECTIONS;
  224. if (Query.IsPropertyRequired(m_szSingleSession))
  225. dwRequiredProperties |= BIT_SINGLESESSION;
  226. if (Query.IsPropertyRequired(m_szProfilePath))
  227. dwRequiredProperties |= BIT_PROFILEPATH;
  228. if (Query.IsPropertyRequired(m_szHomeDirectory))
  229. dwRequiredProperties |= BIT_HOMEDIRECTORY;
  230. if (Query.IsPropertyRequired(m_szDirectConnectLicenseServers))
  231. dwRequiredProperties |= BIT_DIRECTCONNECTLICENSESERVERS;
  232. if (Query.IsPropertyRequired(m_szTimeZoneRedirection))
  233. dwRequiredProperties |= BIT_TIMEZONEREDIRECTION;
  234. if (Query.IsPropertyRequired(m_szDisableForcibleLogoff))
  235. dwRequiredProperties |= BIT_DISABLEFORCIBLELOGOFF;
  236. hr = LoadPropertyValues(pInstance, dwRequiredProperties);
  237. return S_OK ;
  238. }
  239. //=---------
  240. /*****************************************************************************
  241. *
  242. * FUNCTION : CWin32_TerminalServiceSetting::ExecQuery
  243. *
  244. * DESCRIPTION : The method context is passed for use in the creation of
  245. * instances that satisfy the query, and a CFrameworkQuery
  246. * which describes the query. Create and populate all
  247. * instances which satisfy the query. You may return more
  248. * instances or more properties than are requested and WinMgmt
  249. * will post filter out any that do not apply.
  250. *
  251. * INPUTS : A pointer to the MethodContext for communication with WinMgmt.
  252. * A query object describing the query to satisfy.
  253. * A long that contains the flags described in
  254. * IWbemServices::CreateInstanceEnumAsync. Note that the following
  255. * flags are handled by (and filtered out by) WinMgmt:
  256. * WBEM_FLAG_FORWARD_ONLY
  257. * WBEM_FLAG_BIDIRECTIONAL
  258. * WBEM_FLAG_ENSURE_LOCATABLE
  259. *
  260. * RETURNS : WBEM_E_PROVIDER_NOT_CAPABLE if queries not supported for
  261. * this class or if the query is too complex for this class
  262. * to interpret. The framework will call the EnumerateInstances
  263. * function instead and let Winmgmt post filter.
  264. * WBEM_E_FAILED if the query failed
  265. * WBEM_S_NO_ERROR if query was successful
  266. *
  267. * COMMENTS : TO DO: Most providers will not need to implement this method. If you don't, WinMgmt
  268. * will call your enumerate function to get all the instances and perform the
  269. * filtering for you. Unless you expect SIGNIFICANT savings from implementing
  270. * queries, you should remove this method. You should also remove this method
  271. * if you are implementing a 'method only' provider.
  272. *
  273. *****************************************************************************/
  274. HRESULT CWin32_TerminalServiceSetting::ExecQuery (MethodContext *pMethodContext, CFrameworkQuery& Query, long lFlags)
  275. {
  276. HRESULT hr = WBEM_E_NOT_FOUND;
  277. DWORD dwRequiredProperties = 0;
  278. CHStringArray asNames;
  279. DWORD dwMode = 0;
  280. DWORD dwStatus = 0;
  281. CStackClass StackObj;
  282. if( StackObj.m_pCfgComp == NULL)
  283. {
  284. return WBEM_E_ILLEGAL_NULL;
  285. }
  286. // Method 2
  287. Query.GetValuesForProp(m_szServerName, asNames);
  288. BOOL bGetAllInstances = asNames.GetSize() == 0;
  289. // Method 1
  290. if (Query.IsPropertyRequired(m_szServerName))
  291. dwRequiredProperties |= BIT_SERVERNAME;
  292. if (Query.IsPropertyRequired(m_szMode))
  293. dwRequiredProperties |= BIT_MODE;
  294. if (Query.IsPropertyRequired(m_szActiveDesktop))
  295. dwRequiredProperties |= BIT_ACTIVEDESKTOP;
  296. if (Query.IsPropertyRequired(m_szDeleteTempFolders))
  297. dwRequiredProperties |= BIT_DELETETEMPDIRS;
  298. if (Query.IsPropertyRequired(m_szLicensingType))
  299. dwRequiredProperties |= BIT_LICENSING;
  300. if (Query.IsPropertyRequired(m_szLogons))
  301. dwRequiredProperties |= BIT_LOGONS;
  302. if (Query.IsPropertyRequired(m_szUserPerm))
  303. dwRequiredProperties |= BIT_USERPERM;
  304. if (Query.IsPropertyRequired(m_szUseTempFolders))
  305. dwRequiredProperties |= BIT_PERSESSIONTEMPDIR;
  306. if (Query.IsPropertyRequired(m_szHelp))
  307. dwRequiredProperties |= BIT_HELP;
  308. if (Query.IsPropertyRequired(m_szAllowTSConnections))
  309. dwRequiredProperties |= BIT_ALLOWTSCONNECTIONS;
  310. if (Query.IsPropertyRequired(m_szSingleSession))
  311. dwRequiredProperties |= BIT_SINGLESESSION;
  312. if (Query.IsPropertyRequired(m_szProfilePath))
  313. dwRequiredProperties |= BIT_PROFILEPATH;
  314. if (Query.IsPropertyRequired(m_szHomeDirectory))
  315. dwRequiredProperties |= BIT_HOMEDIRECTORY;
  316. if (Query.IsPropertyRequired(m_szDirectConnectLicenseServers))
  317. dwRequiredProperties |= BIT_DIRECTCONNECTLICENSESERVERS;
  318. if (Query.IsPropertyRequired(m_szTimeZoneRedirection))
  319. dwRequiredProperties |= BIT_TIMEZONEREDIRECTION;
  320. if (Query.IsPropertyRequired(m_szDisableForcibleLogoff))
  321. dwRequiredProperties |= BIT_DISABLEFORCIBLELOGOFF;
  322. ISettingsComp *pSettings = NULL;
  323. hr = StackObj.m_pCfgComp->QueryInterface( IID_ISettingsComp , ( PVOID * )&pSettings ) ;
  324. do
  325. {
  326. if( SUCCEEDED( hr ) && pSettings != NULL )
  327. {
  328. // Method 2
  329. CInstance* pInstance = CreateNewInstance(pMethodContext);
  330. if( pInstance == NULL)
  331. {
  332. ERR((TB, "TerminalServiceSetting@ExecQuery: CreateNewInstance failed"));
  333. hr = WBEM_E_OUT_OF_MEMORY;
  334. break;
  335. }
  336. hr = LoadPropertyValues(pInstance, dwRequiredProperties);
  337. if( SUCCEEDED( hr ) )
  338. {
  339. hr = pInstance->Commit();
  340. }
  341. pInstance->Release();
  342. }
  343. }while (0);
  344. if ( pSettings != NULL )
  345. {
  346. pSettings->Release();
  347. }
  348. return hr;
  349. }
  350. //=--------------
  351. BOOL CWin32_TerminalServiceSetting::IsInList(const CHStringArray &asArray, LPCWSTR pszString)
  352. {
  353. DWORD dwSize = asArray.GetSize();
  354. for (DWORD x=0; x < dwSize; x++)
  355. {
  356. if( asArray[x].CompareNoCase(pszString) == 0 )
  357. {
  358. return TRUE;
  359. }
  360. }
  361. return FALSE;
  362. }
  363. //=---------
  364. /*************************************************************************************
  365. *
  366. * FUNCTION : CWin32_TerminalServiceSetting::PutInstance
  367. *
  368. * DESCRIPTION : PutInstance is in provider classes that can
  369. * write instance information back to the registry.
  370. *
  371. * INPUTS : A pointer to a CInstance object containing the key
  372. * property - TerminalServerMode.
  373. *
  374. * A long that contains the flags described in
  375. * IWbemServices::PutInstanceAsync.
  376. *
  377. * RETURNS : WBEM_E_PROVIDER_NOT_CAPABLE if PutInstance is not available
  378. * WBEM_E_FAILED if there is an error delivering the instance
  379. * WBEM_E_INVALID_PARAMETER if any of the instance properties
  380. * are incorrect.
  381. * WBEM_S_NO_ERROR if instance is properly delivered
  382. *
  383. * COMMENTS : ActiveDesktop state, UserPerm and Logon are configurable through
  384. * this method as they are not Group Policy based nor server-overridable.
  385. *
  386. ***************************************************************************************/
  387. HRESULT CWin32_TerminalServiceSetting::PutInstance ( const CInstance &Instance, long lFlags)
  388. {
  389. HRESULT hr = 0;
  390. DWORD dwMode = 0;
  391. DWORD dwlicensing = 0; // Licensing mode
  392. DWORD dwActiveDesktop = 0; // Active Desktop Enabled or Disabled
  393. DWORD dwUserPerm = 0; // Application Compatibility
  394. DWORD dwDeleteTempFolders = 0; // Delete Temporary Directories on Exit
  395. DWORD dwUseTempFolders = 0;
  396. DWORD dwData = 0;
  397. DWORD dwStatus = 0;
  398. CHString chData;
  399. CRegistry oRegObject;
  400. OSVERSIONINFOW OsVersionInfo;
  401. OsVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
  402. TCHAR tch[MAX_PATH] = {0};
  403. ICfgComp *pCfgComp = NULL;
  404. HKEY hKey = NULL;
  405. HKEY hOutKey = NULL;
  406. hr = WBEM_S_NO_ERROR;
  407. CStackClass StackObj;
  408. if(StackObj.m_pCfgComp == NULL)
  409. {
  410. return WBEM_E_ILLEGAL_NULL;
  411. }
  412. ISettingsComp *pSettings = NULL;
  413. hr = StackObj.m_pCfgComp->QueryInterface( IID_ISettingsComp , ( PVOID * )&pSettings ) ;
  414. do
  415. {
  416. if( SUCCEEDED (hr) && pSettings != NULL )
  417. {
  418. if( Instance.GetDWORD(m_szActiveDesktop, dwActiveDesktop ) )
  419. {
  420. hr = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  421. TS_ACTIVEDESKTOP ,
  422. 0,
  423. KEY_READ ,
  424. &hKey );
  425. if( ERROR_SUCCESS == hr )
  426. {
  427. hr = RegCreateKeyEx( hKey ,
  428. L"Explorer",
  429. 0,
  430. NULL,
  431. REG_OPTION_NON_VOLATILE,
  432. KEY_ALL_ACCESS,
  433. NULL,
  434. &hOutKey ,
  435. &dwData );
  436. }
  437. if( dwActiveDesktop != 0 && dwActiveDesktop != 1 )
  438. {
  439. hr = WBEM_E_INVALID_PARAMETER;
  440. break;
  441. }
  442. pSettings->SetActiveDesktopState( dwActiveDesktop, &dwStatus );
  443. TRC2((TB, "TerminalServiceSetting@PutInstance: SetActiveDesktopState returned 0x%x\n" , dwStatus));
  444. }
  445. if( Instance.GetDWORD( m_szUserPerm, dwUserPerm ) )
  446. {
  447. if( dwUserPerm != 0 && dwUserPerm != 1 )
  448. {
  449. hr = WBEM_E_INVALID_PARAMETER;
  450. break;
  451. }
  452. pSettings->SetUserPerm(dwUserPerm, &dwStatus );
  453. TRC2((TB, "TerminalServiceSetting@PutInstance: SetUserPerm returned 0x%x\n" , dwStatus));
  454. }
  455. hr = oRegObject.OpenKey(HKEY_LOCAL_MACHINE, TS_LOGON_PATH);
  456. chData.Empty();
  457. if( SUCCEEDED( hr ) )
  458. {
  459. if( GetVersionEx( &OsVersionInfo) )
  460. {
  461. if( OsVersionInfo.dwMajorVersion == 5 && OsVersionInfo.dwMinorVersion == 0 )
  462. {
  463. TRC2((TB, "TerminalServiceSetting@GetObject GetVersionInfo is Win2000"));
  464. if( Instance.GetCHString(m_szLogons, chData ) )
  465. {
  466. if( chData.IsEmpty() || ((lstrcmp ((LPCTSTR)chData, L"0") != 0 ) && (lstrcmp ((LPCTSTR) chData, L"1") != 0)) )
  467. {
  468. hr = WBEM_E_INVALID_PARAMETER;
  469. break;
  470. }
  471. // Todo: Add this for Beta2 to reverse logic
  472. /*
  473. if( lstrcmp ((LPCTSTR)chData, L"0") == 0 )
  474. {
  475. chData.Empty();
  476. chData = L"1";
  477. }
  478. else
  479. {
  480. chData.Empty();
  481. chData = L"0";
  482. }
  483. */
  484. hr = oRegObject.WriteRegString(L"WinStationsDisabled", (LPTSTR) (LPCTSTR) chData);
  485. TRC2((TB, "TerminalServiceSetting@PutInstance WinStationsDisabled returned 0x%x\n" , hr));
  486. }
  487. }
  488. else
  489. {
  490. TRC2((TB, "TermServiceSetting@PutInstance GetVersionInfo is Whistler"));
  491. if( Instance.GetCHString(m_szLogons, chData ) )
  492. {
  493. if( chData.IsEmpty() || ((lstrcmp ((LPCTSTR)chData, L"0") != 0 ) && (lstrcmp ((LPCTSTR) chData, L"1") != 0)) )
  494. {
  495. hr = WBEM_E_INVALID_PARAMETER;
  496. break;
  497. }
  498. /*
  499. if( lstrcmp ((LPCTSTR)chData, L"0") == 0 )
  500. {
  501. chData.Empty();
  502. chData = L"1";
  503. }
  504. else
  505. {
  506. chData.Empty();
  507. chData = L"0";
  508. }
  509. */
  510. hr = oRegObject.WriteRegString(L"WinStationsDisabled", (LPTSTR) (LPCTSTR) chData);
  511. TRC2((TB, "TermServiceSetting@PutInstance WinStationDisabled returned 0x%x\n" , hr));
  512. }
  513. }
  514. }
  515. }
  516. // ForceUpdate() is called explicitly to update WinstationsDisabled in the registry.
  517. if( SUCCEEDED( hr ) )
  518. {
  519. StackObj.m_pCfgComp->ForceUpdate();
  520. }
  521. }
  522. }while(0);
  523. if( NULL != hKey)
  524. {
  525. RegCloseKey(hKey);
  526. }
  527. if( NULL != hOutKey)
  528. {
  529. RegCloseKey(hOutKey);
  530. }
  531. if( pSettings != NULL )
  532. {
  533. pSettings->Release();
  534. }
  535. return hr;
  536. }
  537. //=---------
  538. /*****************************************************************************
  539. *
  540. * FUNCTION : CWin32_TerminalServiceSetting::DeleteInstance
  541. *
  542. * DESCRIPTION : DeleteInstance, like PutInstance, actually writes information
  543. * to the software or hardware. For most hardware devices,
  544. * DeleteInstance should not be implemented, but for software
  545. * configuration, DeleteInstance implementation is plausible.
  546. *
  547. * INPUTS : A pointer to a CInstance object containing the key properties.
  548. * A long that contains the flags described in
  549. * IWbemServices::DeleteInstanceAsync.
  550. *
  551. * RETURNS : WBEM_E_PROVIDER_NOT_CAPABLE if DeleteInstance is not available.
  552. * WBEM_E_FAILED if there is an error deleting the instance.
  553. * WBEM_E_INVALID_PARAMETER if any of the instance properties
  554. * are incorrect.
  555. * WBEM_S_NO_ERROR if instance is properly deleted.
  556. *
  557. * COMMENTS : TO DO: If you don't intend to support deleting instances or are
  558. * creating a 'method only' provider, remove this method.
  559. *
  560. *****************************************************************************/
  561. HRESULT CWin32_TerminalServiceSetting::DeleteInstance ( const CInstance &Instance, long lFlags )
  562. {
  563. return (WBEM_E_PROVIDER_NOT_CAPABLE);
  564. }
  565. //=---------
  566. /*****************************************************************************
  567. *
  568. * FUNCTION : CWin32_TerminalServiceSetting::ExecMethod
  569. *
  570. * DESCRIPTION : Override this function to provide support for methods.
  571. * A method is an entry point for the user of your provider
  572. * to request your class perform some function above and
  573. * beyond a change of state. (A change of state should be
  574. * handled by PutInstance() )
  575. *
  576. * INPUTS : A pointer to a CInstance containing the instance the method was executed against.
  577. * A string containing the method name
  578. * A pointer to the CInstance which contains the IN parameters.
  579. * A pointer to the CInstance to contain the OUT parameters.
  580. * A set of specialized method flags
  581. *
  582. * RETURNS : WBEM_E_PROVIDER_NOT_CAPABLE if not implemented for this class
  583. * WBEM_S_NO_ERROR if method executes successfully
  584. * WBEM_E_FAILED if error occurs executing method
  585. *
  586. * COMMENTS : Provides method to configure the License type base on
  587. * the Terminal server mode, UseTempFolders, DeleteTempFolders
  588. * and Help that are group policy based.
  589. *
  590. *****************************************************************************/
  591. HRESULT CWin32_TerminalServiceSetting::ExecMethod ( const CInstance& Inst,
  592. const BSTR bstrMethodName,
  593. CInstance *pInParams,
  594. CInstance *pOutParams,
  595. long lFlags)
  596. {
  597. DWORD dwMode = 0;
  598. DWORD dwLicensing = 0;
  599. DWORD dwStatus = 0;
  600. DWORD dwNewStatus = 0;
  601. DWORD dwData = 0;
  602. HANDLE hServer = NULL;
  603. BOOL fRet = FALSE;
  604. CHString chData;
  605. bool fData;
  606. bool bRet;
  607. CRegistry oRegObject;
  608. HRESULT hr = WBEM_E_INVALID_PARAMETER;
  609. CStackClass StackObj;
  610. HKEY hKey = NULL;
  611. HKEY hOutKey = NULL;
  612. if(StackObj.m_pCfgComp == NULL)
  613. {
  614. return WBEM_E_ILLEGAL_NULL;
  615. }
  616. ISettingsComp *pSettings = NULL;
  617. if(pInParams == NULL)
  618. {
  619. return WBEM_E_INVALID_METHOD_PARAMETERS;
  620. }
  621. hr = StackObj.m_pCfgComp->QueryInterface( IID_ISettingsComp , ( PVOID * )&pSettings ) ;
  622. do
  623. {
  624. if( SUCCEEDED (hr) && pSettings != NULL )
  625. {
  626. if( _wcsicmp(bstrMethodName, m_szChangeMode) == 0 )
  627. {
  628. // Configures License type based on the Terminal Server Mode. {None, Remote Administration} for "Remote Admin",
  629. // {Per Seat, Per CPU, ICL} for "Application Server" and {Personal Terminal Server} for "Personal Terminal Server".
  630. // uint32 ChangeMode([In] uint32 LicensingType);
  631. hr = WBEM_S_NO_ERROR ;
  632. bRet = pInParams->GetDWORD(m_szLicensingType, dwLicensing);
  633. if ( !bRet )
  634. {
  635. hr = WBEM_E_INVALID_PARAMETER;
  636. break;
  637. }
  638. hServer = ServerLicensingOpen(NULL);
  639. if (NULL != hServer)
  640. {
  641. dwStatus = ServerLicensingSetPolicy(hServer, dwLicensing, &dwNewStatus);
  642. TRC2( (TB, "TermServiceSetting@ExecMethod:ChangeMode ServerLicensingSetPolicy ret old: 0x%x new: 0x%x\n" , dwStatus, dwNewStatus) );
  643. if( ERROR_SUCCESS == dwStatus && ERROR_SUCCESS == dwNewStatus && pOutParams != NULL )
  644. {
  645. pOutParams->SetDWORD(L"ReturnValue", WBEM_S_NO_ERROR);
  646. }
  647. else if( ERROR_SUCCESS != dwStatus || ERROR_SUCCESS != dwNewStatus )
  648. {
  649. hr = WBEM_E_INVALID_OPERATION;
  650. break;
  651. }
  652. }
  653. }
  654. else if( _wcsicmp( bstrMethodName, m_szSetAllowTSConnections ) == 0 )
  655. {
  656. dwData = 0;
  657. dwStatus = 0;
  658. bRet;
  659. RegGetMachinePolicy(&m_gpPolicy);
  660. if( m_gpPolicy.fPolicyDenyTSConnections == 0 )
  661. {
  662. TRC2((TB, "Condition to update fPolicyDenyTSConnections satisfied"));
  663. bRet = pInParams->GetDWORD(m_szAllowTSConnections, dwData);
  664. if ( !bRet || (dwData != 0 && dwData != 1 ))
  665. {
  666. hr = WBEM_E_INVALID_PARAMETER;
  667. break;
  668. }
  669. // The bit is negated because it calls the function SetDenyTSConnections which is negative logic.
  670. if( dwData == 0 )
  671. {
  672. dwData = 1;
  673. }
  674. else if( dwData == 1 )
  675. {
  676. dwData = 0;
  677. }
  678. hr = pSettings->SetDenyTSConnections( dwData , &dwStatus );
  679. if( SUCCEEDED( hr ) && pOutParams != NULL )
  680. {
  681. hr = StackObj.m_pCfgComp->ForceUpdate();
  682. pOutParams->SetDWORD(L"ReturnValue", WBEM_S_NO_ERROR);
  683. TRC2((TB,"TerminalServiceSetting@ExecMethod: SetAllowTSConnections ret 0x%x\n" , hr ));
  684. }
  685. }
  686. else
  687. {
  688. hr = WBEM_E_INVALID_OPERATION;
  689. break;
  690. }
  691. }
  692. else if( _wcsicmp( bstrMethodName, m_szSetTimeZoneRedirection ) == 0 )
  693. {
  694. dwData = 0;
  695. dwStatus = 0;
  696. bRet;
  697. RegGetMachinePolicy(&m_gpPolicy);
  698. //todo: change the policy name
  699. if( m_gpPolicy.fPolicyEnableTimeZoneRedirection == 0 )
  700. {
  701. TRC2((TB, "Condition to update fPolicyEnableTimeZoneRedirection satisfied"));
  702. bRet = pInParams->GetDWORD(m_szTimeZoneRedirection, dwData);
  703. if ( !bRet || (dwData != 0 && dwData != 1 ))
  704. {
  705. hr = WBEM_E_INVALID_PARAMETER;
  706. break;
  707. }
  708. hr = pSettings->SetTimeZoneRedirection( dwData , &dwStatus );
  709. if( SUCCEEDED( hr ) && pOutParams != NULL )
  710. {
  711. hr = StackObj.m_pCfgComp->ForceUpdate();
  712. pOutParams->SetDWORD(L"ReturnValue", WBEM_S_NO_ERROR);
  713. TRC2((TB,"TerminalServiceSetting@ExecMethod: SetTimeZoneRedirection ret 0x%x\n" , hr ));
  714. }
  715. }
  716. else
  717. {
  718. hr = WBEM_E_INVALID_OPERATION;
  719. break;
  720. }
  721. }
  722. else if( _wcsicmp( bstrMethodName, m_szSetSingleSession ) == 0 )
  723. {
  724. dwData = 0;
  725. dwStatus = 0;
  726. bRet;
  727. RegGetMachinePolicy(&m_gpPolicy);
  728. if( m_gpPolicy.fPolicySingleSessionPerUser == 0 )
  729. {
  730. TRC2((TB, "Condition to update fSingleSessionPerUser satisfied"));
  731. bRet = pInParams->GetDWORD(m_szSingleSession, dwData);
  732. if ( !bRet || (dwData != 0 && dwData != 1 ))
  733. {
  734. hr = WBEM_E_INVALID_PARAMETER;
  735. break;
  736. }
  737. hr = pSettings->SetSingleSessionState( dwData , &dwStatus );
  738. if( SUCCEEDED( hr ) && pOutParams != NULL )
  739. {
  740. hr = StackObj.m_pCfgComp->ForceUpdate();
  741. pOutParams->SetDWORD(L"ReturnValue", WBEM_S_NO_ERROR);
  742. TRC2((TB,"TerminalServiceSetting@ExecMethod: SetSingleSession ret 0x%x\n" , hr ));
  743. }
  744. }
  745. else
  746. {
  747. hr = WBEM_E_INVALID_OPERATION;
  748. break;
  749. }
  750. }
  751. else if( _wcsicmp( bstrMethodName, m_szSetProfilePath ) == 0 )
  752. {
  753. BSTR bstrVal = NULL;
  754. dwStatus = 0;
  755. bRet;
  756. RegGetMachinePolicy(&m_gpPolicy);
  757. if( m_gpPolicy.fPolicyWFProfilePath == 0 )
  758. {
  759. TRC2((TB, "Condition to update WFProfilePath satisfied"));
  760. bRet = pInParams->GetCHString(m_szProfilePath, chData);
  761. if ( !bRet )
  762. {
  763. hr = WBEM_E_INVALID_PARAMETER;
  764. break;
  765. }
  766. bstrVal = SysAllocString((LPTSTR) (LPCTSTR) (chData));
  767. if(bstrVal != NULL)
  768. {
  769. hr = pSettings->SetProfilePath( bstrVal , &dwStatus );
  770. if( SUCCEEDED( hr ) && pOutParams != NULL )
  771. {
  772. hr = StackObj.m_pCfgComp->ForceUpdate();
  773. pOutParams->SetDWORD(L"ReturnValue", WBEM_S_NO_ERROR);
  774. TRC2((TB,"TerminalServiceSetting@ExecMethod: SetProfilePath ret 0x%x\n" , hr ));
  775. }
  776. }
  777. }
  778. else
  779. {
  780. hr = WBEM_E_INVALID_OPERATION;
  781. break;
  782. }
  783. }
  784. else if( _wcsicmp( bstrMethodName, m_szSetHomeDirectory ) == 0 )
  785. {
  786. BSTR bstrVal = NULL;
  787. dwStatus = 0;
  788. bRet;
  789. RegGetMachinePolicy(&m_gpPolicy);
  790. if( m_gpPolicy.fPolicyWFHomeDir == 0 )
  791. {
  792. TRC2((TB, "Condition to update WFProfilePath satisfied"));
  793. bRet = pInParams->GetCHString(m_szHomeDirectory, chData);
  794. if ( !bRet )
  795. {
  796. hr = WBEM_E_INVALID_PARAMETER;
  797. break;
  798. }
  799. bstrVal = SysAllocString((LPTSTR) (LPCTSTR) (chData));
  800. if(bstrVal != NULL)
  801. {
  802. hr = pSettings->SetHomeDir( bstrVal , &dwStatus );
  803. if( SUCCEEDED( hr ) && pOutParams != NULL )
  804. {
  805. hr = StackObj.m_pCfgComp->ForceUpdate();
  806. pOutParams->SetDWORD(L"ReturnValue", WBEM_S_NO_ERROR);
  807. TRC2((TB,"TerminalServiceSetting@ExecMethod: SetHomeDirectory ret 0x%x\n" , hr ));
  808. }
  809. }
  810. }
  811. else
  812. {
  813. hr = WBEM_E_INVALID_OPERATION;
  814. break;
  815. }
  816. }
  817. else if( _wcsicmp( bstrMethodName, m_szSetDisableForcibleLogoff ) == 0 )
  818. {
  819. dwData = 0;
  820. dwStatus = 0;
  821. bRet;
  822. RegGetMachinePolicy(&m_gpPolicy);
  823. if( m_gpPolicy.fPolicyDisableForcibleLogoff == 0 )
  824. {
  825. TRC2((TB, "Condition to update fDisableForcibleLogoff satisfied"));
  826. bRet = pInParams->GetDWORD(m_szDisableForcibleLogoff, dwData);
  827. if ( !bRet || (dwData != 0 && dwData != 1 ))
  828. {
  829. hr = WBEM_E_INVALID_PARAMETER;
  830. break;
  831. }
  832. hr = pSettings->SetDisableForcibleLogoff( dwData , &dwStatus );
  833. if( SUCCEEDED( hr ) && pOutParams != NULL )
  834. {
  835. hr = StackObj.m_pCfgComp->ForceUpdate();
  836. pOutParams->SetDWORD(L"ReturnValue", WBEM_S_NO_ERROR);
  837. TRC2((TB,"TerminalServiceSetting@ExecMethod: SetDisableForcibleLogoff ret 0x%x\n" , hr ));
  838. }
  839. }
  840. else
  841. {
  842. hr = WBEM_E_INVALID_OPERATION;
  843. break;
  844. }
  845. }
  846. else if( _wcsicmp(bstrMethodName, m_szSetPolicyPropertyName) == 0 )
  847. {
  848. // PropertyName is an enumeration of the properties:
  849. // DeleteTempFolders, UseTempFolders and Help which are flags that are either set
  850. // to False or True according as whether Value is set to 0 or 1 respectively.
  851. //
  852. // uint32 SetPolicyPropertyName([In] string PropertyName, [In] boolean Value) ;
  853. bRet = 0;
  854. RegGetMachinePolicy(&m_gpPolicy);
  855. pInParams->GetCHString(m_szPropertyName, chData);
  856. if( chData.CompareNoCase(m_szDeleteTempFolders) == 0 )
  857. {
  858. bRet = pInParams->Getbool(m_szValue, fData);
  859. TRC2((TB, "m_gpPolicy.fPolicyDeleteTempFoldersOnExit ret 0x%x\n", m_gpPolicy.fPolicyDeleteTempFoldersOnExit));
  860. if( m_gpPolicy.fPolicyDeleteTempFoldersOnExit == 0 )
  861. {
  862. TRC2((TB, "Condition to update fPolicyDeleteTempFoldersOnExit satisfied"));
  863. if( !bRet || (fData != 0 && fData != 1 ))
  864. {
  865. hr = WBEM_E_INVALID_PARAMETER;
  866. break;
  867. }
  868. hr = pSettings->SetDelDirsOnExit(fData);
  869. TRC2((TB, "TerminalServiceSetting@PutInstance: SetDelDirsOnExit"));
  870. if( pOutParams != NULL )
  871. {
  872. pOutParams->SetDWORD(L"ReturnValue", hr);
  873. }
  874. }
  875. else
  876. {
  877. hr = WBEM_E_INVALID_OPERATION;
  878. break;
  879. }
  880. }
  881. else if( chData.CompareNoCase(m_szUseTempFolders) == 0 )
  882. {
  883. bRet = 0;
  884. bRet = pInParams->Getbool(L"Value", fData);
  885. TRC2((TB, "m_gpPolicy.fPolicyTempFoldersPerSession ret 0x%x\n", m_gpPolicy.fPolicyTempFoldersPerSession));
  886. if( m_gpPolicy.fPolicyTempFoldersPerSession == 0 )
  887. {
  888. TRC2((TB, "Condition to update fPolicyTempFoldersPerSession satisfied"));
  889. if( !bRet || ( fData != 0 && fData != 1 ))
  890. {
  891. hr = WBEM_E_INVALID_PARAMETER;
  892. break;
  893. }
  894. hr = pSettings->SetUseTempDirPerSession(fData );
  895. TRC2((TB, "TerminalServiceSetting@ExecMethod: SetUseTempDirPerSession"));
  896. if( pOutParams != NULL )
  897. {
  898. pOutParams->SetDWORD(L"ReturnValue", hr);
  899. }
  900. }
  901. else
  902. {
  903. hr = WBEM_E_INVALID_OPERATION;
  904. break;
  905. }
  906. }
  907. else if( chData.CompareNoCase(m_szHelp) == 0 )
  908. {
  909. bRet = 0;
  910. hr = oRegObject.OpenKey(HKEY_LOCAL_MACHINE, TS_POLICY_SUB_TREE);
  911. if( SUCCEEDED (hr) )
  912. {
  913. if( ERROR_SUCCESS != oRegObject.ReadRegDWord(POLICY_TS_REMDSK_ALLOWTOGETHELP, &dwData) )
  914. {
  915. bRet = pInParams->Getbool(m_szValue, fData);
  916. TRC2((TB, "Condition to update fAllowToGetHelp satisfied"));
  917. if( !bRet || (fData != 0 && fData != 1 ))
  918. {
  919. hr = WBEM_E_INVALID_PARAMETER;
  920. break;
  921. }
  922. hr = pSettings->SetSalemHelpMode(fData, &dwStatus );
  923. TRC2((TB, "TerminalServiceSetting@ExecMethod: Help"));
  924. if( pOutParams != NULL && dwStatus == ERROR_SUCCESS )
  925. {
  926. pOutParams->SetDWORD(L"ReturnValue", WBEM_S_NO_ERROR);
  927. }
  928. else
  929. {
  930. hr = WBEM_E_INVALID_OPERATION;
  931. break;
  932. }
  933. }
  934. }
  935. }
  936. else
  937. {
  938. hr = WBEM_E_INVALID_METHOD_PARAMETERS;
  939. break;
  940. }
  941. }
  942. else if( _wcsicmp( bstrMethodName, m_szAddDirectConnectLicenseServer ) == 0 )
  943. {
  944. DWORD dwReturn = 0;
  945. bRet = pInParams->GetCHString(m_szLicenseServerName, chData);
  946. if( chData.IsEmpty() || (chData.GetLength() >= OPAQUESETTINGS_LENGTH) )
  947. {
  948. hr = WBEM_E_INVALID_PARAMETER;
  949. break;
  950. }
  951. hr = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  952. TERMINAL_SERVICE_PARAM_DISCOVERY ,
  953. 0,
  954. KEY_READ ,
  955. &hKey );
  956. if( ERROR_SUCCESS == hr )
  957. {
  958. hr = RegCreateKeyEx( hKey ,
  959. L"LicenseServers",
  960. 0,
  961. NULL,
  962. REG_OPTION_NON_VOLATILE,
  963. KEY_ALL_ACCESS,
  964. NULL,
  965. &hOutKey ,
  966. &dwReturn );
  967. if( ERROR_SUCCESS == hr )
  968. {
  969. hr = RegCreateKeyEx( hOutKey ,
  970. chData.LockBuffer(),
  971. 0,
  972. NULL,
  973. REG_OPTION_NON_VOLATILE,
  974. KEY_ALL_ACCESS,
  975. NULL,
  976. &hOutKey ,
  977. &dwReturn );
  978. chData.UnlockBuffer();
  979. TRC2((TB, "Win32_TerminalServiceSetting@ExecMethod: AddLicenseServer ret 0x%x" , hr));
  980. }
  981. if( hr == ERROR_SUCCESS )
  982. {
  983. pOutParams->SetDWORD(L"ReturnValue", WBEM_S_NO_ERROR);
  984. }
  985. chData.Empty();
  986. }
  987. }
  988. else if( _wcsicmp( bstrMethodName, m_szDeleteDirectConnectLicenseServer ) == 0 )
  989. {
  990. DWORD dwReturn = 0;
  991. bRet = pInParams->GetCHString(m_szLicenseServerName, chData );
  992. if( chData.IsEmpty() || (chData.GetLength() >= OPAQUESETTINGS_LENGTH) )
  993. {
  994. hr = WBEM_E_INVALID_PARAMETER;
  995. break;
  996. }
  997. hr = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  998. TERMINAL_SERVICE_PARAM_DISCOVERY_SERVERS,
  999. 0,
  1000. KEY_ALL_ACCESS ,
  1001. &hKey );
  1002. if( ERROR_SUCCESS == hr )
  1003. {
  1004. hr = RegDeleteKey( hKey ,
  1005. chData.LockBuffer() );
  1006. TRC2((TB, "Win32_TerminalServiceSetting@ExecMethod: DeleteLicenseServer ret 0x%x" , hr));
  1007. if( hr == ERROR_SUCCESS )
  1008. {
  1009. pOutParams->SetDWORD(L"ReturnValue", WBEM_S_NO_ERROR);
  1010. }
  1011. chData.UnlockBuffer();
  1012. chData.Empty();
  1013. }
  1014. else
  1015. {
  1016. hr = S_OK;
  1017. }
  1018. }
  1019. }
  1020. }while (0);
  1021. if( NULL != hKey )
  1022. {
  1023. RegCloseKey(hKey);
  1024. }
  1025. if(NULL != hOutKey)
  1026. {
  1027. RegCloseKey(hOutKey);
  1028. }
  1029. if( NULL != hServer )
  1030. {
  1031. ServerLicensingClose(hServer);
  1032. }
  1033. if( pSettings != NULL )
  1034. {
  1035. pSettings->Release();
  1036. }
  1037. return hr;
  1038. }
  1039. //=---------
  1040. HRESULT CWin32_TerminalServiceSetting::LoadPropertyValues( CInstance *pInstance, DWORD dwRequiredProperties)
  1041. {
  1042. int Licensing;
  1043. DWORD dwMode = 0;
  1044. DWORD dwData = 0;
  1045. ULONG ulMode = 0;
  1046. CRegistry oRegObject;
  1047. DWORD dwSize = 0;
  1048. BOOL bData = 0;
  1049. BOOL bActivate = 0;
  1050. DWORD dwStatus = 0;
  1051. DWORD dwType = 0;
  1052. HANDLE hServer = NULL;
  1053. BYTE bbyte;
  1054. OSVERSIONINFOW OsVersionInfo;
  1055. OsVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
  1056. LPTSTR lpLogon;
  1057. int iData;
  1058. LPLCPOLICYINFO_V1W pPolicyInfo = NULL;
  1059. ULONG ulInfoStructVersion = LCPOLICYINFOTYPE_CURRENT;
  1060. CHString chLogon;
  1061. CHString chData;
  1062. HKEY hParamKey = NULL;
  1063. HRESULT hr = WBEM_E_INVALID_PARAMETER;
  1064. CHString chServerName;
  1065. chServerName.Format(L"%s", (LPCTSTR)GetLocalComputerName());
  1066. CStackClass StackObj;
  1067. if(StackObj.m_pCfgComp == NULL)
  1068. {
  1069. return WBEM_E_ILLEGAL_NULL;
  1070. }
  1071. if( pInstance == NULL )
  1072. {
  1073. ERR((TB, "TermServiceSetting@LoadPropertyValues: invalid interface"));
  1074. return E_FAIL;
  1075. }
  1076. ISettingsComp *pSettings = NULL;
  1077. hr = StackObj.m_pCfgComp->QueryInterface( IID_ISettingsComp , ( PVOID * )&pSettings ) ;
  1078. if( SUCCEEDED (hr) && pSettings != NULL )
  1079. {
  1080. if( dwRequiredProperties & BIT_SERVERNAME )
  1081. {
  1082. pInstance->SetCHString(m_szServerName, chServerName);
  1083. }
  1084. if( dwRequiredProperties & BIT_MODE )
  1085. {
  1086. pSettings->GetTermSrvMode(&dwMode , &dwStatus );
  1087. TRC2((TB, "TermServiceSetting@LoadPropertyValues: GetTermSrvMode returned 0x%x\n" , dwStatus));
  1088. if( ERROR_SUCCESS == dwStatus )
  1089. {
  1090. pInstance->SetDWORD(m_szMode, dwMode);
  1091. }
  1092. }
  1093. if( dwRequiredProperties & BIT_LICENSING )
  1094. {
  1095. hServer = ServerLicensingOpen(NULL);
  1096. if (NULL != hServer)
  1097. {
  1098. if( ServerLicensingGetPolicy( hServer, &ulMode ) )
  1099. {
  1100. TRC2((TB, "TermServiceSetting@LoadPropertyValues: ServerLicensingGetPolicy ret 0x%x\n" , dwStatus));
  1101. pInstance->SetDWORD(m_szLicensingType, (DWORD &)ulMode);
  1102. if( ServerLicensingGetPolicyInformation( hServer, ulMode, &ulInfoStructVersion,
  1103. (LPLCPOLICYINFOGENERIC *) &pPolicyInfo ))
  1104. {
  1105. pInstance->SetCHString(m_szLicensingName, pPolicyInfo->lpPolicyName );
  1106. pInstance->SetCHString(m_szLicensingDescription, pPolicyInfo->lpPolicyDescription );
  1107. ServerLicensingFreePolicyInformation((LPLCPOLICYINFOGENERIC *)&pPolicyInfo);
  1108. }
  1109. }
  1110. ServerLicensingClose(hServer);
  1111. }
  1112. }
  1113. if( dwRequiredProperties & BIT_ACTIVEDESKTOP )
  1114. {
  1115. pSettings->GetActiveDesktopState(&bActivate , &dwStatus );
  1116. TRC2((TB, "TermServiceSetting@LoadPropertyValues: GetActiveDesktopState returned 0x%x\n" , dwStatus));
  1117. if( ERROR_SUCCESS == dwStatus )
  1118. {
  1119. pInstance->SetDWORD(m_szActiveDesktop, (DWORD &)bActivate);
  1120. }
  1121. if( ERROR_FILE_NOT_FOUND == dwStatus )
  1122. {
  1123. pInstance->SetDWORD(m_szActiveDesktop, 1);
  1124. }
  1125. }
  1126. if( dwRequiredProperties & BIT_USERPERM )
  1127. {
  1128. pSettings->GetUserPerm(&bActivate , &dwStatus );
  1129. TRC2((TB, "TermServiceSetting@LoadPropertyValues: GetUserPerm returned 0x%x\n" , dwStatus));
  1130. if( ERROR_SUCCESS == dwStatus )
  1131. {
  1132. pInstance->SetDWORD(m_szUserPerm, bActivate);
  1133. }
  1134. }
  1135. if( dwRequiredProperties & BIT_DELETETEMPDIRS )
  1136. {
  1137. RegGetMachinePolicy(&m_gpPolicy);
  1138. if( m_gpPolicy.fPolicyDeleteTempFoldersOnExit != 0 )
  1139. {
  1140. bActivate = m_gpPolicy.fDeleteTempFoldersOnExit;
  1141. }
  1142. else
  1143. {
  1144. pSettings->GetDelDirsOnExit( &bActivate );
  1145. }
  1146. TRC2((TB, "TermServiceSetting@LoadPropertyValues: GetDelDirsOnExit returned 0x%x\n" , hr));
  1147. pInstance->SetDWORD(m_szDeleteTempFolders, bActivate);
  1148. }
  1149. if( dwRequiredProperties & BIT_PERSESSIONTEMPDIR )
  1150. {
  1151. RegGetMachinePolicy(&m_gpPolicy);
  1152. if( m_gpPolicy.fPolicyTempFoldersPerSession != 0 )
  1153. {
  1154. bActivate = m_gpPolicy.fTempFoldersPerSession;
  1155. }
  1156. else
  1157. {
  1158. pSettings->GetUseTempDirPerSession(&bActivate );
  1159. }
  1160. TRC2((TB, "TermServiceSetting@LoadPropertyValues: GetUseTempDirsPerSession returned 0x%x\n" , hr));
  1161. pInstance->SetDWORD(m_szUseTempFolders, bActivate);
  1162. }
  1163. if( dwRequiredProperties & BIT_LOGONS )
  1164. {
  1165. hr = oRegObject.OpenKey(HKEY_LOCAL_MACHINE, TS_LOGON_PATH);
  1166. if( SUCCEEDED( hr ) )
  1167. {
  1168. if( GetVersionEx( &OsVersionInfo) )
  1169. {
  1170. if( OsVersionInfo.dwMajorVersion == 5 && OsVersionInfo.dwMinorVersion == 0 )
  1171. {
  1172. TRC2((TB, "TermServiceSetting@LoadPropertyValues: GetVersionInfo is Win2000"));
  1173. dwData = 0;
  1174. hr = oRegObject.ReadRegDWord(L"WinStationsDisabled", &dwData);
  1175. TRC2((TB, "TermServiceSetting@LoadPropertyValues: GetWinStationsDisabled returned 0x%x\n" , hr));
  1176. if( SUCCEEDED (hr) )
  1177. {
  1178. if( dwData == 0 )
  1179. {
  1180. pInstance->SetCharSplat(m_szLogons, L"0");
  1181. }
  1182. else
  1183. {
  1184. pInstance->SetCharSplat(m_szLogons, L"1");
  1185. }
  1186. }
  1187. }
  1188. else
  1189. {
  1190. TRC2((TB, "TermServiceSetting@LoadPropertyValues: GetVersionInfo is Whistler"));
  1191. hr = oRegObject.ReadRegString(L"WinStationsDisabled", &lpLogon, &dwData);
  1192. TRC2((TB, "TermServiceSetting@LoadPropertyValues: GetWinStationsDisabled returned 0x%x\n" , hr));
  1193. if( SUCCEEDED( hr ) )
  1194. {
  1195. pInstance->SetCharSplat(m_szLogons, lpLogon);
  1196. }
  1197. }
  1198. }
  1199. }
  1200. }
  1201. if( dwRequiredProperties & BIT_HELP )
  1202. {
  1203. hr = pSettings->GetSalemHelpMode(&iData, &dwStatus );
  1204. TRC2((TB, "TermServiceSetting@LoadPropertyValues: GetHelp returned 0x%x" , dwStatus));
  1205. if( S_OK == dwStatus )
  1206. {
  1207. pInstance->SetDWORD(m_szHelp, iData);
  1208. }
  1209. else
  1210. {
  1211. pInstance->SetDWORD(m_szHelp, 0);
  1212. }
  1213. }
  1214. if( dwRequiredProperties & BIT_ALLOWTSCONNECTIONS )
  1215. {
  1216. RegGetMachinePolicy(&m_gpPolicy);
  1217. if( m_gpPolicy.fPolicyDenyTSConnections != 0 )
  1218. {
  1219. iData = m_gpPolicy.fDenyTSConnections;
  1220. }
  1221. else
  1222. {
  1223. hr = pSettings->GetDenyTSConnections(&iData, &dwStatus );
  1224. TRC2((TB, "TermServiceSetting@LoadPropertyValues: GetAllowTSConnections returned 0x%x" , dwStatus));
  1225. }
  1226. // The bit is negated because it calls the function GetDenyTSConnections which is negative logic.
  1227. if( iData == 0)
  1228. {
  1229. iData = 1;
  1230. }
  1231. else if( iData == 1)
  1232. {
  1233. iData = 0;
  1234. }
  1235. pInstance->SetDWORD(m_szAllowTSConnections, iData);
  1236. TRC2((TB,"TerminalServiceSetting@LoadPropertyValues: AllowTSConnections" ));
  1237. }
  1238. if( dwRequiredProperties & BIT_TIMEZONEREDIRECTION )
  1239. {
  1240. RegGetMachinePolicy(&m_gpPolicy);
  1241. //todo: change policy name
  1242. if( m_gpPolicy.fPolicyEnableTimeZoneRedirection != 0 )
  1243. {
  1244. iData = m_gpPolicy.fEnableTimeZoneRedirection;
  1245. }
  1246. else
  1247. {
  1248. hr = pSettings->GetTimeZoneRedirection(&iData, &dwStatus );
  1249. if(dwStatus != ERROR_SUCCESS)
  1250. {
  1251. iData = 0;
  1252. }
  1253. TRC2((TB, "TerminalServiceSetting@LoadPropertyValues: GetTimeZoneRedirection returned 0x%x" , dwStatus));
  1254. }
  1255. pInstance->SetDWORD(m_szTimeZoneRedirection, iData);
  1256. TRC2((TB,"TerminalServiceSetting@LoadPropertyValues: TimeZoneRedirection" ));
  1257. }
  1258. if( dwRequiredProperties & BIT_SINGLESESSION)
  1259. {
  1260. RegGetMachinePolicy(&m_gpPolicy);
  1261. if( m_gpPolicy.fPolicySingleSessionPerUser != 0 )
  1262. {
  1263. bData = m_gpPolicy.fSingleSessionPerUser;
  1264. }
  1265. else
  1266. {
  1267. hr = pSettings->GetSingleSessionState( &bData, &dwStatus);
  1268. }
  1269. dwData = bData;
  1270. pInstance->SetDWORD(m_szSingleSession, dwData);
  1271. TRC2((TB,"TermServiceSetting@LoadPropertyValues: SingleSession" ));
  1272. }
  1273. if( dwRequiredProperties & BIT_DISABLEFORCIBLELOGOFF)
  1274. {
  1275. RegGetMachinePolicy(&m_gpPolicy);
  1276. if( m_gpPolicy.fPolicyDisableForcibleLogoff != 0 )
  1277. {
  1278. bData = m_gpPolicy.fDisableForcibleLogoff;
  1279. }
  1280. else
  1281. {
  1282. hr = pSettings->GetDisableForcibleLogoff( &bData, &dwStatus);
  1283. }
  1284. dwData = bData;
  1285. pInstance->SetDWORD(m_szDisableForcibleLogoff, dwData);
  1286. TRC2((TB,"TermServiceSetting@LoadPropertyValues: DisableForcibleLogoff" ));
  1287. }
  1288. if( dwRequiredProperties & BIT_PROFILEPATH)
  1289. {
  1290. BSTR bstrData = NULL;
  1291. chData.Empty();
  1292. RegGetMachinePolicy(&m_gpPolicy);
  1293. if( m_gpPolicy.fPolicyWFProfilePath != 0 )
  1294. {
  1295. chData.Format(L"%s", m_gpPolicy.WFProfilePath);
  1296. }
  1297. else
  1298. {
  1299. hr = pSettings->GetProfilePath( &bstrData, &dwStatus);
  1300. if( bstrData != NULL)
  1301. {
  1302. chData.Format(L"%s", (LPCWSTR)(bstrData));
  1303. SysFreeString(bstrData);
  1304. }
  1305. }
  1306. pInstance->SetCHString(m_szProfilePath, chData);
  1307. TRC2((TB,"TermServiceSetting@LoadPropertyValues: ProfilePath" ));
  1308. }
  1309. if( dwRequiredProperties & BIT_HOMEDIRECTORY)
  1310. {
  1311. BSTR bstrData = NULL;
  1312. chData.Empty();
  1313. RegGetMachinePolicy(&m_gpPolicy);
  1314. if( m_gpPolicy.fPolicyWFHomeDir != 0 )
  1315. {
  1316. chData.Format(L"%s", m_gpPolicy.WFHomeDir);
  1317. }
  1318. else
  1319. {
  1320. hr = pSettings->GetHomeDir( &bstrData, &dwStatus);
  1321. if(bstrData != NULL)
  1322. {
  1323. chData.Format(L"%s", (LPCWSTR)(bstrData));
  1324. SysFreeString(bstrData);
  1325. }
  1326. }
  1327. pInstance->SetCHString(m_szHomeDirectory, chData);
  1328. TRC2((TB,"TermServiceSetting@LoadPropertyValues: HomeDirectory" ));
  1329. }
  1330. if( dwRequiredProperties & BIT_DIRECTCONNECTLICENSESERVERS)
  1331. {
  1332. DWORD dwValueType;
  1333. DWORD cbValue = 0, dwDisp;
  1334. LONG lReturn;
  1335. DWORD cbServer;
  1336. DWORD cServers;
  1337. DWORD cchServerMax;
  1338. LPWSTR szServer;
  1339. DWORD i, j;
  1340. CHString chServers;
  1341. chServers.Empty();
  1342. do
  1343. {
  1344. lReturn = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  1345. TERMINAL_SERVICE_PARAM_DISCOVERY_SERVERS,
  1346. 0,
  1347. KEY_READ,
  1348. &hParamKey );
  1349. if (ERROR_SUCCESS != lReturn)
  1350. {
  1351. break;
  1352. }
  1353. lReturn = RegQueryInfoKey(hParamKey,
  1354. NULL,
  1355. NULL,
  1356. NULL,
  1357. &cServers,
  1358. &cchServerMax,
  1359. NULL,
  1360. NULL,
  1361. NULL,
  1362. NULL,
  1363. NULL,
  1364. NULL);
  1365. if (ERROR_SUCCESS != lReturn)
  1366. {
  1367. RegCloseKey( hParamKey );
  1368. break;
  1369. }
  1370. if (0 == cServers)
  1371. {
  1372. RegCloseKey( hParamKey );
  1373. hParamKey = NULL;
  1374. break;
  1375. }
  1376. // Add one for null terminator
  1377. cchServerMax++;
  1378. szServer = (LPWSTR) LocalAlloc(LPTR,cchServerMax * sizeof(WCHAR));
  1379. if(NULL == szServer)
  1380. {
  1381. LocalFree(szServer);
  1382. RegCloseKey( hParamKey );
  1383. hParamKey = NULL;
  1384. break;
  1385. }
  1386. for (i = 0; i < cServers; i++)
  1387. {
  1388. if(!chServers.IsEmpty())
  1389. {
  1390. chServers+=L"; ";
  1391. }
  1392. cbServer = cchServerMax * sizeof(WCHAR);
  1393. lReturn = RegEnumKeyEx(hParamKey,
  1394. i,
  1395. szServer,
  1396. &cbServer,
  1397. NULL,
  1398. NULL,
  1399. NULL,
  1400. NULL);
  1401. if (ERROR_SUCCESS != lReturn)
  1402. {
  1403. LocalFree(szServer);
  1404. RegCloseKey( hParamKey );
  1405. hParamKey = NULL;
  1406. break;
  1407. }
  1408. chServers+= szServer;
  1409. }
  1410. if(szServer)
  1411. {
  1412. LocalFree(szServer);
  1413. }
  1414. pInstance->SetCHString(m_szDirectConnectLicenseServers, chServers);
  1415. }while(0);
  1416. }
  1417. }
  1418. if(hParamKey)
  1419. {
  1420. RegCloseKey(hParamKey);
  1421. }
  1422. if( pSettings != NULL )
  1423. {
  1424. pSettings->Release();
  1425. }
  1426. return S_OK;
  1427. }
  1428. //=---------
  1429. /*************************************************************************************
  1430. *
  1431. * DESCRIPTION : CWin32_TerminalService class is subclassed from the Win32_Service
  1432. * class in CIM schema. It provides live information such as Total
  1433. * sessions, Disconnected sessions, Resource constraint and
  1434. * Raw session capacity.
  1435. *
  1436. ***************************************************************************************/
  1437. CWin32_TerminalService::CWin32_TerminalService (LPCWSTR lpwszName, LPCWSTR lpwszNameSpace ) : Provider( lpwszName, lpwszNameSpace )
  1438. {
  1439. if (g_hInstance != NULL)
  1440. {
  1441. TRC2((TB, "CWin32_TerminalService_ctor"));
  1442. _tcscpy(m_szName, _T("Name"));
  1443. _tcscpy(m_szCaption, _T("Caption"));
  1444. _tcscpy(m_szTotalSessions, _T("TotalSessions"));
  1445. _tcscpy(m_szDisconnectedSessions, _T("DisconnectedSessions"));
  1446. /*
  1447. _tcscpy(m_szEstimatedSessionCapacity, _T("EstimatedSessionCapacity"));
  1448. _tcscpy(m_szResourceConstraint, _T("ResourceConstraint"));
  1449. _tcscpy(m_szRawSessionCapacity, _T("RawSessionCapacity"));
  1450. */
  1451. }
  1452. }
  1453. //=-----------------
  1454. CWin32_TerminalService::~CWin32_TerminalService ()
  1455. {
  1456. }
  1457. //=--------------------
  1458. /************************************************************************************
  1459. *
  1460. * DESCRIPTION : Find a single instance based on the key property, "Name".
  1461. *
  1462. * INPUTS : A pointer to a CInstance object containing the key property, "Name".
  1463. * A long that contains the flags described in
  1464. * IWbemServices::GetObjectAsync.
  1465. *
  1466. * RETURNS : WBEM_S_NO_ERROR if the instance can be found
  1467. * WBEM_E_NOT_FOUND if the instance described by the key properties
  1468. * could not be found
  1469. * WBEM_E_FAILED if the instance could be found but another error
  1470. * occurred.
  1471. *
  1472. **************************************************************************************/
  1473. HRESULT CWin32_TerminalService::GetObject ( CInstance* pInstance, long lFlags, CFrameworkQuery &Query )
  1474. {
  1475. HRESULT hr = WBEM_E_NOT_FOUND;
  1476. CHString chServerName;
  1477. TCHAR tchServer[MAX_PATH] = {0};
  1478. HANDLE hServerName = SERVERNAME_CURRENT;
  1479. ULONG CurrentLogonId = (ULONG) -1;
  1480. WINSTATIONLOADINDICATORDATA LIData;
  1481. ULONG Length = 0;
  1482. DWORD dwRequiredProperties = 0;
  1483. CHString chName;
  1484. pInstance->GetCHString(m_szName, chName);
  1485. pInstance->SetCHString(m_szCaption, chName);
  1486. if( chName.CompareNoCase(L"TermService") == 0 )
  1487. {
  1488. chServerName.Format(L"%s", (LPCTSTR)GetLocalComputerName());
  1489. wcscpy (tchServer, chServerName);
  1490. bool bRet = 0;
  1491. if (Query.IsPropertyRequired(m_szTotalSessions))
  1492. dwRequiredProperties |= BIT_TOTALSESSIONS;
  1493. if (Query.IsPropertyRequired(m_szDisconnectedSessions))
  1494. dwRequiredProperties |= BIT_DISCONNECTEDSESSIONS;
  1495. /*
  1496. if (Query.IsPropertyRequired(m_szEstimatedSessionCapacity))
  1497. dwRequiredProperties |= BIT_ESTIMATEDSESSIONCAPACITY;
  1498. if (Query.IsPropertyRequired(m_szResourceConstraint))
  1499. dwRequiredProperties |= BIT_RESOURCECONSTRAINT;
  1500. if (Query.IsPropertyRequired(m_szRawSessionCapacity))
  1501. dwRequiredProperties |= BIT_RAWSESSIONCAPACITY;
  1502. */
  1503. hServerName = WinStationOpenServer (tchServer);
  1504. CurrentLogonId = GetCurrentLogonId();
  1505. if( hServerName != NULL )
  1506. {
  1507. bRet = WinStationQueryInformation(hServerName, CurrentLogonId,
  1508. WinStationLoadIndicator,
  1509. &LIData,
  1510. sizeof(LIData), &Length) ;
  1511. if( bRet )
  1512. {
  1513. hr = LoadPropertyValues(pInstance, dwRequiredProperties, LIData);
  1514. }
  1515. }
  1516. else
  1517. {
  1518. ERR((TB, "Win32_TerminalService@GetObject: WinStationQueryInformation GetLastError returned: 0x%x\n" ,GetLastError()));
  1519. }
  1520. }
  1521. return hr;
  1522. }
  1523. //=------------------
  1524. /*****************************************************************************
  1525. *
  1526. * FUNCTION : CWin32_TerminalService::EnumerateInstances
  1527. *
  1528. * DESCRIPTION : Returns all the instances of this class.
  1529. *
  1530. * INPUTS : A pointer to the MethodContext for communication with WinMgmt.
  1531. * A long that contains the flags described in
  1532. * IWbemServices::CreateInstanceEnumAsync. Note that the following
  1533. * flags are handled by (and filtered out by) WinMgmt:
  1534. * WBEM_FLAG_DEEP, WBEM_FLAG_SHALLOW, WBEM_FLAG_RETURN_IMMEDIATELY,
  1535. * WBEM_FLAG_FORWARD_ONLY, WBEM_FLAG_BIDIRECTIONAL
  1536. *
  1537. * RETURNS : WBEM_S_NO_ERROR if successful
  1538. *
  1539. * COMMENTS : All instances on the machine are returned here and
  1540. * all properties that this class knows how to populate must
  1541. * be filled in. If there are no instances, return
  1542. * WBEM_S_NO_ERROR.
  1543. *
  1544. *****************************************************************************/
  1545. HRESULT CWin32_TerminalService::EnumerateInstances (MethodContext* pMethodContext, long lFlags )
  1546. {
  1547. return WBEM_S_NO_ERROR;
  1548. // Commented as implementation is protocol dependent
  1549. /*
  1550. CHString chServerName;
  1551. TCHAR tchServer[MAX_PATH] = {0};
  1552. HANDLE hServer = SERVERNAME_CURRENT;
  1553. WINSTATIONLOADINDICATORDATA LIData;
  1554. ULONG CurrentLogonId = (ULONG) -1;
  1555. ULONG Length;
  1556. chServerName.Format(L"%s", (LPCTSTR)GetLocalComputerName());
  1557. wcscpy (tchServer, chServerName);
  1558. hServer = WinStationOpenServer (tchServer);
  1559. bool bRet = 0;
  1560. CurrentLogonId = GetCurrentLogonId();
  1561. if (hServer != NULL)
  1562. {
  1563. bRet = WinStationQueryInformation(hServer, CurrentLogonId,
  1564. WinStationLoadIndicator,
  1565. &LIData,
  1566. sizeof(LIData), &Length);
  1567. TRC2((TB, "Win32_TerminalService@EnumerateInstances: WinStationQueryInformation bRet: 0x%x\n" , bRet));
  1568. if (bRet)
  1569. {
  1570. CInstance* pInstance = CreateNewInstance(pMethodContext);
  1571. if( pInstance != NULL )
  1572. {
  1573. pInstance->SetCHString(m_szServerName, chServerName);
  1574. hr = LoadPropertyValues(pInstance, BIT_ALL_PROPERTIES, LIData);
  1575. if ( SUCCEEDED( hr ))
  1576. {
  1577. hr = pInstance->Commit();
  1578. }
  1579. pInstance->Release();
  1580. }
  1581. }
  1582. }
  1583. else
  1584. {
  1585. TRC2((TB, "Win32_TerminalService@EnumerateInstances: WinStationQueryInformation GetLastError returned: 0x%x\n" , hr));
  1586. }
  1587. return hr;
  1588. */
  1589. }
  1590. //=-------------
  1591. HRESULT CWin32_TerminalService::ExecQuery (MethodContext *pMethodContext, CFrameworkQuery& Query, long lFlags)
  1592. {
  1593. HRESULT hr = WBEM_S_NO_ERROR;
  1594. DWORD dwRequiredProperties = 0;
  1595. CHStringArray asNames;
  1596. DWORD dwMode;
  1597. DWORD dwStatus;
  1598. CHString chServerName;
  1599. TCHAR tchServer[MAX_PATH] = {0};
  1600. bool bRet = 0;
  1601. HANDLE hServerName = SERVERNAME_CURRENT;
  1602. WINSTATIONLOADINDICATORDATA LIData;
  1603. ULONG CurrentLogonId = (ULONG) -1;
  1604. ULONG Length = 0;
  1605. chServerName.Format(L"%s", (LPCTSTR)GetLocalComputerName());
  1606. wcscpy (tchServer, chServerName);
  1607. hServerName = WinStationOpenServer (tchServer);
  1608. CurrentLogonId = GetCurrentLogonId();
  1609. if( hServerName != NULL )
  1610. {
  1611. bRet = WinStationQueryInformation(hServerName, CurrentLogonId,
  1612. WinStationLoadIndicator,
  1613. &LIData,
  1614. sizeof(LIData), &Length);
  1615. if( bRet )
  1616. {
  1617. // Method 2
  1618. Query.GetValuesForProp(m_szName, asNames);
  1619. BOOL bGetAllInstances = asNames.GetSize() == 0;
  1620. // Method 1
  1621. if (Query.IsPropertyRequired(m_szTotalSessions))
  1622. dwRequiredProperties |= BIT_TOTALSESSIONS;
  1623. if (Query.IsPropertyRequired(m_szDisconnectedSessions))
  1624. dwRequiredProperties |= BIT_DISCONNECTEDSESSIONS;
  1625. /*
  1626. if (Query.IsPropertyRequired(m_szEstimatedSessionCapacity))
  1627. dwRequiredProperties |= BIT_ESTIMATEDSESSIONCAPACITY;
  1628. if (Query.IsPropertyRequired(m_szResourceConstraint))
  1629. dwRequiredProperties |= BIT_RESOURCECONSTRAINT;
  1630. if (Query.IsPropertyRequired(m_szRawSessionCapacity))
  1631. dwRequiredProperties |= BIT_RAWSESSIONCAPACITY;
  1632. */
  1633. CInstance* pInstance = CreateNewInstance(pMethodContext);
  1634. if( pInstance != NULL)
  1635. {
  1636. pInstance->SetCHString(m_szName, chServerName);
  1637. pInstance->SetCHString(m_szCaption, chServerName);
  1638. hr = LoadPropertyValues( pInstance, dwRequiredProperties, LIData );
  1639. if( SUCCEEDED( hr ) )
  1640. {
  1641. hr = pInstance->Commit();
  1642. }
  1643. pInstance->Release();
  1644. }
  1645. else
  1646. {
  1647. ERR((TB, "Win32_TerminalService@GetObject@ExecQuery: CreateNewInstance failed"));
  1648. hr = WBEM_E_OUT_OF_MEMORY;
  1649. }
  1650. }
  1651. }
  1652. else
  1653. {
  1654. TRC2((TB, "Win32_TerminalService@ExecQuery: WinStationQueryInformation GetLastError returned: 0x%x\n" , GetLastError()));
  1655. }
  1656. return hr;
  1657. }
  1658. //=---------------------
  1659. HRESULT CWin32_TerminalService::LoadPropertyValues( CInstance *pInstance, DWORD dwRequiredProperties, WINSTATIONLOADINDICATORDATA LIData)
  1660. {
  1661. if( pInstance != NULL )
  1662. {
  1663. if( dwRequiredProperties & BIT_TOTALSESSIONS )
  1664. {
  1665. pInstance->SetDWORD(m_szTotalSessions, LIData.TotalSessions);
  1666. }
  1667. if( dwRequiredProperties & BIT_DISCONNECTEDSESSIONS )
  1668. {
  1669. pInstance->SetDWORD(m_szDisconnectedSessions, LIData.DisconnectedSessions);
  1670. }
  1671. /*
  1672. if( dwRequiredProperties & BIT_ESTIMATEDSESSIONCAPACITY )
  1673. {
  1674. pInstance->SetDWORD(m_szEstimatedSessionCapacity, LIData.RemainingSessionCapacity);
  1675. }
  1676. if( dwRequiredProperties & BIT_RESOURCECONSTRAINT )
  1677. {
  1678. switch( LIData.LoadFactor )
  1679. {
  1680. case 0:
  1681. pInstance->SetCharSplat(m_szResourceConstraint, L"Error");
  1682. break;
  1683. case 1:
  1684. pInstance->SetCharSplat(m_szResourceConstraint, L"PagedPool");
  1685. break;
  1686. case 2:
  1687. pInstance->SetCharSplat(m_szResourceConstraint, L"NonPagedPool");
  1688. break;
  1689. case 3:
  1690. pInstance->SetCharSplat(m_szResourceConstraint, L"Available Memory");
  1691. break;
  1692. case 4:
  1693. pInstance->SetCharSplat(m_szResourceConstraint, L"System PTEs");
  1694. break;
  1695. case 5:
  1696. pInstance->SetCharSplat(m_szResourceConstraint, L"CPU");
  1697. break;
  1698. default:
  1699. pInstance->SetCharSplat(m_szResourceConstraint, L"Error");
  1700. break;
  1701. }
  1702. }
  1703. if( dwRequiredProperties & BIT_RAWSESSIONCAPACITY )
  1704. {
  1705. pInstance->SetDWORD(m_szRawSessionCapacity, LIData.RawSessionCapacity);
  1706. }
  1707. */
  1708. }
  1709. return S_OK;
  1710. }
  1711. //=--------------
  1712. CWin32_TSSessionDirectory::CWin32_TSSessionDirectory (LPCWSTR lpwszName, LPCWSTR lpwszNameSpace ) : Provider( lpwszName, lpwszNameSpace )
  1713. {
  1714. if ( g_hInstance != NULL)
  1715. {
  1716. TRC2((TB, "CWin32_TSSessionDirectory_ctor"));
  1717. _tcscpy(m_szMode, _T("TerminalServerMode"));
  1718. _tcscpy(m_szSessionDirectoryActive, _T("SessionDirectoryActive"));
  1719. _tcscpy(m_szSessionDirectoryLocation, _T("SessionDirectoryLocation"));
  1720. _tcscpy(m_szSessionDirectoryClusterName, _T("SessionDirectoryClusterName"));
  1721. // _tcscpy(m_szSessionDirectoryAdditionalParams, _T("SessionDirectoryAdditionalParams"));
  1722. _tcscpy(m_szSetSessionDirectoryProperty, _T("SetSessionDirectoryProperty"));
  1723. _tcscpy(m_szSetSessionDirectoryActive, _T("SetSessionDirectoryActive"));
  1724. _tcscpy(m_szPropertyName, _T("PropertyName"));
  1725. _tcscpy(m_szValue, _T("Value"));
  1726. _tcscpy(m_szSessionDirectoryExposeServerIP, _T("SessionDirectoryExposeServerIP"));
  1727. _tcscpy(m_szSetSessionDirectoryExposeServerIP, _T("SetSessionDirectoryExposeServerIP"));
  1728. _tcscpy(m_szSessionDirectoryIPAddress, _T("SessionDirectoryIPAddress"));
  1729. }
  1730. }
  1731. //=-------------
  1732. CWin32_TSSessionDirectory::~CWin32_TSSessionDirectory ()
  1733. {
  1734. }
  1735. HRESULT
  1736. GetNLBIP(LPWSTR * ppwszRetIP)
  1737. {
  1738. HRESULT hr = S_OK;
  1739. IWbemLocator * pWbemLocator = NULL;
  1740. IWbemServices * pWbemServices = NULL;
  1741. IWbemClassObject * pWbemObj = NULL;
  1742. IEnumWbemClassObject * pWbemEnum = NULL;
  1743. BSTR bstrServer = NULL;
  1744. BSTR bstrNode = NULL;
  1745. BSTR bstrNameProperty = NULL;
  1746. ULONG uReturned;
  1747. VARIANT vtNLBNodeName;
  1748. size_t dwIPLength;
  1749. // make sure an empty buffer is passed in
  1750. if (*ppwszRetIP != NULL)
  1751. {
  1752. hr = E_INVALIDARG;
  1753. goto Cleanup;
  1754. }
  1755. // create an instance of the WMI Locator, need this to query WMI
  1756. hr = CoCreateInstance(CLSID_WbemLocator,
  1757. 0,
  1758. CLSCTX_INPROC_SERVER,
  1759. IID_IWbemLocator,
  1760. reinterpret_cast<void**>(&pWbemLocator));
  1761. if (FAILED(hr))
  1762. {
  1763. goto Cleanup;
  1764. }
  1765. // create a connection to WMI Namespace "root\\MicrosoftNLB";
  1766. bstrServer = SysAllocString(L"root\\MicrosoftNLB");
  1767. if (bstrServer == NULL)
  1768. {
  1769. hr = E_OUTOFMEMORY;
  1770. goto Cleanup;
  1771. }
  1772. hr = pWbemLocator->ConnectServer(bstrServer,
  1773. NULL,
  1774. NULL,
  1775. 0,
  1776. NULL,
  1777. 0,
  1778. 0,
  1779. &pWbemServices);
  1780. if (FAILED(hr))
  1781. {
  1782. goto Cleanup;
  1783. }
  1784. hr = CoImpersonateClient();
  1785. if (FAILED(hr))
  1786. {
  1787. goto Cleanup;
  1788. }
  1789. // Set the proxy so that impersonation of the client occurs.
  1790. hr = CoSetProxyBlanket(pWbemServices,
  1791. RPC_C_AUTHN_WINNT,
  1792. RPC_C_AUTHZ_NONE,
  1793. NULL,
  1794. RPC_C_AUTHN_LEVEL_CALL,
  1795. RPC_C_IMP_LEVEL_IMPERSONATE,
  1796. NULL,
  1797. EOAC_DYNAMIC_CLOAKING);
  1798. if (FAILED(hr))
  1799. {
  1800. goto Cleanup;
  1801. }
  1802. // get instance of MicrosoftNLB_NodeSetting, this is where we can get the
  1803. // IP Address for the Cluster IP through the "Name" property
  1804. bstrNode = SysAllocString(L"MicrosoftNLB_NodeSetting");
  1805. if (bstrNode == NULL)
  1806. {
  1807. hr = E_OUTOFMEMORY;
  1808. goto Cleanup;
  1809. }
  1810. hr = pWbemServices->CreateInstanceEnum(bstrNode,
  1811. WBEM_FLAG_RETURN_IMMEDIATELY,
  1812. NULL,
  1813. &pWbemEnum);
  1814. if (FAILED(hr))
  1815. {
  1816. goto Cleanup;
  1817. }
  1818. // we only need to look at one instance to get the NLB IP Address
  1819. hr = pWbemEnum->Next(WBEM_INFINITE,
  1820. 1,
  1821. &pWbemObj,
  1822. &uReturned);
  1823. if (FAILED(hr))
  1824. {
  1825. // if NLB provider doesn't exist provider will fail to load
  1826. // this is ok so we'll return S_OK in this case
  1827. if (hr == WBEM_E_PROVIDER_LOAD_FAILURE || hr == WBEM_E_ACCESS_DENIED)
  1828. {
  1829. hr = S_OK;
  1830. *ppwszRetIP = NULL;
  1831. }
  1832. goto Cleanup;
  1833. }
  1834. // query the "Name" property which holds the IP address we want
  1835. bstrNameProperty = SysAllocString(L"Name");
  1836. if (bstrNameProperty == NULL)
  1837. {
  1838. hr = E_OUTOFMEMORY;
  1839. goto Cleanup;
  1840. }
  1841. hr = pWbemObj->Get(bstrNameProperty,
  1842. 0,
  1843. &vtNLBNodeName,
  1844. NULL,
  1845. NULL);
  1846. if (FAILED(hr))
  1847. {
  1848. goto Cleanup;
  1849. }
  1850. // We should get a string back
  1851. if (vtNLBNodeName.vt != VT_BSTR)
  1852. {
  1853. hr = E_UNEXPECTED;
  1854. goto Cleanup;
  1855. }
  1856. // allocate memory for the return string, *** CALLER MUST FREE THIS ***
  1857. dwIPLength = wcslen(vtNLBNodeName.bstrVal) + 1;
  1858. *ppwszRetIP = (LPWSTR)GlobalAlloc(GPTR, dwIPLength * sizeof(WCHAR));
  1859. if (*ppwszRetIP == NULL)
  1860. {
  1861. hr = E_OUTOFMEMORY;
  1862. goto Cleanup;
  1863. }
  1864. // Copy the string into our return buffer
  1865. wcscpy(*ppwszRetIP, vtNLBNodeName.bstrVal);
  1866. (*ppwszRetIP)[dwIPLength - 1] = L'\0';
  1867. Cleanup:
  1868. if (pWbemLocator)
  1869. pWbemLocator->Release();
  1870. if (pWbemServices)
  1871. pWbemServices->Release();
  1872. if (pWbemEnum)
  1873. pWbemEnum->Release();
  1874. if (pWbemObj)
  1875. pWbemObj->Release();
  1876. if (bstrServer)
  1877. SysFreeString(bstrServer);
  1878. if (bstrNode)
  1879. SysFreeString(bstrNode);
  1880. if (bstrNameProperty)
  1881. SysFreeString(bstrNameProperty);
  1882. VariantClear(&vtNLBNodeName);
  1883. return hr;
  1884. }
  1885. //=------------
  1886. HRESULT CWin32_TSSessionDirectory::DeleteInstance ( const CInstance &Instance, long lFlags )
  1887. {
  1888. return WBEM_E_PROVIDER_NOT_CAPABLE;
  1889. }
  1890. //=-------------------
  1891. /*****************************************************************************
  1892. *
  1893. * FUNCTION : CWin32_TSSessionDirectory::EnumerateInstances
  1894. *
  1895. * DESCRIPTION : Returns all the instances of this class.
  1896. *
  1897. * INPUTS : A pointer to the MethodContext for communication with WinMgmt.
  1898. * A long that contains the flags described in
  1899. * IWbemServices::CreateInstanceEnumAsync. Note that the following
  1900. * flags are handled by (and filtered out by) WinMgmt:
  1901. * WBEM_FLAG_DEEP, WBEM_FLAG_SHALLOW, WBEM_FLAG_RETURN_IMMEDIATELY,
  1902. * WBEM_FLAG_FORWARD_ONLY, WBEM_FLAG_BIDIRECTIONAL
  1903. *
  1904. * RETURNS : WBEM_S_NO_ERROR if successful
  1905. *
  1906. * COMMENTS : All instances on the machine are returned here and
  1907. * all properties that this class knows how to populate must
  1908. * be filled in. If there are no instances, return
  1909. * WBEM_S_NO_ERROR.
  1910. *****************************************************************************/
  1911. HRESULT CWin32_TSSessionDirectory::EnumerateInstances (MethodContext* pMethodContext, long lFlags )
  1912. {
  1913. HRESULT hr = WBEM_E_INVALID_CLASS;
  1914. OSVERSIONINFOEX OsVersionInfo;
  1915. OsVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  1916. ISettingsComp* pSettings = NULL;
  1917. DWORD dwStatus = 0;
  1918. DWORD dwMode = 0;
  1919. CStackClass StackObj;
  1920. if(StackObj.m_pCfgComp == NULL)
  1921. {
  1922. return WBEM_E_ILLEGAL_NULL;
  1923. }
  1924. if( GetVersionEx((OSVERSIONINFO*)&OsVersionInfo) )
  1925. {
  1926. if( ( OsVersionInfo.dwMajorVersion < 5 ) || ( OsVersionInfo.dwMajorVersion == 5 && OsVersionInfo.dwMinorVersion < 1 ))
  1927. {
  1928. return WBEM_E_INVALID_CLASS;
  1929. }
  1930. if(!(OsVersionInfo.wSuiteMask & VER_SUITE_ENTERPRISE) && !( OsVersionInfo.wSuiteMask & VER_SUITE_DATACENTER))
  1931. {
  1932. return WBEM_E_INVALID_CLASS;
  1933. }
  1934. }
  1935. hr = StackObj.m_pCfgComp->QueryInterface( IID_ISettingsComp , ( PVOID * )&pSettings ) ;
  1936. if( SUCCEEDED( hr ) && pSettings != NULL )
  1937. {
  1938. pSettings->GetTermSrvMode(&dwMode , &dwStatus );
  1939. TRC2((TB, "Win32_TSSessionDirectory@EnumInst: GetTermSrvMode: dwMode ret 0x%x\n" , dwMode));
  1940. if( ERROR_SUCCESS == dwStatus && dwMode == 1)
  1941. {
  1942. CInstance* pInstance = CreateNewInstance(pMethodContext);
  1943. if( pInstance != NULL )
  1944. {
  1945. TRC2((TB, "Win32_TSSessionDirectory@EnumerateInstances: CreateNewInstance succeeded"));
  1946. hr = LoadPropertyValues(pInstance, BIT_ALL_PROPERTIES);
  1947. if( SUCCEEDED( hr ))
  1948. {
  1949. hr = pInstance->Commit();
  1950. }
  1951. pInstance->Release( );
  1952. }
  1953. }
  1954. }
  1955. if( pSettings != NULL)
  1956. {
  1957. pSettings->Release();
  1958. }
  1959. return hr ;
  1960. }
  1961. //=-------------
  1962. HRESULT CWin32_TSSessionDirectory::GetObject ( CInstance* pInstance, long lFlags, CFrameworkQuery &Query )
  1963. {
  1964. OSVERSIONINFOEX OsVersionInfo ;
  1965. OsVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  1966. HRESULT hr = WBEM_E_INVALID_CLASS;
  1967. ISettingsComp* pSettings = NULL;
  1968. DWORD dwStatus = 0;
  1969. DWORD dwMode = 0;
  1970. ICfgComp *pCfgComp = NULL;
  1971. if( GetVersionEx((OSVERSIONINFO*)&OsVersionInfo) )
  1972. {
  1973. if( ( OsVersionInfo.dwMajorVersion < 5 ) || ( OsVersionInfo.dwMajorVersion == 5 && OsVersionInfo.dwMinorVersion < 1 ) )
  1974. {
  1975. return WBEM_E_INVALID_CLASS;
  1976. }
  1977. if(!(OsVersionInfo.wSuiteMask & VER_SUITE_ENTERPRISE) && !( OsVersionInfo.wSuiteMask & VER_SUITE_DATACENTER))
  1978. {
  1979. return WBEM_E_INVALID_CLASS;
  1980. }
  1981. }
  1982. CStackClass StackObj;
  1983. if(StackObj.m_pCfgComp == NULL)
  1984. {
  1985. return WBEM_E_ILLEGAL_NULL;
  1986. }
  1987. hr = StackObj.m_pCfgComp->QueryInterface( IID_ISettingsComp , ( PVOID * )&pSettings ) ;
  1988. if( SUCCEEDED( hr ) && pSettings != NULL )
  1989. {
  1990. pSettings->GetTermSrvMode(&dwMode , &dwStatus );
  1991. if( ERROR_SUCCESS == dwStatus && dwMode == 1)
  1992. {
  1993. ULONGLONG dwRequiredProperties = 0;
  1994. if (Query.IsPropertyRequired(m_szMode))
  1995. dwRequiredProperties |= BIT_MODE;
  1996. if (Query.IsPropertyRequired(m_szSessionDirectoryActive))
  1997. dwRequiredProperties |= BIT_SESSIONDIRECTORYACTIVE;
  1998. if (Query.IsPropertyRequired(m_szSessionDirectoryLocation))
  1999. dwRequiredProperties |= BIT_SESSIONDIRECTORY;
  2000. if (Query.IsPropertyRequired(m_szSessionDirectoryClusterName))
  2001. dwRequiredProperties |= BIT_CLUSTERNAME;
  2002. if (Query.IsPropertyRequired(m_szSessionDirectoryExposeServerIP))
  2003. dwRequiredProperties |= BIT_SESSIONDIRECTORYEXPOSESERVERIP;
  2004. if (Query.IsPropertyRequired(m_szSessionDirectoryIPAddress))
  2005. dwRequiredProperties |= BIT_SESSIONDIRECTORYIPADDRESS;
  2006. /*
  2007. if (Query.IsPropertyRequired(m_szSessionDirectoryAdditionalParams))
  2008. dwRequiredProperties |= BIT_ADDITIONALPARAMS;
  2009. */
  2010. if( pInstance != NULL )
  2011. {
  2012. hr = LoadPropertyValues(pInstance, dwRequiredProperties);
  2013. TRC2((TB, "Win32_TSSessionDirectory@GetObject: LoadPropertyValues ret 0x%x\n" , hr));
  2014. }
  2015. }
  2016. }
  2017. if( pSettings != NULL)
  2018. {
  2019. pSettings->Release();
  2020. }
  2021. return hr;
  2022. }
  2023. //=-----------------
  2024. HRESULT CWin32_TSSessionDirectory::ExecQuery (MethodContext *pMethodContext, CFrameworkQuery& Query, long lFlags)
  2025. {
  2026. DWORD dwRequiredProperties = 0;
  2027. CHStringArray asNames;
  2028. CHString chSessionDirectory;
  2029. HRESULT hr = WBEM_E_INVALID_CLASS;
  2030. ISettingsComp* pSettings = NULL;
  2031. DWORD dwStatus = 0;
  2032. DWORD dwMode = 0;
  2033. ICfgComp *pCfgComp = NULL;
  2034. OSVERSIONINFOEX OsVersionInfo;
  2035. OsVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  2036. if( GetVersionEx((OSVERSIONINFO*)&OsVersionInfo) )
  2037. {
  2038. if( ( OsVersionInfo.dwMajorVersion < 5 ) || ( OsVersionInfo.dwMajorVersion == 5 && OsVersionInfo.dwMinorVersion < 1 ))
  2039. {
  2040. return WBEM_E_INVALID_CLASS;
  2041. }
  2042. if(!(OsVersionInfo.wSuiteMask & VER_SUITE_ENTERPRISE) && !( OsVersionInfo.wSuiteMask & VER_SUITE_DATACENTER))
  2043. {
  2044. return WBEM_E_INVALID_CLASS;
  2045. }
  2046. }
  2047. CStackClass StackObj;
  2048. if(StackObj.m_pCfgComp == NULL)
  2049. {
  2050. return WBEM_E_ILLEGAL_NULL;
  2051. }
  2052. hr = StackObj.m_pCfgComp->QueryInterface( IID_ISettingsComp , ( PVOID * )&pSettings ) ;
  2053. if( SUCCEEDED( hr ) && pSettings != NULL )
  2054. {
  2055. pSettings->GetTermSrvMode(&dwMode , &dwStatus );
  2056. if( ERROR_SUCCESS == dwStatus && dwMode == 1)
  2057. {
  2058. // Method 2
  2059. // Query.GetValuesForProp(m_szSessionDirectoryLocation, asNames);
  2060. Query.GetValuesForProp(m_szMode, asNames);
  2061. BOOL bGetAllInstances = asNames.GetSize() == 0;
  2062. // Method 1
  2063. if (Query.IsPropertyRequired(m_szMode))
  2064. dwRequiredProperties |= BIT_MODE;
  2065. if (Query.IsPropertyRequired(m_szSessionDirectoryActive))
  2066. dwRequiredProperties |= BIT_SESSIONDIRECTORYACTIVE;
  2067. if (Query.IsPropertyRequired(m_szSessionDirectoryLocation))
  2068. dwRequiredProperties |= BIT_SESSIONDIRECTORY;
  2069. if (Query.IsPropertyRequired(m_szSessionDirectoryClusterName))
  2070. dwRequiredProperties |= BIT_CLUSTERNAME;
  2071. if (Query.IsPropertyRequired(m_szSessionDirectoryExposeServerIP))
  2072. dwRequiredProperties |= BIT_SESSIONDIRECTORYEXPOSESERVERIP;
  2073. if (Query.IsPropertyRequired(m_szSessionDirectoryIPAddress))
  2074. dwRequiredProperties |= BIT_SESSIONDIRECTORYIPADDRESS;
  2075. /*
  2076. if (Query.IsPropertyRequired(m_szSessionDirectoryAdditionalParams))
  2077. dwRequiredProperties |= BIT_ADDITIONALPARAMS;
  2078. */
  2079. // Method 2
  2080. CInstance* pInstance = CreateNewInstance(pMethodContext);
  2081. if( pInstance != NULL)
  2082. {
  2083. pInstance->SetCHString(m_szSessionDirectoryLocation, chSessionDirectory );
  2084. hr = LoadPropertyValues(pInstance, dwRequiredProperties);
  2085. if( SUCCEEDED( hr ) )
  2086. {
  2087. hr = pInstance->Commit();
  2088. }
  2089. pInstance->Release();
  2090. }
  2091. else
  2092. {
  2093. ERR((TB, "Win32_TSSessionDirectory@ExecQuery: CreateNewInstance failed"));
  2094. hr = WBEM_E_OUT_OF_MEMORY;
  2095. }
  2096. }
  2097. }
  2098. if( pSettings != NULL )
  2099. {
  2100. pSettings->Release();
  2101. }
  2102. return hr;
  2103. }
  2104. //=--------------
  2105. BOOL CWin32_TSSessionDirectory::IsInList(const CHStringArray &asArray, LPCWSTR pszString)
  2106. {
  2107. DWORD dwSize = asArray.GetSize();
  2108. for( DWORD x=0; x < dwSize; x++ )
  2109. {
  2110. if( asArray[x].CompareNoCase(pszString) == 0 )
  2111. {
  2112. return TRUE;
  2113. }
  2114. }
  2115. return FALSE;
  2116. }
  2117. //=-------------
  2118. HRESULT CWin32_TSSessionDirectory::ExecMethod ( const CInstance& Inst,
  2119. const BSTR bstrMethodName,
  2120. CInstance *pInParams,
  2121. CInstance *pOutParams,
  2122. long lFlags)
  2123. {
  2124. DWORD dwData = 0;
  2125. CHString chData;
  2126. HKEY hKey = NULL;
  2127. LONG lRet = 0;
  2128. bool bRet;
  2129. bool bUpdate = FALSE;
  2130. DWORD dwSize = sizeof (DWORD);
  2131. TCHAR szName[ SESSDIR_LENGTH ];
  2132. ISettingsComp* pSettings = NULL;
  2133. DWORD dwStatus = 0;
  2134. DWORD dwMode = 0;
  2135. HRESULT hr = WBEM_E_INVALID_CLASS;
  2136. ICfgComp *pCfgComp = NULL;
  2137. CHString chSessDirName;
  2138. DWORD cbName;
  2139. OSVERSIONINFOEX OsVersionInfo;
  2140. OsVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  2141. CStackClass StackObj;
  2142. if(StackObj.m_pCfgComp == NULL)
  2143. {
  2144. return WBEM_E_ILLEGAL_NULL;
  2145. }
  2146. if( pInParams == NULL )
  2147. {
  2148. ERR((TB, "TSSessionDirectory@ExecQuery: invalid interface"));
  2149. return WBEM_E_INVALID_METHOD_PARAMETERS;
  2150. }
  2151. hr = StackObj.m_pCfgComp->QueryInterface( IID_ISettingsComp , ( PVOID * )&pSettings ) ;
  2152. if( SUCCEEDED( hr ) && pSettings != NULL )
  2153. {
  2154. pSettings->GetTermSrvMode(&dwMode , &dwStatus );
  2155. if( ERROR_SUCCESS == dwStatus && dwMode == 0)
  2156. {
  2157. return WBEM_E_INVALID_CLASS;
  2158. }
  2159. }
  2160. if( GetVersionEx((OSVERSIONINFO*) &OsVersionInfo) )
  2161. {
  2162. if( ( OsVersionInfo.dwMajorVersion < 5 ) || ( OsVersionInfo.dwMajorVersion == 5 && OsVersionInfo.dwMinorVersion < 1 ))
  2163. {
  2164. return WBEM_E_INVALID_CLASS;
  2165. }
  2166. if(!(OsVersionInfo.wSuiteMask & VER_SUITE_ENTERPRISE) && !( OsVersionInfo.wSuiteMask & VER_SUITE_DATACENTER))
  2167. {
  2168. return WBEM_E_INVALID_CLASS;
  2169. }
  2170. }
  2171. /*
  2172. Inst.GetCHString(m_szSessionDirectoryLocation, chSessDirName);
  2173. if( chSessDirName.GetLength() > WINSTATIONNAME_LENGTH )
  2174. {
  2175. return WBEM_E_VALUE_OUT_OF_RANGE;
  2176. }
  2177. if( chSessDirName.IsEmpty() != 0 )
  2178. {
  2179. return WBEM_E_ILLEGAL_NULL;
  2180. }
  2181. */
  2182. do
  2183. {
  2184. // Sets one of the properties: SessionDirectoryLocation or SessionDirectoryClusterName
  2185. // uint32 SetSessionDirectoryProperty([In] string PropertyName, string Value);
  2186. if( _wcsicmp(bstrMethodName, m_szSetSessionDirectoryProperty) == 0 )
  2187. {
  2188. lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE ,
  2189. REG_TS_CLUSTERSETTINGS ,
  2190. 0,
  2191. KEY_READ | KEY_WRITE,
  2192. &hKey );
  2193. if( ERROR_SUCCESS != lRet )
  2194. {
  2195. ERR((TB, "TSSessionDirectory@ExecQuery: RegOpenKeyEx failed"));
  2196. hr = WBEM_E_INITIALIZATION_FAILURE;
  2197. break;
  2198. }
  2199. pInParams->GetCHString (m_szPropertyName, chData);
  2200. if( chData.CompareNoCase (m_szSessionDirectoryLocation) == 0 )
  2201. {
  2202. RegGetMachinePolicy(&m_gpPolicy);
  2203. chData.Empty();
  2204. bRet = pInParams->GetCHString(m_szValue, chData );
  2205. if( ( m_gpPolicy.fPolicySessionDirectoryLocation == 0) && bRet )
  2206. {
  2207. if( chData.IsEmpty() )
  2208. {
  2209. hr = WBEM_E_INVALID_PARAMETER;
  2210. break;
  2211. }
  2212. if( chData.GetLength() > SESSDIR_LENGTH )
  2213. {
  2214. hr = WBEM_E_VALUE_OUT_OF_RANGE;
  2215. break;
  2216. }
  2217. lstrcpy(szName, chData);
  2218. cbName = (lstrlen(szName)+ 1) * sizeof(TCHAR);
  2219. lRet = RegSetValueEx( hKey ,
  2220. REG_TS_CLUSTER_STORESERVERNAME,
  2221. NULL ,
  2222. REG_SZ,
  2223. ( CONST LPBYTE )szName ,
  2224. cbName );
  2225. TRC2((TB, "Win32_TSSessionDirectory@ExecMethod: SessionDirectory returned 0x%x" , lRet));
  2226. if( lRet == ERROR_SUCCESS )
  2227. {
  2228. bUpdate = TRUE;
  2229. pOutParams->SetDWORD(L"ReturnValue", WBEM_S_NO_ERROR);
  2230. }
  2231. chData.Empty();
  2232. }
  2233. else
  2234. {
  2235. hr = WBEM_E_INVALID_OPERATION;
  2236. break;
  2237. }
  2238. }
  2239. else if( chData.CompareNoCase(m_szSessionDirectoryClusterName) == 0 )
  2240. {
  2241. RegGetMachinePolicy(&m_gpPolicy);
  2242. chData.Empty();
  2243. bRet = pInParams->GetCHString(m_szValue, chData );
  2244. if( ( m_gpPolicy.fPolicySessionDirectoryClusterName == 0) && bRet )
  2245. {
  2246. if( chData.GetLength() > SESSDIR_LENGTH )
  2247. {
  2248. hr = WBEM_E_VALUE_OUT_OF_RANGE;
  2249. break;
  2250. }
  2251. lstrcpy(szName, chData);
  2252. cbName = (lstrlen(szName)+ 1) * sizeof(TCHAR);
  2253. lRet = RegSetValueEx( hKey ,
  2254. REG_TS_CLUSTER_CLUSTERNAME,
  2255. NULL ,
  2256. REG_SZ,
  2257. ( CONST LPBYTE )szName ,
  2258. cbName );
  2259. TRC2((TB, "Win32_TSSessionDirectory@ExecMethod: SessionDirectory returned 0x%x" , lRet));
  2260. if( lRet == ERROR_SUCCESS )
  2261. {
  2262. bUpdate = TRUE;
  2263. pOutParams->SetDWORD(L"ReturnValue", WBEM_S_NO_ERROR);
  2264. }
  2265. chData.Empty();
  2266. }
  2267. else
  2268. {
  2269. hr = WBEM_E_INVALID_OPERATION;
  2270. break;
  2271. }
  2272. }
  2273. else
  2274. {
  2275. hr = WBEM_E_INVALID_METHOD;
  2276. break;
  2277. }
  2278. }
  2279. // Enables / Disables participation of a server in Session Directory
  2280. // uint32 SetSessionDirectoryActive([In] uint32 Value);
  2281. else if( _wcsicmp(bstrMethodName, m_szSetSessionDirectoryActive) == 0 )
  2282. {
  2283. lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE ,
  2284. REG_CONTROL_TSERVER ,
  2285. 0,
  2286. KEY_READ | KEY_WRITE,
  2287. &hKey );
  2288. if( ERROR_SUCCESS == lRet )
  2289. {
  2290. RegGetMachinePolicy(&m_gpPolicy);
  2291. bRet = pInParams->GetDWORD( m_szSessionDirectoryActive, dwData );
  2292. if( (m_gpPolicy.fPolicySessionDirectoryActive == 0) && bRet )
  2293. {
  2294. if( dwData != 0 && dwData != 1 )
  2295. {
  2296. hr = WBEM_E_INVALID_PARAMETER;
  2297. break;
  2298. }
  2299. lRet = RegSetValueEx( hKey ,
  2300. REG_TS_SESSDIRACTIVE,
  2301. 0 ,
  2302. REG_DWORD,
  2303. ( LPBYTE )&dwData ,
  2304. dwSize );
  2305. TRC2((TB, "Win32_TSSessionDirectory@ExecMethod: SessionDirectoryActive returned 0x%x" , lRet));
  2306. if( ERROR_SUCCESS == lRet )
  2307. {
  2308. bUpdate = TRUE;
  2309. pOutParams->SetDWORD(L"ReturnValue", WBEM_S_NO_ERROR);
  2310. }
  2311. }
  2312. else
  2313. {
  2314. hr = WBEM_E_INVALID_METHOD;
  2315. }
  2316. }
  2317. }
  2318. // Enables / Disables exposing the IP Address of Session Directory Server
  2319. // uint32 SetSessionDirectoryExposeServerIP([In] uint32 Value);
  2320. else if( _wcsicmp(bstrMethodName, m_szSetSessionDirectoryExposeServerIP) == 0 )
  2321. {
  2322. lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE ,
  2323. REG_CONTROL_TSERVER ,
  2324. 0,
  2325. KEY_READ | KEY_WRITE,
  2326. &hKey );
  2327. if( ERROR_SUCCESS == lRet )
  2328. {
  2329. RegGetMachinePolicy(&m_gpPolicy);
  2330. bRet = pInParams->GetDWORD( m_szSessionDirectoryExposeServerIP, dwData );
  2331. //todo: change the policy to IP
  2332. if( (m_gpPolicy.fPolicySessionDirectoryExposeServerIP == 0) && bRet )
  2333. {
  2334. if( dwData != 0 && dwData != 1 )
  2335. {
  2336. hr = WBEM_E_INVALID_PARAMETER;
  2337. break;
  2338. }
  2339. lRet = RegSetValueEx( hKey ,
  2340. REG_TS_SESSDIR_EXPOSE_SERVER_ADDR,
  2341. 0 ,
  2342. REG_DWORD,
  2343. ( LPBYTE )&dwData ,
  2344. dwSize );
  2345. TRC2((TB, "Win32_TSSessionDirectory@ExecMethod: SessionDirectoryExposeServerIP returned 0x%x" , lRet));
  2346. if( ERROR_SUCCESS == lRet )
  2347. {
  2348. bUpdate = TRUE;
  2349. pOutParams->SetDWORD(L"ReturnValue", WBEM_S_NO_ERROR);
  2350. }
  2351. }
  2352. else
  2353. {
  2354. hr = WBEM_E_INVALID_METHOD;
  2355. }
  2356. }
  2357. }
  2358. }while(0);
  2359. if( bUpdate )
  2360. {
  2361. StackObj.m_pCfgComp->UpdateSessionDirectory(&dwStatus);
  2362. }
  2363. if( hKey != NULL )
  2364. {
  2365. RegCloseKey( hKey );
  2366. }
  2367. if( pSettings != NULL )
  2368. {
  2369. pSettings->Release();
  2370. }
  2371. return hr;
  2372. }
  2373. //=-------------
  2374. HRESULT CWin32_TSSessionDirectory::LoadPropertyValues( CInstance *pInstance, DWORD dwRequiredProperties)
  2375. {
  2376. LONG lRet = 0;
  2377. DWORD dwData = 0;
  2378. DWORD dwSize = 0;
  2379. HKEY hKey = NULL;
  2380. WCHAR tchData[ OPAQUESETTINGS_LENGTH +1] ={0};
  2381. TCHAR tchData1[ OPAQUESETTINGS_LENGTH +1] = {0} ;
  2382. dwSize = sizeof( DWORD );
  2383. lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE ,
  2384. REG_CONTROL_TSERVER ,
  2385. 0,
  2386. KEY_READ,
  2387. &hKey );
  2388. if( ERROR_SUCCESS == lRet && hKey != NULL)
  2389. {
  2390. if( dwRequiredProperties & BIT_SESSIONDIRECTORYACTIVE )
  2391. {
  2392. RegGetMachinePolicy(&m_gpPolicy);
  2393. if( m_gpPolicy.fPolicySessionDirectoryActive != 0 )
  2394. {
  2395. dwData = m_gpPolicy.SessionDirectoryActive;
  2396. }
  2397. else
  2398. {
  2399. lRet = RegQueryValueEx( hKey ,
  2400. REG_TS_SESSDIRACTIVE,
  2401. NULL ,
  2402. NULL ,
  2403. (LPBYTE)&dwData ,
  2404. &dwSize );
  2405. }
  2406. TRC2((TB, "Win32_TSSessionDirectory@LoadPropertyValues: SessionDirectoryActive returned 0x%x" , lRet));
  2407. if( ERROR_SUCCESS == lRet )
  2408. {
  2409. pInstance->SetDWORD(m_szSessionDirectoryActive, dwData);
  2410. }
  2411. }
  2412. if( dwRequiredProperties & BIT_SESSIONDIRECTORYEXPOSESERVERIP )
  2413. {
  2414. RegGetMachinePolicy(&m_gpPolicy);
  2415. if( m_gpPolicy.fPolicySessionDirectoryExposeServerIP != 0 )
  2416. {
  2417. dwData = m_gpPolicy.SessionDirectoryExposeServerIP;
  2418. }
  2419. else
  2420. {
  2421. lRet = RegQueryValueEx( hKey ,
  2422. REG_TS_SESSDIR_EXPOSE_SERVER_ADDR,
  2423. NULL ,
  2424. NULL ,
  2425. (LPBYTE)&dwData ,
  2426. &dwSize );
  2427. }
  2428. TRC2((TB, "Win32_TSSessionDirectory@LoadPropertyValues: SessionDirectoryExposeServerIP returned 0x%x" , lRet));
  2429. if( ERROR_SUCCESS == lRet )
  2430. {
  2431. pInstance->SetDWORD(m_szSessionDirectoryExposeServerIP, dwData);
  2432. }
  2433. }
  2434. RegCloseKey (hKey);
  2435. }
  2436. lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE ,
  2437. REG_TS_CLUSTERSETTINGS ,
  2438. 0,
  2439. KEY_READ,
  2440. &hKey );
  2441. if( ERROR_SUCCESS == lRet && hKey != NULL)
  2442. {
  2443. if( dwRequiredProperties & BIT_SESSIONDIRECTORY )
  2444. {
  2445. RegGetMachinePolicy(&m_gpPolicy);
  2446. if( m_gpPolicy.fPolicySessionDirectoryLocation != 0 )
  2447. {
  2448. lstrcpy(tchData, m_gpPolicy.SessionDirectoryLocation);
  2449. }
  2450. else
  2451. {
  2452. dwSize = sizeof( tchData );
  2453. lRet = RegQueryValueEx( hKey ,
  2454. REG_TS_CLUSTER_STORESERVERNAME,
  2455. NULL ,
  2456. NULL ,
  2457. (LPBYTE)tchData ,
  2458. &dwSize );
  2459. }
  2460. TRC2((TB, "Win32_TSSessionDirectory@LoadPropertyValues: SessionDirectoryLocation returned 0x%x" , lRet));
  2461. if( ERROR_SUCCESS == lRet )
  2462. {
  2463. pInstance->SetCHString(m_szSessionDirectoryLocation, tchData);
  2464. }
  2465. }
  2466. if( dwRequiredProperties & BIT_CLUSTERNAME )
  2467. {
  2468. RegGetMachinePolicy(&m_gpPolicy);
  2469. if( m_gpPolicy.fPolicySessionDirectoryClusterName != 0 )
  2470. {
  2471. lstrcpy( tchData, m_gpPolicy.SessionDirectoryClusterName );
  2472. }
  2473. else
  2474. {
  2475. dwSize = sizeof( tchData );
  2476. lRet = RegQueryValueEx( hKey ,
  2477. REG_TS_CLUSTER_CLUSTERNAME,
  2478. NULL ,
  2479. NULL ,
  2480. (LPBYTE)tchData ,
  2481. &dwSize );
  2482. }
  2483. TRC2((TB, "Win32_TSSessionDirectory@LoadPropertyValues: ClusterName returned 0x%x" , lRet));
  2484. if( ERROR_SUCCESS == lRet )
  2485. {
  2486. pInstance->SetCHString(m_szSessionDirectoryClusterName, tchData);
  2487. }
  2488. }
  2489. if( dwRequiredProperties & BIT_SESSIONDIRECTORYIPADDRESS )
  2490. {
  2491. dwSize = sizeof( tchData1 );
  2492. lRet = RegQueryValueEx( hKey ,
  2493. REG_TS_CLUSTER_REDIRECTIONIP,
  2494. NULL ,
  2495. NULL ,
  2496. (LPBYTE)tchData1 ,
  2497. &dwSize );
  2498. TRC2((TB, "Win32_TSSessionDirectory@LoadPropertyValues:Session Directory IP Address returned 0x%x" , lRet));
  2499. if( ERROR_SUCCESS == lRet )
  2500. {
  2501. pInstance->SetCHString(m_szSessionDirectoryIPAddress, tchData1);
  2502. }
  2503. }
  2504. /*
  2505. if( dwRequiredProperties & BIT_ADDITIONALPARAMS )
  2506. {
  2507. dwSize = sizeof( tchData );
  2508. lRet = RegQueryValueEx( hKey ,
  2509. REG_TS_CLUSTER_OPAQUESETTINGS,
  2510. NULL ,
  2511. NULL ,
  2512. (LPBYTE)&tchData ,
  2513. &dwSize );
  2514. TRC2((TB, "Win32_TSSessionDirectory@LoadPropertyValues: AdditionalParams returned 0x%x" , lRet));
  2515. if( ERROR_SUCCESS == lRet )
  2516. {
  2517. pInstance->SetCHString(m_szSessionDirectoryAdditionalParams, (LPTSTR)(LPCTSTR)&tchData);
  2518. }
  2519. }
  2520. */
  2521. RegCloseKey( hKey );
  2522. }
  2523. return S_OK;
  2524. }
  2525. //=-------------------
  2526. HRESULT CWin32_TSSessionDirectory::PutInstance ( const CInstance &Instance, long lFlags)
  2527. {
  2528. LONG hr = 0;
  2529. DWORD dwData;
  2530. CHString chData;
  2531. HKEY hKey = NULL;
  2532. LONG lRet;
  2533. DWORD dwSize = sizeof (DWORD);
  2534. TCHAR szName[ SESSDIR_LENGTH ];
  2535. DWORD cbName;
  2536. DWORD dwStatus;
  2537. ULONG ulTerminals = 0, ulAdapters = 0;
  2538. ULONG ulSize = 0, ulNum =0;
  2539. PWS pWS= NULL;
  2540. PWS pWSList= NULL;
  2541. PGUIDTBL pGuidtbl = NULL;
  2542. TCHAR tchGuid[ GUID_LENGTH ];
  2543. hr = WBEM_S_NO_ERROR;
  2544. CHString chAddress;
  2545. DWORD Err = 0;
  2546. TCHAR tchAdd[MAX_PATH]=L"";
  2547. TCHAR tchAdapterName[MAX_PATH]=L"";
  2548. DWORD AdapterInfoSize;
  2549. PIP_ADDR_STRING pAddrStr;
  2550. PIP_ADAPTER_INFO pAdapterInfo = NULL, pAdapt = NULL;
  2551. LPWSTR pwszNLBipAddress = NULL;
  2552. ICfgComp *pCfgComp = NULL;
  2553. CStackClass StackObj;
  2554. if(StackObj.m_pCfgComp == NULL)
  2555. {
  2556. return WBEM_E_ILLEGAL_NULL;
  2557. }
  2558. lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE ,
  2559. REG_CONTROL_TSERVER ,
  2560. 0,
  2561. KEY_READ,
  2562. &hKey );
  2563. if( ERROR_SUCCESS != lRet || hKey == NULL)
  2564. {
  2565. return WBEM_E_INVALID_OPERATION;
  2566. }
  2567. RegGetMachinePolicy(&m_gpPolicy);
  2568. if( m_gpPolicy.fPolicySessionDirectoryActive != 0 )
  2569. {
  2570. dwData = m_gpPolicy.SessionDirectoryActive;
  2571. }
  2572. else
  2573. {
  2574. lRet = RegQueryValueEx( hKey ,
  2575. REG_TS_SESSDIRACTIVE,
  2576. NULL ,
  2577. NULL ,
  2578. (LPBYTE)&dwData ,
  2579. &dwSize );
  2580. }
  2581. TRC2((TB, "Win32_TSSessionDirectory@PutInstance: RegQuery for SessionDirectoryActive returned 0x%x" , lRet));
  2582. if(hKey)
  2583. {
  2584. RegCloseKey(hKey);
  2585. hKey = NULL;
  2586. }
  2587. if( dwData == 0 )
  2588. {
  2589. return WBEM_E_INVALID_OPERATION;
  2590. }
  2591. Instance.GetCHString(m_szSessionDirectoryIPAddress, chAddress);
  2592. lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE ,
  2593. REG_TS_CLUSTERSETTINGS ,
  2594. 0,
  2595. KEY_READ | KEY_WRITE,
  2596. &hKey );
  2597. if( ERROR_SUCCESS != lRet )
  2598. {
  2599. ERR((TB, "TSSessionDirectory@PutInstance: RegOpenKeyEx failed"));
  2600. return WBEM_E_INVALID_OPERATION;
  2601. }
  2602. hr = GetNLBIP(&pwszNLBipAddress);
  2603. if (FAILED(hr))
  2604. {
  2605. goto Cleanup;
  2606. }
  2607. if( !_tcsicmp(chAddress, _TEXT("0.0.0.0")))
  2608. {
  2609. hr = WBEM_E_INVALID_PARAMETER;
  2610. goto Cleanup;
  2611. }
  2612. //
  2613. // Enumerate all of the adapter specific information using the IP_ADAPTER_INFO structure.
  2614. // Note: IP_ADAPTER_INFO contains a linked list of adapter entries.
  2615. //
  2616. AdapterInfoSize = 0;
  2617. GetAdaptersInfo(NULL, &AdapterInfoSize);
  2618. if(AdapterInfoSize == 0)
  2619. {
  2620. return WBEM_E_OUT_OF_MEMORY;
  2621. }
  2622. if( chAddress.GetLength() > GUID_LENGTH )
  2623. {
  2624. hr = WBEM_E_INVALID_PARAMETER;
  2625. goto Cleanup;
  2626. }
  2627. // Allocate memory from sizing information
  2628. if ((pAdapterInfo = (PIP_ADAPTER_INFO) GlobalAlloc(GPTR, AdapterInfoSize)) == NULL)
  2629. {
  2630. return WBEM_E_OUT_OF_MEMORY;
  2631. }
  2632. // Get actual adapter information
  2633. if ((Err = GetAdaptersInfo(pAdapterInfo, &AdapterInfoSize)) != 0)
  2634. {
  2635. hr = WBEM_E_OUT_OF_MEMORY;
  2636. goto Cleanup;
  2637. }
  2638. BOOL bAllAdapters = FALSE;
  2639. hr = StackObj.m_pCfgComp->GetWinstationList(&ulTerminals, &ulSize, &pWSList);
  2640. if( SUCCEEDED( hr ) && pWSList != NULL )
  2641. {
  2642. for( ulNum = 0; ulNum < ulTerminals ; ulNum++ )
  2643. {
  2644. if( pWSList[ulNum].LanAdapter == 0 )
  2645. {
  2646. bAllAdapters = TRUE;
  2647. }
  2648. }
  2649. }
  2650. pAdapt = pAdapterInfo;
  2651. for (; pAdapt ; pAdapt = pAdapt->Next)
  2652. {
  2653. pAddrStr = &(pAdapt->IpAddressList);
  2654. while(pAddrStr)
  2655. {
  2656. MultiByteToWideChar(GetACP(), 0, pAddrStr->IpAddress.String, -1, tchAdd, MAX_PATH);
  2657. MultiByteToWideChar(GetACP(), 0, pAdapt->AdapterName, -1, tchAdapterName, MAX_PATH);
  2658. if( !_tcsicmp(chAddress, tchAdd))
  2659. {
  2660. if(pwszNLBipAddress && (_tcsstr(pwszNLBipAddress, tchAdd)!= NULL))
  2661. {
  2662. hr = WBEM_E_INVALID_PARAMETER;
  2663. goto Cleanup;
  2664. }
  2665. goto Label;
  2666. }
  2667. pAddrStr = pAddrStr->Next;
  2668. }
  2669. }
  2670. hr = WBEM_E_INVALID_PARAMETER;
  2671. goto Cleanup;
  2672. Label:
  2673. if(bAllAdapters == TRUE)
  2674. {
  2675. goto Found;
  2676. }
  2677. if( SUCCEEDED( hr ) && pWSList != NULL)
  2678. {
  2679. for( ulNum = 0; ulNum < ulTerminals ; ulNum++ )
  2680. {
  2681. if(_tcsicmp(pWSList[ulNum].pdName, L"Console"))
  2682. break;
  2683. }
  2684. hr = StackObj.m_pCfgComp->GetLanAdapterList2(pWSList[ulNum].pdName, &ulAdapters , &pGuidtbl );
  2685. if( SUCCEEDED( hr ) && pGuidtbl != NULL)
  2686. {
  2687. StringFromGUID2( ( pGuidtbl )[ pWSList[ulNum].LanAdapter ].guidNIC , tchGuid , ARRAYSIZE( tchGuid ) );
  2688. if( _tcsicmp( tchGuid, tchAdapterName ) == 0 )
  2689. {
  2690. goto Found;
  2691. }
  2692. }
  2693. }
  2694. hr = WBEM_E_INVALID_PARAMETER;
  2695. goto Cleanup;
  2696. Found:
  2697. lstrcpy(szName, chAddress);
  2698. cbName = (lstrlen(szName)+ 1) * sizeof(TCHAR);
  2699. lRet = RegSetValueEx( hKey ,
  2700. REG_TS_CLUSTER_REDIRECTIONIP,
  2701. NULL ,
  2702. REG_SZ,
  2703. ( CONST LPBYTE )szName ,
  2704. cbName );
  2705. TRC2((TB, "Win32_TSSessionDirectory@ExecMethod: SessionDirectory returned 0x%x" , lRet));
  2706. if(lRet == ERROR_SUCCESS)
  2707. {
  2708. StackObj.m_pCfgComp->UpdateSessionDirectory(&dwStatus);
  2709. }
  2710. Cleanup:
  2711. if (pwszNLBipAddress)
  2712. GlobalFree(pwszNLBipAddress);
  2713. if(pAdapterInfo)
  2714. {
  2715. GlobalFree(pAdapterInfo);
  2716. }
  2717. return hr;
  2718. }