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.

2956 lines
86 KiB

  1. /////////////////////////////////////////////////////////////////////
  2. //
  3. // CopyRight ( c ) 1999 Microsoft Corporation
  4. //
  5. // Module Name: DnsWrap.cpp
  6. //
  7. // Description:
  8. // Implementation of dnswrap class
  9. //
  10. // Author:
  11. // Henry Wang ( henrywa ) March 8, 2000
  12. //
  13. //
  14. //////////////////////////////////////////////////////////////////////
  15. #include "DnsWmi.h"
  16. //
  17. // These string tables are in client\print.c
  18. //
  19. extern "C" LPSTR MemTagStringsNT5[];
  20. extern "C" LPSTR MemTagStrings[];
  21. //
  22. // These macros allow us to widen DNS RPC string constants.
  23. //
  24. #define MYTEXT2(str) L##str
  25. #define MYTEXT(str) MYTEXT2(str)
  26. //
  27. // Globals for statistics.
  28. //
  29. struct
  30. {
  31. DWORD dwStatId;
  32. const WCHAR * pszName;
  33. } g_StatInfo[] =
  34. {
  35. { DNSSRV_STATID_TIME, L"Time Stats" },
  36. { DNSSRV_STATID_QUERY, L"Query and Response Stats" },
  37. { DNSSRV_STATID_QUERY2, L"Query Stats" },
  38. { DNSSRV_STATID_RECURSE, L"Recursion Stats" },
  39. { DNSSRV_STATID_MASTER, L"Master Stats" },
  40. { DNSSRV_STATID_SECONDARY, L"Secondary Stats" },
  41. { DNSSRV_STATID_WINS, L"WINS Referral Stats" },
  42. { DNSSRV_STATID_WIRE_UPDATE, L"Packet Dynamic Update Stats" },
  43. { DNSSRV_STATID_SKWANSEC, L"SkwanSec Stats" },
  44. { DNSSRV_STATID_DS, L"DS Integration Stats" },
  45. { DNSSRV_STATID_NONWIRE_UPDATE, L"Internal Dynamic Update Stats" },
  46. { DNSSRV_STATID_MEMORY, L"Memory Stats" },
  47. { DNSSRV_STATID_DBASE, L"Database Stats" },
  48. { DNSSRV_STATID_RECORD, L"Record Stats" },
  49. { DNSSRV_STATID_PACKET, L"Packet Memory Usage Stats" },
  50. { DNSSRV_STATID_NBSTAT, L"Nbstat Memory Usage Stats" },
  51. { DNSSRV_STATID_ERRORS, L"Error Stats" },
  52. { DNSSRV_STATID_TIMEOUT, L"Timeout Stats" },
  53. { DNSSRV_STATID_CACHE, L"Query" },
  54. { DNSSRV_STATID_PRIVATE, L"Private Stats" },
  55. { 0, NULL } // terminator
  56. };
  57. //////////////////////////////////////////////////////////////////////
  58. // Construction/Destruction
  59. //////////////////////////////////////////////////////////////////////
  60. CDnsWrap::CDnsWrap()
  61. :m_wszpServerName(NULL)
  62. {
  63. CServerInfo serverInfo;
  64. PDNS_RPC_SERVER_INFO pdata = (PDNS_RPC_SERVER_INFO) serverInfo.m_pInfo;
  65. char* p = pdata->pszServerName;
  66. CharToWchar(p, &m_wszpServerName);
  67. }
  68. CDnsWrap::~CDnsWrap()
  69. {
  70. delete [] m_wszpServerName;
  71. }
  72. CDnsWrap::CServerInfo::CServerInfo()
  73. :m_pInfo(NULL)
  74. {
  75. DWORD dwtypeid;
  76. int status = DnssrvQuery(
  77. PVD_DNS_LOCAL_SERVER,
  78. NULL,
  79. DNSSRV_QUERY_SERVER_INFO,
  80. &dwtypeid,
  81. &m_pInfo);
  82. if(status != ERROR_SUCCESS)
  83. ThrowException(status);
  84. }
  85. CDnsWrap::CServerInfo::~CServerInfo()
  86. {
  87. DnssrvFreeServerInfo((PDNS_RPC_SERVER_INFO)m_pInfo);
  88. }
  89. CDnsWrap& CDnsWrap::DnsObject(void)
  90. {
  91. static CDnsWrap dns;
  92. return dns;
  93. }
  94. /////////////////////////////////////////////////////////////////////////////
  95. //++
  96. //
  97. // Description:
  98. // enumerates record for a give domain. If bRecursive is true, enum all
  99. // records including subdomain, otherwise, enum records directly under
  100. // the domain. It also take a call back function pFilter to allow
  101. // further filtering the records
  102. //
  103. // Arguments:
  104. // objNode [IN ] list of domains
  105. // pFilter [IN] pointer a class contains the criteria
  106. // on how to filter records
  107. // pfFilter [IN] call back function allows further
  108. // processing of records using pFilter
  109. // bRecursive [IN] true for deep enum, otherwise false
  110. // wType, [IN] type of records to enum
  111. // dwFlag, [IN] flag
  112. // pClass, [IN] wmi class for the type of records to enum
  113. // InstMgr [IN] manage wmi object and send them wmi
  114. // Return Value:
  115. // WBEM_S_NO_ERROR
  116. //
  117. //--
  118. /////////////////////////////////////////////////////////////////////////////
  119. SCODE
  120. CDnsWrap::dnsEnumRecordsForDomainEx(
  121. CDomainNode& objNode,
  122. PVOID pFilter,
  123. FILTER pfFilter,
  124. BOOL bRecursive,
  125. WORD wType,
  126. DWORD dwFlag,
  127. IWbemClassObject * pClass,
  128. CWbemInstanceMgr& InstMgr
  129. )
  130. {
  131. CDnsRpcRecordSet RecordSet(
  132. objNode,
  133. wType,
  134. dwFlag,
  135. NULL,
  136. NULL);
  137. PDNS_RPC_NODE pNode=NULL;
  138. WCHAR DomainName[MAX_PATH] = L"";
  139. while (( pNode = RecordSet.GetNextNode()) != NULL)
  140. {
  141. CDnsRpcNode dnsNode;
  142. CObjPath opNew;
  143. if( !dnsNode.Init(pNode))
  144. {
  145. return WBEM_E_FAILED;
  146. }
  147. //find record node
  148. if(dnsNode.IsDomainNode())
  149. {
  150. // get domain name
  151. wstring wstrSubDomainName = dnsNode.GetNodeName();;
  152. wstrSubDomainName += PVD_DNS_LOCAL_SERVER + objNode.wstrNodeName;
  153. CDomainNode subDomain = objNode;
  154. subDomain.wstrNodeName = wstrSubDomainName;
  155. //recursion
  156. if(bRecursive)
  157. {
  158. dnsEnumRecordsForDomainEx(
  159. subDomain,
  160. pFilter,
  161. pfFilter,
  162. bRecursive,
  163. wType,
  164. dwFlag,
  165. pClass,
  166. InstMgr);
  167. }
  168. }
  169. pfFilter(
  170. objNode,
  171. pFilter,
  172. &dnsNode,
  173. pClass,
  174. InstMgr);
  175. }
  176. return WBEM_S_NO_ERROR;
  177. }
  178. SCODE
  179. CDnsWrap::dnsGetDomain(
  180. CObjPath& objParent,
  181. IWbemClassObject* pClass,
  182. IWbemObjectSink* pHandler
  183. )
  184. {
  185. // get top level domain
  186. wstring wstrZoneName = objParent.GetStringValueForProperty(
  187. PVD_DOMAIN_CONTAINER_NAME);
  188. wstring wstrNodeName = objParent.GetStringValueForProperty(
  189. PVD_DOMAIN_FQDN);
  190. list<CDomainNode> nodeList;
  191. dnsEnumDomainForServer(&nodeList);
  192. list<CDomainNode>::iterator i;
  193. BOOL FoundFlag = FALSE;
  194. // check for zone
  195. for(i=nodeList.begin(); i != nodeList.end(); ++i)
  196. {
  197. if(_wcsicmp(
  198. wstrZoneName.data(),
  199. i->wstrZoneName.data()) == 0 )
  200. {
  201. // only roothints and catch, NodeName is initialize to
  202. // nil, we can't do the compare
  203. if(i->wstrNodeName.empty() ||
  204. (_wcsicmp(
  205. wstrNodeName.data(),
  206. i->wstrNodeName.data())==0))
  207. {
  208. FoundFlag = TRUE;
  209. break;
  210. }
  211. }
  212. }
  213. // check for domain in container
  214. if(! FoundFlag)
  215. {
  216. DNS_STATUS status ;
  217. char *pszZoneName=NULL, *pszNodeName=NULL, *pszStartChild=NULL;
  218. DWORD dwBufferLength;
  219. PBYTE pBuffer = NULL;
  220. WcharToChar(wstrZoneName.data(), &pszZoneName);
  221. WcharToChar(wstrNodeName.data(), &pszNodeName);
  222. status = DnssrvEnumRecords(
  223. PVD_DNS_LOCAL_SERVER,
  224. pszZoneName,
  225. pszNodeName,
  226. pszStartChild,
  227. DNS_TYPE_ALL,
  228. DNS_RPC_VIEW_ALL_DATA,
  229. NULL,
  230. NULL,
  231. & dwBufferLength,
  232. & pBuffer);
  233. delete [] pszNodeName;
  234. delete [] pszZoneName;
  235. DnssrvFreeRecordsBuffer(pBuffer);
  236. if (status != ERROR_SUCCESS)
  237. ThrowException(status);
  238. FoundFlag = TRUE;
  239. }
  240. if(FoundFlag)
  241. {
  242. CWbemClassObject Inst;
  243. pClass->SpawnInstance(0, &Inst);
  244. Inst.SetProperty(
  245. wstrNodeName,
  246. PVD_DOMAIN_FQDN);
  247. Inst.SetProperty(
  248. wstrZoneName,
  249. PVD_DOMAIN_CONTAINER_NAME);
  250. Inst.SetProperty(
  251. m_wszpServerName,
  252. PVD_DOMAIN_SERVER_NAME);
  253. // clean up
  254. pHandler->Indicate(1, &Inst);
  255. }
  256. return WBEM_S_NO_ERROR;
  257. }
  258. SCODE
  259. CDnsWrap::dnsDeleteDomain(
  260. char * pszContainer,
  261. char * pszDomain
  262. )
  263. {
  264. LONG status = DnssrvDeleteNode(
  265. PVD_DNS_LOCAL_SERVER,
  266. pszContainer,
  267. pszDomain,
  268. 1 //fDeleteSubtree
  269. );
  270. if ( status != ERROR_SUCCESS )
  271. {
  272. ThrowException(status);
  273. }
  274. return WBEM_S_NO_ERROR;
  275. }
  276. /////////////////////////////////////////////////////////////////////////////
  277. //++
  278. //
  279. // Description:
  280. // enumeratr all zones including cache for local dns server, returns
  281. // them as a list of object path
  282. //
  283. // Arguments:
  284. // pList [IN OUT] list of object path to domains
  285. //
  286. // Return Value:
  287. // WBEM_S_NO_ERROR
  288. //
  289. //--
  290. /////////////////////////////////////////////////////////////////////////////
  291. SCODE
  292. CDnsWrap::dnsEnumDomainForServer(
  293. list<CObjPath>* pList
  294. )
  295. {
  296. PDNS_RPC_ZONE_LIST pZoneList = NULL;
  297. DNS_STATUS status = DnssrvEnumZones(
  298. PVD_DNS_LOCAL_SERVER,
  299. ZONE_REQUEST_ALL_ZONES_AND_CACHE,
  300. NULL,
  301. &pZoneList);
  302. if(status == ERROR_SUCCESS)
  303. {
  304. DNS_RPC_ZONE* pDnsZone = NULL;
  305. CDnsWrap& dns = CDnsWrap::DnsObject();
  306. for(DWORD i = 0; i < pZoneList->dwZoneCount; i++)
  307. {
  308. pDnsZone = (pZoneList->ZoneArray[i]);
  309. if(_wcsicmp(pDnsZone->pszZoneName, PVD_DNS_LOCAL_SERVER))
  310. {
  311. CObjPath opInst;
  312. opInst.SetClass(PVD_CLASS_DOMAIN);
  313. opInst.AddProperty(
  314. PVD_DOMAIN_SERVER_NAME ,
  315. dns.GetServerName().data()
  316. );
  317. opInst.AddProperty(
  318. PVD_DOMAIN_CONTAINER_NAME,
  319. pDnsZone->pszZoneName
  320. );
  321. opInst.AddProperty(
  322. PVD_DOMAIN_FQDN,
  323. pDnsZone->pszZoneName
  324. );
  325. pList->insert(
  326. pList->end(),
  327. opInst);
  328. }
  329. }
  330. // add catch domain
  331. CObjPath opCache;
  332. opCache.SetClass(PVD_CLASS_DOMAIN);
  333. opCache.AddProperty(
  334. PVD_DOMAIN_SERVER_NAME,
  335. dns.GetServerName().data()
  336. );
  337. opCache.AddProperty(
  338. PVD_DOMAIN_CONTAINER_NAME,
  339. PVD_DNS_CACHE
  340. );
  341. opCache.AddProperty(
  342. PVD_DOMAIN_FQDN,
  343. PVD_DNS_CACHE
  344. );
  345. //add roothints
  346. CObjPath opRh;
  347. opRh.SetClass(PVD_CLASS_DOMAIN);
  348. opRh.AddProperty(
  349. PVD_DOMAIN_SERVER_NAME,
  350. dns.GetServerName().data()
  351. );
  352. opRh.AddProperty(
  353. PVD_DOMAIN_CONTAINER_NAME,
  354. PVD_DNS_ROOTHINTS
  355. );
  356. opRh.AddProperty(
  357. PVD_DOMAIN_FQDN,
  358. PVD_DNS_ROOTHINTS
  359. );
  360. pList->insert(pList->begin(), opRh);
  361. pList->insert(pList->begin(), opCache);
  362. }
  363. // CLEAN UP
  364. DnssrvFreeZoneList(pZoneList);
  365. if(status != ERROR_SUCCESS)
  366. {
  367. ThrowException(status);
  368. }
  369. return WBEM_S_NO_ERROR;
  370. }
  371. /////////////////////////////////////////////////////////////////////////////
  372. //++
  373. //
  374. // Description:
  375. // enumeratr all zones including cache for local dns server, returns
  376. // them as a list of domain node
  377. //
  378. // Arguments:
  379. // pList [IN OUT] list of domains
  380. //
  381. // Return Value:
  382. // WBEM_S_NO_ERROR
  383. //
  384. //--
  385. /////////////////////////////////////////////////////////////////////////////
  386. SCODE CDnsWrap::dnsEnumDomainForServer(
  387. list<CDomainNode>* pList
  388. )
  389. {
  390. PDNS_RPC_ZONE_LIST pZoneList = NULL;
  391. LONG status = DnssrvEnumZones(
  392. PVD_DNS_LOCAL_SERVER,
  393. ZONE_REQUEST_ALL_ZONES_AND_CACHE,
  394. NULL,
  395. &pZoneList);
  396. DNS_RPC_ZONE * pDnsZone = NULL;
  397. if( status == ERROR_SUCCESS && pZoneList )
  398. {
  399. for(DWORD i = 0; i < pZoneList->dwZoneCount; i++)
  400. {
  401. pDnsZone = (pZoneList->ZoneArray[i]);
  402. if(_wcsicmp(pDnsZone->pszZoneName, L"."))
  403. {
  404. CDomainNode objNode;
  405. objNode.wstrNodeName = pDnsZone->pszZoneName;
  406. objNode.wstrZoneName = pDnsZone->pszZoneName;
  407. pList->insert(pList->end(), objNode);
  408. }
  409. }
  410. // add catch domain
  411. CDomainNode nodeCache;
  412. nodeCache.wstrZoneName = PVD_DNS_CACHE;
  413. //add roothints
  414. CDomainNode nodeRH;
  415. nodeRH.wstrZoneName = PVD_DNS_ROOTHINTS;
  416. pList->insert(pList->begin(), nodeCache);
  417. pList->insert(pList->begin(), nodeRH);
  418. }
  419. // CLEAN UP
  420. DnssrvFreeZoneList(pZoneList);
  421. if (status != ERROR_SUCCESS)
  422. {
  423. ThrowException(status);
  424. }
  425. return WBEM_S_NO_ERROR;
  426. }
  427. SCODE
  428. CDnsWrap::ValidateServerName(
  429. const WCHAR* pwzStr)
  430. {
  431. if(_wcsicmp(pwzStr, PVD_DNS_LOCAL_SERVER))
  432. if(_wcsicmp(pwzStr, L"127.0.0.1"))
  433. if(_wcsicmp(pwzStr, m_wszpServerName) )
  434. return WBEM_E_INVALID_PARAMETER;
  435. return WBEM_S_NO_ERROR;
  436. }
  437. SCODE
  438. CDnsWrap::dnsQueryServerInfo(
  439. const WCHAR* strServerName,
  440. CWbemClassObject& NewInst,
  441. IWbemObjectSink* pHandler
  442. )
  443. {
  444. // get dnsserver
  445. DWORD dwtypeid;
  446. PVOID pdata=NULL;
  447. DNS_STATUS status;
  448. PDNS_RPC_SERVER_INFO pServerInfo = NULL;
  449. // dww - 6/14/99
  450. // Changed to make see if ValidateServerName does not return WBEM_S_NO_ERROR.
  451. //
  452. if(WBEM_S_NO_ERROR != ValidateServerName(strServerName))
  453. return WBEM_E_INVALID_PARAMETER;
  454. status = DnssrvQuery(
  455. strServerName,
  456. NULL,
  457. DNSSRV_QUERY_SERVER_INFO,
  458. &dwtypeid,
  459. &pdata);
  460. if( status == ERROR_SUCCESS)
  461. {
  462. pServerInfo = (PDNS_RPC_SERVER_INFO) pdata;
  463. NewInst.SetProperty(
  464. pServerInfo->dwVersion,
  465. PVD_SRV_VERSION);
  466. NewInst.SetProperty(
  467. pServerInfo->fDsAvailable,
  468. PVD_SRV_DS_AVAILABLE);
  469. // ListenAddress array
  470. if(pServerInfo->aipListenAddrs)
  471. {
  472. NewInst.SetProperty(
  473. pServerInfo->aipListenAddrs->AddrArray,
  474. pServerInfo->aipListenAddrs->AddrCount,
  475. MYTEXT( DNS_REGKEY_LISTEN_ADDRESSES ) );
  476. }
  477. if(pServerInfo->aipForwarders)
  478. {
  479. NewInst.SetProperty(
  480. pServerInfo->aipForwarders->AddrArray,
  481. pServerInfo->aipForwarders->AddrCount,
  482. MYTEXT( DNS_REGKEY_FORWARDERS ) );
  483. }
  484. if(pServerInfo->aipServerAddrs)
  485. {
  486. NewInst.SetProperty(
  487. pServerInfo->aipServerAddrs->AddrArray,
  488. pServerInfo->aipServerAddrs->AddrCount,
  489. PVD_SRV_SERVER_IP_ADDRESSES_ARRAY);
  490. }
  491. }
  492. DnssrvFreeServerInfo(pServerInfo);
  493. if ( status != ERROR_SUCCESS )
  494. {
  495. ThrowException(status);
  496. }
  497. return ERROR_SUCCESS;
  498. }
  499. SCODE
  500. CDnsWrap::dnsRestartServer(
  501. WCHAR* strServerName
  502. )
  503. {
  504. LONG status = DnssrvOperation(
  505. strServerName,
  506. NULL,
  507. DNSSRV_OP_RESTART,
  508. DNSSRV_TYPEID_NULL,
  509. NULL );
  510. if(status != ERROR_SUCCESS)
  511. {
  512. ThrowException(status);
  513. }
  514. return WBEM_S_NO_ERROR;
  515. }
  516. /////////////////////////////////////////////////////////////////////////////
  517. //++
  518. //
  519. // Description:
  520. // using property value from wmi instance to set dns server property
  521. //
  522. // Arguments:
  523. // Inst [IN] wmi instance whose property value
  524. // to be sent to dns server
  525. //
  526. // Return Value:
  527. // WBEM_S_NO_ERROR
  528. //
  529. //--
  530. /////////////////////////////////////////////////////////////////////////////
  531. SCODE
  532. CDnsWrap::dnsServerPropertySet(
  533. CWbemClassObject& Inst,
  534. BOOL bGet
  535. )
  536. {
  537. DBG_FN( "CDnsWrap::dnsServerPropertySet" )
  538. //
  539. // get mapping table
  540. //
  541. DWORD cNumOfEntries;
  542. PropertyTable* pt = (PropertyTable*)GetPropertyTable(&cNumOfEntries);
  543. for(int i=0; i<cNumOfEntries; i++)
  544. {
  545. FPDNSOPS fp;
  546. fp = pt[i].fpOperationSet;
  547. if(fp != NULL)
  548. {
  549. DNS_DEBUG( INSTPROV, (
  550. "%s: Inst=%p prop=%S\n", fn,
  551. &Inst,
  552. pt[i].pwzProperty ));
  553. // set dns server property
  554. fp(
  555. NULL,
  556. pt[i].pwzProperty,
  557. pt[i].OperationName,
  558. Inst);
  559. }
  560. }
  561. return S_OK;
  562. }
  563. // dww - 6/14/99
  564. // Added the dnsDsServerName method in the CDnsWrap class.
  565. //
  566. SCODE
  567. CDnsWrap::dnsDsServerName(
  568. wstring& wstrDsName)
  569. {
  570. CServerInfo serverInfo;
  571. LPWSTR pwsz = DnssrvCreateDsServerName(
  572. (PDNS_RPC_SERVER_INFO)serverInfo.m_pInfo);
  573. if(pwsz)
  574. wstrDsName = pwsz;
  575. FREE_HEAP(pwsz);
  576. return WBEM_S_NO_ERROR;
  577. }
  578. // dww - 6/14/99
  579. // Added the dnsDsZoneName method in the CDnsWrap class.
  580. //
  581. SCODE
  582. CDnsWrap::dnsDsZoneName(
  583. wstring& wstrDsName,
  584. wstring& wstrInZone
  585. )
  586. {
  587. CServerInfo serverInfo;
  588. LPWSTR pwsz = DnssrvCreateDsZoneName(
  589. (PDNS_RPC_SERVER_INFO)serverInfo.m_pInfo,
  590. (LPWSTR)wstrInZone.data());
  591. if(pwsz)
  592. wstrDsName = pwsz;
  593. FREE_HEAP(pwsz);
  594. return WBEM_S_NO_ERROR;
  595. }
  596. // dww - 6/14/99
  597. // Added the dnsDsNodeName method in the CDnsWrap class.
  598. //
  599. SCODE
  600. CDnsWrap::dnsDsNodeName(
  601. wstring& wstrDsName,
  602. wstring& wstrInZone,
  603. wstring& wstrInNode
  604. )
  605. {
  606. CServerInfo serverInfo;
  607. LPWSTR pwsz = DnssrvCreateDsNodeName(
  608. (PDNS_RPC_SERVER_INFO)serverInfo.m_pInfo,
  609. (LPWSTR)wstrInZone.data(),
  610. (LPWSTR)wstrInNode.data());
  611. if(pwsz)
  612. wstrDsName = pwsz;
  613. FREE_HEAP(pwsz);
  614. return WBEM_S_NO_ERROR;
  615. }
  616. /////////////////////////////////////////////////////////////////////////////
  617. //++
  618. //
  619. // Description:
  620. // retrive dns server property and output to wmi instance
  621. //
  622. // Arguments:
  623. // Inst [IN OUT] wmi instance to receive property value
  624. // got from dns server
  625. //
  626. // Return Value:
  627. // WBEM_S_NO_ERROR
  628. //
  629. //--
  630. /////////////////////////////////////////////////////////////////////////////
  631. SCODE
  632. CDnsWrap::dnsServerPropertyGet(
  633. CWbemClassObject& Inst,
  634. BOOL bGet
  635. )
  636. {
  637. //
  638. // get maping table
  639. //
  640. DWORD cNumOfEntries;
  641. PropertyTable* pt = (PropertyTable*)GetPropertyTable(&cNumOfEntries);
  642. // set array and name property
  643. dnsQueryServerInfo(
  644. PVD_DNS_LOCAL_SERVER,
  645. Inst,
  646. NULL);
  647. for(int i=0; i<cNumOfEntries; i++)
  648. {
  649. FPDNSOPS fp;
  650. fp = pt[i].fpOperationGet;
  651. if(fp != NULL)
  652. { //
  653. // get property from dns, and set wmi property
  654. //
  655. fp(
  656. NULL,
  657. pt[i].pwzProperty,
  658. pt[i].OperationName,
  659. Inst);
  660. }
  661. }
  662. //
  663. // Hard-code the Status property to OK.
  664. //
  665. Inst.SetProperty( L"OK", L"Status" );
  666. return S_OK;
  667. }
  668. /*---------------------------------------------------------------------------
  669. */
  670. SCODE
  671. CDnsWrap::dnsGetDwordProperty(
  672. const char * pszZoneName,
  673. const WCHAR* wszWbemProperty,
  674. const char* pszOperationName,
  675. CWbemClassObject& Inst
  676. )
  677. {
  678. DWORD dwValue;
  679. DNS_STATUS status = DnssrvQueryDwordProperty(
  680. PVD_DNS_LOCAL_SERVER,
  681. pszZoneName,
  682. pszOperationName,
  683. &dwValue);
  684. if(status != ERROR_SUCCESS)
  685. ThrowException(status);
  686. Inst.SetProperty(
  687. dwValue,
  688. (WCHAR*)wszWbemProperty);
  689. return WBEM_S_NO_ERROR;
  690. }
  691. /*---------------------------------------------------------------------------
  692. */
  693. SCODE
  694. CDnsWrap::dnsSetDwordProperty(
  695. const char * pszZoneName,
  696. const WCHAR* wszWbemProperty,
  697. const char* pszOperationName,
  698. CWbemClassObject& Inst
  699. )
  700. {
  701. DWORD dwValue;
  702. if(Inst.GetProperty(
  703. &dwValue,
  704. (WCHAR*)wszWbemProperty) == S_OK)
  705. {
  706. DNS_RPC_NAME_AND_PARAM param;
  707. param.dwParam = dwValue;
  708. param.pszNodeName = (LPSTR) pszOperationName;
  709. DNS_STATUS status = DnssrvOperation(
  710. PVD_DNS_LOCAL_SERVER,
  711. pszZoneName,
  712. DNSSRV_OP_RESET_DWORD_PROPERTY,
  713. DNSSRV_TYPEID_NAME_AND_PARAM,
  714. & param );
  715. if(status != ERROR_SUCCESS)
  716. ThrowException(status);
  717. }
  718. return WBEM_S_NO_ERROR;
  719. }
  720. /*---------------------------------------------------------------------------
  721. */
  722. SCODE
  723. CDnsWrap::dnsGetStringProperty(
  724. const char * pszZoneName,
  725. const WCHAR * wszWbemProperty,
  726. const char * pszDnssrvPropertyName,
  727. CWbemClassObject& Inst
  728. )
  729. {
  730. DWORD dataType;
  731. PVOID pdata;
  732. DNS_STATUS status = DnssrvQuery(
  733. PVD_DNS_LOCAL_SERVER,
  734. pszZoneName,
  735. pszDnssrvPropertyName,
  736. &dataType,
  737. &pdata );
  738. if( status != ERROR_SUCCESS )
  739. {
  740. ThrowException( status );
  741. }
  742. if ( dataType != DNSSRV_TYPEID_LPWSTR )
  743. {
  744. ThrowException( WBEM_E_TYPE_MISMATCH );
  745. }
  746. Inst.SetProperty(
  747. ( PWSTR ) pdata,
  748. ( PWCHAR ) wszWbemProperty);
  749. return WBEM_S_NO_ERROR;
  750. }
  751. /*---------------------------------------------------------------------------
  752. */
  753. SCODE
  754. CDnsWrap::dnsSetStringProperty(
  755. const char * pszZoneName,
  756. const WCHAR * wszWbemProperty,
  757. const char * pszDnssrvPropertyName,
  758. CWbemClassObject & Inst
  759. )
  760. {
  761. wstring val;
  762. if( Inst.GetProperty(
  763. val,
  764. ( PWCHAR ) wszWbemProperty ) == S_OK )
  765. {
  766. DNS_STATUS status = DnssrvResetStringProperty(
  767. PVD_DNS_LOCAL_SERVER,
  768. pszZoneName,
  769. pszDnssrvPropertyName,
  770. val.c_str(),
  771. 0 );
  772. if( status != ERROR_SUCCESS )
  773. {
  774. ThrowException( status );
  775. }
  776. }
  777. return WBEM_S_NO_ERROR;
  778. } // CDnsWrap::dnsSetStringProperty
  779. /*---------------------------------------------------------------------------
  780. Read the property value from DNS server and set in class object.
  781. */
  782. SCODE
  783. CDnsWrap::dnsGetIPArrayProperty(
  784. const char * pszZoneName,
  785. const WCHAR * wszWbemProperty,
  786. const char * pszDnssrvPropertyName,
  787. CWbemClassObject & Inst
  788. )
  789. {
  790. SCODE sc = WBEM_S_NO_ERROR;
  791. DWORD dataType = 0;
  792. PVOID pdata = 0;
  793. SAFEARRAY * psa = NULL;
  794. SAFEARRAYBOUND rgsabound[ 1 ] = { 0, 0 };
  795. PIP_ARRAY pipArray;
  796. //
  797. // Retrieve the setting from the DNS server and check it's type.
  798. //
  799. DNS_STATUS status = DnssrvQuery(
  800. PVD_DNS_LOCAL_SERVER,
  801. pszZoneName,
  802. pszDnssrvPropertyName,
  803. &dataType,
  804. &pdata );
  805. if( status != ERROR_SUCCESS )
  806. {
  807. sc = status;
  808. goto Done;
  809. }
  810. if ( dataType != DNSSRV_TYPEID_IPARRAY )
  811. {
  812. sc = WBEM_E_TYPE_MISMATCH;
  813. goto Done;
  814. }
  815. if ( pdata == NULL )
  816. {
  817. Inst.SetProperty(
  818. ( PWCHAR ) NULL,
  819. ( PWCHAR ) wszWbemProperty );
  820. goto Done;
  821. }
  822. pipArray = ( PIP_ARRAY ) pdata;
  823. //
  824. // Create a SAFEARRAY of BSTRs to represent the IP address list.
  825. //
  826. rgsabound[ 0 ].cElements = pipArray->AddrCount;
  827. psa = SafeArrayCreate( VT_BSTR, 1, rgsabound );
  828. if ( psa == NULL )
  829. {
  830. sc = WBEM_E_OUT_OF_MEMORY;
  831. goto Done;
  832. }
  833. for ( int i = 0; i < pipArray->AddrCount; ++i )
  834. {
  835. BSTR bstr = AllocBstr(
  836. IpAddressToString( pipArray->AddrArray[ i ] ).c_str() );
  837. if ( bstr == NULL )
  838. {
  839. sc = WBEM_E_OUT_OF_MEMORY;
  840. goto Done;
  841. }
  842. LONG ix = i;
  843. sc = SafeArrayPutElement( psa, &ix, bstr );
  844. SysFreeString( bstr );
  845. if ( sc != S_OK )
  846. {
  847. goto Done;
  848. }
  849. }
  850. Inst.SetProperty(
  851. psa,
  852. ( PWCHAR ) wszWbemProperty );
  853. Done:
  854. if ( pdata )
  855. {
  856. // JJW: do something to free RPC piparray???
  857. }
  858. if ( psa )
  859. {
  860. SafeArrayDestroy( psa );
  861. }
  862. return sc;
  863. } // CDnsWrap::dnsGetIPArrayProperty
  864. /*---------------------------------------------------------------------------
  865. Read the property value out of the class object and send to DNS server.
  866. If the specified property does not exist on the object, do nothing and
  867. return WBEM_S_NO_ERROR.
  868. */
  869. SCODE
  870. CDnsWrap::dnsSetIPArrayProperty(
  871. const char * pszZoneName,
  872. const WCHAR * wszWbemProperty,
  873. const char * pszDnssrvPropertyName,
  874. CWbemClassObject & Inst
  875. )
  876. {
  877. DBG_FN( "CDnsWrap::dnsSetIPArrayProperty" )
  878. SCODE sc = WBEM_S_NO_ERROR;
  879. SAFEARRAY * psa = NULL;
  880. VARIANT var;
  881. VariantInit( &var );
  882. if( Inst.GetProperty(
  883. &var,
  884. ( LPCWSTR ) wszWbemProperty ) == S_OK &&
  885. var.vt != VT_NULL )
  886. {
  887. DNS_DEBUG( INSTPROV, (
  888. "%s: %s on zone %s\n", fn, pszDnssrvPropertyName, pszZoneName ));
  889. if ( var.vt != ( VT_ARRAY |VT_BSTR ) )
  890. {
  891. sc = WBEM_E_TYPE_MISMATCH;
  892. goto Done;
  893. }
  894. sc = SafeArrayCopy( var.parray, &psa );
  895. BSTR * pbstr = NULL;
  896. sc = SafeArrayAccessData( psa, ( void ** ) &pbstr );
  897. if ( sc != S_OK )
  898. {
  899. goto Done;
  900. }
  901. int ipCount = psa->rgsabound[ 0 ].cElements;
  902. IP_ADDRESS * pipAddrArray = new IP_ADDRESS[ ipCount + 1 ];
  903. if ( pipAddrArray == NULL )
  904. {
  905. ThrowException( WBEM_E_OUT_OF_MEMORY );
  906. }
  907. for ( int i = 0; i < ipCount; ++i )
  908. {
  909. string str;
  910. WcharToString( pbstr[ i ], str );
  911. pipAddrArray[ i ] = inet_addr( str.c_str() );
  912. }
  913. SafeArrayUnaccessData( psa );
  914. PIP_ARRAY pipArray = Dns_BuildIpArray( ipCount, pipAddrArray );
  915. delete [] pipAddrArray;
  916. DNS_STATUS status = DnssrvResetIPListProperty(
  917. PVD_DNS_LOCAL_SERVER,
  918. pszZoneName,
  919. pszDnssrvPropertyName,
  920. pipArray,
  921. 0 );
  922. FREE_HEAP( pipArray );
  923. if( status != ERROR_SUCCESS )
  924. {
  925. sc = status;
  926. }
  927. }
  928. Done:
  929. VariantClear( &var );
  930. if ( psa )
  931. {
  932. SafeArrayDestroy( psa );
  933. }
  934. return sc;
  935. } // CDnsWrap::dnsSetIPArrayProperty
  936. SCODE
  937. CDnsWrap::dnsSetServerForwarders(
  938. const char * pszZoneName,
  939. const WCHAR* wszWbemProperty,
  940. const char* pszOperationName,
  941. CWbemClassObject & Inst
  942. )
  943. {
  944. // get forward ip array
  945. DWORD* pdwValue=NULL;
  946. DWORD dwSize;
  947. if(Inst.GetProperty(
  948. &pdwValue,
  949. &dwSize,
  950. (WCHAR*)wszWbemProperty) == S_OK)
  951. {
  952. DWORD dwSlave;
  953. DWORD dwTimeOut;
  954. try
  955. {
  956. // start changing forwarders process
  957. // get slave
  958. if(Inst.GetProperty(
  959. &dwSlave,
  960. MYTEXT( DNS_REGKEY_SLAVE ) ) != S_OK)
  961. {
  962. return WBEM_E_INVALID_PARAMETER;
  963. }
  964. // get forward time out
  965. if(Inst.GetProperty(
  966. &dwTimeOut,
  967. MYTEXT( DNS_REGKEY_FORWARD_TIMEOUT ) ) != S_OK)
  968. {
  969. return WBEM_E_INVALID_PARAMETER;
  970. }
  971. }
  972. catch(...)
  973. {
  974. delete [] pdwValue;
  975. throw;
  976. }
  977. // now let's change it
  978. DNS_STATUS status = DnssrvResetForwarders(
  979. PVD_DNS_LOCAL_SERVER,
  980. dwSize,
  981. pdwValue,
  982. dwTimeOut,
  983. dwSlave );
  984. delete [] pdwValue;
  985. if(status != ERROR_SUCCESS)
  986. {
  987. ThrowException(status);
  988. }
  989. }
  990. return WBEM_S_NO_ERROR;
  991. }
  992. SCODE
  993. CDnsWrap::dnsSetServerListenAddress(
  994. const char * pszZoneName,
  995. const WCHAR* wszWbemProperty,
  996. const char* pszOperationName,
  997. CWbemClassObject& Inst
  998. )
  999. {
  1000. // dww - 6/28/99
  1001. // Rewrote to accept NULL as a valid parameter.
  1002. //
  1003. DWORD* dwValue = NULL;
  1004. DWORD dwSize = 0;
  1005. Inst.GetProperty( &dwValue, &dwSize, (WCHAR*)wszWbemProperty);
  1006. if ( dwSize == 0 )
  1007. {
  1008. dwValue = new DWORD[1];
  1009. if ( !dwValue )
  1010. {
  1011. return WBEM_E_OUT_OF_MEMORY;
  1012. }
  1013. dwValue[0] = 0;
  1014. }
  1015. DNS_STATUS status = DnssrvResetServerListenAddresses(
  1016. PVD_DNS_LOCAL_SERVER,
  1017. dwSize,
  1018. dwValue);
  1019. delete [] dwValue;
  1020. if(status != ERROR_SUCCESS)
  1021. {
  1022. ThrowException(status);
  1023. }
  1024. return WBEM_S_NO_ERROR;
  1025. }
  1026. SCODE
  1027. CDnsWrap::dnsDeleteZone(
  1028. CObjPath& objZone)
  1029. {
  1030. wstring wstrZoneName = objZone.GetStringValueForProperty(
  1031. PVD_DOMAIN_CONTAINER_NAME
  1032. );
  1033. // dww - 6/14/99
  1034. // Added code to see if this is an integrated zone. If it is, you have to use
  1035. // The DNSSRV_OP_ZONE_DELETE_FROM_DS operation. All other zone types use the
  1036. // DNSSRV_OP_ZONE_DELETE operation.
  1037. //
  1038. // Get the Zone Type to determine if it is an integrated zone.
  1039. DWORD dwValue = -1;
  1040. LONG status = WBEM_S_NO_ERROR;
  1041. char* pszZoneName = NULL;
  1042. WcharToChar(wstrZoneName.data(), &pszZoneName);
  1043. DnssrvQueryDwordProperty(
  1044. PVD_DNS_LOCAL_SERVER,
  1045. pszZoneName,
  1046. DNS_REGKEY_ZONE_DS_INTEGRATED,
  1047. &dwValue
  1048. );
  1049. if(dwValue == 1) // integrated zone
  1050. {
  1051. status= DnssrvOperation(
  1052. PVD_DNS_LOCAL_SERVER,
  1053. pszZoneName,
  1054. DNSSRV_OP_ZONE_DELETE_FROM_DS,
  1055. DNSSRV_TYPEID_NULL,
  1056. (PVOID) NULL
  1057. );
  1058. }
  1059. else
  1060. {
  1061. status= DnssrvOperation(
  1062. PVD_DNS_LOCAL_SERVER,
  1063. pszZoneName,
  1064. DNSSRV_OP_ZONE_DELETE,
  1065. DNSSRV_TYPEID_NULL,
  1066. (PVOID) NULL
  1067. );
  1068. }
  1069. delete [] pszZoneName;
  1070. if( status != ERROR_SUCCESS)
  1071. ThrowException(status);
  1072. return WBEM_S_NO_ERROR;
  1073. }
  1074. wstring
  1075. CDnsWrap::GetServerName(void)
  1076. {
  1077. return m_wszpServerName;
  1078. }
  1079. SCODE
  1080. CDnsWrap::dnsGetZone(
  1081. const WCHAR* wszServer,
  1082. const WCHAR* wszZone,
  1083. CWbemClassObject& Inst,
  1084. IWbemObjectSink* pHandler
  1085. )
  1086. {
  1087. DBG_FN( "CDnsWrap::dnsGetZone" )
  1088. DNS_STATUS status;
  1089. char* pszZoneName = NULL;
  1090. PDNS_RPC_ZONE_INFO pZoneInfo=NULL;
  1091. WcharToChar(wszZone, &pszZoneName);
  1092. status = DnssrvGetZoneInfo(
  1093. wszServer,
  1094. pszZoneName,
  1095. &pZoneInfo );
  1096. DNS_DEBUG( INSTPROV, (
  1097. "%s: server %S zone %S\n", fn, wszServer, wszZone ));
  1098. DWORD dwDsIntegratedValue = 0;
  1099. if ( status == ERROR_SUCCESS)
  1100. {
  1101. status = DnssrvQueryDwordProperty(
  1102. PVD_DNS_LOCAL_SERVER,
  1103. pszZoneName,
  1104. DNS_REGKEY_ZONE_DS_INTEGRATED,
  1105. &dwDsIntegratedValue );
  1106. }
  1107. delete [] pszZoneName;
  1108. if ( status == DNS_ERROR_ZONE_DOES_NOT_EXIST)
  1109. {
  1110. return WBEM_E_NOT_FOUND;
  1111. }
  1112. // setup wbem object
  1113. if(status == ERROR_SUCCESS)
  1114. {
  1115. Inst.SetProperty(
  1116. pZoneInfo->dwZoneType,
  1117. PVD_ZONE_ZONE_TYPE);
  1118. // setup keys
  1119. Inst.SetProperty(
  1120. m_wszpServerName,
  1121. PVD_DOMAIN_SERVER_NAME);
  1122. Inst.SetProperty(
  1123. wszZone,
  1124. PVD_DOMAIN_CONTAINER_NAME);
  1125. Inst.SetProperty(
  1126. wszZone,
  1127. PVD_DOMAIN_FQDN);
  1128. Inst.SetProperty(
  1129. pZoneInfo->fAllowUpdate,
  1130. PVD_ZONE_ALLOW_UPDATE);
  1131. Inst.SetProperty(
  1132. pZoneInfo->fAutoCreated,
  1133. PVD_ZONE_AUTO_CREATED);
  1134. Inst.SetProperty(
  1135. pZoneInfo->fPaused,
  1136. PVD_ZONE_PAUSED );
  1137. Inst.SetProperty(
  1138. pZoneInfo->fReverse,
  1139. PVD_ZONE_REVERSE );
  1140. Inst.SetProperty(
  1141. pZoneInfo->fAging,
  1142. PVD_ZONE_AGING );
  1143. Inst.SetProperty(
  1144. pZoneInfo->fSecureSecondaries,
  1145. PVD_ZONE_SECURE_SECONDARIES );
  1146. Inst.SetProperty(
  1147. pZoneInfo->fNotifyLevel,
  1148. PVD_ZONE_NOTIFY);
  1149. Inst.SetProperty(
  1150. pZoneInfo->fShutdown,
  1151. PVD_ZONE_SHUTDOWN );
  1152. Inst.SetProperty(
  1153. pZoneInfo->fUseWins,
  1154. PVD_ZONE_USE_WINS);
  1155. Inst.SetProperty(
  1156. pZoneInfo->pszDataFile,
  1157. PVD_ZONE_DATA_FILE);
  1158. Inst.SetProperty(
  1159. dwDsIntegratedValue,
  1160. PVD_ZONE_DS_INTEGRATED);
  1161. Inst.SetProperty(
  1162. pZoneInfo->dwAvailForScavengeTime,
  1163. PVD_ZONE_AVAIL_FOR_SCAVENGE_TIME );
  1164. Inst.SetProperty(
  1165. pZoneInfo->dwNoRefreshInterval,
  1166. PVD_ZONE_NOREFRESH_INTERVAL );
  1167. Inst.SetProperty(
  1168. pZoneInfo->dwRefreshInterval,
  1169. PVD_ZONE_REFRESH_INTERVAL );
  1170. Inst.SetProperty(
  1171. pZoneInfo->fForwarderSlave,
  1172. PVD_ZONE_FORWARDER_SLAVE );
  1173. Inst.SetProperty(
  1174. pZoneInfo->dwForwarderTimeout,
  1175. PVD_ZONE_FORWARDER_TIMEOUT );
  1176. if (pZoneInfo->aipMasters != NULL)
  1177. {
  1178. Inst.SetProperty(
  1179. pZoneInfo->aipMasters->AddrArray,
  1180. pZoneInfo->aipMasters->AddrCount,
  1181. PVD_ZONE_MASTERS_IP_ADDRESSES_ARRAY );
  1182. }
  1183. if (pZoneInfo->aipSecondaries != NULL)
  1184. {
  1185. Inst.SetProperty(
  1186. pZoneInfo->aipSecondaries->AddrArray,
  1187. pZoneInfo->aipSecondaries->AddrCount,
  1188. PVD_ZONE_SECONDARIES_IP_ADDRESSES_ARRAY );
  1189. }
  1190. if( pZoneInfo->aipNotify != NULL)
  1191. {
  1192. Inst.SetProperty(
  1193. pZoneInfo->aipNotify->AddrArray,
  1194. pZoneInfo->aipNotify->AddrCount,
  1195. PVD_ZONE_NOTIFY_IPADDRESSES_ARRAY );
  1196. }
  1197. if( pZoneInfo->aipScavengeServers )
  1198. {
  1199. Inst.SetProperty(
  1200. pZoneInfo->aipScavengeServers->AddrArray,
  1201. pZoneInfo->aipScavengeServers->AddrCount,
  1202. PVD_ZONE_SCAVENGE_SERVERS );
  1203. }
  1204. Inst.SetProperty(
  1205. pZoneInfo->dwLastSuccessfulSoaCheck,
  1206. PVD_ZONE_LAST_SOA_CHECK );
  1207. Inst.SetProperty(
  1208. pZoneInfo->dwLastSuccessfulXfr,
  1209. PVD_ZONE_LAST_GOOD_XFR );
  1210. }
  1211. //clean up
  1212. DnssrvFreeZoneInfo(pZoneInfo);
  1213. if( status != ERROR_SUCCESS)
  1214. {
  1215. DNS_DEBUG( INSTPROV, (
  1216. "%s: server %S zone %S throwing %s\n", fn, wszServer, wszZone, status ));
  1217. ThrowException(status);
  1218. }
  1219. DNS_DEBUG( INSTPROV, (
  1220. "%s: server %S zone %S returning WBEM_S_NO_ERROR\n", fn, wszServer, wszZone ));
  1221. return WBEM_S_NO_ERROR;
  1222. }
  1223. SCODE
  1224. CDnsWrap::dnsSetProperty(
  1225. const WCHAR* wszZoneName,
  1226. const char* pszPropertyName,
  1227. DWORD dwValue
  1228. )
  1229. {
  1230. char * pszZone = NULL;
  1231. WcharToChar(wszZoneName, &pszZone);
  1232. return dnsSetProperty( pszZone, pszPropertyName, dwValue );
  1233. }
  1234. SCODE
  1235. CDnsWrap::dnsSetProperty(
  1236. const char* pszZoneName,
  1237. const char* pszPropertyName,
  1238. DWORD dwValue
  1239. )
  1240. {
  1241. DBG_FN( "CDnsWrap::dnsSetDwordProperty" );
  1242. DNS_DEBUG( INSTPROV, (
  1243. "%s: zone %s property %s value %d\n", fn,
  1244. pszZoneName,
  1245. pszPropertyName,
  1246. dwValue ));
  1247. LONG status = DnssrvResetDwordProperty(
  1248. PVD_DNS_LOCAL_SERVER,
  1249. pszZoneName,
  1250. pszPropertyName,
  1251. dwValue );
  1252. if ( status != ERROR_SUCCESS )
  1253. {
  1254. DNS_DEBUG( INSTPROV, (
  1255. "%s: throwing 0x%X for zone %s property %s\n", fn,
  1256. status,
  1257. pszZoneName,
  1258. pszPropertyName ));
  1259. ThrowException( status );
  1260. }
  1261. return WBEM_S_NO_ERROR;
  1262. }
  1263. SCODE
  1264. CDnsWrap::dnsQueryProperty(
  1265. const WCHAR* wszZoneName,
  1266. const WCHAR* wszPropertyName,
  1267. DWORD* pdwResult
  1268. )
  1269. {
  1270. char * szZone = NULL;
  1271. char * szProp = NULL;
  1272. WcharToChar(wszZoneName, &szZone);
  1273. WcharToChar(wszPropertyName, &szProp);
  1274. LONG status = DnssrvQueryZoneDwordProperty(
  1275. PVD_DNS_LOCAL_SERVER,
  1276. szZone,
  1277. szProp,
  1278. pdwResult
  1279. );
  1280. delete [] szZone;
  1281. delete [] szProp;
  1282. if(status != ERROR_SUCCESS)
  1283. ThrowException(status);
  1284. return WBEM_S_NO_ERROR;
  1285. }
  1286. SCODE
  1287. CDnsWrap::dnsResumeZone(
  1288. const char* strZoneName
  1289. )
  1290. {
  1291. DNS_STATUS status = DnssrvResumeZone(
  1292. PVD_DNS_LOCAL_SERVER,
  1293. strZoneName);
  1294. if(status != ERROR_SUCCESS)
  1295. {
  1296. ThrowException(status);
  1297. }
  1298. return WBEM_S_NO_ERROR;
  1299. }
  1300. SCODE
  1301. CDnsWrap::dnsPauseZone(
  1302. const char *strZoneName
  1303. )
  1304. {
  1305. int status = DnssrvPauseZone(
  1306. PVD_DNS_LOCAL_SERVER,
  1307. strZoneName // zone name
  1308. );
  1309. if ( status != ERROR_SUCCESS )
  1310. {
  1311. ThrowException(status);
  1312. }
  1313. return WBEM_S_NO_ERROR;
  1314. }
  1315. void
  1316. CDnsWrap::ThrowException(
  1317. LONG status)
  1318. {
  1319. CDnsProvException dnsExcep(Dns_StatusString(status),status);
  1320. throw dnsExcep;
  1321. }
  1322. void
  1323. CDnsWrap::ThrowException(
  1324. LPCSTR ErrString
  1325. )
  1326. {
  1327. CDnsProvException dnsExcep(ErrString);
  1328. throw dnsExcep;
  1329. }
  1330. SCODE CDnsWrap::dnsClearCache()
  1331. {
  1332. DNS_STATUS status = DnssrvOperation(
  1333. PVD_DNS_LOCAL_SERVER,
  1334. NULL,
  1335. DNSSRV_OP_CLEAR_CACHE,
  1336. DNSSRV_TYPEID_NULL,
  1337. NULL );
  1338. if(status != S_OK)
  1339. ThrowException(status);
  1340. return WBEM_S_NO_ERROR;
  1341. }
  1342. SCODE
  1343. CDnsWrap::dnsOperation(
  1344. string& strZone, //zone name
  1345. OpsFlag OperationID
  1346. )
  1347. {
  1348. string strOps;
  1349. switch(OperationID)
  1350. {
  1351. case DNS_WRAP_RELOAD_ZONE:
  1352. strOps = DNSSRV_OP_ZONE_RELOAD;
  1353. break;
  1354. case DNS_WRAP_RESUME_ZONE:
  1355. strOps = DNSSRV_OP_ZONE_RESUME;
  1356. break;
  1357. case DNS_WRAP_PAUSE_ZONE:
  1358. strOps = DNSSRV_OP_ZONE_PAUSE;
  1359. break;
  1360. case DNS_WRAP_DS_UPDATE:
  1361. strOps = DNSSRV_OP_ZONE_UPDATE_FROM_DS;
  1362. break;
  1363. case DNS_WRAP_WRITE_BACK_ZONE:
  1364. strOps = DNSSRV_OP_ZONE_WRITE_BACK_FILE;
  1365. break;
  1366. case DNS_WRAP_REFRESH_SECONDARY:
  1367. strOps = DNSSRV_OP_ZONE_REFRESH;
  1368. break;
  1369. default:
  1370. return WBEM_E_FAILED;
  1371. }
  1372. DNS_STATUS status = DnssrvOperation(
  1373. PVD_DNS_LOCAL_SERVER,
  1374. strZone.data(),
  1375. strOps.data(),
  1376. DNSSRV_TYPEID_NULL,
  1377. NULL );
  1378. if(status != S_OK)
  1379. ThrowException(status);
  1380. return WBEM_S_NO_ERROR;
  1381. }
  1382. /////////////////////////////////////////////////////////////////////////////
  1383. //++
  1384. //
  1385. // Description:
  1386. // returns a mapping table that maps wbem property and dns property
  1387. // , and operation can be performed
  1388. // on the property such as get and set
  1389. //
  1390. // Arguments:
  1391. // pdwSize [IN ] size of the table
  1392. // Return Value:
  1393. // WBEM_S_NO_ERROR
  1394. //
  1395. //--
  1396. /////////////////////////////////////////////////////////////////////////////
  1397. PVOID
  1398. CDnsWrap::GetPropertyTable(
  1399. DWORD* pdwSize
  1400. )
  1401. {
  1402. //
  1403. // Macros to simplify adding elements to the property array.
  1404. //
  1405. #define DECLARE_DW_ELEMENT( str ) \
  1406. { \
  1407. MYTEXT( str ), \
  1408. str, \
  1409. dnsSetDwordProperty, \
  1410. dnsGetDwordProperty \
  1411. }
  1412. #define DECLARE_STR_ELEMENT( str ) \
  1413. { \
  1414. MYTEXT( str ), \
  1415. str, \
  1416. dnsSetStringProperty, \
  1417. dnsGetStringProperty \
  1418. }
  1419. #define DECLARE_IPARRAY_ELEMENT( str ) \
  1420. { \
  1421. MYTEXT( str ), \
  1422. str, \
  1423. dnsSetIPArrayProperty, \
  1424. dnsGetIPArrayProperty \
  1425. }
  1426. //
  1427. // Array of server properties.
  1428. //
  1429. static PropertyTable pt[] =
  1430. {
  1431. DECLARE_DW_ELEMENT( DNS_REGKEY_ADDRESS_ANSWER_LIMIT ),
  1432. DECLARE_DW_ELEMENT( DNS_REGKEY_ALLOW_UPDATE ),
  1433. DECLARE_DW_ELEMENT( DNS_REGKEY_RPC_PROTOCOL ),
  1434. DECLARE_DW_ELEMENT( DNS_REGKEY_NO_RECURSION ),
  1435. DECLARE_DW_ELEMENT( DNS_REGKEY_RECURSION_RETRY ),
  1436. DECLARE_DW_ELEMENT( DNS_REGKEY_RECURSION_TIMEOUT ),
  1437. DECLARE_DW_ELEMENT( DNS_REGKEY_FORWARD_TIMEOUT ),
  1438. DECLARE_DW_ELEMENT( DNS_REGKEY_SLAVE ),
  1439. DECLARE_DW_ELEMENT( DNS_REGKEY_AUTO_CACHE_UPDATE ),
  1440. DECLARE_DW_ELEMENT( DNS_REGKEY_DISJOINT_NETS ),
  1441. DECLARE_DW_ELEMENT( DNS_REGKEY_ROUND_ROBIN ),
  1442. DECLARE_DW_ELEMENT( DNS_REGKEY_BIND_SECONDARIES ),
  1443. DECLARE_DW_ELEMENT( DNS_REGKEY_WRITE_AUTHORITY_NS ),
  1444. DECLARE_DW_ELEMENT( DNS_REGKEY_STRICT_FILE_PARSING ),
  1445. DECLARE_DW_ELEMENT( DNS_REGKEY_LOOSE_WILDCARDING ),
  1446. DECLARE_DW_ELEMENT( DNS_REGKEY_EVENTLOG_LEVEL ),
  1447. DECLARE_DW_ELEMENT( DNS_REGKEY_LOG_LEVEL ),
  1448. DECLARE_DW_ELEMENT( DNS_REGKEY_MAX_CACHE_TTL ),
  1449. DECLARE_DW_ELEMENT( DNS_REGKEY_MAX_NEGATIVE_CACHE_TTL ),
  1450. DECLARE_DW_ELEMENT( DNS_REGKEY_DS_POLLING_INTERVAL ),
  1451. DECLARE_DW_ELEMENT( DNS_REGKEY_DS_TOMBSTONE_INTERVAL ),
  1452. DECLARE_DW_ELEMENT( DNS_REGKEY_NAME_CHECK_FLAG ),
  1453. DECLARE_DW_ELEMENT( DNS_REGKEY_SEND_PORT ),
  1454. DECLARE_DW_ELEMENT( DNS_REGKEY_BOOT_METHOD ),
  1455. DECLARE_DW_ELEMENT( DNS_REGKEY_NO_AUTO_REVERSE_ZONES ),
  1456. DECLARE_DW_ELEMENT( DNS_REGKEY_LOCAL_NET_PRIORITY ),
  1457. DECLARE_DW_ELEMENT( DNS_REGKEY_FORWARD_DELEGATIONS ),
  1458. DECLARE_DW_ELEMENT( DNS_REGKEY_SECURE_RESPONSES ),
  1459. DECLARE_DW_ELEMENT( DNS_REGKEY_AUTO_CONFIG_FILE_ZONES ),
  1460. DECLARE_DW_ELEMENT( DNS_REGKEY_DEFAULT_AGING_STATE ),
  1461. DECLARE_DW_ELEMENT( DNS_REGKEY_DEFAULT_REFRESH_INTERVAL ),
  1462. DECLARE_DW_ELEMENT( DNS_REGKEY_DEFAULT_NOREFRESH_INTERVAL ),
  1463. DECLARE_DW_ELEMENT( DNS_REGKEY_ENABLE_DNSSEC ),
  1464. DECLARE_DW_ELEMENT( DNS_REGKEY_ENABLE_EDNS ),
  1465. DECLARE_DW_ELEMENT( DNS_REGKEY_EDNS_CACHE_TIMEOUT ),
  1466. DECLARE_DW_ELEMENT( DNS_REGKEY_ENABLE_DP ),
  1467. DECLARE_DW_ELEMENT( DNS_REGKEY_XFR_CONNECT_TIMEOUT ),
  1468. DECLARE_DW_ELEMENT( DNS_REGKEY_SCAVENGING_INTERVAL ),
  1469. DECLARE_DW_ELEMENT( DNS_REGKEY_UPDATE_OPTIONS ),
  1470. DECLARE_DW_ELEMENT( DNS_REGKEY_LOG_FILE_MAX_SIZE ),
  1471. DECLARE_STR_ELEMENT( DNS_REGKEY_LOG_FILE_PATH ),
  1472. DECLARE_IPARRAY_ELEMENT( DNS_REGKEY_LOG_IP_FILTER_LIST ),
  1473. {
  1474. MYTEXT( DNS_REGKEY_FORWARDERS ),
  1475. DNS_REGKEY_FORWARDERS,
  1476. dnsSetServerForwarders,
  1477. NULL
  1478. },
  1479. DECLARE_DW_ELEMENT( DNS_REGKEY_FORWARD_TIMEOUT ),
  1480. DECLARE_DW_ELEMENT( DNS_REGKEY_SLAVE ),
  1481. {
  1482. MYTEXT( DNS_REGKEY_LISTEN_ADDRESSES ),
  1483. DNS_REGKEY_LISTEN_ADDRESSES,
  1484. dnsSetServerListenAddress,
  1485. NULL
  1486. },
  1487. };
  1488. static DWORD dwNumofElements =
  1489. sizeof(pt)/sizeof(PropertyTable);
  1490. *pdwSize = dwNumofElements;
  1491. return &pt;
  1492. }
  1493. SCODE
  1494. CDnsWrap::dnsZoneCreate(
  1495. string& strZoneName,
  1496. DWORD dwZoneType,
  1497. string& strDataFile,
  1498. string& strAdmin,
  1499. DWORD* pIp,
  1500. DWORD cIp
  1501. )
  1502. {
  1503. DWORD loadOptions = 0, fuseDs = FALSE;
  1504. LPSTR pszData = NULL;
  1505. if(dwZoneType == 2)
  1506. //secondary zone must supply master ip array
  1507. {
  1508. if( cIp <=0 || pIp == NULL)
  1509. return WBEM_E_INVALID_PARAMETER;
  1510. }
  1511. else if(dwZoneType == 0) //dsIntegrated
  1512. {
  1513. loadOptions = TRUE; //load existing
  1514. fuseDs = TRUE;
  1515. dwZoneType =1; // dsPrimary
  1516. }
  1517. if( !strDataFile.empty())
  1518. {
  1519. loadOptions |= DNS_ZONE_LOAD_EXISTING;
  1520. pszData = (LPSTR) strDataFile.data();
  1521. }
  1522. string strAdminEmail = strAdmin;
  1523. if(strAdminEmail.empty())
  1524. strAdminEmail = "Admin";
  1525. DNS_STATUS status;
  1526. status = DnssrvCreateZone(
  1527. PVD_DNS_LOCAL_SERVER, //server
  1528. (char*) strZoneName.data(), //zone
  1529. dwZoneType, //zone type
  1530. strAdminEmail.data(), // admin email
  1531. cIp, // size of master
  1532. pIp, // master ip
  1533. loadOptions, // load option
  1534. fuseDs, //dwDsIntegrated, //fuseDs,
  1535. pszData, //pszDataFile
  1536. 0, // timeout for forwarder zone
  1537. 0 // doNotRecurse flag for forwarder zone
  1538. );
  1539. if ( status != ERROR_SUCCESS )
  1540. ThrowException(status);
  1541. return WBEM_S_NO_ERROR;
  1542. }
  1543. SCODE
  1544. CDnsWrap::dnsZoneChangeType(
  1545. string& strZone,
  1546. DWORD dwZoneType,
  1547. string& strDataFile,
  1548. string& strAdmin,
  1549. DWORD* pIp,
  1550. DWORD cIp
  1551. )
  1552. {
  1553. //set zone type
  1554. DWORD dwUseDs=FALSE, dwLoadOptions=TRUE, cMaster=0;
  1555. if(dwZoneType ==1 && strDataFile.empty())
  1556. {
  1557. ThrowException("DataFile required");
  1558. }
  1559. if( dwZoneType == 2)
  1560. {
  1561. // change to secondary zone
  1562. if(pIp == NULL || cIp <= 0 ) // secondary must have master IP
  1563. return WBEM_E_INVALID_PARAMETER;
  1564. }
  1565. else if (dwZoneType == 0)
  1566. {
  1567. if(!strDataFile.empty()) //dsIntegrated doesn't use file
  1568. return WBEM_E_INVALID_PARAMETER;
  1569. dwUseDs = TRUE;
  1570. }
  1571. DNS_STATUS status;
  1572. status = DnssrvResetZoneTypeEx(
  1573. PVD_DNS_LOCAL_SERVER,
  1574. strZone.data(),
  1575. dwZoneType,
  1576. cIp,
  1577. pIp,
  1578. dwLoadOptions,
  1579. dwUseDs,
  1580. strDataFile.data());
  1581. if(status != S_OK)
  1582. ThrowException(status);
  1583. return WBEM_S_NO_ERROR;
  1584. }
  1585. SCODE
  1586. CDnsWrap::dnsZoneResetSecondary(
  1587. string& strZoneName,
  1588. DWORD dwSecurity,
  1589. DWORD* pSecondaryIp,
  1590. DWORD cSecondaryIp,
  1591. DWORD dwNotify,
  1592. DWORD * pNotifyIp,
  1593. DWORD cNotifyIp
  1594. )
  1595. {
  1596. DNS_STATUS status;
  1597. DWORD tdwNotifyLevel = ZONE_NOTIFY_ALL;
  1598. DWORD tdwSecurity = ZONE_SECSECURE_NO_SECURITY;
  1599. if( dwSecurity <=3 )
  1600. {
  1601. tdwSecurity = dwSecurity;
  1602. }
  1603. if( dwNotify <=2)
  1604. {
  1605. tdwNotifyLevel = dwNotify;
  1606. }
  1607. status = DnssrvResetZoneSecondaries(
  1608. PVD_DNS_LOCAL_SERVER,
  1609. strZoneName.data(),
  1610. tdwSecurity,
  1611. cSecondaryIp,
  1612. pSecondaryIp,
  1613. tdwNotifyLevel,
  1614. cNotifyIp,
  1615. pNotifyIp);
  1616. if ( status != ERROR_SUCCESS )
  1617. {
  1618. ThrowException(status);
  1619. }
  1620. return WBEM_S_NO_ERROR;
  1621. }
  1622. SCODE
  1623. CDnsWrap::dnsZoneResetMaster(
  1624. string& strZoneName,
  1625. DWORD* pMasterIp,
  1626. DWORD cMasterIp,
  1627. DWORD dwLocal
  1628. )
  1629. {
  1630. DNS_STATUS status;
  1631. DWORD dwValue = -1;
  1632. status = DnssrvResetZoneMastersEx(
  1633. PVD_DNS_LOCAL_SERVER,
  1634. strZoneName.data(),
  1635. cMasterIp,
  1636. pMasterIp,
  1637. dwLocal );
  1638. if ( status != ERROR_SUCCESS )
  1639. {
  1640. ThrowException(status);
  1641. }
  1642. return WBEM_S_NO_ERROR;
  1643. }
  1644. SCODE
  1645. CDnsWrap::dnsZonePut(
  1646. CWbemClassObject& Inst
  1647. )
  1648. /*++
  1649. Routine Description:
  1650. This function commits all of the property values in a zone
  1651. object to the DNS server.
  1652. Arguments:
  1653. Inst -- zone object
  1654. Return Value:
  1655. S_OK on success.
  1656. --*/
  1657. {
  1658. DBG_FN( "CDnsWrap::dnsZonePut" )
  1659. SCODE sc;
  1660. DNS_STATUS status = ERROR_SUCCESS;
  1661. DWORD dwProperty = 0;
  1662. DWORD dwZoneType = -1;
  1663. DWORD * dwArray = NULL;
  1664. DWORD dwArraySize = 0;
  1665. string strZoneName;
  1666. string strDataFile;
  1667. DWORD dwValue;
  1668. #define DNS_CHECK_STATUS() if ( status != ERROR_SUCCESS ) goto Done
  1669. //
  1670. // Get basic properties of the new zone.
  1671. //
  1672. Inst.GetProperty( strZoneName, PVD_DOMAIN_CONTAINER_NAME );
  1673. Inst.GetProperty( &dwZoneType, PVD_ZONE_ZONE_TYPE );
  1674. DNS_DEBUG( INSTPROV, (
  1675. "%s: zone %s\n", fn, strZoneName.c_str() ));
  1676. //
  1677. // Retrieve properties from the class object and set values
  1678. // to the server.
  1679. //
  1680. if( dwZoneType == DNS_ZONE_TYPE_PRIMARY &&
  1681. Inst.GetProperty(
  1682. &dwProperty,
  1683. PVD_ZONE_ALLOW_UPDATE ) == S_OK )
  1684. {
  1685. status = dnsSetProperty(
  1686. strZoneName.data(),
  1687. DNS_REGKEY_ZONE_ALLOW_UPDATE,
  1688. dwProperty );
  1689. DNS_CHECK_STATUS();
  1690. }
  1691. if( Inst.GetProperty(
  1692. &dwProperty,
  1693. PVD_ZONE_REFRESH_INTERVAL ) == S_OK )
  1694. {
  1695. status = dnsSetProperty(
  1696. strZoneName.data(),
  1697. DNS_REGKEY_ZONE_REFRESH_INTERVAL,
  1698. dwProperty );
  1699. DNS_CHECK_STATUS();
  1700. }
  1701. if( Inst.GetProperty(
  1702. &dwProperty,
  1703. PVD_ZONE_NOREFRESH_INTERVAL ) == S_OK )
  1704. {
  1705. status = dnsSetProperty(
  1706. strZoneName.data(),
  1707. DNS_REGKEY_ZONE_NOREFRESH_INTERVAL,
  1708. dwProperty );
  1709. DNS_CHECK_STATUS();
  1710. }
  1711. status = dnsSetIPArrayProperty(
  1712. strZoneName.data(),
  1713. MYTEXT( DNS_REGKEY_ZONE_MASTERS ),
  1714. DNS_REGKEY_ZONE_MASTERS,
  1715. Inst );
  1716. DNS_CHECK_STATUS();
  1717. status = dnsSetIPArrayProperty(
  1718. strZoneName.data(),
  1719. MYTEXT( DNS_REGKEY_ZONE_LOCAL_MASTERS ),
  1720. DNS_REGKEY_ZONE_LOCAL_MASTERS,
  1721. Inst );
  1722. DNS_CHECK_STATUS();
  1723. status = dnsSetIPArrayProperty(
  1724. strZoneName.data(),
  1725. MYTEXT( DNS_REGKEY_ZONE_SCAVENGE_SERVERS ),
  1726. DNS_REGKEY_ZONE_SCAVENGE_SERVERS,
  1727. Inst );
  1728. DNS_CHECK_STATUS();
  1729. //
  1730. // Forwarder zone properties.
  1731. //
  1732. if ( dwZoneType == DNS_ZONE_TYPE_FORWARDER )
  1733. {
  1734. if( Inst.GetProperty(
  1735. &dwProperty,
  1736. MYTEXT( DNS_REGKEY_ZONE_FWD_SLAVE ) ) == S_OK )
  1737. {
  1738. status = dnsSetProperty(
  1739. strZoneName.data(),
  1740. DNS_REGKEY_ZONE_FWD_SLAVE,
  1741. dwProperty );
  1742. DNS_CHECK_STATUS();
  1743. }
  1744. if( Inst.GetProperty(
  1745. &dwProperty,
  1746. MYTEXT( DNS_REGKEY_ZONE_FWD_TIMEOUT ) ) == S_OK )
  1747. {
  1748. status = dnsSetProperty(
  1749. strZoneName.data(),
  1750. DNS_REGKEY_ZONE_FWD_TIMEOUT,
  1751. dwProperty );
  1752. DNS_CHECK_STATUS();
  1753. }
  1754. }
  1755. //
  1756. // To handle the zone data file, call DnssrvResetZoneDatabase
  1757. //
  1758. dwValue = 0;
  1759. DnssrvQueryDwordProperty(
  1760. PVD_DNS_LOCAL_SERVER,
  1761. strZoneName.data(),
  1762. DNS_REGKEY_ZONE_DS_INTEGRATED,
  1763. &dwValue );
  1764. if( Inst.GetProperty(
  1765. strDataFile,
  1766. PVD_ZONE_DATA_FILE ) == S_OK )
  1767. {
  1768. if( status == S_OK && dwZoneType != 0 && !strDataFile.empty() )
  1769. {
  1770. status = DnssrvResetZoneDatabase(
  1771. PVD_DNS_LOCAL_SERVER,
  1772. strZoneName.data(),
  1773. dwValue,
  1774. strDataFile.data() );
  1775. DNS_CHECK_STATUS();
  1776. }
  1777. }
  1778. Done:
  1779. if ( status != ERROR_SUCCESS )
  1780. {
  1781. DNS_DEBUG( INSTPROV, (
  1782. "%s: zone %s throwing %d\n", fn, strZoneName.c_str(), status ));
  1783. ThrowException( status );
  1784. }
  1785. DNS_DEBUG( INSTPROV, (
  1786. "%s: zone %s returning WBEM_S_NO_ERROR\n", fn, strZoneName.c_str() ));
  1787. return WBEM_S_NO_ERROR;
  1788. #undef DNS_CHECK_STATUS
  1789. }
  1790. static SCODE
  1791. dnsWrapCreateStatistic(
  1792. IWbemClassObject * pClass,
  1793. IWbemObjectSink * pHandler,
  1794. DWORD dwStatCollection,
  1795. const WCHAR * pszStatisticName,
  1796. CIMTYPE cimType,
  1797. const void * value
  1798. )
  1799. /*++
  1800. Routine Description:
  1801. Creates and populates a single DNS statistic object.
  1802. Arguments:
  1803. pClass -- MicrosoftDNS_Statistic class object used to spawn new instance
  1804. dwStatCollection -- index into global collection array
  1805. pszStatisticName -- statistic name
  1806. cimType - type of statistic
  1807. VT_UI4: value is a DWORD
  1808. VT_BSTR: value is a pointer to a string
  1809. value - interpret as per cimType
  1810. Return Value:
  1811. S_OK or error code.
  1812. --*/
  1813. {
  1814. CDnsWrap & dns = CDnsWrap::DnsObject();
  1815. CWbemClassObject Inst;
  1816. pClass->SpawnInstance( 0, &Inst);
  1817. Inst.SetProperty( dns.GetServerName(), PVD_DOMAIN_SERVER_NAME );
  1818. Inst.SetProperty( g_StatInfo[ dwStatCollection ].pszName, L"CollectionName" );
  1819. Inst.SetProperty( g_StatInfo[ dwStatCollection ].dwStatId, L"CollectionId" );
  1820. Inst.SetProperty( pszStatisticName, L"Name" );
  1821. if ( cimType == VT_BSTR )
  1822. {
  1823. Inst.SetProperty( ( LPCWSTR ) value, L"StringValue" );
  1824. }
  1825. else
  1826. {
  1827. DWORD dw = ( DWORD ) ( DWORD_PTR ) value;
  1828. Inst.SetProperty( dw, L"Value" );
  1829. }
  1830. pHandler->Indicate( 1, &Inst );
  1831. return S_OK;
  1832. } // dnsWrapCreateStatistic
  1833. static SCODE
  1834. dnsWrapAddStatisticsForTypeArray(
  1835. IWbemClassObject * pClass,
  1836. IWbemObjectSink * pHandler,
  1837. DWORD statCollIdx,
  1838. PWSTR pszHeader,
  1839. PDWORD pArray
  1840. )
  1841. /*++
  1842. Routine Description:
  1843. Adds DWORD statistics for each member of a type array.
  1844. Arguments:
  1845. pClass -- WMI statistic class
  1846. pHandler -- WMI object sink
  1847. statCollIdx -- index into global stat information array
  1848. pszHeader -- header text used to format statistic description
  1849. pArray -- array of DWORDs for types
  1850. Return Value:
  1851. None
  1852. --*/
  1853. {
  1854. WCHAR sz[ 80 ];
  1855. #define dwStat( pwszName, dwValue ) \
  1856. dnsWrapCreateStatistic( \
  1857. pClass, \
  1858. pHandler, \
  1859. statCollIdx, \
  1860. pwszName, \
  1861. VT_UI4, \
  1862. ( void * ) ( DWORD_PTR ) ( dwValue ) );
  1863. for ( DWORD i = 0; i < STATS_TYPE_MAX; i++ )
  1864. {
  1865. if ( i == STATS_TYPE_MIXED || i == STATS_TYPE_UNKNOWN )
  1866. {
  1867. continue;
  1868. }
  1869. wsprintfW(
  1870. sz,
  1871. L"%s for %S type",
  1872. pszHeader,
  1873. Dns_RecordStringForType( ( WORD ) i ) );
  1874. dwStat( sz, pArray[ i ] );
  1875. }
  1876. wsprintfW(
  1877. sz,
  1878. L"%s for unknown type",
  1879. pszHeader );
  1880. dwStat( sz, pArray[ STATS_TYPE_UNKNOWN ] );
  1881. wsprintfW(
  1882. sz,
  1883. L"%s for mixed type",
  1884. pszHeader );
  1885. dwStat( sz, pArray[ STATS_TYPE_MIXED ] );
  1886. #undef dwStat
  1887. return S_OK;
  1888. } // dnsWrapAddStatisticsForTypeArray
  1889. static SCODE
  1890. dnsWrapHandleSingleStat(
  1891. IWbemClassObject * pClass,
  1892. IWbemObjectSink * pHandler,
  1893. PDNSSRV_STAT pStat
  1894. )
  1895. /*++
  1896. Routine Description:
  1897. Process a single statistic buffer by creating Statistic object
  1898. instances for each of the members of the stat buffer.
  1899. Arguments:
  1900. pClass -- WMI statistic class
  1901. pHandler -- WMI object sink
  1902. pStat -- buffer of stats to process
  1903. Return Value:
  1904. None
  1905. --*/
  1906. {
  1907. SCODE sc = S_OK;
  1908. const int szBufferLen = 254;
  1909. WCHAR szBuffer[ szBufferLen ];
  1910. SAFEARRAY * psa = NULL;
  1911. SAFEARRAYBOUND rgsabound[ 1 ] = { 0, 0 };
  1912. int statCollIdx = -1;
  1913. //
  1914. // Get index into g_StatInfo element for this stat.
  1915. //
  1916. for ( int i = 0;
  1917. g_StatInfo[ i ].dwStatId != 0 &&
  1918. g_StatInfo[ i ].dwStatId != pStat->Header.StatId;
  1919. ++i );
  1920. if ( g_StatInfo[ i ].dwStatId != 0 )
  1921. {
  1922. statCollIdx = i;
  1923. }
  1924. //
  1925. // Macros to creating individual stat objects.
  1926. //
  1927. #define strStat( pwszName, pwszValue ) \
  1928. dnsWrapCreateStatistic( \
  1929. pClass, \
  1930. pHandler, \
  1931. statCollIdx, \
  1932. pwszName, \
  1933. VT_BSTR, \
  1934. pwszValue );
  1935. #define dwStat( pwszName, dwValue ) \
  1936. dnsWrapCreateStatistic( \
  1937. pClass, \
  1938. pHandler, \
  1939. statCollIdx, \
  1940. pwszName, \
  1941. VT_UI4, \
  1942. ( void * ) ( DWORD_PTR ) ( dwValue ) );
  1943. //
  1944. // Process the individual statistics in this stat collection.
  1945. //
  1946. switch ( pStat->Header.StatId )
  1947. {
  1948. case DNSSRV_STATID_TIME:
  1949. {
  1950. PDNSSRV_TIME_STATS pstat = ( PDNSSRV_TIME_STATS ) pStat;
  1951. SYSTEMTIME localTime;
  1952. SystemTimeToTzSpecificLocalTime(
  1953. NULL,
  1954. ( PSYSTEMTIME ) &pstat->ServerStartTime,
  1955. &localTime );
  1956. GetDateFormatW(
  1957. LOCALE_SYSTEM_DEFAULT,
  1958. LOCALE_NOUSEROVERRIDE,
  1959. &localTime,
  1960. NULL,
  1961. szBuffer,
  1962. szBufferLen );
  1963. wcscat( szBuffer, L" " );
  1964. GetTimeFormatW(
  1965. LOCALE_SYSTEM_DEFAULT,
  1966. LOCALE_NOUSEROVERRIDE,
  1967. &localTime,
  1968. NULL,
  1969. szBuffer + wcslen( szBuffer ),
  1970. szBufferLen - wcslen( szBuffer ) );
  1971. strStat( L"Server started", szBuffer );
  1972. SystemTimeToTzSpecificLocalTime(
  1973. NULL,
  1974. ( PSYSTEMTIME ) &pstat->LastClearTime,
  1975. &localTime );
  1976. GetDateFormatW(
  1977. LOCALE_SYSTEM_DEFAULT,
  1978. LOCALE_NOUSEROVERRIDE,
  1979. &localTime,
  1980. NULL,
  1981. szBuffer,
  1982. szBufferLen );
  1983. wcscat( szBuffer, L" " );
  1984. GetTimeFormatW(
  1985. LOCALE_SYSTEM_DEFAULT,
  1986. LOCALE_NOUSEROVERRIDE,
  1987. &localTime,
  1988. NULL,
  1989. szBuffer + wcslen( szBuffer ),
  1990. szBufferLen - wcslen( szBuffer ) );
  1991. strStat( L"Statistics last cleared", szBuffer );
  1992. break;
  1993. }
  1994. case DNSSRV_STATID_QUERY:
  1995. {
  1996. PDNSSRV_QUERY_STATS pstat = ( PDNSSRV_QUERY_STATS ) pStat;
  1997. dwStat( L"Queries received", pstat->UdpQueries + pstat->TcpQueries );
  1998. dwStat( L"Responses sent", pstat->UdpResponses + pstat->TcpResponses );
  1999. dwStat( L"UDP queries received", pstat->UdpQueries );
  2000. dwStat( L"UDP responses sent", pstat->UdpResponses );
  2001. dwStat( L"UDP queries sent", pstat->UdpQueriesSent );
  2002. dwStat( L"UDP responses received", pstat->UdpResponsesReceived );
  2003. dwStat( L"TCP client connections", pstat->TcpClientConnections );
  2004. dwStat( L"TCP queries received", pstat->TcpQueries );
  2005. dwStat( L"TCP responses sent", pstat->TcpResponses );
  2006. dwStat( L"TCP queries sent", pstat->TcpQueriesSent );
  2007. dwStat( L"TCP responses received", pstat->TcpResponsesReceived );
  2008. break;
  2009. }
  2010. case DNSSRV_STATID_QUERY2:
  2011. {
  2012. PDNSSRV_QUERY2_STATS pstat = ( PDNSSRV_QUERY2_STATS ) pStat;
  2013. dwStat( L"Total queries", pstat->TotalQueries );
  2014. dwStat( L"Notify queries", pstat->Notify );
  2015. dwStat( L"Update queries", pstat->Update );
  2016. dwStat( L"TKeyNego queries", pstat->TKeyNego );
  2017. dwStat( L"Standard queries", pstat->Standard );
  2018. dwStat( L"A queries", pstat->TypeA );
  2019. dwStat( L"NS queries", pstat->TypeNs );
  2020. dwStat( L"SOA queries", pstat->TypeSoa );
  2021. dwStat( L"MX queries", pstat->TypeMx );
  2022. dwStat( L"PTR queries", pstat->TypePtr );
  2023. dwStat( L"SRV queries", pstat->TypeSrv );
  2024. dwStat( L"ALL queries", pstat->TypeAll );
  2025. dwStat( L"IXFR queries", pstat->TypeIxfr );
  2026. dwStat( L"AXFR queries", pstat->TypeAxfr );
  2027. dwStat( L"Other queries", pstat->TypeOther );
  2028. break;
  2029. }
  2030. case DNSSRV_STATID_RECURSE:
  2031. {
  2032. PDNSSRV_RECURSE_STATS pstat = ( PDNSSRV_RECURSE_STATS ) pStat;
  2033. dwStat( L"Queries recursed", pstat->QueriesRecursed );
  2034. dwStat( L"Original questions recursed", pstat->OriginalQuestionRecursed );
  2035. dwStat( L"Additional questions recursed", pstat->AdditionalRecursed );
  2036. dwStat( L"Total questions recursed", pstat->TotalQuestionsRecursed );
  2037. dwStat( L"Original questions recursed", pstat->OriginalQuestionRecursed );
  2038. dwStat( L"Retries", pstat->Retries );
  2039. dwStat( L"Total passes", pstat->LookupPasses );
  2040. dwStat( L"To forwarders", pstat->Forwards );
  2041. dwStat( L"Sends", pstat->Sends );
  2042. dwStat( L"Total responses", pstat->Responses );
  2043. dwStat( L"Responses unmatched", pstat->ResponseUnmatched );
  2044. dwStat( L"Responses mismatched", pstat->ResponseMismatched );
  2045. dwStat( L"Responses from forwarders", pstat->ResponseFromForwarder );
  2046. dwStat( L"Authoritative responses", pstat->ResponseAuthoritative );
  2047. dwStat( L"NotAuthoritative responses", pstat->ResponseNotAuth );
  2048. dwStat( L"Answer responses", pstat->ResponseAnswer );
  2049. dwStat( L"Empty responses", pstat->ResponseEmpty );
  2050. dwStat( L"Name error responses", pstat->ResponseAnswer );
  2051. dwStat( L"Rcode responses", pstat->ResponseRcode );
  2052. dwStat( L"Delegation responses", pstat->ResponseDelegation );
  2053. dwStat( L"Non-zone data responses", pstat->ResponseNonZoneData );
  2054. dwStat( L"Unsecure responses", pstat->ResponseUnsecure );
  2055. dwStat( L"Bad packet responses", pstat->ResponseBadPacket );
  2056. dwStat( L"Forwarded responses", pstat->SendResponseDirect );
  2057. dwStat( L"Continue current recursion responses", pstat->ContinueCurrentRecursion );
  2058. dwStat( L"Continue current lookup responses", pstat->ContinueCurrentLookup );
  2059. dwStat( L"Continue next lookup responses", pstat->ContinueNextLookup );
  2060. dwStat( L"Send timeouts", pstat->PacketTimeout );
  2061. dwStat( L"Final queued timeouts", pstat->FinalTimeoutQueued );
  2062. dwStat( L"Final timeouts expired", pstat->FinalTimeoutExpired );
  2063. dwStat( L"Recurse failures", pstat->RecursePassFailure );
  2064. dwStat( L"Into authority failures", pstat->FailureReachAuthority );
  2065. dwStat( L"Previous zone failures", pstat->FailureReachPreviousResponse );
  2066. dwStat( L"Retry count failures", pstat->FailureRetryCount );
  2067. dwStat( L"Cache update failures", pstat->CacheUpdateFailure );
  2068. dwStat( L"Server failure responses", pstat->ServerFailure );
  2069. dwStat( L"Total failures", pstat->Failures );
  2070. dwStat( L"TCP recursions tried", pstat->TcpTry );
  2071. dwStat( L"TCP recursion queries", pstat->TcpQuery );
  2072. dwStat( L"TCP recursion responses", pstat->TcpResponse );
  2073. dwStat( L"TCP recursion disconnects", pstat->TcpDisconnect );
  2074. dwStat( L"Cache update queries allocated", pstat->CacheUpdateAlloc );
  2075. dwStat( L"Cache update query responses", pstat->CacheUpdateResponse );
  2076. dwStat( L"Cache update query retries", pstat->CacheUpdateRetry );
  2077. dwStat( L"Cache update queries freed", pstat->CacheUpdateFree );
  2078. dwStat( L"Cache update queries for root NS", pstat->RootNsQuery );
  2079. dwStat( L"Cache update responses for root NS", pstat->RootNsResponse );
  2080. dwStat( L"Cache update queries suspended", pstat->SuspendedQuery );
  2081. dwStat( L"Cache update queries resumed", pstat->ResumeSuspendedQuery );
  2082. break;
  2083. }
  2084. case DNSSRV_STATID_MASTER:
  2085. {
  2086. PDNSSRV_MASTER_STATS pstat = ( PDNSSRV_MASTER_STATS ) pStat;
  2087. dwStat( L"Notifies sent", pstat->NotifySent );
  2088. dwStat( L"Requests", pstat->Request );
  2089. dwStat( L"NameErrors", pstat->NameError );
  2090. dwStat( L"FormErrors", pstat->FormError );
  2091. dwStat( L"Refused", pstat->Refused );
  2092. dwStat( L"AxfrLimit refused", pstat->AxfrLimit );
  2093. dwStat( L"Security refused", pstat->RefuseSecurity );
  2094. dwStat( L"Shutdown refused", pstat->RefuseShutdown );
  2095. dwStat( L"ServFail refused", pstat->RefuseServerFailure );
  2096. dwStat( L"Transfer failures", pstat->Failure );
  2097. dwStat( L"Transfer successes", pstat->AxfrSuccess + pstat->IxfrUpdateSuccess );
  2098. dwStat( L"AXFR requests", pstat->AxfrRequest );
  2099. dwStat( L"AXFR successes", pstat->AxfrSuccess );
  2100. dwStat( L"AXFR in IXFR", pstat->IxfrAxfr );
  2101. dwStat( L"IXFR requests", pstat->IxfrRequest );
  2102. dwStat( L"IXFR successes", pstat->IxfrUpdateSuccess );
  2103. dwStat( L"IXFR UDP requests", pstat->IxfrUdpRequest );
  2104. dwStat( L"IXFR UDP successes", pstat->IxfrUdpSuccess );
  2105. dwStat( L"IXFR UDP force TCP", pstat->IxfrUdpForceTcp );
  2106. dwStat( L"IXFR UDP force AXFR", pstat->IxfrUdpForceAxfr );
  2107. dwStat( L"IXFR TCP requests", pstat->IxfrTcpRequest );
  2108. dwStat( L"IXFR TCP successes", pstat->IxfrTcpSuccess );
  2109. dwStat( L"IXFR TCP force AXFR", pstat->IxfrAxfr );
  2110. break;
  2111. }
  2112. case DNSSRV_STATID_SECONDARY:
  2113. {
  2114. PDNSSRV_SECONDARY_STATS pstat = (PDNSSRV_SECONDARY_STATS)pStat;
  2115. dwStat( L"Notifies received", pstat->NotifyReceived );
  2116. dwStat( L"Notifies invalid", pstat->NotifyInvalid );
  2117. dwStat( L"Notifies primary", pstat->NotifyPrimary );
  2118. dwStat( L"Notifies no version", pstat->NotifyNoVersion );
  2119. dwStat( L"Notifies new version", pstat->NotifyNewVersion );
  2120. dwStat( L"Notifies current version", pstat->NotifyCurrentVersion );
  2121. dwStat( L"Notifies old version", pstat->NotifyOldVersion );
  2122. dwStat( L"Notifies master unknown", pstat->NotifyMasterUnknown );
  2123. dwStat( L"SOA requests", pstat->SoaRequest );
  2124. dwStat( L"SOA responses", pstat->SoaResponse );
  2125. dwStat( L"SOA invalid responses", pstat->SoaResponseInvalid );
  2126. dwStat( L"SOA NameError responses", pstat->SoaResponseNameError );
  2127. dwStat( L"AXFR requests", pstat->AxfrRequest );
  2128. dwStat( L"AXFR in IXFR requests", pstat->IxfrTcpAxfr );
  2129. dwStat( L"AXFR responses", pstat->AxfrResponse );
  2130. dwStat( L"AXFR success responses", pstat->AxfrSuccess );
  2131. dwStat( L"AXFR refused responses", pstat->AxfrRefused );
  2132. dwStat( L"AXFR invalid responses", pstat->AxfrInvalid );
  2133. dwStat( L"Stub zone AXFR requests", pstat->StubAxfrRequest );
  2134. dwStat( L"Stub zone AXFR responses", pstat->StubAxfrResponse );
  2135. dwStat( L"Stub zone AXFR success responses", pstat->StubAxfrSuccess );
  2136. dwStat( L"Stub zone AXFR refused responses", pstat->StubAxfrRefused );
  2137. dwStat( L"Stub zone AXFR invalid responses", pstat->StubAxfrInvalid );
  2138. dwStat( L"IXFR UDP requests", pstat->IxfrUdpRequest );
  2139. dwStat( L"IXFR UDP responses", pstat->IxfrUdpResponse );
  2140. dwStat( L"IXFR UDP success responses", pstat->IxfrUdpSuccess );
  2141. dwStat( L"IXFR UDP UseTcp responses", pstat->IxfrUdpUseTcp );
  2142. dwStat( L"IXFR UDP UseAxfr responses", pstat->IxfrUdpUseAxfr );
  2143. dwStat( L"IXFR UDP new primary responses", pstat->IxfrUdpNewPrimary );
  2144. dwStat( L"IXFR UDP refused responses", pstat->IxfrUdpRefused );
  2145. dwStat( L"IXFR UDP wrong server responses", pstat->IxfrUdpWrongServer );
  2146. dwStat( L"IXFR UDP FormError responses", pstat->IxfrUdpFormerr );
  2147. dwStat( L"IXFR UDP invalid responses", pstat->IxfrUdpInvalid );
  2148. dwStat( L"IXFR TCP requests", pstat->IxfrTcpRequest );
  2149. dwStat( L"IXFR TCP responses", pstat->IxfrTcpResponse );
  2150. dwStat( L"IXFR TCP success responses", pstat->IxfrTcpSuccess );
  2151. dwStat( L"IXFR TCP AXFR responses", pstat->IxfrTcpAxfr );
  2152. dwStat( L"IXFR TCP FormError responses", pstat->IxfrTcpFormerr );
  2153. dwStat( L"IXFR TCP refused responses", pstat->IxfrTcpRefused );
  2154. dwStat( L"IXFR TCP invalid responses", pstat->IxfrTcpInvalid );
  2155. break;
  2156. }
  2157. case DNSSRV_STATID_WINS:
  2158. {
  2159. PDNSSRV_WINS_STATS pstat = ( PDNSSRV_WINS_STATS ) pStat;
  2160. dwStat( L"WINS forward lookups", pstat->WinsLookups );
  2161. dwStat( L"WINS forward lookup responses", pstat->WinsResponses );
  2162. dwStat( L"WINS reverse lookups", pstat->WinsReverseLookups );
  2163. dwStat( L"WINS reverse lookup responses", pstat->WinsReverseResponses );
  2164. break;
  2165. }
  2166. case DNSSRV_STATID_NBSTAT:
  2167. {
  2168. PDNSSRV_NBSTAT_STATS pstat = (PDNSSRV_NBSTAT_STATS)pStat;
  2169. dwStat( L"Nbstat total buffers allocated", pstat->NbstatAlloc );
  2170. dwStat( L"Nbstat total buffers freed", pstat->NbstatFree );
  2171. dwStat( L"Nbstat net buffers allocated", pstat->NbstatNetAllocs );
  2172. dwStat( L"Nbstat net bytes allocated", pstat->NbstatMemory );
  2173. dwStat( L"Nbstat memory highwater mark", pstat->NbstatUsed );
  2174. dwStat( L"Nbstat buffers returned", pstat->NbstatReturn );
  2175. dwStat( L"Nbstat buffers in use", pstat->NbstatInUse );
  2176. dwStat( L"Nbstat buffers on free list", pstat->NbstatInFreeList );
  2177. break;
  2178. }
  2179. case DNSSRV_STATID_WIRE_UPDATE:
  2180. case DNSSRV_STATID_NONWIRE_UPDATE:
  2181. {
  2182. PDNSSRV_UPDATE_STATS pstat = ( PDNSSRV_UPDATE_STATS ) pStat;
  2183. dwStat( L"Updates received", pstat->Received );
  2184. dwStat( L"Updates forwarded", pstat->Forwards );
  2185. dwStat( L"Updates retried", pstat->Retry );
  2186. dwStat( L"Updates empty (precon only)", pstat->Empty );
  2187. dwStat( L"Updates NoOps (duplicates)", pstat->NoOps );
  2188. dwStat( L"Updates rejected", pstat->Rejected );
  2189. dwStat( L"Updates completed", pstat->Completed );
  2190. dwStat( L"Updates timed out", pstat->Timeout );
  2191. dwStat( L"Updates in queue", pstat->InQueue );
  2192. dwStat( L"Updates rejected", pstat->Rejected );
  2193. dwStat( L"Updates rejected with FormError", pstat->FormErr );
  2194. dwStat( L"Updates rejected with NameError", pstat->NxDomain );
  2195. dwStat( L"Updates rejected with NotImpl", pstat->NotImpl );
  2196. dwStat( L"Updates rejected with Refused", pstat->Refused );
  2197. dwStat( L"Updates rejected with Refused (nonsecure)", pstat->RefusedNonSecure );
  2198. dwStat( L"Updates rejected with Refused (access denied)", pstat->RefusedAccessDenied );
  2199. dwStat( L"Updates rejected with YxDomain", pstat->YxDomain );
  2200. dwStat( L"Updates rejected with YxRRSet", pstat->YxRrset );
  2201. dwStat( L"Updates rejected with NxRRSet", pstat->NxRrset );
  2202. dwStat( L"Updates rejected with NotAuth", pstat->NotAuth );
  2203. dwStat( L"Updates rejected with NotZone", pstat->NotZone );
  2204. dwStat( L"Secure update successes", pstat->SecureSuccess );
  2205. dwStat( L"Secure update continues", pstat->SecureContinue );
  2206. dwStat( L"Secure update failures", pstat->SecureFailure );
  2207. dwStat( L"Secure update DS write failures", pstat->SecureDsWriteFailure );
  2208. dwStat( L"Updates forwarded via TCP", pstat->TcpForwards );
  2209. dwStat( L"Responses for forwarded updates", pstat->ForwardResponses );
  2210. dwStat( L"Timeouts for forwarded updates", pstat->ForwardTimeouts );
  2211. dwStat( L"Forwarded updates in queue", pstat->ForwardInQueue );
  2212. dnsWrapAddStatisticsForTypeArray(
  2213. pClass,
  2214. pHandler,
  2215. statCollIdx,
  2216. L"Updates",
  2217. pstat->UpdateType );
  2218. break;
  2219. }
  2220. case DNSSRV_STATID_DS:
  2221. {
  2222. PDNSSRV_DS_STATS pstat = ( PDNSSRV_DS_STATS ) pStat;
  2223. dwStat( L"Nodes read", pstat->DsTotalNodesRead );
  2224. dwStat( L"Records read", pstat->DsTotalRecordsRead );
  2225. dwStat( L"Nodes loaded", pstat->DsNodesLoaded );
  2226. dwStat( L"Records loaded", pstat->DsRecordsLoaded );
  2227. dwStat( L"Update searches", pstat->DsUpdateSearches );
  2228. dwStat( L"Update nodes read", pstat->DsUpdateNodesRead );
  2229. dwStat( L"Update records read", pstat->DsUpdateRecordsRead );
  2230. dwStat( L"Nodes added", pstat->DsNodesAdded );
  2231. dwStat( L"Nodes modified", pstat->DsNodesModified );
  2232. dwStat( L"Nodes tombstoned", pstat->DsNodesTombstoned );
  2233. dwStat( L"Tombstones read", pstat->DsTombstonesRead );
  2234. dwStat( L"Nodes deleted", pstat->DsNodesDeleted );
  2235. dwStat( L"Nodes write suppressed", pstat->DsWriteSuppressed );
  2236. dwStat( L"RR sets added", pstat->DsRecordsAdded );
  2237. dwStat( L"RR sets replaced", pstat->DsRecordsReplaced );
  2238. dwStat( L"Serial number writes", pstat->DsSerialWrites );
  2239. dwStat( L"Update lists", pstat->UpdateLists );
  2240. dwStat( L"Update nodes", pstat->UpdateNodes );
  2241. dwStat( L"Updates suppressed ", pstat->UpdateSuppressed );
  2242. dwStat( L"Update writes", pstat->UpdateWrites );
  2243. dwStat( L"Update tombstones", pstat->UpdateTombstones );
  2244. dwStat( L"Update record changes", pstat->UpdateRecordChange );
  2245. dwStat( L"Update aging refresh", pstat->UpdateAgingRefresh );
  2246. dwStat( L"Update aging on", pstat->UpdateAgingOn );
  2247. dwStat( L"Update aging off", pstat->UpdateAgingOff );
  2248. dwStat( L"Update from packet", pstat->UpdatePacket );
  2249. dwStat( L"Update from packet (precon)", pstat->UpdatePacketPrecon );
  2250. dwStat( L"Update from admin", pstat->UpdateAdmin );
  2251. dwStat( L"Update from auto config", pstat->UpdateAutoConfig );
  2252. dwStat( L"Update from scavenge", pstat->UpdateScavenge );
  2253. dwStat( L"LDAP timed writes", pstat->LdapTimedWrites );
  2254. dwStat( L"LDAP total write time", pstat->LdapWriteTimeTotal );
  2255. dwStat( L"LDAP average write time", pstat->LdapWriteAverage );
  2256. dwStat( L"LDAP writes < 10 ms", pstat->LdapWriteBucket0 );
  2257. dwStat( L"LDAP writes < 100 ms", pstat->LdapWriteBucket1 );
  2258. dwStat( L"LDAP writes < 1 s", pstat->LdapWriteBucket2 );
  2259. dwStat( L"LDAP writes < 10 s", pstat->LdapWriteBucket3 );
  2260. dwStat( L"LDAP writes < 100 s", pstat->LdapWriteBucket4 );
  2261. dwStat( L"LDAP writes > 100 s", pstat->LdapWriteBucket5 );
  2262. dwStat( L"LDAP writes max timeout", pstat->LdapWriteMax );
  2263. dwStat( L"Total LDAP search time", pstat->LdapSearchTime );
  2264. dwStat( L"Failed deletions", pstat->FailedDeleteDsEntries );
  2265. dwStat( L"Failed reads", pstat->FailedReadRecords );
  2266. dwStat( L"Failed modifies", pstat->FailedLdapModify );
  2267. dwStat( L"Failed adds", pstat->FailedLdapAdd );
  2268. dwStat( L"Polling passes with DS errors", pstat->PollingPassesWithDsErrors );
  2269. dnsWrapAddStatisticsForTypeArray(
  2270. pClass,
  2271. pHandler,
  2272. statCollIdx,
  2273. L"LDAP writes",
  2274. pstat->DsWriteType );
  2275. break;
  2276. }
  2277. case DNSSRV_STATID_SKWANSEC:
  2278. {
  2279. PDNSSRV_SKWANSEC_STATS pstat = ( PDNSSRV_SKWANSEC_STATS ) pStat;
  2280. dwStat( L"Security contexts created", pstat->SecContextCreate );
  2281. dwStat( L"Security contexts freed", pstat->SecContextFree );
  2282. dwStat( L"Security contexts timed out", pstat->SecContextTimeout );
  2283. dwStat( L"Security contexts queue length", pstat->SecContextQueueLength );
  2284. dwStat( L"Security contexts queued", pstat->SecContextQueue );
  2285. dwStat( L"Security contexts queued in negotiation", pstat->SecContextQueueInNego );
  2286. dwStat( L"Security contexts queued negotiation complete", pstat->SecContextQueueNegoComplete );
  2287. dwStat( L"Security contexts dequeued", pstat->SecContextDequeue );
  2288. dwStat( L"Security packet contexts allocated", pstat->SecPackAlloc );
  2289. dwStat( L"Security packet contexts freed", pstat->SecPackFree );
  2290. dwStat( L"Invalid TKEYs", pstat->SecTkeyInvalid );
  2291. dwStat( L"Bad time TKEYs", pstat->SecTkeyBadTime );
  2292. dwStat( L"FormErr TSIGs", pstat->SecTsigFormerr );
  2293. dwStat( L"Echo TSIGs", pstat->SecTsigEcho );
  2294. dwStat( L"BadKey TSIGs", pstat->SecTsigBadKey );
  2295. dwStat( L"Verify success TSIGs", pstat->SecTsigVerifySuccess );
  2296. dwStat( L"Verify failed TSIGs", pstat->SecTsigVerifyFailed );
  2297. break;
  2298. }
  2299. case DNSSRV_STATID_MEMORY:
  2300. {
  2301. PDNSSRV_MEMORY_STATS pstat = ( PDNSSRV_MEMORY_STATS ) pStat;
  2302. LPSTR * pnameArray = MemTagStrings;
  2303. DWORD count = MEMTAG_COUNT;
  2304. dwStat( L"Total memory", pstat->StdUsed );
  2305. dwStat( L"Allocation count", pstat->Alloc );
  2306. dwStat( L"Free count", pstat->Free );
  2307. dwStat( L"Standard allocs used", pstat->StdUsed );
  2308. dwStat( L"Standard allocs returned", pstat->StdReturn );
  2309. dwStat( L"Standard allocs in use", pstat->StdInUse );
  2310. dwStat( L"Standard allocs memory", pstat->StdMemory );
  2311. dwStat( L"Standard to heap allocs used", pstat->StdToHeapAlloc );
  2312. dwStat( L"Standard to heap allocs returned", pstat->StdToHeapFree );
  2313. dwStat( L"Standard to heap allocs in use", pstat->StdToHeapInUse );
  2314. dwStat( L"Standard to heap allocs memory", pstat->StdToHeapMemory );
  2315. dwStat( L"Standard blocks allocated", pstat->StdBlockAlloc );
  2316. dwStat( L"Standard blocks used", pstat->StdBlockUsed );
  2317. dwStat( L"Standard blocks returned", pstat->StdBlockReturn );
  2318. dwStat( L"Standard blocks in use", pstat->StdBlockInUse );
  2319. dwStat( L"Standard blocks in free list", pstat->StdBlockFreeList );
  2320. dwStat( L"Standard block memory in free list", pstat->StdBlockFreeListMemory );
  2321. dwStat( L"Standard block total memory", pstat->StdBlockMemory );
  2322. for ( DWORD i = 0; i < count; ++i )
  2323. {
  2324. WCHAR sz[ 80 ];
  2325. wsprintfW( sz, L"%S blocks allocated", pnameArray[ i ] );
  2326. dwStat( sz, pstat->MemTags[ i ].Alloc );
  2327. wsprintfW( sz, L"%S blocks freed", pnameArray[ i ] );
  2328. dwStat( sz, pstat->MemTags[ i ].Free );
  2329. wsprintfW( sz, L"%S blocks in use", pnameArray[ i ] );
  2330. dwStat( sz, pstat->MemTags[ i ].Alloc - pstat->MemTags[ i ].Free );
  2331. wsprintfW( sz, L"%S memory", pnameArray[ i ] );
  2332. dwStat( sz, pstat->MemTags[ i ].Memory );
  2333. }
  2334. break;
  2335. }
  2336. case DNSSRV_STATID_DBASE:
  2337. {
  2338. PDNSSRV_DBASE_STATS pstat = ( PDNSSRV_DBASE_STATS ) pStat;
  2339. dwStat( L"Database nodes used", pstat->NodeUsed );
  2340. dwStat( L"Database nodes returned", pstat->NodeReturn );
  2341. dwStat( L"Database nodes in use", pstat->NodeInUse );
  2342. dwStat( L"Database nodes memory", pstat->NodeMemory );
  2343. break;
  2344. }
  2345. case DNSSRV_STATID_RECORD:
  2346. {
  2347. PDNSSRV_RECORD_STATS pstat = ( PDNSSRV_RECORD_STATS ) pStat;
  2348. dwStat( L"Records used", pstat->Used );
  2349. dwStat( L"Records returned", pstat->Return );
  2350. dwStat( L"Records in use", pstat->InUse );
  2351. dwStat( L"Records memory", pstat->Memory );
  2352. dwStat( L"Records queued for slow free", pstat->SlowFreeQueued );
  2353. dwStat( L"Records slow freed", pstat->SlowFreeFinished );
  2354. dwStat( L"Total records cached", pstat->CacheTotal );
  2355. dwStat( L"Records currently cached", pstat->CacheCurrent );
  2356. dwStat( L"Cached records timed out", pstat->CacheTimeouts );
  2357. break;
  2358. }
  2359. case DNSSRV_STATID_PACKET:
  2360. {
  2361. PDNSSRV_PACKET_STATS pstat = ( PDNSSRV_PACKET_STATS ) pStat;
  2362. dwStat( L"UDP messages allocated", pstat->UdpAlloc );
  2363. dwStat( L"UDP messages freed", pstat->UdpFree );
  2364. dwStat( L"UDP messages net allocations", pstat->UdpNetAllocs );
  2365. dwStat( L"UDP messages memory", pstat->UdpMemory );
  2366. dwStat( L"UDP messages used", pstat->UdpUsed );
  2367. dwStat( L"UDP messages returned", pstat->UdpReturn );
  2368. dwStat( L"UDP messages in use", pstat->UdpInUse );
  2369. dwStat( L"UDP messages in free list", pstat->UdpInFreeList );
  2370. dwStat( L"UDP messages allocated", pstat->TcpAlloc );
  2371. dwStat( L"UDP messages reallocated", pstat->TcpRealloc );
  2372. dwStat( L"UDP messages freed", pstat->TcpFree );
  2373. dwStat( L"UDP messages net allocations", pstat->TcpNetAllocs );
  2374. dwStat( L"UDP messages memory", pstat->TcpMemory );
  2375. dwStat( L"Recursion messages used", pstat->RecursePacketUsed );
  2376. dwStat( L"Recursion messages returned", pstat->RecursePacketReturn );
  2377. break;
  2378. }
  2379. case DNSSRV_STATID_TIMEOUT:
  2380. {
  2381. PDNSSRV_TIMEOUT_STATS pstat = ( PDNSSRV_TIMEOUT_STATS ) pStat;
  2382. dwStat( L"Nodes queued", pstat->SetTotal );
  2383. dwStat( L"Nodes directed queued", pstat->SetDirect );
  2384. dwStat( L"Nodes queued from reference", pstat->SetFromDereference );
  2385. dwStat( L"Nodes queued from child delete", pstat->SetFromChildDelete );
  2386. dwStat( L"Nodes duplicate (already queued)", pstat->AlreadyInSystem );
  2387. dwStat( L"Nodes checked", pstat->Checks );
  2388. dwStat( L"Recent access nodes checked", pstat->RecentAccess );
  2389. dwStat( L"Active record nodes checked", pstat->ActiveRecord );
  2390. dwStat( L"Can not delete nodes checked", pstat->CanNotDelete );
  2391. dwStat( L"Deleted nodes checked", pstat->Deleted );
  2392. dwStat( L"Timeout blocks created", pstat->ArrayBlocksCreated );
  2393. dwStat( L"Timeout blocks deleted", pstat->ArrayBlocksDeleted );
  2394. dwStat( L"Delayed frees queued", pstat->DelayedFreesQueued );
  2395. dwStat( L"Delayed frees queued with function", pstat->DelayedFreesQueuedWithFunction );
  2396. dwStat( L"Delayed frees executed", pstat->DelayedFreesExecuted );
  2397. dwStat( L"Delayed frees executed with function", pstat->DelayedFreesExecutedWithFunction );
  2398. break;
  2399. }
  2400. case DNSSRV_STATID_ERRORS:
  2401. {
  2402. PDNSSRV_ERROR_STATS pstat = ( PDNSSRV_ERROR_STATS ) pStat;
  2403. dwStat( L"NoError", pstat->NoError );
  2404. dwStat( L"FormError", pstat->FormError );
  2405. dwStat( L"ServFail", pstat->ServFail );
  2406. dwStat( L"NxDomain", pstat->NxDomain );
  2407. dwStat( L"NotImpl", pstat->NotImpl );
  2408. dwStat( L"Refused", pstat->Refused );
  2409. dwStat( L"YxDomain", pstat->YxDomain );
  2410. dwStat( L"YxRRSet", pstat->YxRRSet );
  2411. dwStat( L"NxRRSet", pstat->NxRRSet );
  2412. dwStat( L"NotAuth", pstat->NotAuth );
  2413. dwStat( L"NotZone", pstat->NotZone );
  2414. dwStat( L"Max", pstat->Max );
  2415. dwStat( L"BadSig", pstat->BadSig );
  2416. dwStat( L"BadKey", pstat->BadKey );
  2417. dwStat( L"BadTime", pstat->BadTime );
  2418. dwStat( L"UnknownError", pstat->UnknownError );
  2419. break;
  2420. }
  2421. case DNSSRV_STATID_CACHE:
  2422. {
  2423. PDNSSRV_CACHE_STATS pstat = ( PDNSSRV_CACHE_STATS ) pStat;
  2424. dwStat( L"Checks where cache exceeded limit", pstat->CacheExceededLimitChecks );
  2425. dwStat( L"Successful cache enforcement passes", pstat->SuccessfulFreePasses );
  2426. dwStat( L"Failed cache enforcement passes", pstat->FailedFreePasses );
  2427. dwStat( L"Passes requiring aggressive free", pstat->PassesRequiringAggressiveFree );
  2428. dwStat( L"Passes where nothing was freed", pstat->PassesWithNoFrees );
  2429. break;
  2430. }
  2431. default:
  2432. break;
  2433. }
  2434. //
  2435. // Cleanup and return.
  2436. //
  2437. return sc;
  2438. }
  2439. SCODE
  2440. CDnsWrap::dnsGetStatistics(
  2441. IWbemClassObject * pClass,
  2442. IWbemObjectSink * pHandler,
  2443. DWORD dwStatId
  2444. )
  2445. /*++
  2446. Routine Description:
  2447. Retrieve DNS statistics.
  2448. Arguments:
  2449. dwStatId -- statistic ID or zero for all
  2450. pClass -- ptr to StatisticsCollection class object
  2451. Return Value:
  2452. None
  2453. --*/
  2454. {
  2455. SCODE sc = S_OK;
  2456. DNS_STATUS status = ERROR_SUCCESS;
  2457. PDNS_RPC_BUFFER pstatbuff = NULL;
  2458. BSTR bstrStatClass = NULL;
  2459. IWbemClassObject * pStatClass = NULL;
  2460. //
  2461. // Retrieve RPC stat buffer from server.
  2462. //
  2463. if ( dwStatId == 0 )
  2464. {
  2465. dwStatId = DNSSRV_STATID_ALL;
  2466. }
  2467. status = DnssrvGetStatistics(
  2468. PVD_DNS_LOCAL_SERVER,
  2469. dwStatId,
  2470. &pstatbuff );
  2471. if ( status != ERROR_SUCCESS )
  2472. {
  2473. ThrowException( status );
  2474. }
  2475. if ( !pstatbuff )
  2476. {
  2477. ThrowException( ERROR_NO_DATA );
  2478. }
  2479. //
  2480. // Iterate stats in buffer. Add each "single stat" in the buffer
  2481. // to the WMI instance as a StatisticCollection. Add each individual
  2482. // statistics in each "single stat" buffer as a value to that
  2483. // statistic collection.
  2484. //
  2485. PDNSSRV_STAT pstat;
  2486. PBYTE pch = &pstatbuff->Buffer[ 0 ];
  2487. PBYTE pchstop = pch + pstatbuff->dwLength;
  2488. while ( sc == S_OK && pch < pchstop )
  2489. {
  2490. pstat = ( PDNSSRV_STAT ) pch;
  2491. pch = ( PBYTE ) GET_NEXT_STAT_IN_BUFFER( pstat );
  2492. sc = dnsWrapHandleSingleStat( pClass, pHandler, pstat );
  2493. if ( sc != S_OK )
  2494. {
  2495. break;
  2496. }
  2497. }
  2498. //
  2499. // Cleanup and return.
  2500. //
  2501. SysFreeString( bstrStatClass );
  2502. if ( pstatbuff )
  2503. {
  2504. MIDL_user_free( pstatbuff );
  2505. }
  2506. if ( pStatClass )
  2507. {
  2508. pStatClass->Release();
  2509. }
  2510. return sc;
  2511. } // CDnsWrap::dnsGetStatistics