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.

484 lines
7.4 KiB

  1. /*++
  2. Copyright (c) 2001-2002 Microsoft Corporation
  3. Module Name:
  4. util.c
  5. Abstract:
  6. Domain Name System (DNS) API
  7. General utils.
  8. Includes:
  9. Extra info processing.
  10. Author:
  11. Jim Gilroy (jamesg) October, 1996
  12. Revision History:
  13. --*/
  14. #include "local.h"
  15. //
  16. // Extra info routines.
  17. //
  18. PDNS_EXTRA_INFO
  19. ExtraInfo_FindInList(
  20. IN OUT PDNS_EXTRA_INFO pExtraList,
  21. IN DWORD Id
  22. )
  23. /*++
  24. Routine Description:
  25. Get extra info blob from extra list.
  26. Arguments:
  27. pExtra -- ptr to extra info
  28. Id -- ID to find
  29. Return Value:
  30. Ptr to extra info of ID type -- if found.
  31. NULL if not found.
  32. --*/
  33. {
  34. PDNS_EXTRA_INFO pextra = pExtraList;
  35. //
  36. // find and set extra info result blob (if any)
  37. //
  38. while ( pextra )
  39. {
  40. if ( pextra->Id == Id )
  41. {
  42. break;
  43. }
  44. pextra = pextra->pNext;
  45. }
  46. return pextra;
  47. }
  48. BOOL
  49. ExtraInfo_SetBasicResults(
  50. IN OUT PDNS_EXTRA_INFO pExtraList,
  51. IN PBASIC_RESULTS pResults
  52. )
  53. /*++
  54. Routine Description:
  55. Get extra info blob from extra list.
  56. Arguments:
  57. pExtraList -- ptr to extra info
  58. pResults to write.
  59. Return Value:
  60. TRUE if found, wrote results extra info.
  61. FALSE otherwise.
  62. --*/
  63. {
  64. PDNS_EXTRA_INFO pextra;
  65. //
  66. // find results extra
  67. //
  68. pextra = ExtraInfo_FindInList(
  69. pExtraList,
  70. DNS_EXINFO_ID_RESULTS_BASIC );
  71. if ( pextra )
  72. {
  73. RtlCopyMemory(
  74. & pextra->ResultsBasic,
  75. pResults,
  76. sizeof( pextra->ResultsBasic ) );
  77. }
  78. return( pextra != NULL );
  79. }
  80. PDNS_ADDR_ARRAY
  81. ExtraInfo_GetServerList(
  82. IN PDNS_EXTRA_INFO pExtraList
  83. )
  84. /*++
  85. Routine Description:
  86. Get server list from extra info.
  87. Arguments:
  88. pExtraList -- ptr to extra info
  89. pResults to write.
  90. Return Value:
  91. Allocated DNS_ADDR_ARRAY server list if found.
  92. NULL if not found or error.
  93. --*/
  94. {
  95. PDNS_EXTRA_INFO pextra;
  96. PDNS_ADDR_ARRAY parray = NULL;
  97. //
  98. // find server list
  99. //
  100. pextra = ExtraInfo_FindInList(
  101. pExtraList,
  102. DNS_EXINFO_ID_SERVER_LIST );
  103. if ( pextra && pextra->pServerList )
  104. {
  105. parray = DnsAddrArray_CreateCopy( pextra->pServerList );
  106. if ( parray )
  107. {
  108. goto Done;
  109. }
  110. }
  111. //
  112. // check IP4
  113. //
  114. pextra = ExtraInfo_FindInList(
  115. pExtraList,
  116. DNS_EXINFO_ID_SERVER_LIST_IP4 );
  117. if ( pextra && pextra->pServerList4 )
  118. {
  119. parray = DnsAddrArray_CreateFromIp4Array( pextra->pServerList4 );
  120. if ( parray )
  121. {
  122. goto Done;
  123. }
  124. }
  125. #if 0
  126. //
  127. // check IP6
  128. //
  129. pextra = ExtraInfo_FindInList(
  130. pExtraList,
  131. DNS_EXINFO_ID_SERVER_LIST_IP6 );
  132. if ( pextra && pextra->pServerList6 )
  133. {
  134. parray = DnsAddrArray_CreateFromIp6Array( pextra->pServerList6 );
  135. if ( parray )
  136. {
  137. goto Done;
  138. }
  139. }
  140. #endif
  141. Done:
  142. return( parray );
  143. }
  144. PDNS_ADDR_ARRAY
  145. ExtraInfo_GetServerListPossiblyImbedded(
  146. IN PIP4_ARRAY pList
  147. )
  148. /*++
  149. Routine Description:
  150. Get server list from extra info.
  151. Arguments:
  152. pExtraList -- ptr to extra info
  153. pResults to write.
  154. Return Value:
  155. Allocated DNS_ADDR_ARRAY server list if found.
  156. NULL if not found or error.
  157. --*/
  158. {
  159. if ( !pList )
  160. {
  161. return NULL;
  162. }
  163. //
  164. // check for imbedded
  165. //
  166. if ( pList->AddrCount == DNS_IMBEDDED_EXTRA_INFO_TAG )
  167. {
  168. return ExtraInfo_GetServerList(
  169. ((PDNS_IMBEDDED_EXTRA_INFO)pList)->pExtraInfo );
  170. }
  171. //
  172. // check IP4 directly
  173. //
  174. return DnsAddrArray_CreateFromIp4Array( pList );
  175. }
  176. //
  177. // Random utils
  178. //
  179. VOID
  180. Util_SetBasicResults(
  181. OUT PBASIC_RESULTS pResults,
  182. IN DWORD Status,
  183. IN DWORD Rcode,
  184. IN PDNS_ADDR pServerAddr
  185. )
  186. /*++
  187. Routine Description:
  188. Save basic result info.
  189. Arguments:
  190. pResults -- results
  191. Status -- update status
  192. Rcode -- returned RCODE
  193. pServerAddr -- ptr to DNS_ADDR of server
  194. Return Value:
  195. None
  196. --*/
  197. {
  198. pResults->Rcode = Rcode;
  199. pResults->Status = Status;
  200. if ( pServerAddr )
  201. {
  202. DnsAddr_Copy(
  203. (PDNS_ADDR) &pResults->ServerAddr,
  204. pServerAddr );
  205. }
  206. else
  207. {
  208. DnsAddr_Clear( (PDNS_ADDR)&pResults->ServerAddr );
  209. }
  210. }
  211. PDNS_ADDR_ARRAY
  212. Util_GetAddrArray(
  213. OUT PDWORD fCopy,
  214. IN PDNS_ADDR_ARRAY pServList,
  215. IN PIP4_ARRAY pServList4,
  216. IN PDNS_EXTRA_INFO pExtraInfo
  217. )
  218. /*++
  219. Routine Description:
  220. Build combined server list.
  221. Arguments:
  222. fCopy -- currently ignored (idea is to grab without copy)
  223. pServList -- input server list
  224. pServList4 -- IP4 server list
  225. pExtraInfo -- ptr to extra info
  226. Return Value:
  227. Allocated DNS_ADDR_ARRAY server list if found.
  228. NULL if not found or error.
  229. --*/
  230. {
  231. PDNS_ADDR_ARRAY parray = NULL;
  232. //
  233. // explicit list
  234. //
  235. if ( pServList )
  236. {
  237. parray = DnsAddrArray_CreateCopy( pServList );
  238. if ( parray )
  239. {
  240. goto Done;
  241. }
  242. }
  243. //
  244. // IP4 list
  245. //
  246. if ( pServList4 )
  247. {
  248. parray = ExtraInfo_GetServerListPossiblyImbedded( pServList4 );
  249. if ( parray )
  250. {
  251. goto Done;
  252. }
  253. }
  254. //
  255. // check extra info
  256. //
  257. if ( pExtraInfo )
  258. {
  259. parray = ExtraInfo_GetServerList( pExtraInfo );
  260. if ( parray )
  261. {
  262. goto Done;
  263. }
  264. }
  265. Done:
  266. return parray;
  267. }
  268. //
  269. // IP6 active test
  270. //
  271. VOID
  272. Util_GetActiveProtocols(
  273. OUT PBOOL pfRunning6,
  274. OUT PBOOL pfRunning4
  275. )
  276. /*++
  277. Routine Description:
  278. Determine protocols running.
  279. Arguments:
  280. pfRunning6 -- addr to hold running IP6 flag
  281. pfRunning4 -- addr to hold running IP4 flag
  282. Return Value:
  283. None
  284. --*/
  285. {
  286. SOCKET sock;
  287. //
  288. // open IP6 socket
  289. //
  290. sock = Socket_Create(
  291. AF_INET6,
  292. SOCK_DGRAM,
  293. NULL,
  294. 0,
  295. 0 );
  296. *pfRunning6 = ( sock != 0 );
  297. Socket_Close( sock );
  298. sock = Socket_Create(
  299. AF_INET,
  300. SOCK_DGRAM,
  301. NULL,
  302. 0,
  303. 0 );
  304. *pfRunning4 = ( sock != 0 );
  305. Socket_Close( sock );
  306. }
  307. BOOL
  308. Util_IsIp6Running(
  309. VOID
  310. )
  311. /*++
  312. Routine Description:
  313. Determine if IP6 running.
  314. Arguments:
  315. Return Value:
  316. None
  317. --*/
  318. {
  319. SOCKET sock;
  320. //
  321. // open IP6 socket
  322. //
  323. sock = Socket_Create(
  324. AF_INET6,
  325. SOCK_DGRAM,
  326. NULL,
  327. 0,
  328. 0 );
  329. Socket_Close( sock );
  330. return ( sock != 0 );
  331. }
  332. //
  333. // End util.c
  334. //