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.

624 lines
16 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. net\rras\ip\iprtrint\iprtrint.c
  5. Abstract:
  6. Contains the private APIs exported by static library iprtrint.lib
  7. Revision History:
  8. Anshul Dhir Created
  9. For help contact routerdev
  10. --*/
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windef.h>
  15. #include <winbase.h>
  16. #include <mprapi.h>
  17. #include <routprot.h>
  18. #include <ipnathlp.h>
  19. #include "iprtrint.h"
  20. #pragma hdrstop
  21. DWORD WINAPI
  22. InternalRouterUpdateProtocolInfo(
  23. DWORD dwProtocolId,
  24. DWORD dwOperationId,
  25. PVOID MoreInfo1,
  26. PVOID MoreInfo2)
  27. /*++
  28. Routine Description:
  29. This routine is used to update protocol information maintained by the
  30. router.
  31. e.g. it can be used to enable/disable DNS_PROXY.
  32. Also, can be extended to control other protocols like DHCP_ALLOCATOR.
  33. NOTE: Any functionality added to this routine should also be added to
  34. InternalConfigUpdateProtocolInfo
  35. Arguments:
  36. dwProtocolId:
  37. Protocol whose status is to be updated.
  38. Currently supported protocols:
  39. MS_IP_DNS_PROXY
  40. dwOperationId:
  41. Possible values:
  42. UPI_OP_ENABLE
  43. enables the specified protocol
  44. UPI_OP_DISABLE
  45. disables the specified protocol
  46. UPI_OP_RESTORE_CONFIG
  47. information (corresponding to the
  48. specified protocol) stored in the config, is set to
  49. the router
  50. MoreInfo1:
  51. Any extra information required to perform the specified operation
  52. MoreInfo2:
  53. Any extra information required to perform the specified operation
  54. Return Value:
  55. DWORD - status code
  56. --*/
  57. {
  58. #if defined(NT4) || defined(CHICAGO)
  59. return ERROR_NOT_SUPPORTED;
  60. #else
  61. BOOL bModified = FALSE;
  62. DWORD dwErr = NO_ERROR;
  63. HANDLE hMprAdmin = NULL;
  64. HANDLE hMprConfig = NULL;
  65. HANDLE hTransport = NULL;
  66. LPBYTE pAdminCurIPInfo = NULL;
  67. LPBYTE pAdminModIPInfo = NULL;
  68. LPBYTE pAdminProtoInfo = NULL;
  69. LPBYTE pConfigCurIPInfo = NULL;
  70. LPBYTE pConfigProtoInfo = NULL;
  71. LPBYTE pNewProtoInfo = NULL;
  72. PIP_DNS_PROXY_GLOBAL_INFO pDnsInfo = NULL;
  73. DWORD dwAdminCurIPInfoSize;
  74. DWORD dwAdminProtoInfoSize, dwAdminProtoInfoCount;
  75. DWORD dwConfigCurIPInfoSize;
  76. DWORD dwConfigProtoInfoSize, dwConfigProtoInfoCount;
  77. DWORD dwNewProtoInfoSize, dwNewProtoInfoCount;
  78. if ( dwProtocolId != MS_IP_DNS_PROXY ) {
  79. return ERROR_INVALID_PARAMETER;
  80. }
  81. do {
  82. dwErr = MprAdminServerConnect(
  83. NULL,
  84. &hMprAdmin);
  85. if (dwErr != NO_ERROR) {
  86. break;
  87. }
  88. // Get the global information for IP
  89. dwErr = MprAdminTransportGetInfo(
  90. hMprAdmin,
  91. PID_IP,
  92. (LPBYTE *) &pAdminCurIPInfo,
  93. &dwAdminCurIPInfoSize,
  94. NULL,
  95. NULL);
  96. if (dwErr != NO_ERROR) {
  97. break;
  98. }
  99. // Find the Protocol specific information
  100. dwErr = MprInfoBlockFind(
  101. pAdminCurIPInfo,
  102. dwProtocolId,
  103. &dwAdminProtoInfoSize,
  104. &dwAdminProtoInfoCount,
  105. &pAdminProtoInfo);
  106. if (dwErr != NO_ERROR) {
  107. break;
  108. }
  109. // If we have to restore the config information
  110. if ( dwOperationId == UPI_OP_RESTORE_CONFIG ) {
  111. dwErr = MprConfigServerConnect(
  112. NULL,
  113. &hMprConfig);
  114. if (dwErr != NO_ERROR) {
  115. break;
  116. }
  117. dwErr = MprConfigTransportGetHandle(
  118. hMprConfig,
  119. PID_IP,
  120. &hTransport);
  121. if (dwErr != NO_ERROR) {
  122. break;
  123. }
  124. dwErr = MprConfigTransportGetInfo(
  125. hMprConfig,
  126. hTransport,
  127. (LPBYTE *) &pConfigCurIPInfo,
  128. &dwConfigCurIPInfoSize,
  129. NULL,
  130. NULL,
  131. NULL);
  132. if (dwErr != NO_ERROR) {
  133. break;
  134. }
  135. dwErr = MprInfoBlockFind(
  136. pConfigCurIPInfo,
  137. dwProtocolId,
  138. &dwConfigProtoInfoSize,
  139. &dwConfigProtoInfoCount,
  140. &pConfigProtoInfo);
  141. if (dwErr != NO_ERROR) {
  142. break;
  143. }
  144. pNewProtoInfo = pConfigProtoInfo;
  145. dwNewProtoInfoSize = dwConfigProtoInfoSize;
  146. dwNewProtoInfoCount = dwConfigProtoInfoCount;
  147. // If we are restoring the router's protocol state to the
  148. // state stored in the registry (config), we always set the
  149. // bModfied flag
  150. bModified = TRUE;
  151. }
  152. else {
  153. // Perform the desired update
  154. if ( dwProtocolId == MS_IP_DNS_PROXY ) {
  155. pDnsInfo = (PIP_DNS_PROXY_GLOBAL_INFO)pAdminProtoInfo;
  156. //
  157. // jwesth: added some NULL checking on pDnsInfo to pacify PREFIX.
  158. //
  159. if ( dwOperationId == UPI_OP_ENABLE ) {
  160. if ( pDnsInfo && !(pDnsInfo->Flags & IP_DNS_PROXY_FLAG_ENABLE_DNS) ) {
  161. pDnsInfo->Flags |= IP_DNS_PROXY_FLAG_ENABLE_DNS;
  162. bModified = TRUE;
  163. }
  164. }
  165. else if ( dwOperationId == UPI_OP_DISABLE ) {
  166. if ( pDnsInfo && ( pDnsInfo->Flags & IP_DNS_PROXY_FLAG_ENABLE_DNS ) ) {
  167. pDnsInfo->Flags &= ~IP_DNS_PROXY_FLAG_ENABLE_DNS;
  168. bModified = TRUE;
  169. }
  170. }
  171. else {
  172. // The operation is invalid for the spcified protocol
  173. dwErr = ERROR_INVALID_PARAMETER;
  174. break;
  175. }
  176. pNewProtoInfo = pAdminProtoInfo;
  177. dwNewProtoInfoSize = dwAdminProtoInfoSize;
  178. dwNewProtoInfoCount = dwAdminProtoInfoCount;
  179. }
  180. else {
  181. // Invalid Protocol id
  182. dwErr = ERROR_INVALID_PARAMETER;
  183. break;
  184. }
  185. }
  186. // If any change was made, communicate that to the router
  187. if ( bModified ) {
  188. dwErr = MprInfoBlockSet(
  189. pAdminCurIPInfo,
  190. dwProtocolId,
  191. dwNewProtoInfoSize,
  192. dwNewProtoInfoCount,
  193. pNewProtoInfo,
  194. &pAdminModIPInfo);
  195. if ( dwErr != NO_ERROR ) {
  196. break;
  197. }
  198. // Set the modified IP info block back to the router
  199. dwErr = MprAdminTransportSetInfo(
  200. hMprAdmin,
  201. PID_IP,
  202. pAdminModIPInfo,
  203. dwAdminCurIPInfoSize,
  204. NULL,
  205. 0);
  206. if ( dwErr != NO_ERROR ) {
  207. break;
  208. }
  209. }
  210. } while (FALSE);
  211. if ( pAdminCurIPInfo )
  212. MprAdminBufferFree(pAdminCurIPInfo);
  213. if ( pAdminModIPInfo )
  214. MprAdminBufferFree(pAdminModIPInfo);
  215. if ( pConfigCurIPInfo )
  216. MprConfigBufferFree(pConfigCurIPInfo);
  217. if ( hMprAdmin )
  218. MprAdminServerDisconnect(hMprAdmin);
  219. if ( hMprConfig )
  220. MprConfigServerDisconnect(hMprConfig);
  221. return dwErr;
  222. #endif
  223. }
  224. DWORD WINAPI
  225. InternalConfigUpdateProtocolInfo(
  226. DWORD dwProtocolId,
  227. DWORD dwOperationId,
  228. PVOID MoreInfo1,
  229. PVOID MoreInfo2)
  230. /*++
  231. Routine Description:
  232. This routine is used to update protocol information stored in the
  233. config (registry)
  234. e.g. it can be used to enable/disable DNS_PROXY.
  235. Also, can be extended to control other protocols like DHCP_ALLOCATOR.
  236. NOTE: Any functionality added to this routine should also be added to
  237. InternalRouterUpdateProtocolInfo
  238. Arguments:
  239. dwProtocolId:
  240. Protocol whose status is to be updated.
  241. Currently supported protocols:
  242. MS_IP_DNS_PROXY
  243. dwOperationId:
  244. Possible values:
  245. UPI_OP_ENABLE
  246. enables the specified protocol
  247. UPI_OP_DISABLE
  248. disables the specified protocol
  249. MoreInfo1:
  250. Any extra information required to perform the specified operation
  251. MoreInfo2:
  252. Any extra information required to perform the specified operation
  253. Return Value:
  254. DWORD - status code
  255. --*/
  256. {
  257. #if defined(NT4) || defined(CHICAGO)
  258. return ERROR_NOT_SUPPORTED;
  259. #else
  260. BOOL bModified = FALSE;
  261. DWORD dwErr = NO_ERROR;
  262. HANDLE hMprConfig = NULL, hTransport = NULL;
  263. LPBYTE pConfigCurIPInfo = NULL;
  264. LPBYTE pConfigModIPInfo = NULL;
  265. LPBYTE pConfigProtoInfo = NULL;
  266. PIP_DNS_PROXY_GLOBAL_INFO pDnsInfo = NULL;
  267. DWORD dwConfigCurIPInfoSize;
  268. DWORD dwConfigProtoInfoSize, dwConfigProtoInfoCount;
  269. if ( dwProtocolId != MS_IP_DNS_PROXY ) {
  270. return ERROR_INVALID_PARAMETER;
  271. }
  272. do {
  273. dwErr = MprConfigServerConnect(
  274. NULL,
  275. &hMprConfig);
  276. if (dwErr != NO_ERROR) {
  277. break;
  278. }
  279. dwErr = MprConfigTransportGetHandle(
  280. hMprConfig,
  281. PID_IP,
  282. &hTransport);
  283. if (dwErr != NO_ERROR) {
  284. break;
  285. }
  286. dwErr = MprConfigTransportGetInfo(
  287. hMprConfig,
  288. hTransport,
  289. (LPBYTE *) &pConfigCurIPInfo,
  290. &dwConfigCurIPInfoSize,
  291. NULL,
  292. NULL,
  293. NULL);
  294. if (dwErr != NO_ERROR) {
  295. break;
  296. }
  297. dwErr = MprInfoBlockFind(
  298. pConfigCurIPInfo,
  299. dwProtocolId,
  300. &dwConfigProtoInfoSize,
  301. &dwConfigProtoInfoCount,
  302. &pConfigProtoInfo);
  303. if (dwErr != NO_ERROR) {
  304. break;
  305. }
  306. // Perform the desired update
  307. if ( dwProtocolId == MS_IP_DNS_PROXY ) {
  308. pDnsInfo = (PIP_DNS_PROXY_GLOBAL_INFO)pConfigProtoInfo;
  309. if ( dwOperationId == UPI_OP_ENABLE ) {
  310. if ( !(pDnsInfo->Flags & IP_DNS_PROXY_FLAG_ENABLE_DNS) ) {
  311. pDnsInfo->Flags |= IP_DNS_PROXY_FLAG_ENABLE_DNS;
  312. bModified = TRUE;
  313. }
  314. }
  315. else if ( dwOperationId == UPI_OP_DISABLE ) {
  316. if ( pDnsInfo->Flags & IP_DNS_PROXY_FLAG_ENABLE_DNS ) {
  317. pDnsInfo->Flags &= ~IP_DNS_PROXY_FLAG_ENABLE_DNS;
  318. bModified = TRUE;
  319. }
  320. }
  321. else {
  322. // The operation is invalid for the spcified protocol
  323. dwErr = ERROR_INVALID_PARAMETER;
  324. break;
  325. }
  326. }
  327. else {
  328. // Invalid Protocol id
  329. dwErr = ERROR_INVALID_PARAMETER;
  330. break;
  331. }
  332. // If any change was made, save it to the config
  333. if ( bModified ) {
  334. dwErr = MprInfoBlockSet(
  335. pConfigCurIPInfo,
  336. dwProtocolId,
  337. dwConfigProtoInfoSize,
  338. dwConfigProtoInfoCount,
  339. pConfigProtoInfo,
  340. &pConfigModIPInfo);
  341. if ( dwErr != NO_ERROR ) {
  342. break;
  343. }
  344. // Set the modified IP info block back to the config
  345. dwErr = MprConfigTransportSetInfo(
  346. hMprConfig,
  347. hTransport,
  348. pConfigModIPInfo,
  349. dwConfigCurIPInfoSize,
  350. NULL,
  351. 0,
  352. NULL);
  353. if ( dwErr != NO_ERROR ) {
  354. break;
  355. }
  356. }
  357. } while (FALSE);
  358. if ( pConfigCurIPInfo )
  359. MprConfigBufferFree(pConfigCurIPInfo);
  360. if ( pConfigModIPInfo )
  361. MprConfigBufferFree(pConfigModIPInfo);
  362. if ( hMprConfig )
  363. MprConfigServerDisconnect(hMprConfig);
  364. return dwErr;
  365. #endif
  366. }
  367. DWORD WINAPI
  368. InternalUpdateProtocolStatus(
  369. DWORD dwProtocolId,
  370. DWORD dwOperationId,
  371. DWORD dwFlags)
  372. /*++
  373. Routine Description:
  374. This routine is used to enable/disable a protocol
  375. Arguments:
  376. dwProtocolId:
  377. Protocol whose status is to be updated.
  378. Currently supported protocols:
  379. MS_IP_DNS_PROXY
  380. dwOperationId:
  381. Possible values:
  382. UPI_OP_ENABLE
  383. enables the specified protocol
  384. UPI_OP_DISABLE
  385. disables the specified protocol
  386. UPI_OP_RESTORE_CONFIG
  387. information (corresponding to the
  388. specified protocol) stored in the config, is set to
  389. the router
  390. dwFlags:
  391. Possible values
  392. UPI_FLAG_WRITE_TO_CONFIG
  393. When specified, the changes are made to both router and
  394. the config
  395. Return Value:
  396. DWORD - status code
  397. --*/
  398. {
  399. #if defined(NT4) || defined(CHICAGO)
  400. return ERROR_NOT_SUPPORTED;
  401. #else
  402. DWORD dwRouterErr = NO_ERROR;
  403. DWORD dwConfigErr = NO_ERROR;
  404. dwRouterErr = InternalRouterUpdateProtocolInfo(
  405. dwProtocolId,
  406. dwOperationId,
  407. NULL,
  408. NULL);
  409. if ( dwFlags & UPI_FLAG_WRITE_TO_CONFIG ) {
  410. dwConfigErr = InternalConfigUpdateProtocolInfo(
  411. dwProtocolId,
  412. dwOperationId,
  413. NULL,
  414. NULL);
  415. }
  416. return (dwRouterErr ? dwRouterErr : dwConfigErr);
  417. #endif
  418. }
  419. DWORD WINAPI
  420. InternalUpdateDNSProxyStatus(
  421. DWORD dwOperationId,
  422. DWORD dwFlags)
  423. /*++
  424. Routine Description:
  425. This routine is used to enable/disable/restore DNS proxy
  426. Arguments:
  427. dwOperationId:
  428. Possible values:
  429. UPI_OP_ENABLE
  430. enables the specified protocol
  431. UPI_OP_DISABLE
  432. disables the specified protocol
  433. UPI_OP_RESTORE_CONFIG
  434. information (corresponding to the
  435. specified protocol) stored in the config, is set to
  436. the router
  437. dwFlags:
  438. Possible values
  439. UPI_FLAG_WRITE_TO_CONFIG
  440. When specified, the changes are made to both router and
  441. the config
  442. Return Value:
  443. DWORD - status code
  444. --*/
  445. {
  446. #if defined(NT4) || defined(CHICAGO)
  447. return ERROR_NOT_SUPPORTED;
  448. #else
  449. DWORD dwErr = NO_ERROR;
  450. dwErr = InternalUpdateProtocolStatus(
  451. MS_IP_DNS_PROXY,
  452. dwOperationId,
  453. dwFlags);
  454. return dwErr;
  455. #endif
  456. }