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.

811 lines
21 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation, All Rights Reserved
  4. //
  5. // NtDomain.cpp
  6. //
  7. // Purpose: Nt domain discovery property set provider
  8. //
  9. //***************************************************************************
  10. #include "precomp.h"
  11. #include <frqueryex.h>
  12. #include "wbemnetapi32.h"
  13. #include <dsgetdc.h>
  14. #include "NtDomain.h"
  15. #define MAX_PROPS CWin32_NtDomain::e_End_Property_Marker
  16. #define MAX_PROP_IN_BYTES MAX_PROPS/8 + 1
  17. #define _tobit( a ) ( 1 << a )
  18. #define DOMAIN_PREPEND L"Domain: "
  19. #define DOMAIN_PREPEND_SIZE ((sizeof(DOMAIN_PREPEND)/sizeof(WCHAR)) - 1 )
  20. // into strings.cpp
  21. LPCWSTR IDS_DomainControllerName = L"DomainControllerName" ;
  22. LPCWSTR IDS_DomainControllerAddress = L"DomainControllerAddress" ;
  23. LPCWSTR IDS_DomainControllerAddressType = L"DomainControllerAddressType" ;
  24. LPCWSTR IDS_DomainGuid = L"DomainGuid" ;
  25. LPCWSTR IDS_DomainName = L"DomainName" ;
  26. LPCWSTR IDS_DnsForestName = L"DnsForestName" ;
  27. LPCWSTR IDS_DS_PDC_Flag = L"DSPrimaryDomainControllerFlag" ;
  28. LPCWSTR IDS_DS_Writable_Flag = L"DSWritableFlag" ;
  29. LPCWSTR IDS_DS_GC_Flag = L"DSGlobalCatalogFlag" ;
  30. LPCWSTR IDS_DS_DS_Flag = L"DSDirectoryServiceFlag" ;
  31. LPCWSTR IDS_DS_KDC_Flag = L"DSKerberosDistributionCenterFlag" ;
  32. LPCWSTR IDS_DS_Timeserv_Flag = L"DSTimeServiceFlag" ;
  33. LPCWSTR IDS_DS_DNS_Controller_Flag = L"DSDnsControllerFlag" ;
  34. LPCWSTR IDS_DS_DNS_Domain_Flag = L"DSDnsDomainFlag" ;
  35. LPCWSTR IDS_DS_DNS_Forest_Flag = L"DSDnsForestFlag" ;
  36. LPCWSTR IDS_DcSiteName = L"DcSiteName" ;
  37. LPCWSTR IDS_ClientSiteName = L"ClientSiteName" ;
  38. // Property set declaration
  39. //=========================
  40. CWin32_NtDomain s_Win32_NtDomain( PROPSET_NAME_NTDOMAIN , IDS_CimWin32Namespace ) ;
  41. /*****************************************************************************
  42. *
  43. * FUNCTION : CWin32_NtDomain::CWin32_NtDomain
  44. *
  45. * DESCRIPTION : Constructor
  46. *
  47. * INPUTS : const CHString& strName - Name of the class.
  48. *
  49. * OUTPUTS : none
  50. *
  51. * RETURNS : nothing
  52. *
  53. * COMMENTS : Registers property set with framework
  54. *
  55. *****************************************************************************/
  56. CWin32_NtDomain::CWin32_NtDomain (
  57. LPCWSTR a_Name,
  58. LPCWSTR a_Namespace
  59. )
  60. : Provider(a_Name, a_Namespace)
  61. {
  62. SetPropertyTable() ;
  63. }
  64. /*****************************************************************************
  65. *
  66. * FUNCTION : CWin32_NtDomain::~CWin32_NtDomain
  67. *
  68. * DESCRIPTION : Destructor
  69. *
  70. * INPUTS : none
  71. *
  72. * OUTPUTS : none
  73. *
  74. * RETURNS : nothing
  75. *
  76. * COMMENTS : Deregisters property set from framework
  77. *
  78. *****************************************************************************/
  79. CWin32_NtDomain :: ~CWin32_NtDomain()
  80. {
  81. }
  82. //
  83. void CWin32_NtDomain::SetPropertyTable()
  84. {
  85. // property set names for query optimization
  86. m_pProps.SetSize( MAX_PROPS ) ;
  87. // Win32_NtDomain
  88. m_pProps[e_DomainControllerName] =(LPVOID) IDS_DomainControllerName;
  89. m_pProps[e_DomainControllerAddress] =(LPVOID) IDS_DomainControllerAddress;
  90. m_pProps[e_DomainControllerAddressType] =(LPVOID) IDS_DomainControllerAddressType;
  91. m_pProps[e_DomainGuid] =(LPVOID) IDS_DomainGuid;
  92. m_pProps[e_DomainName] =(LPVOID) IDS_DomainName;
  93. m_pProps[e_DnsForestName] =(LPVOID) IDS_DnsForestName;
  94. m_pProps[e_DS_PDC_Flag] =(LPVOID) IDS_DS_PDC_Flag;
  95. m_pProps[e_DS_Writable_Flag] =(LPVOID) IDS_DS_Writable_Flag;
  96. m_pProps[e_DS_GC_Flag] =(LPVOID) IDS_DS_GC_Flag;
  97. m_pProps[e_DS_DS_Flag] =(LPVOID) IDS_DS_DS_Flag;
  98. m_pProps[e_DS_KDC_Flag] =(LPVOID) IDS_DS_KDC_Flag;
  99. m_pProps[e_DS_Timeserv_Flag] =(LPVOID) IDS_DS_Timeserv_Flag;
  100. m_pProps[e_DS_DNS_Controller_Flag] =(LPVOID) IDS_DS_DNS_Controller_Flag;
  101. m_pProps[e_DS_DNS_Domain_Flag] =(LPVOID) IDS_DS_DNS_Domain_Flag;
  102. m_pProps[e_DS_DNS_Forest_Flag] =(LPVOID) IDS_DS_DNS_Forest_Flag;
  103. m_pProps[e_DcSiteName] =(LPVOID) IDS_DcSiteName;
  104. m_pProps[e_ClientSiteName] =(LPVOID) IDS_ClientSiteName;
  105. // CIM_System
  106. m_pProps[e_CreationClassName] =(LPVOID) IDS_CreationClassName;
  107. m_pProps[e_Name] =(LPVOID) IDS_Name; // key, override from CIM_ManagedSystemElement
  108. m_pProps[e_NameFormat] =(LPVOID) IDS_NameFormat;
  109. m_pProps[e_PrimaryOwnerContact] =(LPVOID) IDS_PrimaryOwnerContact;
  110. m_pProps[e_PrimaryOwnerName] =(LPVOID) IDS_PrimaryOwnerName;
  111. m_pProps[e_Roles] =(LPVOID) IDS_Roles;
  112. // CIM_ManagedSystemElement
  113. m_pProps[e_Caption] =(LPVOID) IDS_Caption;
  114. m_pProps[e_Description] =(LPVOID) IDS_Description;
  115. m_pProps[e_InstallDate] =(LPVOID) IDS_InstallDate;
  116. m_pProps[e_Status] =(LPVOID) IDS_Status;
  117. }
  118. ////////////////////////////////////////////////////////////////////////
  119. //
  120. // Function: CWin32_NtDomain::GetObject
  121. //
  122. // Inputs: CInstance* pInstance - Instance into which we
  123. // retrieve data.
  124. //
  125. // Outputs: None.
  126. //
  127. // Returns: HRESULT Success/Failure code.
  128. //
  129. // Comments: The calling function will commit the instance.
  130. //
  131. ////////////////////////////////////////////////////////////////////////
  132. #ifdef WIN9XONLY
  133. HRESULT CWin32_NtDomain::GetObject(
  134. CInstance *a_pInstance,
  135. long a_Flags,
  136. CFrameworkQuery &a_rQuery
  137. )
  138. {
  139. return WBEM_S_NO_ERROR;
  140. }
  141. #endif
  142. #ifdef NTONLY
  143. HRESULT CWin32_NtDomain::GetObject(
  144. CInstance *a_pInstance,
  145. long a_Flags,
  146. CFrameworkQuery &a_rQuery
  147. )
  148. {
  149. HRESULT t_hResult = WBEM_E_NOT_FOUND ;
  150. CHString t_chsDomainName ;
  151. CHString t_chsDomainKey ;
  152. DWORD t_dwBits ;
  153. CFrameworkQueryEx *t_pQuery2 ;
  154. std::vector<_bstr_t> t_vectorTrustList ;
  155. CNetAPI32 t_NetAPI ;
  156. if( ERROR_SUCCESS != t_NetAPI.Init() )
  157. {
  158. return WBEM_E_FAILED ;
  159. }
  160. // the key
  161. a_pInstance->GetCHString( IDS_Name, t_chsDomainKey ) ;
  162. // NTD: begins the key -- this keeps this class from colliding
  163. // other CIM_System based classes
  164. if( 0 == _wcsnicmp(t_chsDomainKey, DOMAIN_PREPEND, DOMAIN_PREPEND_SIZE ) )
  165. {
  166. t_chsDomainName = t_chsDomainKey.Mid( DOMAIN_PREPEND_SIZE ) ;
  167. }
  168. else
  169. {
  170. return WBEM_E_NOT_FOUND ;
  171. }
  172. // test resultant key
  173. if( t_chsDomainName.IsEmpty() )
  174. {
  175. return WBEM_E_NOT_FOUND ;
  176. }
  177. // secure trusted domain list for key validation
  178. t_NetAPI.GetTrustedDomainsNT( t_vectorTrustList ) ;
  179. for( UINT t_u = 0L; t_u < t_vectorTrustList.size(); t_u++ )
  180. {
  181. if( 0 == _wcsicmp( t_vectorTrustList[t_u], bstr_t( t_chsDomainName ) ) )
  182. {
  183. // properties required
  184. t_pQuery2 = static_cast <CFrameworkQueryEx*>( &a_rQuery ) ;
  185. t_pQuery2->GetPropertyBitMask( m_pProps, &t_dwBits ) ;
  186. t_hResult = GetDomainInfo( t_NetAPI,
  187. bstr_t( t_chsDomainName ),
  188. a_pInstance,
  189. t_dwBits ) ;
  190. if( WBEM_E_NOT_FOUND == t_hResult )
  191. {
  192. // We have instantiated the domain. Couldn't obtain info though...
  193. t_hResult = WBEM_S_PARTIAL_RESULTS ;
  194. }
  195. break;
  196. }
  197. }
  198. return t_hResult ;
  199. }
  200. #endif
  201. ////////////////////////////////////////////////////////////////////////
  202. //
  203. // Function: CWin32_NtDomain::EnumerateInstances
  204. //
  205. // Inputs: MethodContext* a_pMethodContext - Context to enum
  206. // instance data in.
  207. //
  208. // Outputs: None.
  209. //
  210. // Returns: HRESULT Success/Failure code.
  211. //
  212. // Comments: None.
  213. //
  214. ////////////////////////////////////////////////////////////////////////
  215. #ifdef WIN9XONLY
  216. HRESULT CWin32_NtDomain::EnumerateInstances(
  217. MethodContext *a_pMethodContext,
  218. long a_Flags
  219. )
  220. {
  221. return WBEM_S_NO_ERROR;
  222. }
  223. #endif
  224. #ifdef NTONLY
  225. HRESULT CWin32_NtDomain::EnumerateInstances(
  226. MethodContext *a_pMethodContext,
  227. long a_Flags
  228. )
  229. {
  230. CNetAPI32 t_NetAPI ;
  231. if( ERROR_SUCCESS != t_NetAPI.Init() )
  232. {
  233. return WBEM_E_FAILED ;
  234. }
  235. // Property mask -- include all
  236. DWORD t_dwBits = 0xffffffff;
  237. return EnumerateInstances( a_pMethodContext,
  238. a_Flags,
  239. t_NetAPI,
  240. t_dwBits ) ;
  241. }
  242. #endif
  243. /*****************************************************************************
  244. *
  245. * FUNCTION : CWin32_NtDomain::ExecQuery
  246. *
  247. * DESCRIPTION : Query optimizer
  248. *
  249. * INPUTS :
  250. *
  251. * OUTPUTS :
  252. *
  253. * RETURNS :
  254. *
  255. * COMMENTS :
  256. *
  257. *****************************************************************************/
  258. #ifdef WIN9XONLY
  259. HRESULT CWin32_NtDomain::ExecQuery(
  260. MethodContext *a_pMethodContext,
  261. CFrameworkQuery &a_rQuery,
  262. long a_lFlags
  263. )
  264. {
  265. return WBEM_S_NO_ERROR;
  266. }
  267. #endif
  268. #ifdef NTONLY
  269. HRESULT CWin32_NtDomain::ExecQuery(
  270. MethodContext *a_pMethodContext,
  271. CFrameworkQuery &a_rQuery,
  272. long a_lFlags
  273. )
  274. {
  275. HRESULT t_hResult = WBEM_S_NO_ERROR ;
  276. HRESULT t_hPartialResult = WBEM_S_NO_ERROR ;
  277. DWORD t_dwBits ;
  278. CFrameworkQueryEx *t_pQuery2 ;
  279. std::vector<_bstr_t> t_vectorReqDomains ;
  280. std::vector<_bstr_t> t_vectorTrustList;
  281. CNetAPI32 t_NetAPI ;
  282. CHString t_chsDomainPrepend( DOMAIN_PREPEND ) ;
  283. if( ERROR_SUCCESS != t_NetAPI.Init() )
  284. {
  285. return WBEM_E_FAILED ;
  286. }
  287. // properties required
  288. t_pQuery2 = static_cast <CFrameworkQueryEx*>( &a_rQuery ) ;
  289. t_pQuery2->GetPropertyBitMask( m_pProps, &t_dwBits ) ;
  290. // keys supplied
  291. a_rQuery.GetValuesForProp( IDS_Name, t_vectorReqDomains ) ;
  292. // Note: the primary key has prepended chars to distinquish
  293. // these instances from other CIM_System instances.
  294. //
  295. if( t_vectorReqDomains.size() )
  296. {
  297. // strip prepended characters
  298. for( int t_y = 0; t_y < t_vectorReqDomains.size(); t_y++ )
  299. {
  300. if( DOMAIN_PREPEND_SIZE < t_vectorReqDomains[t_y].length() )
  301. {
  302. // match on prepend?
  303. if( _wcsnicmp( (wchar_t*)t_vectorReqDomains[t_y],
  304. DOMAIN_PREPEND,
  305. DOMAIN_PREPEND_SIZE ) == 0 )
  306. {
  307. t_vectorReqDomains[t_y] = ( (wchar_t*)t_vectorReqDomains[t_y] +
  308. DOMAIN_PREPEND_SIZE ) ;
  309. }
  310. }
  311. else
  312. {
  313. // does not contain the class prepend
  314. t_vectorReqDomains.erase( t_vectorReqDomains.begin() + t_y ) ;
  315. t_y--;
  316. }
  317. }
  318. }
  319. // If the primary key is not specified
  320. // then try for the alternate non key query.
  321. //
  322. // This is a requirement for assocation support
  323. // via CBinding as the linkage there is to DomainName
  324. if( !t_vectorReqDomains.size() )
  325. {
  326. a_rQuery.GetValuesForProp( IDS_DomainName, t_vectorReqDomains ) ;
  327. }
  328. // General enum if query is ambigious
  329. if( !t_vectorReqDomains.size() )
  330. {
  331. t_hResult = EnumerateInstances( a_pMethodContext,
  332. a_lFlags,
  333. t_NetAPI,
  334. t_dwBits ) ;
  335. }
  336. else
  337. {
  338. // smart ptr
  339. CInstancePtr t_pInst ;
  340. // secure trusted domain list
  341. t_NetAPI.GetTrustedDomainsNT( t_vectorTrustList ) ;
  342. // by query list
  343. for ( UINT t_uD = 0; t_uD < t_vectorReqDomains.size(); t_uD++ )
  344. {
  345. // by Domain trust list
  346. for( UINT t_uT = 0L; t_uT < t_vectorTrustList.size(); t_uT++ )
  347. {
  348. // Trust to request match
  349. if( 0 == _wcsicmp( t_vectorTrustList[t_uT], t_vectorReqDomains[t_uD] ) )
  350. {
  351. t_pInst.Attach( CreateNewInstance( a_pMethodContext ) ) ;
  352. t_hResult = GetDomainInfo( t_NetAPI,
  353. t_vectorReqDomains[t_uD],
  354. t_pInst,
  355. t_dwBits ) ;
  356. if( SUCCEEDED( t_hResult ) )
  357. {
  358. // the key
  359. t_pInst->SetCHString( IDS_Name, t_chsDomainPrepend +
  360. (wchar_t*)t_vectorReqDomains[t_uD] ) ;
  361. t_hResult = t_pInst->Commit() ;
  362. }
  363. else if( WBEM_E_NOT_FOUND == t_hResult )
  364. {
  365. // We have instantiated the domain. Couldn't obtain info though...
  366. t_pInst->SetCHString( IDS_Name, t_chsDomainPrepend +
  367. (wchar_t*)t_vectorReqDomains[t_uD] ) ;
  368. t_hResult = t_pInst->Commit() ;
  369. t_hPartialResult = WBEM_S_PARTIAL_RESULTS ;
  370. }
  371. break ;
  372. }
  373. }
  374. if( FAILED( t_hResult ) )
  375. {
  376. break ;
  377. }
  378. }
  379. }
  380. return ( WBEM_S_NO_ERROR != t_hResult ) ? t_hResult : t_hPartialResult ;
  381. }
  382. #endif
  383. //
  384. #ifdef NTONLY
  385. HRESULT CWin32_NtDomain::EnumerateInstances(
  386. MethodContext *a_pMethodContext,
  387. long a_Flags,
  388. CNetAPI32 &a_rNetAPI,
  389. DWORD a_dwProps
  390. )
  391. {
  392. HRESULT t_hResult = WBEM_S_NO_ERROR ;
  393. HRESULT t_hPartialResult = WBEM_S_NO_ERROR ;
  394. std::vector<_bstr_t> t_vectorTrustList;
  395. CHString t_chsDomainPrepend( DOMAIN_PREPEND ) ;
  396. // smart ptr
  397. CInstancePtr t_pInst ;
  398. // secure trusted domain list
  399. a_rNetAPI.GetTrustedDomainsNT( t_vectorTrustList ) ;
  400. for( UINT t_u = 0L; t_u < t_vectorTrustList.size(); t_u++ )
  401. {
  402. t_pInst.Attach( CreateNewInstance( a_pMethodContext ) ) ;
  403. t_hResult = GetDomainInfo( a_rNetAPI,
  404. t_vectorTrustList[ t_u ],
  405. t_pInst,
  406. a_dwProps ) ;
  407. if( SUCCEEDED( t_hResult ) )
  408. {
  409. // the key
  410. t_pInst->SetCHString( IDS_Name, t_chsDomainPrepend +
  411. (wchar_t*)t_vectorTrustList[t_u] ) ;
  412. t_hResult = t_pInst->Commit() ;
  413. }
  414. else if( WBEM_E_NOT_FOUND == t_hResult )
  415. {
  416. // the key. We have instantiated the domain. Couldn't obtain info though...
  417. t_pInst->SetCHString( IDS_Name, t_chsDomainPrepend +
  418. (wchar_t*)t_vectorTrustList[t_u] ) ;
  419. t_hResult = t_pInst->Commit() ;
  420. t_hPartialResult = WBEM_S_PARTIAL_RESULTS ;
  421. }
  422. else
  423. {
  424. break ;
  425. }
  426. }
  427. return ( WBEM_S_NO_ERROR != t_hResult ) ? t_hResult : t_hPartialResult ;
  428. }
  429. #endif
  430. //
  431. #ifdef NTONLY
  432. HRESULT CWin32_NtDomain::GetDomainInfo(
  433. CNetAPI32 &a_rNetAPI,
  434. bstr_t &a_bstrDomainName,
  435. CInstance *a_pInst,
  436. DWORD a_dwProps
  437. )
  438. {
  439. HRESULT t_hResult = WBEM_S_NO_ERROR ;
  440. if( a_bstrDomainName.length() )
  441. {
  442. ULONG t_uFlags = 0L ;
  443. DOMAIN_CONTROLLER_INFO *t_pDCInfo = NULL ;
  444. DWORD t_dwNetApiResult = 0 ;
  445. try
  446. {
  447. // avoid the NetAPI call if not needed
  448. if( a_dwProps & (
  449. _tobit( e_DomainControllerName ) |
  450. _tobit( e_DomainControllerAddress ) |
  451. _tobit( e_DomainControllerAddressType ) |
  452. _tobit( e_DomainGuid ) |
  453. _tobit( e_DomainName ) |
  454. _tobit( e_DnsForestName ) |
  455. _tobit( e_DS_PDC_Flag ) |
  456. _tobit( e_DS_Writable_Flag ) |
  457. _tobit( e_DS_GC_Flag ) |
  458. _tobit( e_DS_DS_Flag ) |
  459. _tobit( e_DS_KDC_Flag ) |
  460. _tobit( e_DS_Timeserv_Flag ) |
  461. _tobit( e_DS_DNS_Controller_Flag ) |
  462. _tobit( e_DS_DNS_Domain_Flag ) |
  463. _tobit( e_DS_DNS_Forest_Flag ) |
  464. _tobit( e_DcSiteName ) |
  465. _tobit( e_ClientSiteName ) ) )
  466. {
  467. // if requesting domain IP
  468. if( a_dwProps & _tobit( e_DomainControllerAddress ) )
  469. {
  470. t_uFlags |= DS_IP_REQUIRED ;
  471. }
  472. t_dwNetApiResult = a_rNetAPI.DsGetDcName(
  473. NULL,
  474. (wchar_t*)a_bstrDomainName,
  475. NULL,
  476. NULL,
  477. t_uFlags,
  478. &t_pDCInfo ) ;
  479. // force it if not cached
  480. if( NO_ERROR != t_dwNetApiResult )
  481. {
  482. t_uFlags |= DS_FORCE_REDISCOVERY ;
  483. t_dwNetApiResult = a_rNetAPI.DsGetDcName(
  484. NULL,
  485. (wchar_t*)a_bstrDomainName,
  486. NULL,
  487. NULL,
  488. t_uFlags,
  489. &t_pDCInfo ) ;
  490. }
  491. if( ( NO_ERROR == t_dwNetApiResult ) && t_pDCInfo )
  492. {
  493. // DomainControllerName
  494. if( a_dwProps & _tobit( e_DomainControllerName ) )
  495. {
  496. if( t_pDCInfo->DomainControllerName )
  497. {
  498. a_pInst->SetWCHARSplat( IDS_DomainControllerName,
  499. t_pDCInfo->DomainControllerName ) ;
  500. }
  501. }
  502. // DomainControllerAddress
  503. if( a_dwProps & _tobit( e_DomainControllerAddress ) )
  504. {
  505. if( t_pDCInfo->DomainControllerAddress )
  506. {
  507. a_pInst->SetWCHARSplat( IDS_DomainControllerAddress,
  508. t_pDCInfo->DomainControllerAddress ) ;
  509. }
  510. // DomainControllerAddressType, dependent on DS_IP_REQUIRED request
  511. if( a_dwProps & _tobit( e_DomainControllerAddressType ) )
  512. {
  513. a_pInst->SetDWORD( IDS_DomainControllerAddressType,
  514. t_pDCInfo->DomainControllerAddressType ) ;
  515. }
  516. }
  517. // DomainGuid
  518. if( a_dwProps & _tobit( e_DomainGuid ) )
  519. {
  520. GUID t_NullGuid ;
  521. memset( &t_NullGuid, 0, sizeof( t_NullGuid ) ) ;
  522. if( !IsEqualGUID( t_NullGuid, t_pDCInfo->DomainGuid ) )
  523. {
  524. WCHAR t_cGuid[ 128 ] ;
  525. StringFromGUID2( t_pDCInfo->DomainGuid, t_cGuid, sizeof( t_cGuid ) / sizeof (WCHAR) ) ;
  526. a_pInst->SetWCHARSplat( IDS_DomainGuid,
  527. t_cGuid ) ;
  528. }
  529. }
  530. // DomainName
  531. if( a_dwProps & _tobit( e_DomainName ) )
  532. {
  533. if( t_pDCInfo->DomainName )
  534. {
  535. a_pInst->SetWCHARSplat( IDS_DomainName,
  536. t_pDCInfo->DomainName ) ;
  537. }
  538. }
  539. // DnsForestName
  540. if( a_dwProps & _tobit( e_DnsForestName ) )
  541. {
  542. if( t_pDCInfo->DnsForestName )
  543. {
  544. a_pInst->SetWCHARSplat( IDS_DnsForestName,
  545. t_pDCInfo->DnsForestName ) ;
  546. }
  547. }
  548. // DSPrimaryDomainControllerFlag
  549. if( a_dwProps & _tobit( e_DS_PDC_Flag ) )
  550. {
  551. a_pInst->Setbool( IDS_DS_PDC_Flag,
  552. (bool)(t_pDCInfo->Flags & DS_PDC_FLAG) ) ;
  553. }
  554. // DSWritableFlag
  555. if( a_dwProps & _tobit( e_DS_Writable_Flag ) )
  556. {
  557. a_pInst->Setbool( IDS_DS_Writable_Flag,
  558. (bool)(t_pDCInfo->Flags & DS_WRITABLE_FLAG) ) ;
  559. }
  560. // DSGlobalCatalogFlag
  561. if( a_dwProps & _tobit( e_DS_GC_Flag ) )
  562. {
  563. a_pInst->Setbool( IDS_DS_GC_Flag,
  564. (bool)(t_pDCInfo->Flags & DS_GC_FLAG) ) ;
  565. }
  566. // DSDirectoryServiceFlag
  567. if( a_dwProps & _tobit( e_DS_DS_Flag ) )
  568. {
  569. a_pInst->Setbool( IDS_DS_DS_Flag,
  570. (bool)(t_pDCInfo->Flags & DS_DS_FLAG) ) ;
  571. }
  572. // DSKerberosDistributionCenterFlag
  573. if( a_dwProps & _tobit( e_DS_KDC_Flag ) )
  574. {
  575. a_pInst->Setbool( IDS_DS_KDC_Flag,
  576. (bool)(t_pDCInfo->Flags & DS_KDC_FLAG) ) ;
  577. }
  578. // DSTimeServiceFlag
  579. if( a_dwProps & _tobit( e_DS_Timeserv_Flag ) )
  580. {
  581. a_pInst->Setbool( IDS_DS_Timeserv_Flag,
  582. (bool)(t_pDCInfo->Flags & DS_TIMESERV_FLAG) ) ;
  583. }
  584. // DSDnsControllerFlag
  585. if( a_dwProps & _tobit( e_DS_DNS_Controller_Flag ) )
  586. {
  587. a_pInst->Setbool( IDS_DS_DNS_Controller_Flag,
  588. (bool)(t_pDCInfo->Flags & DS_DNS_CONTROLLER_FLAG) ) ;
  589. }
  590. // DSDnsDomainFlag
  591. if( a_dwProps & _tobit( e_DS_DNS_Domain_Flag ) )
  592. {
  593. a_pInst->Setbool( IDS_DS_DNS_Domain_Flag,
  594. (bool)(t_pDCInfo->Flags & DS_DNS_DOMAIN_FLAG) ) ;
  595. }
  596. // DSDnsForestFlag
  597. if( a_dwProps & _tobit( e_DS_DNS_Forest_Flag ) )
  598. {
  599. a_pInst->Setbool( IDS_DS_DNS_Forest_Flag,
  600. (bool)(t_pDCInfo->Flags & DS_DNS_FOREST_FLAG) ) ;
  601. }
  602. // DcSiteName
  603. if( a_dwProps & _tobit( e_DcSiteName ) )
  604. {
  605. if( t_pDCInfo->DcSiteName )
  606. {
  607. a_pInst->SetWCHARSplat( IDS_DcSiteName,
  608. t_pDCInfo->DcSiteName ) ;
  609. }
  610. }
  611. // ClientSiteName
  612. if( a_dwProps & _tobit( e_ClientSiteName ) )
  613. {
  614. if( t_pDCInfo->ClientSiteName )
  615. {
  616. a_pInst->SetWCHARSplat( IDS_ClientSiteName,
  617. t_pDCInfo->ClientSiteName ) ;
  618. }
  619. }
  620. t_hResult = WBEM_S_NO_ERROR ;
  621. }
  622. else if( ERROR_NOT_ENOUGH_MEMORY == t_dwNetApiResult )
  623. {
  624. t_hResult = WBEM_E_OUT_OF_MEMORY ;
  625. }
  626. else
  627. {
  628. t_hResult = WBEM_E_NOT_FOUND ;
  629. }
  630. }
  631. // CIM_System follows
  632. // CreationClassName
  633. if( a_dwProps & _tobit( e_CreationClassName ) )
  634. {
  635. a_pInst->SetWCHARSplat( IDS_CreationClassName,
  636. PROPSET_NAME_NTDOMAIN ) ;
  637. }
  638. // CIM_System::Name is the key
  639. // TODO:
  640. // e_NameFormat, IDS_NameFormat
  641. // e_PrimaryOwnerContact, IDS_PrimaryOwnerContact
  642. // e_PrimaryOwnerName, IDS_PrimaryOwnerName
  643. // e_Roles, IDS_Roles
  644. // CIM_ManagedSystemElement follows
  645. // Caption
  646. if( a_dwProps & _tobit( e_Caption ) )
  647. {
  648. // REVIEW:
  649. a_pInst->SetWCHARSplat( IDS_Caption,
  650. (wchar_t*)a_bstrDomainName ) ;
  651. }
  652. // Description
  653. if( a_dwProps & _tobit( e_Description ) )
  654. {
  655. // REVIEW:
  656. a_pInst->SetWCHARSplat( IDS_Description,
  657. (wchar_t*)a_bstrDomainName ) ;
  658. }
  659. // Status
  660. if( a_dwProps & _tobit( e_Status ) )
  661. {
  662. if( NO_ERROR == t_dwNetApiResult )
  663. {
  664. // REVIEW:
  665. a_pInst->SetCHString ( IDS_Status , IDS_STATUS_OK ) ;
  666. }
  667. else
  668. {
  669. // REVIEW:
  670. a_pInst->SetCHString ( IDS_Status , IDS_STATUS_Unknown ) ;
  671. }
  672. }
  673. // TODO:
  674. // e_InstallDate, IDS_InstallDate
  675. }
  676. catch(...)
  677. {
  678. if( t_pDCInfo )
  679. {
  680. a_rNetAPI.NetApiBufferFree( t_pDCInfo ) ;
  681. }
  682. throw;
  683. }
  684. if( t_pDCInfo )
  685. {
  686. a_rNetAPI.NetApiBufferFree( t_pDCInfo ) ;
  687. t_pDCInfo = NULL ;
  688. }
  689. }
  690. else // NULL domain
  691. {
  692. t_hResult = WBEM_E_NOT_FOUND ;
  693. }
  694. return t_hResult ;
  695. }
  696. #endif