Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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