Source code of Windows XP (NT5)
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.

2101 lines
47 KiB

  1. /*
  2. File: rasip.h
  3. The 'remoteaccess ip' sub context
  4. 3/2/99
  5. */
  6. #include "precomp.h"
  7. #include "rasip.h"
  8. #include <winsock2.h>
  9. #define MAKEIPADDRESS(b1,b2,b3,b4) \
  10. (((DWORD)(b1)<<24)+((DWORD)(b2)<<16)+((DWORD)(b3)<<8)+((DWORD)(b4)))
  11. #define FIRST_IPADDRESS(x) ((x>>24) & 0xff)
  12. #define SECOND_IPADDRESS(x) ((x>>16) & 0xff)
  13. #define THIRD_IPADDRESS(x) ((x>>8) & 0xff)
  14. #define FOURTH_IPADDRESS(x) (x & 0xff)
  15. // The guid for this context
  16. //
  17. GUID g_RasIpGuid = RASIP_GUID;
  18. static PWCHAR g_pszServer = NULL;
  19. static DWORD g_dwBuild = 0;
  20. // The commands supported in this context
  21. //
  22. CMD_ENTRY g_RasIpSetCmdTable[] =
  23. {
  24. CREATE_CMD_ENTRY(RASIP_SET_NEGOTIATION,RasIpHandleSetNegotiation),
  25. CREATE_CMD_ENTRY(RASIP_SET_ACCESS, RasIpHandleSetAccess),
  26. CREATE_CMD_ENTRY(RASIP_SET_ASSIGNMENT, RasIpHandleSetAssignment),
  27. CREATE_CMD_ENTRY(RASIP_SET_CALLERSPEC, RasIpHandleSetCallerSpec),
  28. CREATE_CMD_ENTRY(RASIP_SET_NETBTBCAST, RasIpHandleSetNetbtBcast),
  29. };
  30. CMD_ENTRY g_RasIpShowCmdTable[] =
  31. {
  32. CREATE_CMD_ENTRY(RASIP_SHOW_CONFIG, RasIpHandleShow),
  33. };
  34. CMD_ENTRY g_RasIpAddCmdTable[] =
  35. {
  36. CREATE_CMD_ENTRY(RASIP_ADD_RANGE, RasIpHandleAddRange),
  37. };
  38. CMD_ENTRY g_RasIpDelCmdTable[] =
  39. {
  40. CREATE_CMD_ENTRY(RASIP_DEL_RANGE, RasIpHandleDelRange),
  41. CREATE_CMD_ENTRY(RASIP_DEL_POOL, RasIpHandleDelPool),
  42. };
  43. CMD_GROUP_ENTRY g_RasIpCmdGroups[] =
  44. {
  45. CREATE_CMD_GROUP_ENTRY(GROUP_SET, g_RasIpSetCmdTable),
  46. CREATE_CMD_GROUP_ENTRY(GROUP_SHOW, g_RasIpShowCmdTable),
  47. CREATE_CMD_GROUP_ENTRY(GROUP_ADD, g_RasIpAddCmdTable),
  48. CREATE_CMD_GROUP_ENTRY(GROUP_DEL, g_RasIpDelCmdTable),
  49. };
  50. ULONG g_ulRasIpNumGroups = sizeof(g_RasIpCmdGroups)/sizeof(CMD_GROUP_ENTRY);
  51. //
  52. // Flags that control how/what info is read/written
  53. // in the RASIP_CB structure
  54. //
  55. #define RASIP_F_EnableIn 0x1
  56. #define RASIP_F_Access 0x2
  57. #define RASIP_F_Auto 0x4
  58. #define RASIP_F_Pool 0x8
  59. #define RASIP_F_Mask 0x10
  60. #define RASIP_F_CallerSpec 0x20
  61. #define RASIP_F_All 0xFFFF
  62. //
  63. // Reasons for the ras ip pool to be invalid
  64. //
  65. #define RASIP_REASON_BadAddress 0x1
  66. #define RASIP_REASON_BadRange 0x3
  67. #define RASIP_REASON_127 0x4
  68. //
  69. // RAS pool definition
  70. //
  71. typedef struct _RAS_IPRANGE_NODE
  72. {
  73. DWORD dwFrom;
  74. DWORD dwTo;
  75. struct _RAS_IPRANGE_NODE* pNext;
  76. } RAS_IPRANGE_NODE;
  77. typedef struct _RAS_IPPOOL
  78. {
  79. DWORD dwCount;
  80. RAS_IPRANGE_NODE* pHead;
  81. RAS_IPRANGE_NODE* pTail;
  82. } RAS_IPPOOL;
  83. //
  84. // Control block for ras ip configuration
  85. //
  86. typedef struct _RASIP_CB
  87. {
  88. DWORD dwFlags; // See RASIP_F_* values
  89. BOOL bEnableIn;
  90. BOOL bAccess;
  91. BOOL bAuto;
  92. RAS_IPPOOL* pPool;
  93. BOOL bCallerSpec;
  94. } RASIP_CB;
  95. //
  96. // Ip specific registry parameters
  97. //
  98. WCHAR pszIpParams[] = L"Ip";
  99. WCHAR pszIpAddress[] = L"IpAddress";
  100. WCHAR pszIpMask[] = L"IpMask";
  101. WCHAR pszIpClientSpec[] = L"AllowClientIpAddresses";
  102. WCHAR pszIpUseDhcp[] = L"UseDhcpAddressing";
  103. WCHAR pszIpFrom[] = L"From";
  104. WCHAR pszIpTo[] = L"To";
  105. WCHAR pszIpPoolSubKey[] = L"StaticAddressPool";
  106. //
  107. // Prototypes of functions that manipulate the
  108. // RASIP_CB structures
  109. //
  110. DWORD
  111. RasIpCbCleanup(
  112. IN RASIP_CB* pConfig);
  113. DWORD
  114. RasIpCbCreateDefault(
  115. OUT RASIP_CB** ppConfig);
  116. DWORD
  117. RasIpCbOpenRegKeys(
  118. IN LPCWSTR pszServer,
  119. OUT HKEY* phKey);
  120. DWORD
  121. RasIpCbRead(
  122. IN LPCWSTR pszServer,
  123. OUT RASIP_CB* pConfig);
  124. DWORD
  125. RasIpCbWrite(
  126. IN LPCWSTR pszServer,
  127. IN RASIP_CB* pConfig);
  128. DWORD
  129. RasIpPoolReset(
  130. IN HKEY hkParams);
  131. DWORD
  132. RasIpPoolRead(
  133. IN HKEY hkParams,
  134. OUT RAS_IPPOOL** ppRanges);
  135. DWORD
  136. RasIpPoolWrite(
  137. IN HKEY hkParams,
  138. IN RAS_IPPOOL* pPool);
  139. DWORD
  140. RasIpPoolAdd(
  141. IN OUT RAS_IPPOOL* pPool,
  142. IN DWORD dwFrom,
  143. IN DWORD dwTo);
  144. DWORD
  145. RasIpPoolDel(
  146. IN OUT RAS_IPPOOL* pPool,
  147. IN DWORD dwFrom,
  148. IN DWORD dwTo);
  149. DWORD
  150. RasIpPoolCleanup(
  151. IN RAS_IPPOOL* pPool);
  152. DWORD
  153. RasIpSetNetbtBcast(
  154. DWORD dwEnable
  155. );
  156. BOOL
  157. RasIpShowNetbtBcast(
  158. VOID
  159. );
  160. //
  161. // Entry called by rasmontr to register this context
  162. //
  163. DWORD
  164. WINAPI
  165. RasIpStartHelper(
  166. IN CONST GUID *pguidParent,
  167. IN DWORD dwVersion)
  168. {
  169. DWORD dwErr = NO_ERROR;
  170. NS_CONTEXT_ATTRIBUTES attMyAttributes;
  171. // Initialize
  172. //
  173. ZeroMemory(&attMyAttributes, sizeof(attMyAttributes));
  174. attMyAttributes.pwszContext = L"ip";
  175. attMyAttributes.guidHelper = g_RasIpGuid;
  176. attMyAttributes.dwVersion = RASIP_VERSION;
  177. attMyAttributes.dwFlags = 0;
  178. attMyAttributes.ulNumTopCmds = 0;
  179. attMyAttributes.pTopCmds = NULL;
  180. attMyAttributes.ulNumGroups = g_ulRasIpNumGroups;
  181. attMyAttributes.pCmdGroups = (CMD_GROUP_ENTRY (*)[])&g_RasIpCmdGroups;
  182. attMyAttributes.pfnDumpFn = RasIpDump;
  183. dwErr = RegisterContext( &attMyAttributes );
  184. return dwErr;
  185. }
  186. DWORD
  187. RasIpDisplayInvalidPool(
  188. IN DWORD dwReason
  189. )
  190. {
  191. DWORD dwArg = 0;
  192. PWCHAR pszArg = NULL;
  193. switch (dwReason)
  194. {
  195. case RASIP_REASON_BadAddress:
  196. dwArg = EMSG_RASIP_BAD_ADDRESS;
  197. break;
  198. case RASIP_REASON_BadRange:
  199. dwArg = EMSG_RASIP_BAD_RANGE;
  200. break;
  201. case RASIP_REASON_127:
  202. dwArg = EMSG_RASIP_NETID_127;
  203. break;
  204. default:
  205. dwArg = EMSG_RASIP_BAD_POOL_GENERIC;
  206. break;
  207. }
  208. // Make the argument string
  209. //
  210. pszArg = MakeString(g_hModule, dwArg);
  211. if (pszArg == NULL)
  212. {
  213. DisplayError(NULL, ERROR_NOT_ENOUGH_MEMORY);
  214. return ERROR_NOT_ENOUGH_MEMORY;
  215. }
  216. // Display the error
  217. //
  218. DisplayMessage(
  219. g_hModule,
  220. EMSG_RASIP_INVALID_POOL,
  221. pszArg);
  222. // Cleanup
  223. //
  224. FreeString(pszArg);
  225. return NO_ERROR;
  226. }
  227. DWORD
  228. RasIpDisplayPool(
  229. IN RASIP_CB* pConfig,
  230. IN BOOL bReport)
  231. {
  232. DWORD dwErr = NO_ERROR, i;
  233. RAS_IPPOOL* pPool = pConfig->pPool;
  234. RAS_IPRANGE_NODE* pNode = NULL;
  235. PWCHAR pszFrom = NULL, pszTo = NULL;
  236. WCHAR pszFromBuf[128], pszToBuf[128];
  237. if (!pPool)
  238. {
  239. return ERROR_CAN_NOT_COMPLETE;
  240. }
  241. do
  242. {
  243. pNode = pPool->pHead;
  244. for (i = 0; i < pPool->dwCount; i++, pNode = pNode->pNext)
  245. {
  246. wsprintfW(
  247. pszFromBuf,
  248. L"%d.%d.%d.%d",
  249. FIRST_IPADDRESS(pNode->dwFrom),
  250. SECOND_IPADDRESS(pNode->dwFrom),
  251. THIRD_IPADDRESS(pNode->dwFrom),
  252. FOURTH_IPADDRESS(pNode->dwFrom));
  253. wsprintfW(
  254. pszToBuf,
  255. L"%d.%d.%d.%d",
  256. FIRST_IPADDRESS(pNode->dwTo),
  257. SECOND_IPADDRESS(pNode->dwTo),
  258. THIRD_IPADDRESS(pNode->dwTo),
  259. FOURTH_IPADDRESS(pNode->dwTo));
  260. if (bReport)
  261. {
  262. DisplayMessage(
  263. g_hModule,
  264. MSG_RASIP_SHOW_POOL,
  265. pszFromBuf,
  266. pszToBuf);
  267. }
  268. else
  269. {
  270. pszFrom = RutlAssignmentFromTokens(g_hModule, TOKEN_FROM, pszFromBuf);
  271. pszTo = RutlAssignmentFromTokens(g_hModule, TOKEN_TO, pszToBuf);
  272. if (pszFrom == NULL || pszTo == NULL)
  273. {
  274. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  275. break;
  276. }
  277. DisplayMessage(
  278. g_hModule,
  279. MSG_RASIP_ADD_RANGE_CMD,
  280. DMP_RASIP_ADD_RANGE,
  281. pszFrom,
  282. pszTo);
  283. }
  284. }
  285. } while (FALSE);
  286. // Cleanup
  287. {
  288. RutlFree(pszFrom);
  289. RutlFree(pszTo);
  290. }
  291. return dwErr;
  292. }
  293. DWORD
  294. RasIpDisplayConfig(
  295. IN BOOL bReport)
  296. {
  297. DWORD dwErr = NO_ERROR, dwReason;
  298. RASIP_CB* pConfig = NULL;
  299. PWCHAR pszPool = NULL, pszAccess = NULL, pszAuto = NULL, pszMask = NULL;
  300. PWCHAR pszEnableIn = NULL, pszCaller = NULL, pszNetbtBcast = NULL;
  301. do
  302. {
  303. // Get a default config blob
  304. //
  305. dwErr = RasIpCbCreateDefault(&pConfig);
  306. BREAK_ON_DWERR( dwErr );
  307. // Read in all of the values
  308. //
  309. pConfig->dwFlags = RASIP_F_All;
  310. dwErr = RasIpCbRead(g_pszServer, pConfig);
  311. BREAK_ON_DWERR( dwErr );
  312. if (bReport)
  313. {
  314. pszEnableIn =
  315. RutlStrDup(pConfig->bEnableIn ? TOKEN_ALLOW : TOKEN_DENY);
  316. pszAccess =
  317. RutlStrDup(pConfig->bAccess ? TOKEN_ALL : TOKEN_SERVERONLY);
  318. pszAuto =
  319. RutlStrDup(pConfig->bAuto ? TOKEN_AUTO : TOKEN_POOL);
  320. pszCaller =
  321. RutlStrDup(pConfig->bCallerSpec ? TOKEN_ALLOW : TOKEN_DENY);
  322. // Whistler bug: 359847 Netsh: move broadcastnameresolution from
  323. // routing ip to ras ip
  324. //
  325. pszNetbtBcast =
  326. RutlStrDup(RasIpShowNetbtBcast() ? TOKEN_ENABLED :
  327. TOKEN_DISABLED);
  328. DisplayMessage(
  329. g_hModule,
  330. MSG_RASIP_SERVERCONFIG,
  331. g_pszServer,
  332. pszEnableIn,
  333. pszAccess,
  334. pszAuto,
  335. pszCaller,
  336. pszNetbtBcast);
  337. RasIpDisplayPool(pConfig, bReport);
  338. }
  339. else
  340. {
  341. pszEnableIn = RutlAssignmentFromTokens(
  342. g_hModule,
  343. TOKEN_MODE,
  344. pConfig->bEnableIn ? TOKEN_ALLOW : TOKEN_DENY);
  345. pszAccess = RutlAssignmentFromTokens(
  346. g_hModule,
  347. TOKEN_MODE,
  348. pConfig->bAccess ? TOKEN_ALL : TOKEN_SERVERONLY);
  349. pszAuto = RutlAssignmentFromTokens(
  350. g_hModule,
  351. TOKEN_METHOD,
  352. pConfig->bAuto ? TOKEN_AUTO : TOKEN_POOL);
  353. pszCaller = RutlAssignmentFromTokens(
  354. g_hModule,
  355. TOKEN_MODE,
  356. pConfig->bCallerSpec ? TOKEN_ALLOW : TOKEN_DENY);
  357. // Whistler bug: 359847 Netsh: move broadcastnameresolution from
  358. // routing ip to ras ip
  359. //
  360. pszNetbtBcast = RutlAssignmentFromTokens(
  361. g_hModule,
  362. TOKEN_MODE,
  363. RasIpShowNetbtBcast() ? TOKEN_ENABLED :
  364. TOKEN_DISABLED);
  365. DisplayMessage(
  366. g_hModule,
  367. MSG_RASIP_SCRIPTHEADER);
  368. DisplayMessageT(DMP_RASIP_PUSHD);
  369. DisplayMessageT(
  370. DMP_RASIP_DEL_POOL);
  371. DisplayMessageT(MSG_NEWLINE);
  372. DisplayMessageT(MSG_NEWLINE);
  373. DisplayMessage(
  374. g_hModule,
  375. MSG_RASIP_SET_CMD,
  376. DMP_RASIP_SET_NEGOTIATION,
  377. pszEnableIn);
  378. DisplayMessage(
  379. g_hModule,
  380. MSG_RASIP_SET_CMD,
  381. DMP_RASIP_SET_ACCESS,
  382. pszAccess);
  383. DisplayMessage(
  384. g_hModule,
  385. MSG_RASIP_SET_CMD,
  386. DMP_RASIP_SET_CALLERSPEC,
  387. pszCaller);
  388. DisplayMessage(
  389. g_hModule,
  390. MSG_RASIP_SET_CMD,
  391. DMP_RASIP_SET_NETBTBCAST,
  392. pszNetbtBcast);
  393. if (! pConfig->bAuto)
  394. {
  395. RasIpDisplayPool(pConfig, bReport);
  396. }
  397. DisplayMessage(
  398. g_hModule,
  399. MSG_RASIP_SET_CMD,
  400. DMP_RASIP_SET_ASSIGNMENT,
  401. pszAuto);
  402. DisplayMessageT(DMP_RASIP_POPD);
  403. DisplayMessage(
  404. g_hModule,
  405. MSG_RASIP_SCRIPTFOOTER);
  406. }
  407. } while (FALSE);
  408. // Cleanup
  409. {
  410. if (pConfig)
  411. {
  412. RasIpCbCleanup(pConfig);
  413. }
  414. if (pszEnableIn)
  415. {
  416. RutlFree(pszEnableIn);
  417. }
  418. if (pszAccess)
  419. {
  420. RutlFree(pszAccess);
  421. }
  422. if (pszAuto)
  423. {
  424. RutlFree(pszAuto);
  425. }
  426. if (pszCaller)
  427. {
  428. RutlFree(pszCaller);
  429. }
  430. if (pszNetbtBcast)
  431. {
  432. RutlFree(pszNetbtBcast);
  433. }
  434. if (pszPool)
  435. {
  436. RutlFree(pszPool);
  437. }
  438. if (pszMask)
  439. {
  440. RutlFree(pszMask);
  441. }
  442. }
  443. return dwErr;
  444. }
  445. DWORD
  446. WINAPI
  447. RasIpDump(
  448. IN LPCWSTR pwszRouter,
  449. IN OUT LPWSTR *ppwcArguments,
  450. IN DWORD dwArgCount,
  451. IN LPCVOID pvData
  452. )
  453. {
  454. return RasIpDisplayConfig(FALSE);
  455. }
  456. //
  457. // Returns NO_ERROR if the given address is a valid IP pool.
  458. // The offending component is returned in lpdwErrReason.
  459. // See RASIP_F_* values
  460. //
  461. DWORD
  462. RasIpValidateRange(
  463. IN DWORD dwFrom,
  464. IN DWORD dwTo,
  465. OUT LPDWORD lpdwErrReason
  466. )
  467. {
  468. DWORD dwLowIp, dwHighIp;
  469. // Initialize
  470. //
  471. *lpdwErrReason = 0;
  472. dwLowIp = MAKEIPADDRESS(1,0,0,0);
  473. dwHighIp = MAKEIPADDRESS(224,0,0,0);
  474. // Make sure that the netId is a valid class
  475. //
  476. if ((dwFrom < dwLowIp) ||
  477. (dwFrom >= dwHighIp) ||
  478. (dwTo < dwLowIp) ||
  479. (dwTo >= dwHighIp))
  480. {
  481. *lpdwErrReason = RASIP_REASON_BadAddress;
  482. return ERROR_BAD_FORMAT;
  483. }
  484. if ((FIRST_IPADDRESS(dwFrom) == 127) ||
  485. (FIRST_IPADDRESS(dwTo) == 127))
  486. {
  487. *lpdwErrReason = RASIP_REASON_127;
  488. return ERROR_BAD_FORMAT;
  489. }
  490. if (!(dwFrom <= dwTo))
  491. {
  492. *lpdwErrReason = RASIP_REASON_BadRange;
  493. return ERROR_BAD_FORMAT;
  494. }
  495. return NO_ERROR;
  496. }
  497. DWORD
  498. RasIpConvertRangePszToDword(
  499. IN LPCWSTR pszFrom,
  500. IN LPCWSTR pszTo,
  501. OUT LPDWORD lpdwFrom,
  502. OUT LPDWORD lpdwTo)
  503. {
  504. DWORD dwFrom = 0, dwTo = 0;
  505. CHAR pszFromA[64], pszToA[64];
  506. // Whistler bug 259799 PREFIX
  507. //
  508. if (NULL == pszFrom || NULL == pszTo)
  509. {
  510. return ERROR_INVALID_PARAMETER;
  511. }
  512. wcstombs(pszFromA, pszFrom, sizeof(pszFromA));
  513. dwFrom = inet_addr(pszFromA);
  514. if (dwFrom == INADDR_NONE)
  515. {
  516. return ERROR_BAD_FORMAT;
  517. }
  518. wcstombs(pszToA, pszTo, sizeof(pszToA));
  519. dwTo = inet_addr(pszToA);
  520. if (dwTo == INADDR_NONE)
  521. {
  522. return ERROR_BAD_FORMAT;
  523. }
  524. // Convert for x86
  525. //
  526. *lpdwFrom = ntohl(dwFrom);
  527. *lpdwTo = ntohl(dwTo);
  528. return NO_ERROR;
  529. }
  530. DWORD
  531. RasIpHandleSetAccess(
  532. IN LPCWSTR pwszMachine,
  533. IN OUT LPWSTR *ppwcArguments,
  534. IN DWORD dwCurrentIndex,
  535. IN DWORD dwArgCount,
  536. IN DWORD dwFlags,
  537. IN LPCVOID pvData,
  538. OUT BOOL *pbDone
  539. )
  540. {
  541. DWORD dwErr = NO_ERROR, dwValue = 0;
  542. RASIP_CB Config;
  543. TOKEN_VALUE rgEnumMode[] =
  544. {
  545. {TOKEN_ALL, TRUE},
  546. {TOKEN_SERVERONLY, FALSE}
  547. };
  548. RASMON_CMD_ARG pArgs[] =
  549. {
  550. {
  551. RASMONTR_CMD_TYPE_ENUM,
  552. {TOKEN_MODE, TRUE, FALSE},
  553. rgEnumMode,
  554. sizeof(rgEnumMode)/sizeof(*rgEnumMode),
  555. NULL
  556. }
  557. };
  558. do
  559. {
  560. // Parse the command line
  561. //
  562. dwErr = RutlParse(
  563. ppwcArguments,
  564. dwCurrentIndex,
  565. dwArgCount,
  566. pbDone,
  567. pArgs,
  568. sizeof(pArgs)/sizeof(*pArgs));
  569. BREAK_ON_DWERR( dwErr );
  570. dwValue = RASMON_CMD_ARG_GetDword(&pArgs[0]);
  571. // If successful, go ahead and set the info
  572. //
  573. ZeroMemory(&Config, sizeof(Config));
  574. Config.dwFlags = RASIP_F_Access;
  575. Config.bAccess = dwValue;
  576. dwErr = RasIpCbWrite(g_pszServer, &Config);
  577. if (dwErr != NO_ERROR)
  578. {
  579. DisplayError(NULL, dwErr);
  580. break;
  581. }
  582. } while (FALSE);
  583. // Cleanup
  584. {
  585. }
  586. return dwErr;
  587. }
  588. DWORD
  589. RasIpHandleSetAssignment(
  590. IN LPCWSTR pwszMachine,
  591. IN OUT LPWSTR *ppwcArguments,
  592. IN DWORD dwCurrentIndex,
  593. IN DWORD dwArgCount,
  594. IN DWORD dwFlags,
  595. IN LPCVOID pvData,
  596. OUT BOOL *pbDone
  597. )
  598. {
  599. DWORD dwErr = NO_ERROR, dwValue = 0, dwReason = 0;
  600. RASIP_CB* pConfig = NULL;
  601. TOKEN_VALUE rgEnum[] =
  602. {
  603. {TOKEN_AUTO, TRUE},
  604. {TOKEN_POOL, FALSE}
  605. };
  606. RASMON_CMD_ARG pArgs[] =
  607. {
  608. {
  609. RASMONTR_CMD_TYPE_ENUM,
  610. {TOKEN_METHOD, TRUE, FALSE},
  611. rgEnum,
  612. sizeof(rgEnum)/sizeof(*rgEnum),
  613. NULL
  614. }
  615. };
  616. // Initialize
  617. RasIpCbCreateDefault(&pConfig);
  618. do
  619. {
  620. // Parse the command line
  621. //
  622. dwErr = RutlParse(
  623. ppwcArguments,
  624. dwCurrentIndex,
  625. dwArgCount,
  626. pbDone,
  627. pArgs,
  628. sizeof(pArgs)/sizeof(*pArgs));
  629. BREAK_ON_DWERR( dwErr );
  630. dwValue = RASMON_CMD_ARG_GetDword(&pArgs[0]);
  631. // If this is an attempt to switch to pool mode,
  632. // make sure there is a valid pool.
  633. //
  634. if (dwValue == FALSE)
  635. {
  636. pConfig->dwFlags = RASIP_F_Pool | RASIP_F_Mask;
  637. dwErr = RasIpCbRead(g_pszServer, pConfig);
  638. BREAK_ON_DWERR( dwErr );
  639. if (pConfig->pPool->dwCount == 0)
  640. {
  641. DisplayMessage(
  642. g_hModule,
  643. EMSG_RASIP_NEED_VALID_POOL,
  644. DMP_RASIP_ADD_RANGE);
  645. dwErr = ERROR_CAN_NOT_COMPLETE;
  646. break;
  647. }
  648. }
  649. // If successful, go ahead and set the info
  650. //
  651. pConfig->dwFlags = RASIP_F_Auto;
  652. pConfig->bAuto = dwValue;
  653. dwErr = RasIpCbWrite(g_pszServer, pConfig);
  654. if (dwErr != NO_ERROR)
  655. {
  656. DisplayError(NULL, dwErr);
  657. break;
  658. }
  659. } while (FALSE);
  660. // Cleanup
  661. {
  662. RasIpCbCleanup(pConfig);
  663. }
  664. return dwErr;
  665. }
  666. DWORD
  667. RasIpHandleSetCallerSpec(
  668. IN LPCWSTR pwszMachine,
  669. IN OUT LPWSTR *ppwcArguments,
  670. IN DWORD dwCurrentIndex,
  671. IN DWORD dwArgCount,
  672. IN DWORD dwFlags,
  673. IN LPCVOID pvData,
  674. OUT BOOL *pbDone
  675. )
  676. {
  677. DWORD dwErr = NO_ERROR, dwValue = 0;
  678. RASIP_CB Config;
  679. TOKEN_VALUE rgEnum[] =
  680. {
  681. {TOKEN_ALLOW, TRUE},
  682. {TOKEN_DENY, FALSE}
  683. };
  684. RASMON_CMD_ARG pArgs[] =
  685. {
  686. {
  687. RASMONTR_CMD_TYPE_ENUM,
  688. {TOKEN_MODE, TRUE, FALSE},
  689. rgEnum,
  690. sizeof(rgEnum)/sizeof(*rgEnum),
  691. NULL
  692. }
  693. };
  694. do
  695. {
  696. // Parse the command line
  697. //
  698. dwErr = RutlParse(
  699. ppwcArguments,
  700. dwCurrentIndex,
  701. dwArgCount,
  702. pbDone,
  703. pArgs,
  704. sizeof(pArgs)/sizeof(*pArgs));
  705. BREAK_ON_DWERR( dwErr );
  706. dwValue = RASMON_CMD_ARG_GetDword(&pArgs[0]);
  707. // If successful, go ahead and set the info
  708. //
  709. ZeroMemory(&Config, sizeof(Config));
  710. Config.dwFlags = RASIP_F_CallerSpec;
  711. Config.bCallerSpec = dwValue;
  712. dwErr = RasIpCbWrite(g_pszServer, &Config);
  713. if (dwErr != NO_ERROR)
  714. {
  715. DisplayError(NULL, dwErr);
  716. break;
  717. }
  718. } while (FALSE);
  719. // Cleanup
  720. {
  721. }
  722. return dwErr;
  723. }
  724. DWORD
  725. RasIpHandleSetNegotiation(
  726. IN LPCWSTR pwszMachine,
  727. IN OUT LPWSTR *ppwcArguments,
  728. IN DWORD dwCurrentIndex,
  729. IN DWORD dwArgCount,
  730. IN DWORD dwFlags,
  731. IN LPCVOID pvData,
  732. OUT BOOL *pbDone
  733. )
  734. {
  735. DWORD dwErr = NO_ERROR, dwValue = 0;
  736. RASIP_CB Config;
  737. TOKEN_VALUE rgEnum[] =
  738. {
  739. {TOKEN_ALLOW, TRUE},
  740. {TOKEN_DENY, FALSE}
  741. };
  742. RASMON_CMD_ARG pArgs[] =
  743. {
  744. {
  745. RASMONTR_CMD_TYPE_ENUM,
  746. {TOKEN_MODE, TRUE, FALSE},
  747. rgEnum,
  748. sizeof(rgEnum)/sizeof(*rgEnum),
  749. NULL
  750. }
  751. };
  752. do
  753. {
  754. // Parse the command line
  755. //
  756. dwErr = RutlParse(
  757. ppwcArguments,
  758. dwCurrentIndex,
  759. dwArgCount,
  760. pbDone,
  761. pArgs,
  762. sizeof(pArgs)/sizeof(*pArgs));
  763. BREAK_ON_DWERR( dwErr );
  764. dwValue = RASMON_CMD_ARG_GetDword(&pArgs[0]);
  765. // If successful, go ahead and set the info
  766. //
  767. ZeroMemory(&Config, sizeof(Config));
  768. Config.dwFlags = RASIP_F_EnableIn;
  769. Config.bEnableIn = dwValue;
  770. dwErr = RasIpCbWrite(g_pszServer, &Config);
  771. if (dwErr != NO_ERROR)
  772. {
  773. DisplayError(NULL, dwErr);
  774. break;
  775. }
  776. } while (FALSE);
  777. // Cleanup
  778. {
  779. }
  780. return dwErr;
  781. }
  782. //
  783. // Get options to set NETBT broadcast enable/disable
  784. // ppwcArguments - Argument array
  785. // dwCurrentIndex - ppwcArguments[dwCurrentIndex] is the first arg
  786. // dwArgCount - ppwcArguments[dwArgCount - 1] is the last arg
  787. //
  788. // Whistler bug: 359847 Netsh: move broadcastnameresolution from routing ip to
  789. // ras ip
  790. //
  791. DWORD
  792. RasIpHandleSetNetbtBcast(
  793. IN LPCWSTR pwszMachine,
  794. IN OUT LPWSTR *ppwcArguments,
  795. IN DWORD dwCurrentIndex,
  796. IN DWORD dwArgCount,
  797. IN DWORD dwFlags,
  798. IN LPCVOID pvData,
  799. OUT BOOL *pbDone
  800. )
  801. {
  802. DWORD dwErr = NO_ERROR, dwValue = 0;
  803. TOKEN_VALUE rgEnum[] =
  804. {
  805. {TOKEN_ENABLED, TRUE},
  806. {TOKEN_DISABLED, FALSE}
  807. };
  808. RASMON_CMD_ARG pArgs[] =
  809. {
  810. {
  811. RASMONTR_CMD_TYPE_ENUM,
  812. {TOKEN_MODE, TRUE, FALSE},
  813. rgEnum,
  814. sizeof(rgEnum)/sizeof(*rgEnum),
  815. NULL
  816. }
  817. };
  818. do
  819. {
  820. // Parse the command line
  821. //
  822. dwErr = RutlParse(
  823. ppwcArguments,
  824. dwCurrentIndex,
  825. dwArgCount,
  826. pbDone,
  827. pArgs,
  828. sizeof(pArgs)/sizeof(*pArgs));
  829. BREAK_ON_DWERR( dwErr );
  830. dwValue = RASMON_CMD_ARG_GetDword(&pArgs[0]);
  831. // If successful, go ahead and set the info
  832. //
  833. dwErr = RasIpSetNetbtBcast(dwValue);
  834. if (dwErr != NO_ERROR)
  835. {
  836. DisplayError(NULL, dwErr);
  837. break;
  838. }
  839. } while (FALSE);
  840. // Cleanup
  841. {
  842. }
  843. return dwErr;
  844. }
  845. DWORD
  846. RasIpHandleAddDelRange(
  847. IN OUT LPWSTR *ppwcArguments,
  848. IN DWORD dwCurrentIndex,
  849. IN DWORD dwArgCount,
  850. IN BOOL *pbDone,
  851. IN BOOL bAdd
  852. )
  853. {
  854. PWCHAR pszFrom = NULL, pszTo = NULL;
  855. DWORD dwFrom = 0, dwTo = 0, dwErr = NO_ERROR, dwReason;
  856. RASIP_CB * pConfig = NULL;
  857. RASMON_CMD_ARG pArgs[] =
  858. {
  859. {
  860. RASMONTR_CMD_TYPE_STRING,
  861. {TOKEN_FROM, TRUE, FALSE},
  862. NULL,
  863. 0,
  864. NULL
  865. },
  866. {
  867. RASMONTR_CMD_TYPE_STRING,
  868. {TOKEN_TO, TRUE, FALSE},
  869. NULL,
  870. 0,
  871. NULL
  872. }
  873. };
  874. PWCHAR pszAddr = NULL, pszMask = NULL;
  875. do
  876. {
  877. pConfig = (RASIP_CB*) RutlAlloc(sizeof(RASIP_CB), TRUE);
  878. if (pConfig == NULL)
  879. {
  880. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  881. break;
  882. }
  883. // Parse the command line
  884. //
  885. dwErr = RutlParse(
  886. ppwcArguments,
  887. dwCurrentIndex,
  888. dwArgCount,
  889. pbDone,
  890. pArgs,
  891. sizeof(pArgs)/sizeof(*pArgs));
  892. BREAK_ON_DWERR( dwErr );
  893. pszFrom = RASMON_CMD_ARG_GetPsz(&pArgs[0]);
  894. pszTo = RASMON_CMD_ARG_GetPsz(&pArgs[1]);
  895. dwErr = RasIpConvertRangePszToDword(
  896. pszFrom,
  897. pszTo,
  898. &dwFrom,
  899. &dwTo);
  900. BREAK_ON_DWERR(dwErr);
  901. // Validate the values entered
  902. //
  903. dwErr = RasIpValidateRange(dwFrom, dwTo, &dwReason);
  904. if (dwErr != NO_ERROR)
  905. {
  906. RasIpDisplayInvalidPool(dwReason);
  907. dwErr = ERROR_CAN_NOT_COMPLETE;
  908. break;
  909. }
  910. // Read in the old config
  911. pConfig->dwFlags = RASIP_F_Pool;
  912. dwErr = RasIpCbRead(g_pszServer, pConfig);
  913. BREAK_ON_DWERR(dwErr);
  914. if (bAdd)
  915. {
  916. // Add the range
  917. //
  918. dwErr = RasIpPoolAdd(
  919. pConfig->pPool,
  920. dwFrom,
  921. dwTo);
  922. if (dwErr == ERROR_CAN_NOT_COMPLETE)
  923. {
  924. DisplayMessage(
  925. g_hModule,
  926. EMSG_RASIP_OVERLAPPING_RANGE);
  927. }
  928. BREAK_ON_DWERR(dwErr);
  929. }
  930. else
  931. {
  932. // Delete the range
  933. //
  934. dwErr = RasIpPoolDel(
  935. pConfig->pPool,
  936. dwFrom,
  937. dwTo);
  938. BREAK_ON_DWERR(dwErr);
  939. }
  940. // Commit the change
  941. //
  942. dwErr = RasIpCbWrite(
  943. g_pszServer,
  944. pConfig);
  945. BREAK_ON_DWERR(dwErr);
  946. } while (FALSE);
  947. // Cleanup
  948. {
  949. RutlFree(pszFrom);
  950. RutlFree(pszTo);
  951. RasIpCbCleanup(pConfig);
  952. }
  953. return dwErr;
  954. }
  955. DWORD
  956. RasIpHandleAddRange(
  957. IN LPCWSTR pwszMachine,
  958. IN OUT LPWSTR *ppwcArguments,
  959. IN DWORD dwCurrentIndex,
  960. IN DWORD dwArgCount,
  961. IN DWORD dwFlags,
  962. IN LPCVOID pvData,
  963. OUT BOOL *pbDone
  964. )
  965. {
  966. return RasIpHandleAddDelRange(
  967. ppwcArguments,
  968. dwCurrentIndex,
  969. dwArgCount,
  970. pbDone,
  971. TRUE);
  972. }
  973. DWORD
  974. RasIpHandleDelRange(
  975. IN LPCWSTR pwszMachine,
  976. IN OUT LPWSTR *ppwcArguments,
  977. IN DWORD dwCurrentIndex,
  978. IN DWORD dwArgCount,
  979. IN DWORD dwFlags,
  980. IN LPCVOID pvData,
  981. OUT BOOL *pbDone
  982. )
  983. {
  984. return RasIpHandleAddDelRange(
  985. ppwcArguments,
  986. dwCurrentIndex,
  987. dwArgCount,
  988. pbDone,
  989. FALSE);
  990. }
  991. DWORD
  992. RasIpHandleDelPool(
  993. IN LPCWSTR pwszMachine,
  994. IN OUT LPWSTR *ppwcArguments,
  995. IN DWORD dwCurrentIndex,
  996. IN DWORD dwArgCount,
  997. IN DWORD dwFlags,
  998. IN LPCVOID pvData,
  999. OUT BOOL *pbDone
  1000. )
  1001. {
  1002. DWORD dwNumArgs = dwArgCount - dwCurrentIndex;
  1003. RASIP_CB Config;
  1004. RAS_IPPOOL* pPool = NULL;
  1005. DWORD dwErr = NO_ERROR;
  1006. // Check that the number of arguments is correct
  1007. //
  1008. if (dwNumArgs > 0)
  1009. {
  1010. DisplayMessage(
  1011. g_hModule,
  1012. HLP_RASIP_DEL_POOL_EX,
  1013. DMP_RASIP_DEL_POOL);
  1014. return NO_ERROR;
  1015. }
  1016. do
  1017. {
  1018. // Initialize an empty pool
  1019. //
  1020. pPool = RutlAlloc(sizeof(RAS_IPPOOL), TRUE);
  1021. if (pPool == NULL)
  1022. {
  1023. return ERROR_NOT_ENOUGH_MEMORY;
  1024. }
  1025. ZeroMemory(&Config, sizeof(Config));
  1026. Config.dwFlags = RASIP_F_Pool;
  1027. Config.pPool = pPool;
  1028. dwErr = RasIpCbWrite(g_pszServer, &Config);
  1029. BREAK_ON_DWERR(dwErr);
  1030. } while (FALSE);
  1031. // Cleanup
  1032. {
  1033. if (pPool)
  1034. {
  1035. RasIpPoolCleanup(pPool);
  1036. }
  1037. }
  1038. return dwErr;
  1039. }
  1040. DWORD
  1041. RasIpHandleShow(
  1042. IN LPCWSTR pwszMachine,
  1043. IN OUT LPWSTR *ppwcArguments,
  1044. IN DWORD dwCurrentIndex,
  1045. IN DWORD dwArgCount,
  1046. IN DWORD dwFlags,
  1047. IN LPCVOID pvData,
  1048. OUT BOOL *pbDone
  1049. )
  1050. {
  1051. DWORD dwNumArgs = dwArgCount - dwCurrentIndex;
  1052. // Check that the number of arguments is correct
  1053. //
  1054. if (dwNumArgs > 0)
  1055. {
  1056. DisplayMessage(
  1057. g_hModule,
  1058. HLP_RASIP_SHOW_CONFIG_EX,
  1059. DMP_RASIP_SHOW_CONFIG);
  1060. return NO_ERROR;
  1061. }
  1062. return RasIpDisplayConfig(TRUE);
  1063. }
  1064. //
  1065. // Opens the registry keys associated with the ras ip address pool
  1066. //
  1067. DWORD
  1068. RasIpPoolOpenKeys(
  1069. IN HKEY hkParams,
  1070. IN BOOL bCreate,
  1071. OUT HKEY* phNew)
  1072. {
  1073. DWORD dwErr = NO_ERROR, dwDisposition;
  1074. do
  1075. {
  1076. *phNew = NULL;
  1077. if (bCreate)
  1078. {
  1079. dwErr = RegCreateKeyEx(
  1080. hkParams,
  1081. pszIpPoolSubKey,
  1082. 0,
  1083. NULL,
  1084. REG_OPTION_NON_VOLATILE,
  1085. KEY_ALL_ACCESS,
  1086. NULL,
  1087. phNew,
  1088. &dwDisposition);
  1089. }
  1090. else
  1091. {
  1092. dwErr = RegOpenKeyEx(
  1093. hkParams,
  1094. pszIpPoolSubKey,
  1095. 0,
  1096. KEY_ALL_ACCESS,
  1097. phNew);
  1098. }
  1099. BREAK_ON_DWERR(dwErr);
  1100. } while (FALSE);
  1101. // Cleanup
  1102. {
  1103. }
  1104. return dwErr;
  1105. }
  1106. //
  1107. // Find a given range in the IP address pool.
  1108. // If bExact is TRUE, it searches for an exact match to the range
  1109. // If bExact is FALSE, it searches for any overlapping range.
  1110. //
  1111. DWORD
  1112. RasIpPoolFind(
  1113. IN RAS_IPPOOL* pPool,
  1114. IN DWORD dwFrom,
  1115. IN DWORD dwTo,
  1116. IN BOOL bExact,
  1117. OUT RAS_IPRANGE_NODE** ppNode OPTIONAL)
  1118. {
  1119. RAS_IPRANGE_NODE* pNode = pPool->pHead;
  1120. if (bExact)
  1121. {
  1122. for (; pNode; pNode = pNode->pNext)
  1123. {
  1124. if ((pNode->dwFrom == dwFrom) && (pNode->dwTo == pNode->dwTo))
  1125. {
  1126. break;
  1127. }
  1128. }
  1129. }
  1130. else
  1131. {
  1132. for (; pNode; pNode = pNode->pNext)
  1133. {
  1134. if (
  1135. // Overlap case 1: The lower end falls within an existing range
  1136. //
  1137. ((dwFrom >= pNode->dwFrom) && (dwFrom <= pNode->dwTo)) ||
  1138. // Overlap case 2: The upper end falls within an existing range
  1139. //
  1140. ((dwTo >= pNode->dwFrom) && (dwTo <= pNode->dwTo)) ||
  1141. // Overlap case 3: The range is a superset of an existing range
  1142. //
  1143. ((dwFrom < pNode->dwFrom) && (dwTo > pNode->dwTo))
  1144. )
  1145. {
  1146. break;
  1147. }
  1148. }
  1149. }
  1150. if (pNode)
  1151. {
  1152. if (ppNode)
  1153. {
  1154. *ppNode = pNode;
  1155. }
  1156. return NO_ERROR;
  1157. }
  1158. return ERROR_NOT_FOUND;
  1159. }
  1160. //
  1161. // Callback function populates a pool of addresses
  1162. //
  1163. DWORD
  1164. RasIpPoolReadNode(
  1165. IN LPCWSTR pszName, // sub key name
  1166. IN HKEY hKey, // sub key
  1167. IN HANDLE hData)
  1168. {
  1169. RAS_IPPOOL* pPool = (RAS_IPPOOL*)hData;
  1170. DWORD dwErr = NO_ERROR;
  1171. DWORD dwFrom = 0, dwTo = 0;
  1172. dwErr = RutlRegReadDword(hKey, pszIpFrom, &dwFrom);
  1173. if (dwErr != NO_ERROR)
  1174. {
  1175. return NO_ERROR;
  1176. }
  1177. dwErr = RutlRegReadDword(hKey, pszIpTo, &dwTo);
  1178. if (dwErr != NO_ERROR)
  1179. {
  1180. return NO_ERROR;
  1181. }
  1182. dwErr = RasIpPoolAdd(pPool, dwFrom, dwTo);
  1183. return dwErr;
  1184. }
  1185. //
  1186. // Resets the ras pool on the given server
  1187. //
  1188. DWORD
  1189. RasIpPoolReset(
  1190. IN HKEY hkParams)
  1191. {
  1192. DWORD dwErr = NO_ERROR;
  1193. HKEY hkPool = NULL;
  1194. do
  1195. {
  1196. dwErr = RasIpPoolOpenKeys(
  1197. hkParams,
  1198. TRUE,
  1199. &hkPool);
  1200. BREAK_ON_DWERR(dwErr);
  1201. {
  1202. DWORD i;
  1203. WCHAR pszBuf[16];
  1204. HKEY hkRange = NULL;
  1205. for (i = 0; ;i++)
  1206. {
  1207. _itow(i, pszBuf, 10);
  1208. dwErr = RegOpenKeyEx(
  1209. hkPool,
  1210. pszBuf,
  1211. 0,
  1212. KEY_ALL_ACCESS,
  1213. &hkRange);
  1214. if (dwErr != ERROR_SUCCESS)
  1215. {
  1216. dwErr = NO_ERROR;
  1217. break;
  1218. }
  1219. RegCloseKey(hkRange);
  1220. RegDeleteKey(hkPool, pszBuf);
  1221. }
  1222. BREAK_ON_DWERR(dwErr);
  1223. }
  1224. } while (FALSE);
  1225. // Cleanup
  1226. {
  1227. if (hkPool)
  1228. {
  1229. RegCloseKey(hkPool);
  1230. }
  1231. }
  1232. return dwErr;
  1233. }
  1234. //
  1235. // Reads the ras ip pool from the given server
  1236. //
  1237. DWORD
  1238. RasIpPoolRead(
  1239. IN HKEY hkParams,
  1240. OUT RAS_IPPOOL** ppPool)
  1241. {
  1242. DWORD dwErr = NO_ERROR;
  1243. RAS_IPPOOL* pPool = NULL;
  1244. HKEY hkPool = NULL;
  1245. PWCHAR pszAddress = NULL, pszMask = NULL;
  1246. do
  1247. {
  1248. // Allocate the new pool
  1249. //
  1250. pPool = (RAS_IPPOOL*) RutlAlloc(sizeof(RAS_IPPOOL), TRUE);
  1251. if (pPool == NULL)
  1252. {
  1253. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  1254. break;
  1255. }
  1256. // Attempt to open the new location
  1257. //
  1258. dwErr = RasIpPoolOpenKeys(
  1259. hkParams,
  1260. FALSE,
  1261. &hkPool);
  1262. // The new location exists -- load in the
  1263. // pool
  1264. if (dwErr == NO_ERROR)
  1265. {
  1266. DWORD i;
  1267. WCHAR pszBuf[16];
  1268. HKEY hkRange = NULL;
  1269. for (i = 0; ;i++)
  1270. {
  1271. _itow(i, pszBuf, 10);
  1272. dwErr = RegOpenKeyEx(
  1273. hkPool,
  1274. pszBuf,
  1275. 0,
  1276. KEY_ALL_ACCESS,
  1277. &hkRange);
  1278. if (dwErr != ERROR_SUCCESS)
  1279. {
  1280. dwErr = NO_ERROR;
  1281. break;
  1282. }
  1283. dwErr = RasIpPoolReadNode(
  1284. pszBuf,
  1285. hkRange,
  1286. (HANDLE)pPool);
  1287. BREAK_ON_DWERR(dwErr);
  1288. }
  1289. BREAK_ON_DWERR(dwErr);
  1290. *ppPool = pPool;
  1291. }
  1292. // The new location does not exist -- use legacy
  1293. // values
  1294. //
  1295. else if (dwErr == ERROR_FILE_NOT_FOUND)
  1296. {
  1297. DWORD dwAddress = 0, dwMask = 0;
  1298. dwErr = RutlRegReadString(hkParams, pszIpAddress, &pszAddress);
  1299. BREAK_ON_DWERR(dwErr);
  1300. dwErr = RutlRegReadString(hkParams, pszIpMask, &pszMask);
  1301. BREAK_ON_DWERR(dwErr);
  1302. dwErr = RasIpConvertRangePszToDword(
  1303. pszAddress,
  1304. pszMask,
  1305. &dwAddress,
  1306. &dwMask);
  1307. BREAK_ON_DWERR(dwErr);
  1308. if (dwAddress != 0)
  1309. {
  1310. dwErr = RasIpPoolAdd(
  1311. pPool,
  1312. dwAddress + 2,
  1313. (dwAddress + ~dwMask) - 1);
  1314. BREAK_ON_DWERR(dwErr);
  1315. }
  1316. *ppPool = pPool;
  1317. }
  1318. } while (FALSE);
  1319. // Cleanup
  1320. {
  1321. if (dwErr != NO_ERROR)
  1322. {
  1323. if (pPool)
  1324. {
  1325. RasIpPoolCleanup(pPool);
  1326. }
  1327. }
  1328. if (hkPool)
  1329. {
  1330. RegCloseKey(hkPool);
  1331. }
  1332. RutlFree(pszAddress);
  1333. RutlFree(pszMask);
  1334. }
  1335. return dwErr;
  1336. }
  1337. //
  1338. // Writes the given ras ip pool to the given server
  1339. //
  1340. DWORD
  1341. RasIpPoolWrite(
  1342. IN HKEY hkParams,
  1343. IN RAS_IPPOOL* pPool)
  1344. {
  1345. DWORD dwErr = NO_ERROR;
  1346. HKEY hkPool = NULL, hkNode = NULL;
  1347. DWORD i, dwDisposition;
  1348. WCHAR pszName[16];
  1349. RAS_IPRANGE_NODE* pNode = pPool->pHead;
  1350. do
  1351. {
  1352. dwErr = RasIpPoolReset(hkParams);
  1353. BREAK_ON_DWERR(dwErr);
  1354. dwErr = RasIpPoolOpenKeys(
  1355. hkParams,
  1356. TRUE,
  1357. &hkPool);
  1358. BREAK_ON_DWERR(dwErr);
  1359. for (i = 0; i < pPool->dwCount; i++, pNode = pNode->pNext)
  1360. {
  1361. _itow(i, pszName, 10);
  1362. dwErr = RegCreateKeyEx(
  1363. hkPool,
  1364. pszName,
  1365. 0,
  1366. NULL,
  1367. REG_OPTION_NON_VOLATILE,
  1368. KEY_ALL_ACCESS,
  1369. NULL,
  1370. &hkNode,
  1371. &dwDisposition);
  1372. if (dwErr != ERROR_SUCCESS)
  1373. {
  1374. continue;
  1375. }
  1376. RegSetValueEx(
  1377. hkNode,
  1378. pszIpFrom,
  1379. 0,
  1380. REG_DWORD,
  1381. (CONST BYTE*)&pNode->dwFrom,
  1382. sizeof(DWORD));
  1383. RegSetValueEx(
  1384. hkNode,
  1385. pszIpTo,
  1386. 0,
  1387. REG_DWORD,
  1388. (CONST BYTE*)&pNode->dwTo,
  1389. sizeof(DWORD));
  1390. }
  1391. } while (FALSE);
  1392. // Cleanup
  1393. {
  1394. if (hkPool)
  1395. {
  1396. RegCloseKey(hkPool);
  1397. }
  1398. }
  1399. return dwErr;
  1400. }
  1401. //
  1402. // Adds a range to a ras ip pool
  1403. //
  1404. DWORD
  1405. RasIpPoolAdd(
  1406. IN OUT RAS_IPPOOL* pPool,
  1407. IN DWORD dwFrom,
  1408. IN DWORD dwTo)
  1409. {
  1410. RAS_IPRANGE_NODE* pNode = NULL;
  1411. DWORD dwErr;
  1412. // Make sure the pool does not overlap
  1413. //
  1414. dwErr = RasIpPoolFind(pPool, dwFrom, dwTo, FALSE, NULL);
  1415. if (dwErr == NO_ERROR)
  1416. {
  1417. return ERROR_CAN_NOT_COMPLETE;
  1418. }
  1419. // Allocate the new node
  1420. //
  1421. pNode = (RAS_IPRANGE_NODE*) RutlAlloc(sizeof(RAS_IPRANGE_NODE), TRUE);
  1422. if (pNode == NULL)
  1423. {
  1424. return ERROR_NOT_ENOUGH_MEMORY;
  1425. }
  1426. pNode->dwFrom = dwFrom;
  1427. pNode->dwTo = dwTo;
  1428. // Add it to the list
  1429. //
  1430. if (pPool->pTail)
  1431. {
  1432. pPool->pTail->pNext = pNode;
  1433. pPool->pTail = pNode;
  1434. }
  1435. else
  1436. {
  1437. pPool->pHead = pPool->pTail = pNode;
  1438. }
  1439. pPool->dwCount++;
  1440. return NO_ERROR;
  1441. }
  1442. //
  1443. // Deletes a range from a ras ip pool
  1444. //
  1445. DWORD
  1446. RasIpPoolDel(
  1447. IN OUT RAS_IPPOOL* pPool,
  1448. IN DWORD dwFrom,
  1449. IN DWORD dwTo)
  1450. {
  1451. RAS_IPRANGE_NODE* pCur = NULL, *pPrev = NULL;
  1452. if (pPool->dwCount == 0)
  1453. {
  1454. return ERROR_NOT_FOUND;
  1455. }
  1456. pCur = pPrev = pPool->pHead;
  1457. if ((pCur->dwFrom == dwFrom) && (pCur->dwTo == dwTo))
  1458. {
  1459. pPool->pHead = pCur->pNext;
  1460. if (pCur == pPool->pTail)
  1461. {
  1462. pPool->pTail = NULL;
  1463. }
  1464. RutlFree(pCur);
  1465. pPool->dwCount--;
  1466. return NO_ERROR;
  1467. }
  1468. for (pCur = pCur->pNext; pCur; pCur = pCur->pNext, pPrev = pPrev->pNext)
  1469. {
  1470. if ((pCur->dwFrom == dwFrom) && (pCur->dwTo == dwTo))
  1471. {
  1472. pPrev->pNext = pCur->pNext;
  1473. if (pCur == pPool->pTail)
  1474. {
  1475. pPool->pTail = pPrev;
  1476. }
  1477. RutlFree(pCur);
  1478. pPool->dwCount--;
  1479. return NO_ERROR;
  1480. }
  1481. }
  1482. return ERROR_NOT_FOUND;
  1483. }
  1484. //
  1485. // Cleans up a config control block
  1486. //
  1487. DWORD
  1488. RasIpCbCleanup(
  1489. IN RASIP_CB* pConfig)
  1490. {
  1491. if (pConfig)
  1492. {
  1493. if (pConfig->pPool)
  1494. {
  1495. RasIpPoolCleanup(pConfig->pPool);
  1496. }
  1497. RutlFree(pConfig);
  1498. }
  1499. return NO_ERROR;
  1500. }
  1501. DWORD
  1502. RasIpPoolCleanup(
  1503. IN RAS_IPPOOL* pPool)
  1504. {
  1505. RAS_IPRANGE_NODE* pNode = NULL;
  1506. if (pPool)
  1507. {
  1508. while (pPool->pHead)
  1509. {
  1510. pNode = pPool->pHead->pNext;
  1511. RutlFree(pPool->pHead);
  1512. pPool->pHead = pNode;
  1513. }
  1514. RutlFree(pPool);
  1515. }
  1516. return NO_ERROR;
  1517. }
  1518. //
  1519. // Creates a default config control block
  1520. //
  1521. DWORD
  1522. RasIpCbCreateDefault(
  1523. OUT RASIP_CB** ppConfig)
  1524. {
  1525. RASIP_CB* pConfig = NULL;
  1526. DWORD dwErr = NO_ERROR;
  1527. do
  1528. {
  1529. pConfig = (RASIP_CB*) RutlAlloc(sizeof(RASIP_CB), TRUE);
  1530. if (pConfig == NULL)
  1531. {
  1532. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  1533. break;
  1534. }
  1535. pConfig->bEnableIn = TRUE;
  1536. pConfig->bAccess = TRUE;
  1537. pConfig->bAuto = TRUE;
  1538. pConfig->pPool = NULL;
  1539. pConfig->bCallerSpec = TRUE;
  1540. *ppConfig = pConfig;
  1541. } while (FALSE);
  1542. // Cleanup
  1543. {
  1544. if (dwErr != NO_ERROR)
  1545. {
  1546. RasIpCbCleanup(pConfig);
  1547. }
  1548. }
  1549. return dwErr;
  1550. }
  1551. //
  1552. // Helper function opens the ras ip config registry key
  1553. //
  1554. DWORD
  1555. RasIpCbOpenRegKeys(
  1556. IN LPCWSTR pszServer,
  1557. OUT HKEY* phKey)
  1558. {
  1559. DWORD dwErr = NO_ERROR;
  1560. WCHAR pszKey[MAX_PATH];
  1561. do
  1562. {
  1563. // Generate the parameters key name
  1564. //
  1565. wsprintfW(
  1566. pszKey,
  1567. L"%s%s",
  1568. pszRemoteAccessParamStub,
  1569. pszIpParams);
  1570. // Open the parameters keys
  1571. //
  1572. dwErr = RegOpenKeyEx(
  1573. g_pServerInfo->hkMachine,
  1574. pszKey,
  1575. 0,
  1576. KEY_READ | KEY_WRITE,
  1577. phKey);
  1578. BREAK_ON_DWERR( dwErr );
  1579. } while (FALSE);
  1580. // Cleanup
  1581. {
  1582. }
  1583. return dwErr;
  1584. }
  1585. //
  1586. // Functions that manipulate RASIP_CB's
  1587. //
  1588. DWORD
  1589. RasIpCbRead(
  1590. IN LPCWSTR pszServer,
  1591. OUT RASIP_CB* pConfig)
  1592. {
  1593. HKEY hkParams = NULL;
  1594. DWORD dwErr = NO_ERROR;
  1595. PWCHAR pszTemp = NULL;
  1596. do
  1597. {
  1598. // Get a handle to the server's registry config
  1599. //
  1600. dwErr = RasIpCbOpenRegKeys(
  1601. pszServer,
  1602. &hkParams);
  1603. BREAK_ON_DWERR( dwErr );
  1604. // Load the params from the registry
  1605. //
  1606. if (pConfig->dwFlags & RASIP_F_EnableIn)
  1607. {
  1608. dwErr = RutlRegReadDword(
  1609. hkParams,
  1610. pszEnableIn,
  1611. &pConfig->bEnableIn);
  1612. BREAK_ON_DWERR( dwErr );
  1613. }
  1614. if (pConfig->dwFlags & RASIP_F_Access)
  1615. {
  1616. dwErr = RutlRegReadDword(
  1617. hkParams,
  1618. pszAllowNetworkAccess,
  1619. &pConfig->bAccess);
  1620. BREAK_ON_DWERR( dwErr );
  1621. }
  1622. if (pConfig->dwFlags & RASIP_F_Auto)
  1623. {
  1624. dwErr = RutlRegReadDword(
  1625. hkParams,
  1626. pszIpUseDhcp,
  1627. &pConfig->bAuto);
  1628. BREAK_ON_DWERR( dwErr );
  1629. }
  1630. if (pConfig->dwFlags & RASIP_F_CallerSpec)
  1631. {
  1632. dwErr = RutlRegReadDword(
  1633. hkParams,
  1634. pszIpClientSpec,
  1635. &pConfig->bCallerSpec);
  1636. BREAK_ON_DWERR( dwErr );
  1637. }
  1638. if (pConfig->dwFlags & RASIP_F_Pool)
  1639. {
  1640. dwErr = RasIpPoolRead(
  1641. hkParams,
  1642. &pConfig->pPool);
  1643. BREAK_ON_DWERR( dwErr );
  1644. }
  1645. } while (FALSE);
  1646. // Cleanup
  1647. {
  1648. if (hkParams)
  1649. {
  1650. RegCloseKey(hkParams);
  1651. }
  1652. }
  1653. return dwErr;
  1654. }
  1655. DWORD
  1656. RasIpCbWrite(
  1657. IN LPCWSTR pszServer,
  1658. IN RASIP_CB* pConfig)
  1659. {
  1660. HKEY hkParams = NULL;
  1661. DWORD dwErr = NO_ERROR;
  1662. do
  1663. {
  1664. // Get a handle to the server's registry config
  1665. //
  1666. dwErr = RasIpCbOpenRegKeys(
  1667. pszServer,
  1668. &hkParams);
  1669. BREAK_ON_DWERR( dwErr );
  1670. // Write out the params to the registry
  1671. //
  1672. if (pConfig->dwFlags & RASIP_F_EnableIn)
  1673. {
  1674. dwErr = RutlRegWriteDword(
  1675. hkParams,
  1676. pszEnableIn,
  1677. pConfig->bEnableIn);
  1678. BREAK_ON_DWERR( dwErr );
  1679. }
  1680. if (pConfig->dwFlags & RASIP_F_Access)
  1681. {
  1682. dwErr = RutlRegWriteDword(
  1683. hkParams,
  1684. pszAllowNetworkAccess,
  1685. pConfig->bAccess);
  1686. BREAK_ON_DWERR( dwErr );
  1687. }
  1688. if (pConfig->dwFlags & RASIP_F_Auto)
  1689. {
  1690. dwErr = RutlRegWriteDword(
  1691. hkParams,
  1692. pszIpUseDhcp,
  1693. pConfig->bAuto);
  1694. BREAK_ON_DWERR( dwErr );
  1695. }
  1696. if (pConfig->dwFlags & RASIP_F_CallerSpec)
  1697. {
  1698. dwErr = RutlRegWriteDword(
  1699. hkParams,
  1700. pszIpClientSpec,
  1701. pConfig->bCallerSpec);
  1702. BREAK_ON_DWERR( dwErr );
  1703. }
  1704. if (pConfig->dwFlags & RASIP_F_Pool)
  1705. {
  1706. dwErr = RasIpPoolWrite(
  1707. hkParams,
  1708. pConfig->pPool);
  1709. BREAK_ON_DWERR( dwErr );
  1710. }
  1711. } while (FALSE);
  1712. // Cleanup
  1713. {
  1714. if (hkParams)
  1715. {
  1716. RegCloseKey(hkParams);
  1717. }
  1718. }
  1719. return dwErr;
  1720. }
  1721. //
  1722. // Set NETBT broadcast based name resolution reg. value
  1723. // dwArgCount - Value to set the registry value to
  1724. // returns NO_ERROR - Success
  1725. // Other - System error code
  1726. //
  1727. // Whistler bug: 359847 Netsh: move broadcastnameresolution from routing ip to
  1728. // ras ip
  1729. //
  1730. DWORD
  1731. RasIpSetNetbtBcast(
  1732. DWORD dwEnable
  1733. )
  1734. {
  1735. DWORD dwResult, dwEnableOld = -1, dwSize = sizeof(DWORD);
  1736. HKEY hkIpcpParam;
  1737. do
  1738. {
  1739. dwResult = RegOpenKeyExW(
  1740. g_pServerInfo->hkMachine,
  1741. L"System\\CurrentControlSet\\Services\\RemoteAccess\\Parameters\\Ip",
  1742. 0,
  1743. KEY_READ | KEY_WRITE,
  1744. &hkIpcpParam
  1745. );
  1746. if(dwResult isnot NO_ERROR)
  1747. {
  1748. break;
  1749. }
  1750. dwResult = RegQueryValueExW(
  1751. hkIpcpParam,
  1752. L"EnableNetbtBcastFwd",
  1753. NULL,
  1754. NULL,
  1755. (PBYTE)&dwEnableOld,
  1756. &dwSize
  1757. );
  1758. if((dwResult is NO_ERROR) and (dwEnable == dwEnableOld))
  1759. {
  1760. break;
  1761. }
  1762. dwResult = RegSetValueExW(
  1763. hkIpcpParam,
  1764. L"EnableNetbtBcastFwd",
  1765. 0,
  1766. REG_DWORD,
  1767. (PBYTE) &dwEnable,
  1768. sizeof( DWORD )
  1769. );
  1770. } while(FALSE);
  1771. if(dwResult is NO_ERROR)
  1772. {
  1773. DisplayMessage(g_hModule, MSG_RASAAAA_MUST_RESTART_SERVICES);
  1774. }
  1775. return dwResult;
  1776. }
  1777. //
  1778. // Whistler bug: 359847 Netsh: move broadcastnameresolution from routing ip to
  1779. // ras ip
  1780. //
  1781. BOOL
  1782. RasIpShowNetbtBcast(
  1783. VOID
  1784. )
  1785. {
  1786. HKEY hkIpcpParam = NULL;
  1787. BOOL bReturn = FALSE;
  1788. DWORD dwResult, dwEnable = -1, dwSize = sizeof(DWORD);
  1789. do
  1790. {
  1791. dwResult = RegOpenKeyExW(
  1792. g_pServerInfo->hkMachine,
  1793. L"System\\CurrentControlSet\\Services\\RemoteAccess\\Parameters\\Ip",
  1794. 0,
  1795. KEY_READ | KEY_WRITE,
  1796. &hkIpcpParam
  1797. );
  1798. if(dwResult isnot NO_ERROR)
  1799. {
  1800. break;
  1801. }
  1802. dwResult = RegQueryValueExW(
  1803. hkIpcpParam,
  1804. L"EnableNetbtBcastFwd",
  1805. NULL,
  1806. NULL,
  1807. (PBYTE)&dwEnable,
  1808. &dwSize
  1809. );
  1810. if(dwResult isnot NO_ERROR)
  1811. {
  1812. break;
  1813. }
  1814. if (dwEnable isnot 0)
  1815. {
  1816. bReturn = TRUE;
  1817. }
  1818. } while(FALSE);
  1819. return bReturn;
  1820. }