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.

720 lines
23 KiB

  1. /*++
  2. Copyright (c) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. dnsutil.c
  5. Abstract:
  6. Domain Name System (DNS) Library
  7. General DNS utilities.
  8. Author:
  9. Jim Gilroy (jamesg) Decemeber 1996
  10. Revision History:
  11. --*/
  12. #include "local.h"
  13. IP4_ADDRESS
  14. Dns_GetNetworkMask(
  15. IN IP4_ADDRESS IpAddr
  16. )
  17. /*++
  18. Routine Description:
  19. Gets network mask for IP address.
  20. Note, this is standard IP network mask for address type,
  21. obviously subnetting is unknown.
  22. Arguments:
  23. IpAddr -- IP to get mask for
  24. Return Value:
  25. Network mask in network byte order.
  26. --*/
  27. {
  28. // note addresses and masks are in netbyte order
  29. // which we are treating as byte flipped and hence
  30. // test the high bits in the low byte
  31. // class A?
  32. if ( ! (0x80 & IpAddr) )
  33. {
  34. return( 0x000000ff );
  35. }
  36. // class B?
  37. if ( ! (0x40 & IpAddr) )
  38. {
  39. return( 0x0000ffff );
  40. }
  41. // then class C
  42. // yes, there's some multicast BS out there, I don't
  43. // believe it requires any special handling
  44. return( 0x00ffffff );
  45. }
  46. BOOL
  47. Dns_AreIp4InSameDefaultNetwork(
  48. IN IP4_ADDRESS IpAddr1,
  49. IN IP4_ADDRESS IpAddr2
  50. )
  51. /*++
  52. Routine Description:
  53. Check if two IP4 addresses are in same default network.
  54. Note: this is strictly DEFAULT network info. It is NOT
  55. a statement of subnet match, but of default network match
  56. which will in general -- but not necessarily -- suggest
  57. the addresses are in a connected network.
  58. Arguments:
  59. IpAddr1 -- first IP
  60. IpAddr2 -- second IP
  61. Return Value:
  62. TRUE if in same default network.
  63. FALSE otherwise.
  64. --*/
  65. {
  66. IP4_ADDRESS mask;
  67. //
  68. // note that due to the default IP classes, the mask
  69. // need only be gotten for ONE IP, because there is no
  70. // way to screen with the WRONG class mask on an IP
  71. // and produce network address that is valid for the
  72. // class
  73. //
  74. mask = Dns_GetNetworkMask( IpAddr1 );
  75. return( (IpAddr1 & mask) == (IpAddr2 & mask) );
  76. }
  77. //
  78. // DNS status\error mappings
  79. //
  80. // DCR: investigate tossing error mappings
  81. // and have all errors in Win32 system
  82. //
  83. typedef struct _DnsStatusStringMap
  84. {
  85. DNS_STATUS Status;
  86. PCHAR String;
  87. }
  88. DNS_STATUS_STRING_MAP;
  89. #define DNS_MAP_END ((DWORD)(-1))
  90. #define DNS_MAP_ENTRY( _ErrorCode ) _ErrorCode, #_ErrorCode
  91. DNS_STATUS_STRING_MAP DnsStatusStringMappings[] =
  92. {
  93. //
  94. // Response codes
  95. //
  96. DNS_ERROR_RCODE_NO_ERROR ,"ERROR_SUCCESS",
  97. DNS_ERROR_RCODE_FORMAT_ERROR ,"RCODE_FORMAT_ERROR",
  98. DNS_ERROR_RCODE_SERVER_FAILURE ,"RCODE_SERVER_FAILURE",
  99. DNS_ERROR_RCODE_NAME_ERROR ,"RCODE_NAME_ERROR",
  100. DNS_ERROR_RCODE_NOT_IMPLEMENTED ,"RCODE_NOT_IMPLEMENTED",
  101. DNS_ERROR_RCODE_REFUSED ,"RCODE_REFUSED",
  102. DNS_ERROR_RCODE_YXDOMAIN ,"RCODE_YXDOMAIN",
  103. DNS_ERROR_RCODE_YXRRSET ,"RCODE_YXRRSET",
  104. DNS_ERROR_RCODE_NXRRSET ,"RCODE_NXRRSET",
  105. DNS_ERROR_RCODE_NOTAUTH ,"RCODE_NOTAUTH",
  106. DNS_ERROR_RCODE_NOTZONE ,"RCODE_NOTZONE",
  107. DNS_ERROR_RCODE_BADSIG ,"RCODE_BADSIG",
  108. DNS_ERROR_RCODE_BADKEY ,"RCODE_BADKEY",
  109. DNS_ERROR_RCODE_BADTIME ,"RCODE_BADTIME",
  110. //
  111. // Packet format
  112. //
  113. DNS_INFO_NO_RECORDS ,"DNS_INFO_NO_RECORDS",
  114. DNS_ERROR_BAD_PACKET ,"DNS_ERROR_BAD_PACKET",
  115. DNS_ERROR_NO_PACKET ,"DNS_ERROR_NO_PACKET",
  116. DNS_ERROR_RCODE ,"DNS_ERROR_RCODE",
  117. DNS_ERROR_UNSECURE_PACKET ,"DNS_ERROR_UNSECURE_PACKET",
  118. //
  119. // General API errors
  120. //
  121. DNS_ERROR_INVALID_NAME ,"ERROR_INVALID_NAME",
  122. DNS_ERROR_INVALID_DATA ,"ERROR_INVALID_DATA",
  123. DNS_ERROR_INVALID_TYPE ,"ERROR_INVALID_TYPE",
  124. DNS_ERROR_NOT_ALLOWED_UNDER_DELEGATION ,"DNS_ERROR_NOT_ALLOWED_UNDER_DELEGATION",
  125. DNS_ERROR_INVALID_IP_ADDRESS ,"DNS_ERROR_INVALID_IP_ADDRESS",
  126. DNS_ERROR_INVALID_PROPERTY ,"DNS_ERROR_INVALID_PROPERTY",
  127. DNS_ERROR_TRY_AGAIN_LATER ,"DNS_ERROR_TRY_AGAIN_LATER",
  128. DNS_ERROR_NOT_UNIQUE ,"DNS_ERROR_NOT_UNIQUE",
  129. DNS_ERROR_NON_RFC_NAME ,"DNS_ERROR_NON_RFC_NAME",
  130. DNS_STATUS_FQDN ,"DNS_STATUS_FQDN",
  131. DNS_STATUS_DOTTED_NAME ,"DNS_STATUS_DOTTED_NAME",
  132. DNS_STATUS_SINGLE_PART_NAME ,"DNS_STATUS_SINGLE_PART_NAME",
  133. DNS_ERROR_INVALID_NAME_CHAR ,"DNS_ERROR_INVALID_NAME_CHAR",
  134. DNS_ERROR_NUMERIC_NAME ,"DNS_ERROR_NUMERIC_NAME",
  135. DNS_MAP_ENTRY( DNS_ERROR_CANNOT_FIND_ROOT_HINTS ),
  136. DNS_MAP_ENTRY( DNS_ERROR_INCONSISTENT_ROOT_HINTS ),
  137. //
  138. // Server errors
  139. //
  140. DNS_MAP_ENTRY( DNS_ERROR_NOT_ALLOWED_ON_ROOT_SERVER ),
  141. //
  142. // Zone errors
  143. //
  144. DNS_ERROR_ZONE_DOES_NOT_EXIST ,"DNS_ERROR_ZONE_DOES_NOT_EXIST",
  145. DNS_ERROR_NO_ZONE_INFO ,"DNS_ERROR_NO_ZONE_INFO",
  146. DNS_ERROR_INVALID_ZONE_OPERATION ,"DNS_ERROR_INVALID_ZONE_OPERATION",
  147. DNS_ERROR_ZONE_CONFIGURATION_ERROR ,"DNS_ERROR_ZONE_CONFIGURATION_ERROR",
  148. DNS_ERROR_ZONE_HAS_NO_SOA_RECORD ,"DNS_ERROR_ZONE_HAS_NO_SOA_RECORD",
  149. DNS_ERROR_ZONE_HAS_NO_NS_RECORDS ,"DNS_ERROR_ZONE_HAS_NO_NS_RECORDS",
  150. DNS_ERROR_ZONE_LOCKED ,"DNS_ERROR_ZONE_LOCKED",
  151. DNS_ERROR_ZONE_CREATION_FAILED ,"DNS_ERROR_ZONE_CREATION_FAILED",
  152. DNS_ERROR_ZONE_ALREADY_EXISTS ,"DNS_ERROR_ZONE_ALREADY_EXISTS",
  153. DNS_ERROR_AUTOZONE_ALREADY_EXISTS ,"DNS_ERROR_AUTOZONE_ALREADY_EXISTS",
  154. DNS_ERROR_INVALID_ZONE_TYPE ,"DNS_ERROR_INVALID_ZONE_TYPE",
  155. DNS_ERROR_SECONDARY_REQUIRES_MASTER_IP ,"DNS_ERROR_SECONDARY_REQUIRES_MASTER_IP",
  156. DNS_MAP_ENTRY( DNS_ERROR_ZONE_REQUIRES_MASTER_IP ),
  157. DNS_MAP_ENTRY( DNS_ERROR_ZONE_IS_SHUTDOWN ),
  158. DNS_ERROR_ZONE_NOT_SECONDARY ,"DNS_ERROR_ZONE_NOT_SECONDARY",
  159. DNS_ERROR_NEED_SECONDARY_ADDRESSES ,"DNS_ERROR_NEED_SECONDARY_ADDRESSES",
  160. DNS_ERROR_WINS_INIT_FAILED ,"DNS_ERROR_WINS_INIT_FAILED",
  161. DNS_ERROR_NEED_WINS_SERVERS ,"DNS_ERROR_NEED_WINS_SERVERS",
  162. DNS_ERROR_NBSTAT_INIT_FAILED ,"DNS_ERROR_NBSTAT_INIT_FAILED",
  163. DNS_ERROR_SOA_DELETE_INVALID ,"DNS_ERROR_SOA_DELETE_INVALID",
  164. DNS_MAP_ENTRY( DNS_ERROR_FORWARDER_ALREADY_EXISTS ),
  165. //
  166. // Datafile errors
  167. //
  168. DNS_ERROR_PRIMARY_REQUIRES_DATAFILE ,"DNS_ERROR_PRIMARY_REQUIRES_DATAFILE",
  169. DNS_ERROR_INVALID_DATAFILE_NAME ,"DNS_ERROR_INVALID_DATAFILE_NAME",
  170. DNS_ERROR_DATAFILE_OPEN_FAILURE ,"DNS_ERROR_DATAFILE_OPEN_FAILURE",
  171. DNS_ERROR_FILE_WRITEBACK_FAILED ,"DNS_ERROR_FILE_WRITEBACK_FAILED",
  172. DNS_ERROR_DATAFILE_PARSING ,"DNS_ERROR_DATAFILE_PARSING",
  173. //
  174. // Database errors
  175. //
  176. DNS_ERROR_RECORD_DOES_NOT_EXIST ,"DNS_ERROR_RECORD_DOES_NOT_EXIST",
  177. DNS_ERROR_RECORD_FORMAT ,"DNS_ERROR_RECORD_FORMAT",
  178. DNS_ERROR_NODE_CREATION_FAILED ,"DNS_ERROR_NODE_CREATION_FAILED",
  179. DNS_ERROR_UNKNOWN_RECORD_TYPE ,"DNS_ERROR_UNKNOWN_RECORD_TYPE",
  180. DNS_ERROR_RECORD_TIMED_OUT ,"DNS_ERROR_RECORD_TIMED_OUT",
  181. DNS_ERROR_NAME_NOT_IN_ZONE ,"DNS_ERROR_NAME_NOT_IN_ZONE",
  182. DNS_ERROR_CNAME_LOOP ,"DNS_ERROR_CNAME_LOOP",
  183. DNS_ERROR_NODE_IS_CNAME ,"DNS_ERROR_NODE_IS_CNAME",
  184. DNS_ERROR_CNAME_COLLISION ,"DNS_ERROR_CNAME_COLLISION",
  185. DNS_ERROR_RECORD_ONLY_AT_ZONE_ROOT ,"DNS_ERROR_RECORD_ONLY_AT_ZONE_ROOT",
  186. DNS_ERROR_RECORD_ALREADY_EXISTS ,"DNS_ERROR_RECORD_ALREADY_EXISTS",
  187. DNS_ERROR_SECONDARY_DATA ,"DNS_ERROR_SECONDARY_DATA",
  188. DNS_ERROR_NO_CREATE_CACHE_DATA ,"DNS_ERROR_NO_CREATE_CACHE_DATA",
  189. DNS_ERROR_NAME_DOES_NOT_EXIST ,"DNS_ERROR_NAME_DOES_NOT_EXIST",
  190. DNS_WARNING_PTR_CREATE_FAILED ,"DNS_WARNING_PTR_CREATE_FAILED",
  191. DNS_WARNING_DOMAIN_UNDELETED ,"DNS_WARNING_DOMAIN_UNDELETED",
  192. DNS_ERROR_DS_UNAVAILABLE ,"DNS_ERROR_DS_UNAVAILABLE",
  193. DNS_ERROR_DS_ZONE_ALREADY_EXISTS ,"DNS_ERROR_DS_ZONE_ALREADY_EXISTS",
  194. DNS_MAP_ENTRY( ERROR_DS_COULDNT_CONTACT_FSMO ),
  195. //
  196. // Operation errors
  197. //
  198. DNS_INFO_AXFR_COMPLETE ,"DNS_INFO_AXFR_COMPLETE",
  199. DNS_ERROR_AXFR ,"DNS_ERROR_AXFR",
  200. DNS_INFO_ADDED_LOCAL_WINS ,"DNS_INFO_ADDED_LOCAL_WINS",
  201. //
  202. // Secure update
  203. //
  204. DNS_STATUS_CONTINUE_NEEDED ,"DNS_STATUS_CONTINUE_NEEDED",
  205. //
  206. // Client setup errors
  207. //
  208. DNS_ERROR_NO_TCPIP ,"DNS_ERROR_NO_TCPIP",
  209. DNS_ERROR_NO_DNS_SERVERS ,"DNS_ERROR_NO_DNS_SERVERS",
  210. //
  211. // Directory partition errors
  212. //
  213. DNS_MAP_ENTRY( DNS_ERROR_DP_DOES_NOT_EXIST ),
  214. DNS_MAP_ENTRY( DNS_ERROR_DP_ALREADY_EXISTS ),
  215. DNS_MAP_ENTRY( DNS_ERROR_DP_NOT_ENLISTED ),
  216. DNS_MAP_ENTRY( DNS_ERROR_DP_ALREADY_ENLISTED ),
  217. DNS_MAP_ENTRY( DNS_ERROR_DP_NOT_AVAILABLE ),
  218. DNS_MAP_ENTRY( DNS_ERROR_DP_FSMO_ERROR ),
  219. //
  220. // Throw in common Win32 errors
  221. //
  222. ERROR_FILE_NOT_FOUND ,"ERROR_FILE_NOT_FOUND",
  223. ERROR_ACCESS_DENIED ,"ERROR_ACCESS_DENIED",
  224. ERROR_NOT_ENOUGH_MEMORY ,"ERROR_NOT_ENOUGH_MEMORY",
  225. ERROR_BAD_FORMAT ,"ERROR_BAD_FORMAT",
  226. ERROR_INVALID_DATA ,"ERROR_INVALID_DATA",
  227. ERROR_OUTOFMEMORY ,"ERROR_OUTOFMEMORY",
  228. ERROR_SHARING_VIOLATION ,"ERROR_SHARING_VIOLATION",
  229. ERROR_NOT_SUPPORTED ,"ERROR_NOT_SUPPORTED",
  230. ERROR_INVALID_PARAMETER ,"ERROR_INVALID_PARAMETER",
  231. ERROR_INVALID_NAME ,"ERROR_INVALID_NAME",
  232. ERROR_BAD_ARGUMENTS ,"ERROR_BAD_ARGUMENTS",
  233. ERROR_BUSY ,"ERROR_BUSY",
  234. ERROR_ALREADY_EXISTS ,"ERROR_ALREADY_EXISTS",
  235. ERROR_LOCKED ,"ERROR_LOCKED",
  236. ERROR_MORE_DATA ,"ERROR_MORE_DATA",
  237. ERROR_INVALID_FLAGS ,"ERROR_INVALID_FLAGS",
  238. ERROR_FILE_INVALID ,"ERROR_FILE_INVALID",
  239. ERROR_TIMEOUT ,"ERROR_TIMEOUT",
  240. //
  241. // RPC errors
  242. //
  243. RPC_S_SERVER_UNAVAILABLE ,"RPC_S_SERVER_UNAVAILABLE",
  244. RPC_S_INVALID_NET_ADDR ,"RPC_S_INVALID_NET_ADDR",
  245. EPT_S_NOT_REGISTERED ,"EPT_S_NOT_REGISTERED",
  246. EPT_S_NOT_REGISTERED ,"EPT_S_NOT_REGISTERED",
  247. DNS_MAP_ENTRY( RPC_S_CALL_CANCELLED ),
  248. //
  249. // others:
  250. //
  251. ERROR_PATH_NOT_FOUND ,"ERROR_PATH_NOT_FOUND",
  252. ERROR_INVALID_ACCESS ,"ERROR_INVALID_ACCESS",
  253. ERROR_INVALID_DRIVE ,"ERROR_INVALID_DRIVE",
  254. ERROR_WRITE_PROTECT ,"ERROR_WRITE_PROTECT",
  255. ERROR_SHARING_VIOLATION ,"ERROR_SHARING_VIOLATION",
  256. ERROR_HANDLE_DISK_FULL ,"ERROR_HANDLE_DISK_FULL",
  257. ERROR_NOT_SUPPORTED ,"ERROR_NOT_SUPPORTED",
  258. ERROR_REM_NOT_LIST ,"ERROR_REM_NOT_LIST",
  259. ERROR_DUP_NAME ,"ERROR_DUP_NAME",
  260. ERROR_NETNAME_DELETED ,"ERROR_NETNAME_DELETED",
  261. ERROR_FILE_EXISTS ,"ERROR_FILE_EXISTS",
  262. ERROR_NET_WRITE_FAULT ,"ERROR_NET_WRITE_FAULT",
  263. ERROR_INVALID_SECURITY_DESCR ,"ERROR_INVALID_SECURITY_DESCR",
  264. //
  265. // winsock
  266. //
  267. WSAEINTR ,"WSAEINTR ",
  268. WSAEBADF ,"WSAEBADF ",
  269. WSAEACCES ,"WSAEACCES ",
  270. WSAEFAULT ,"WSAEFAULT ",
  271. WSAEINVAL ,"WSAEINVAL ",
  272. WSAEMFILE ,"WSAEMFILE ",
  273. WSAEWOULDBLOCK ,"WSAEWOULDBLOCK ",
  274. WSAEINPROGRESS ,"WSAEINPROGRESS ",
  275. WSAEALREADY ,"WSAEALREADY ",
  276. WSAENOTSOCK ,"WSAENOTSOCK ",
  277. WSAEDESTADDRREQ ,"WSAEDESTADDRREQ ",
  278. WSAEMSGSIZE ,"WSAEMSGSIZE ",
  279. WSAEPROTOTYPE ,"WSAEPROTOTYPE ",
  280. WSAENOPROTOOPT ,"WSAENOPROTOOPT ",
  281. WSAEPROTONOSUPPORT ,"WSAEPROTONOSUPPORT ",
  282. WSAESOCKTNOSUPPORT ,"WSAESOCKTNOSUPPORT ",
  283. WSAEOPNOTSUPP ,"WSAEOPNOTSUPP ",
  284. WSAEPFNOSUPPORT ,"WSAEPFNOSUPPORT ",
  285. WSAEAFNOSUPPORT ,"WSAEAFNOSUPPORT ",
  286. WSAEADDRINUSE ,"WSAEADDRINUSE ",
  287. WSAEADDRNOTAVAIL ,"WSAEADDRNOTAVAIL ",
  288. WSAENETDOWN ,"WSAENETDOWN ",
  289. WSAENETUNREACH ,"WSAENETUNREACH ",
  290. WSAENETRESET ,"WSAENETRESET ",
  291. WSAECONNABORTED ,"WSAECONNABORTED ",
  292. WSAECONNRESET ,"WSAECONNRESET ",
  293. WSAENOBUFS ,"WSAENOBUFS ",
  294. WSAEISCONN ,"WSAEISCONN ",
  295. WSAENOTCONN ,"WSAENOTCONN ",
  296. WSAESHUTDOWN ,"WSAESHUTDOWN ",
  297. WSAETOOMANYREFS ,"WSAETOOMANYREFS ",
  298. WSAETIMEDOUT ,"WSAETIMEDOUT ",
  299. WSAECONNREFUSED ,"WSAECONNREFUSED ",
  300. WSAELOOP ,"WSAELOOP ",
  301. WSAENAMETOOLONG ,"WSAENAMETOOLONG ",
  302. WSAEHOSTDOWN ,"WSAEHOSTDOWN ",
  303. WSAEHOSTUNREACH ,"WSAEHOSTUNREACH ",
  304. WSAENOTEMPTY ,"WSAENOTEMPTY ",
  305. WSAEPROCLIM ,"WSAEPROCLIM ",
  306. WSAEUSERS ,"WSAEUSERS ",
  307. WSAEDQUOT ,"WSAEDQUOT ",
  308. WSAESTALE ,"WSAESTALE ",
  309. WSAEREMOTE ,"WSAEREMOTE ",
  310. WSASYSNOTREADY ,"WSASYSNOTREADY ",
  311. WSAVERNOTSUPPORTED ,"WSAVERNOTSUPPORTED ",
  312. WSANOTINITIALISED ,"WSANOTINITIALISED ",
  313. WSAEDISCON ,"WSAEDISCON ",
  314. WSAENOMORE ,"WSAENOMORE ",
  315. WSAECANCELLED ,"WSAECANCELLED ",
  316. WSAEINVALIDPROCTABLE ,"WSAEINVALIDPROCTABLE ",
  317. WSAEINVALIDPROVIDER ,"WSAEINVALIDPROVIDER ",
  318. WSAEPROVIDERFAILEDINIT ,"WSAEPROVIDERFAILEDINIT ",
  319. WSASYSCALLFAILURE ,"WSASYSCALLFAILURE ",
  320. WSASERVICE_NOT_FOUND ,"WSASERVICE_NOT_FOUND ",
  321. WSATYPE_NOT_FOUND ,"WSATYPE_NOT_FOUND ",
  322. WSA_E_NO_MORE ,"WSA_E_NO_MORE ",
  323. WSA_E_CANCELLED ,"WSA_E_CANCELLED ",
  324. WSAEREFUSED ,"WSAEREFUSED ",
  325. WSAHOST_NOT_FOUND ,"WSAHOST_NOT_FOUND ",
  326. WSATRY_AGAIN ,"WSATRY_AGAIN ",
  327. WSANO_RECOVERY ,"WSANO_RECOVERY ",
  328. WSANO_DATA ,"WSANO_DATA ",
  329. WSA_QOS_RECEIVERS ,"WSA_QOS_RECEIVERS ",
  330. WSA_QOS_SENDERS ,"WSA_QOS_SENDERS ",
  331. WSA_QOS_NO_SENDERS ,"WSA_QOS_NO_SENDERS ",
  332. WSA_QOS_NO_RECEIVERS ,"WSA_QOS_NO_RECEIVERS ",
  333. WSA_QOS_REQUEST_CONFIRMED ,"WSA_QOS_REQUEST_CONFIRMED ",
  334. WSA_QOS_ADMISSION_FAILURE ,"WSA_QOS_ADMISSION_FAILURE ",
  335. WSA_QOS_POLICY_FAILURE ,"WSA_QOS_POLICY_FAILURE ",
  336. WSA_QOS_BAD_STYLE ,"WSA_QOS_BAD_STYLE ",
  337. WSA_QOS_BAD_OBJECT ,"WSA_QOS_BAD_OBJECT ",
  338. WSA_QOS_TRAFFIC_CTRL_ERROR ,"WSA_QOS_TRAFFIC_CTRL_ERROR ",
  339. WSA_QOS_GENERIC_ERROR ,"WSA_QOS_GENERIC_ERROR ",
  340. WSA_QOS_ESERVICETYPE ,"WSA_QOS_ESERVICETYPE ",
  341. WSA_QOS_EFLOWSPEC ,"WSA_QOS_EFLOWSPEC ",
  342. WSA_QOS_EPROVSPECBUF ,"WSA_QOS_EPROVSPECBUF ",
  343. WSA_QOS_EFILTERSTYLE ,"WSA_QOS_EFILTERSTYLE ",
  344. WSA_QOS_EFILTERTYPE ,"WSA_QOS_EFILTERTYPE ",
  345. WSA_QOS_EFILTERCOUNT ,"WSA_QOS_EFILTERCOUNT ",
  346. WSA_QOS_EOBJLENGTH ,"WSA_QOS_EOBJLENGTH ",
  347. WSA_QOS_EFLOWCOUNT ,"WSA_QOS_EFLOWCOUNT ",
  348. WSA_QOS_EUNKOWNPSOBJ ,"WSA_QOS_EUNKOWNPSOBJ ",
  349. WSA_QOS_EPOLICYOBJ ,"WSA_QOS_EPOLICYOBJ ",
  350. WSA_QOS_EFLOWDESC ,"WSA_QOS_EFLOWDESC ",
  351. WSA_QOS_EPSFLOWSPEC ,"WSA_QOS_EPSFLOWSPEC ",
  352. WSA_QOS_EPSFILTERSPEC ,"WSA_QOS_EPSFILTERSPEC ",
  353. WSA_QOS_ESDMODEOBJ ,"WSA_QOS_ESDMODEOBJ ",
  354. WSA_QOS_ESHAPERATEOBJ ,"WSA_QOS_ESHAPERATEOBJ ",
  355. WSA_QOS_RESERVED_PETYPE ,"WSA_QOS_RESERVED_PETYPE ",
  356. //
  357. // RPC errors
  358. //
  359. RPC_S_SERVER_TOO_BUSY ,"RPC_S_SERVER_TOO_BUSY ",
  360. DNS_MAP_END ,"UNKNOWN",
  361. };
  362. PCHAR
  363. _fastcall
  364. Dns_StatusString(
  365. IN DNS_STATUS Status
  366. )
  367. /*++
  368. Routine Description:
  369. Map DNS error code to status string.
  370. Arguments:
  371. Status -- status code to check
  372. Return Value:
  373. DNS error string for error code.
  374. --*/
  375. {
  376. INT i = 0;
  377. DNS_STATUS mappedStatus;
  378. while ( 1 )
  379. {
  380. mappedStatus = DnsStatusStringMappings[i].Status;
  381. if ( mappedStatus == Status || mappedStatus == DNS_MAP_END )
  382. {
  383. return( DnsStatusStringMappings[i].String );
  384. }
  385. i++;
  386. }
  387. DNS_ASSERT( FALSE );
  388. return( NULL ); // make compiler happy
  389. }
  390. DNS_STATUS
  391. _fastcall
  392. Dns_MapRcodeToStatus(
  393. IN BYTE ResponseCode
  394. )
  395. /*++
  396. Routine Description:
  397. Map response code to DNS error code.
  398. Arguments:
  399. ResponseCode - response code to get error for
  400. Return Value:
  401. DNS error code for response code.
  402. --*/
  403. {
  404. if ( !ResponseCode )
  405. {
  406. return( ERROR_SUCCESS );
  407. }
  408. else
  409. {
  410. return( DNS_ERROR_MASK + ((DWORD) ResponseCode) );
  411. }
  412. }
  413. BYTE
  414. _fastcall
  415. Dns_IsStatusRcode(
  416. IN DNS_STATUS Status
  417. )
  418. /*++
  419. Routine Description:
  420. Determine if status is RCODE and if so return it.
  421. Arguments:
  422. Status -- status code to check
  423. Return Value:
  424. Response code corresponding to status, if found.
  425. Zero otherwise.
  426. --*/
  427. {
  428. if ( Status >= DNS_ERROR_RCODE_FORMAT_ERROR &&
  429. Status <= DNS_ERROR_RCODE_LAST )
  430. {
  431. return( (BYTE) (DNS_ERROR_MASK ^ Status) );
  432. }
  433. else
  434. {
  435. return( 0 );
  436. }
  437. }
  438. DNS_STATUS
  439. Dns_CreateTypeArrayFromMultiTypeString(
  440. IN LPSTR pchMultiTypeString,
  441. OUT INT * piTypeCount,
  442. OUT PWORD * ppwTypeArray
  443. )
  444. /*++
  445. Routine Description:
  446. Allocates an array of types from a string containing DNS types
  447. in numeric and/or string format separated by whitespace.
  448. Arguments:
  449. pBuffer -- string buffer with list of numeric or alpha types
  450. piTypeCount -- number of types parsed written here
  451. ppwTypeArray -- ptr to allocated array of types written here
  452. this ptr must be freed even if the number of types returned
  453. is zero
  454. Return Value:
  455. ERROR_SUCCESS
  456. --*/
  457. {
  458. PCHAR psz;
  459. DWORD argc;
  460. PCHAR argv[ 50 ];
  461. DWORD idx;
  462. ASSERT( pchMultiTypeString );
  463. ASSERT( piTypeCount );
  464. ASSERT( ppwTypeArray );
  465. *piTypeCount = 0;
  466. //
  467. // Allocate array: be cheap and assume max # of types in string
  468. // is twice the length of the string, e.g. "1 2 3 4 5".
  469. //
  470. *ppwTypeArray = ALLOCATE_HEAP(
  471. ( strlen( pchMultiTypeString ) / 2 + 2 ) * sizeof( WORD ) );
  472. if ( !*ppwTypeArray )
  473. {
  474. return DNS_ERROR_NO_MEMORY;
  475. }
  476. //
  477. // Parse the string.
  478. //
  479. argc = Dns_TokenizeStringA(
  480. pchMultiTypeString,
  481. argv,
  482. sizeof( argv ) / sizeof( PCHAR ) );
  483. for ( idx = 0; idx < argc; ++idx )
  484. {
  485. if ( isdigit( argv[ idx ][ 0 ] ) )
  486. {
  487. ( *ppwTypeArray )[ *piTypeCount ] =
  488. ( WORD ) strtol( argv[ idx ], NULL, 0 );
  489. }
  490. else
  491. {
  492. ( *ppwTypeArray )[ *piTypeCount ] = Dns_RecordTypeForName(
  493. argv[ idx ],
  494. 0 ); // string length
  495. }
  496. if ( ( *ppwTypeArray )[ *piTypeCount ] != 0 )
  497. {
  498. ++*piTypeCount;
  499. }
  500. }
  501. return ERROR_SUCCESS;
  502. } // Dns_CreateTypeArrayFromMultiTypeString
  503. LPSTR
  504. Dns_CreateMultiTypeStringFromTypeArray(
  505. IN INT iTypeCount,
  506. IN PWORD ppwTypeArray,
  507. IN CHAR chSeparator OPTIONAL
  508. )
  509. /*++
  510. Routine Description:
  511. Allocate a string and write the types in the array in string format
  512. separated by the specified separator or by a space char.
  513. Arguments:
  514. iTypeCount -- number of types in the array
  515. ppwTypeArray -- ptr to array of types
  516. chSeparator -- string separator or zero for the default separator
  517. Return Value:
  518. ERROR_SUCCESS
  519. --*/
  520. {
  521. LPSTR pszTypes;
  522. INT idx;
  523. LPSTR psz;
  524. ASSERT( ppwTypeArray );
  525. //
  526. // Allocate array: be cheap and assume 10 chars per element.
  527. //
  528. psz = pszTypes = ALLOCATE_HEAP( iTypeCount * 10 * sizeof( CHAR ) );
  529. if ( !psz )
  530. {
  531. return NULL;
  532. }
  533. //
  534. // Output type strings.
  535. //
  536. for ( idx = 0; idx < iTypeCount; ++idx )
  537. {
  538. PCHAR pszThisType;
  539. pszThisType = Dns_RecordStringForType( ppwTypeArray[ idx ] );
  540. if ( !pszThisType )
  541. {
  542. continue;
  543. }
  544. strcpy( psz, pszThisType );
  545. psz += strlen( pszThisType );
  546. *psz++ = chSeparator ? chSeparator : ' ';
  547. }
  548. *psz = '\0'; // NULL terminate the string
  549. return pszTypes;
  550. } // Dns_CreateMultiTypeStringFromTypeArray
  551. //
  552. // End dnsutil.c
  553. //