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.

568 lines
12 KiB

  1. /*
  2. File: rasat.h
  3. The 'remoteaccess at' sub context
  4. 3/2/99
  5. */
  6. #include "precomp.h"
  7. #include "rasat.h"
  8. // The guid for this context
  9. //
  10. GUID g_RasAtGuid = RASAT_GUID;
  11. static PWCHAR g_pszServer = NULL;
  12. static DWORD g_dwBuild = 0;
  13. // The commands supported in this context
  14. //
  15. CMD_ENTRY g_RasAtSetCmdTable[] =
  16. {
  17. CREATE_CMD_ENTRY(RASAT_SET_NEGOTIATION,RasAtHandleSetNegotiation),
  18. CREATE_CMD_ENTRY(RASAT_SET_ACCESS, RasAtHandleSetAccess),
  19. };
  20. CMD_ENTRY g_RasAtShowCmdTable[] =
  21. {
  22. CREATE_CMD_ENTRY(RASAT_SHOW_CONFIG, RasAtHandleShow),
  23. };
  24. CMD_GROUP_ENTRY g_RasAtCmdGroups[] =
  25. {
  26. CREATE_CMD_GROUP_ENTRY(GROUP_SET, g_RasAtSetCmdTable),
  27. CREATE_CMD_GROUP_ENTRY(GROUP_SHOW, g_RasAtShowCmdTable),
  28. };
  29. ULONG g_ulRasAtNumGroups = sizeof(g_RasAtCmdGroups)/sizeof(CMD_GROUP_ENTRY);
  30. //
  31. // Flags that control how/what info is read/written
  32. // in the RASAT_CB structure
  33. //
  34. #define RASAT_F_EnableIn 0x1
  35. #define RASAT_F_Access 0x2
  36. #define RASAT_F_All 0xFFFF
  37. //
  38. // Control block for remoteaccess at configuration
  39. //
  40. typedef struct _RASAT_CB
  41. {
  42. DWORD dwFlags; // See RASAT_F_* values
  43. BOOL bEnableIn;
  44. BOOL bAccess;
  45. } RASAT_CB;
  46. //
  47. // At specific registry parameters
  48. //
  49. WCHAR pszAtParams[] = L"AppleTalk";
  50. WCHAR pszAtNetworkAccess[] = L"NetworkAccess";
  51. //
  52. // Prototypes of functions that manipulate the
  53. // RASAT_CB structures
  54. //
  55. DWORD
  56. RasAtCbCleanup(
  57. IN RASAT_CB* pConfig);
  58. DWORD
  59. RasAtCbCreateDefault(
  60. OUT RASAT_CB** ppConfig);
  61. DWORD
  62. RasAtCbOpenRegKeys(
  63. IN LPCWSTR pszServer,
  64. OUT HKEY* phKey);
  65. DWORD
  66. RasAtCbRead(
  67. IN LPCWSTR pszServer,
  68. OUT RASAT_CB* pConfig);
  69. DWORD
  70. RasAtCbWrite(
  71. IN LPCWSTR pszServer,
  72. IN RASAT_CB* pConfig);
  73. //
  74. // Entry called by rasmontr to register this context
  75. //
  76. DWORD
  77. WINAPI
  78. RasAtStartHelper(
  79. IN CONST GUID *pguidParent,
  80. IN DWORD dwVersion)
  81. {
  82. DWORD dwErr = NO_ERROR;
  83. NS_CONTEXT_ATTRIBUTES attMyAttributes;
  84. // Initialize
  85. //
  86. ZeroMemory(&attMyAttributes, sizeof(attMyAttributes));
  87. attMyAttributes.pwszContext = L"appletalk";
  88. attMyAttributes.guidHelper = g_RasAtGuid;
  89. attMyAttributes.dwVersion = RASAT_VERSION;
  90. attMyAttributes.dwFlags = 0;
  91. attMyAttributes.ulNumTopCmds= 0;
  92. attMyAttributes.pTopCmds = NULL;
  93. attMyAttributes.ulNumGroups = g_ulRasAtNumGroups;
  94. attMyAttributes.pCmdGroups = (CMD_GROUP_ENTRY (*)[])&g_RasAtCmdGroups;
  95. attMyAttributes.pfnDumpFn = RasAtDump;
  96. dwErr = RegisterContext( &attMyAttributes );
  97. return dwErr;
  98. }
  99. DWORD
  100. RasAtDisplayConfig(
  101. IN BOOL bReport)
  102. {
  103. DWORD dwErr = NO_ERROR;
  104. RASAT_CB* pConfig = NULL;
  105. PWCHAR pszEnableIn = NULL, pszAccess = NULL;
  106. do
  107. {
  108. // Get a default config blob
  109. //
  110. dwErr = RasAtCbCreateDefault(&pConfig);
  111. BREAK_ON_DWERR( dwErr );
  112. // Read in all of the values
  113. //
  114. pConfig->dwFlags = RASAT_F_All;
  115. dwErr = RasAtCbRead(g_pszServer, pConfig);
  116. BREAK_ON_DWERR( dwErr );
  117. if (bReport)
  118. {
  119. pszEnableIn =
  120. RutlStrDup(pConfig->bEnableIn ? TOKEN_ALLOW : TOKEN_DENY);
  121. pszAccess =
  122. RutlStrDup(pConfig->bAccess ? TOKEN_ALL : TOKEN_SERVERONLY);
  123. DisplayMessage(
  124. g_hModule,
  125. MSG_RASAT_SERVERCONFIG,
  126. g_pszServer,
  127. pszEnableIn,
  128. pszAccess);
  129. }
  130. else
  131. {
  132. pszEnableIn = RutlAssignmentFromTokens(
  133. g_hModule,
  134. TOKEN_MODE,
  135. pConfig->bEnableIn ? TOKEN_ALLOW : TOKEN_DENY);
  136. pszAccess = RutlAssignmentFromTokens(
  137. g_hModule,
  138. TOKEN_MODE,
  139. pConfig->bAccess ? TOKEN_ALL : TOKEN_SERVERONLY);
  140. DisplayMessage(
  141. g_hModule,
  142. MSG_RASAT_SCRIPTHEADER);
  143. DisplayMessageT(DMP_RASAT_PUSHD);
  144. DisplayMessage(
  145. g_hModule,
  146. MSG_RASAT_SET_CMD,
  147. DMP_RASAT_SET_NEGOTIATION,
  148. pszEnableIn);
  149. DisplayMessage(
  150. g_hModule,
  151. MSG_RASAT_SET_CMD,
  152. DMP_RASAT_SET_ACCESS,
  153. pszAccess);
  154. DisplayMessageT(DMP_RASAT_POPD);
  155. DisplayMessage(
  156. g_hModule,
  157. MSG_RASAT_SCRIPTFOOTER);
  158. }
  159. } while (FALSE);
  160. // Cleanup
  161. {
  162. if (pConfig)
  163. {
  164. RasAtCbCleanup(pConfig);
  165. }
  166. if (pszEnableIn)
  167. {
  168. RutlFree(pszEnableIn);
  169. }
  170. if (pszAccess)
  171. {
  172. RutlFree(pszAccess);
  173. }
  174. }
  175. return dwErr;
  176. }
  177. DWORD
  178. WINAPI
  179. RasAtDump(
  180. IN LPCWSTR pwszRouter,
  181. IN OUT LPWSTR *ppwcArguments,
  182. IN DWORD dwArgCount,
  183. IN LPCVOID pvData
  184. )
  185. {
  186. return RasAtDisplayConfig(FALSE);
  187. }
  188. DWORD
  189. RasAtHandleSetAccess(
  190. IN LPCWSTR pwszMachine,
  191. IN OUT LPWSTR *ppwcArguments,
  192. IN DWORD dwCurrentIndex,
  193. IN DWORD dwArgCount,
  194. IN DWORD dwFlags,
  195. IN LPCVOID pvData,
  196. OUT BOOL *pbDone
  197. )
  198. {
  199. DWORD dwErr = NO_ERROR, dwValue = 0;
  200. RASAT_CB Config;
  201. TOKEN_VALUE rgEnum[] = { {TOKEN_ALL, TRUE}, {TOKEN_SERVERONLY, FALSE} };
  202. RASMON_CMD_ARG pArgs[] =
  203. {
  204. {
  205. RASMONTR_CMD_TYPE_ENUM,
  206. {TOKEN_MODE, TRUE, FALSE},
  207. rgEnum,
  208. sizeof(rgEnum)/sizeof(*rgEnum),
  209. NULL
  210. }
  211. };
  212. do
  213. {
  214. // Parse the command line
  215. //
  216. dwErr = RutlParse(
  217. ppwcArguments,
  218. dwCurrentIndex,
  219. dwArgCount,
  220. pbDone,
  221. pArgs,
  222. sizeof(pArgs)/sizeof(*pArgs));
  223. BREAK_ON_DWERR( dwErr );
  224. dwValue = RASMON_CMD_ARG_GetDword(&pArgs[0]);
  225. // If successful, go ahead and set the info
  226. //
  227. ZeroMemory(&Config, sizeof(Config));
  228. Config.dwFlags = RASAT_F_Access;
  229. Config.bAccess = dwValue;
  230. dwErr = RasAtCbWrite(g_pszServer, &Config);
  231. if (dwErr != NO_ERROR)
  232. {
  233. DisplayError(NULL, dwErr);
  234. break;
  235. }
  236. } while (FALSE);
  237. // Cleanup
  238. {
  239. }
  240. return dwErr;
  241. }
  242. DWORD
  243. RasAtHandleSetNegotiation(
  244. IN LPCWSTR pwszMachine,
  245. IN OUT LPWSTR *ppwcArguments,
  246. IN DWORD dwCurrentIndex,
  247. IN DWORD dwArgCount,
  248. IN DWORD dwFlags,
  249. IN LPCVOID pvData,
  250. OUT BOOL *pbDone
  251. )
  252. {
  253. DWORD dwErr = NO_ERROR, dwValue = 0;
  254. RASAT_CB Config;
  255. TOKEN_VALUE rgEnum[] = { {TOKEN_ALLOW, TRUE}, {TOKEN_DENY, FALSE} };
  256. RASMON_CMD_ARG pArgs[] =
  257. {
  258. {
  259. RASMONTR_CMD_TYPE_ENUM,
  260. {TOKEN_MODE, TRUE, FALSE},
  261. rgEnum,
  262. sizeof(rgEnum)/sizeof(*rgEnum),
  263. NULL
  264. }
  265. };
  266. do
  267. {
  268. // Parse the command line
  269. //
  270. dwErr = RutlParse(
  271. ppwcArguments,
  272. dwCurrentIndex,
  273. dwArgCount,
  274. pbDone,
  275. pArgs,
  276. sizeof(pArgs)/sizeof(*pArgs));
  277. BREAK_ON_DWERR( dwErr );
  278. dwValue = RASMON_CMD_ARG_GetDword(&pArgs[0]);
  279. // If successful, go ahead and set the info
  280. //
  281. ZeroMemory(&Config, sizeof(Config));
  282. Config.dwFlags = RASAT_F_EnableIn;
  283. Config.bEnableIn = dwValue;
  284. dwErr = RasAtCbWrite(g_pszServer, &Config);
  285. if (dwErr != NO_ERROR)
  286. {
  287. DisplayError(NULL, dwErr);
  288. break;
  289. }
  290. } while (FALSE);
  291. // Cleanup
  292. {
  293. }
  294. return dwErr;
  295. }
  296. DWORD
  297. RasAtHandleShow(
  298. IN LPCWSTR pwszMachine,
  299. IN OUT LPWSTR *ppwcArguments,
  300. IN DWORD dwCurrentIndex,
  301. IN DWORD dwArgCount,
  302. IN DWORD dwFlags,
  303. IN LPCVOID pvData,
  304. OUT BOOL *pbDone
  305. )
  306. {
  307. DWORD dwNumArgs = dwArgCount - dwCurrentIndex;
  308. // Check that the number of arguments is correct
  309. //
  310. if (dwNumArgs > 0)
  311. {
  312. DisplayMessage(
  313. g_hModule,
  314. HLP_RASAT_SHOW_CONFIG_EX,
  315. DMP_RASAT_SHOW_CONFIG);
  316. return NO_ERROR;
  317. }
  318. return RasAtDisplayConfig(TRUE);
  319. }
  320. //
  321. // Cleans up a config control block
  322. //
  323. DWORD
  324. RasAtCbCleanup(
  325. IN RASAT_CB* pConfig)
  326. {
  327. if (pConfig)
  328. {
  329. RutlFree(pConfig);
  330. }
  331. return NO_ERROR;
  332. }
  333. //
  334. // Creates a default config control block
  335. //
  336. DWORD
  337. RasAtCbCreateDefault(
  338. OUT RASAT_CB** ppConfig)
  339. {
  340. RASAT_CB* pConfig = NULL;
  341. DWORD dwErr = NO_ERROR;
  342. do
  343. {
  344. pConfig = (RASAT_CB*) RutlAlloc(sizeof(RASAT_CB), TRUE);
  345. if (pConfig == NULL)
  346. {
  347. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  348. break;
  349. }
  350. pConfig->bEnableIn = TRUE;
  351. pConfig->bAccess = TRUE;
  352. *ppConfig = pConfig;
  353. } while (FALSE);
  354. // Cleanup
  355. {
  356. if (dwErr != NO_ERROR)
  357. {
  358. RasAtCbCleanup(pConfig);
  359. }
  360. }
  361. return dwErr;
  362. }
  363. //
  364. // Helper function opens the remoteaccess at config registry key
  365. //
  366. DWORD
  367. RasAtCbOpenRegKeys(
  368. IN LPCWSTR pszServer,
  369. OUT HKEY* phKey)
  370. {
  371. DWORD dwErr = NO_ERROR;
  372. WCHAR pszKey[MAX_PATH];
  373. do
  374. {
  375. // Generate the parameters key name
  376. //
  377. wsprintfW(
  378. pszKey,
  379. L"%s%s",
  380. pszRemoteAccessParamStub,
  381. pszAtParams);
  382. // Open the parameters keys
  383. //
  384. dwErr = RegOpenKeyEx(
  385. g_pServerInfo->hkMachine,
  386. pszKey,
  387. 0,
  388. KEY_READ | KEY_WRITE,
  389. phKey);
  390. BREAK_ON_DWERR( dwErr );
  391. } while (FALSE);
  392. return dwErr;
  393. }
  394. //
  395. // Functions that manipulate RASAT_CB's
  396. //
  397. DWORD
  398. RasAtCbRead(
  399. IN LPCWSTR pszServer,
  400. OUT RASAT_CB* pConfig)
  401. {
  402. HKEY hkParams = NULL;
  403. DWORD dwErr = NO_ERROR;
  404. do
  405. {
  406. // Get a handle to the server's registry config
  407. //
  408. dwErr = RasAtCbOpenRegKeys(
  409. pszServer,
  410. &hkParams);
  411. BREAK_ON_DWERR( dwErr );
  412. // Load the params from the registry
  413. //
  414. if (pConfig->dwFlags & RASAT_F_EnableIn)
  415. {
  416. dwErr = RutlRegReadDword(
  417. hkParams,
  418. pszEnableIn,
  419. &pConfig->bEnableIn);
  420. BREAK_ON_DWERR( dwErr );
  421. }
  422. if (pConfig->dwFlags & RASAT_F_Access)
  423. {
  424. dwErr = RutlRegReadDword(
  425. hkParams,
  426. pszAtNetworkAccess,
  427. &pConfig->bAccess);
  428. BREAK_ON_DWERR( dwErr );
  429. }
  430. } while (FALSE);
  431. // Cleanup
  432. {
  433. if (hkParams)
  434. {
  435. RegCloseKey(hkParams);
  436. }
  437. }
  438. return dwErr;
  439. }
  440. DWORD
  441. RasAtCbWrite(
  442. IN LPCWSTR pszServer,
  443. IN RASAT_CB* pConfig)
  444. {
  445. HKEY hkParams = NULL;
  446. DWORD dwErr = NO_ERROR;
  447. do
  448. {
  449. // Get a handle to the server's registry config
  450. //
  451. dwErr = RasAtCbOpenRegKeys(
  452. pszServer,
  453. &hkParams);
  454. BREAK_ON_DWERR( dwErr );
  455. // Write out the params to the registry
  456. //
  457. if (pConfig->dwFlags & RASAT_F_EnableIn)
  458. {
  459. dwErr = RutlRegWriteDword(
  460. hkParams,
  461. pszEnableIn,
  462. pConfig->bEnableIn);
  463. BREAK_ON_DWERR( dwErr );
  464. }
  465. if (pConfig->dwFlags & RASAT_F_Access)
  466. {
  467. dwErr = RutlRegWriteDword(
  468. hkParams,
  469. pszAtNetworkAccess,
  470. pConfig->bAccess);
  471. BREAK_ON_DWERR( dwErr );
  472. }
  473. } while (FALSE);
  474. // Cleanup
  475. {
  476. if (hkParams)
  477. {
  478. RegCloseKey(hkParams);
  479. }
  480. }
  481. return dwErr;
  482. }