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.

401 lines
9.1 KiB

  1. /*++
  2. Copyright (c) 1989-1993 Microsoft Corporation
  3. Module Name:
  4. spxreg.c
  5. Abstract:
  6. This contains all routines necessary for the support of the dynamic
  7. configuration of the ISN SPX module.
  8. Revision History:
  9. --*/
  10. #include "precomp.h"
  11. #pragma hdrstop
  12. // Define module number for event logging entries
  13. #define FILENUM SPXREG
  14. // Local functions used to access the registry.
  15. NTSTATUS
  16. SpxInitReadIpxDeviceName(
  17. VOID);
  18. NTSTATUS
  19. SpxInitSetIpxDeviceName(
  20. IN PWSTR ValueName,
  21. IN ULONG ValueType,
  22. IN PVOID ValueData,
  23. IN ULONG ValueLength,
  24. IN PVOID Context,
  25. IN PVOID EntryContext);
  26. NTSTATUS
  27. SpxInitGetConfigValue(
  28. IN PWSTR ValueName,
  29. IN ULONG ValueType,
  30. IN PVOID ValueData,
  31. IN ULONG ValueLength,
  32. IN PVOID Context,
  33. IN PVOID EntryContext);
  34. #ifdef ALLOC_PRAGMA
  35. #pragma alloc_text(INIT, SpxInitGetConfiguration)
  36. #pragma alloc_text(INIT, SpxInitFreeConfiguration)
  37. #pragma alloc_text(INIT, SpxInitGetConfigValue)
  38. #pragma alloc_text(INIT, SpxInitReadIpxDeviceName)
  39. #pragma alloc_text(INIT, SpxInitSetIpxDeviceName)
  40. #endif
  41. NTSTATUS
  42. SpxInitGetConfiguration (
  43. IN PUNICODE_STRING RegistryPath,
  44. OUT PCONFIG * ConfigPtr
  45. )
  46. /*++
  47. Routine Description:
  48. This routine is called by SPX to get information from the configuration
  49. management routines. We read the registry, starting at RegistryPath,
  50. to get the parameters. If they don't exist, we use the defaults
  51. set in ipxcnfg.h file. A list of adapters to bind to is chained
  52. on to the config information.
  53. Arguments:
  54. RegistryPath - The name of ST's node in the registry.
  55. ConfigPtr - Returns the configuration information.
  56. Return Value:
  57. Status - STATUS_SUCCESS if everything OK, STATUS_INSUFFICIENT_RESOURCES
  58. otherwise.
  59. --*/
  60. {
  61. NTSTATUS Status;
  62. UINT i;
  63. PWSTR RegistryPathBuffer;
  64. PCONFIG Config;
  65. RTL_QUERY_REGISTRY_TABLE QueryTable[CONFIG_PARAMETERS+2];
  66. ULONG Zero = 0;
  67. ULONG Two = 2;
  68. ULONG Four = 4;
  69. ULONG Five = 5;
  70. ULONG Eight = 8;
  71. ULONG Twelve = 12;
  72. ULONG Fifteen = 15;
  73. ULONG Thirty = 30;
  74. ULONG FiveHundred = 500;
  75. ULONG Hex4000 = 0x4000;
  76. ULONG Hex7FFF = 0x7FFF;
  77. ULONG FourK = 4096;
  78. PWSTR Parameters = L"Parameters";
  79. struct {
  80. PWSTR KeyName;
  81. PULONG DefaultValue;
  82. } ParameterValues[CONFIG_PARAMETERS] = {
  83. { L"ConnectionCount", &Five },
  84. { L"ConnectionTimeout", &Two },
  85. { L"InitPackets", &Five },
  86. { L"MaxPackets", &Thirty},
  87. { L"InitialRetransmissionTime", &FiveHundred},
  88. { L"KeepAliveCount", &Eight},
  89. { L"KeepAliveTimeout", &Twelve},
  90. { L"WindowSize", &Four},
  91. { L"SpxSocketRangeStart", &Hex4000},
  92. { L"SpxSocketRangeEnd", &Hex7FFF},
  93. { L"SpxSocketUniqueness", &Eight},
  94. { L"MaxPacketSize", &FourK},
  95. { L"RetransmissionCount", &Eight},
  96. { L"DisableSpx2", &Zero},
  97. { L"RouterMtu", &Zero},
  98. { L"BackCompSpx", &Zero},
  99. { L"DisableRTT", &Zero}
  100. };
  101. if (!NT_SUCCESS(SpxInitReadIpxDeviceName()))
  102. {
  103. return STATUS_INSUFFICIENT_RESOURCES;
  104. }
  105. // Allocate memory for the main config structure.
  106. Config = CTEAllocMem (sizeof(CONFIG));
  107. if (Config == NULL) {
  108. TMPLOGERR();
  109. return STATUS_INSUFFICIENT_RESOURCES;
  110. }
  111. Config->cf_DeviceName.Buffer = NULL;
  112. // SpxReadLinkageInformation expects a null-terminated path,
  113. // so we have to create one from the UNICODE_STRING.
  114. RegistryPathBuffer = (PWSTR)CTEAllocMem(RegistryPath->Length + sizeof(WCHAR));
  115. if (RegistryPathBuffer == NULL) {
  116. SpxInitFreeConfiguration(Config);
  117. TMPLOGERR();
  118. return STATUS_INSUFFICIENT_RESOURCES;
  119. }
  120. RtlCopyMemory (
  121. RegistryPathBuffer,
  122. RegistryPath->Buffer,
  123. RegistryPath->Length);
  124. *(PWCHAR)(((PUCHAR)RegistryPathBuffer)+RegistryPath->Length) = (WCHAR)'\0';
  125. Config->cf_RegistryPathBuffer = RegistryPathBuffer;
  126. // Read the per-transport (as opposed to per-binding)
  127. // parameters.
  128. //
  129. // Set up QueryTable to do the following:
  130. // 1) Switch to the Parameters key below SPX
  131. //
  132. QueryTable[0].QueryRoutine = NULL;
  133. QueryTable[0].Flags = RTL_QUERY_REGISTRY_SUBKEY;
  134. QueryTable[0].Name = Parameters;
  135. // 2-14) Call SpxSetBindingValue for each of the keys we
  136. // care about.
  137. for (i = 0; i < CONFIG_PARAMETERS; i++) {
  138. QueryTable[i+1].QueryRoutine = SpxInitGetConfigValue;
  139. QueryTable[i+1].Flags = 0;
  140. QueryTable[i+1].Name = ParameterValues[i].KeyName;
  141. QueryTable[i+1].EntryContext = UlongToPtr(i);
  142. QueryTable[i+1].DefaultType = REG_DWORD;
  143. QueryTable[i+1].DefaultData = (PVOID)(ParameterValues[i].DefaultValue);
  144. QueryTable[i+1].DefaultLength = sizeof(ULONG);
  145. }
  146. // 15) Stop
  147. QueryTable[CONFIG_PARAMETERS+1].QueryRoutine = NULL;
  148. QueryTable[CONFIG_PARAMETERS+1].Flags = 0;
  149. QueryTable[CONFIG_PARAMETERS+1].Name = NULL;
  150. Status = RtlQueryRegistryValues(
  151. RTL_REGISTRY_ABSOLUTE,
  152. Config->cf_RegistryPathBuffer,
  153. QueryTable,
  154. (PVOID)Config,
  155. NULL);
  156. if (Status != STATUS_SUCCESS) {
  157. SpxInitFreeConfiguration(Config);
  158. TMPLOGERR();
  159. return Status;
  160. }
  161. CTEFreeMem (RegistryPathBuffer);
  162. *ConfigPtr = Config;
  163. return STATUS_SUCCESS;
  164. } // SpxInitGetConfiguration
  165. VOID
  166. SpxInitFreeConfiguration (
  167. IN PCONFIG Config
  168. )
  169. /*++
  170. Routine Description:
  171. This routine is called by SPX to get free any storage that was allocated
  172. by SpxGetConfiguration in producing the specified CONFIG structure.
  173. Arguments:
  174. Config - A pointer to the configuration information structure.
  175. Return Value:
  176. None.
  177. --*/
  178. {
  179. CTEFreeMem (Config);
  180. } // SpxInitFreeConfig
  181. NTSTATUS
  182. SpxInitGetConfigValue(
  183. IN PWSTR ValueName,
  184. IN ULONG ValueType,
  185. IN PVOID ValueData,
  186. IN ULONG ValueLength,
  187. IN PVOID Context,
  188. IN PVOID EntryContext
  189. )
  190. /*++
  191. Routine Description:
  192. This routine is a callback routine for RtlQueryRegistryValues
  193. It is called for each entry in the Parameters
  194. node to set the config values. The table is set up
  195. so that this function will be called with correct default
  196. values for keys that are not present.
  197. Arguments:
  198. ValueName - The name of the value (ignored).
  199. ValueType - The type of the value (REG_DWORD -- ignored).
  200. ValueData - The data for the value.
  201. ValueLength - The length of ValueData (ignored).
  202. Context - A pointer to the CONFIG structure.
  203. EntryContext - The index in Config->Parameters to save the value.
  204. Return Value:
  205. STATUS_SUCCESS
  206. --*/
  207. {
  208. PCONFIG Config = (PCONFIG)Context;
  209. UNREFERENCED_PARAMETER(ValueName);
  210. UNREFERENCED_PARAMETER(ValueType);
  211. UNREFERENCED_PARAMETER(ValueLength);
  212. if ((ValueType != REG_DWORD) || (ValueLength != sizeof(ULONG))) {
  213. return STATUS_INVALID_PARAMETER;
  214. }
  215. DBGPRINT(CONFIG, INFO,
  216. ("Config parameter %d, value %lx\n",
  217. (ULONG_PTR)EntryContext, *(UNALIGNED ULONG *)ValueData));
  218. Config->cf_Parameters[(ULONG_PTR)EntryContext] = *(UNALIGNED ULONG *)ValueData;
  219. return STATUS_SUCCESS;
  220. } // SpxInitGetConfigValue
  221. NTSTATUS
  222. SpxInitReadIpxDeviceName(
  223. VOID
  224. )
  225. {
  226. NTSTATUS Status;
  227. RTL_QUERY_REGISTRY_TABLE QueryTable[2];
  228. PWSTR Export = L"Export";
  229. PWSTR IpxRegistryPath = IPX_REG_PATH;
  230. // Set up QueryTable to do the following:
  231. //
  232. // 1) Call SetIpxDeviceName for the string in "Export"
  233. QueryTable[0].QueryRoutine = SpxInitSetIpxDeviceName;
  234. QueryTable[0].Flags = 0;
  235. QueryTable[0].Name = Export;
  236. QueryTable[0].EntryContext = NULL;
  237. QueryTable[0].DefaultType = REG_NONE;
  238. // 2) Stop
  239. QueryTable[1].QueryRoutine = NULL;
  240. QueryTable[1].Flags = 0;
  241. QueryTable[1].Name = NULL;
  242. Status = RtlQueryRegistryValues(
  243. RTL_REGISTRY_SERVICES,
  244. IpxRegistryPath,
  245. QueryTable,
  246. NULL,
  247. NULL);
  248. return Status;
  249. }
  250. NTSTATUS
  251. SpxInitSetIpxDeviceName(
  252. IN PWSTR ValueName,
  253. IN ULONG ValueType,
  254. IN PVOID ValueData,
  255. IN ULONG ValueLength,
  256. IN PVOID Context,
  257. IN PVOID EntryContext
  258. )
  259. /*++
  260. Routine Description:
  261. This routine is a callback routine for RtlQueryRegistryValues
  262. It is called for each piece of the "Export" multi-string and
  263. saves the information in a ConfigurationInfo structure.
  264. Arguments:
  265. ValueName - The name of the value ("Export" -- ignored).
  266. ValueType - The type of the value (REG_SZ -- ignored).
  267. ValueData - The null-terminated data for the value.
  268. ValueLength - The length of ValueData.
  269. Context - NULL.
  270. EntryContext - NULL.
  271. Return Value:
  272. status
  273. --*/
  274. {
  275. PWSTR fileName;
  276. NTSTATUS status = STATUS_SUCCESS;
  277. fileName = (PWSTR)CTEAllocMem(ValueLength);
  278. if (fileName != NULL) {
  279. RtlCopyMemory(fileName, ValueData, ValueLength);
  280. RtlInitUnicodeString (&IpxDeviceName, fileName);
  281. }
  282. else
  283. {
  284. status = STATUS_UNSUCCESSFUL;
  285. }
  286. return(status);
  287. }