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.

2427 lines
61 KiB

  1. /////////////////////////////////////////////////////////////////////
  2. //
  3. // CopyRight ( c ) 1999 Microsoft Corporation
  4. //
  5. // Module Name: dnsrpcreocrd.cpp
  6. //
  7. // Description:
  8. // Implementation of dns rpc related class
  9. //
  10. // Author:
  11. // Henry Wang ( henrywa ) March 8, 2000
  12. //
  13. //
  14. //////////////////////////////////////////////////////////////////////
  15. #include "DnsWmi.h"
  16. // defination for CDnsRpcmemory
  17. CDnsRpcMemory::CDnsRpcMemory()
  18. {
  19. }
  20. CDnsRpcMemory::~CDnsRpcMemory()
  21. {
  22. }
  23. PBYTE
  24. CDnsRpcMemory::IncrementPtrByNodeHead(PBYTE pByte)
  25. {
  26. pByte += ((PDNS_RPC_NODE)pByte)->wLength;
  27. return DNS_NEXT_DWORD_PTR(pByte);
  28. }
  29. PBYTE
  30. CDnsRpcMemory::IncrementPtrByRecord(PBYTE pByte)
  31. {
  32. pByte += ((PDNS_RPC_RECORD)pByte)->wDataLength
  33. + SIZEOF_DNS_RPC_RECORD_HEADER;
  34. return DNS_NEXT_DWORD_PTR(pByte);
  35. }
  36. SCODE
  37. CDnsRpcRecord::Init(
  38. string& strOwner,
  39. string& strRdata,
  40. DWORD dwTtl
  41. )
  42. {
  43. m_dwTtl = dwTtl;
  44. m_strOwnerName = strOwner;
  45. ParseRdata(strRdata, m_cRdata);
  46. return BuildRpcRecord(m_cRdata, m_ppRdata+1);
  47. }
  48. SCODE
  49. CDnsRpcRecord::Init(
  50. wstring& wstrClass,
  51. string& strOwner,
  52. string& strRdata,
  53. CWbemClassObject& Inst
  54. )
  55. {
  56. if(Inst.GetProperty(
  57. &m_dwTtl,
  58. PVD_REC_TTL) != S_OK)
  59. m_dwTtl = 0;
  60. m_strOwnerName = strOwner;
  61. if(!strRdata.empty())
  62. {
  63. ParseRdata(
  64. strRdata,
  65. m_cRdata);
  66. }
  67. // what value we got in wmi?
  68. const WCHAR** ppName = GetRdataName();
  69. for(int i = 0; i<m_cRdata; i++)
  70. {
  71. ReplaceRdata(
  72. i+1,
  73. ppName[i],
  74. Inst);
  75. }
  76. return BuildRpcRecord(m_cRdata, m_ppRdata+1);
  77. }
  78. CDnsRpcRecord::CDnsRpcRecord(
  79. WORD wRdataSize ) :
  80. m_pRecord( NULL ),
  81. m_pRecordRequiresFree( TRUE ),
  82. m_bRdataChange( FALSE ),
  83. m_cRdata( 0 )
  84. {
  85. m_ppRdata = new char* [wRdataSize+1];
  86. if ( m_ppRdata )
  87. {
  88. for(int i=0; i<= wRdataSize; i++)
  89. {
  90. m_ppRdata[i] = NULL;
  91. }
  92. m_cRdata = wRdataSize;
  93. }
  94. else
  95. {
  96. m_cRdata = 0;
  97. }
  98. }
  99. CDnsRpcRecord::~CDnsRpcRecord()
  100. {
  101. if(m_cRdata > 0)
  102. {
  103. for(int i = 0; i<= m_cRdata; i++)
  104. {
  105. delete [] m_ppRdata[i];
  106. }
  107. }
  108. delete [] m_ppRdata;
  109. if ( m_pRecord && m_pRecordRequiresFree )
  110. {
  111. FREE_HEAP( m_pRecord );
  112. }
  113. }
  114. /////////////////////////////////////////////////////////////////////////////
  115. //++
  116. //
  117. // Description:
  118. // helper function to arguments from rdata string. each time the function
  119. // is called, it sets *ppszOut to the newly allocated buffer and copy the
  120. // value over, and return a pointer that moved to the char after that rdata
  121. // argument
  122. //
  123. // Arguments:
  124. // pszIn [IN] input Rdata string
  125. // ppszOut [OUT] output string which is one of the rdata arg
  126. //
  127. // Return Value:
  128. //
  129. //--
  130. /////////////////////////////////////////////////////////////////////////////
  131. char*
  132. CDnsRpcRecord::GetNextArg(
  133. char * pszIn,
  134. char ** ppszOut
  135. )
  136. {
  137. if(!pszIn || *pszIn == '\0')
  138. {
  139. return NULL;
  140. }
  141. char* bin ;
  142. //ignore leading space
  143. for(bin = pszIn; *bin == ' '; bin++);
  144. char* end;
  145. char delimeter = ' ';
  146. if( *bin == '\"')
  147. {
  148. delimeter = *bin++;
  149. }
  150. int length = 1;
  151. for(end = bin; *end != delimeter && *end != '\0'; end++, length++);
  152. if(delimeter == '\"')
  153. {
  154. end++; // pass delimeter
  155. }
  156. *ppszOut = new char[length];
  157. strncpy(
  158. *ppszOut,
  159. bin,
  160. length-1);
  161. *(*ppszOut+length-1) = '\0';
  162. return end;
  163. }
  164. /////////////////////////////////////////////////////////////////////////////
  165. //++
  166. //
  167. // Description:
  168. // use data in record to set wbem object
  169. //
  170. // Arguments:
  171. // Inst [IN OUT] wmi object
  172. //
  173. // Return Value:
  174. //
  175. //--
  176. /////////////////////////////////////////////////////////////////////////////
  177. SCODE
  178. CDnsRpcRecord::ConvertToWbemObject(
  179. CWbemClassObject& Inst)
  180. {
  181. Inst.SetProperty(
  182. (DWORD)1,
  183. PVD_REC_CLASS);
  184. Inst.SetProperty(
  185. GetTtl(),
  186. PVD_REC_TTL);
  187. return WBEM_NO_ERROR;
  188. }
  189. /////////////////////////////////////////////////////////////////////////////
  190. //++
  191. //
  192. // Description:
  193. // creating concrete record type class based on a type value
  194. //
  195. // Arguments:
  196. // wType [IN] type indicating the type of record
  197. // pptr [OUT] a pointer to base record class.
  198. // Return Value:
  199. //
  200. //--
  201. /////////////////////////////////////////////////////////////////////////////
  202. SCODE
  203. CDnsRpcRecord::CreateClass(
  204. WORD wType,
  205. PVOID * pptr
  206. )
  207. {
  208. switch ( wType)
  209. {
  210. case DNS_TYPE_ATMA:
  211. *pptr = (CDnsRpcRecord*) new CDnsRpcATMA(wType);
  212. break;
  213. case DNS_TYPE_A:
  214. *pptr = (CDnsRpcRecord*) new CDnsRpcA(wType);
  215. break;
  216. case DNS_TYPE_SOA:
  217. *pptr = (CDnsRpcRecord*) new CDnsRpcSOA(wType);
  218. break;
  219. case DNS_TYPE_PTR:
  220. case DNS_TYPE_NS:
  221. case DNS_TYPE_CNAME:
  222. case DNS_TYPE_MD:
  223. case DNS_TYPE_MB:
  224. case DNS_TYPE_MF:
  225. case DNS_TYPE_MG:
  226. case DNS_TYPE_MR:
  227. *pptr = (CDnsRpcRecord*) new CDnsRpcNS(wType);
  228. break;
  229. case DNS_TYPE_MX:
  230. case DNS_TYPE_RT:
  231. case DNS_TYPE_AFSDB:
  232. *pptr = (CDnsRpcRecord*) new CDnsRpcMX(wType);
  233. break;
  234. case DNS_TYPE_MINFO:
  235. case DNS_TYPE_RP:
  236. *pptr = (CDnsRpcRecord*) new CDnsRpcMINFO(wType);
  237. break;
  238. case DNS_TYPE_AAAA:
  239. *pptr = (CDnsRpcRecord*) new CDnsRpcAAAA(wType);
  240. break;
  241. case DNS_TYPE_HINFO:
  242. case DNS_TYPE_ISDN:
  243. case DNS_TYPE_X25:
  244. case DNS_TYPE_TEXT:
  245. *pptr = (CDnsRpcRecord*) new CDnsRpcTXT(wType);
  246. break;
  247. case DNS_TYPE_WKS:
  248. *pptr = (CDnsRpcRecord*) new CDnsRpcWKS(wType);
  249. break;
  250. case DNS_TYPE_SRV:
  251. *pptr = (CDnsRpcRecord*) new CDnsRpcSRV(wType);
  252. break;
  253. case DNS_TYPE_WINS:
  254. *pptr = (CDnsRpcRecord*) new CDnsRpcWINS(wType);
  255. break;
  256. case DNS_TYPE_WINSR:
  257. *pptr = (CDnsRpcRecord*) new CDnsRpcWINSR(wType);
  258. break;
  259. default:
  260. return WBEM_E_FAILED;
  261. }
  262. return WBEM_S_NO_ERROR;
  263. }
  264. /////////////////////////////////////////////////////////////////////////////
  265. //++
  266. //
  267. // Description:
  268. // send the record to dns server to delete or add
  269. //
  270. // Arguments:
  271. // szContainerName [IN] zone name
  272. // Type [IN] type of action,delete or add
  273. // Return Value:
  274. //
  275. //--
  276. /////////////////////////////////////////////////////////////////////////////
  277. SCODE
  278. CDnsRpcRecord::SendToServer(
  279. const char* szContainerName,
  280. ActionType Type
  281. )
  282. {
  283. PDNS_RPC_RECORD pRecordToAdd=NULL, pRecordToDelete=NULL;
  284. if(Type == AddRecord)
  285. {
  286. pRecordToAdd = m_pRecord;
  287. }
  288. else if(Type == DeleteRecord)
  289. {
  290. pRecordToDelete = m_pRecord;
  291. }
  292. else
  293. {
  294. return WBEM_E_INVALID_PARAMETER;
  295. }
  296. int status = DnssrvUpdateRecord(
  297. PVD_DNS_LOCAL_SERVER, // server
  298. szContainerName, //zone
  299. m_strOwnerName.data(), //node
  300. pRecordToAdd, // RR to add
  301. pRecordToDelete
  302. );
  303. if ( status != ERROR_SUCCESS )
  304. {
  305. CDnsWrap::DnsObject().ThrowException(status);
  306. }
  307. // when SOA saved, serial no. automaticly increment by 1
  308. if(m_wType == DNS_TYPE_SOA && Type == AddRecord)
  309. { PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  310. pData->SOA.dwSerialNo++;
  311. }
  312. return WBEM_S_NO_ERROR;
  313. }
  314. /////////////////////////////////////////////////////////////////////////////
  315. //++
  316. //
  317. // Description:
  318. // initialize a record based on PDNS_RPC_RECORD
  319. //
  320. // Arguments:
  321. // pRecord [IN] pointer to a rpc record
  322. //
  323. // Return Value:
  324. //
  325. //--
  326. /////////////////////////////////////////////////////////////////////////////
  327. BOOL
  328. CDnsRpcRecord::Init(
  329. PDNS_RPC_RECORD pRecord
  330. )
  331. {
  332. if(!pRecord)
  333. {
  334. return FALSE;
  335. }
  336. m_pRecord = pRecord;
  337. m_pRecordRequiresFree = FALSE;
  338. m_wType = pRecord->wType;
  339. return TRUE;
  340. }
  341. /////////////////////////////////////////////////////////////////////////////
  342. //++
  343. //
  344. // Description:
  345. // get the type of a record
  346. //
  347. // Arguments:
  348. //
  349. //
  350. // Return Value:
  351. //
  352. //--
  353. /////////////////////////////////////////////////////////////////////////////
  354. WORD
  355. CDnsRpcRecord::GetType()
  356. {
  357. if(m_pRecord==NULL)
  358. {
  359. return 0;
  360. }
  361. return m_pRecord->wType;
  362. }
  363. DWORD
  364. CDnsRpcRecord::GetTtl()
  365. {
  366. if(m_pRecord == NULL)
  367. {
  368. return 0;
  369. }
  370. return m_pRecord->dwTtlSeconds;
  371. }
  372. BOOL
  373. CDnsRpcRecord::RpcNameCopy(
  374. wstring& wstrTarget,
  375. PDNS_RPC_NAME pName
  376. )
  377. {
  378. wstrTarget = CharToWstring(
  379. pName->achName,
  380. pName->cchNameLength);
  381. return TRUE;
  382. }
  383. /////////////////////////////////////////////////////////////////////////////
  384. //++
  385. //
  386. // Description:
  387. // retrieve object path from rpc record
  388. //
  389. // Arguments:
  390. // wstrServer [IN] dns server name
  391. // wstrZone [IN] dns zone name
  392. // wstrDomain [IN] dns domain name
  393. // wstrOwner [IN] dns owner name
  394. // objOP [IN OUT] objpath to be set
  395. //
  396. // Return Value:
  397. //
  398. //--
  399. /////////////////////////////////////////////////////////////////////////////
  400. SCODE
  401. CDnsRpcRecord::GetObjectPath(
  402. wstring wstrServer,
  403. wstring wstrZone,
  404. wstring wstrDomain,
  405. wstring wstrOwner,
  406. CObjPath& objOP
  407. )
  408. {
  409. objOP.SetClass(m_pwszClassName);
  410. objOP.AddProperty(
  411. PVD_REC_RDATA,
  412. GetData().data());
  413. objOP.AddProperty(
  414. PVD_REC_CLASS,
  415. (WORD)1);
  416. objOP.AddProperty(
  417. PVD_REC_SERVER_NAME,
  418. wstrServer.data()
  419. );
  420. objOP.AddProperty(
  421. PVD_REC_CONTAINER_NAME,
  422. wstrZone.data()
  423. );
  424. objOP.AddProperty(
  425. PVD_REC_DOMAIN_NAME,
  426. GetRecDomain(wstrZone, wstrDomain, wstrOwner).data()
  427. );
  428. objOP.AddProperty(
  429. PVD_REC_OWNER_NAME,
  430. wstrOwner.data()
  431. );
  432. return WBEM_S_NO_ERROR;
  433. }
  434. wstring
  435. CDnsRpcRecord::GetTextRepresentation(
  436. wstring wstrNodeName // fully qualified
  437. )
  438. {
  439. wstring wstrTxt = GetClass() + L" " + GetTypeString()+ L" ";
  440. return wstrNodeName + L" " + wstrTxt + GetData();
  441. }
  442. /////////////////////////////////////////////////////////////////////////////
  443. //++
  444. //
  445. // Description:
  446. // figure out what's domain name and return it
  447. //
  448. // Arguments:
  449. //
  450. //
  451. // Return Value:
  452. //
  453. //--
  454. /////////////////////////////////////////////////////////////////////////////
  455. wstring
  456. CDnsRpcRecord::GetRecDomain(
  457. wstring wstrZone,
  458. wstring wstrDomain,
  459. wstring wstrOwner
  460. )
  461. {
  462. if(!wstrDomain.empty())
  463. {
  464. return wstrDomain;
  465. }
  466. else if( _wcsicmp( wstrZone.c_str(), wstrOwner.c_str() ) == 0 )
  467. {
  468. wstrDomain = wstrZone;
  469. }
  470. else
  471. {
  472. int posFirstPeriod = wstrOwner.find_first_of( '.' );
  473. if( posFirstPeriod == wstring::npos)
  474. throw WBEM_E_INVALID_PARAMETER;
  475. wstrDomain = wstrOwner.substr(
  476. posFirstPeriod + 1,
  477. wstrOwner.length() );
  478. //varify if this is valid domain
  479. //if(wstrZone.find(wstrDomain, 0) == string::npos)
  480. // throw WBEM_E_INVALID_PARAMETER;
  481. }
  482. return wstrDomain;
  483. }
  484. /////////////////////////////////////////////////////////////////////////////
  485. //++
  486. //
  487. // Description:
  488. // use the property value from Inst to modify Rdata. pwsz identifies
  489. // which value in Inst should be used. and wIndex identifies which
  490. // one in rdata should be replaced.
  491. //
  492. // Arguments:
  493. // wIndex [IN] index for m_ppRdata
  494. // pwsz [IN] Name for Rdata field
  495. // Inst [IN] wmi object
  496. //
  497. // Return Value:
  498. //
  499. //--
  500. /////////////////////////////////////////////////////////////////////////////
  501. SCODE
  502. CDnsRpcRecord::ReplaceRdata(
  503. WORD wIndex, // index for m_ppRdata
  504. const WCHAR* pwsz, // Name for Rdata field
  505. CWbemClassObject& Inst
  506. )
  507. {
  508. string str;
  509. wstring wstr;
  510. VARIANT v;
  511. VariantInit(&v);
  512. try
  513. {
  514. Inst.GetProperty(
  515. &v,
  516. pwsz);
  517. switch(v.vt)
  518. {
  519. case VT_I4:
  520. char sz[30];
  521. _ltoa(v.lVal, sz, 10);
  522. str = sz;
  523. break;
  524. case VT_BSTR:
  525. WcharToString(v.bstrVal, str);
  526. break;
  527. case VT_NULL:
  528. return WBEM_S_NO_ERROR;
  529. default:
  530. throw WBEM_E_INVALID_PARAMETER;
  531. }
  532. delete [] m_ppRdata[wIndex];
  533. m_ppRdata[wIndex] = new char[str.length()+1];
  534. if ( !m_ppRdata[wIndex] )
  535. {
  536. return WBEM_E_OUT_OF_MEMORY;
  537. }
  538. strcpy(m_ppRdata[wIndex], str.data());
  539. m_bRdataChange = TRUE;
  540. VariantClear(&v);
  541. }
  542. catch(...)
  543. {
  544. VariantClear(&v);
  545. throw;
  546. }
  547. return WBEM_S_NO_ERROR;
  548. }
  549. /////////////////////////////////////////////////////////////////////////////
  550. //++
  551. //
  552. // Description:
  553. // parse rdata string and save them as an array of string in
  554. // member variable m_ppRdata
  555. //
  556. // Arguments:
  557. // strRdata [IN] rdata string
  558. // wSize [IN] number of arg in rdata
  559. //
  560. //
  561. // Return Value:
  562. //
  563. //--
  564. /////////////////////////////////////////////////////////////////////////////
  565. SCODE
  566. CDnsRpcRecord::ParseRdata(
  567. string& strRdata,
  568. WORD wSize
  569. )
  570. {
  571. m_ppRdata[0] = new char[strRdata.length()+1];
  572. if ( !m_ppRdata[0] )
  573. {
  574. return WBEM_E_OUT_OF_MEMORY;
  575. }
  576. strcpy(m_ppRdata[0], strRdata.data());
  577. char * bin = m_ppRdata[0];
  578. for(int i=1; i<=wSize; i++)
  579. {
  580. if(bin == NULL || *bin == '\0')
  581. {
  582. return WBEM_E_INVALID_PARAMETER;
  583. }
  584. bin = GetNextArg(bin , &(m_ppRdata[i]));
  585. }
  586. return S_OK;
  587. }
  588. CDnsRpcRecord::RdataIsChanged()
  589. {
  590. return m_bRdataChange;
  591. }
  592. CDnsRpcSOA::~CDnsRpcSOA()
  593. {
  594. }
  595. CDnsRpcSOA::CDnsRpcSOA(
  596. WORD wType)
  597. :CDnsRpcRecord(NUM_OF_ARG_IN_RDATA)
  598. {
  599. m_wType = wType;
  600. m_pwszClassName = PVD_CLASS_RR_SOA;
  601. }
  602. const
  603. WCHAR**
  604. CDnsRpcSOA::GetRdataName(void)
  605. {
  606. static const WCHAR* pwsz[] ={
  607. PVD_REC_SOA_PRIMARY_SERVER,
  608. PVD_REC_SOA_RESPONSIBLE,
  609. PVD_REC_SOA_SERIAL_NUMBER,
  610. PVD_REC_SOA_REFRESH,
  611. PVD_REC_SOA_RETRY_DELAY,
  612. PVD_REC_SOA_EXPIRE_LIMIT,
  613. PVD_REC_SOA_TTL};
  614. return pwsz;
  615. }
  616. SCODE
  617. CDnsRpcSOA::BuildRpcRecord(
  618. WORD argc,
  619. char** argv)
  620. {
  621. int cLength = strlen(argv[0]);
  622. if(*(argv[0]+cLength-1) != '.')
  623. {
  624. char * pNew = new char[cLength+2];
  625. if ( !pNew )
  626. {
  627. return WBEM_E_OUT_OF_MEMORY;
  628. }
  629. strcpy(pNew, argv[0]);
  630. strcat(pNew, ".");
  631. delete argv[0];
  632. argv[0] = pNew;
  633. }
  634. cLength = strlen(argv[1]);
  635. if(*(argv[1]+cLength-1) != '.')
  636. {
  637. char * pNew = new char[cLength+2];
  638. if ( !pNew )
  639. {
  640. return WBEM_E_OUT_OF_MEMORY;
  641. }
  642. strcpy(pNew, argv[1]);
  643. strcat(pNew, ".");
  644. delete argv[1];
  645. argv[1] = pNew;
  646. }
  647. return CDnsRpcRecord::BuildRpcRecord( argc, argv );
  648. }
  649. DWORD
  650. CDnsRpcSOA::GetMinimumTtl(void)
  651. {
  652. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  653. return pData->SOA.dwMinimumTtl;
  654. }
  655. DWORD
  656. CDnsRpcSOA::GetExpire(void)
  657. {
  658. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  659. return pData->SOA.dwExpire;
  660. }
  661. DWORD
  662. CDnsRpcSOA::GetRefresh(void)
  663. {
  664. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  665. return pData->SOA.dwRefresh;
  666. }
  667. DWORD
  668. CDnsRpcSOA::GetRetry(void)
  669. {
  670. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  671. return pData->SOA.dwRetry;
  672. }
  673. DWORD
  674. CDnsRpcSOA::GetSerialNo(void)
  675. {
  676. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  677. return pData->SOA.dwSerialNo;
  678. }
  679. wstring
  680. CDnsRpcSOA::GetPrimaryServer(void)
  681. {
  682. wstring wstrTxt;
  683. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  684. RpcNameCopy(wstrTxt, &(pData->SOA.namePrimaryServer));
  685. return wstrTxt;
  686. }
  687. wstring
  688. CDnsRpcSOA::GetResponsible(void)
  689. {
  690. wstring wstrTxt;
  691. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  692. int iLength = pData->SOA.namePrimaryServer.cchNameLength;
  693. RpcNameCopy(
  694. wstrTxt,
  695. (PDNS_RPC_NAME)(pData->SOA.namePrimaryServer.achName+iLength));
  696. return wstrTxt;
  697. }
  698. wstring
  699. CDnsRpcSOA::GetData(void)
  700. {
  701. char temp[MAX_PATH];
  702. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  703. sprintf(temp," %lu %lu %lu %lu %lu",
  704. pData->SOA.dwSerialNo,
  705. pData->SOA.dwRefresh,
  706. pData->SOA.dwRetry,
  707. pData->SOA.dwExpire,
  708. pData->SOA.dwMinimumTtl );
  709. return GetPrimaryServer() +
  710. L" " +
  711. GetResponsible()+
  712. L" " +
  713. CharToWstring(temp, strlen(temp));
  714. }
  715. SCODE
  716. CDnsRpcSOA::ConvertToWbemObject(
  717. CWbemClassObject& Inst)
  718. {
  719. Inst.SetProperty(
  720. GetExpire(),
  721. PVD_REC_SOA_EXPIRE_LIMIT);
  722. Inst.SetProperty(
  723. GetMinimumTtl(),
  724. PVD_REC_SOA_TTL);
  725. Inst.SetProperty(
  726. GetRefresh(),
  727. PVD_REC_SOA_REFRESH);
  728. Inst.SetProperty(
  729. GetRetry(),
  730. PVD_REC_SOA_RETRY_DELAY);
  731. Inst.SetProperty(
  732. GetSerialNo(),
  733. PVD_REC_SOA_SERIAL_NUMBER);
  734. Inst.SetProperty(
  735. GetPrimaryServer(),
  736. PVD_REC_SOA_PRIMARY_SERVER );
  737. Inst.SetProperty(
  738. GetResponsible(),
  739. PVD_REC_SOA_RESPONSIBLE);
  740. Inst.SetProperty(
  741. GetData(),
  742. PVD_REC_RDATA);
  743. CDnsRpcRecord::ConvertToWbemObject(Inst);
  744. return WBEM_NO_ERROR;
  745. }
  746. CDnsRpcA::~CDnsRpcA()
  747. {
  748. }
  749. CDnsRpcA::CDnsRpcA(
  750. WORD wType)
  751. :CDnsRpcRecord(NUM_OF_ARG_IN_RDATA)
  752. {
  753. m_wType = wType;
  754. m_pwszClassName = PVD_CLASS_RR_A;
  755. }
  756. SCODE
  757. CDnsRpcA::ConvertToWbemObject(
  758. CWbemClassObject& Inst)
  759. {
  760. Inst.SetProperty(
  761. GetIP(),
  762. PVD_REC_A_IP);
  763. Inst.SetProperty(
  764. GetData(),
  765. PVD_REC_RDATA);
  766. CDnsRpcRecord::ConvertToWbemObject(Inst);
  767. return WBEM_NO_ERROR;
  768. }
  769. wstring
  770. CDnsRpcA::GetIP(void)
  771. {
  772. char temp[MAX_PATH];
  773. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  774. return IpAddressToString(pData->A.ipAddress);
  775. }
  776. wstring
  777. CDnsRpcA::GetData(void)
  778. {
  779. return GetIP();
  780. }
  781. // CDnsRpcNS
  782. CDnsRpcNS::CDnsRpcNS(
  783. WORD wType)
  784. :CDnsRpcRecord(NUM_OF_ARG_IN_RDATA)
  785. {
  786. m_wType = wType;
  787. switch (m_wType)
  788. {
  789. case DNS_TYPE_PTR:
  790. m_pwszClassName = PVD_CLASS_RR_PTR;
  791. break;
  792. case DNS_TYPE_NS:
  793. m_pwszClassName = PVD_CLASS_RR_NS;
  794. break;
  795. case DNS_TYPE_CNAME:
  796. m_pwszClassName = PVD_CLASS_RR_CNAME;
  797. break;
  798. case DNS_TYPE_MD:
  799. m_pwszClassName = PVD_CLASS_RR_MD;
  800. break;
  801. case DNS_TYPE_MB:
  802. m_pwszClassName = PVD_CLASS_RR_MB;
  803. break;
  804. case DNS_TYPE_MF:
  805. m_pwszClassName =PVD_CLASS_RR_MF;
  806. break;
  807. case DNS_TYPE_MG:
  808. m_pwszClassName = PVD_CLASS_RR_MG;
  809. break;
  810. case DNS_TYPE_MR:
  811. m_pwszClassName = PVD_CLASS_RR_MR;
  812. break;
  813. default:
  814. throw WBEM_E_INVALID_PARAMETER;
  815. }
  816. }
  817. CDnsRpcNS::~CDnsRpcNS()
  818. {
  819. }
  820. const
  821. WCHAR**
  822. CDnsRpcNS::GetRdataName(void)
  823. {
  824. switch (m_wType)
  825. {
  826. case DNS_TYPE_PTR:
  827. {
  828. static const WCHAR* pwszPTR[] =
  829. {PVD_REC_PTR_PTRDOMAIN_NAME};
  830. return pwszPTR;
  831. }
  832. case DNS_TYPE_NS:
  833. {
  834. static const WCHAR* pwszNS[] =
  835. {PVD_REC_NS_NSHOST};
  836. return pwszNS;
  837. }
  838. case DNS_TYPE_CNAME:
  839. {
  840. static const WCHAR* pwszCNAME[] =
  841. {PVD_REC_CNAME_PRIMARY_NAME};
  842. return pwszCNAME;
  843. }
  844. case DNS_TYPE_MD:
  845. {
  846. static const WCHAR* pwszMD[] =
  847. {PVD_REC_MD_MDHOST};
  848. return pwszMD;
  849. }
  850. case DNS_TYPE_MB:
  851. {
  852. static const WCHAR* pwszMB[] =
  853. {PVD_REC_MB_MBHOST};
  854. return pwszMB;
  855. }
  856. case DNS_TYPE_MF:
  857. {
  858. static const WCHAR* pwszMF[] =
  859. {PVD_REC_MF_MFHOST};
  860. return pwszMF;
  861. }
  862. case DNS_TYPE_MG:
  863. {
  864. static const WCHAR* pwszMG[] =
  865. {PVD_REC_MG_MGMAILBOX};
  866. return pwszMG;
  867. }
  868. case DNS_TYPE_MR:
  869. {
  870. static const WCHAR* pwszMR[] =
  871. {PVD_REC_MR_MRMAILBOX};
  872. return pwszMR;
  873. }
  874. default:
  875. throw WBEM_E_INVALID_PARAMETER;
  876. }
  877. return NULL;
  878. }
  879. wstring
  880. CDnsRpcNS::GetNodeName(void)
  881. {
  882. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  883. wstring wstrTxt;
  884. RpcNameCopy(wstrTxt, &(pData->NS.nameNode));
  885. return wstrTxt;
  886. }
  887. wstring
  888. CDnsRpcNS::GetRecDomain(
  889. wstring wstrZone,
  890. wstring wstrDomain,
  891. wstring wstrOwner)
  892. {
  893. if(m_wType == DNS_TYPE_NS)
  894. {
  895. return wstrOwner;
  896. }
  897. return CDnsRpcRecord::GetRecDomain(
  898. wstrZone,
  899. wstrDomain,
  900. wstrOwner);
  901. }
  902. wstring
  903. CDnsRpcNS::GetData(void)
  904. {
  905. return GetNodeName();
  906. }
  907. SCODE
  908. CDnsRpcNS::ConvertToWbemObject(
  909. CWbemClassObject& Inst)
  910. {
  911. const WCHAR** ppName = GetRdataName();
  912. Inst.SetProperty(
  913. GetNodeName(),
  914. ppName[0]);
  915. Inst.SetProperty(
  916. GetData(),
  917. PVD_REC_RDATA);
  918. CDnsRpcRecord::ConvertToWbemObject(Inst);
  919. return WBEM_NO_ERROR;
  920. }
  921. SCODE
  922. CDnsRpcNS::BuildRpcRecord(
  923. WORD argc,
  924. char** argv)
  925. {
  926. int cLength = strlen(argv[0]);
  927. if(*(argv[0]+cLength-1) != '.')
  928. {
  929. char * pNew = new char[ cLength + 2 ];
  930. if ( !pNew )
  931. {
  932. return WBEM_E_OUT_OF_MEMORY;
  933. }
  934. strcpy(pNew, argv[0]);
  935. strcat(pNew, ".");
  936. delete argv[0];
  937. argv[0] = pNew;
  938. }
  939. return CDnsRpcRecord::BuildRpcRecord(
  940. argc,
  941. argv);
  942. }
  943. // CDnsRpcMX
  944. CDnsRpcMX::CDnsRpcMX(WORD wType)
  945. :CDnsRpcRecord(NUM_OF_ARG_IN_RDATA)
  946. {
  947. m_wType = wType;
  948. switch(m_wType)
  949. {
  950. case DNS_TYPE_MX:
  951. m_pwszClassName = PVD_CLASS_RR_MX;
  952. break;
  953. case DNS_TYPE_RT:
  954. m_pwszClassName = PVD_CLASS_RR_RT;
  955. break;
  956. case DNS_TYPE_AFSDB:
  957. m_pwszClassName = PVD_CLASS_RR_AFSDB;
  958. break;
  959. default:
  960. throw WBEM_E_INVALID_PARAMETER;
  961. }
  962. }
  963. CDnsRpcMX::~CDnsRpcMX()
  964. {
  965. }
  966. SCODE
  967. CDnsRpcMX::ConvertToWbemObject(
  968. CWbemClassObject& Inst)
  969. {
  970. const WCHAR** ppName = GetRdataName();
  971. Inst.SetProperty(
  972. GetPreference(),
  973. ppName[0]);
  974. Inst.SetProperty(
  975. GetNodeName(),
  976. ppName[1]);
  977. Inst.SetProperty(
  978. GetData(),
  979. PVD_REC_RDATA);
  980. CDnsRpcRecord::ConvertToWbemObject(Inst);
  981. return WBEM_NO_ERROR;
  982. }
  983. const
  984. WCHAR**
  985. CDnsRpcMX::GetRdataName(void)
  986. {
  987. switch(m_wType)
  988. {
  989. case DNS_TYPE_MX:
  990. {
  991. static const WCHAR* pwszMX[] =
  992. {PVD_REC_MX_PREFERENCE,
  993. PVD_REC_MX_MAIL_EXCHANGE};
  994. return pwszMX;
  995. }
  996. case DNS_TYPE_RT:
  997. {
  998. static const WCHAR* pwszRT[] =
  999. { PVD_REC_RT_PREFERENCE,
  1000. PVD_REC_RT_HOST};
  1001. return pwszRT;
  1002. }
  1003. case DNS_TYPE_AFSDB:
  1004. {
  1005. static const WCHAR* pwszAFSDB[] =
  1006. {PVD_REC_AFSBD_SUB_TYPE,
  1007. PVD_REC_AFSBD_SERVER_NAME};
  1008. return pwszAFSDB;
  1009. }
  1010. default:
  1011. throw WBEM_E_INVALID_PARAMETER;
  1012. }
  1013. return NULL;
  1014. }
  1015. wstring
  1016. CDnsRpcMX::GetNodeName()
  1017. {
  1018. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1019. wstring wstrTxt;
  1020. RpcNameCopy(wstrTxt, &(pData->MX.nameExchange));
  1021. return wstrTxt;
  1022. }
  1023. DWORD
  1024. CDnsRpcMX::GetPreference()
  1025. {
  1026. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1027. return pData->MX.wPreference;
  1028. }
  1029. wstring
  1030. CDnsRpcMX::GetData(void)
  1031. {
  1032. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1033. WCHAR temp[MAX_PATH];
  1034. swprintf(
  1035. temp,
  1036. L" %d ",
  1037. pData->MX.wPreference);
  1038. return temp + GetNodeName();
  1039. }
  1040. CDnsRpcMINFO::CDnsRpcMINFO(
  1041. WORD wType)
  1042. :CDnsRpcRecord(NUM_OF_ARG_IN_RDATA)
  1043. {
  1044. m_wType = wType;
  1045. switch(m_wType)
  1046. {
  1047. case DNS_TYPE_MINFO:
  1048. m_pwszClassName = PVD_CLASS_RR_MINFO;
  1049. break;
  1050. case DNS_TYPE_RP:
  1051. m_pwszClassName = PVD_CLASS_RR_RP;
  1052. break;
  1053. default:
  1054. throw WBEM_E_INVALID_PARAMETER;
  1055. }
  1056. }
  1057. CDnsRpcMINFO::~CDnsRpcMINFO()
  1058. {
  1059. }
  1060. SCODE
  1061. CDnsRpcMINFO::ConvertToWbemObject(
  1062. CWbemClassObject& Inst)
  1063. {
  1064. const WCHAR** ppName = GetRdataName();
  1065. Inst.SetProperty(
  1066. GetRPMailBox(),
  1067. ppName[0]);
  1068. Inst.SetProperty(
  1069. GetErrMailBox(),
  1070. ppName[1]);
  1071. Inst.SetProperty(
  1072. GetData(),
  1073. PVD_REC_RDATA);
  1074. CDnsRpcRecord::ConvertToWbemObject(Inst);
  1075. return WBEM_NO_ERROR;
  1076. }
  1077. const
  1078. WCHAR**
  1079. CDnsRpcMINFO::GetRdataName(void)
  1080. {
  1081. switch(m_wType)
  1082. {
  1083. case DNS_TYPE_MINFO:
  1084. { static const WCHAR* pwszMINFO[] =
  1085. {PVD_REC_MINFO_RESP_MAILBOX,
  1086. PVD_REC_MINFO_ERROR_MAILBOX};
  1087. return pwszMINFO;
  1088. }
  1089. case DNS_TYPE_RP:
  1090. {
  1091. static const WCHAR* pwszRP[] =
  1092. {PVD_REC_RP_RPMAILBOX,
  1093. PVD_REC_RP_TXT_DOMAIN_NAME};
  1094. return pwszRP;
  1095. }
  1096. default:
  1097. throw WBEM_E_INVALID_PARAMETER;
  1098. }
  1099. return NULL;
  1100. }
  1101. wstring
  1102. CDnsRpcMINFO::GetRPMailBox()
  1103. {
  1104. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1105. wstring wstrTxt;
  1106. RpcNameCopy(
  1107. wstrTxt,
  1108. &(pData->MINFO.nameMailBox));
  1109. return wstrTxt;
  1110. }
  1111. wstring
  1112. CDnsRpcMINFO::GetErrMailBox()
  1113. {
  1114. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1115. wstring wstrTxt;
  1116. int iLength = pData->MINFO.nameMailBox.cchNameLength;
  1117. RpcNameCopy(
  1118. wstrTxt,
  1119. (PDNS_RPC_NAME)(pData->MINFO.nameMailBox.achName+iLength));
  1120. return wstrTxt;
  1121. }
  1122. wstring
  1123. CDnsRpcMINFO::GetData(void)
  1124. {
  1125. return GetRPMailBox() + L" " + GetErrMailBox();
  1126. }
  1127. CDnsRpcAAAA::~CDnsRpcAAAA()
  1128. {
  1129. }
  1130. CDnsRpcAAAA::CDnsRpcAAAA(
  1131. WORD wType)
  1132. :CDnsRpcRecord(NUM_OF_ARG_IN_RDATA)
  1133. {
  1134. m_wType = wType;
  1135. m_pwszClassName = PVD_CLASS_RR_AAAA;
  1136. }
  1137. SCODE
  1138. CDnsRpcAAAA::ConvertToWbemObject(
  1139. CWbemClassObject& Inst)
  1140. {
  1141. Inst.SetProperty(
  1142. GetIP(),
  1143. PVD_REC_AAAA_IP);
  1144. Inst.SetProperty(
  1145. GetData(),
  1146. PVD_REC_RDATA);
  1147. CDnsRpcRecord::ConvertToWbemObject(Inst);
  1148. return WBEM_NO_ERROR;
  1149. }
  1150. wstring
  1151. CDnsRpcAAAA::GetData(void)
  1152. {
  1153. return GetIP();
  1154. }
  1155. wstring
  1156. CDnsRpcAAAA::GetIP(void)
  1157. {
  1158. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1159. CHAR ip6String[ IP6_ADDRESS_STRING_BUFFER_LENGTH ];
  1160. Dns_Ip6AddressToString_A(
  1161. ip6String,
  1162. &pData->AAAA.ipv6Address );
  1163. return CharToWstring( ip6String, strlen(ip6String) );
  1164. }
  1165. const
  1166. WCHAR**
  1167. CDnsRpcAAAA::GetRdataName(void)
  1168. {
  1169. static const WCHAR* pwsz[] ={PVD_REC_AAAA_IP};
  1170. return pwsz;
  1171. }
  1172. // CDnsRpcTXT
  1173. CDnsRpcTXT::~CDnsRpcTXT()
  1174. {
  1175. }
  1176. CDnsRpcTXT::CDnsRpcTXT(
  1177. WORD wType)
  1178. :CDnsRpcRecord(NUM_OF_ARG_IN_RDATA_HINFO)
  1179. {
  1180. m_wType = wType;
  1181. switch(m_wType)
  1182. {
  1183. case DNS_TYPE_HINFO:
  1184. m_pwszClassName = PVD_CLASS_RR_HINFO;
  1185. m_cRdata=NUM_OF_ARG_IN_RDATA_HINFO;
  1186. break;
  1187. case DNS_TYPE_ISDN:
  1188. m_pwszClassName = PVD_CLASS_RR_ISDN;
  1189. m_cRdata=NUM_OF_ARG_IN_RDATA_HINFO;
  1190. break;
  1191. case DNS_TYPE_X25:
  1192. m_pwszClassName = PVD_CLASS_RR_X25;
  1193. m_cRdata=NUM_OF_ARG_IN_RDATA_TXT;
  1194. break;
  1195. case DNS_TYPE_TEXT:
  1196. m_pwszClassName = PVD_CLASS_RR_TXT;
  1197. m_cRdata=NUM_OF_ARG_IN_RDATA_TXT;
  1198. break;
  1199. default:
  1200. throw WBEM_E_INVALID_PARAMETER;
  1201. }
  1202. }
  1203. SCODE
  1204. CDnsRpcTXT::ConvertToWbemObject(
  1205. CWbemClassObject& Inst)
  1206. {
  1207. const WCHAR** ppName = GetRdataName();
  1208. Inst.SetProperty(
  1209. GetString1(),
  1210. ppName[0]);
  1211. //exception case .num of rdata arg varies depends on type.
  1212. // handle it.
  1213. if(m_cRdata == 2)
  1214. {
  1215. Inst.SetProperty(
  1216. GetString2(),
  1217. ppName[1]);
  1218. }
  1219. Inst.SetProperty(
  1220. GetData(),
  1221. PVD_REC_RDATA);
  1222. CDnsRpcRecord::ConvertToWbemObject(Inst);
  1223. return WBEM_NO_ERROR;
  1224. }
  1225. const
  1226. WCHAR**
  1227. CDnsRpcTXT::GetRdataName(void)
  1228. {
  1229. switch(m_wType)
  1230. {
  1231. case DNS_TYPE_HINFO:
  1232. {
  1233. static const WCHAR* pwszHINFO[] =
  1234. {PVD_REC_HINFO_CPU,
  1235. PVD_REC_HINFO_OS};
  1236. return pwszHINFO;
  1237. }
  1238. case DNS_TYPE_ISDN:
  1239. {
  1240. static const WCHAR* pwszISDN[] =
  1241. { PVD_REC_ISDN_ISDN_NUM,
  1242. PVD_REC_ISDN_SUB_ADDRESS};
  1243. return pwszISDN;
  1244. }
  1245. case DNS_TYPE_X25:
  1246. {
  1247. static const WCHAR* pwszX25[] =
  1248. {PVD_REC_X25_PSDNADDRESS};
  1249. return pwszX25;
  1250. }
  1251. case DNS_TYPE_TEXT:
  1252. {
  1253. static const WCHAR* pwszTEXT[] =
  1254. {PVD_REC_TXT_TEXT};
  1255. return pwszTEXT;
  1256. }
  1257. default:
  1258. throw WBEM_E_INVALID_PARAMETER;
  1259. }
  1260. return NULL;
  1261. }
  1262. wstring
  1263. CDnsRpcTXT::GetString1()
  1264. {
  1265. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1266. wstring wstrTxt;
  1267. RpcNameCopy(
  1268. wstrTxt,
  1269. &(pData->TXT.stringData));
  1270. return wstrTxt;
  1271. }
  1272. wstring
  1273. CDnsRpcTXT::GetString2()
  1274. {
  1275. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1276. wstring wstrTxt;
  1277. int iLength = pData->TXT.stringData.cchNameLength;
  1278. if( (m_pRecord->wDataLength-1) > iLength)
  1279. {
  1280. RpcNameCopy(
  1281. wstrTxt,
  1282. (PDNS_RPC_NAME)(pData->TXT.stringData.achName+iLength));
  1283. }
  1284. return wstrTxt;
  1285. }
  1286. wstring
  1287. CDnsRpcTXT::GetTextRepresentation(
  1288. wstring wstrNodeName)
  1289. {
  1290. wstring wstrTxt = GetClass() + L" " + GetTypeString()+ L" ";
  1291. return wstrNodeName + L" " + wstrTxt + GetData();
  1292. }
  1293. wstring
  1294. CDnsRpcTXT::GetData(void)
  1295. {
  1296. wstring wstrTxt = L"\"" + GetString1() + L"\"";
  1297. wstring wstrTxt2 = GetString2();
  1298. if(wstrTxt2.empty())
  1299. {
  1300. return wstrTxt;
  1301. }
  1302. else
  1303. return wstrTxt + L" \"" +wstrTxt2 +L"\"";
  1304. }
  1305. CDnsRpcWKS::~CDnsRpcWKS()
  1306. {
  1307. }
  1308. CDnsRpcWKS::CDnsRpcWKS(
  1309. WORD wType)
  1310. :CDnsRpcRecord(NUM_OF_ARG_IN_RDATA)
  1311. {
  1312. m_wType = wType;
  1313. m_pwszClassName = PVD_CLASS_RR_WKS;
  1314. }
  1315. SCODE
  1316. CDnsRpcWKS::ConvertToWbemObject(
  1317. CWbemClassObject& Inst)
  1318. {
  1319. Inst.SetProperty(
  1320. GetIP(),
  1321. PVD_REC_WKS_INTERNET_ADDRESS);
  1322. Inst.SetProperty(
  1323. GetIPProtocal(),
  1324. PVD_REC_WKS_IP_PROTOCOL);
  1325. Inst.SetProperty(
  1326. GetServices(),
  1327. PVD_REC_WKS_BIT_MASK);
  1328. Inst.SetProperty(
  1329. GetData(),
  1330. PVD_REC_RDATA);
  1331. CDnsRpcRecord::ConvertToWbemObject(Inst);
  1332. return WBEM_NO_ERROR;
  1333. }
  1334. const
  1335. WCHAR**
  1336. CDnsRpcWKS::GetRdataName(void)
  1337. {
  1338. static const WCHAR* pwsz[] ={
  1339. PVD_REC_WKS_IP_PROTOCOL,
  1340. PVD_REC_WKS_INTERNET_ADDRESS,
  1341. PVD_REC_WKS_BIT_MASK};
  1342. return pwsz;
  1343. }wstring
  1344. CDnsRpcWKS::GetIP(void)
  1345. {
  1346. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1347. return IpAddressToString(pData->WKS.ipAddress);
  1348. }
  1349. wstring
  1350. CDnsRpcWKS::GetIPProtocal(void)
  1351. {
  1352. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1353. WSADATA wsaData;
  1354. struct protoent * pProtoent;
  1355. DNS_STATUS status = WSAStartup(
  1356. DNS_WINSOCK_VERSION,
  1357. &wsaData );
  1358. if ( status == SOCKET_ERROR )
  1359. {
  1360. status = WSAGetLastError();
  1361. CDnsWrap::ThrowException(status);
  1362. }
  1363. // get protocal name
  1364. pProtoent = getprotobynumber( pData->WKS.chProtocol );
  1365. if ( ! pProtoent || pProtoent->p_proto >= MAXUCHAR )
  1366. {
  1367. status = WSAGetLastError();
  1368. CDnsWrap::ThrowException(status);
  1369. }
  1370. return CharToWstring(
  1371. pProtoent->p_name,
  1372. strlen(pProtoent->p_name));
  1373. }
  1374. wstring
  1375. CDnsRpcWKS::GetServices(void)
  1376. {
  1377. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1378. char temp[MAX_PATH];
  1379. WORD wLength = m_pRecord->wDataLength -
  1380. sizeof(pData->WKS.ipAddress) -
  1381. sizeof(pData->WKS.chProtocol)-1;
  1382. UCHAR* p = &pData->WKS.bBitMask[1]; //ignore the first
  1383. for(WORD i=0; i< wLength; i++)
  1384. {
  1385. temp[i] = *p++;
  1386. }
  1387. temp[i]='\0';
  1388. wstring wstr = CharToWstring(temp, wLength);
  1389. if(wstr.find_first_of(L" ") != string::npos)
  1390. { //if string contains space, enclose it in quote
  1391. wstr = L"\"" + wstr + L"\"";
  1392. }
  1393. return wstr;
  1394. }
  1395. wstring
  1396. CDnsRpcWKS::GetData(void)
  1397. {
  1398. return GetIPProtocal() +L" " + GetIP()+ L" " + GetServices();
  1399. }
  1400. // CDnsRpcSRV
  1401. CDnsRpcSRV::~CDnsRpcSRV()
  1402. {
  1403. }
  1404. CDnsRpcSRV::CDnsRpcSRV(
  1405. WORD wType)
  1406. :CDnsRpcRecord(NUM_OF_ARG_IN_RDATA)
  1407. {
  1408. m_wType = wType;
  1409. m_pwszClassName = PVD_CLASS_RR_SRV;
  1410. }
  1411. SCODE
  1412. CDnsRpcSRV::ConvertToWbemObject(
  1413. CWbemClassObject& Inst)
  1414. {
  1415. wstring wstrClassName;
  1416. Inst.SetProperty(
  1417. GetPriority(),
  1418. PVD_REC_SRV_PRIORITY);
  1419. Inst.SetProperty(
  1420. GetWeight(),
  1421. PVD_REC_SRV_WEIGHT);
  1422. Inst.SetProperty(
  1423. GetPort(),
  1424. PVD_REC_SRV_PORT);
  1425. Inst.SetProperty(
  1426. GetDomainName(),
  1427. PVD_REC_SRV_DOMAINNAME);
  1428. Inst.SetProperty(
  1429. GetData(),
  1430. PVD_REC_RDATA);
  1431. CDnsRpcRecord::ConvertToWbemObject(Inst);
  1432. return WBEM_NO_ERROR;
  1433. }
  1434. const
  1435. WCHAR**
  1436. CDnsRpcSRV::GetRdataName(void)
  1437. {
  1438. static const WCHAR* pwsz[] ={
  1439. PVD_REC_SRV_PRIORITY,
  1440. PVD_REC_SRV_WEIGHT,
  1441. PVD_REC_SRV_PORT,
  1442. PVD_REC_SRV_DOMAINNAME};
  1443. return pwsz;
  1444. }
  1445. wstring
  1446. CDnsRpcSRV::GetDomainName(void)
  1447. {
  1448. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1449. wstring wstrTxt;
  1450. RpcNameCopy(wstrTxt, &(pData->SRV.nameTarget));
  1451. return wstrTxt;
  1452. }
  1453. DWORD
  1454. CDnsRpcSRV::GetPort()
  1455. {
  1456. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1457. return pData->SRV.wPort;
  1458. }
  1459. DWORD
  1460. CDnsRpcSRV::GetPriority()
  1461. {
  1462. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1463. return pData->SRV.wPriority;
  1464. }
  1465. DWORD
  1466. CDnsRpcSRV::GetWeight()
  1467. {
  1468. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1469. return pData->SRV.wWeight;
  1470. }
  1471. wstring
  1472. CDnsRpcSRV::GetData(void)
  1473. {
  1474. WCHAR temp[MAX_PATH];
  1475. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1476. swprintf(temp,
  1477. L"%d %d %d ",
  1478. pData->SRV.wPriority,
  1479. pData->SRV.wWeight,
  1480. pData->SRV.wPort);
  1481. return temp + GetDomainName();
  1482. }
  1483. // CDnsRpcWINS
  1484. CDnsRpcWINS::~CDnsRpcWINS()
  1485. {
  1486. }
  1487. CDnsRpcWINS::CDnsRpcWINS(
  1488. WORD wType)
  1489. :CDnsRpcRecord(NUM_OF_ARG_IN_RDATA)
  1490. {
  1491. m_wType = wType;
  1492. m_pwszClassName = PVD_CLASS_RR_WINS;
  1493. }
  1494. SCODE
  1495. CDnsRpcWINS::ConvertToWbemObject(
  1496. CWbemClassObject& Inst)
  1497. {
  1498. Inst.SetProperty(
  1499. GetCacheTimeOut(),
  1500. PVD_REC_WINS_CACHE_TIMEOUT);
  1501. Inst.SetProperty(
  1502. GetLookupTimeOut(),
  1503. PVD_REC_WINS_TIMEOUT);
  1504. Inst.SetProperty(
  1505. GetMapFlag(),
  1506. PVD_REC_WINS_MAPPING_FLAG );
  1507. Inst.SetProperty(
  1508. GetWinServer(),
  1509. PVD_REC_WINS_WINS_SERVER);
  1510. Inst.SetProperty(
  1511. GetData(),
  1512. PVD_REC_RDATA);
  1513. CDnsRpcRecord::ConvertToWbemObject(Inst);
  1514. return WBEM_NO_ERROR;
  1515. }
  1516. const
  1517. WCHAR**
  1518. CDnsRpcWINS::GetRdataName(void)
  1519. {
  1520. static const WCHAR* pwsz[] ={
  1521. PVD_REC_WINS_MAPPING_FLAG,
  1522. PVD_REC_WINS_TIMEOUT,
  1523. PVD_REC_WINS_CACHE_TIMEOUT,
  1524. PVD_REC_WINS_WINS_SERVER};
  1525. return pwsz;
  1526. }
  1527. SCODE
  1528. CDnsRpcWINS::BuildRpcRecord(
  1529. WORD argc,
  1530. char** argv)
  1531. {
  1532. char* pWinserver = argv[3];
  1533. // if winser string has mutiple server, then change it from
  1534. // from flat string to array
  1535. int nCount=0;
  1536. char*p = pWinserver;
  1537. while(*p != '\0')
  1538. {
  1539. if(*p != ' ')
  1540. {
  1541. nCount++;
  1542. while(*(++p) != ' ' && *p != '\0' );
  1543. }
  1544. else
  1545. {
  1546. p++;
  1547. }
  1548. }
  1549. if(nCount >1 )
  1550. {
  1551. int nSize = strlen(pWinserver)+1;
  1552. char* pArg = (char*) _alloca(nSize);
  1553. strcpy(pArg, pWinserver);
  1554. // alloc new array
  1555. WORD cNewArray = argc+nCount-1;
  1556. char** pNewArgv = (char**) _alloca(cNewArray*sizeof(char*));
  1557. // copy old value first
  1558. for(int i =0; i< argc-1; i++)
  1559. {
  1560. pNewArgv[i] = (char*) _alloca(sizeof(char) * (strlen(argv[i])+1));
  1561. strcpy(pNewArgv[i], argv[i]);
  1562. }
  1563. for(; i<cNewArray; i++)
  1564. {
  1565. if(pArg == NULL || *pArg == '\0')
  1566. return WBEM_E_INVALID_PARAMETER;
  1567. pArg = GetNextArg(pArg , &(pNewArgv[i]));
  1568. }
  1569. return CDnsRpcRecord::BuildRpcRecord(cNewArray,
  1570. pNewArgv);
  1571. }
  1572. return CDnsRpcRecord::BuildRpcRecord(
  1573. argc,
  1574. argv);
  1575. }
  1576. DWORD
  1577. CDnsRpcWINS::GetCacheTimeOut()
  1578. {
  1579. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1580. return pData->WINS.dwCacheTimeout;
  1581. }
  1582. DWORD
  1583. CDnsRpcWINS::GetLookupTimeOut()
  1584. {
  1585. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1586. return pData->WINS.dwLookupTimeout;
  1587. }
  1588. DWORD
  1589. CDnsRpcWINS::GetMapFlag()
  1590. {
  1591. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1592. return pData->WINS.dwMappingFlag;
  1593. }
  1594. wstring
  1595. CDnsRpcWINS::GetWinServer()
  1596. {
  1597. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1598. wstring wstrServers;
  1599. for(int i=0; i < pData->WINS.cWinsServerCount; i++)
  1600. {
  1601. wstrServers += IpAddressToString(
  1602. pData->WINS.aipWinsServers[i]);
  1603. wstrServers +=L" ";
  1604. }
  1605. return L"\"" + wstrServers + L"\"";
  1606. }
  1607. wstring
  1608. CDnsRpcWINS::GetData(void)
  1609. {
  1610. WCHAR temp[MAX_PATH];
  1611. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1612. swprintf(temp,
  1613. L"%d %d %d ",
  1614. pData->WINS.dwMappingFlag,
  1615. pData->WINS.dwLookupTimeout,
  1616. pData->WINS.dwCacheTimeout);
  1617. return temp + GetWinServer() ;
  1618. }
  1619. // CDnsRpcWINSR
  1620. CDnsRpcWINSR::~CDnsRpcWINSR()
  1621. {
  1622. }
  1623. CDnsRpcWINSR::CDnsRpcWINSR(
  1624. WORD wType)
  1625. :CDnsRpcRecord(NUM_OF_ARG_IN_RDATA)
  1626. {
  1627. m_wType = wType;
  1628. m_pwszClassName = PVD_CLASS_RR_WINSR;
  1629. }
  1630. SCODE
  1631. CDnsRpcWINSR::ConvertToWbemObject(
  1632. CWbemClassObject& Inst)
  1633. {
  1634. Inst.SetProperty(
  1635. GetCacheTimeOut(),
  1636. PVD_REC_WINSR_CACHE_TIMEOUT);
  1637. Inst.SetProperty(
  1638. GetLookupTimeOut(),
  1639. PVD_REC_WINSR_TIMEOUT);
  1640. Inst.SetProperty(
  1641. GetMapFlag(),
  1642. PVD_REC_WINSR_MAPPING_FLAG );
  1643. Inst.SetProperty(
  1644. GetResultDomain(),
  1645. PVD_REC_WINSR_RESULT_DOMAIN);
  1646. Inst.SetProperty(
  1647. GetData(),
  1648. PVD_REC_RDATA);
  1649. CDnsRpcRecord::ConvertToWbemObject(Inst);
  1650. return WBEM_NO_ERROR;
  1651. }
  1652. const
  1653. WCHAR**
  1654. CDnsRpcWINSR::GetRdataName(void)
  1655. {
  1656. static const WCHAR* pwsz[] ={
  1657. PVD_REC_WINSR_MAPPING_FLAG,
  1658. PVD_REC_WINSR_TIMEOUT,
  1659. PVD_REC_WINSR_CACHE_TIMEOUT,
  1660. PVD_REC_WINSR_RESULT_DOMAIN};
  1661. return pwsz;
  1662. }
  1663. DWORD
  1664. CDnsRpcWINSR::GetCacheTimeOut()
  1665. {
  1666. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1667. return pData->WINSR.dwCacheTimeout;
  1668. }
  1669. DWORD
  1670. CDnsRpcWINSR::GetLookupTimeOut()
  1671. {
  1672. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1673. return pData->WINSR.dwLookupTimeout;
  1674. }
  1675. DWORD
  1676. CDnsRpcWINSR::GetMapFlag()
  1677. {
  1678. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1679. return pData->WINSR.dwMappingFlag;
  1680. }
  1681. wstring
  1682. CDnsRpcWINSR::GetResultDomain()
  1683. {
  1684. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1685. wstring wstrTxt;
  1686. RpcNameCopy(wstrTxt, &(pData->WINSR.nameResultDomain));
  1687. return wstrTxt;
  1688. }
  1689. wstring
  1690. CDnsRpcWINSR::GetData(void)
  1691. {
  1692. WCHAR temp[MAX_PATH];
  1693. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1694. swprintf(temp,
  1695. L"%d %d %d ",
  1696. pData->WINSR.dwMappingFlag,
  1697. pData->WINSR.dwLookupTimeout,
  1698. pData->WINSR.dwCacheTimeout);
  1699. return temp + GetResultDomain();
  1700. }
  1701. // CDnsRpcNULL
  1702. CDnsRpcNULL::~CDnsRpcNULL()
  1703. {
  1704. }
  1705. CDnsRpcNULL::CDnsRpcNULL(
  1706. WORD wType)
  1707. :CDnsRpcRecord(NUM_OF_ARG_IN_RDATA)
  1708. {
  1709. m_wType = wType;
  1710. m_pwszClassName = PVD_CLASS_RR_NULL;
  1711. }
  1712. SCODE
  1713. CDnsRpcNULL::ConvertToWbemObject(
  1714. CWbemClassObject& Inst)
  1715. {
  1716. Inst.SetProperty(
  1717. GetNullData(),
  1718. PVD_REC_NULL_NULLDATA);
  1719. Inst.SetProperty(
  1720. GetData(),
  1721. PVD_REC_RDATA);
  1722. CDnsRpcRecord::ConvertToWbemObject(Inst);
  1723. return WBEM_NO_ERROR;
  1724. }
  1725. const
  1726. WCHAR**
  1727. CDnsRpcNULL::GetRdataName(void)
  1728. {
  1729. return NULL;
  1730. }
  1731. const
  1732. WCHAR**
  1733. CDnsRpcA::GetRdataName(void)
  1734. {
  1735. static const WCHAR* pwsz[] ={ PVD_REC_A_IP};
  1736. return pwsz;
  1737. }
  1738. wstring
  1739. CDnsRpcNULL::GetData(void)
  1740. {
  1741. return GetNullData();
  1742. }
  1743. wstring
  1744. CDnsRpcNULL::GetNullData(void)
  1745. {
  1746. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1747. WCHAR temp[1000];
  1748. WCHAR* pos = temp;
  1749. for(int i=0; i < m_pRecord->wDataLength; i++)
  1750. {
  1751. swprintf(pos++,L"%c",pData->Null.bData[i]);
  1752. }
  1753. return temp;
  1754. }
  1755. SCODE
  1756. CDnsRpcNULL::Init(
  1757. wstring& wstrClass,
  1758. string& strOwner,
  1759. string& strRdata,
  1760. CWbemClassObject& pInst
  1761. )
  1762. {
  1763. return WBEM_E_NOT_SUPPORTED;
  1764. }
  1765. SCODE
  1766. CDnsRpcNULL::Init(
  1767. string& strOwner,
  1768. string& strRdata,
  1769. DWORD dwTtl)
  1770. {
  1771. return WBEM_E_NOT_SUPPORTED;
  1772. }
  1773. // CDnsRpcATMA
  1774. CDnsRpcATMA::~CDnsRpcATMA()
  1775. {
  1776. }
  1777. CDnsRpcATMA::CDnsRpcATMA(
  1778. WORD wType)
  1779. :CDnsRpcRecord(NUM_OF_ARG_IN_RDATA)
  1780. {
  1781. m_wType = wType;
  1782. m_pwszClassName = PVD_CLASS_RR_ATMA;
  1783. }
  1784. SCODE
  1785. CDnsRpcATMA::ConvertToWbemObject(
  1786. CWbemClassObject& Inst)
  1787. {
  1788. Inst.SetProperty(
  1789. GetFormat(),
  1790. PVD_REC_ATMA_FORMAT);
  1791. Inst.SetProperty(
  1792. GetData(),
  1793. PVD_REC_RDATA);
  1794. CDnsRpcRecord::ConvertToWbemObject(Inst);
  1795. return WBEM_NO_ERROR;
  1796. }
  1797. wstring
  1798. CDnsRpcATMA::GetData(void)
  1799. {
  1800. WCHAR temp[MAX_PATH];
  1801. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1802. swprintf(temp,
  1803. L" %d ",
  1804. pData->ATMA.chFormat);
  1805. return temp + GetAddress();
  1806. }
  1807. DWORD
  1808. CDnsRpcATMA::GetFormat(void)
  1809. {
  1810. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1811. return pData->ATMA.chFormat;
  1812. }
  1813. wstring
  1814. CDnsRpcATMA::GetAddress()
  1815. {
  1816. PDNS_RPC_RECORD_DATA pData = &(m_pRecord->Data);
  1817. char temp[MAX_PATH];
  1818. WORD wLength = m_pRecord->wDataLength -
  1819. sizeof(pData->ATMA.chFormat)-1;
  1820. UCHAR* p = &pData->ATMA.bAddress[1]; //ignore the first
  1821. for(WORD i=0; i< wLength; i++)
  1822. {
  1823. temp[i] = *p++;
  1824. }
  1825. temp[i]='\0';
  1826. wstring wstr = CharToWstring(temp, wLength);
  1827. return wstr;
  1828. }
  1829. const
  1830. WCHAR**
  1831. CDnsRpcATMA::GetRdataName(void)
  1832. {
  1833. return NULL;
  1834. }
  1835. SCODE
  1836. CDnsRpcATMA::Init(
  1837. wstring& wstrClass,
  1838. string& strOwner,
  1839. string& strRdata,
  1840. CWbemClassObject& pInst
  1841. )
  1842. {
  1843. return WBEM_E_NOT_SUPPORTED;
  1844. }
  1845. SCODE
  1846. CDnsRpcATMA::Init(
  1847. string& strOwner,
  1848. string& strRdata,
  1849. DWORD dwTtl)
  1850. {
  1851. return WBEM_E_NOT_SUPPORTED;
  1852. }
  1853. //////////////////////////////////////////////////////////////////////
  1854. // Construction/Destruction
  1855. //////////////////////////////////////////////////////////////////////
  1856. CDnsRpcRecordSet::~CDnsRpcRecordSet()
  1857. {
  1858. DnssrvFreeRecordsBuffer(m_pbStart);
  1859. }
  1860. CDnsRpcRecordSet::CDnsRpcRecordSet(
  1861. CDomainNode& DomainNode,
  1862. WORD wType,
  1863. DWORD dwFlag,
  1864. LPCSTR pszFilterStart,
  1865. LPCSTR pszFilterStop
  1866. )
  1867. :m_pbStart(NULL),m_pbCurrent(NULL),m_pbStop(NULL),
  1868. m_pbPrevious(NULL), m_bMoreData(FALSE)
  1869. {
  1870. // remember query
  1871. WcharToString(DomainNode.wstrZoneName.data(), m_strZone);
  1872. WcharToString(DomainNode.wstrNodeName.data(), m_strNode);
  1873. WcharToString(DomainNode.wstrChildName.data(), m_strStartChild);
  1874. m_wType = wType;
  1875. m_dwFlag = dwFlag;
  1876. if(pszFilterStart)
  1877. m_strFilterStart = pszFilterStart;
  1878. if(pszFilterStop)
  1879. m_strFilterStop = pszFilterStop;
  1880. // make query
  1881. GetRecordSet();
  1882. }
  1883. /////////////////////////////////////////////////////////////////////////////
  1884. //++
  1885. //
  1886. // Description:
  1887. // a helper function when first called, it returns a block of rpc memory
  1888. // of the record set. when more data follows, the next call release this
  1889. // memory block and then bring in next rpc memory block for the remaining
  1890. // records
  1891. //
  1892. // Arguments:
  1893. // wType [IN] type indicating the type of record
  1894. // pptr [OUT] a pointer to base record class.
  1895. // Return Value:
  1896. //
  1897. //--
  1898. /////////////////////////////////////////////////////////////////////////////
  1899. void
  1900. CDnsRpcRecordSet::GetRecordSet()
  1901. {
  1902. DNS_STATUS status = ERROR_SUCCESS;
  1903. DWORD dwBufferLength;
  1904. PBYTE pBuffer;
  1905. WORD wRetryTime=1, wRetryMax=3;
  1906. while(TRUE)
  1907. {
  1908. status = DnssrvEnumRecords(
  1909. PVD_DNS_LOCAL_SERVER,
  1910. m_strZone.empty() ? NULL : m_strZone.data(),
  1911. m_strNode.empty() ? "@" : m_strNode.data(),
  1912. m_strStartChild.empty() ? NULL : m_strStartChild.data(),
  1913. m_wType,
  1914. m_dwFlag,
  1915. m_strFilterStart.data(),
  1916. m_strFilterStop.data(),
  1917. &dwBufferLength,
  1918. &pBuffer);
  1919. wRetryTime++;
  1920. if( status == RPC_S_SERVER_TOO_BUSY && wRetryTime <= wRetryMax)
  1921. {
  1922. Sleep(2000);
  1923. }
  1924. else
  1925. {
  1926. break;
  1927. }
  1928. }
  1929. if( status == ERROR_SUCCESS || status == ERROR_MORE_DATA)
  1930. {
  1931. //let's free the record set
  1932. if(m_pbStart != NULL)
  1933. {
  1934. DnssrvFreeRecordsBuffer(m_pbStart);
  1935. }
  1936. // set beginning pointer to the rpc buffer
  1937. m_pbStart = pBuffer;
  1938. m_pbStop = m_pbStart + dwBufferLength;
  1939. m_bMoreData = (status == ERROR_MORE_DATA);
  1940. }
  1941. //
  1942. // we don't throw exeception if zone is shutdown.
  1943. //
  1944. else if(status == DNS_ERROR_NAME_DOES_NOT_EXIST)
  1945. {
  1946. DNS_STATUS CheckZoneStatus;
  1947. PDNS_RPC_ZONE_INFO pZoneInfo=NULL;
  1948. CheckZoneStatus = DnssrvGetZoneInfo(
  1949. PVD_DNS_LOCAL_SERVER,
  1950. m_strZone.data(),
  1951. &pZoneInfo );
  1952. BOOL bShutDown=TRUE;
  1953. if( CheckZoneStatus == ERROR_SUCCESS)
  1954. {
  1955. // if zone is shutdown, ignor this zone, continue with the
  1956. // rest zones
  1957. bShutDown = pZoneInfo->fShutdown;
  1958. }
  1959. //clean up
  1960. DnssrvFreeZoneInfo(pZoneInfo);
  1961. if( CheckZoneStatus != ERROR_SUCCESS || bShutDown == FALSE )
  1962. {
  1963. CDnsWrap::ThrowException(status);
  1964. }
  1965. }
  1966. else
  1967. CDnsWrap::ThrowException(status);
  1968. return;
  1969. }
  1970. /////////////////////////////////////////////////////////////////////////////
  1971. //++
  1972. //
  1973. // Description:
  1974. // return the next node in the record set
  1975. //
  1976. // Arguments:
  1977. // wType [IN] type indicating the type of record
  1978. // pptr [OUT] a pointer to base record class.
  1979. // Return Value:
  1980. //
  1981. //--
  1982. /////////////////////////////////////////////////////////////////////////////
  1983. const
  1984. PDNS_RPC_NODE
  1985. CDnsRpcRecordSet::GetNextNode()
  1986. {
  1987. if (m_pbCurrent >= m_pbStop)
  1988. {
  1989. return NULL;
  1990. }
  1991. //return first node if current is NULL
  1992. // otherwise, return the node follows the current
  1993. if (m_pbCurrent == NULL)
  1994. {
  1995. m_pbCurrent = m_pbStart;
  1996. }
  1997. else
  1998. {
  1999. m_pbPrevious = m_pbCurrent;
  2000. m_pbCurrent = IncrementPtrByNodeHead(m_pbCurrent);
  2001. while (m_cRecord -- > 0)
  2002. {
  2003. m_pbCurrent = IncrementPtrByRecord(m_pbCurrent);
  2004. }
  2005. }
  2006. if (m_pbCurrent >= m_pbStop)
  2007. {
  2008. // prepare another query if there are more data
  2009. if(m_bMoreData)
  2010. {
  2011. PDNS_RPC_NODE pNode = (PDNS_RPC_NODE)m_pbPrevious;
  2012. WORD wSize = pNode->dnsNodeName.cchNameLength;
  2013. PCHAR p = new CHAR[wSize+1];
  2014. if ( !p )
  2015. {
  2016. return NULL;
  2017. }
  2018. strncpy(p,
  2019. pNode->dnsNodeName.achName,
  2020. wSize);
  2021. *(p+wSize) = '\0';
  2022. m_strStartChild = p;
  2023. delete [] p;
  2024. // query again
  2025. GetRecordSet();
  2026. // skip the first record, since it's the last record in
  2027. // previous rpc buffer and it's already handled
  2028. m_pbCurrent = m_pbStart;
  2029. m_cRecord = ((PDNS_RPC_NODE)m_pbCurrent)->wRecordCount;
  2030. return GetNextNode();
  2031. }
  2032. else
  2033. {
  2034. return NULL;
  2035. }
  2036. }
  2037. else
  2038. {
  2039. m_cRecord = ((PDNS_RPC_NODE)m_pbCurrent)->wRecordCount;
  2040. return (PDNS_RPC_NODE) m_pbCurrent;
  2041. }
  2042. }
  2043. BOOL
  2044. CDnsRpcRecordSet::IsDomainNode()
  2045. {
  2046. return (m_cRecord == 0);
  2047. }
  2048. //class defination for CDnsRpcNode
  2049. CDnsRpcNode::~CDnsRpcNode()
  2050. {
  2051. }
  2052. CDnsRpcNode::CDnsRpcNode()
  2053. {
  2054. }
  2055. BOOL
  2056. CDnsRpcNode::Init(
  2057. PDNS_RPC_NODE pNode)
  2058. {
  2059. if(!pNode)
  2060. {
  2061. return FALSE;
  2062. }
  2063. m_pNode = pNode;
  2064. m_cRecord = m_pNode->wRecordCount;
  2065. m_Index = 0;
  2066. m_pCurrent = NULL;
  2067. PDNS_RPC_NAME pName = &(m_pNode->dnsNodeName);
  2068. m_wstrNodeName = CharToWstring(
  2069. pName->achName,
  2070. (WORD)pName->cchNameLength);
  2071. return TRUE;
  2072. }
  2073. BOOL
  2074. CDnsRpcNode::IsDomainNode()
  2075. {
  2076. return ( m_cRecord == 0 && m_Index ==0 && !m_wstrNodeName.empty());
  2077. }
  2078. wstring
  2079. CDnsRpcNode::GetNodeName()
  2080. {
  2081. return m_wstrNodeName;
  2082. }
  2083. CDnsRpcRecord*
  2084. CDnsRpcNode::GetNextRecord()
  2085. {
  2086. if(m_cRecord == 0 || m_pNode == NULL)
  2087. {
  2088. return NULL;
  2089. }
  2090. CDnsRpcRecord * pRec = NULL;
  2091. if (m_Index < m_cRecord )
  2092. {
  2093. if(m_Index ++ == 0)
  2094. {
  2095. m_pCurrent = IncrementPtrByNodeHead((PBYTE)m_pNode);
  2096. }
  2097. else
  2098. {
  2099. m_pCurrent = IncrementPtrByRecord((PBYTE) m_pCurrent);
  2100. }
  2101. SCODE sc = CDnsRpcRecord::CreateClass(
  2102. ((PDNS_RPC_RECORD)m_pCurrent)->wType,
  2103. (PVOID*) &pRec
  2104. );
  2105. if ( SUCCEEDED ( sc ) && pRec )
  2106. {
  2107. pRec->Init( (PDNS_RPC_RECORD)m_pCurrent);
  2108. return pRec;
  2109. }
  2110. else
  2111. {
  2112. return NULL;
  2113. }
  2114. }
  2115. else
  2116. {
  2117. return NULL;
  2118. }
  2119. }
  2120. /////////////////////////////////////////////////////////////////////////////
  2121. //++
  2122. //
  2123. // Description:
  2124. // build a rpc record based on rdata arguments
  2125. //
  2126. // Arguments:
  2127. // argc [IN] number of argument in argv
  2128. // argv [IN] array of string represent
  2129. //
  2130. // Return Value:
  2131. // WBEM_S_NO_ERROR
  2132. //
  2133. //--
  2134. /////////////////////////////////////////////////////////////////////////////
  2135. SCODE
  2136. CDnsRpcRecord::BuildRpcRecord(
  2137. WORD argc,
  2138. char ** argv)
  2139. {
  2140. PDNS_RECORD pdnsRecord;
  2141. pdnsRecord = Dns_RecordBuild_A(
  2142. NULL, // ptr to RRSet
  2143. (char*) m_strOwnerName.data(), //NULL, //(char*) strFQDN.data(), // nameOwner
  2144. m_wType, // RR type in WORD
  2145. TRUE, // add record
  2146. 0, // S.section
  2147. argc, // count of strings
  2148. argv // strings to fill into RR
  2149. );
  2150. if ( ! pdnsRecord )
  2151. {
  2152. return WBEM_E_INVALID_PARAMETER;
  2153. }
  2154. // convert DNS_RECORD to RPC buffer
  2155. m_pRecord = DnsConvertRecordToRpcBuffer( pdnsRecord );
  2156. m_pRecordRequiresFree = TRUE;
  2157. if ( ! m_pRecord )
  2158. {
  2159. return WBEM_E_FAILED;
  2160. }
  2161. if( m_dwTtl != 0)
  2162. {
  2163. m_pRecord->dwTtlSeconds = m_dwTtl;
  2164. m_pRecord->dwFlags = DNS_RPC_RECORD_FLAG_TTL_CHANGE;
  2165. }
  2166. else
  2167. {
  2168. m_pRecord->dwFlags = DNS_RPC_RECORD_FLAG_DEFAULT_TTL;
  2169. }
  2170. return WBEM_S_NO_ERROR;
  2171. }
  2172. wstring CDnsRpcRecord::GetTypeString()
  2173. {
  2174. if(m_pRecord==NULL)
  2175. {
  2176. return CharToWstring( NULL, 0 );
  2177. }
  2178. PCHAR pszType = Dns_RecordStringForType( m_pRecord->wType );
  2179. return CharToWstring(pszType, strlen(pszType));
  2180. }