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.

519 lines
13 KiB

  1. /////////////////////////////////////////////////////////////////////
  2. //
  3. // CopyRight ( c ) 1999 Microsoft Corporation
  4. //
  5. // Module Name: dnszone.cpp
  6. //
  7. // Description:
  8. // Implementation of CDnsZone class
  9. //
  10. // Author:
  11. // Henry Wang ( henrywa ) March 8, 2000
  12. //
  13. //
  14. //////////////////////////////////////////////////////////////////////
  15. #include "DnsWmi.h"
  16. //////////////////////////////////////////////////////////////////////
  17. // Construction/Destruction
  18. //////////////////////////////////////////////////////////////////////
  19. /////////////////////////////////////////////////////////////////////////////
  20. //++
  21. //
  22. // Description:
  23. // create an instance of CDnsZone
  24. //
  25. // Arguments:
  26. // wszName [IN] class name
  27. // pNamespace [IN] wmi namespace
  28. // szType [IN] child class name of resource record class
  29. //
  30. // Return Value:
  31. // WBEM_S_NO_ERROR
  32. //
  33. //--
  34. /////////////////////////////////////////////////////////////////////////////
  35. CDnsBase*
  36. CDnsZone::CreateThis(
  37. const WCHAR * wszName,
  38. CWbemServices * pNamespace,
  39. const char * szType
  40. )
  41. {
  42. return new CDnsZone(wszName, pNamespace);
  43. }
  44. CDnsZone::CDnsZone()
  45. {
  46. }
  47. CDnsZone::CDnsZone(
  48. const WCHAR* wszName,
  49. CWbemServices *pNamespace)
  50. :CDnsBase(wszName, pNamespace)
  51. {
  52. }
  53. CDnsZone::~CDnsZone()
  54. {
  55. }
  56. /////////////////////////////////////////////////////////////////////////////
  57. //++
  58. //
  59. // Description:
  60. // enum instances of dns zone
  61. //
  62. // Arguments:
  63. // lFlags [IN] WMI flag
  64. // pCtx [IN] WMI context
  65. // pHandler [IN] WMI sink pointer
  66. //
  67. // Return Value:
  68. // WBEM_S_NO_ERROR
  69. //
  70. //--
  71. /////////////////////////////////////////////////////////////////////////////
  72. SCODE
  73. CDnsZone::EnumInstance(
  74. long lFlags,
  75. IWbemContext * pCtx,
  76. IWbemObjectSink * pHandler)
  77. {
  78. list<CDomainNode> opList;
  79. list<CDomainNode>::iterator i;
  80. SCODE sc;
  81. CDnsWrap& dns = CDnsWrap::DnsObject();
  82. sc = dns.dnsEnumDomainForServer(&opList);
  83. if (FAILED(sc))
  84. {
  85. return sc;
  86. }
  87. for(i=opList.begin(); i!=opList.end(); ++i)
  88. {
  89. if(_wcsicmp(i->wstrZoneName.data(), PVD_DNS_CACHE) &&
  90. _wcsicmp(i->wstrZoneName.data(), PVD_DNS_ROOTHINTS) )
  91. {
  92. CWbemClassObject Inst;
  93. m_pClass->SpawnInstance(0, &Inst);
  94. sc = dns.dnsGetZone(
  95. dns.GetServerName().data(),
  96. i->wstrZoneName.data(),
  97. Inst,
  98. pHandler);
  99. if ( SUCCEEDED ( sc ) )
  100. {
  101. pHandler->Indicate(1, &Inst);
  102. }
  103. }
  104. }
  105. return sc;
  106. }
  107. /////////////////////////////////////////////////////////////////////////////
  108. //++
  109. //
  110. // Description:
  111. // retrieve record object pointed by the given object path
  112. //
  113. // Arguments:
  114. // ObjectPath [IN] object path to object
  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
  125. CDnsZone::GetObject(
  126. CObjPath & ObjectPath,
  127. long lFlags,
  128. IWbemContext * pCtx,
  129. IWbemObjectSink * pHandler)
  130. {
  131. DBG_FN( "CDnsZone::GetObject" )
  132. wstring wstrZone = ObjectPath.GetStringValueForProperty(
  133. PVD_DOMAIN_CONTAINER_NAME);
  134. wstring wstrNode = ObjectPath.GetStringValueForProperty(
  135. PVD_DOMAIN_FQDN);
  136. DNS_DEBUG( INSTPROV, (
  137. "%s: zone %S\n", fn, wstrNode.c_str() ));
  138. // incase of zone, container name and fqdn are same
  139. // roothints and cache are managed by roothints and cache class
  140. if( (_wcsicmp(wstrZone.data(), wstrNode.data()) != 0 ) ||
  141. _wcsicmp(wstrZone.data(), PVD_DNS_CACHE) == 0 ||
  142. _wcsicmp(wstrZone.data(), PVD_DNS_ROOTHINTS) ==0 )
  143. {
  144. return WBEM_S_NO_ERROR;
  145. }
  146. CWbemClassObject Inst;
  147. m_pClass->SpawnInstance(0, &Inst);
  148. CDnsWrap& dns = CDnsWrap::DnsObject();
  149. SCODE sc = dns.dnsGetZone(
  150. PVD_DNS_LOCAL_SERVER,
  151. ObjectPath.GetStringValueForProperty(PVD_DOMAIN_CONTAINER_NAME).data(),
  152. Inst,
  153. pHandler);
  154. if( SUCCEEDED ( sc ) )
  155. {
  156. pHandler->Indicate(1, &Inst);
  157. }
  158. return sc;
  159. }
  160. /////////////////////////////////////////////////////////////////////////////
  161. //++
  162. //
  163. // Description:
  164. // save this instance
  165. //
  166. // Arguments:
  167. // InstToPut [IN] WMI object to be saved
  168. // lFlags [IN] WMI flag
  169. // pCtx [IN] WMI context
  170. // pHandler [IN] WMI sink pointer
  171. //
  172. // Return Value:
  173. //
  174. //
  175. //--
  176. /////////////////////////////////////////////////////////////////////////////
  177. SCODE
  178. CDnsZone::PutInstance(
  179. IWbemClassObject * pInst ,
  180. long lFlags,
  181. IWbemContext* pCtx ,
  182. IWbemObjectSink * pHandler)
  183. {
  184. DBG_FN( "CDnsZone::PutInstance" )
  185. DNS_DEBUG( INSTPROV, (
  186. "%s: pInst=%p\n", fn, pInst ));
  187. CDnsWrap& dns = CDnsWrap::DnsObject();
  188. CWbemClassObject Inst(pInst);
  189. return dns.dnsZonePut(Inst);
  190. };
  191. /////////////////////////////////////////////////////////////////////////////
  192. //++
  193. //
  194. // Description:
  195. // delete the object specified in ObjectPath
  196. //
  197. // Arguments:
  198. // ObjectPath [IN] ObjPath for the instance to be deleted
  199. // lFlags [IN] WMI flag
  200. // pCtx [IN] WMI context
  201. // pHandler [IN] WMI sink pointer
  202. //
  203. // Return Value:
  204. // WBEM_S_NO_ERROR
  205. //
  206. //--
  207. /////////////////////////////////////////////////////////////////////////////
  208. SCODE
  209. CDnsZone::DeleteInstance(
  210. CObjPath & ObjectPath,
  211. long lFlags,
  212. IWbemContext * pCtx,
  213. IWbemObjectSink * pHandler)
  214. {
  215. CDnsWrap& dns = CDnsWrap::DnsObject();
  216. SCODE sc = dns.dnsDeleteZone(ObjectPath);
  217. pHandler->SetStatus(
  218. 0,
  219. sc,
  220. NULL,
  221. NULL);
  222. return sc;
  223. }
  224. /////////////////////////////////////////////////////////////////////////////
  225. //++
  226. //
  227. // Description:
  228. // execute methods defined in the mof
  229. //
  230. // Arguments:
  231. // ObjPath [IN] pointing to the object that the
  232. // method should be performed on
  233. // wzMethodName [IN] name of the method to be invoked
  234. // lFlags [IN] WMI flag
  235. // pInParams [IN] Input parameters for the method
  236. // pHandler [IN] WMI sink pointer
  237. //
  238. // Return Value:
  239. // WBEM_S_NO_ERROR
  240. // WBEM_E_INVALID_PARAMETER
  241. //
  242. //--
  243. /////////////////////////////////////////////////////////////////////////////
  244. SCODE
  245. CDnsZone::ExecuteMethod(
  246. CObjPath & ObjPath,
  247. WCHAR * wzMethodName,
  248. long lFlag,
  249. IWbemClassObject * pInArgs,
  250. IWbemObjectSink * pHandler)
  251. {
  252. DBG_FN( "CDnsZone::ExecuteMethod" )
  253. CDnsWrap& dns = CDnsWrap::DnsObject();
  254. wstring wstrZoneName = ObjPath.GetStringValueForProperty(
  255. PVD_DOMAIN_CONTAINER_NAME);
  256. string strZoneName;
  257. WcharToString(wstrZoneName.data(), strZoneName);
  258. SCODE sc;
  259. if(_wcsicmp(wzMethodName, PVD_MTH_ZONE_PAUSEZONE) == 0)
  260. {
  261. //sc = dns.dnsPauseZone(strZoneName.data());
  262. sc = dns.dnsOperation(
  263. strZoneName,
  264. CDnsWrap::DNS_WRAP_PAUSE_ZONE);
  265. }
  266. else if(_wcsicmp(wzMethodName, PVD_MTH_ZONE_RESUMEZONE) == 0)
  267. {
  268. //sc = dns.dnsResumeZone(strZoneName.data());
  269. sc = dns.dnsOperation(
  270. strZoneName,
  271. CDnsWrap::DNS_WRAP_RESUME_ZONE);
  272. }
  273. else if(_wcsicmp(
  274. wzMethodName,
  275. PVD_MTH_ZONE_RELOADZONE ) == 0)
  276. {
  277. sc = dns.dnsOperation(
  278. strZoneName,
  279. CDnsWrap::DNS_WRAP_RELOAD_ZONE);
  280. }
  281. else if(_wcsicmp(
  282. wzMethodName,
  283. PVD_MTH_ZONE_FORCEREFRESH ) == 0)
  284. {
  285. sc = dns.dnsOperation(
  286. strZoneName,
  287. CDnsWrap::DNS_WRAP_REFRESH_SECONDARY);
  288. }
  289. else if(_wcsicmp(
  290. wzMethodName,
  291. PVD_MTH_ZONE_UPDATEFROMDS ) == 0)
  292. {
  293. sc = dns.dnsOperation(
  294. strZoneName,
  295. CDnsWrap::DNS_WRAP_DS_UPDATE );
  296. }
  297. else if(_wcsicmp(
  298. wzMethodName,
  299. PVD_MTH_ZONE_WRITEBACKZONETOFILE ) == 0)
  300. {
  301. sc = dns.dnsOperation(
  302. strZoneName,
  303. CDnsWrap::DNS_WRAP_WRITE_BACK_ZONE);
  304. }
  305. else if(_wcsicmp(
  306. wzMethodName,
  307. PVD_MTH_ZONE_CHANGEZONETYPE) == 0)
  308. {
  309. CWbemClassObject Inst(pInArgs);
  310. string strDataFile, strAdmin;
  311. DWORD *pIp=NULL, cIp=0, dwZoneType=-1;
  312. Inst.GetProperty(
  313. strDataFile,
  314. PVD_MTH_ZONE_ARG_DATAFILENAME);
  315. Inst.GetProperty(
  316. strAdmin,
  317. PVD_MTH_ZONE_ARG_ADMINEMAILNAME);
  318. Inst.GetProperty(
  319. &pIp,
  320. &cIp,
  321. PVD_MTH_ZONE_ARG_IPADDRARRAY);
  322. Inst.GetProperty(
  323. &dwZoneType,
  324. PVD_MTH_ZONE_ARG_ZONETYPE);
  325. sc = dns.dnsZoneChangeType(
  326. strZoneName,
  327. dwZoneType,
  328. strDataFile,
  329. strAdmin,
  330. pIp,
  331. cIp);
  332. delete [] pIp;
  333. }
  334. else if(_wcsicmp(
  335. wzMethodName,
  336. PVD_MTH_ZONE_CREATEZONE) == 0)
  337. {
  338. CWbemClassObject Inst(pInArgs);
  339. CWbemClassObject wcoOutArgs;
  340. CWbemClassObject wcoOutArgsClass;
  341. string strDataFile, strAdmin, strNewZoneName;
  342. strAdmin = "Admin";
  343. DWORD *pIp=NULL, cIp=0, dwZoneType=-1;
  344. sc = m_pClass->GetMethod(wzMethodName, 0, NULL, &wcoOutArgsClass );
  345. if( FAILED ( sc ) )
  346. {
  347. return sc;
  348. }
  349. wcoOutArgsClass.SpawnInstance(0, & wcoOutArgs);
  350. Inst.GetProperty(
  351. strDataFile,
  352. PVD_MTH_ZONE_ARG_DATAFILENAME);
  353. Inst.GetProperty(
  354. strAdmin,
  355. PVD_MTH_ZONE_ARG_ADMINEMAILNAME);
  356. Inst.GetProperty(
  357. &pIp,
  358. &cIp,
  359. PVD_MTH_ZONE_ARG_IPADDRARRAY);
  360. Inst.GetProperty(
  361. &dwZoneType,
  362. PVD_MTH_ZONE_ARG_ZONETYPE);
  363. Inst.GetProperty(
  364. strNewZoneName,
  365. PVD_MTH_ZONE_ARG_ZONENAME);
  366. sc = dns.dnsZoneCreate(
  367. strNewZoneName,
  368. dwZoneType,
  369. strDataFile,
  370. strAdmin,
  371. pIp,
  372. cIp);
  373. if ( SUCCEEDED ( sc ) )
  374. {
  375. CWbemClassObject wco;
  376. wstring wstrObjPath;
  377. m_pClass->SpawnInstance( 0 , & wco );
  378. wco.SetProperty(
  379. PVD_DNS_LOCAL_SERVER,
  380. PVD_DOMAIN_SERVER_NAME );
  381. wco.SetProperty(
  382. strNewZoneName.data(),
  383. PVD_DOMAIN_CONTAINER_NAME );
  384. wco.SetProperty(
  385. strNewZoneName.data(),
  386. PVD_DOMAIN_FQDN );
  387. wco.GetProperty(
  388. wstrObjPath,
  389. L"__RelPath");
  390. wcoOutArgs.SetProperty(
  391. wstrObjPath,
  392. L"RR" );
  393. pHandler->Indicate( 1, & wcoOutArgs );
  394. }
  395. delete [] pIp;
  396. }
  397. else if(_wcsicmp(
  398. wzMethodName,
  399. PVD_MTH_ZONE_RESETSECONDARYIPARRAY) == 0)
  400. {
  401. DNS_DEBUG( INSTPROV, (
  402. "%s: executing %S\n", fn, PVD_MTH_ZONE_RESETSECONDARYIPARRAY ));
  403. CWbemClassObject Inst(pInArgs);
  404. DWORD *pSecondaryIp=NULL, cSecondaryIp=0, dwSecurity=-1;
  405. DWORD *pNotifyIp=NULL, cNotifyIp=0, dwNotify=-1;
  406. Inst.GetProperty(
  407. &pSecondaryIp,
  408. &cSecondaryIp,
  409. PVD_MTH_ZONE_ARG_SECONDARYIPARRAY);
  410. Inst.GetProperty(
  411. &pNotifyIp,
  412. &cNotifyIp,
  413. PVD_MTH_ZONE_ARG_NOTIFYIPARRAY);
  414. Inst.GetProperty(
  415. &dwSecurity,
  416. PVD_MTH_ZONE_ARG_SECURITY);
  417. Inst.GetProperty(
  418. &dwNotify,
  419. PVD_MTH_ZONE_ARG_NOTIFY);
  420. sc = dns.dnsZoneResetSecondary(
  421. strZoneName,
  422. dwSecurity,
  423. pSecondaryIp,
  424. cSecondaryIp,
  425. dwNotify,
  426. pNotifyIp,
  427. cNotifyIp);
  428. DNS_DEBUG( INSTPROV, (
  429. "%s: dnsZoneResetSecondary returned 0x%08X\n", fn, sc ));
  430. delete [] pSecondaryIp;
  431. delete [] pNotifyIp;
  432. }
  433. else if(_wcsicmp(
  434. wzMethodName,
  435. PVD_MTH_ZONE_GETDISTINGUISHEDNAME) == 0)
  436. {
  437. wstring wstrName;
  438. CWbemClassObject OutParams, OutClass, Class ;
  439. HRESULT hr;
  440. dns.dnsDsZoneName(wstrName, wstrZoneName);
  441. BSTR ClassName=NULL;
  442. ClassName = AllocBstr(PVD_CLASS_ZONE);
  443. hr = m_pNamespace->GetObject(ClassName, 0, 0, &Class, NULL);
  444. SysFreeString(ClassName);
  445. if ( SUCCEEDED ( hr ) )
  446. {
  447. Class.GetMethod(wzMethodName, 0, NULL, &OutClass);
  448. OutClass.SpawnInstance(0, &OutParams);
  449. OutParams.SetProperty(wstrName, PVD_DNS_RETURN_VALUE);
  450. hr = pHandler->Indicate(1, &OutParams);
  451. }
  452. return hr;
  453. }
  454. else
  455. {
  456. return WBEM_E_NOT_SUPPORTED;
  457. }
  458. return sc;
  459. }