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.

1108 lines
24 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. dconvert.c
  5. Abstract:
  6. Domain Name System (DNS) Server -- Admin Client Library
  7. RPC record conversion routines.
  8. Convert DNS_RECORD records into RPC buffer.
  9. Author:
  10. Jing Chen (t-jingc) June, 1998
  11. reverse functions of rconvert.c
  12. Revision History:
  13. --*/
  14. #include "dnsclip.h"
  15. //
  16. // size of string in RPC format
  17. //
  18. #define STRING_UTF8_BUF_SIZE( string, fUnicode ) \
  19. Dns_GetBufferLengthForStringCopy( \
  20. (string), \
  21. 0, \
  22. ((fUnicode) ? DnsCharSetUnicode : DnsCharSetUtf8), \
  23. DnsCharSetUtf8 )
  24. #if 0
  25. // with comments
  26. Dns_GetBufferLengthForStringCopy( \
  27. (string), \ // string
  28. 0, \ // unknown length
  29. ((fUnicode) ? DnsCharSetUnicode : DnsCharSetUtf8), \ // in string
  30. DnsCharSetUtf8 ) // RPC string always UTF8
  31. #endif
  32. //
  33. // Writing strings to RPC buffer format
  34. //
  35. #define WRITE_STRING_TO_RPC_BUF(buf, psz, len, funicode) \
  36. Dns_StringCopy( \
  37. (buf), \
  38. NULL, \
  39. (psz), \
  40. (len), \
  41. ((funicode) ? DnsCharSetUnicode : DnsCharSetUtf8), \
  42. DnsCharSetUtf8 )
  43. #if 0
  44. // with commments
  45. Dns_StringCopy( \
  46. (buf), \ // buffer
  47. NULL, \ // adequate buffer length
  48. (psz), \ // string
  49. (len), \ // string length (if known)
  50. ((funicode) ? DnsCharSetUnicode : DnsCharSet), \ // input format
  51. DnsCharSetUtf8 ) // RPC buffer always in UTF8
  52. #endif
  53. //
  54. // size of name in RPC format
  55. //
  56. #define NAME_UTF8_BUF_SIZE( string, fUnicode ) \
  57. Dns_GetBufferLengthForStringCopy( \
  58. (string), \
  59. 0, \
  60. ((fUnicode) ? DnsCharSetUnicode : DnsCharSetUtf8), \
  61. DnsCharSetUtf8 )
  62. #if 0
  63. // with comments
  64. Dns_GetBufferLengthForStringCopy( \
  65. (string), \ // string
  66. 0, \ // unknown length
  67. ((fUnicode) ? DnsCharSetUnicode : DnsCharSetUtf8), \ // in string
  68. DnsCharSetUtf8 ) // RPC string always UTF8
  69. #endif
  70. //
  71. // Writing names to RPC buffer format
  72. //
  73. #define WRITE_NAME_TO_RPC_BUF(buf, psz, len, funicode) \
  74. Dns_StringCopy( \
  75. (buf), \
  76. NULL, \
  77. (psz), \
  78. (len), \
  79. ((funicode) ? DnsCharSetUnicode : DnsCharSetUtf8), \
  80. DnsCharSetUtf8 )
  81. #if 0
  82. // with commments
  83. Dns_StringCopy( \
  84. (buf), \ // buffer
  85. NULL, \ // adequate buffer length
  86. (psz), \ // string
  87. (len), \ // string length (if known)
  88. ((funicode) ? DnsCharSetUnicode : DnsCharSet), \ // input format
  89. DnsCharSetUtf8 ) // RPC buffer always in UTF8
  90. #endif
  91. //
  92. // Private protos
  93. //
  94. PDNS_RPC_RECORD
  95. Rpc_AllocateRecord(
  96. IN DWORD BufferLength
  97. );
  98. //
  99. // RPC buffer conversion functions
  100. //
  101. PDNS_RPC_RECORD
  102. ADnsRecordConvert(
  103. IN PDNS_RECORD pRR
  104. )
  105. /*++
  106. Routine Description:
  107. Convert A record from DNS Record to RPC buffer.
  108. Arguments:
  109. pRR - record being read
  110. Return Value:
  111. Ptr to new RPC buffer if successful.
  112. NULL on failure.
  113. --*/
  114. {
  115. PDNS_RPC_RECORD prpcRR;
  116. DNS_ASSERT( pRR->wDataLength == sizeof(IP_ADDRESS) );
  117. prpcRR = Rpc_AllocateRecord( sizeof(IP_ADDRESS) );
  118. if ( !prpcRR )
  119. {
  120. return( NULL );
  121. }
  122. prpcRR->Data.A.ipAddress = pRR->Data.A.IpAddress;
  123. return( prpcRR);
  124. }
  125. PDNS_RPC_RECORD
  126. PtrDnsRecordConvert(
  127. IN PDNS_RECORD pRR
  128. )
  129. /*++
  130. Routine Description:
  131. Process PTR compatible record from wire.
  132. Includes: NS, PTR, CNAME, MB, MR, MG, MD, MF
  133. Arguments:
  134. pRR - record being read
  135. Return Value:
  136. Ptr to new RPC buffer if successful.
  137. NULL on failure.
  138. --*/
  139. {
  140. PDNS_RPC_RECORD prpcRR;
  141. DWORD length;
  142. BOOL funicode = IS_UNICODE_RECORD( pRR );
  143. //
  144. // PTR data is another domain name
  145. //
  146. // determine required buffer length and allocate
  147. //
  148. length = NAME_UTF8_BUF_SIZE(pRR->Data.PTR.pNameHost, funicode);
  149. prpcRR = Rpc_AllocateRecord( sizeof(DNS_RPC_NAME) + length );
  150. if ( !prpcRR )
  151. {
  152. return( NULL );
  153. }
  154. //
  155. // write hostname into buffer, immediately following PTR data struct
  156. //
  157. prpcRR->Data.PTR.nameNode.cchNameLength = (UCHAR)length;
  158. WRITE_NAME_TO_RPC_BUF(
  159. prpcRR->Data.PTR.nameNode.achName, // buffer
  160. pRR->Data.PTR.pNameHost,
  161. 0,
  162. funicode );
  163. return( prpcRR );
  164. }
  165. PDNS_RPC_RECORD
  166. SoaDnsRecordConvert(
  167. IN PDNS_RECORD pRR
  168. )
  169. /*++
  170. Routine Description:
  171. Convert SOA record from DNS Record to RPC buffer.
  172. Arguments:
  173. pRR - ptr to record being read
  174. Return Value:
  175. Ptr to new RPC buffer if successful.
  176. NULL on failure.
  177. --*/
  178. {
  179. PDNS_RPC_RECORD prpcRR;
  180. DWORD length1;
  181. DWORD length2;
  182. PDNS_RPC_NAME pnamePrimary;
  183. PDNS_RPC_NAME pnameAdmin;
  184. BOOL funicode = IS_UNICODE_RECORD( pRR );
  185. //
  186. // determine required buffer length and allocate
  187. //
  188. length1 = NAME_UTF8_BUF_SIZE( pRR->Data.SOA.pNamePrimaryServer, funicode );
  189. length2 = NAME_UTF8_BUF_SIZE( pRR->Data.SOA.pNameAdministrator, funicode );
  190. prpcRR = Rpc_AllocateRecord(
  191. SIZEOF_SOA_FIXED_DATA + sizeof(DNS_RPC_NAME) * 2 +
  192. length1 + length2 );
  193. if ( !prpcRR )
  194. {
  195. return( NULL );
  196. }
  197. //
  198. // copy fixed fields
  199. //
  200. RtlCopyMemory(
  201. (PCHAR) & prpcRR->Data.SOA.dwSerialNo,
  202. (PCHAR) & pRR->Data.SOA.dwSerialNo,
  203. SIZEOF_SOA_FIXED_DATA );
  204. //
  205. // copy names into RR buffer
  206. // - primary server immediately follows SOA data struct
  207. // - responsible party follows primary server
  208. //
  209. pnamePrimary = &prpcRR->Data.SOA.namePrimaryServer;
  210. pnamePrimary->cchNameLength = (UCHAR) length1;
  211. pnameAdmin = DNS_GET_NEXT_NAME( pnamePrimary );
  212. pnameAdmin->cchNameLength = (UCHAR) length2;
  213. WRITE_NAME_TO_RPC_BUF(
  214. pnamePrimary->achName,
  215. pRR->Data.Soa.pNamePrimaryServer,
  216. 0,
  217. funicode );
  218. WRITE_NAME_TO_RPC_BUF(
  219. pnameAdmin->achName,
  220. pRR->Data.Soa.pNameAdministrator,
  221. 0,
  222. funicode );
  223. return( prpcRR );
  224. }
  225. PDNS_RPC_RECORD
  226. TxtDnsRecordConvert(
  227. IN PDNS_RECORD pRR
  228. )
  229. /*++
  230. Routine Description:
  231. Read TXT compatible record from wire.
  232. Includes: TXT, X25, HINFO, ISDN
  233. Arguments:
  234. pRR - record being read
  235. Return Value:
  236. Ptr to new RPC buffer if successful.
  237. NULL on failure.
  238. --*/
  239. {
  240. PDNS_RPC_RECORD prpcRR;
  241. DWORD bufLength;
  242. DWORD length;
  243. INT count;
  244. PCHAR pch;
  245. PCHAR * ppstring;
  246. BOOL funicode = IS_UNICODE_RECORD( pRR );
  247. //
  248. // determine required buffer length and allocate
  249. // - allocate space for each string
  250. // - and ptr for each string
  251. //
  252. bufLength = 0;
  253. count = pRR->Data.TXT.dwStringCount;
  254. ppstring = pRR->Data.TXT.pStringArray;
  255. while ( count-- )
  256. {
  257. //
  258. // Note: sizeof(DNS_RPC_NAME) is two: 1 char for the length value
  259. // and 1 char for the first char in the name. The max string length
  260. // is 255 because we store the string length in a single byte.
  261. //
  262. length = STRING_UTF8_BUF_SIZE( *ppstring++, funicode );
  263. if ( length > 255 )
  264. {
  265. return NULL;
  266. }
  267. bufLength += sizeof(DNS_RPC_NAME) + length - 1;
  268. }
  269. // allocate
  270. prpcRR = Rpc_AllocateRecord( bufLength );
  271. if ( !prpcRR )
  272. {
  273. return( NULL );
  274. }
  275. //
  276. // go back through list copying strings to buffer
  277. // - ptrs to strings are saved to argv like data section
  278. // ppstring walks through this section
  279. // - first string written immediately following data section
  280. // - each subsequent string immediately follows predecessor
  281. // pchbuffer keeps ptr to position to write strings
  282. //
  283. // DEVNOTE: this is a mess
  284. //
  285. pch = (PCHAR) &prpcRR->Data.TXT;
  286. ppstring = pRR->Data.TXT.pStringArray;
  287. count = pRR->Data.TXT.dwStringCount;
  288. while ( count-- )
  289. {
  290. length = STRING_UTF8_BUF_SIZE( *ppstring, funicode );
  291. (UCHAR) *pch++ += (UCHAR) length; //+1 for TXT type only
  292. length = WRITE_STRING_TO_RPC_BUF(
  293. pch,
  294. *ppstring++,
  295. 0,
  296. funicode
  297. );
  298. pch += length;
  299. #if DBG
  300. DNS_PRINT((
  301. "Read text string %s\n",
  302. * (ppstring - 1)
  303. ));
  304. #endif
  305. }
  306. return( prpcRR );
  307. }
  308. PDNS_RPC_RECORD
  309. MinfoDnsRecordConvert(
  310. IN PDNS_RECORD pRR
  311. )
  312. /*++
  313. Routine Description:
  314. Read MINFO record from wire.
  315. Arguments:
  316. pRR - record being read
  317. Return Value:
  318. Ptr to new RPC buffer if successful.
  319. NULL on failure.
  320. --*/
  321. {
  322. PDNS_RPC_RECORD prpcRR;
  323. DWORD length1;
  324. DWORD length2;
  325. PDNS_RPC_NAME prpcName1;
  326. PDNS_RPC_NAME prpcName2;
  327. BOOL funicode = IS_UNICODE_RECORD( pRR );
  328. //
  329. // determine required buffer length and allocate
  330. //
  331. length1 = NAME_UTF8_BUF_SIZE( pRR->Data.MINFO.pNameMailbox, funicode );
  332. length2 = NAME_UTF8_BUF_SIZE( pRR->Data.MINFO.pNameErrorsMailbox, funicode );
  333. prpcRR = Rpc_AllocateRecord( sizeof(DNS_RPC_NAME) * 2 + length1 + length2 );
  334. if ( !prpcRR )
  335. {
  336. return( NULL );
  337. }
  338. //
  339. // copy names into RR buffer
  340. // - mailbox immediately follows MINFO data struct
  341. // - errors mailbox immediately follows primary server
  342. //
  343. prpcName1 = &prpcRR->Data.MINFO.nameMailBox;
  344. prpcName1->cchNameLength = (UCHAR) length1;
  345. prpcName2 = DNS_GET_NEXT_NAME( prpcName1);
  346. prpcName2->cchNameLength = (UCHAR) length2;
  347. WRITE_NAME_TO_RPC_BUF(
  348. prpcName1->achName,
  349. pRR->Data.MINFO.pNameMailbox,
  350. 0,
  351. funicode );
  352. WRITE_NAME_TO_RPC_BUF(
  353. prpcName2->achName,
  354. pRR->Data.MINFO.pNameErrorsMailbox,
  355. 0,
  356. funicode );
  357. return( prpcRR );
  358. }
  359. PDNS_RPC_RECORD
  360. MxDnsRecordConvert(
  361. IN PDNS_RECORD pRR
  362. )
  363. /*++
  364. Routine Description:
  365. convert MX compatible record.
  366. Includes: MX, RT, AFSDB
  367. Arguments:
  368. pRR - record being read
  369. Return Value:
  370. Ptr to new RPC buffer if successful.
  371. NULL on failure.
  372. --*/
  373. {
  374. PDNS_RPC_RECORD prpcRR;
  375. PDNS_RPC_NAME prpcName;
  376. DWORD length;
  377. BOOL funicode = IS_UNICODE_RECORD( pRR );
  378. //
  379. // determine required buffer length and allocate
  380. //
  381. length = NAME_UTF8_BUF_SIZE( pRR->Data.MX.pNameExchange, funicode );
  382. prpcRR = Rpc_AllocateRecord(
  383. SIZEOF_MX_FIXED_DATA + sizeof(DNS_RPC_NAME) + length );
  384. if ( !prpcRR )
  385. {
  386. return( NULL );
  387. }
  388. //
  389. // copy preference
  390. //
  391. prpcRR->Data.MX.wPreference = pRR->Data.MX.wPreference;
  392. //
  393. // write hostname into buffer, immediately following MX struct
  394. //
  395. prpcName = &prpcRR->Data.MX.nameExchange;
  396. prpcName->cchNameLength = (UCHAR) length;
  397. WRITE_NAME_TO_RPC_BUF(
  398. prpcName->achName,
  399. pRR->Data.MX.pNameExchange,
  400. 0,
  401. funicode );
  402. return( prpcRR );
  403. }
  404. PDNS_RPC_RECORD
  405. SigDnsRecordConvert(
  406. IN PDNS_RECORD pRR
  407. )
  408. /*++
  409. Routine Description:
  410. Convert SIG record.
  411. Arguments:
  412. pRR - record being read
  413. Return Value:
  414. Ptr to new RPC buffer if successful.
  415. NULL on failure.
  416. --*/
  417. {
  418. PDNS_RPC_RECORD prpcRR;
  419. PDNS_RPC_NAME prpcName;
  420. DWORD nameLength;
  421. DWORD sigLength;
  422. BOOL funicode = IS_UNICODE_RECORD( pRR );
  423. PBYTE pSig;
  424. nameLength = NAME_UTF8_BUF_SIZE( pRR->Data.SIG.pNameSigner, funicode );
  425. sigLength = (DWORD)(pRR->wDataLength -
  426. ( pRR->Data.SIG.Signature - ( PBYTE ) &pRR->Data.SIG ));
  427. prpcRR = Rpc_AllocateRecord(
  428. SIZEOF_SIG_FIXED_DATA + 1 + nameLength + sigLength );
  429. if ( !prpcRR )
  430. {
  431. return( NULL );
  432. }
  433. prpcRR->Data.SIG.wTypeCovered = pRR->Data.SIG.wTypeCovered;
  434. prpcRR->Data.SIG.chAlgorithm = pRR->Data.SIG.chAlgorithm;
  435. prpcRR->Data.SIG.chLabelCount = pRR->Data.SIG.chLabelCount;
  436. prpcRR->Data.SIG.dwOriginalTtl = pRR->Data.SIG.dwOriginalTtl;
  437. prpcRR->Data.SIG.dwSigExpiration = pRR->Data.SIG.dwExpiration;
  438. prpcRR->Data.SIG.dwSigInception = pRR->Data.SIG.dwTimeSigned;
  439. prpcRR->Data.SIG.wKeyTag = pRR->Data.SIG.wKeyTag;
  440. prpcName = &prpcRR->Data.SIG.nameSigner;
  441. prpcName->cchNameLength = ( UCHAR ) nameLength;
  442. WRITE_NAME_TO_RPC_BUF(
  443. prpcName->achName,
  444. pRR->Data.SIG.pNameSigner,
  445. 0,
  446. funicode );
  447. pSig = ( PBYTE ) DNS_GET_NEXT_NAME( prpcName );
  448. RtlCopyMemory( pSig, pRR->Data.SIG.Signature, sigLength );
  449. return prpcRR;
  450. } // SigDnsRecordConvert
  451. PDNS_RPC_RECORD
  452. NxtDnsRecordConvert(
  453. IN PDNS_RECORD pRR
  454. )
  455. /*++
  456. Routine Description:
  457. Convert NXT record.
  458. Arguments:
  459. pRR - record being read
  460. Return Value:
  461. Ptr to new RPC buffer if successful.
  462. NULL on failure.
  463. --*/
  464. {
  465. PDNS_RPC_RECORD prpcRR;
  466. PDNS_RPC_NAME prpcName;
  467. DWORD nameLength;
  468. BOOL funicode = IS_UNICODE_RECORD( pRR );
  469. //
  470. // Allocate the RPC record.
  471. //
  472. nameLength = NAME_UTF8_BUF_SIZE( pRR->Data.NXT.pNameNext, funicode );
  473. prpcRR = Rpc_AllocateRecord(
  474. nameLength + 1 +
  475. ( pRR->Data.NXT.wNumTypes + 1 ) * sizeof( WORD ) );
  476. if ( !prpcRR )
  477. {
  478. return( NULL );
  479. }
  480. //
  481. // Copy the type array.
  482. //
  483. prpcRR->Data.Nxt.wNumTypeWords = pRR->Data.NXT.wNumTypes;
  484. RtlCopyMemory(
  485. prpcRR->Data.Nxt.wTypeWords,
  486. pRR->Data.NXT.wTypes,
  487. pRR->Data.NXT.wNumTypes * sizeof( WORD ) );
  488. //
  489. // Write the next name.
  490. //
  491. prpcName = ( PDNS_RPC_NAME ) (
  492. ( PBYTE ) &prpcRR->Data.NXT.wTypeWords +
  493. prpcRR->Data.Nxt.wNumTypeWords * sizeof( WORD ) );
  494. prpcName->cchNameLength = ( UCHAR ) nameLength;
  495. WRITE_NAME_TO_RPC_BUF(
  496. prpcName->achName,
  497. pRR->Data.NXT.pNameNext,
  498. 0,
  499. funicode );
  500. return prpcRR;
  501. } // NxtDnsRecordConvert
  502. PDNS_RPC_RECORD
  503. FlatDnsRecordConvert(
  504. IN PDNS_RECORD pRR
  505. )
  506. /*++
  507. Routine Description:
  508. Convert memory copy compatible record.
  509. Includes AAAA and WINS types.
  510. Arguments:
  511. pRR - record being read
  512. Return Value:
  513. Ptr to new RPC buffer if successful.
  514. NULL on failure.
  515. --*/
  516. {
  517. PDNS_RPC_RECORD prpcRR;
  518. DWORD bufLength;
  519. //
  520. // determine required buffer length and allocate
  521. //
  522. bufLength = pRR->wDataLength;
  523. prpcRR = Rpc_AllocateRecord( bufLength );
  524. if ( !prpcRR )
  525. {
  526. return( NULL );
  527. }
  528. //
  529. // copy packet data to record
  530. //
  531. RtlCopyMemory(
  532. & prpcRR->Data,
  533. & pRR->Data,
  534. bufLength );
  535. return( prpcRR );
  536. }
  537. PDNS_RPC_RECORD
  538. SrvDnsRecordConvert(
  539. IN PDNS_RECORD pRR
  540. )
  541. /*++
  542. Routine Description:
  543. convert SRV record.
  544. Arguments:
  545. pRR - record being read
  546. Return Value:
  547. Ptr to new RPC buffer if successful.
  548. NULL on failure.
  549. --*/
  550. {
  551. PDNS_RPC_RECORD prpcRR;
  552. PDNS_RPC_NAME prpcName;
  553. DWORD length;
  554. BOOL funicode = IS_UNICODE_RECORD( pRR );
  555. //
  556. // determine required buffer length and allocate
  557. //
  558. length = NAME_UTF8_BUF_SIZE( pRR->Data.SRV.pNameTarget, funicode );
  559. prpcRR = Rpc_AllocateRecord(
  560. SIZEOF_SRV_FIXED_DATA + sizeof(DNS_RPC_NAME) + length );
  561. if ( !prpcRR )
  562. {
  563. return( NULL );
  564. }
  565. //
  566. // copy SRV fixed fields
  567. //
  568. prpcRR->Data.SRV.wPriority = pRR->Data.SRV.wPriority;
  569. prpcRR->Data.SRV.wWeight = pRR->Data.SRV.wWeight;
  570. prpcRR->Data.SRV.wPort = pRR->Data.SRV.wPort;
  571. //
  572. // write hostname into buffer, immediately following SRV struct
  573. //
  574. prpcName = &prpcRR->Data.SRV.nameTarget;
  575. prpcName->cchNameLength = (UCHAR) length;
  576. WRITE_NAME_TO_RPC_BUF(
  577. prpcName->achName,
  578. pRR->Data.SRV.pNameTarget,
  579. 0,
  580. funicode );
  581. return( prpcRR );
  582. }
  583. PDNS_RPC_RECORD
  584. NbstatDnsRecordConvert(
  585. IN PDNS_RECORD pRR
  586. )
  587. /*++
  588. Routine Description:
  589. Read WINSR record from wire.
  590. Arguments:
  591. pRR - record being read
  592. Return Value:
  593. Ptr to new RPC buffer if successful.
  594. NULL on failure.
  595. --*/
  596. {
  597. PDNS_RPC_RECORD prpcRR;
  598. PDNS_RPC_NAME prpcName;
  599. DWORD length;
  600. BOOL funicode = IS_UNICODE_RECORD( pRR );
  601. //
  602. // determine required buffer length and allocate
  603. //
  604. length = NAME_UTF8_BUF_SIZE( pRR->Data.WINSR.pNameResultDomain, funicode );
  605. prpcRR = Rpc_AllocateRecord(
  606. SIZEOF_NBSTAT_FIXED_DATA + sizeof(DNS_RPC_NAME) + length );
  607. if ( !prpcRR )
  608. {
  609. return( NULL );
  610. }
  611. //
  612. // copy WINSR fixed fields
  613. //
  614. prpcRR->Data.WINSR.dwMappingFlag = pRR->Data.WINSR.dwMappingFlag;
  615. prpcRR->Data.WINSR.dwLookupTimeout = pRR->Data.WINSR.dwLookupTimeout;
  616. prpcRR->Data.WINSR.dwCacheTimeout = pRR->Data.WINSR.dwCacheTimeout;
  617. //
  618. // write hostname into buffer, immediately following WINSR struct
  619. //
  620. prpcName = &prpcRR->Data.WINSR.nameResultDomain;
  621. prpcName->cchNameLength = (UCHAR) length;
  622. WRITE_NAME_TO_RPC_BUF(
  623. prpcName->achName,
  624. pRR->Data.WINSR.pNameResultDomain,
  625. 0,
  626. funicode );
  627. return( prpcRR );
  628. }
  629. //
  630. // Jump table for DNS_RECORD => RPC buffer conversion.
  631. //
  632. typedef PDNS_RPC_RECORD (* RECORD_TO_RPC_CONVERT_FUNCTION)( PDNS_RECORD );
  633. RECORD_TO_RPC_CONVERT_FUNCTION RecordToRpcConvertTable[] =
  634. {
  635. NULL, // ZERO
  636. ADnsRecordConvert, // A
  637. PtrDnsRecordConvert, // NS
  638. PtrDnsRecordConvert, // MD
  639. PtrDnsRecordConvert, // MF
  640. PtrDnsRecordConvert, // CNAME
  641. SoaDnsRecordConvert, // SOA
  642. PtrDnsRecordConvert, // MB
  643. PtrDnsRecordConvert, // MG
  644. PtrDnsRecordConvert, // MR
  645. NULL, // NULL
  646. FlatDnsRecordConvert, // WKS
  647. PtrDnsRecordConvert, // PTR
  648. TxtDnsRecordConvert, // HINFO
  649. MinfoDnsRecordConvert, // MINFO
  650. MxDnsRecordConvert, // MX
  651. TxtDnsRecordConvert, // TXT
  652. MinfoDnsRecordConvert, // RP
  653. MxDnsRecordConvert, // AFSDB
  654. TxtDnsRecordConvert, // X25
  655. TxtDnsRecordConvert, // ISDN
  656. MxDnsRecordConvert, // RT
  657. NULL, // NSAP
  658. NULL, // NSAPPTR
  659. SigDnsRecordConvert, // SIG
  660. NULL, // KEY
  661. NULL, // PX
  662. NULL, // GPOS
  663. FlatDnsRecordConvert, // AAAA
  664. NULL, // 29
  665. NxtDnsRecordConvert, // 30
  666. NULL, // 31
  667. NULL, // 32
  668. SrvDnsRecordConvert, // SRV
  669. NULL, // ATMA
  670. NULL, // 35
  671. NULL, // 36
  672. NULL, // 37
  673. NULL, // 38
  674. NULL, // 39
  675. NULL, // 40
  676. NULL, // OPT
  677. NULL, // 42
  678. NULL, // 43
  679. NULL, // 44
  680. NULL, // 45
  681. NULL, // 46
  682. NULL, // 47
  683. NULL, // 48
  684. //
  685. // NOTE: last type indexed by type ID MUST be set
  686. // as MAX_SELF_INDEXED_TYPE #define in record.h
  687. // (see note above in record info table)
  688. // note these follow, but require OFFSET_TO_WINS_RR subtraction
  689. // from actual type value
  690. NULL, // TKEY
  691. NULL, // TSIG
  692. FlatDnsRecordConvert, // WINS
  693. NbstatDnsRecordConvert // WINS-R
  694. };
  695. PDNS_RPC_RECORD
  696. Rpc_AllocateRecord(
  697. IN DWORD BufferLength
  698. )
  699. /*++
  700. Routine Description:
  701. Allocate RPC record structure.
  702. Arguments:
  703. wBufferLength - desired buffer length (beyond structure header)
  704. Return Value:
  705. Ptr to buffer.
  706. NULL on error.
  707. --*/
  708. {
  709. PDNS_RPC_RECORD prr;
  710. if ( BufferLength > MAXWORD )
  711. {
  712. return( NULL );
  713. }
  714. prr = ALLOCATE_HEAP( SIZEOF_DNS_RPC_RECORD_HEADER + BufferLength );
  715. if ( !prr )
  716. {
  717. SetLastError( ERROR_NOT_ENOUGH_MEMORY );
  718. return( NULL );
  719. }
  720. // set datalength to buffer length
  721. prr->wDataLength = (WORD) BufferLength;
  722. return( prr );
  723. }
  724. PDNS_RPC_RECORD
  725. DnsConvertRecordToRpcBuffer(
  726. IN PDNS_RECORD pRecord
  727. )
  728. /*++
  729. Routine Description:
  730. Convert standard DNS record to RPC buffer.
  731. Arguments:
  732. pRecord -- DNS Record to be converted.
  733. //fUnicode -- flag, write records into unicode
  734. Return Value:
  735. Ptr to new RPC buffer if successful.
  736. NULL on failure.
  737. --*/
  738. {
  739. PDNS_RPC_RECORD prpcRecord;
  740. WORD index;
  741. WORD type;
  742. RECORD_TO_RPC_CONVERT_FUNCTION pFunc;
  743. DNS_ASSERT( DNS_IS_DWORD_ALIGNED(pRecord) );
  744. IF_DNSDBG( RPC2 )
  745. {
  746. DNS_PRINT((
  747. "Enter DnsConvertRecordToRpcBuffer()\n"
  748. "\tpRecord = %p\n",
  749. pRecord ));
  750. }
  751. //DNS_RRSET_INIT( rrset );
  752. //
  753. // convert record
  754. // set unicode flag if converting
  755. //
  756. //if ( fUnicode )
  757. //{
  758. //SET_RPC_UNICODE( pRecord );
  759. //}
  760. type = pRecord->wType;
  761. index = INDEX_FOR_TYPE( type );
  762. DNS_ASSERT( index <= MAX_RECORD_TYPE_INDEX );
  763. if ( !index || !(pFunc = RecordToRpcConvertTable[ index ]) )
  764. {
  765. // if unknown type try flat record copy -- best we can
  766. // do to protect if server added new types since admin built
  767. DNS_PRINT((
  768. "ERROR: no DNS_RECORD to RPC conversion routine for type %d.\n"
  769. "\tusing flat conversion routine.\n",
  770. type ));
  771. pFunc = FlatDnsRecordConvert;
  772. }
  773. prpcRecord = (*pFunc)( pRecord );
  774. if ( ! prpcRecord )
  775. {
  776. DNS_PRINT((
  777. "ERROR: Record build routine failure for record type %d.\n"
  778. "\tstatus = %p\n\n",
  779. type,
  780. GetLastError() ));
  781. return(NULL);
  782. }
  783. //
  784. // fill out record structure
  785. //
  786. prpcRecord->wType = type;
  787. prpcRecord->dwTtlSeconds = pRecord->dwTtl;
  788. //
  789. // DEVNOTE: data types (root hint, glue set)
  790. // - need way to default that works for NT4
  791. // (JJW: this is probably an obsolete B*GB*G)
  792. //
  793. /*
  794. if ( prpcRecord->dwFlags & DNS_RPC_RECORD_FLAG_CACHE_DATA )
  795. {
  796. precord->Flags.S.Section = DNSREC_CACHE_DATA;
  797. }
  798. else
  799. {
  800. precord->Flags.S.Section = DNSREC_ZONE_DATA;
  801. }
  802. */
  803. IF_DNSDBG( INIT )
  804. {
  805. DNS_PRINT((
  806. "New RPC buffer built\n"
  807. ));
  808. }
  809. IF_DNSDBG( RPC2 )
  810. {
  811. /*
  812. DnsDbg_RecordSet(
  813. "Finished DnsConvertRpcBufferToRecords() ",
  814. rrset.pFirstRR );
  815. */
  816. DNS_PRINT((
  817. "Finished DnsConvertRpcBufferToRecords() "
  818. ));
  819. }
  820. return(prpcRecord);
  821. }
  822. //
  823. // End dconvert.c
  824. //