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.

616 lines
14 KiB

  1. /*
  2. File: rasnbf.h
  3. The 'remoteaccess nbf' sub context
  4. 3/2/99
  5. */
  6. #include "precomp.h"
  7. #include "rasnbf.h"
  8. //
  9. // Local prototypes
  10. //
  11. BOOL
  12. WINAPI
  13. RasNbfCheckVersion(
  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_RasNbfGuid = RASNBF_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_RasNbfSetCmdTable[] =
  31. {
  32. // Whistler bug 249293, changes for architecture version checking
  33. //
  34. CREATE_CMD_ENTRY(RASNBF_SET_NEGOTIATION,RasNbfHandleSetNegotiation),
  35. CREATE_CMD_ENTRY(RASNBF_SET_ACCESS, RasNbfHandleSetAccess),
  36. };
  37. CMD_ENTRY g_RasNbfShowCmdTable[] =
  38. {
  39. // Whistler bug 249293, changes for architecture version checking
  40. //
  41. CREATE_CMD_ENTRY(RASNBF_SHOW_CONFIG, RasNbfHandleShow),
  42. };
  43. CMD_GROUP_ENTRY g_RasNbfCmdGroups[] =
  44. {
  45. CREATE_CMD_GROUP_ENTRY(GROUP_SET, g_RasNbfSetCmdTable),
  46. CREATE_CMD_GROUP_ENTRY(GROUP_SHOW, g_RasNbfShowCmdTable),
  47. };
  48. ULONG g_ulRasNbfNumGroups = sizeof(g_RasNbfCmdGroups)/sizeof(CMD_GROUP_ENTRY);
  49. //
  50. // Flags that control how/what info is read/written
  51. // in the RASNBF_CB structure
  52. //
  53. #define RASNBF_F_EnableIn 0x1
  54. #define RASNBF_F_Access 0x2
  55. #define RASNBF_F_All 0xFFFF
  56. //
  57. // Control block for ras nbf configuration
  58. //
  59. typedef struct _RASNBF_CB
  60. {
  61. DWORD dwFlags; // See RASNBF_F_* values
  62. BOOL bEnableIn;
  63. BOOL bAccess;
  64. } RASNBF_CB;
  65. //
  66. // Nbf specific registry parameters
  67. //
  68. WCHAR pszNbfParams[] = L"Nbf";
  69. //
  70. // Prototypes of functions that manipulate the
  71. // RASNBF_CB structures
  72. //
  73. DWORD
  74. RasNbfCbCleanup(
  75. IN RASNBF_CB* pConfig);
  76. DWORD
  77. RasNbfCbCreateDefault(
  78. OUT RASNBF_CB** ppConfig);
  79. DWORD
  80. RasNbfCbOpenRegKeys(
  81. IN LPCWSTR pszServer,
  82. OUT HKEY* phKey);
  83. DWORD
  84. RasNbfCbRead(
  85. IN LPCWSTR pszServer,
  86. OUT RASNBF_CB* pConfig);
  87. DWORD
  88. RasNbfCbWrite(
  89. IN LPCWSTR pszServer,
  90. IN RASNBF_CB* pConfig);
  91. //
  92. // Callback determines if a command is valid on a given architecture
  93. //
  94. BOOL
  95. WINAPI
  96. RasNbfCheckVersion(
  97. IN UINT CIMOSType,
  98. IN UINT CIMOSProductSuite,
  99. IN LPCWSTR CIMOSVersion,
  100. IN LPCWSTR CIMOSBuildNumber,
  101. IN LPCWSTR CIMServicePackMajorVersion,
  102. IN LPCWSTR CIMServicePackMinorVersion,
  103. IN UINT CIMProcessorArchitecture,
  104. IN DWORD dwReserved
  105. )
  106. {
  107. INT iBuild = _wtoi(CIMOSBuildNumber);
  108. // Only available pre-whistler
  109. return ((iBuild != 0) && (iBuild <= 2195));
  110. }
  111. //
  112. // Entry called by rasmontr to register this context
  113. //
  114. DWORD
  115. WINAPI
  116. RasNbfStartHelper(
  117. IN CONST GUID *pguidParent,
  118. IN DWORD dwVersion)
  119. {
  120. DWORD dwErr = NO_ERROR;
  121. NS_CONTEXT_ATTRIBUTES attMyAttributes;
  122. // Initialize
  123. //
  124. ZeroMemory(&attMyAttributes, sizeof(attMyAttributes));
  125. // Whistler bug 249293, changes for architecture version checking
  126. //
  127. attMyAttributes.pfnOsVersionCheck= RasNbfCheckVersion;
  128. attMyAttributes.pwszContext = L"netbeui";
  129. attMyAttributes.guidHelper = g_RasNbfGuid;
  130. attMyAttributes.dwVersion = RASNBF_VERSION;
  131. attMyAttributes.dwFlags = 0;
  132. attMyAttributes.ulNumTopCmds = 0;
  133. attMyAttributes.pTopCmds = NULL;
  134. attMyAttributes.ulNumGroups = g_ulRasNbfNumGroups;
  135. attMyAttributes.pCmdGroups = (CMD_GROUP_ENTRY (*)[])&g_RasNbfCmdGroups;
  136. attMyAttributes.pfnDumpFn = RasNbfDump;
  137. dwErr = RegisterContext( &attMyAttributes );
  138. return dwErr;
  139. }
  140. DWORD
  141. RasNbfDisplayConfig(
  142. IN BOOL bReport)
  143. {
  144. DWORD dwErr = NO_ERROR;
  145. RASNBF_CB* pConfig = NULL;
  146. PWCHAR pszEnableIn = NULL, pszAccess = NULL;
  147. do
  148. {
  149. // Get a default config blob
  150. //
  151. dwErr = RasNbfCbCreateDefault(&pConfig);
  152. BREAK_ON_DWERR( dwErr );
  153. // Read in all of the values
  154. //
  155. pConfig->dwFlags = RASNBF_F_All;
  156. dwErr = RasNbfCbRead(g_pszServer, pConfig);
  157. BREAK_ON_DWERR( dwErr );
  158. if (bReport)
  159. {
  160. pszEnableIn =
  161. RutlStrDup(pConfig->bEnableIn ? TOKEN_ALLOW : TOKEN_DENY);
  162. pszAccess =
  163. RutlStrDup(pConfig->bAccess ? TOKEN_ALL : TOKEN_SERVERONLY);
  164. DisplayMessage(
  165. g_hModule,
  166. MSG_RASNBF_SERVERCONFIG,
  167. g_pszServer,
  168. pszEnableIn,
  169. pszAccess);
  170. }
  171. else
  172. {
  173. pszEnableIn = RutlAssignmentFromTokens(
  174. g_hModule,
  175. TOKEN_MODE,
  176. pConfig->bEnableIn ? TOKEN_ALLOW : TOKEN_DENY);
  177. pszAccess = RutlAssignmentFromTokens(
  178. g_hModule,
  179. TOKEN_MODE,
  180. pConfig->bAccess ? TOKEN_ALL : TOKEN_SERVERONLY);
  181. DisplayMessage(
  182. g_hModule,
  183. MSG_RASNBF_SCRIPTHEADER);
  184. DisplayMessageT(DMP_RASNBF_PUSHD);
  185. DisplayMessage(
  186. g_hModule,
  187. MSG_RASNBF_SET_CMD,
  188. DMP_RASNBF_SET_NEGOTIATION,
  189. pszEnableIn);
  190. DisplayMessage(
  191. g_hModule,
  192. MSG_RASNBF_SET_CMD,
  193. DMP_RASNBF_SET_ACCESS,
  194. pszAccess);
  195. DisplayMessageT(DMP_RASNBF_POPD);
  196. DisplayMessage(
  197. g_hModule,
  198. MSG_RASNBF_SCRIPTFOOTER);
  199. }
  200. } while (FALSE);
  201. // Cleanup
  202. {
  203. if (pConfig)
  204. {
  205. RasNbfCbCleanup(pConfig);
  206. }
  207. if (pszEnableIn)
  208. {
  209. RutlFree(pszEnableIn);
  210. }
  211. if (pszAccess)
  212. {
  213. RutlFree(pszAccess);
  214. }
  215. }
  216. return dwErr;
  217. }
  218. DWORD
  219. WINAPI
  220. RasNbfDump(
  221. IN LPCWSTR pwszRouter,
  222. IN OUT LPWSTR *ppwcArguments,
  223. IN DWORD dwArgCount,
  224. IN LPCVOID pvData
  225. )
  226. {
  227. return RasNbfDisplayConfig(FALSE);
  228. }
  229. DWORD
  230. RasNbfHandleSetAccess(
  231. IN LPCWSTR pwszMachine,
  232. IN OUT LPWSTR *ppwcArguments,
  233. IN DWORD dwCurrentIndex,
  234. IN DWORD dwArgCount,
  235. IN DWORD dwFlags,
  236. IN LPCVOID pvData,
  237. OUT BOOL *pbDone
  238. )
  239. {
  240. DWORD dwErr = NO_ERROR, dwValue = 0;
  241. RASNBF_CB Config;
  242. TOKEN_VALUE rgEnum[] = { {TOKEN_ALL, TRUE}, {TOKEN_SERVERONLY, FALSE} };
  243. RASMON_CMD_ARG pArgs[] =
  244. {
  245. {
  246. RASMONTR_CMD_TYPE_ENUM,
  247. {TOKEN_MODE, TRUE, FALSE},
  248. rgEnum,
  249. sizeof(rgEnum)/sizeof(*rgEnum),
  250. NULL
  251. }
  252. };
  253. do
  254. {
  255. // Parse the command line
  256. //
  257. dwErr = RutlParse(
  258. ppwcArguments,
  259. dwCurrentIndex,
  260. dwArgCount,
  261. pbDone,
  262. pArgs,
  263. sizeof(pArgs)/sizeof(*pArgs));
  264. BREAK_ON_DWERR( dwErr );
  265. dwValue = RASMON_CMD_ARG_GetDword(&pArgs[0]);
  266. // If successful, go ahead and set the info
  267. //
  268. ZeroMemory(&Config, sizeof(Config));
  269. Config.dwFlags = RASNBF_F_Access;
  270. Config.bAccess = dwValue;
  271. dwErr = RasNbfCbWrite(g_pszServer, &Config);
  272. if (dwErr != NO_ERROR)
  273. {
  274. DisplayError(NULL, dwErr);
  275. break;
  276. }
  277. } while (FALSE);
  278. // Cleanup
  279. {
  280. }
  281. return dwErr;
  282. }
  283. DWORD
  284. RasNbfHandleSetNegotiation(
  285. IN LPCWSTR pwszMachine,
  286. IN OUT LPWSTR *ppwcArguments,
  287. IN DWORD dwCurrentIndex,
  288. IN DWORD dwArgCount,
  289. IN DWORD dwFlags,
  290. IN LPCVOID pvData,
  291. OUT BOOL *pbDone
  292. )
  293. {
  294. DWORD dwErr = NO_ERROR, dwValue = 0;
  295. RASNBF_CB Config;
  296. TOKEN_VALUE rgEnum[] = { {TOKEN_ALLOW, TRUE}, {TOKEN_DENY, FALSE} };
  297. RASMON_CMD_ARG pArgs[] =
  298. {
  299. {
  300. RASMONTR_CMD_TYPE_ENUM,
  301. {TOKEN_MODE, TRUE, FALSE},
  302. rgEnum,
  303. sizeof(rgEnum)/sizeof(*rgEnum),
  304. NULL
  305. }
  306. };
  307. do
  308. {
  309. // Parse the command line
  310. //
  311. dwErr = RutlParse(
  312. ppwcArguments,
  313. dwCurrentIndex,
  314. dwArgCount,
  315. pbDone,
  316. pArgs,
  317. sizeof(pArgs)/sizeof(*pArgs));
  318. BREAK_ON_DWERR( dwErr );
  319. dwValue = RASMON_CMD_ARG_GetDword(&pArgs[0]);
  320. // If successful, go ahead and set the info
  321. //
  322. ZeroMemory(&Config, sizeof(Config));
  323. Config.dwFlags = RASNBF_F_EnableIn;
  324. Config.bEnableIn = dwValue;
  325. dwErr = RasNbfCbWrite(g_pszServer, &Config);
  326. if (dwErr != NO_ERROR)
  327. {
  328. DisplayError(NULL, dwErr);
  329. break;
  330. }
  331. } while (FALSE);
  332. // Cleanup
  333. {
  334. }
  335. return dwErr;
  336. }
  337. DWORD
  338. RasNbfHandleShow(
  339. IN LPCWSTR pwszMachine,
  340. IN OUT LPWSTR *ppwcArguments,
  341. IN DWORD dwCurrentIndex,
  342. IN DWORD dwArgCount,
  343. IN DWORD dwFlags,
  344. IN LPCVOID pvData,
  345. OUT BOOL *pbDone
  346. )
  347. {
  348. DWORD dwNumArgs = dwArgCount - dwCurrentIndex;
  349. // Check that the number of arguments is correct
  350. //
  351. if (dwNumArgs > 0)
  352. {
  353. DisplayMessage(
  354. g_hModule,
  355. HLP_RASNBF_SHOW_CONFIG_EX,
  356. DMP_RASNBF_SHOW_CONFIG);
  357. return NO_ERROR;
  358. }
  359. return RasNbfDisplayConfig(TRUE);
  360. }
  361. //
  362. // Cleans up a config control block
  363. //
  364. DWORD
  365. RasNbfCbCleanup(
  366. IN RASNBF_CB* pConfig)
  367. {
  368. if (pConfig)
  369. {
  370. RutlFree(pConfig);
  371. }
  372. return NO_ERROR;
  373. }
  374. //
  375. // Creates a default config control block
  376. //
  377. DWORD
  378. RasNbfCbCreateDefault(
  379. OUT RASNBF_CB** ppConfig)
  380. {
  381. RASNBF_CB* pConfig = NULL;
  382. DWORD dwErr = NO_ERROR;
  383. do
  384. {
  385. pConfig = (RASNBF_CB*) RutlAlloc(sizeof(RASNBF_CB), TRUE);
  386. if (pConfig == NULL)
  387. {
  388. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  389. break;
  390. }
  391. pConfig->bEnableIn = TRUE;
  392. pConfig->bAccess = TRUE;
  393. *ppConfig = pConfig;
  394. } while (FALSE);
  395. // Cleanup
  396. {
  397. if (dwErr != NO_ERROR)
  398. {
  399. RasNbfCbCleanup(pConfig);
  400. }
  401. }
  402. return dwErr;
  403. }
  404. //
  405. // Helper function opens the ras nbf config registry key
  406. //
  407. DWORD
  408. RasNbfCbOpenRegKeys(
  409. IN LPCWSTR pszServer,
  410. OUT HKEY* phKey)
  411. {
  412. DWORD dwErr = NO_ERROR;
  413. WCHAR pszKey[MAX_PATH];
  414. do
  415. {
  416. // Generate the parameters key name
  417. //
  418. wsprintfW(
  419. pszKey,
  420. L"%s%s",
  421. pszRemoteAccessParamStub,
  422. pszNbfParams);
  423. // Open the parameters keys
  424. //
  425. dwErr = RegOpenKeyEx(
  426. g_pServerInfo->hkMachine,
  427. pszKey,
  428. 0,
  429. KEY_READ | KEY_WRITE,
  430. phKey);
  431. BREAK_ON_DWERR( dwErr );
  432. } while (FALSE);
  433. // Cleanup
  434. {
  435. }
  436. return dwErr;
  437. }
  438. //
  439. // Functions that manipulate RASNBF_CB's
  440. //
  441. DWORD
  442. RasNbfCbRead(
  443. IN LPCWSTR pszServer,
  444. OUT RASNBF_CB* pConfig)
  445. {
  446. HKEY hkParams = NULL;
  447. DWORD dwErr = NO_ERROR;
  448. do
  449. {
  450. // Get a handle to the server's registry config
  451. //
  452. dwErr = RasNbfCbOpenRegKeys(
  453. pszServer,
  454. &hkParams);
  455. BREAK_ON_DWERR( dwErr );
  456. // Load the params from the registry
  457. //
  458. if (pConfig->dwFlags & RASNBF_F_EnableIn)
  459. {
  460. dwErr = RutlRegReadDword(
  461. hkParams,
  462. pszEnableIn,
  463. &pConfig->bEnableIn);
  464. BREAK_ON_DWERR( dwErr );
  465. }
  466. if (pConfig->dwFlags & RASNBF_F_Access)
  467. {
  468. dwErr = RutlRegReadDword(
  469. hkParams,
  470. pszAllowNetworkAccess,
  471. &pConfig->bAccess);
  472. BREAK_ON_DWERR( dwErr );
  473. }
  474. } while (FALSE);
  475. // Cleanup
  476. {
  477. if (hkParams)
  478. {
  479. RegCloseKey(hkParams);
  480. }
  481. }
  482. return dwErr;
  483. }
  484. DWORD
  485. RasNbfCbWrite(
  486. IN LPCWSTR pszServer,
  487. IN RASNBF_CB* pConfig)
  488. {
  489. HKEY hkParams = NULL;
  490. DWORD dwErr = NO_ERROR;
  491. do
  492. {
  493. // Get a handle to the server's registry config
  494. //
  495. dwErr = RasNbfCbOpenRegKeys(
  496. pszServer,
  497. &hkParams);
  498. BREAK_ON_DWERR( dwErr );
  499. // Write out the params to the registry
  500. //
  501. if (pConfig->dwFlags & RASNBF_F_EnableIn)
  502. {
  503. dwErr = RutlRegWriteDword(
  504. hkParams,
  505. pszEnableIn,
  506. pConfig->bEnableIn);
  507. BREAK_ON_DWERR( dwErr );
  508. }
  509. if (pConfig->dwFlags & RASNBF_F_Access)
  510. {
  511. dwErr = RutlRegWriteDword(
  512. hkParams,
  513. pszAllowNetworkAccess,
  514. pConfig->bAccess);
  515. BREAK_ON_DWERR( dwErr );
  516. }
  517. } while (FALSE);
  518. // Cleanup
  519. {
  520. if (hkParams)
  521. {
  522. RegCloseKey(hkParams);
  523. }
  524. }
  525. return dwErr;
  526. }