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.

375 lines
11 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. // concatinate domain name
  97. wstring wstrParentFQDN = ParentDomain.wstrNodeName;
  98. wstring wstrFQDN = pNode->GetNodeName();
  99. wstrFQDN += PVD_DNS_LOCAL_SERVER + wstrParentFQDN;
  100. // setting domain name
  101. NewInst.SetProperty(
  102. wstrFQDN,
  103. PVD_DOMAIN_FQDN );
  104. InstMgr.Indicate( NewInst.data() );
  105. return WBEM_S_NO_ERROR;
  106. }
  107. /////////////////////////////////////////////////////////////////////////////
  108. //++
  109. //
  110. // Description:
  111. // enum instances of dns domain
  112. //
  113. // Arguments:
  114. // lFlags [IN] WMI flag
  115. // pCtx [IN] WMI context
  116. // pHandler [IN] WMI sink pointer
  117. //
  118. // Return Value:
  119. // WBEM_S_NO_ERROR
  120. //
  121. //--
  122. /////////////////////////////////////////////////////////////////////////////
  123. SCODE CDnsDomain::EnumInstance(
  124. long lFlags,
  125. IWbemContext * pCtx,
  126. IWbemObjectSink * pHandler)
  127. {
  128. // Get all zones
  129. list<CDomainNode> objList, domainList;
  130. CDnsWrap& dns = CDnsWrap::DnsObject();
  131. SCODE sc = dns.dnsEnumDomainForServer(&objList);
  132. list<CDomainNode>::iterator i;
  133. CWbemInstanceMgr InstMgr(
  134. pHandler,
  135. 100);
  136. for(i=objList.begin(); i!=objList.end(); ++i)
  137. {
  138. sc = dns.dnsEnumRecordsForDomainEx(
  139. *i,
  140. NULL,
  141. &InstanceFilter,
  142. TRUE,
  143. DNS_TYPE_ALL,
  144. DNS_RPC_VIEW_ALL_DATA,
  145. m_pClass,
  146. InstMgr);
  147. // Zones are domains, let's set them
  148. CWbemClassObject NewInst;
  149. if( SUCCEEDED ( m_pClass->SpawnInstance(0, &NewInst) ) )
  150. {
  151. wstring wstrNodeName = i->wstrNodeName;
  152. NewInst.SetProperty(
  153. dns.GetServerName(),
  154. PVD_DOMAIN_SERVER_NAME);
  155. NewInst.SetProperty(
  156. i->wstrZoneName,
  157. PVD_DOMAIN_CONTAINER_NAME);
  158. if(! _wcsicmp(i->wstrZoneName.data(), PVD_DNS_ROOTHINTS) ||
  159. ! _wcsicmp(i->wstrZoneName.data(), PVD_DNS_CACHE) )
  160. wstrNodeName = i->wstrZoneName;
  161. NewInst.SetProperty(
  162. wstrNodeName,
  163. PVD_DOMAIN_FQDN);
  164. pHandler->Indicate(
  165. 1,
  166. &NewInst);
  167. }
  168. }
  169. return sc;
  170. }
  171. /////////////////////////////////////////////////////////////////////////////
  172. //++
  173. //
  174. // Description:
  175. // retrieve domain object pointed by the given object path
  176. //
  177. // Arguments:
  178. // ObjectPath [IN] object path to object
  179. // lFlags [IN] WMI flag
  180. // pCtx [IN] WMI context
  181. // pHandler [IN] WMI sink pointer
  182. //
  183. // Return Value:
  184. // WBEM_S_NO_ERROR
  185. //
  186. //--
  187. /////////////////////////////////////////////////////////////////////////////
  188. SCODE
  189. CDnsDomain::GetObject(
  190. CObjPath & ObjectPath,
  191. long lFlags,
  192. IWbemContext * pCtx,
  193. IWbemObjectSink * pHandler)
  194. {
  195. // validate input
  196. wstring wstrServerName =
  197. ObjectPath.GetStringValueForProperty(
  198. PVD_DOMAIN_SERVER_NAME);
  199. if( wstrServerName.empty() ||
  200. ObjectPath.GetStringValueForProperty(
  201. PVD_DOMAIN_CONTAINER_NAME).empty() ||
  202. ObjectPath.GetStringValueForProperty(PVD_DOMAIN_FQDN).empty()
  203. )
  204. {
  205. return WBEM_E_INVALID_PARAMETER;
  206. }
  207. CDnsWrap& dns = CDnsWrap::DnsObject();
  208. if(WBEM_S_NO_ERROR != dns.ValidateServerName(wstrServerName.data()))
  209. return WBEM_E_INVALID_PARAMETER;
  210. SCODE sc = dns.dnsGetDomain(
  211. ObjectPath,
  212. m_pClass,
  213. pHandler);
  214. return sc;
  215. }
  216. /////////////////////////////////////////////////////////////////////////////
  217. //++
  218. //
  219. // Description:
  220. // execute methods defined for domain class in the mof
  221. //
  222. // Arguments:
  223. // ObjPath [IN] pointing to the object that the
  224. // method should be performed on
  225. // wzMethodName [IN] name of the method to be invoked
  226. // lFlags [IN] WMI flag
  227. // pInParams [IN] Input parameters for the method
  228. // pHandler [IN] WMI sink pointer
  229. //
  230. // Return Value:
  231. // WBEM_S_NO_ERROR
  232. // WBEM_E_INVALID_PARAMETER
  233. //
  234. //--
  235. /////////////////////////////////////////////////////////////////////////////
  236. SCODE
  237. CDnsDomain::ExecuteMethod(
  238. CObjPath & ObjPath,
  239. WCHAR * wzMethodName,
  240. long lFlag,
  241. IWbemClassObject * pInArgs,
  242. IWbemObjectSink * pHandler)
  243. {
  244. CDnsWrap& dns = CDnsWrap::DnsObject();
  245. wstring wstrDomainName = ObjPath.GetStringValueForProperty(
  246. PVD_DOMAIN_FQDN);
  247. if( _wcsicmp(
  248. wzMethodName,
  249. PVD_MTH_ZONE_GETDISTINGUISHEDNAME) == 0 )
  250. {
  251. wstring wstrName;
  252. CWbemClassObject OutParams, OutClass, Class ;
  253. HRESULT hr;
  254. dns.dnsDsZoneName(wstrName, wstrDomainName);
  255. BSTR ClassName=NULL;
  256. ClassName = AllocBstr(PVD_CLASS_DOMAIN);
  257. hr = m_pNamespace->GetObject(ClassName, 0, 0, &Class, NULL);
  258. SysFreeString(ClassName);
  259. if ( SUCCEEDED ( hr ) )
  260. {
  261. Class.GetMethod( wzMethodName, 0, NULL, &OutClass);
  262. OutClass.SpawnInstance(0, &OutParams);
  263. OutParams.SetProperty(wstrName, PVD_DNS_RETURN_VALUE);
  264. hr = pHandler->Indicate(1, &OutParams);
  265. }
  266. return hr;
  267. }
  268. return S_OK;
  269. }
  270. /////////////////////////////////////////////////////////////////////////////
  271. //++
  272. //
  273. // Description:
  274. // save this instance
  275. //
  276. // Arguments:
  277. // InstToPut [IN] WMI object to be saved
  278. // lFlags [IN] WMI flag
  279. // pCtx [IN] WMI context
  280. // pHandler [IN] WMI sink pointer
  281. //
  282. // Return Value:
  283. //
  284. //
  285. //--
  286. /////////////////////////////////////////////////////////////////////////////
  287. SCODE CDnsDomain::PutInstance(
  288. IWbemClassObject * pInst ,
  289. long lFlags,
  290. IWbemContext* pCtx ,
  291. IWbemObjectSink * pHandler)
  292. {
  293. return WBEM_S_NO_ERROR;
  294. };
  295. /////////////////////////////////////////////////////////////////////////////
  296. //++
  297. //
  298. // Description:
  299. // delete the object specified in ObjectPath
  300. //
  301. // Arguments:
  302. // ObjectPath [IN] ObjPath for the instance to be deleted
  303. // lFlags [IN] WMI flag
  304. // pCtx [IN] WMI context
  305. // pHandler [IN] WMI sink pointer
  306. //
  307. // Return Value:
  308. // WBEM_S_NO_ERROR
  309. //
  310. //--
  311. /////////////////////////////////////////////////////////////////////////////
  312. SCODE
  313. CDnsDomain::DeleteInstance(
  314. CObjPath & ObjectPath,
  315. long lFlags,
  316. IWbemContext * pCtx,
  317. IWbemObjectSink * pHandler)
  318. {
  319. wstring wstrContainer = ObjectPath.GetStringValueForProperty(
  320. PVD_DOMAIN_CONTAINER_NAME);
  321. string strContainer;
  322. WcharToString(
  323. wstrContainer.data(),
  324. strContainer);
  325. wstring wstrDomain = ObjectPath.GetStringValueForProperty(PVD_DOMAIN_FQDN);
  326. string strDomain;
  327. WcharToString(
  328. wstrDomain.data(),
  329. strContainer);
  330. CDnsWrap& dns = CDnsWrap::DnsObject();
  331. SCODE sc = dns.dnsDeleteDomain(
  332. (char*)strContainer.data(),
  333. (char*) strDomain.data());
  334. pHandler->SetStatus(
  335. 0,
  336. sc,
  337. NULL,
  338. NULL);
  339. return WBEM_S_NO_ERROR;
  340. }