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.

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