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.

206 lines
5.3 KiB

  1. /////////////////////////////////////////////////////////////////////
  2. //
  3. // CopyRight ( c ) 1999 Microsoft Corporation
  4. //
  5. // Module Name: DnsDomainResourceRecordContainment.cpp
  6. //
  7. // Description:
  8. // Implementation of CDnsDomainResourceRecordContainment class
  9. //
  10. // Author:
  11. // Henry Wang ( henrywa ) March 8, 2000
  12. //
  13. //
  14. //////////////////////////////////////////////////////////////////////
  15. #include "DnsWmi.h"
  16. //////////////////////////////////////////////////////////////////////
  17. // Construction/Destruction
  18. //////////////////////////////////////////////////////////////////////
  19. CDnsBase*
  20. CDnsDomainResourceRecordContainment::CreateThis(
  21. const WCHAR * wszName, //class name
  22. CWbemServices * pNamespace, //namespace
  23. const char * szType //str type id
  24. )
  25. {
  26. return new CDnsDomainResourceRecordContainment(wszName, pNamespace);
  27. }
  28. CDnsDomainResourceRecordContainment::CDnsDomainResourceRecordContainment()
  29. {
  30. }
  31. CDnsDomainResourceRecordContainment::CDnsDomainResourceRecordContainment(
  32. const WCHAR* wszName,
  33. CWbemServices *pNamespace)
  34. :CDnsBase(wszName, pNamespace)
  35. {
  36. }
  37. CDnsDomainResourceRecordContainment::~CDnsDomainResourceRecordContainment()
  38. {
  39. }
  40. /////////////////////////////////////////////////////////////////////////////
  41. //++
  42. //
  43. //
  44. // Description:
  45. // enum instances of domain and record association
  46. //
  47. // Arguments:
  48. // lFlags [IN] WMI flag
  49. // pCtx [IN] WMI context
  50. // pHandler [IN] WMI sink pointer
  51. //
  52. // Return Value:
  53. // WBEM_S_NO_ERROR
  54. //
  55. //--
  56. /////////////////////////////////////////////////////////////////////////////
  57. SCODE
  58. CDnsDomainResourceRecordContainment::EnumInstance(
  59. long lFlags,
  60. IWbemContext * pCtx,
  61. IWbemObjectSink * pHandler)
  62. {
  63. list<CDomainNode> objList;
  64. CDnsWrap& dns = CDnsWrap::DnsObject();
  65. SCODE sc = dns.dnsEnumDomainForServer(&objList);
  66. list<CDomainNode>::iterator i;
  67. CWbemInstanceMgr InstMgr(
  68. pHandler);
  69. for(i=objList.begin(); i!=objList.end(); ++i)
  70. {
  71. sc = dns.dnsEnumRecordsForDomainEx(
  72. *i,
  73. NULL,
  74. InstanceFilter,
  75. TRUE,
  76. DNS_TYPE_ALL,
  77. DNS_RPC_VIEW_ALL_DATA,
  78. m_pClass,
  79. InstMgr);
  80. }
  81. return sc;
  82. }
  83. SCODE
  84. CDnsDomainResourceRecordContainment::GetObject(
  85. CObjPath & ObjectPath,
  86. long lFlags,
  87. IWbemContext * pCtx,
  88. IWbemObjectSink * pHandler
  89. )
  90. {
  91. return WBEM_E_NOT_SUPPORTED;
  92. }
  93. SCODE CDnsDomainResourceRecordContainment::ExecuteMethod(
  94. CObjPath & objPath,
  95. WCHAR * wzMethodName,
  96. long lFlag,
  97. IWbemClassObject * pInArgs,
  98. IWbemObjectSink * pHandler
  99. )
  100. {
  101. return WBEM_E_NOT_SUPPORTED;
  102. }
  103. /////////////////////////////////////////////////////////////////////////////
  104. //++
  105. //
  106. // Description:
  107. // call back function to enum domain and record association instance.
  108. // if pNode represents a domain node, create a wmi domain instance
  109. //
  110. // Arguments:
  111. // ParentDomain [IN] Parent domain
  112. // pFilter [IN] pointer to object that contains the criteria to filter
  113. // which instance should be send to wmi
  114. // not used here
  115. // pNode [IN] pointer to Dns Rpc Node object
  116. // pClass [IN] wmi class used to create instance
  117. // InstMgr [IN] a ref to Instance manager obj that is
  118. // responsible to send mutiple instance
  119. // back to wmi at once
  120. //
  121. // Return Value:
  122. // WBEM_S_NO_ERROR
  123. //
  124. //--
  125. /////////////////////////////////////////////////////////////////////////////
  126. SCODE CDnsDomainResourceRecordContainment::InstanceFilter(
  127. CDomainNode & ParentDomain,
  128. PVOID pFilter,
  129. CDnsRpcNode * pNode,
  130. IWbemClassObject * pClass,
  131. CWbemInstanceMgr & InstMgr
  132. )
  133. {
  134. if (pNode->IsDomainNode())
  135. return 0;
  136. // CObjPath* pFilterObj = (CObjPath*) pFilter;
  137. CDnsWrap& dns = CDnsWrap::DnsObject();
  138. CObjPath objPathParent;
  139. objPathParent.SetClass(PVD_CLASS_DOMAIN);
  140. objPathParent.AddProperty(
  141. PVD_DOMAIN_SERVER_NAME,
  142. dns.GetServerName().data()
  143. );
  144. objPathParent.AddProperty(
  145. PVD_DOMAIN_CONTAINER_NAME,
  146. ParentDomain.wstrZoneName.data()
  147. );
  148. objPathParent.AddProperty(
  149. PVD_DOMAIN_FQDN,
  150. ParentDomain.wstrNodeName.data()
  151. );
  152. wstring wstrOwner = pNode->GetNodeName();
  153. if(!wstrOwner.empty())
  154. wstrOwner += PVD_DNS_LOCAL_SERVER + ParentDomain.wstrNodeName;
  155. else
  156. wstrOwner = ParentDomain.wstrNodeName;
  157. CDnsRpcRecord* p;
  158. while( (p = pNode->GetNextRecord()) != NULL )
  159. {
  160. auto_ptr<CDnsRpcRecord> pRec(p);
  161. CObjPath objPathChild;
  162. // populate rdata section
  163. pRec->GetObjectPath(
  164. dns.GetServerName(),
  165. ParentDomain.wstrZoneName,
  166. ParentDomain.wstrNodeName,
  167. wstrOwner,
  168. objPathChild);
  169. CWbemClassObject NewInst;
  170. pClass->SpawnInstance(0, &NewInst);
  171. // set domain ref
  172. NewInst.SetProperty(
  173. objPathParent.GetObjectPathString(),
  174. PVD_ASSOC_PARENT
  175. );
  176. // set record ref
  177. NewInst.SetProperty(
  178. objPathChild.GetObjectPathString(),
  179. PVD_ASSOC_CHILD
  180. );
  181. InstMgr.Indicate(NewInst.data());
  182. }
  183. return WBEM_S_NO_ERROR;
  184. }