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.

262 lines
6.7 KiB

  1. /*++
  2. Copyright (c) 2001-2002 Microsoft Corporation
  3. Module Name:
  4. teredo.c
  5. Abstract:
  6. Teredo commands.
  7. Author:
  8. Mohit Talwar (mohitt) Wed Nov 07 22:18:53 2001
  9. --*/
  10. #include "precomp.h"
  11. //
  12. // The following enums and defines should be kept consistent with
  13. // teredo.h in 6to4svc.
  14. //
  15. //
  16. // TEREDO_TYPE
  17. //
  18. // Define the type of the teredo service.
  19. //
  20. typedef enum {
  21. TEREDO_DEFAULT = 0,
  22. TEREDO_CLIENT,
  23. TEREDO_SERVER,
  24. TEREDO_DISABLE,
  25. TEREDO_MAXIMUM,
  26. } TEREDO_TYPE, *PTEREDO_TYPE;
  27. #define KEY_TEREDO_REFRESH_INTERVAL L"RefreshInterval"
  28. #define KEY_TEREDO_TYPE L"Type"
  29. #define KEY_TEREDO_SERVER_NAME L"ServerName"
  30. #define KEY_TEREDO L"System\\CurrentControlSet\\Services\\Teredo"
  31. PWCHAR pwszTypeString[] = {
  32. TOKEN_VALUE_DEFAULT,
  33. TOKEN_VALUE_CLIENT,
  34. TOKEN_VALUE_SERVER,
  35. TOKEN_VALUE_DISABLE,
  36. };
  37. /////////////////////////////////////////////////////////////////////////////
  38. // Commands related to teredo
  39. /////////////////////////////////////////////////////////////////////////////
  40. DWORD
  41. ShowTeredo(
  42. IN FORMAT Format
  43. )
  44. {
  45. HKEY hKey = INVALID_HANDLE_VALUE;
  46. TEREDO_TYPE tyType;
  47. WCHAR pwszServerName[NI_MAXHOST] = TOKEN_VALUE_DEFAULT;
  48. ULONG ulRefreshInterval;
  49. (VOID) RegOpenKeyEx(
  50. HKEY_LOCAL_MACHINE, KEY_TEREDO, 0, KEY_QUERY_VALUE, &hKey);
  51. tyType = GetInteger(hKey, KEY_TEREDO_TYPE, TEREDO_DEFAULT);
  52. if (tyType >= TEREDO_MAXIMUM) {
  53. tyType = TEREDO_DEFAULT;
  54. }
  55. GetString(hKey, KEY_TEREDO_SERVER_NAME, pwszServerName, NI_MAXHOST);
  56. ulRefreshInterval = GetInteger(hKey, KEY_TEREDO_REFRESH_INTERVAL, 0);
  57. RegCloseKey(hKey);
  58. if (Format == FORMAT_DUMP) {
  59. DisplayMessageT(DMP_IPV6_SET_TEREDO);
  60. DisplayMessageT(DMP_STRING_ARG, TOKEN_TYPE, pwszTypeString[tyType]);
  61. DisplayMessageT(DMP_STRING_ARG, TOKEN_SERVERNAME, pwszServerName);
  62. if (ulRefreshInterval == 0) {
  63. DisplayMessageT(
  64. DMP_STRING_ARG, TOKEN_REFRESH_INTERVAL, TOKEN_VALUE_DEFAULT);
  65. } else {
  66. DisplayMessageT(
  67. DMP_INTEGER_ARG, TOKEN_REFRESH_INTERVAL, ulRefreshInterval);
  68. }
  69. DisplayMessage(g_hModule, MSG_NEWLINE);
  70. } else {
  71. /*
  72. DisplayMessage(
  73. g_hModule,
  74. MSG_TEREDO_PARAMETERS,
  75. pwszTypeString[tyType],
  76. pwszServerName);
  77. if (ulRefreshInterval == 0) {
  78. DisplayMessage(g_hModule, MSG_STRING, TOKEN_VALUE_DEFAULT);
  79. } else {
  80. DisplayMessage(g_hModule, MSG_STRING, ulRefreshInterval);
  81. DisplayMessage(g_hModule, MSG_SECONDS, ulRefreshInterval);
  82. }
  83. */
  84. }
  85. return NO_ERROR;
  86. }
  87. DWORD
  88. HandleSetTeredo(
  89. IN LPCWSTR pwszMachine,
  90. IN OUT LPWSTR *ppwcArguments,
  91. IN DWORD dwCurrentIndex,
  92. IN DWORD dwArgCount,
  93. IN DWORD dwFlags,
  94. IN LPCVOID pvData,
  95. OUT BOOL *pbDone
  96. )
  97. {
  98. DWORD dwErr = NO_ERROR;
  99. HKEY hKey = INVALID_HANDLE_VALUE;
  100. TEREDO_TYPE tyType;
  101. PWCHAR pwszServerName;
  102. ULONG ulRefreshInterval;
  103. BOOL bType, bServer, bRefreshInterval;
  104. TAG_TYPE pttTags[] = {{TOKEN_TYPE, FALSE, FALSE},
  105. {TOKEN_SERVERNAME, FALSE, FALSE},
  106. {TOKEN_REFRESH_INTERVAL, FALSE, FALSE}};
  107. DWORD rgdwTagType[sizeof(pttTags) / sizeof(TAG_TYPE)];
  108. TOKEN_VALUE rgtvEnums[] = {
  109. { TOKEN_VALUE_DEFAULT, TEREDO_DEFAULT },
  110. { TOKEN_VALUE_CLIENT, TEREDO_CLIENT },
  111. { TOKEN_VALUE_SERVER, TEREDO_SERVER },
  112. { TOKEN_VALUE_DISABLE, TEREDO_DISABLE },
  113. };
  114. DWORD i;
  115. bType = bServer = bRefreshInterval = FALSE;
  116. // Parse arguments
  117. dwErr = PreprocessCommand(g_hModule,
  118. ppwcArguments,
  119. dwCurrentIndex,
  120. dwArgCount,
  121. pttTags,
  122. sizeof(pttTags)/sizeof(TAG_TYPE),
  123. 1,
  124. sizeof(pttTags)/sizeof(TAG_TYPE),
  125. rgdwTagType );
  126. if (dwErr != NO_ERROR) {
  127. return dwErr;
  128. }
  129. for (i = 0; i < (dwArgCount - dwCurrentIndex); i++) {
  130. switch(rgdwTagType[i]) {
  131. case 0: // TYPE
  132. dwErr = MatchEnumTag(NULL,
  133. ppwcArguments[dwCurrentIndex + i],
  134. NUM_TOKENS_IN_TABLE(rgtvEnums),
  135. rgtvEnums,
  136. (PDWORD) &tyType);
  137. if (dwErr != NO_ERROR) {
  138. dwErr = ERROR_INVALID_PARAMETER;
  139. break;
  140. }
  141. bType = TRUE;
  142. break;
  143. case 1: // SERVERNAME
  144. pwszServerName = ppwcArguments[dwCurrentIndex + i];
  145. bServer = TRUE;
  146. break;
  147. case 2: // REFRESHINTERVAL
  148. ulRefreshInterval = wcstoul(
  149. ppwcArguments[dwCurrentIndex + i], NULL, 10);
  150. bRefreshInterval = TRUE;
  151. break;
  152. default:
  153. dwErr = ERROR_INVALID_SYNTAX;
  154. break;
  155. }
  156. if (dwErr != NO_ERROR) {
  157. return dwErr;
  158. }
  159. }
  160. // Now do the sets
  161. dwErr = RegCreateKeyEx(HKEY_LOCAL_MACHINE, KEY_TEREDO, 0, NULL, 0,
  162. KEY_ALL_ACCESS, NULL, &hKey, NULL);
  163. if (dwErr != NO_ERROR) {
  164. return dwErr;
  165. }
  166. if (bType) { // 0 (TEREDO_DEFAULT) resets to default.
  167. dwErr = SetInteger(hKey, KEY_TEREDO_TYPE, tyType);
  168. if (dwErr != NO_ERROR)
  169. return dwErr;
  170. }
  171. if (bServer) { // "default" resets to default.
  172. dwErr = SetString(hKey, KEY_TEREDO_SERVER_NAME, pwszServerName);
  173. if (dwErr != NO_ERROR)
  174. goto Bail;
  175. }
  176. if (bRefreshInterval) { // 0 resets to default.
  177. dwErr = SetInteger(
  178. hKey, KEY_TEREDO_REFRESH_INTERVAL, ulRefreshInterval);
  179. if (dwErr != NO_ERROR)
  180. goto Bail;
  181. }
  182. Bail:
  183. RegCloseKey(hKey);
  184. Ip6to4PokeService();
  185. return ERROR_OKAY;
  186. }
  187. DWORD
  188. HandleShowTeredo(
  189. IN LPCWSTR pwszMachine,
  190. IN OUT LPWSTR *ppwcArguments,
  191. IN DWORD dwCurrentIndex,
  192. IN DWORD dwArgCount,
  193. IN DWORD dwFlags,
  194. IN LPCVOID pvData,
  195. OUT BOOL *pbDone
  196. )
  197. {
  198. return ShowTeredo(FORMAT_NORMAL);
  199. }
  200. DWORD
  201. ResetTeredo(
  202. VOID
  203. )
  204. {
  205. DWORD dwErr;
  206. // Nuke teredo parameters.
  207. dwErr = RegDeleteKey(HKEY_LOCAL_MACHINE, KEY_TEREDO);
  208. if ((dwErr != NO_ERROR) && (dwErr != ERROR_FILE_NOT_FOUND)) {
  209. return dwErr;
  210. }
  211. // Poke the teredo service.
  212. Ip6to4PokeService();
  213. return ERROR_OKAY;
  214. }