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.

1117 lines
27 KiB

  1. /*
  2. File: rasipx.h
  3. The 'remoteaccess ipx' sub context
  4. 3/2/99
  5. */
  6. #include "precomp.h"
  7. #include "rasipx.h"
  8. //
  9. // Local prototypes
  10. //
  11. BOOL
  12. WINAPI
  13. RasIpxCheckVersion(
  14. IN UINT CIMOSType,
  15. IN UINT CIMOSProductSuite,
  16. IN LPCWSTR CIMOSVersion,
  17. IN LPCWSTR CIMOSBuildNumber,
  18. IN LPCWSTR CIMServicePackMajorVersion,
  19. IN LPCWSTR CIMServicePackMinorVersion,
  20. IN UINT CIMProcessorArchitecture,
  21. IN DWORD dwReserved
  22. );
  23. // The guid for this context
  24. //
  25. GUID g_RasIpxGuid = RASIPX_GUID;
  26. static PWCHAR g_pszServer = NULL;
  27. static DWORD g_dwBuild = 0;
  28. // The commands supported in this context
  29. //
  30. CMD_ENTRY g_RasIpxSetCmdTable[] =
  31. {
  32. // Whistler bug 249293, changes for architecture version checking
  33. //
  34. CREATE_CMD_ENTRY(RASIPX_SET_NEGOTIATION,RasIpxHandleSetNegotiation),
  35. CREATE_CMD_ENTRY(RASIPX_SET_ACCESS, RasIpxHandleSetAccess),
  36. CREATE_CMD_ENTRY(RASIPX_SET_ASSIGNMENT, RasIpxHandleSetAssignment),
  37. CREATE_CMD_ENTRY(RASIPX_SET_CALLERSPEC, RasIpxHandleSetCallerSpec),
  38. CREATE_CMD_ENTRY(RASIPX_SET_POOL, RasIpxHandleSetPool),
  39. };
  40. CMD_ENTRY g_RasIpxShowCmdTable[] =
  41. {
  42. // Whistler bug 249293, changes for architecture version checking
  43. //
  44. CREATE_CMD_ENTRY(RASIPX_SHOW_CONFIG, RasIpxHandleShow),
  45. };
  46. CMD_GROUP_ENTRY g_RasIpxCmdGroups[] =
  47. {
  48. CREATE_CMD_GROUP_ENTRY(GROUP_SET, g_RasIpxSetCmdTable),
  49. CREATE_CMD_GROUP_ENTRY(GROUP_SHOW, g_RasIpxShowCmdTable),
  50. };
  51. ULONG g_ulRasIpxNumGroups = sizeof(g_RasIpxCmdGroups)/sizeof(CMD_GROUP_ENTRY);
  52. //
  53. // Flags that control how/what info is read/written
  54. // in the RASIPX_CB structure
  55. //
  56. #define RASIPX_F_EnableIn 0x1
  57. #define RASIPX_F_Access 0x2
  58. #define RASIPX_F_Auto 0x4
  59. #define RASIPX_F_Global 0x8
  60. #define RASIPX_F_FirstNet 0x10
  61. #define RASIPX_F_PoolSize 0x20
  62. #define RASIPX_F_CallerSpec 0x40
  63. #define RASIPX_F_All 0xFFFF
  64. //
  65. // Control block for ras ipx configuration
  66. //
  67. typedef struct _RASIPX_CB
  68. {
  69. DWORD dwFlags; // See RASIPX_F_* values
  70. BOOL bEnableIn;
  71. BOOL bAccess;
  72. BOOL bAuto;
  73. BOOL bGlobal;
  74. BOOL bCallerSpec;
  75. DWORD dwFirstNet;
  76. DWORD dwPoolSize;
  77. } RASIPX_CB;
  78. //
  79. // Ipx specific registry parameters
  80. //
  81. WCHAR pszIpxParams[] = L"Ipx";
  82. WCHAR pszIpxFirstNet[] = L"FirstWanNet";
  83. WCHAR pszIpxPoolSize[] = L"WanNetPoolSize";
  84. WCHAR pszIpxClientSpec[] = L"AcceptRemoteNodeNumber";
  85. WCHAR pszIpxAutoAssign[] = L"AutoWanNetAllocation";
  86. WCHAR pszIpxGlobalWanNet[] = L"GlobalWanNet";
  87. //
  88. // Prototypes of functions that manipulate the
  89. // RASIPX_CB structures
  90. //
  91. DWORD
  92. RasIpxCbCleanup(
  93. IN RASIPX_CB* pConfig);
  94. DWORD
  95. RasIpxCbCreateDefault(
  96. OUT RASIPX_CB** ppConfig);
  97. DWORD
  98. RasIpxCbOpenRegKeys(
  99. IN LPCWSTR pszServer,
  100. OUT HKEY* phKey);
  101. DWORD
  102. RasIpxCbRead(
  103. IN LPCWSTR pszServer,
  104. OUT RASIPX_CB* pConfig);
  105. DWORD
  106. RasIpxCbWrite(
  107. IN LPCWSTR pszServer,
  108. IN RASIPX_CB* pConfig);
  109. PWCHAR
  110. RasIpxuStrFromDword(
  111. IN DWORD dwVal,
  112. IN DWORD dwRadix);
  113. DWORD
  114. RasIpxuDwordFromString(
  115. IN LPCWSTR pszVal,
  116. IN DWORD dwRadix);
  117. //
  118. // Callback determines if a command is valid on a given architecture
  119. //
  120. BOOL
  121. WINAPI
  122. RasIpxCheckVersion(
  123. IN UINT CIMOSType,
  124. IN UINT CIMOSProductSuite,
  125. IN LPCWSTR CIMOSVersion,
  126. IN LPCWSTR CIMOSBuildNumber,
  127. IN LPCWSTR CIMServicePackMajorVersion,
  128. IN LPCWSTR CIMServicePackMinorVersion,
  129. IN UINT CIMProcessorArchitecture,
  130. IN DWORD dwReserved
  131. )
  132. {
  133. // Only available on x86 platforms
  134. //
  135. // Whistler bug 249293, changes for architecture version checking
  136. //
  137. if (CIMProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
  138. {
  139. return TRUE;
  140. }
  141. return FALSE;
  142. }
  143. //
  144. // Entry called by rasmontr to register this context
  145. //
  146. DWORD
  147. WINAPI
  148. RasIpxStartHelper(
  149. IN CONST GUID *pguidParent,
  150. IN DWORD dwVersion)
  151. {
  152. DWORD dwErr = NO_ERROR;
  153. NS_CONTEXT_ATTRIBUTES attMyAttributes;
  154. // Initialize
  155. //
  156. ZeroMemory(&attMyAttributes, sizeof(attMyAttributes));
  157. // Whistler bug 249293, changes for architecture version checking
  158. //
  159. attMyAttributes.pfnOsVersionCheck= RasIpxCheckVersion;
  160. attMyAttributes.pwszContext = L"ipx";
  161. attMyAttributes.guidHelper = g_RasIpxGuid;
  162. attMyAttributes.dwVersion = RASIPX_VERSION;
  163. attMyAttributes.dwFlags = 0;
  164. attMyAttributes.ulNumTopCmds = 0;
  165. attMyAttributes.pTopCmds = NULL;
  166. attMyAttributes.ulNumGroups = g_ulRasIpxNumGroups;
  167. attMyAttributes.pCmdGroups = (CMD_GROUP_ENTRY (*)[])&g_RasIpxCmdGroups;
  168. attMyAttributes.pfnDumpFn = RasIpxDump;
  169. dwErr = RegisterContext( &attMyAttributes );
  170. return dwErr;
  171. }
  172. DWORD
  173. RasIpxDisplayConfig(
  174. IN BOOL bReport)
  175. {
  176. DWORD dwErr = NO_ERROR;
  177. RASIPX_CB* pConfig = NULL;
  178. PWCHAR pszEnableIn = NULL, pszAccess = NULL, pszAssign = NULL, pszCaller = NULL;
  179. PWCHAR pszFirstNet = NULL, pszSize = NULL, pszTemp = NULL;
  180. PWCHAR pszTknAuto = NULL;
  181. do
  182. {
  183. // Get a default config blob
  184. //
  185. dwErr = RasIpxCbCreateDefault(&pConfig);
  186. BREAK_ON_DWERR( dwErr );
  187. // Read in all of the values
  188. //
  189. pConfig->dwFlags = RASIPX_F_All;
  190. dwErr = RasIpxCbRead(g_pszServer, pConfig);
  191. BREAK_ON_DWERR( dwErr );
  192. // Calculate the "auto" token
  193. //
  194. if (pConfig->bAuto)
  195. {
  196. pszTknAuto = (pConfig->bGlobal) ? TOKEN_AUTOSAME : TOKEN_AUTO;
  197. }
  198. else
  199. {
  200. pszTknAuto = (pConfig->bGlobal) ? TOKEN_POOLSAME : TOKEN_POOL;
  201. }
  202. if (bReport)
  203. {
  204. pszEnableIn =
  205. RutlStrDup(pConfig->bEnableIn ? TOKEN_ALLOW : TOKEN_DENY);
  206. pszAccess =
  207. RutlStrDup(pConfig->bAccess ? TOKEN_ALL : TOKEN_SERVERONLY);
  208. pszAssign =
  209. RutlStrDup(pszTknAuto);
  210. pszCaller =
  211. RutlStrDup(pConfig->bCallerSpec ? TOKEN_ALLOW : TOKEN_DENY);
  212. pszFirstNet =
  213. RasIpxuStrFromDword(pConfig->dwFirstNet, 16);
  214. if (pConfig->dwPoolSize == 0)
  215. {
  216. pszSize =
  217. RutlStrDup(TOKEN_DYNAMIC);
  218. }
  219. else
  220. {
  221. pszSize =
  222. RasIpxuStrFromDword(pConfig->dwPoolSize, 10);
  223. }
  224. DisplayMessage(
  225. g_hModule,
  226. MSG_RASIPX_SERVERCONFIG,
  227. g_pszServer,
  228. pszEnableIn,
  229. pszAccess,
  230. pszAssign,
  231. pszCaller,
  232. pszFirstNet,
  233. pszSize);
  234. }
  235. else
  236. {
  237. pszEnableIn = RutlAssignmentFromTokens(
  238. g_hModule,
  239. TOKEN_MODE,
  240. pConfig->bEnableIn ? TOKEN_ALLOW : TOKEN_DENY);
  241. pszAccess = RutlAssignmentFromTokens(
  242. g_hModule,
  243. TOKEN_MODE,
  244. pConfig->bAccess ? TOKEN_ALL : TOKEN_SERVERONLY);
  245. pszAssign = RutlAssignmentFromTokens(
  246. g_hModule,
  247. TOKEN_METHOD,
  248. pszTknAuto);
  249. pszCaller = RutlAssignmentFromTokens(
  250. g_hModule,
  251. TOKEN_MODE,
  252. pConfig->bCallerSpec ? TOKEN_ALLOW : TOKEN_DENY);
  253. pszTemp = RasIpxuStrFromDword(pConfig->dwFirstNet, 16);
  254. pszFirstNet = RutlAssignmentFromTokens(
  255. g_hModule,
  256. TOKEN_FIRSTNET,
  257. pszTemp);
  258. RutlFree(pszTemp);
  259. // Whistler bug 27366 NETSH RAS - ipx set pool will not accept hex
  260. // values, yet ipx dump outputs them as hex
  261. //
  262. pszTemp = RasIpxuStrFromDword(pConfig->dwPoolSize, 10);
  263. pszSize = RutlAssignmentFromTokens(
  264. g_hModule,
  265. TOKEN_SIZE,
  266. pszTemp);
  267. RutlFree(pszTemp);
  268. DisplayMessage(
  269. g_hModule,
  270. MSG_RASIPX_SCRIPTHEADER);
  271. DisplayMessageT(DMP_RASIPX_PUSHD);
  272. DisplayMessage(
  273. g_hModule,
  274. MSG_RASIPX_SET_CMD,
  275. DMP_RASIPX_SET_NEGOTIATION,
  276. pszEnableIn);
  277. DisplayMessage(
  278. g_hModule,
  279. MSG_RASIPX_SET_CMD,
  280. DMP_RASIPX_SET_ACCESS,
  281. pszAccess);
  282. DisplayMessage(
  283. g_hModule,
  284. MSG_RASIPX_SET_CMD,
  285. DMP_RASIPX_SET_CALLERSPEC,
  286. pszCaller);
  287. DisplayMessage(
  288. g_hModule,
  289. MSG_RASIPX_SET_CMD,
  290. DMP_RASIPX_SET_ASSIGNMENT,
  291. pszAssign);
  292. if (! pConfig->bAuto)
  293. {
  294. DisplayMessage(
  295. g_hModule,
  296. MSG_RASIPX_SET_POOL_CMD,
  297. DMP_RASIPX_SET_POOL,
  298. pszFirstNet,
  299. pszSize);
  300. }
  301. DisplayMessageT(DMP_RASIPX_POPD);
  302. DisplayMessage(
  303. g_hModule,
  304. MSG_RASIPX_SCRIPTFOOTER);
  305. }
  306. } while (FALSE);
  307. // Cleanup
  308. {
  309. if (pConfig)
  310. {
  311. RasIpxCbCleanup(pConfig);
  312. }
  313. if (pszEnableIn)
  314. {
  315. RutlFree(pszEnableIn);
  316. }
  317. if (pszAccess)
  318. {
  319. RutlFree(pszAccess);
  320. }
  321. if (pszAssign)
  322. {
  323. RutlFree(pszAssign);
  324. }
  325. if (pszCaller)
  326. {
  327. RutlFree(pszCaller);
  328. }
  329. if (pszFirstNet)
  330. {
  331. RutlFree(pszFirstNet);
  332. }
  333. if (pszSize)
  334. {
  335. RutlFree(pszSize);
  336. }
  337. }
  338. return dwErr;
  339. }
  340. DWORD
  341. WINAPI
  342. RasIpxDump(
  343. IN LPCWSTR pwszRouter,
  344. IN OUT LPWSTR *ppwcArguments,
  345. IN DWORD dwArgCount,
  346. IN LPCVOID pvData
  347. )
  348. {
  349. return RasIpxDisplayConfig(FALSE);
  350. }
  351. DWORD
  352. RasIpxHandleSetAccess(
  353. IN LPCWSTR pwszMachine,
  354. IN OUT LPWSTR *ppwcArguments,
  355. IN DWORD dwCurrentIndex,
  356. IN DWORD dwArgCount,
  357. IN DWORD dwFlags,
  358. IN LPCVOID pvData,
  359. OUT BOOL *pbDone
  360. )
  361. {
  362. DWORD dwErr = NO_ERROR, dwValue = 0;
  363. RASIPX_CB Config;
  364. TOKEN_VALUE rgEnum[] = { {TOKEN_ALL, TRUE}, {TOKEN_SERVERONLY, FALSE} };
  365. RASMON_CMD_ARG pArgs[] =
  366. {
  367. {
  368. RASMONTR_CMD_TYPE_ENUM,
  369. {TOKEN_MODE, TRUE, FALSE},
  370. rgEnum,
  371. sizeof(rgEnum)/sizeof(*rgEnum),
  372. NULL
  373. }
  374. };
  375. do
  376. {
  377. // Parse the command line
  378. //
  379. dwErr = RutlParse(
  380. ppwcArguments,
  381. dwCurrentIndex,
  382. dwArgCount,
  383. pbDone,
  384. pArgs,
  385. sizeof(pArgs)/sizeof(*pArgs));
  386. BREAK_ON_DWERR( dwErr );
  387. dwValue = RASMON_CMD_ARG_GetDword(&pArgs[0]);
  388. // If successful, go ahead and set the info
  389. //
  390. ZeroMemory(&Config, sizeof(Config));
  391. Config.dwFlags = RASIPX_F_Access;
  392. Config.bAccess = dwValue;
  393. dwErr = RasIpxCbWrite(g_pszServer, &Config);
  394. if (dwErr != NO_ERROR)
  395. {
  396. DisplayError(NULL, dwErr);
  397. break;
  398. }
  399. } while (FALSE);
  400. // Cleanup
  401. {
  402. }
  403. return dwErr;
  404. }
  405. DWORD
  406. RasIpxHandleSetAssignment(
  407. IN LPCWSTR pwszMachine,
  408. IN OUT LPWSTR *ppwcArguments,
  409. IN DWORD dwCurrentIndex,
  410. IN DWORD dwArgCount,
  411. IN DWORD dwFlags,
  412. IN LPCVOID pvData,
  413. OUT BOOL *pbDone
  414. )
  415. {
  416. DWORD dwErr = NO_ERROR, dwValue = 0;
  417. RASIPX_CB Config;
  418. TOKEN_VALUE rgEnum[] =
  419. {
  420. {TOKEN_AUTO, 0},
  421. {TOKEN_POOL, 1},
  422. {TOKEN_AUTOSAME, 2},
  423. {TOKEN_POOLSAME, 3}
  424. };
  425. RASMON_CMD_ARG pArgs[] =
  426. {
  427. {
  428. RASMONTR_CMD_TYPE_ENUM,
  429. {TOKEN_METHOD, TRUE, FALSE},
  430. rgEnum,
  431. sizeof(rgEnum)/sizeof(*rgEnum),
  432. NULL
  433. }
  434. };
  435. do
  436. {
  437. // Parse the command line
  438. //
  439. dwErr = RutlParse(
  440. ppwcArguments,
  441. dwCurrentIndex,
  442. dwArgCount,
  443. pbDone,
  444. pArgs,
  445. sizeof(pArgs)/sizeof(*pArgs));
  446. BREAK_ON_DWERR( dwErr );
  447. dwValue = RASMON_CMD_ARG_GetDword(&pArgs[0]);
  448. // If successful, go ahead and set the info
  449. //
  450. ZeroMemory(&Config, sizeof(Config));
  451. Config.dwFlags = RASIPX_F_Auto | RASIPX_F_Global;
  452. switch (dwValue)
  453. {
  454. case 0:
  455. Config.bAuto = TRUE;
  456. Config.bGlobal = FALSE;
  457. break;
  458. case 1:
  459. Config.bAuto = FALSE;
  460. Config.bGlobal = FALSE;
  461. break;
  462. case 2:
  463. Config.bAuto = TRUE;
  464. Config.bGlobal = TRUE;
  465. break;
  466. case 3:
  467. Config.bAuto = FALSE;
  468. Config.bGlobal = TRUE;
  469. break;
  470. }
  471. dwErr = RasIpxCbWrite(g_pszServer, &Config);
  472. if (dwErr != NO_ERROR)
  473. {
  474. DisplayError(NULL, dwErr);
  475. break;
  476. }
  477. } while (FALSE);
  478. // Cleanup
  479. {
  480. }
  481. return dwErr;
  482. }
  483. DWORD
  484. RasIpxHandleSetCallerSpec(
  485. IN LPCWSTR pwszMachine,
  486. IN OUT LPWSTR *ppwcArguments,
  487. IN DWORD dwCurrentIndex,
  488. IN DWORD dwArgCount,
  489. IN DWORD dwFlags,
  490. IN LPCVOID pvData,
  491. OUT BOOL *pbDone
  492. )
  493. {
  494. DWORD dwErr = NO_ERROR, dwValue = 0;
  495. RASIPX_CB Config;
  496. TOKEN_VALUE rgEnum[] = { {TOKEN_ALLOW, TRUE}, {TOKEN_DENY, FALSE} };
  497. RASMON_CMD_ARG pArgs[] =
  498. {
  499. {
  500. RASMONTR_CMD_TYPE_ENUM,
  501. {TOKEN_MODE, TRUE, FALSE},
  502. rgEnum,
  503. sizeof(rgEnum)/sizeof(*rgEnum),
  504. NULL
  505. }
  506. };
  507. do
  508. {
  509. // Parse the command line
  510. //
  511. dwErr = RutlParse(
  512. ppwcArguments,
  513. dwCurrentIndex,
  514. dwArgCount,
  515. pbDone,
  516. pArgs,
  517. sizeof(pArgs)/sizeof(*pArgs));
  518. BREAK_ON_DWERR( dwErr );
  519. dwValue = RASMON_CMD_ARG_GetDword(&pArgs[0]);
  520. // If successful, go ahead and set the info
  521. //
  522. ZeroMemory(&Config, sizeof(Config));
  523. Config.dwFlags = RASIPX_F_CallerSpec;
  524. Config.bCallerSpec = dwValue;
  525. dwErr = RasIpxCbWrite(g_pszServer, &Config);
  526. if (dwErr != NO_ERROR)
  527. {
  528. DisplayError(NULL, dwErr);
  529. break;
  530. }
  531. } while (FALSE);
  532. // Cleanup
  533. {
  534. }
  535. return dwErr;
  536. }
  537. DWORD
  538. RasIpxHandleSetNegotiation(
  539. IN LPCWSTR pwszMachine,
  540. IN OUT LPWSTR *ppwcArguments,
  541. IN DWORD dwCurrentIndex,
  542. IN DWORD dwArgCount,
  543. IN DWORD dwFlags,
  544. IN LPCVOID pvData,
  545. OUT BOOL *pbDone
  546. )
  547. {
  548. DWORD dwErr = NO_ERROR, dwValue = 0;
  549. RASIPX_CB Config;
  550. TOKEN_VALUE rgEnum[] = { {TOKEN_ALLOW, TRUE}, {TOKEN_DENY, FALSE} };
  551. RASMON_CMD_ARG pArgs[] =
  552. {
  553. {
  554. RASMONTR_CMD_TYPE_ENUM,
  555. {TOKEN_MODE, TRUE, FALSE},
  556. rgEnum,
  557. sizeof(rgEnum)/sizeof(*rgEnum),
  558. NULL
  559. }
  560. };
  561. do
  562. {
  563. // Parse the command line
  564. //
  565. dwErr = RutlParse(
  566. ppwcArguments,
  567. dwCurrentIndex,
  568. dwArgCount,
  569. pbDone,
  570. pArgs,
  571. sizeof(pArgs)/sizeof(*pArgs));
  572. BREAK_ON_DWERR( dwErr );
  573. dwValue = RASMON_CMD_ARG_GetDword(&pArgs[0]);
  574. // If successful, go ahead and set the info
  575. //
  576. ZeroMemory(&Config, sizeof(Config));
  577. Config.dwFlags = RASIPX_F_EnableIn;
  578. Config.bEnableIn = dwValue;
  579. dwErr = RasIpxCbWrite(g_pszServer, &Config);
  580. if (dwErr != NO_ERROR)
  581. {
  582. DisplayError(NULL, dwErr);
  583. break;
  584. }
  585. } while (FALSE);
  586. // Cleanup
  587. {
  588. }
  589. return dwErr;
  590. }
  591. DWORD
  592. RasIpxHandleSetPool(
  593. IN LPCWSTR pwszMachine,
  594. IN OUT LPWSTR *ppwcArguments,
  595. IN DWORD dwCurrentIndex,
  596. IN DWORD dwArgCount,
  597. IN DWORD dwFlags,
  598. IN LPCVOID pvData,
  599. OUT BOOL *pbDone
  600. )
  601. {
  602. DWORD dwErr = NO_ERROR, i;
  603. RASIPX_CB Config;
  604. RASMON_CMD_ARG pArgs[] =
  605. {
  606. {
  607. RASMONTR_CMD_TYPE_STRING,
  608. {TOKEN_FIRSTNET, TRUE, FALSE},
  609. NULL,
  610. 0,
  611. NULL
  612. },
  613. {
  614. RASMONTR_CMD_TYPE_STRING,
  615. {TOKEN_SIZE, TRUE, FALSE},
  616. NULL,
  617. 0,
  618. NULL
  619. }
  620. };
  621. PWCHAR pszPool = NULL, pszSize = NULL;
  622. do
  623. {
  624. // Parse the command line
  625. //
  626. dwErr = RutlParse(
  627. ppwcArguments,
  628. dwCurrentIndex,
  629. dwArgCount,
  630. pbDone,
  631. pArgs,
  632. sizeof(pArgs)/sizeof(*pArgs));
  633. BREAK_ON_DWERR( dwErr );
  634. pszPool = RASMON_CMD_ARG_GetPsz(&pArgs[0]);
  635. pszSize = RASMON_CMD_ARG_GetPsz(&pArgs[1]);
  636. // Initialize
  637. //
  638. ZeroMemory(&Config, sizeof(Config));
  639. // The address
  640. //
  641. if (pszPool)
  642. {
  643. Config.dwFlags |= RASIPX_F_FirstNet;
  644. Config.dwFirstNet = RasIpxuDwordFromString(pszPool, 16);
  645. if ((Config.dwFirstNet == 0) ||
  646. (Config.dwFirstNet == 1) ||
  647. (Config.dwFirstNet == 0xffffffff))
  648. {
  649. DisplayMessage(g_hModule, EMSG_RASIPX_BAD_IPX);
  650. dwErr = ERROR_CAN_NOT_COMPLETE;
  651. break;
  652. }
  653. }
  654. // The size
  655. //
  656. if (pszSize)
  657. {
  658. Config.dwFlags |= RASIPX_F_PoolSize;
  659. Config.dwPoolSize = RasIpxuDwordFromString(pszSize, 10);
  660. if (Config.dwPoolSize > 64000)
  661. {
  662. DisplayMessage(g_hModule, EMSG_RASIPX_BAD_POOLSIZE);
  663. dwErr = ERROR_CAN_NOT_COMPLETE;
  664. break;
  665. }
  666. }
  667. // Commit the change to the pool
  668. //
  669. dwErr = RasIpxCbWrite(g_pszServer, &Config);
  670. if (dwErr != NO_ERROR)
  671. {
  672. DisplayError(NULL, dwErr);
  673. break;
  674. }
  675. } while (FALSE);
  676. // Cleanup
  677. {
  678. RutlFree(pszPool);
  679. RutlFree(pszSize);
  680. }
  681. return dwErr;
  682. }
  683. DWORD
  684. RasIpxHandleShow(
  685. IN LPCWSTR pwszMachine,
  686. IN OUT LPWSTR *ppwcArguments,
  687. IN DWORD dwCurrentIndex,
  688. IN DWORD dwArgCount,
  689. IN DWORD dwFlags,
  690. IN LPCVOID pvData,
  691. OUT BOOL *pbDone
  692. )
  693. {
  694. DWORD dwNumArgs = dwArgCount - dwCurrentIndex;
  695. // Check that the number of arguments is correct
  696. //
  697. if (dwNumArgs > 0)
  698. {
  699. DisplayMessage(
  700. g_hModule,
  701. HLP_RASIPX_SHOW_CONFIG_EX,
  702. DMP_RASIPX_SHOW_CONFIG);
  703. return NO_ERROR;
  704. }
  705. return RasIpxDisplayConfig(TRUE);
  706. }
  707. //
  708. // Cleans up a config control block
  709. //
  710. DWORD
  711. RasIpxCbCleanup(
  712. IN RASIPX_CB* pConfig)
  713. {
  714. if (pConfig)
  715. {
  716. RutlFree(pConfig);
  717. }
  718. return NO_ERROR;
  719. }
  720. //
  721. // Creates a default config control block
  722. //
  723. DWORD
  724. RasIpxCbCreateDefault(
  725. OUT RASIPX_CB** ppConfig)
  726. {
  727. RASIPX_CB* pConfig = NULL;
  728. DWORD dwErr = NO_ERROR;
  729. do
  730. {
  731. pConfig = (RASIPX_CB*) RutlAlloc(sizeof(RASIPX_CB), TRUE);
  732. if (pConfig == NULL)
  733. {
  734. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  735. break;
  736. }
  737. pConfig->bEnableIn = TRUE;
  738. pConfig->bAccess = TRUE;
  739. pConfig->bAuto = TRUE;
  740. pConfig->dwFirstNet = 0;
  741. pConfig->dwPoolSize = 0;
  742. pConfig->bGlobal = TRUE;
  743. pConfig->bCallerSpec = TRUE;
  744. *ppConfig = pConfig;
  745. } while (FALSE);
  746. // Cleanup
  747. {
  748. if (dwErr != NO_ERROR)
  749. {
  750. RasIpxCbCleanup(pConfig);
  751. }
  752. }
  753. return dwErr;
  754. }
  755. //
  756. // Helper function opens the ras ipx config registry key
  757. //
  758. DWORD
  759. RasIpxCbOpenRegKeys(
  760. IN LPCWSTR pszServer,
  761. OUT HKEY* phKey)
  762. {
  763. DWORD dwErr = NO_ERROR;
  764. WCHAR pszKey[MAX_PATH];
  765. do
  766. {
  767. // Generate the parameters key name
  768. //
  769. wsprintfW(
  770. pszKey,
  771. L"%s%s",
  772. pszRemoteAccessParamStub,
  773. pszIpxParams);
  774. // Open the parameters keys
  775. //
  776. dwErr = RegOpenKeyEx(
  777. g_pServerInfo->hkMachine,
  778. pszKey,
  779. 0,
  780. KEY_READ | KEY_WRITE,
  781. phKey);
  782. BREAK_ON_DWERR( dwErr );
  783. } while (FALSE);
  784. // Cleanup
  785. {
  786. }
  787. return dwErr;
  788. }
  789. //
  790. // Functions that manipulate RASIPX_CB's
  791. //
  792. DWORD
  793. RasIpxCbRead(
  794. IN LPCWSTR pszServer,
  795. OUT RASIPX_CB* pConfig)
  796. {
  797. HKEY hkParams = NULL;
  798. DWORD dwErr = NO_ERROR;
  799. do
  800. {
  801. // Get a handle to the server's registry config
  802. //
  803. dwErr = RasIpxCbOpenRegKeys(
  804. pszServer,
  805. &hkParams);
  806. BREAK_ON_DWERR( dwErr );
  807. // Load the params from the registry
  808. //
  809. if (pConfig->dwFlags & RASIPX_F_EnableIn)
  810. {
  811. dwErr = RutlRegReadDword(
  812. hkParams,
  813. pszEnableIn,
  814. &pConfig->bEnableIn);
  815. BREAK_ON_DWERR( dwErr );
  816. }
  817. if (pConfig->dwFlags & RASIPX_F_Access)
  818. {
  819. dwErr = RutlRegReadDword(
  820. hkParams,
  821. pszAllowNetworkAccess,
  822. &pConfig->bAccess);
  823. BREAK_ON_DWERR( dwErr );
  824. }
  825. if (pConfig->dwFlags & RASIPX_F_Auto)
  826. {
  827. dwErr = RutlRegReadDword(
  828. hkParams,
  829. pszIpxAutoAssign,
  830. &pConfig->bAuto);
  831. BREAK_ON_DWERR( dwErr );
  832. }
  833. if (pConfig->dwFlags & RASIPX_F_Global)
  834. {
  835. dwErr = RutlRegReadDword(
  836. hkParams,
  837. pszIpxGlobalWanNet,
  838. &pConfig->bGlobal);
  839. BREAK_ON_DWERR( dwErr );
  840. }
  841. if (pConfig->dwFlags & RASIPX_F_CallerSpec)
  842. {
  843. dwErr = RutlRegReadDword(
  844. hkParams,
  845. pszIpxClientSpec,
  846. &pConfig->bCallerSpec);
  847. BREAK_ON_DWERR( dwErr );
  848. }
  849. if (pConfig->dwFlags & RASIPX_F_FirstNet)
  850. {
  851. dwErr = RutlRegReadDword(
  852. hkParams,
  853. pszIpxFirstNet,
  854. &pConfig->dwFirstNet);
  855. BREAK_ON_DWERR( dwErr );
  856. }
  857. if (pConfig->dwFlags & RASIPX_F_PoolSize)
  858. {
  859. dwErr = RutlRegReadDword(
  860. hkParams,
  861. pszIpxPoolSize,
  862. &pConfig->dwPoolSize);
  863. BREAK_ON_DWERR( dwErr );
  864. }
  865. } while (FALSE);
  866. // Cleanup
  867. {
  868. if (hkParams)
  869. {
  870. RegCloseKey(hkParams);
  871. }
  872. }
  873. return dwErr;
  874. }
  875. DWORD
  876. RasIpxCbWrite(
  877. IN LPCWSTR pszServer,
  878. IN RASIPX_CB* pConfig)
  879. {
  880. HKEY hkParams = NULL;
  881. DWORD dwErr = NO_ERROR;
  882. do
  883. {
  884. // Get a handle to the server's registry config
  885. //
  886. dwErr = RasIpxCbOpenRegKeys(
  887. pszServer,
  888. &hkParams);
  889. BREAK_ON_DWERR( dwErr );
  890. // Write out the params to the registry
  891. //
  892. if (pConfig->dwFlags & RASIPX_F_EnableIn)
  893. {
  894. dwErr = RutlRegWriteDword(
  895. hkParams,
  896. pszEnableIn,
  897. pConfig->bEnableIn);
  898. BREAK_ON_DWERR( dwErr );
  899. }
  900. if (pConfig->dwFlags & RASIPX_F_Access)
  901. {
  902. dwErr = RutlRegWriteDword(
  903. hkParams,
  904. pszAllowNetworkAccess,
  905. pConfig->bAccess);
  906. BREAK_ON_DWERR( dwErr );
  907. }
  908. if (pConfig->dwFlags & RASIPX_F_Auto)
  909. {
  910. dwErr = RutlRegWriteDword(
  911. hkParams,
  912. pszIpxAutoAssign,
  913. pConfig->bAuto);
  914. BREAK_ON_DWERR( dwErr );
  915. }
  916. if (pConfig->dwFlags & RASIPX_F_Global)
  917. {
  918. dwErr = RutlRegWriteDword(
  919. hkParams,
  920. pszIpxGlobalWanNet,
  921. pConfig->bGlobal);
  922. BREAK_ON_DWERR( dwErr );
  923. }
  924. if (pConfig->dwFlags & RASIPX_F_CallerSpec)
  925. {
  926. dwErr = RutlRegWriteDword(
  927. hkParams,
  928. pszIpxClientSpec,
  929. pConfig->bCallerSpec);
  930. BREAK_ON_DWERR( dwErr );
  931. }
  932. if (pConfig->dwFlags & RASIPX_F_FirstNet)
  933. {
  934. dwErr = RutlRegWriteDword(
  935. hkParams,
  936. pszIpxFirstNet,
  937. pConfig->dwFirstNet);
  938. BREAK_ON_DWERR( dwErr );
  939. }
  940. if (pConfig->dwFlags & RASIPX_F_PoolSize)
  941. {
  942. dwErr = RutlRegWriteDword(
  943. hkParams,
  944. pszIpxPoolSize,
  945. pConfig->dwPoolSize);
  946. BREAK_ON_DWERR( dwErr );
  947. }
  948. } while (FALSE);
  949. // Cleanup
  950. {
  951. if (hkParams)
  952. {
  953. RegCloseKey(hkParams);
  954. }
  955. }
  956. return dwErr;
  957. }
  958. PWCHAR
  959. RasIpxuStrFromDword(
  960. IN DWORD dwVal,
  961. IN DWORD dwRadix)
  962. {
  963. WCHAR pszBuf[64];
  964. pszBuf[0] = 0;
  965. _itow(dwVal, pszBuf, dwRadix);
  966. return RutlStrDup(pszBuf);
  967. }
  968. DWORD
  969. RasIpxuDwordFromString(
  970. IN LPCWSTR pszVal,
  971. IN DWORD dwRadix)
  972. {
  973. return wcstoul(pszVal, NULL, dwRadix);
  974. }