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.

381 lines
9.4 KiB

  1. /////////////////////////////////////////////////////////////////////
  2. //
  3. // CopyRight ( c ) 1999 Microsoft Corporation
  4. //
  5. // Module Name: dnsdomain.cpp
  6. //
  7. // Description:
  8. // Implementation of CDnsDomain class
  9. //
  10. // Author:
  11. // Henry Wang ( henrywa ) March 8, 2000
  12. //
  13. //
  14. //////////////////////////////////////////////////////////////////////
  15. #include "DnsWmi.h"
  16. /////////////////////////////////////////////////////////////////////////////
  17. //++
  18. //
  19. // Description:
  20. // create an instance of CDnsDomain
  21. //
  22. // Arguments:
  23. // wszName [IN] class name
  24. // pNamespace [IN] wmi namespace
  25. // szType [IN] child class name of resource record class
  26. //
  27. // Return Value:
  28. // WBEM_S_NO_ERROR
  29. //
  30. //--
  31. /////////////////////////////////////////////////////////////////////////////
  32. CDnsBase*
  33. CDnsDomain::CreateThis(
  34. const WCHAR * wszName, //class name
  35. CWbemServices * pNamespace, //namespace
  36. const char * szType //str type id
  37. )
  38. {
  39. return new CDnsDomain(wszName, pNamespace);
  40. }
  41. CDnsDomain::CDnsDomain()
  42. {
  43. }
  44. CDnsDomain::CDnsDomain(
  45. const WCHAR * wszName,
  46. CWbemServices * pNamespace)
  47. :CDnsBase(wszName, pNamespace)
  48. {
  49. }
  50. CDnsDomain::~CDnsDomain()
  51. {
  52. }
  53. /////////////////////////////////////////////////////////////////////////////
  54. //++
  55. //
  56. // Description:
  57. // call back function to enum domain instance.
  58. // if pNode represents a domain node, create a wmi domain instance
  59. //
  60. // Arguments:
  61. // ParentDomain [IN] Parent domain
  62. // pFilter [IN] pointer to object that contains the criteria to filter
  63. // which instance should be send to wmi
  64. // not used here
  65. // pNode [IN] pointer to Dns Rpc Node object
  66. // pClass [IN] wmi class used to create instance
  67. // InstMgr [IN] a ref to Instance manager obj that is
  68. // responsible to send mutiple instance
  69. // back to wmi at once
  70. //
  71. // Return Value:
  72. // WBEM_S_NO_ERROR
  73. //
  74. //--
  75. /////////////////////////////////////////////////////////////////////////////
  76. SCODE CDnsDomain::InstanceFilter(
  77. CDomainNode & ParentDomain,
  78. PVOID pFilter,
  79. CDnsRpcNode * pNode,
  80. IWbemClassObject * pClass,
  81. CWbemInstanceMgr & InstMgr )
  82. {
  83. if (!pNode->IsDomainNode())
  84. return 0;
  85. CWbemClassObject NewInst;
  86. CDnsWrap& dns = CDnsWrap::DnsObject();
  87. pClass->SpawnInstance(0, &NewInst);
  88. //setting server name
  89. NewInst.SetProperty(
  90. dns.GetServerName(),
  91. PVD_DOMAIN_SERVER_NAME);
  92. // setting container name
  93. NewInst.SetProperty(
  94. ParentDomain.wstrZoneName,
  95. PVD_DOMAIN_CONTAINER_NAME
  96. );
  97. // concatinate domain name
  98. wstring wstrParentFQDN = ParentDomain.wstrNodeName;
  99. wstring wstrFQDN = pNode->GetNodeName();
  100. wstrFQDN += PVD_DNS_LOCAL_SERVER + wstrParentFQDN;
  101. // setting domain name
  102. NewInst.SetProperty(
  103. wstrFQDN,
  104. PVD_DOMAIN_FQDN);
  105. InstMgr.Indicate(NewInst.data());
  106. return WBEM_S_NO_ERROR;
  107. }
  108. /////////////////////////////////////////////////////////////////////////////
  109. //++
  110. //
  111. // Description:
  112. // enum instances of dns domain
  113. //
  114. // Arguments:
  115. // lFlags [IN] WMI flag
  116. // pCtx [IN] WMI context
  117. // pHandler [IN] WMI sink pointer
  118. //
  119. // Return Value:
  120. // WBEM_S_NO_ERROR
  121. //
  122. //--
  123. /////////////////////////////////////////////////////////////////////////////
  124. SCODE CDnsDomain::EnumInstance(
  125. long lFlags,
  126. IWbemContext * pCtx,
  127. IWbemObjectSink * pHandler)
  128. {
  129. // Get all zones
  130. list<CDomainNode> objList, domainList;
  131. CDnsWrap& dns = CDnsWrap::DnsObject();
  132. SCODE sc = dns.dnsEnumDomainForServer(&objList);
  133. list<CDomainNode>::iterator i;
  134. CWbemInstanceMgr InstMgr(
  135. pHandler,
  136. 100);
  137. for(i=objList.begin(); i!=objList.end(); ++i)
  138. {
  139. sc = dns.dnsEnumRecordsForDomainEx(
  140. *i,
  141. NULL,
  142. &InstanceFilter,
  143. TRUE,
  144. DNS_TYPE_ALL,
  145. DNS_RPC_VIEW_ALL_DATA,
  146. m_pClass,
  147. InstMgr);
  148. // Zones are domains, let's set them
  149. CWbemClassObject NewInst;
  150. if( SUCCEEDED ( m_pClass->SpawnInstance(0, &NewInst) ) )
  151. {
  152. wstring wstrNodeName = i->wstrNodeName;
  153. NewInst.SetProperty(
  154. dns.GetServerName(),
  155. PVD_DOMAIN_SERVER_NAME);
  156. NewInst.SetProperty(
  157. i->wstrZoneName,
  158. PVD_DOMAIN_CONTAINER_NAME);
  159. if(! _wcsicmp(i->wstrZoneName.data(), PVD_DNS_ROOTHINTS) ||
  160. ! _wcsicmp(i->wstrZoneName.data(), PVD_DNS_CACHE) )
  161. wstrNodeName = i->wstrZoneName;
  162. NewInst.SetProperty(
  163. wstrNodeName,
  164. PVD_DOMAIN_FQDN);
  165. pHandler->Indicate(
  166. 1,
  167. &NewInst);
  168. }
  169. }
  170. return sc;
  171. }
  172. /////////////////////////////////////////////////////////////////////////////
  173. //++
  174. //
  175. // Description:
  176. // retrieve domain object pointed by the given object path
  177. //
  178. // Arguments:
  179. // ObjectPath [IN] object path to object
  180. // lFlags [IN] WMI flag
  181. // pCtx [IN] WMI context
  182. // pHandler [IN] WMI sink pointer
  183. //
  184. // Return Value:
  185. // WBEM_S_NO_ERROR
  186. //
  187. //--
  188. /////////////////////////////////////////////////////////////////////////////
  189. SCODE
  190. CDnsDomain::GetObject(
  191. CObjPath & ObjectPath,
  192. long lFlags,
  193. IWbemContext * pCtx,
  194. IWbemObjectSink * pHandler)
  195. {
  196. // validate input
  197. wstring wstrServerName =
  198. ObjectPath.GetStringValueForProperty(
  199. PVD_DOMAIN_SERVER_NAME);
  200. if( wstrServerName.empty() ||
  201. ObjectPath.GetStringValueForProperty(
  202. PVD_DOMAIN_CONTAINER_NAME).empty() ||
  203. ObjectPath.GetStringValueForProperty(PVD_DOMAIN_FQDN).empty()
  204. )
  205. {
  206. return WBEM_E_INVALID_PARAMETER;
  207. }
  208. CDnsWrap& dns = CDnsWrap::DnsObject();
  209. // dww - 6/14/99
  210. // Changed to make see if ValidateServerName does not return WBEM_S_NO_ERROR.
  211. //
  212. if(WBEM_S_NO_ERROR != dns.ValidateServerName(wstrServerName.data()))
  213. return WBEM_E_INVALID_PARAMETER;
  214. SCODE sc = dns.dnsGetDomain(
  215. ObjectPath,
  216. m_pClass,
  217. pHandler);
  218. return sc;
  219. }
  220. /////////////////////////////////////////////////////////////////////////////
  221. //++
  222. //
  223. // Description:
  224. // execute methods defined for domain class in the mof
  225. //
  226. // Arguments:
  227. // ObjPath [IN] pointing to the object that the
  228. // method should be performed on
  229. // wzMethodName [IN] name of the method to be invoked
  230. // lFlags [IN] WMI flag
  231. // pInParams [IN] Input parameters for the method
  232. // pHandler [IN] WMI sink pointer
  233. //
  234. // Return Value:
  235. // WBEM_S_NO_ERROR
  236. // WBEM_E_INVALID_PARAMETER
  237. //
  238. //--
  239. /////////////////////////////////////////////////////////////////////////////
  240. SCODE
  241. CDnsDomain::ExecuteMethod(
  242. CObjPath & ObjPath,
  243. WCHAR * wzMethodName,
  244. long lFlag,
  245. IWbemClassObject * pInArgs,
  246. IWbemObjectSink * pHandler)
  247. {
  248. CDnsWrap& dns = CDnsWrap::DnsObject();
  249. wstring wstrDomainName = ObjPath.GetStringValueForProperty(
  250. PVD_DOMAIN_FQDN);
  251. // dww - 6/14/99
  252. // Added the GetDistinguishedName method in the CDnsDomain class.
  253. //
  254. if(_wcsicmp(
  255. wzMethodName,
  256. PVD_MTH_ZONE_GETDISTINGUISHEDNAME) == 0)
  257. {
  258. wstring wstrName;
  259. CWbemClassObject OutParams, OutClass, Class ;
  260. HRESULT hr;
  261. dns.dnsDsZoneName(wstrName, wstrDomainName);
  262. BSTR ClassName=NULL;
  263. ClassName = AllocBstr(PVD_CLASS_DOMAIN);
  264. hr = m_pNamespace->GetObject(ClassName, 0, 0, &Class, NULL);
  265. SysFreeString(ClassName);
  266. if ( SUCCEEDED ( hr ) )
  267. {
  268. Class.GetMethod( wzMethodName, 0, NULL, &OutClass);
  269. OutClass.SpawnInstance(0, &OutParams);
  270. OutParams.SetProperty(wstrName, PVD_DNS_RETURN_VALUE);
  271. hr = pHandler->Indicate(1, &OutParams);
  272. }
  273. return hr;
  274. }
  275. return S_OK;
  276. }
  277. /////////////////////////////////////////////////////////////////////////////
  278. //++
  279. //
  280. // Description:
  281. // save this instance
  282. //
  283. // Arguments:
  284. // InstToPut [IN] WMI object to be saved
  285. // lFlags [IN] WMI flag
  286. // pCtx [IN] WMI context
  287. // pHandler [IN] WMI sink pointer
  288. //
  289. // Return Value:
  290. //
  291. //
  292. //--
  293. /////////////////////////////////////////////////////////////////////////////
  294. SCODE CDnsDomain::PutInstance(
  295. IWbemClassObject * pInst ,
  296. long lFlags,
  297. IWbemContext* pCtx ,
  298. IWbemObjectSink * pHandler)
  299. {
  300. return WBEM_S_NO_ERROR;
  301. };
  302. /////////////////////////////////////////////////////////////////////////////
  303. //++
  304. //
  305. // Description:
  306. // delete the object specified in ObjectPath
  307. //
  308. // Arguments:
  309. // ObjectPath [IN] ObjPath for the instance to be deleted
  310. // lFlags [IN] WMI flag
  311. // pCtx [IN] WMI context
  312. // pHandler [IN] WMI sink pointer
  313. //
  314. // Return Value:
  315. // WBEM_S_NO_ERROR
  316. //
  317. //--
  318. /////////////////////////////////////////////////////////////////////////////
  319. SCODE
  320. CDnsDomain::DeleteInstance(
  321. CObjPath & ObjectPath,
  322. long lFlags,
  323. IWbemContext * pCtx,
  324. IWbemObjectSink * pHandler)
  325. {
  326. wstring wstrContainer = ObjectPath.GetStringValueForProperty(
  327. PVD_DOMAIN_CONTAINER_NAME);
  328. string strContainer;
  329. WcharToString(
  330. wstrContainer.data(),
  331. strContainer);
  332. wstring wstrDomain = ObjectPath.GetStringValueForProperty(PVD_DOMAIN_FQDN);
  333. string strDomain;
  334. WcharToString(
  335. wstrDomain.data(),
  336. strContainer);
  337. CDnsWrap& dns = CDnsWrap::DnsObject();
  338. SCODE sc = dns.dnsDeleteDomain(
  339. (char*)strContainer.data(),
  340. (char*) strDomain.data());
  341. pHandler->SetStatus(
  342. 0,
  343. sc,
  344. NULL,
  345. NULL);
  346. return WBEM_S_NO_ERROR;
  347. }