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.

1160 lines
28 KiB

  1. /*
  2. Copyright (c) 1998, Microsoft Corporation, all rights reserved
  3. Description:
  4. HBO: host byte order. Used by DNS, DHCP (except in DhcpNotifyConfigChange).
  5. NBO: network byte order. Used by IPCP, inet_ntoa, inet_addr, the stack
  6. (SetProxyArpEntryToStack, IPRouteEntry, etc).
  7. */
  8. #include "helper_.h"
  9. #include "reghelp.h" // for RegHelpGuidFromString
  10. /*
  11. Returns:
  12. VOID
  13. Description:
  14. */
  15. VOID
  16. TraceHlp(
  17. IN CHAR* Format,
  18. ...
  19. )
  20. {
  21. va_list arglist;
  22. RTASSERT(NULL != Format);
  23. va_start(arglist, Format);
  24. TraceVprintfEx(HelperTraceId,
  25. 0x00010000 | TRACE_USE_MASK |
  26. TRACE_USE_MSEC | TRACE_USE_DATE,
  27. Format,
  28. arglist);
  29. va_end(arglist);
  30. }
  31. /*
  32. Returns:
  33. Notes:
  34. */
  35. DWORD
  36. HelperInitialize(
  37. OUT HINSTANCE* phInstanceDhcpDll
  38. )
  39. {
  40. DWORD dwErr = NO_ERROR;
  41. HelperTraceId = TraceRegister("RASIPHLP");
  42. TraceHlp("HelperInitialize");
  43. while (InterlockedIncrement(&HelperLock) > 1)
  44. {
  45. InterlockedDecrement(&HelperLock);
  46. if (!HelperInitialized)
  47. {
  48. Sleep(1000);
  49. }
  50. else
  51. {
  52. *phInstanceDhcpDll = HelperDhcpDll;
  53. goto LDone;
  54. }
  55. }
  56. ZeroMemory(&HelperRegVal, sizeof(HelperRegVal));
  57. HelperDhcpDll = LoadLibrary("dhcpcsvc.dll");
  58. if (NULL == HelperDhcpDll)
  59. {
  60. dwErr = GetLastError();
  61. TraceHlp("LoadLibrary(dhcpcsvc.dll) failed and returned %d",
  62. dwErr);
  63. goto LDone;
  64. }
  65. HelperIpHlpDll = LoadLibrary("iphlpapi.dll");
  66. if (NULL == HelperIpHlpDll)
  67. {
  68. dwErr = GetLastError();
  69. TraceHlp("LoadLibrary(iphlpapi.dll) failed and returned %d",
  70. dwErr);
  71. goto LDone;
  72. }
  73. HelperIpBootpDll = LoadLibrary("ipbootp.dll");
  74. if (NULL == HelperIpBootpDll)
  75. {
  76. TraceHlp("LoadLibrary(ipbootp.dll) failed and returned %d",
  77. GetLastError());
  78. }
  79. dwErr = helperGetAddressOfProcs();
  80. if (NO_ERROR != dwErr)
  81. {
  82. goto LDone;
  83. }
  84. /*
  85. This is done to send an IRP_MJ_CREATE to the driver. WanArp starts
  86. "working" (initializes itself etc) only when a component opens it. When the
  87. router is running, this is done by the router manager, but in the ras
  88. client case we need to force WanArp to start.
  89. */
  90. HelperWanArpHandle = CreateFile(
  91. WANARP_DOS_NAME_T,
  92. GENERIC_READ | GENERIC_WRITE,
  93. FILE_SHARE_READ | FILE_SHARE_WRITE,
  94. NULL,
  95. OPEN_EXISTING,
  96. FILE_FLAG_OVERLAPPED,
  97. NULL);
  98. if (INVALID_HANDLE_VALUE == HelperWanArpHandle)
  99. {
  100. dwErr = GetLastError();
  101. TraceHlp("CreateFile(%s) failed and returned %d",
  102. WANARP_DOS_NAME_A, dwErr);
  103. goto LDone;
  104. }
  105. // This is done last. If something fails above, we don't have to
  106. // DeleteCriticalSection.
  107. InitializeCriticalSection(&RasDhcpCriticalSection);
  108. InitializeCriticalSection(&RasStatCriticalSection);
  109. InitializeCriticalSection(&RasSrvrCriticalSection);
  110. InitializeCriticalSection(&RasTimrCriticalSection);
  111. HelperChangeNotification();
  112. *phInstanceDhcpDll = HelperDhcpDll;
  113. HelperInitialized = TRUE;
  114. LDone:
  115. if (NO_ERROR != dwErr)
  116. {
  117. if ((DWORD)-1 != HelperTraceId)
  118. {
  119. TraceDeregister(HelperTraceId);
  120. HelperTraceId = (DWORD)-1;
  121. }
  122. if (INVALID_HANDLE_VALUE != HelperWanArpHandle)
  123. {
  124. CloseHandle(HelperWanArpHandle);
  125. HelperWanArpHandle = INVALID_HANDLE_VALUE;
  126. }
  127. if (NULL != HelperDhcpDll)
  128. {
  129. FreeLibrary(HelperDhcpDll);
  130. HelperDhcpDll = NULL;
  131. }
  132. if (NULL != HelperIpHlpDll)
  133. {
  134. FreeLibrary(HelperIpHlpDll);
  135. HelperIpHlpDll = NULL;
  136. }
  137. if (NULL != HelperIpBootpDll)
  138. {
  139. FreeLibrary(HelperIpBootpDll);
  140. HelperIpBootpDll = NULL;
  141. }
  142. PDhcpNotifyConfigChange = NULL;
  143. PDhcpLeaseIpAddress = NULL;
  144. PDhcpRenewIpAddressLease = NULL;
  145. PDhcpReleaseIpAddressLease = NULL;
  146. PAllocateAndGetIpAddrTableFromStack = NULL;
  147. PSetProxyArpEntryToStack = NULL;
  148. PSetIpForwardEntryToStack = NULL;
  149. PSetIpForwardEntry = NULL;
  150. PDeleteIpForwardEntry = NULL;
  151. PNhpAllocateAndGetInterfaceInfoFromStack = NULL;
  152. PAllocateAndGetIpForwardTableFromStack = NULL;
  153. PGetAdaptersInfo = NULL;
  154. PGetPerAdapterInfo = NULL;
  155. PEnableDhcpInformServer = NULL;
  156. PDisableDhcpInformServer = NULL;
  157. ZeroMemory(&HelperRegVal, sizeof(HelperRegVal));
  158. InterlockedDecrement(&HelperLock);
  159. }
  160. return(dwErr);
  161. }
  162. /*
  163. Returns:
  164. VOID
  165. Notes:
  166. */
  167. VOID
  168. HelperUninitialize(
  169. VOID
  170. )
  171. {
  172. TraceHlp("HelperUninitialize");
  173. if ((DWORD)-1 != HelperTraceId)
  174. {
  175. TraceDeregister(HelperTraceId);
  176. HelperTraceId = (DWORD)-1;
  177. }
  178. if (INVALID_HANDLE_VALUE != HelperWanArpHandle)
  179. {
  180. CloseHandle(HelperWanArpHandle);
  181. HelperWanArpHandle = INVALID_HANDLE_VALUE;
  182. }
  183. if (NULL != HelperDhcpDll)
  184. {
  185. FreeLibrary(HelperDhcpDll);
  186. HelperDhcpDll = NULL;
  187. }
  188. if (NULL != HelperIpHlpDll)
  189. {
  190. FreeLibrary(HelperIpHlpDll);
  191. HelperIpHlpDll = NULL;
  192. }
  193. if (NULL != HelperIpBootpDll)
  194. {
  195. FreeLibrary(HelperIpBootpDll);
  196. HelperIpBootpDll = NULL;
  197. }
  198. RasStatFreeAddrPool(HelperRegVal.pAddrPool);
  199. HelperRegVal.pAddrPool = NULL;
  200. PDhcpNotifyConfigChange = NULL;
  201. PDhcpLeaseIpAddress = NULL;
  202. PDhcpRenewIpAddressLease = NULL;
  203. PDhcpReleaseIpAddressLease = NULL;
  204. PAllocateAndGetIpAddrTableFromStack = NULL;
  205. PSetProxyArpEntryToStack = NULL;
  206. PSetIpForwardEntryToStack = NULL;
  207. PSetIpForwardEntry = NULL;
  208. PDeleteIpForwardEntry = NULL;
  209. PNhpAllocateAndGetInterfaceInfoFromStack = NULL;
  210. PAllocateAndGetIpForwardTableFromStack = NULL;
  211. PGetAdaptersInfo = NULL;
  212. PGetPerAdapterInfo = NULL;
  213. PEnableDhcpInformServer = NULL;
  214. PDisableDhcpInformServer = NULL;
  215. ZeroMemory(&HelperRegVal, sizeof(HelperRegVal));
  216. if (HelperInitialized)
  217. {
  218. DeleteCriticalSection(&RasDhcpCriticalSection);
  219. DeleteCriticalSection(&RasStatCriticalSection);
  220. DeleteCriticalSection(&RasSrvrCriticalSection);
  221. DeleteCriticalSection(&RasTimrCriticalSection);
  222. HelperInitialized = FALSE;
  223. InterlockedDecrement(&HelperLock);
  224. }
  225. }
  226. /*
  227. Returns:
  228. VOID
  229. Description:
  230. */
  231. VOID
  232. HelperChangeNotification(
  233. VOID
  234. )
  235. {
  236. BOOL fUseDhcpAddressingOld;
  237. BOOL fUseDhcpAddressing = TRUE;
  238. ADDR_POOL* pAddrPool = NULL;
  239. BOOL fNICChosen;
  240. GUID guidChosenNIC;
  241. HANDLE h;
  242. DWORD dwNumBytes;
  243. HKEY hKey = NULL;
  244. LONG lErr;
  245. DWORD dwErr;
  246. TraceHlp("HelperChangeNotification");
  247. fUseDhcpAddressingOld = HelperRegVal.fUseDhcpAddressing;
  248. fNICChosen = HelperRegVal.fNICChosen;
  249. CopyMemory(&guidChosenNIC, &(HelperRegVal.guidChosenNIC), sizeof(GUID));
  250. lErr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGKEY_RAS_IP_PARAM_A, 0, KEY_READ,
  251. &hKey);
  252. if (ERROR_SUCCESS == lErr)
  253. {
  254. dwNumBytes = sizeof(fUseDhcpAddressing);
  255. lErr = RegQueryValueEx(hKey, REGVAL_USEDHCPADDRESSING_A, NULL, NULL,
  256. (BYTE*)&fUseDhcpAddressing, &dwNumBytes);
  257. if (ERROR_SUCCESS != lErr)
  258. {
  259. fUseDhcpAddressing = TRUE;
  260. }
  261. }
  262. helperReadRegistry();
  263. if (!fUseDhcpAddressing)
  264. {
  265. RasStatCreatePoolList(&pAddrPool);
  266. }
  267. EnterCriticalSection(&RasSrvrCriticalSection);
  268. if (RasSrvrRunning)
  269. {
  270. RasSrvrEnableRouter(HelperRegVal.fEnableRoute);
  271. if ( (fUseDhcpAddressingOld != fUseDhcpAddressing)
  272. || ( !fUseDhcpAddressing
  273. && RasStatAddrPoolsDiffer(HelperRegVal.pAddrPool, pAddrPool))
  274. || ( fUseDhcpAddressing
  275. && ( (fNICChosen != HelperRegVal.fNICChosen)
  276. || ( fNICChosen
  277. && (!IsEqualGUID(&guidChosenNIC,
  278. &(HelperRegVal.guidChosenNIC)))))))
  279. {
  280. RasSrvrStop(TRUE /* fParametersChanged */);
  281. HelperRegVal.fUseDhcpAddressing = fUseDhcpAddressing;
  282. RasStatFreeAddrPool(HelperRegVal.pAddrPool);
  283. HelperRegVal.pAddrPool = pAddrPool;
  284. pAddrPool = NULL;
  285. dwErr = RasSrvrStart();
  286. if (NO_ERROR != dwErr)
  287. {
  288. TraceHlp("RasSrvrStart failed and returned %d");
  289. }
  290. }
  291. if( (!fUseDhcpAddressing)
  292. && (pAddrPool != NULL))
  293. {
  294. RasStatFreeAddrPool(pAddrPool);
  295. pAddrPool = NULL;
  296. }
  297. }
  298. else
  299. {
  300. HelperRegVal.fUseDhcpAddressing = fUseDhcpAddressing;
  301. RasStatFreeAddrPool(HelperRegVal.pAddrPool);
  302. HelperRegVal.pAddrPool = pAddrPool;
  303. }
  304. LeaveCriticalSection(&RasSrvrCriticalSection);
  305. if (NULL != hKey)
  306. {
  307. RegCloseKey(hKey);
  308. }
  309. }
  310. /*
  311. Returns:
  312. Description:
  313. */
  314. DWORD
  315. HelperSetDefaultInterfaceNet(
  316. IN IPADDR nboIpAddrLocal,
  317. IN IPADDR nboIpAddrRemote,
  318. IN BOOL fPrioritize,
  319. IN WCHAR *pszDevice
  320. )
  321. {
  322. DWORD dwErr = NO_ERROR;
  323. GUID DeviceGuid;
  324. TraceHlp("HelperSetDefaultInterfaceNet(IP addr: 0x%x, fPrioritize: %d)",
  325. nboIpAddrLocal, fPrioritize);
  326. if(NULL == pszDevice)
  327. {
  328. dwErr = ERROR_INVALID_PARAMETER;
  329. goto LDone;
  330. }
  331. RegHelpGuidFromString(pszDevice, &DeviceGuid);
  332. // If fPrioritize flag is set, "fix" the metrics so that the packets go on
  333. // the RAS links
  334. if (fPrioritize)
  335. {
  336. dwErr = RasTcpAdjustRouteMetrics(nboIpAddrLocal, TRUE);
  337. if (NO_ERROR != dwErr)
  338. {
  339. goto LDone;
  340. }
  341. }
  342. // Add code to check for the remote network - same as the one of the local
  343. // networks - if so, set the subnet route to be over the RAS adapter -
  344. // making the ras link as the primary adapter
  345. // We add a Default route to make RAS adapter as the default net if
  346. // fPrioritize flag is set.
  347. if (fPrioritize)
  348. {
  349. // RasTcpSetRoutesForNameServers(TRUE);
  350. RasTcpSetRouteEx(
  351. ALL_NETWORKS_ROUTE,
  352. nboIpAddrLocal,
  353. 0,
  354. nboIpAddrLocal,
  355. TRUE,
  356. 1,
  357. TRUE,
  358. &DeviceGuid);
  359. }
  360. else
  361. {
  362. IPADDR nboMask;
  363. nboMask = RasTcpDeriveMask(nboIpAddrLocal);
  364. if (nboMask != 0)
  365. {
  366. RasTcpSetRouteEx(
  367. nboIpAddrLocal & nboMask,
  368. nboIpAddrLocal,
  369. nboMask,
  370. nboIpAddrLocal,
  371. TRUE,
  372. 1,
  373. TRUE,
  374. &DeviceGuid);
  375. }
  376. }
  377. if (0 != nboIpAddrRemote)
  378. {
  379. RasTcpSetRouteEx(
  380. nboIpAddrRemote,
  381. nboIpAddrLocal,
  382. HOST_MASK,
  383. nboIpAddrLocal,
  384. TRUE,
  385. 1,
  386. TRUE,
  387. &DeviceGuid);
  388. }
  389. LDone:
  390. return(dwErr);
  391. }
  392. /*
  393. Returns:
  394. Description:
  395. */
  396. DWORD
  397. HelperResetDefaultInterfaceNet(
  398. IN IPADDR nboIpAddr,
  399. IN BOOL fPrioritize
  400. )
  401. {
  402. DWORD dwErr = NO_ERROR;;
  403. if (fPrioritize)
  404. {
  405. // RasTcpSetRoutesForNameServers(FALSE);
  406. dwErr = RasTcpAdjustRouteMetrics(nboIpAddr, FALSE);
  407. }
  408. return(dwErr);
  409. }
  410. /*
  411. Set interface information for SLIP connections
  412. Returns:
  413. Notes:
  414. */
  415. DWORD
  416. HelperSetDefaultInterfaceNetEx(
  417. IPADDR nboIpAddr,
  418. WCHAR* wszDevice,
  419. BOOL fPrioritize,
  420. WCHAR* wszDnsAddress,
  421. WCHAR* wszDns2Address,
  422. WCHAR* wszWinsAddress,
  423. WCHAR* wszWins2Address,
  424. BOOL fDisableNetBIOS
  425. )
  426. {
  427. DWORD dwErr = NO_ERROR;
  428. IPADDR nboIpMask = HOST_MASK;
  429. TCPIP_INFO* pTcpipInfo = NULL;
  430. TraceHlp("HelperSetDefaultInterfaceNetEx(IP addr: 0x%x, Device: %ws, "
  431. "fPrioritize: %d, DNS1: %ws, DNS2: %ws, WINS1: %ws, WINS2: %ws, ",
  432. "fDisableNetBIOS: %d",
  433. nboIpAddr, wszDevice, fPrioritize, wszDnsAddress, wszDns2Address,
  434. wszWinsAddress, wszWins2Address, fDisableNetBIOS);
  435. dwErr = LoadTcpipInfo(&pTcpipInfo, wszDevice, FALSE /* fAdapterOnly */);
  436. if (NO_ERROR != dwErr)
  437. {
  438. goto LDone;
  439. }
  440. AbcdWszFromIpAddress(nboIpAddr, pTcpipInfo->wszIPAddress);
  441. AbcdWszFromIpAddress(nboIpMask, pTcpipInfo->wszSubnetMask);
  442. // Since we are adding the addresses to the head of the list, we need to add
  443. // the backup DNS and WINS addresses before the primary addresses, so the
  444. // primary ones will be at the head of the list when we're done.
  445. if (wszDns2Address != NULL)
  446. {
  447. dwErr = PrependWszIpAddress(&pTcpipInfo->wszDNSNameServers,
  448. wszDns2Address);
  449. if (NO_ERROR != dwErr)
  450. {
  451. goto LDone;
  452. }
  453. }
  454. if (wszDnsAddress != NULL)
  455. {
  456. dwErr = PrependWszIpAddress(&pTcpipInfo->wszDNSNameServers,
  457. wszDnsAddress);
  458. if (NO_ERROR != dwErr)
  459. {
  460. goto LDone;
  461. }
  462. }
  463. if (wszWins2Address != NULL)
  464. {
  465. dwErr = PrependWszIpAddressToMwsz(&pTcpipInfo->mwszNetBIOSNameServers,
  466. wszWins2Address);
  467. if (NO_ERROR != dwErr)
  468. {
  469. goto LDone;
  470. }
  471. }
  472. if (wszWinsAddress != NULL)
  473. {
  474. dwErr = PrependWszIpAddressToMwsz(&pTcpipInfo->mwszNetBIOSNameServers,
  475. wszWinsAddress);
  476. if (NO_ERROR != dwErr)
  477. {
  478. goto LDone;
  479. }
  480. }
  481. pTcpipInfo->fDisableNetBIOSoverTcpip = fDisableNetBIOS;
  482. pTcpipInfo->fChanged = TRUE;
  483. dwErr = SaveTcpipInfo(pTcpipInfo);
  484. if (NO_ERROR != dwErr)
  485. {
  486. goto LDone;
  487. }
  488. dwErr = PDhcpNotifyConfigChange(NULL, wszDevice, TRUE, 0, nboIpAddr,
  489. nboIpMask, IgnoreFlag);
  490. if (NO_ERROR != dwErr)
  491. {
  492. TraceHlp("DhcpNotifyConfigChange failed and returned %d", dwErr);
  493. goto LDone;
  494. }
  495. // If fPrioritize flag is set "Fix" the metrics so that the packets go on
  496. // the RAS links
  497. if (fPrioritize)
  498. {
  499. dwErr = RasTcpAdjustRouteMetrics(nboIpAddr, TRUE);
  500. if (NO_ERROR != dwErr)
  501. {
  502. goto LDone;
  503. }
  504. }
  505. // Add code to check for the remote network - same as the one of the local
  506. // networks - if so, set the subnet route to be over the RAS adapter -
  507. // making the RAS link as the primary adapter
  508. // We add a Default route to make RAS adapter as the default net if
  509. // fPrioritize flag is set.
  510. if (fPrioritize)
  511. {
  512. // RasTcpSetRoutesForNameServers(TRUE);
  513. RasTcpSetRoute(ALL_NETWORKS_ROUTE,
  514. nboIpAddr,
  515. 0,
  516. nboIpAddr,
  517. TRUE,
  518. 1,
  519. TRUE);
  520. }
  521. else
  522. {
  523. IPADDR nboMask;
  524. nboMask = RasTcpDeriveMask(nboIpAddr);
  525. if (nboMask != 0)
  526. {
  527. RasTcpSetRoute(
  528. nboIpAddr & nboMask,
  529. nboIpAddr,
  530. nboMask,
  531. nboIpAddr,
  532. TRUE,
  533. 1,
  534. TRUE);
  535. }
  536. }
  537. LDone:
  538. if (pTcpipInfo != NULL)
  539. {
  540. FreeTcpipInfo(&pTcpipInfo);
  541. }
  542. return(dwErr);
  543. }
  544. /*
  545. Returns:
  546. Notes:
  547. */
  548. DWORD
  549. HelperResetDefaultInterfaceNetEx(
  550. IPADDR nboIpAddr,
  551. WCHAR* wszDevice,
  552. BOOL fPrioritize,
  553. WCHAR* wszDnsAddress,
  554. WCHAR* wszDns2Address,
  555. WCHAR* wszWinsAddress,
  556. WCHAR* wszWins2Address
  557. )
  558. {
  559. DWORD dwErr = NO_ERROR;
  560. TCPIP_INFO* pTcpipInfo = NULL;
  561. TraceHlp("HelperResetDefaultInterfaceNetEx(0x%x)", nboIpAddr);
  562. if (fPrioritize)
  563. {
  564. // RasTcpSetRoutesForNameServers(FALSE);
  565. RasTcpAdjustRouteMetrics(nboIpAddr, FALSE);
  566. }
  567. dwErr = LoadTcpipInfo(&pTcpipInfo, wszDevice, TRUE /* fAdapterOnly */);
  568. if (NO_ERROR != dwErr)
  569. {
  570. goto LDone;
  571. }
  572. pTcpipInfo->fChanged = TRUE;
  573. dwErr = SaveTcpipInfo(pTcpipInfo);
  574. if (NO_ERROR != dwErr)
  575. {
  576. goto LDone;
  577. }
  578. dwErr = PDhcpNotifyConfigChange(NULL, wszDevice, TRUE, 0, 0, 0, IgnoreFlag);
  579. if (NO_ERROR != dwErr)
  580. {
  581. TraceHlp("DhcpNotifyConfigChange failed and returned %d", dwErr);
  582. dwErr = NO_ERROR;
  583. }
  584. LDone:
  585. if (pTcpipInfo != NULL)
  586. {
  587. FreeTcpipInfo(&pTcpipInfo);
  588. }
  589. return(dwErr);
  590. }
  591. /*
  592. Returns:
  593. Description:
  594. */
  595. DWORD
  596. helperGetAddressOfProcs(
  597. VOID
  598. )
  599. {
  600. DWORD dwErr = NO_ERROR;
  601. PDhcpNotifyConfigChange = (DHCPNOTIFYCONFIGCHANGE)
  602. GetProcAddress(HelperDhcpDll, "DhcpNotifyConfigChange");
  603. if (NULL == PDhcpNotifyConfigChange)
  604. {
  605. dwErr = GetLastError();
  606. TraceHlp("GetProcAddress(DhcpNotifyConfigChange) failed and returned "
  607. "%d", dwErr);
  608. goto LDone;
  609. }
  610. PDhcpLeaseIpAddress = (DHCPLEASEIPADDRESS)
  611. GetProcAddress(HelperDhcpDll, "DhcpLeaseIpAddress");
  612. if (NULL == PDhcpLeaseIpAddress)
  613. {
  614. dwErr = GetLastError();
  615. TraceHlp("GetProcAddress(DhcpLeaseIpAddress) failed and returned "
  616. "%d", dwErr);
  617. goto LDone;
  618. }
  619. PDhcpRenewIpAddressLease = (DHCPRENEWIPADDRESSLEASE)
  620. GetProcAddress(HelperDhcpDll, "DhcpRenewIpAddressLease");
  621. if (NULL == PDhcpRenewIpAddressLease)
  622. {
  623. dwErr = GetLastError();
  624. TraceHlp("GetProcAddress(DhcpRenewIpAddressLease) failed and returned "
  625. "%d", dwErr);
  626. goto LDone;
  627. }
  628. PDhcpReleaseIpAddressLease = (DHCPRELEASEIPADDRESSLEASE)
  629. GetProcAddress(HelperDhcpDll, "DhcpReleaseIpAddressLease");
  630. if (NULL == PDhcpReleaseIpAddressLease)
  631. {
  632. dwErr = GetLastError();
  633. TraceHlp("GetProcAddress(DhcpReleaseIpAddressLease) failed and "
  634. "returned %d", dwErr);
  635. goto LDone;
  636. }
  637. PAllocateAndGetIpAddrTableFromStack = (ALLOCATEANDGETIPADDRTABLEFROMSTACK)
  638. GetProcAddress(HelperIpHlpDll, "AllocateAndGetIpAddrTableFromStack");
  639. if (NULL == PAllocateAndGetIpAddrTableFromStack)
  640. {
  641. dwErr = GetLastError();
  642. TraceHlp("GetProcAddress(AllocateAndGetIpAddrTableFromStack) failed "
  643. "and returned %d", dwErr);
  644. goto LDone;
  645. }
  646. PSetProxyArpEntryToStack = (SETPROXYARPENTRYTOSTACK)
  647. GetProcAddress(HelperIpHlpDll, "SetProxyArpEntryToStack");
  648. if (NULL == PSetProxyArpEntryToStack)
  649. {
  650. dwErr = GetLastError();
  651. TraceHlp("GetProcAddress(SetProxyArpEntryToStack) failed and "
  652. "returned %d", dwErr);
  653. goto LDone;
  654. }
  655. PSetIpForwardEntryToStack = (SETIPFORWARDENTRYTOSTACK)
  656. GetProcAddress(HelperIpHlpDll, "SetIpForwardEntryToStack");
  657. if (NULL == PSetIpForwardEntryToStack)
  658. {
  659. dwErr = GetLastError();
  660. TraceHlp("GetProcAddress(SetIpForwardEntryToStack) failed and "
  661. "returned %d", dwErr);
  662. goto LDone;
  663. }
  664. PSetIpForwardEntry = (SETIPFORWARDENTRY)
  665. GetProcAddress(HelperIpHlpDll, "SetIpForwardEntry");
  666. if (NULL == PSetIpForwardEntry)
  667. {
  668. dwErr = GetLastError();
  669. TraceHlp("GetProcAddress(SetIpForwardEntry) failed and "
  670. "returned %d", dwErr);
  671. goto LDone;
  672. }
  673. PDeleteIpForwardEntry = (DELETEIPFORWARDENTRY)
  674. GetProcAddress(HelperIpHlpDll, "DeleteIpForwardEntry");
  675. if (NULL == PDeleteIpForwardEntry)
  676. {
  677. dwErr = GetLastError();
  678. TraceHlp("GetProcAddress(DeleteIpForwardEntry) failed and "
  679. "returned %d", dwErr);
  680. goto LDone;
  681. }
  682. PNhpAllocateAndGetInterfaceInfoFromStack =
  683. (NHPALLOCATEANDGETINTERFACEINFOFROMSTACK)
  684. GetProcAddress(HelperIpHlpDll,
  685. "NhpAllocateAndGetInterfaceInfoFromStack");
  686. if (NULL == PNhpAllocateAndGetInterfaceInfoFromStack)
  687. {
  688. dwErr = GetLastError();
  689. TraceHlp("GetProcAddress(NhpAllocateAndGetInterfaceInfoFromStack) "
  690. "failed and returned %d", dwErr);
  691. goto LDone;
  692. }
  693. PAllocateAndGetIpForwardTableFromStack =
  694. (ALLOCATEANDGETIPFORWARDTABLEFROMSTACK)
  695. GetProcAddress(HelperIpHlpDll,
  696. "AllocateAndGetIpForwardTableFromStack");
  697. if (NULL == PAllocateAndGetIpForwardTableFromStack)
  698. {
  699. dwErr = GetLastError();
  700. TraceHlp("GetProcAddress(AllocateAndGetIpForwardTableFromStack) "
  701. "failed and returned %d", dwErr);
  702. goto LDone;
  703. }
  704. PGetAdaptersInfo = (GETADAPTERSINFO)
  705. GetProcAddress(HelperIpHlpDll, "GetAdaptersInfo");
  706. if (NULL == PGetAdaptersInfo)
  707. {
  708. dwErr = GetLastError();
  709. TraceHlp("GetProcAddress(GetAdaptersInfo) failed and "
  710. "returned %d", dwErr);
  711. goto LDone;
  712. }
  713. PGetPerAdapterInfo = (GETPERADAPTERINFO)
  714. GetProcAddress(HelperIpHlpDll, "GetPerAdapterInfo");
  715. if (NULL == PGetPerAdapterInfo)
  716. {
  717. dwErr = GetLastError();
  718. TraceHlp("GetProcAddress(GetPerAdapterInfo) failed and "
  719. "returned %d", dwErr);
  720. goto LDone;
  721. }
  722. if (NULL != HelperIpBootpDll)
  723. {
  724. PEnableDhcpInformServer = (ENABLEDHCPINFORMSERVER)
  725. GetProcAddress(HelperIpBootpDll, "EnableDhcpInformServer");
  726. if (NULL == PEnableDhcpInformServer)
  727. {
  728. dwErr = GetLastError();
  729. TraceHlp("GetProcAddress(EnableDhcpInformServer) failed and "
  730. "returned %d", dwErr);
  731. goto LDone;
  732. }
  733. PDisableDhcpInformServer = (DISABLEDHCPINFORMSERVER)
  734. GetProcAddress(HelperIpBootpDll, "DisableDhcpInformServer");
  735. if (NULL == PDisableDhcpInformServer)
  736. {
  737. dwErr = GetLastError();
  738. TraceHlp("GetProcAddress(DisableDhcpInformServer) failed and "
  739. "returned %d", dwErr);
  740. goto LDone;
  741. }
  742. }
  743. LDone:
  744. return(dwErr);
  745. }
  746. /*
  747. Returns:
  748. VOID
  749. Description:
  750. */
  751. VOID
  752. helperReadRegistry(
  753. VOID
  754. )
  755. {
  756. LONG lErr;
  757. DWORD dwErr;
  758. DWORD dw;
  759. DWORD dwNumBytes;
  760. CHAR* szIpAddr = NULL;
  761. CHAR* szAlloced = NULL;
  762. IPADDR nboIpAddr1;
  763. IPADDR nboIpAddr2;
  764. HKEY hKeyIpParam = NULL;
  765. WCHAR* wszAdapterGuid = NULL;
  766. HRESULT hr;
  767. HelperRegVal.fSuppressWINSNameServers = FALSE;
  768. HelperRegVal.fSuppressDNSNameServers = FALSE;
  769. HelperRegVal.dwChunkSize = 10;
  770. HelperRegVal.nboWINSNameServer1 = 0;
  771. HelperRegVal.nboWINSNameServer2 = 0;
  772. HelperRegVal.nboDNSNameServer1 = 0;
  773. HelperRegVal.nboDNSNameServer2 = 0;
  774. HelperRegVal.fNICChosen = FALSE;
  775. HelperRegVal.fEnableRoute = FALSE;
  776. lErr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGKEY_RAS_IP_PARAM_A, 0,
  777. KEY_READ, &hKeyIpParam);
  778. if (ERROR_SUCCESS == lErr)
  779. {
  780. dwErr = RegQueryValueWithAllocW(hKeyIpParam, REGVAL_ADAPTERGUID_W,
  781. REG_SZ, (BYTE**)&wszAdapterGuid);
  782. if ( (NO_ERROR == dwErr)
  783. && (wszAdapterGuid[0]))
  784. {
  785. hr = CLSIDFromString(wszAdapterGuid, &(HelperRegVal.guidChosenNIC));
  786. if (!FAILED(hr))
  787. {
  788. HelperRegVal.fNICChosen = TRUE;
  789. }
  790. }
  791. dwNumBytes = sizeof(dw);
  792. lErr = RegQueryValueEx(hKeyIpParam, REGVAL_SUPPRESSWINS_A, NULL, NULL,
  793. (BYTE*)&dw, &dwNumBytes);
  794. if ( (ERROR_SUCCESS == lErr)
  795. && (0 != dw))
  796. {
  797. HelperRegVal.fSuppressWINSNameServers = TRUE;
  798. }
  799. dwNumBytes = sizeof(dw);
  800. lErr = RegQueryValueEx(hKeyIpParam, REGVAL_SUPPRESSDNS_A, NULL, NULL,
  801. (BYTE*)&dw, &dwNumBytes);
  802. if ( (ERROR_SUCCESS == lErr)
  803. && (0 != dw))
  804. {
  805. HelperRegVal.fSuppressDNSNameServers = TRUE;
  806. }
  807. dwNumBytes = sizeof(dw);
  808. lErr = RegQueryValueEx(hKeyIpParam, REGVAL_CHUNK_SIZE_A, NULL, NULL,
  809. (BYTE*)&dw, &dwNumBytes);
  810. if (ERROR_SUCCESS == lErr)
  811. {
  812. HelperRegVal.dwChunkSize = dw;
  813. }
  814. dwNumBytes = sizeof(dw);
  815. lErr = RegQueryValueEx(hKeyIpParam, REGVAL_ALLOW_NETWORK_ACCESS_A, NULL,
  816. NULL, (BYTE*)&dw, &dwNumBytes);
  817. if (ERROR_SUCCESS == lErr)
  818. {
  819. HelperRegVal.fEnableRoute = dw;
  820. }
  821. dwErr = RegQueryValueWithAllocA(hKeyIpParam, REGVAL_WINSSERVER_A,
  822. REG_SZ, &szIpAddr);
  823. if (NO_ERROR == dwErr)
  824. {
  825. nboIpAddr1 = inet_addr(szIpAddr);
  826. if (INADDR_NONE != nboIpAddr1)
  827. {
  828. HelperRegVal.nboWINSNameServer1 = nboIpAddr1;
  829. }
  830. LocalFree(szIpAddr);
  831. szIpAddr = NULL;
  832. }
  833. dwErr = RegQueryValueWithAllocA(hKeyIpParam, REGVAL_WINSSERVERBACKUP_A,
  834. REG_SZ, &szIpAddr);
  835. if (NO_ERROR == dwErr)
  836. {
  837. nboIpAddr2 = inet_addr(szIpAddr);
  838. if ( (INADDR_NONE != nboIpAddr2)
  839. && (0 != HelperRegVal.nboWINSNameServer1))
  840. {
  841. HelperRegVal.nboWINSNameServer2 = nboIpAddr2;
  842. }
  843. LocalFree(szIpAddr);
  844. szIpAddr = NULL;
  845. }
  846. dwErr = RegQueryValueWithAllocA(hKeyIpParam, REGVAL_DNSSERVERS_A,
  847. REG_MULTI_SZ, &szAlloced);
  848. if (NO_ERROR == dwErr)
  849. {
  850. szIpAddr = szAlloced;
  851. nboIpAddr1 = inet_addr(szIpAddr);
  852. // We are sure that the buffer szIpAddr has 2 zeros at the end
  853. szIpAddr += strlen(szIpAddr) + 1;
  854. nboIpAddr2 = inet_addr(szIpAddr);
  855. if ( (INADDR_NONE != nboIpAddr1)
  856. && (0 != nboIpAddr1))
  857. {
  858. HelperRegVal.nboDNSNameServer1 = nboIpAddr1;
  859. if (INADDR_NONE != nboIpAddr2)
  860. {
  861. HelperRegVal.nboDNSNameServer2 = nboIpAddr2;
  862. }
  863. }
  864. LocalFree(szAlloced);
  865. szAlloced = NULL;
  866. }
  867. }
  868. TraceHlp("%s: %d, %s: %d, %s: %d",
  869. REGVAL_SUPPRESSWINS_A, HelperRegVal.fSuppressWINSNameServers,
  870. REGVAL_SUPPRESSDNS_A, HelperRegVal.fSuppressDNSNameServers,
  871. REGVAL_CHUNK_SIZE_A, HelperRegVal.dwChunkSize);
  872. TraceHlp("%s: 0x%x, %s: 0x%x, %s: 0x%x, 0x%x",
  873. REGVAL_WINSSERVER_A, HelperRegVal.nboWINSNameServer1,
  874. REGVAL_WINSSERVERBACKUP_A, HelperRegVal.nboWINSNameServer2,
  875. REGVAL_DNSSERVERS_A, HelperRegVal.nboDNSNameServer1,
  876. HelperRegVal.nboDNSNameServer2);
  877. if (NULL != hKeyIpParam)
  878. {
  879. RegCloseKey(hKeyIpParam);
  880. }
  881. LocalFree(wszAdapterGuid);
  882. }