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.

315 lines
8.6 KiB

  1. //=============================================================================
  2. // Copyright (c) 2002 Microsoft Corporation
  3. // Abstract:
  4. // This module implements ISATAP configuration commands.
  5. //=============================================================================
  6. #include "precomp.h"
  7. #pragma hdrstop
  8. #define KEY_ENABLE_ISATAP_RESOLUTION L"EnableIsatapResolution"
  9. #define KEY_ISATAP_RESOLUTION_INTERVAL L"IsatapResolutionInterval"
  10. #define KEY_ISATAP_ROUTER_NAME L"IsatapRouterName"
  11. // The commands supported in this context
  12. //
  13. CMD_ENTRY g_IsatapSetCmdTable[] =
  14. {
  15. CREATE_UNDOCUMENTED_CMD_ENTRY(ISATAP_SET_ROUTER, IsatapHandleSetRouter),
  16. };
  17. CMD_ENTRY g_IsatapShowCmdTable[] =
  18. {
  19. CREATE_UNDOCUMENTED_CMD_ENTRY(ISATAP_SHOW_ROUTER, IsatapHandleShowRouter),
  20. };
  21. CMD_GROUP_ENTRY g_IsatapCmdGroups[] =
  22. {
  23. CREATE_CMD_GROUP_ENTRY(GROUP_SET, g_IsatapSetCmdTable),
  24. CREATE_CMD_GROUP_ENTRY(GROUP_SHOW, g_IsatapShowCmdTable),
  25. };
  26. ULONG g_ulIsatapNumGroups = sizeof(g_IsatapCmdGroups)/sizeof(CMD_GROUP_ENTRY);
  27. DWORD
  28. WINAPI
  29. IsatapStartHelper(
  30. IN CONST GUID *pguidParent,
  31. IN DWORD dwVersion
  32. )
  33. /*++
  34. Routine Description
  35. Used to initialize the helper.
  36. Arguments
  37. pguidParent IPv6's guid
  38. pfnRegisterContext
  39. Return Value
  40. NO_ERROR
  41. other error code
  42. --*/
  43. {
  44. DWORD dwErr = NO_ERROR;
  45. NS_CONTEXT_ATTRIBUTES attMyAttributes;
  46. // Initialize attributes. We reuse the same GUID as 6to4 since both
  47. // are leaf contexts.
  48. //
  49. ZeroMemory(&attMyAttributes, sizeof(attMyAttributes));
  50. attMyAttributes.pwszContext = L"isatap";
  51. attMyAttributes.guidHelper = g_Ip6to4Guid;
  52. attMyAttributes.dwVersion = IP6TO4_VERSION;
  53. attMyAttributes.dwFlags = 0;
  54. attMyAttributes.pfnDumpFn = IsatapDump;
  55. attMyAttributes.ulNumTopCmds= 0;
  56. attMyAttributes.pTopCmds = NULL;
  57. attMyAttributes.ulNumGroups = g_ulIsatapNumGroups;
  58. attMyAttributes.pCmdGroups = (CMD_GROUP_ENTRY (*)[])&g_IsatapCmdGroups;
  59. dwErr = RegisterContext( &attMyAttributes );
  60. return dwErr;
  61. }
  62. #define BM_ENABLE_RESOLUTION 0x01
  63. #define BM_ROUTER_NAME 0x02
  64. #define BM_RESOLUTION_INTERVAL 0x04
  65. DWORD
  66. IsatapHandleSetRouter(
  67. IN LPCWSTR pwszMachine,
  68. IN OUT LPWSTR *ppwcArguments,
  69. IN DWORD dwCurrentIndex,
  70. IN DWORD dwArgCount,
  71. IN DWORD dwFlags,
  72. IN LPCVOID pvData,
  73. OUT BOOL *pbDone
  74. )
  75. {
  76. DWORD dwErr = NO_ERROR;
  77. HKEY hGlobal;
  78. STATE stEnableResolution;
  79. ULONG ulResolutionInterval;
  80. PWCHAR pwszRouterName;
  81. DWORD dwBitVector = 0;
  82. TAG_TYPE pttTags[] = {{TOKEN_NAME, NS_REQ_ZERO, FALSE},
  83. {TOKEN_STATE, NS_REQ_ZERO, FALSE},
  84. {TOKEN_INTERVAL, NS_REQ_ZERO, FALSE}};
  85. DWORD rgdwTagType[sizeof(pttTags)/sizeof(TAG_TYPE)];
  86. DWORD dwNumArg;
  87. DWORD i;
  88. // Parse arguments
  89. dwErr = PreprocessCommand(g_hModule,
  90. ppwcArguments,
  91. dwCurrentIndex,
  92. dwArgCount,
  93. pttTags,
  94. sizeof(pttTags)/sizeof(TAG_TYPE),
  95. 1,
  96. sizeof(pttTags)/sizeof(TAG_TYPE),
  97. rgdwTagType );
  98. if (dwErr isnot NO_ERROR) {
  99. return dwErr;
  100. }
  101. for (i=0; i<dwArgCount-dwCurrentIndex; i++) {
  102. switch(rgdwTagType[i]) {
  103. case 0: // ROUTERNAME
  104. pwszRouterName = ppwcArguments[dwCurrentIndex + i];
  105. dwBitVector |= BM_ROUTER_NAME;
  106. break;
  107. case 1: // STATE
  108. dwErr = MatchEnumTag(NULL,
  109. ppwcArguments[dwCurrentIndex + i],
  110. NUM_TOKENS_IN_TABLE(rgtvEnums),
  111. rgtvEnums,
  112. (PDWORD)&stEnableResolution);
  113. if (dwErr isnot NO_ERROR) {
  114. dwErr = ERROR_INVALID_PARAMETER;
  115. break;
  116. }
  117. dwBitVector |= BM_ENABLE_RESOLUTION;
  118. break;
  119. case 2: // INTERVAL
  120. ulResolutionInterval = wcstoul(ppwcArguments[dwCurrentIndex + i],
  121. NULL, 10);
  122. dwBitVector |= BM_RESOLUTION_INTERVAL;
  123. break;
  124. default:
  125. dwErr = ERROR_INVALID_SYNTAX;
  126. break;
  127. }
  128. if (dwErr isnot NO_ERROR) {
  129. return dwErr;
  130. }
  131. }
  132. // Now do the sets
  133. dwErr = RegCreateKeyEx(HKEY_LOCAL_MACHINE, KEY_GLOBAL, 0,
  134. NULL, 0, KEY_ALL_ACCESS, NULL, &hGlobal, NULL);
  135. if (dwErr != NO_ERROR) {
  136. return dwErr;
  137. }
  138. if (dwBitVector & BM_ENABLE_RESOLUTION) {
  139. dwErr = SetInteger(hGlobal, KEY_ENABLE_ISATAP_RESOLUTION,
  140. stEnableResolution);
  141. if (dwErr != NO_ERROR)
  142. return dwErr;
  143. }
  144. if (dwBitVector & BM_ROUTER_NAME) {
  145. dwErr = SetString(hGlobal, KEY_ISATAP_ROUTER_NAME, pwszRouterName);
  146. if (dwErr != NO_ERROR)
  147. return dwErr;
  148. }
  149. if (dwBitVector & BM_RESOLUTION_INTERVAL) {
  150. dwErr = SetInteger(hGlobal, KEY_ISATAP_RESOLUTION_INTERVAL,
  151. ulResolutionInterval);
  152. if (dwErr != NO_ERROR)
  153. return dwErr;
  154. }
  155. RegCloseKey(hGlobal);
  156. Ip6to4PokeService();
  157. return ERROR_OKAY;
  158. }
  159. DWORD
  160. ShowRouterConfig(
  161. IN BOOL bDump
  162. )
  163. {
  164. DWORD dwErr = NO_ERROR;
  165. HKEY hGlobal;
  166. STATE stEnableResolution;
  167. ULONG ulResolutionInterval;
  168. WCHAR pwszRouterName[NI_MAXHOST];
  169. BOOL bHaveRouterName;
  170. dwErr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, KEY_GLOBAL, 0, KEY_QUERY_VALUE,
  171. &hGlobal);
  172. if (dwErr != NO_ERROR) {
  173. hGlobal = INVALID_HANDLE_VALUE;
  174. dwErr = NO_ERROR;
  175. }
  176. stEnableResolution = GetInteger(hGlobal,
  177. KEY_ENABLE_ISATAP_RESOLUTION,
  178. VAL_DEFAULT);
  179. bHaveRouterName = GetString(hGlobal, KEY_ISATAP_ROUTER_NAME, pwszRouterName,
  180. NI_MAXHOST);
  181. ulResolutionInterval = GetInteger(hGlobal,
  182. KEY_ISATAP_RESOLUTION_INTERVAL,
  183. 0);
  184. RegCloseKey(hGlobal);
  185. if (bDump) {
  186. if (bHaveRouterName || (stEnableResolution != VAL_DEFAULT)
  187. || (ulResolutionInterval > 0)) {
  188. DisplayMessageT(DMP_ISATAP_SET_ROUTER);
  189. if (bHaveRouterName) {
  190. DisplayMessageT(DMP_STRING_ARG, TOKEN_NAME, pwszRouterName);
  191. }
  192. if (stEnableResolution != VAL_DEFAULT) {
  193. DisplayMessageT(DMP_STRING_ARG,
  194. TOKEN_STATE,
  195. pwszStateString[stEnableResolution]);
  196. }
  197. if (ulResolutionInterval > 0) {
  198. DisplayMessageT(DMP_INTEGER_ARG, TOKEN_INTERVAL,
  199. ulResolutionInterval);
  200. }
  201. DisplayMessage(g_hModule, MSG_NEWLINE);
  202. }
  203. } else {
  204. DisplayMessage(g_hModule, MSG_RELAY_NAME);
  205. // DisplayMessage(g_hModule, MSG_ROUTER_NAME);
  206. if (bHaveRouterName) {
  207. DisplayMessage(g_hModule, MSG_STRING, pwszRouterName);
  208. } else {
  209. DisplayMessage(g_hModule, MSG_STRING, TOKEN_VALUE_DEFAULT);
  210. }
  211. DisplayMessage(g_hModule, MSG_RESOLUTION_STATE,
  212. pwszStateString[stEnableResolution]);
  213. DisplayMessage(g_hModule, MSG_RESOLUTION_INTERVAL);
  214. if (ulResolutionInterval) {
  215. DisplayMessage(g_hModule, MSG_MINUTES, ulResolutionInterval);
  216. } else {
  217. DisplayMessage(g_hModule, MSG_STRING, TOKEN_VALUE_DEFAULT);
  218. }
  219. }
  220. return dwErr;
  221. }
  222. DWORD
  223. IsatapHandleShowRouter(
  224. IN LPCWSTR pwszMachine,
  225. IN OUT LPWSTR *ppwcArguments,
  226. IN DWORD dwCurrentIndex,
  227. IN DWORD dwArgCount,
  228. IN DWORD dwFlags,
  229. IN LPCVOID pvData,
  230. OUT BOOL *pbDone
  231. )
  232. {
  233. return ShowRouterConfig(FALSE);
  234. }
  235. DWORD
  236. WINAPI
  237. IsatapDump(
  238. IN LPCWSTR pwszRouter,
  239. IN OUT LPWSTR *ppwcArguments,
  240. IN DWORD dwArgCount,
  241. IN LPCVOID pvData
  242. )
  243. {
  244. // DisplayMessage(g_hModule, DMP_ISATAP_HEADER);
  245. DisplayMessageT(DMP_ISATAP_PUSHD);
  246. ShowRouterConfig(TRUE);
  247. DisplayMessageT(DMP_ISATAP_POPD);
  248. // DisplayMessage(g_hModule, DMP_ISATAP_FOOTER);
  249. return NO_ERROR;
  250. }