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.

559 lines
15 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.dnsOperation(
  262. strZoneName,
  263. CDnsWrap::DNS_WRAP_PAUSE_ZONE);
  264. }
  265. else if(_wcsicmp(wzMethodName, PVD_MTH_ZONE_RESUMEZONE) == 0)
  266. {
  267. sc = dns.dnsOperation(
  268. strZoneName,
  269. CDnsWrap::DNS_WRAP_RESUME_ZONE);
  270. }
  271. else if(_wcsicmp(
  272. wzMethodName,
  273. PVD_MTH_ZONE_RELOADZONE ) == 0)
  274. {
  275. sc = dns.dnsOperation(
  276. strZoneName,
  277. CDnsWrap::DNS_WRAP_RELOAD_ZONE);
  278. }
  279. else if(_wcsicmp(
  280. wzMethodName,
  281. PVD_MTH_ZONE_FORCEREFRESH ) == 0)
  282. {
  283. sc = dns.dnsOperation(
  284. strZoneName,
  285. CDnsWrap::DNS_WRAP_REFRESH_SECONDARY);
  286. }
  287. else if(_wcsicmp(
  288. wzMethodName,
  289. PVD_MTH_ZONE_UPDATEFROMDS ) == 0)
  290. {
  291. sc = dns.dnsOperation(
  292. strZoneName,
  293. CDnsWrap::DNS_WRAP_DS_UPDATE );
  294. }
  295. else if(_wcsicmp(
  296. wzMethodName,
  297. PVD_MTH_ZONE_WRITEBACKZONE ) == 0)
  298. {
  299. sc = dns.dnsOperation(
  300. strZoneName,
  301. CDnsWrap::DNS_WRAP_WRITE_BACK_ZONE);
  302. }
  303. else if( _wcsicmp(
  304. wzMethodName,
  305. PVD_MTH_ZONE_CHANGEZONETYPE ) == 0)
  306. {
  307. CWbemClassObject Inst(pInArgs);
  308. string strDataFile, strAdmin;
  309. DWORD * pIp = NULL, cIp = 0, dwZoneType = -1;
  310. BOOL DsIntegrated = FALSE;
  311. Inst.GetProperty(
  312. strDataFile,
  313. PVD_MTH_ZONE_ARG_DATAFILENAME);
  314. Inst.GetProperty(
  315. strAdmin,
  316. PVD_MTH_ZONE_ARG_ADMINEMAILNAME);
  317. Inst.GetProperty(
  318. &pIp,
  319. &cIp,
  320. PVD_MTH_ZONE_ARG_IPADDRARRAY);
  321. Inst.GetProperty(
  322. &dwZoneType,
  323. PVD_MTH_ZONE_ARG_ZONETYPE);
  324. Inst.GetProperty(
  325. &DsIntegrated,
  326. PVD_MTH_ZONE_ARG_DSINTEGRATED );
  327. sc = dns.dnsZoneChangeType(
  328. strZoneName,
  329. dwZoneType,
  330. DsIntegrated,
  331. strDataFile,
  332. strAdmin,
  333. pIp,
  334. cIp );
  335. delete [] pIp;
  336. }
  337. else if(_wcsicmp(
  338. wzMethodName,
  339. PVD_MTH_ZONE_CREATEZONE) == 0)
  340. {
  341. CWbemClassObject Inst(pInArgs);
  342. CWbemClassObject wcoOutArgs;
  343. CWbemClassObject wcoOutArgsClass;
  344. string strDataFile, strAdmin, strNewZoneName;
  345. strAdmin = "Admin";
  346. DWORD * pIp = NULL, cIp = 0, dwZoneType = -1;
  347. BOOL DsIntegrated = FALSE;
  348. sc = m_pClass->GetMethod(wzMethodName, 0, NULL, &wcoOutArgsClass );
  349. if( FAILED ( sc ) )
  350. {
  351. return sc;
  352. }
  353. wcoOutArgsClass.SpawnInstance(0, & wcoOutArgs);
  354. Inst.GetProperty(
  355. strDataFile,
  356. PVD_MTH_ZONE_ARG_DATAFILENAME);
  357. Inst.GetProperty(
  358. strAdmin,
  359. PVD_MTH_ZONE_ARG_ADMINEMAILNAME);
  360. Inst.GetProperty(
  361. &DsIntegrated,
  362. PVD_MTH_ZONE_ARG_DSINTEGRATED );
  363. Inst.GetProperty(
  364. &pIp,
  365. &cIp,
  366. PVD_MTH_ZONE_ARG_IPADDRARRAY);
  367. Inst.GetProperty(
  368. &dwZoneType,
  369. PVD_MTH_ZONE_ARG_ZONETYPE);
  370. Inst.GetProperty(
  371. strNewZoneName,
  372. PVD_MTH_ZONE_ARG_ZONENAME);
  373. sc = dns.dnsZoneCreate(
  374. strNewZoneName,
  375. dwZoneType,
  376. DsIntegrated,
  377. strDataFile,
  378. strAdmin,
  379. pIp,
  380. cIp );
  381. if ( SUCCEEDED ( sc ) )
  382. {
  383. CWbemClassObject wco;
  384. wstring wstrObjPath;
  385. m_pClass->SpawnInstance( 0 , & wco );
  386. wco.SetProperty(
  387. PVD_DNS_LOCAL_SERVER,
  388. PVD_DOMAIN_SERVER_NAME );
  389. wco.SetProperty(
  390. strNewZoneName.data(),
  391. PVD_DOMAIN_CONTAINER_NAME );
  392. wco.SetProperty(
  393. strNewZoneName.data(),
  394. PVD_DOMAIN_FQDN );
  395. wco.GetProperty(
  396. wstrObjPath,
  397. L"__RelPath");
  398. wcoOutArgs.SetProperty(
  399. wstrObjPath,
  400. L"RR" );
  401. pHandler->Indicate( 1, & wcoOutArgs );
  402. }
  403. delete [] pIp;
  404. }
  405. else if(_wcsicmp(
  406. wzMethodName,
  407. PVD_MTH_ZONE_RESETSECONDARYIPARRAY) == 0)
  408. {
  409. DNS_DEBUG( INSTPROV, (
  410. "%s: executing %S\n", fn, PVD_MTH_ZONE_RESETSECONDARYIPARRAY ));
  411. CWbemClassObject Inst(pInArgs);
  412. DWORD *pSecondaryIp=NULL, cSecondaryIp=0, dwSecurity=-1;
  413. DWORD *pNotifyIp=NULL, cNotifyIp=0, dwNotify=-1;
  414. Inst.GetProperty(
  415. &pSecondaryIp,
  416. &cSecondaryIp,
  417. PVD_MTH_ZONE_ARG_SECONDARYIPARRAY);
  418. Inst.GetProperty(
  419. &pNotifyIp,
  420. &cNotifyIp,
  421. PVD_MTH_ZONE_ARG_NOTIFYIPARRAY);
  422. Inst.GetProperty(
  423. &dwSecurity,
  424. PVD_MTH_ZONE_ARG_SECURITY);
  425. Inst.GetProperty(
  426. &dwNotify,
  427. PVD_MTH_ZONE_ARG_NOTIFY);
  428. sc = dns.dnsZoneResetSecondary(
  429. strZoneName,
  430. dwSecurity,
  431. pSecondaryIp,
  432. cSecondaryIp,
  433. dwNotify,
  434. pNotifyIp,
  435. cNotifyIp);
  436. DNS_DEBUG( INSTPROV, (
  437. "%s: dnsZoneResetSecondary returned 0x%08X\n", fn, sc ));
  438. delete [] pSecondaryIp;
  439. delete [] pNotifyIp;
  440. }
  441. else if(_wcsicmp(
  442. wzMethodName,
  443. PVD_MTH_ZONE_GETDISTINGUISHEDNAME) == 0)
  444. {
  445. wstring wstrName;
  446. CWbemClassObject OutParams, OutClass, Class ;
  447. HRESULT hr;
  448. dns.dnsDsZoneName(wstrName, wstrZoneName);
  449. BSTR ClassName = AllocBstr( PVD_CLASS_ZONE );
  450. hr = m_pNamespace->GetObject(ClassName, 0, 0, &Class, NULL);
  451. SysFreeString(ClassName);
  452. if ( SUCCEEDED ( hr ) )
  453. {
  454. Class.GetMethod( wzMethodName, 0, NULL, &OutClass);
  455. OutClass.SpawnInstance(0, &OutParams);
  456. OutParams.SetProperty(wstrName, PVD_DNS_RETURN_VALUE);
  457. hr = pHandler->Indicate(1, &OutParams);
  458. }
  459. return hr;
  460. }
  461. else if( _wcsicmp( wzMethodName,
  462. PVD_MTH_ZONE_AGEALLRECORDS ) == 0 )
  463. {
  464. DNS_DEBUG( INSTPROV, (
  465. "%s: executing %S\n", fn, PVD_MTH_ZONE_AGEALLRECORDS ));
  466. CWbemClassObject Inst( pInArgs );
  467. string strNodeName;
  468. BOOL applyToSubtree = FALSE;
  469. Inst.GetProperty(
  470. strNodeName,
  471. PVD_MTH_ZONE_ARG_NODENAME );
  472. Inst.GetProperty(
  473. &applyToSubtree,
  474. PVD_MTH_ZONE_ARG_APPLYTOSUBTREE );
  475. sc = dns.dnsAgeAllRecords(
  476. strZoneName.c_str(),
  477. strNodeName.c_str(),
  478. applyToSubtree );
  479. CWbemClassObject wco;
  480. wstring wstrObjPath;
  481. m_pClass->SpawnInstance( 0 , & wco );
  482. }
  483. else
  484. {
  485. return WBEM_E_NOT_SUPPORTED;
  486. }
  487. return sc;
  488. }