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.

378 lines
6.4 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. resolver.c
  5. Abstract:
  6. Domain Name System (DNS) API
  7. Resolver control.
  8. Author:
  9. Jim Gilroy (jamesg) March 2000
  10. Revision History:
  11. --*/
  12. #include "local.h"
  13. //
  14. // Flush cache routines
  15. //
  16. BOOL
  17. WINAPI
  18. DnsFlushResolverCache(
  19. VOID
  20. )
  21. /*++
  22. Routine Description:
  23. Flush resolver cache.
  24. Arguments:
  25. None
  26. Return Value:
  27. TRUE if successful.
  28. FALSE otherwise.
  29. --*/
  30. {
  31. DNS_STATUS status = ERROR_SUCCESS;
  32. DNSDBG( TRACE, ( "DnsFlushResolverCache()\n" ));
  33. RpcTryExcept
  34. {
  35. R_ResolverFlushCache( NULL );
  36. }
  37. RpcExcept( DNS_RPC_EXCEPTION_FILTER )
  38. {
  39. status = RpcExceptionCode();
  40. }
  41. RpcEndExcept
  42. if ( status )
  43. {
  44. DNSDBG( RPC, (
  45. "DnsFlushResolverCache() RPC failed status = %d\n",
  46. status ));
  47. return FALSE;
  48. }
  49. return TRUE;
  50. }
  51. BOOL
  52. WINAPI
  53. DnsFlushResolverCacheEntry_W(
  54. IN PWSTR pszName
  55. )
  56. /*++
  57. Routine Description:
  58. Flush resolver cache entry.
  59. Arguments:
  60. pszName -- name of entry to flush in unicode
  61. Return Value:
  62. TRUE if entry non-existant or flushed.
  63. FALSE on error.
  64. --*/
  65. {
  66. DWORD status;
  67. DNSDBG( TRACE, (
  68. "DnsFlushResolverCacheEntry_W( %S )\n",
  69. pszName ));
  70. if ( !pszName )
  71. {
  72. return FALSE;
  73. }
  74. RpcTryExcept
  75. {
  76. status = R_ResolverFlushCacheEntry(
  77. NULL, // dummy handle
  78. pszName,
  79. 0 // flush all types
  80. );
  81. }
  82. RpcExcept( DNS_RPC_EXCEPTION_FILTER )
  83. {
  84. status = RpcExceptionCode();
  85. }
  86. RpcEndExcept
  87. if ( status != ERROR_SUCCESS )
  88. {
  89. DNSDBG( RPC, (
  90. "DnsFlushResolverCacheEntry() RPC failed status = %d\n",
  91. status ));
  92. return FALSE;
  93. }
  94. return TRUE;
  95. }
  96. BOOL
  97. WINAPI
  98. FlushResolverCacheEntryNarrow(
  99. IN PSTR pszName,
  100. IN DNS_CHARSET CharSet
  101. )
  102. /*++
  103. Routine Description:
  104. Flush resolver cache entry with narrow string name.
  105. Handles flush for _A and _UTF8
  106. Arguments:
  107. pszName -- name of entry to flush
  108. CharSet -- char set of name
  109. Return Value:
  110. TRUE if entry non-existant or flushed.
  111. FALSE on error.
  112. --*/
  113. {
  114. WCHAR wideNameBuffer[ DNS_MAX_NAME_BUFFER_LENGTH ];
  115. DWORD bufLength = DNS_MAX_NAME_BUFFER_LENGTH * sizeof(WCHAR);
  116. BOOL flag = TRUE;
  117. DNSDBG( TRACE, (
  118. "FlushResolverCacheEntryNarrow( %s )\n",
  119. pszName ));
  120. // must have name
  121. if ( !pszName )
  122. {
  123. // return ERROR_INVALID_NAME;
  124. return FALSE;
  125. }
  126. //
  127. // convert name to unicode
  128. // - bail if name too long or conversion error
  129. if ( ! Dns_NameCopy(
  130. (PBYTE) wideNameBuffer,
  131. & bufLength,
  132. pszName,
  133. 0, // name is string
  134. CharSet,
  135. DnsCharSetUnicode ))
  136. {
  137. // return ERROR_INVALID_NAME;
  138. return FALSE;
  139. }
  140. // flush cache entry
  141. return DnsFlushResolverCacheEntry_W( wideNameBuffer );
  142. }
  143. BOOL
  144. WINAPI
  145. DnsFlushResolverCacheEntry_A(
  146. IN PSTR pszName
  147. )
  148. {
  149. return FlushResolverCacheEntryNarrow(
  150. pszName,
  151. DnsCharSetAnsi );
  152. }
  153. BOOL
  154. WINAPI
  155. DnsFlushResolverCacheEntry_UTF8(
  156. IN PSTR pszName
  157. )
  158. {
  159. return FlushResolverCacheEntryNarrow(
  160. pszName,
  161. DnsCharSetUtf8 );
  162. }
  163. //
  164. // Resolver poke
  165. //
  166. VOID
  167. DnsNotifyResolverEx(
  168. IN DWORD Id,
  169. IN DWORD Flag,
  170. IN DWORD Cookie,
  171. IN PVOID pReserved
  172. )
  173. /*++
  174. Routine Description:
  175. Notify resolver of cluster IP coming on\offline.
  176. Arguments:
  177. ClusterIp -- cluster IP
  178. fAdd -- TRUE if coming online; FALSE if offline.
  179. Return Value:
  180. None
  181. --*/
  182. {
  183. RpcTryExcept
  184. {
  185. R_ResolverPoke(
  186. NULL, // RPC handle
  187. Cookie,
  188. Id );
  189. }
  190. RpcExcept( DNS_RPC_EXCEPTION_FILTER )
  191. {
  192. }
  193. RpcEndExcept
  194. }
  195. //
  196. // Cluster interface
  197. //
  198. DNS_STATUS
  199. DnsRegisterClusterAddress(
  200. IN DWORD Tag,
  201. IN PWSTR pwsName,
  202. IN PSOCKADDR pSockaddr,
  203. IN DWORD Flag
  204. )
  205. /*++
  206. Routine Description:
  207. Register cluster addresses with resolver.
  208. Arguments:
  209. pwsName -- cluster name
  210. pSockaddr -- sockaddr for cluster address
  211. fAdd -- TRUE if coming online; FALSE if offline.
  212. Tag -- cluster add tag
  213. Return Value:
  214. None
  215. --*/
  216. {
  217. DNS_ADDR addr;
  218. DNS_STATUS status;
  219. DNSDBG( TRACE, (
  220. "DnsRegisterClusterAddress()\n"
  221. "\tTag = %08x\n"
  222. "\tpName = %S\n"
  223. "\tpSockaddr = %p (fam=%d)\n"
  224. "\tFlag = %d\n",
  225. Tag,
  226. pwsName,
  227. pSockaddr, pSockaddr->sa_family,
  228. Flag ));
  229. //
  230. // DCR: write cluster key
  231. //
  232. // DCR: check that we are on cluster machime
  233. //
  234. if ( !g_IsServer )
  235. {
  236. return ERROR_ACCESS_DENIED;
  237. }
  238. //
  239. // convert to our private IP union
  240. //
  241. if ( ! DnsAddr_Build(
  242. &addr,
  243. pSockaddr,
  244. 0, // default family
  245. 0, // no subnet info
  246. 0 // no flags
  247. ) )
  248. {
  249. DNSDBG( ANY, (
  250. "ERROR: failed converting sockaddr to DNS_ADDR!\n" ));
  251. return ERROR_INVALID_PARAMETER;
  252. }
  253. //
  254. // notify resolver of cluster IP
  255. //
  256. RpcTryExcept
  257. {
  258. status = R_ResolverRegisterCluster(
  259. NULL, // RPC handle
  260. Tag,
  261. pwsName,
  262. & addr,
  263. Flag );
  264. }
  265. RpcExcept( DNS_RPC_EXCEPTION_FILTER )
  266. {
  267. status = RpcExceptionCode();
  268. }
  269. RpcEndExcept
  270. DNSDBG( TRACE, (
  271. "Leave DnsRegisterClusterAddress( %S ) => %d\n",
  272. pwsName,
  273. status ));
  274. return status;
  275. }
  276. //
  277. // End resolver.c
  278. //