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.

1075 lines
32 KiB

  1. #include "precomp.h"
  2. EXTERN_C
  3. VOID
  4. WINAPI
  5. NetCfgDiagRepairRegistryBindings (
  6. IN FILE* pLogFile);
  7. #define REG_DELETE 100
  8. CONST CHAR Empty[] = "";
  9. typedef union _TR_VALUE_DATA {
  10. ULONG_PTR __asignany;
  11. ULONG Value;
  12. CONST BYTE* Pointer;
  13. } TR_VALUE_DATA;
  14. typedef
  15. VOID
  16. (TR_CONDITIONAL_ROUTINE)(
  17. IN CONST struct _TR_REPAIR_CONTEXT *Ctx,
  18. IN CONST struct _TR_KEY_DESCRIPTOR *Kd,
  19. IN CONST struct _TR_VALUE_DESCRIPTOR *Vd,
  20. OUT DWORD *RegType,
  21. OUT TR_VALUE_DATA *Data,
  22. OUT DWORD *DataSize
  23. );
  24. typedef TR_CONDITIONAL_ROUTINE *PTR_CONDITIONAL_ROUTINE;
  25. typedef struct _TR_VALUE_DESCRIPTOR {
  26. PCSTR SubKeyName;
  27. PCSTR ValueName;
  28. DWORD RegType;
  29. TR_VALUE_DATA Data;
  30. DWORD DataSize;
  31. //
  32. // If Conditional is TRUE, then Data and DataSize are obtained at run-time
  33. // by invoking the routine whose address is in ConditionalRoutine.
  34. // ConditionalData may be used to hold arbitrary information for use by
  35. // ConditionalRoutine.
  36. //
  37. BOOLEAN Conditional;
  38. PTR_CONDITIONAL_ROUTINE ConditionalRoutine;
  39. TR_VALUE_DATA ConditionalData;
  40. } TR_VALUE_DESCRIPTOR;
  41. #define TRV_DW(_subkey, _valuename, _data) \
  42. { _subkey, _valuename, REG_DWORD, (ULONG_PTR)_data, sizeof(DWORD) },
  43. #define TRV_ESZ(_subkey, _valuename, _esz) \
  44. { _subkey, _valuename, REG_EXPAND_SZ, (ULONG_PTR)_esz, sizeof(_esz) },
  45. #define TRV_MSZ(_subkey, _valuename, _msz) \
  46. { _subkey, _valuename, REG_MULTI_SZ, (ULONG_PTR)_msz, sizeof(_msz) },
  47. #define TRV_SZ(_subkey, _valuename, _sz) \
  48. { _subkey, _valuename, REG_SZ, (ULONG_PTR)_sz, sizeof(_sz) },
  49. #define TRV_DEL(_subkey, _valuename) \
  50. { _subkey, _valuename, REG_DELETE, 0, 0 },
  51. #define TRV_COND(_subkey, _valuename, _routine, _cdata) \
  52. { _subkey, _valuename, REG_NONE, 0, 0, TRUE, _routine, _cdata },
  53. #define TRV_END() \
  54. { NULL, NULL, REG_NONE, 0, 0 }
  55. typedef struct _TR_KEY_DESCRIPTOR {
  56. //
  57. // RootKey is one of the HKEY_* values. (e.g. HKEY_LOCAL_MACHINE)
  58. //
  59. HKEY RootKey;
  60. //
  61. // ParentKey is the name of a subkey (under RootKey) where either the
  62. // values reside or subkeys are to be enumerated and values found under
  63. // each subkey.
  64. //
  65. PCSTR ParentKeyName;
  66. //
  67. // TRUE if all subkeys of Parentkey are to be enumerated and values
  68. // found under each of those subkeys.
  69. //
  70. BOOL EnumKey;
  71. //
  72. // Pointer to an array of value descriptors. The array is terminated
  73. // with an entry of all zeros.
  74. //
  75. CONST TR_VALUE_DESCRIPTOR *Value;
  76. } TR_KEY_DESCRIPTOR;
  77. #define DHCP_OPT_TCPIP(_name) \
  78. "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\"_name"\0"
  79. #define DHCP_OPT_TCPIP_INTERFACE(_name) \
  80. "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\?\\"_name"\0"
  81. #define DHCP_OPT_LEGACY_TCPIP_INTERFACE(_name) \
  82. "SYSTEM\\CurrentControlSet\\Services\\?\\Parameters\\Tcpip\\"_name"\0"
  83. #define DHCP_OPT_NETBT(_name) \
  84. "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters\\"_name
  85. #define DHCP_OPT_NETBT_INTERFACE(_name) \
  86. "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters\\Interfaces\\Tcpip_?\\"_name"\0"
  87. #define DHCP_OPT_NETBT_ADAPTER(_name) \
  88. "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Adapters\\?\\"_name"\0"
  89. CONST TR_VALUE_DESCRIPTOR DhcpParameterOptions_Values [] =
  90. {
  91. TRV_DW ("1", "KeyType", 7)
  92. TRV_MSZ("1", "RegLocation", DHCP_OPT_TCPIP_INTERFACE ("DhcpSubnetMaskOpt")
  93. DHCP_OPT_LEGACY_TCPIP_INTERFACE("DhcpSubnetMaskOpt"))
  94. TRV_DW ("3", "KeyType", 7)
  95. TRV_MSZ("3", "RegLocation", DHCP_OPT_TCPIP_INTERFACE ("DhcpDefaultGateway")
  96. DHCP_OPT_LEGACY_TCPIP_INTERFACE("DhcpDefaultGateway"))
  97. TRV_DW ("6", "KeyType", 1)
  98. TRV_MSZ("6", "RegLocation", DHCP_OPT_TCPIP_INTERFACE("DhcpNameServer")
  99. DHCP_OPT_TCPIP ("DhcpNameServer"))
  100. TRV_DW ("15", "KeyType", 1)
  101. TRV_MSZ("15", "RegLocation", DHCP_OPT_TCPIP_INTERFACE("DhcpDomain")
  102. DHCP_OPT_TCPIP ("DhcpDomain"))
  103. TRV_DW ("44", "KeyType", 1)
  104. TRV_MSZ("44", "RegLocation", DHCP_OPT_NETBT_INTERFACE("DhcpNameServerList")
  105. DHCP_OPT_NETBT_ADAPTER ("DhcpNameServer"))
  106. TRV_DW ("46", "KeyType", 4)
  107. TRV_SZ ("46", "RegLocation", DHCP_OPT_NETBT("DhcpNodeType"))
  108. TRV_DW ("47", "KeyType", 1)
  109. TRV_SZ ("47", "RegLocation", DHCP_OPT_NETBT("DhcpScopeID"))
  110. TRV_DW ("DhcpNetbiosOptions", "KeyType", 4)
  111. TRV_DW ("DhcpNetbiosOptions", "OptionId", 1)
  112. TRV_DW ("DhcpNetbiosOptions", "VendorType", 1)
  113. TRV_MSZ("DhcpNetbiosOptions", "RegLocation", DHCP_OPT_NETBT_INTERFACE("DhcpNetbiosOptions"))
  114. TRV_END()
  115. };
  116. CONST TR_KEY_DESCRIPTOR DhcpParameterOptions =
  117. {
  118. HKEY_LOCAL_MACHINE,
  119. "SYSTEM\\CurrentControlSet\\Services\\Dhcp\\Parameters\\Options",
  120. FALSE,
  121. DhcpParameterOptions_Values
  122. };
  123. CONST TR_VALUE_DESCRIPTOR DhcpParameter_Values [] =
  124. {
  125. TRV_ESZ(NULL, "ServiceDll", "%SystemRoot%\\System32\\dhcpcsvc.dll")
  126. TRV_END()
  127. };
  128. CONST TR_KEY_DESCRIPTOR DhcpParameters =
  129. {
  130. HKEY_LOCAL_MACHINE,
  131. "SYSTEM\\CurrentControlSet\\Services\\Dhcp\\Parameters",
  132. FALSE,
  133. DhcpParameter_Values
  134. };
  135. CONST TR_VALUE_DESCRIPTOR DnscacheParameter_Values [] =
  136. {
  137. TRV_ESZ(NULL, "ServiceDll", "%SystemRoot%\\System32\\dnsrslvr.dll")
  138. TRV_DEL(NULL, "AdapterTimeoutCacheTime")
  139. TRV_DEL(NULL, "CacheHashTableBucketSize")
  140. TRV_DEL(NULL, "CacheHashTableSize")
  141. TRV_DEL(NULL, "DefaultRegistrationRefreshInterval")
  142. TRV_DEL(NULL, "MaxCacheEntryTtlLimit")
  143. TRV_DEL(NULL, "MaxSoaCacheEntryTtlLimit")
  144. TRV_DEL(NULL, "NegativeCacheTime")
  145. TRV_DEL(NULL, "NegativeSoaCacheTime")
  146. TRV_DEL(NULL, "NetFailureCacheTime")
  147. TRV_DEL(NULL, "NetFailureErrorPopupLimit")
  148. TRV_END()
  149. };
  150. CONST TR_KEY_DESCRIPTOR DnscacheParameters =
  151. {
  152. HKEY_LOCAL_MACHINE,
  153. "SYSTEM\\CurrentControlSet\\Services\\Dnscache\\Parameters",
  154. FALSE,
  155. DnscacheParameter_Values
  156. };
  157. CONST TR_VALUE_DESCRIPTOR LmHostsParameter_Values [] =
  158. {
  159. TRV_ESZ(NULL, "ServiceDll", "%SystemRoot%\\System32\\lmhsvc.dll")
  160. TRV_END()
  161. };
  162. CONST TR_KEY_DESCRIPTOR LmHostsParameters =
  163. {
  164. HKEY_LOCAL_MACHINE,
  165. "SYSTEM\\CurrentControlSet\\Services\\LmHosts\\Parameters",
  166. FALSE,
  167. LmHostsParameter_Values
  168. };
  169. CONST TR_VALUE_DESCRIPTOR NetbtInterface_Values [] =
  170. {
  171. TRV_DEL(NULL, "EnableAdapterDomainNameRegistration")
  172. TRV_MSZ(NULL, "NameServerList", "")
  173. TRV_DW (NULL, "NetbiosOptions", 0)
  174. TRV_END()
  175. };
  176. CONST TR_KEY_DESCRIPTOR NetbtInterfaces =
  177. {
  178. HKEY_LOCAL_MACHINE,
  179. "SYSTEM\\CurrentControlSet\\Services\\Netbt\\Parameters\\Interfaces",
  180. TRUE,
  181. NetbtInterface_Values
  182. };
  183. CONST TR_VALUE_DESCRIPTOR NetbtParameter_Values [] =
  184. {
  185. TRV_DEL(NULL, "BacklogIncrement")
  186. TRV_DW (NULL, "BcastNameQueryCount", 3)
  187. TRV_DW (NULL, "BcastQueryTimeout", 750)
  188. TRV_DEL(NULL, "BroadcastAddress")
  189. TRV_DEL(NULL, "CachePerAdapterEnabled")
  190. TRV_DW (NULL, "CacheTimeout", 600000)
  191. TRV_DEL(NULL, "ConnectOnRequestedInterfaceOnly")
  192. TRV_DEL(NULL, "EnableDns")
  193. TRV_DEL(NULL, "EnableLmhosts")
  194. TRV_DEL(NULL, "EnableProxy")
  195. TRV_DEL(NULL, "EnableProxyRegCheck")
  196. TRV_DEL(NULL, "InitialRefreshT.O.")
  197. TRV_DEL(NULL, "LmhostsTimeout")
  198. TRV_DEL(NULL, "MaxConnBackLog")
  199. TRV_DEL(NULL, "MaxDgramBuffering")
  200. TRV_DEL(NULL, "MaxPreloadEntries")
  201. TRV_DEL(NULL, "MinimumFreeLowerConnections")
  202. TRV_DEL(NULL, "MinimumRefreshSleepTime")
  203. TRV_DW (NULL, "NameServerPort", 137)
  204. TRV_DW (NULL, "NameSrvQueryCount", 3)
  205. TRV_DW (NULL, "NameSrvQueryTimeout", 1500)
  206. TRV_SZ (NULL, "NbProvider", "_tcp")
  207. TRV_DEL(NULL, "NodeType")
  208. TRV_DEL(NULL, "NoNameReleaseOnDemand")
  209. TRV_DEL(NULL, "RandomAdapter")
  210. TRV_DEL(NULL, "RefreshOpCode")
  211. TRV_DEL(NULL, "ScopeId")
  212. TRV_DW (NULL, "SessionKeepAlive", 3600000)
  213. TRV_DEL(NULL, "SingleResponse")
  214. TRV_DW (NULL, "Size/Small/Medium/Large", 1)
  215. TRV_DEL(NULL, "SmbDeviceEnabled")
  216. TRV_SZ (NULL, "TransportBindName", "\\Device\\")
  217. TRV_DEL(NULL, "TryAllIpAddrs")
  218. TRV_DEL(NULL, "TryAllNameServers")
  219. TRV_DEL(NULL, "UseDnsOnlyForNameResolutions")
  220. TRV_DEL(NULL, "WinsDownTimeout")
  221. TRV_END()
  222. };
  223. CONST TR_KEY_DESCRIPTOR NetbtParameters =
  224. {
  225. HKEY_LOCAL_MACHINE,
  226. "SYSTEM\\CurrentControlSet\\Services\\Netbt\\Parameters",
  227. FALSE,
  228. NetbtParameter_Values
  229. };
  230. CONST TR_VALUE_DESCRIPTOR NlaParameter_Values [] =
  231. {
  232. TRV_ESZ(NULL, "ServiceDll", "%SystemRoot%\\System32\\mswsock.dll")
  233. TRV_END()
  234. };
  235. CONST TR_KEY_DESCRIPTOR NlaParameters =
  236. {
  237. HKEY_LOCAL_MACHINE,
  238. "SYSTEM\\CurrentControlSet\\Services\\Nla\\Parameters",
  239. FALSE,
  240. NlaParameter_Values
  241. };
  242. typedef enum {
  243. TrAddressTypeTcpipValue,
  244. TrDefaultGatewayMetricTcpipValue,
  245. TrDisableDynamicUpdateTcpipValue,
  246. TrDontAddDefaultGatewayTcpipValue,
  247. TrEnableDhcpTcpipValue,
  248. TrNameServerTcpipValue,
  249. TrRawIpAllowedProtocolsTcpipValue,
  250. TrTcpAllowedPortsTcpipValue,
  251. TrUdpAllowedPortsTcpipValue,
  252. TrEnableDeadGwDetectTcpipValue,
  253. } TR_TCPIP_VALUE;
  254. TR_CONDITIONAL_ROUTINE TrTcpipWanConditionalRoutine;
  255. TR_CONDITIONAL_ROUTINE TrTcpipRrasConditionalRoutine;
  256. CONST TR_VALUE_DESCRIPTOR TcpipInterface_Values [] =
  257. {
  258. TRV_COND(NULL, "AddressType",
  259. TrTcpipWanConditionalRoutine,
  260. TrAddressTypeTcpipValue)
  261. TRV_MSZ (NULL, "DefaultGateway", "")
  262. TRV_COND(NULL, "DefaultGatewayMetric",
  263. TrTcpipWanConditionalRoutine,
  264. TrDefaultGatewayMetricTcpipValue)
  265. TRV_COND(NULL, "DisableDynamicUpdate",
  266. TrTcpipWanConditionalRoutine,
  267. TrDisableDynamicUpdateTcpipValue)
  268. TRV_DEL (NULL, "DisableReverseAddressRegistrations")
  269. TRV_COND(NULL, "DontAddDefaultGateway",
  270. TrTcpipRrasConditionalRoutine,
  271. TrDontAddDefaultGatewayTcpipValue)
  272. TRV_COND(NULL, "EnableDhcp",
  273. TrTcpipWanConditionalRoutine,
  274. TrEnableDhcpTcpipValue)
  275. TRV_MSZ (NULL, "IpAddress", "0.0.0.0\0")
  276. TRV_DEL (NULL, "IpAutoconfigurationAddress")
  277. TRV_DEL (NULL, "IpAutoconfigurationEnabled")
  278. TRV_DEL (NULL, "IpAutoconfigurationMask")
  279. TRV_DEL (NULL, "IpAutoconfigurationSeed")
  280. TRV_DEL (NULL, "IpAutoconfigurationSubnet")
  281. TRV_DEL (NULL, "MaxForwardPending")
  282. TRV_DEL (NULL, "Mtu")
  283. TRV_COND(NULL, "NameServer",
  284. TrTcpipWanConditionalRoutine,
  285. TrNameServerTcpipValue)
  286. TRV_DEL (NULL, "PerformRouterDiscovery")
  287. TRV_DEL (NULL, "PerformRouterDiscoveryBackup")
  288. TRV_DEL (NULL, "PptpFiltering")
  289. TRV_COND(NULL, "RawIpAllowedProtocols",
  290. TrTcpipWanConditionalRoutine,
  291. TrRawIpAllowedProtocolsTcpipValue)
  292. TRV_DEL (NULL, "SolicitationAddressBcast")
  293. TRV_MSZ (NULL, "SubnetMask", "0.0.0.0\0")
  294. TRV_COND(NULL, "TcpAllowedPorts",
  295. TrTcpipWanConditionalRoutine,
  296. TrTcpAllowedPortsTcpipValue)
  297. TRV_DEL (NULL, "TcpDelAckTicks")
  298. TRV_DEL (NULL, "TcpInitialRtt")
  299. TRV_DEL (NULL, "TcpWindowSize")
  300. TRV_DEL (NULL, "TypeOfInterface")
  301. TRV_COND(NULL, "UdpAllowedPorts",
  302. TrTcpipWanConditionalRoutine,
  303. TrUdpAllowedPortsTcpipValue)
  304. TRV_DW (NULL, "UseZeroBroadcast", 0)
  305. TRV_END ()
  306. };
  307. CONST TR_KEY_DESCRIPTOR TcpipInterfaces =
  308. {
  309. HKEY_LOCAL_MACHINE,
  310. "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces",
  311. TRUE,
  312. TcpipInterface_Values
  313. };
  314. CONST TR_VALUE_DESCRIPTOR TcpipParameter_Values [] =
  315. {
  316. TRV_DEL (NULL, "AllowUnqualifiedQuery")
  317. TRV_DEL (NULL, "AllowUserRawAccess")
  318. TRV_DEL (NULL, "ArpAlwaysSourceRoute")
  319. TRV_DEL (NULL, "ArpCacheLife")
  320. TRV_DEL (NULL, "ArpCacheMinReferencedLife")
  321. TRV_DEL (NULL, "ArpRetryCount")
  322. TRV_DEL (NULL, "ArpTrSingleRoute")
  323. TRV_DEL (NULL, "ArpUseEtherSnap")
  324. TRV_ESZ (NULL, "DatabasePath", "%SystemRoot%\\System32\\drivers\\etc")
  325. TRV_DEL (NULL, "DefaultRegistrationTtl")
  326. TRV_DEL (NULL, "DefaultTosValue")
  327. TRV_DEL (NULL, "DefaultTtl")
  328. TRV_DEL (NULL, "DisableDhcpMediaSense")
  329. TRV_DEL (NULL, "DisableDynamicUpdate")
  330. TRV_DEL (NULL, "DisableIpSourceRouting")
  331. TRV_DEL (NULL, "DisableMediaSenseEventLog")
  332. TRV_DEL (NULL, "DisableReplaceAddressesInConflicts")
  333. TRV_DEL (NULL, "DisableTaskOffload")
  334. TRV_DEL (NULL, "DisableUserTosSetting")
  335. TRV_DEL (NULL, "DisjointNameSpace")
  336. TRV_DEL (NULL, "DontAddDefaultGatewayDefault")
  337. TRV_DEL (NULL, "DnsQueryTimeouts")
  338. TRV_DEL (NULL, "EnableAddrMaskReply")
  339. TRV_DEL (NULL, "EnableBcastArpReply")
  340. TRV_COND(NULL, "EnableDeadGwDetect",
  341. TrTcpipRrasConditionalRoutine,
  342. TrEnableDeadGwDetectTcpipValue)
  343. TRV_DEL (NULL, "EnableFastRouteLookup")
  344. TRV_DEL (NULL, "EnableIcmpRedirect")
  345. TRV_DEL (NULL, "EnableMulticastForwarding")
  346. TRV_DEL (NULL, "EnablePmtuBhDetect")
  347. TRV_DEL (NULL, "EnablePmtuDiscovery")
  348. TRV_DEL (NULL, "EnableSecurityFilters")
  349. TRV_DEL (NULL, "FfpControlFlags")
  350. TRV_DEL (NULL, "FfpFastForwardingCacheSize")
  351. TRV_DW (NULL, "ForwardBroadcasts", 0)
  352. TRV_DEL (NULL, "ForwardBufferMemory")
  353. TRV_DEL (NULL, "GlobalMaxTcpWindowSize")
  354. TRV_DEL (NULL, "IgmpLevel")
  355. TRV_DEL (NULL, "IpAutoconfigurationEnabled")
  356. TRV_DEL (NULL, "IpAutoconfigurationMask")
  357. TRV_DEL (NULL, "IpAutoconfigurationSeed")
  358. TRV_DW (NULL, "IpEnableRouter", 0)
  359. TRV_DEL (NULL, "IpEnableRouterBackup")
  360. TRV_DEL (NULL, "KeepAliveInterval")
  361. TRV_DEL (NULL, "KeepAliveTime")
  362. TRV_SZ (NULL, "NameServer", "")
  363. TRV_DEL (NULL, "MaxForwardBufferMemory")
  364. TRV_DEL (NULL, "MaxFreeTWTcbs")
  365. TRV_DEL (NULL, "MaxFreeTcbs")
  366. TRV_DEL (NULL, "MaxHashTableSize")
  367. TRV_DEL (NULL, "MaxNormLookupMemory")
  368. TRV_DEL (NULL, "MaxNumForwardPackets")
  369. TRV_DEL (NULL, "MaxUserPort")
  370. TRV_DEL (NULL, "NumForwardPackets")
  371. TRV_DEL (NULL, "NumTcbTablePartitions")
  372. TRV_DEL (NULL, "PptpTcpMaxDataRetransmissions")
  373. TRV_DEL (NULL, "PrioritizeRecordData")
  374. TRV_DEL (NULL, "QueryIpMatching")
  375. TRV_DEL (NULL, "SackOpts")
  376. TRV_DEL (NULL, "SearchList")
  377. TRV_DEL (NULL, "SynAttackProtect")
  378. TRV_DEL (NULL, "Tcp1323Opts")
  379. TRV_DEL (NULL, "TcpMaxConnectResponseRetransmissions")
  380. TRV_DEL (NULL, "TcpMaxConnectRetransmissions")
  381. TRV_DEL (NULL, "TcpMaxDataRetransmissions")
  382. TRV_DEL (NULL, "TcpMaxDupAcks")
  383. TRV_DEL (NULL, "TcpMaxHalfOpen")
  384. TRV_DEL (NULL, "TcpMaxHalfOpenRetried")
  385. TRV_DEL (NULL, "TcpMaxPortsExhausted")
  386. TRV_DEL (NULL, "TcpMaxSendFree")
  387. TRV_DEL (NULL, "TcpNumConnections")
  388. TRV_DEL (NULL, "TcpTimedWaitDelay")
  389. TRV_DEL (NULL, "TcpUseRfc1122UrgentPointer")
  390. TRV_DEL (NULL, "TcpWindowSize")
  391. TRV_DEL (NULL, "TrFunctionalMcastAddress")
  392. TRV_DEL (NULL, "UpdateSecurityLevel")
  393. TRV_DEL (NULL, "UseDomainNameDevolution")
  394. TRV_DW ("Winsock", "UseDelayedAcceptance", 0)
  395. TRV_END ()
  396. };
  397. CONST TR_KEY_DESCRIPTOR TcpipParameters =
  398. {
  399. HKEY_LOCAL_MACHINE,
  400. "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",
  401. FALSE,
  402. TcpipParameter_Values
  403. };
  404. CONST TR_VALUE_DESCRIPTOR TcpipPerformance_Values [] =
  405. {
  406. TRV_SZ (NULL, "Close", "CloseTcpIpPerformanceData")
  407. TRV_SZ (NULL, "Collect", "CollectTcpIpPerformanceData")
  408. TRV_SZ (NULL, "Library", "Perfctrs.dll")
  409. TRV_SZ (NULL, "Open", "OpenTcpIpPerformanceData")
  410. TRV_SZ (NULL, "Object List", "502 510 546 582 638 658")
  411. TRV_END()
  412. };
  413. CONST TR_KEY_DESCRIPTOR TcpipPerformance =
  414. {
  415. HKEY_LOCAL_MACHINE,
  416. "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Performance",
  417. FALSE,
  418. TcpipPerformance_Values
  419. };
  420. CONST TR_VALUE_DESCRIPTOR TcpipServiceProvider_Values [] =
  421. {
  422. TRV_DW (NULL, "Class", 8)
  423. TRV_DW (NULL, "DnsPriority", 2000)
  424. TRV_DW (NULL, "HostsPriority", 500)
  425. TRV_DW (NULL, "LocalPriority", 499)
  426. TRV_DW (NULL, "NetbtPriority", 2001)
  427. TRV_SZ (NULL, "Name", "TCP/IP")
  428. TRV_ESZ(NULL, "ProviderPath", "%SystemRoot%\\System32\\wsock32.dll")
  429. TRV_END()
  430. };
  431. CONST TR_KEY_DESCRIPTOR TcpipServiceProvider =
  432. {
  433. HKEY_LOCAL_MACHINE,
  434. "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\ServiceProvider",
  435. FALSE,
  436. TcpipServiceProvider_Values
  437. };
  438. CONST TR_KEY_DESCRIPTOR* TrRepairSet [] =
  439. {
  440. &DhcpParameterOptions,
  441. &DhcpParameters,
  442. &DnscacheParameters,
  443. &LmHostsParameters,
  444. &NetbtInterfaces,
  445. &NetbtParameters,
  446. &NlaParameters,
  447. &TcpipInterfaces,
  448. &TcpipParameters,
  449. &TcpipPerformance,
  450. &TcpipServiceProvider,
  451. NULL
  452. };
  453. #define SAM_DESIRED KEY_READ | KEY_WRITE | DELETE
  454. typedef enum _TR_LOG_ACTION {
  455. TR_ADDED,
  456. TR_DELETED,
  457. TR_RESET,
  458. } TR_LOG_ACTION;
  459. CONST PCSTR LogActionPrefix [] = {
  460. "added ",
  461. "deleted",
  462. "reset ",
  463. };
  464. typedef struct _TR_REPAIR_CONTEXT {
  465. HANDLE Heap;
  466. FILE *LogFile;
  467. PBYTE RegData;
  468. ULONG RegDataSize;
  469. CHAR EnumKeyName [MAX_PATH];
  470. } TR_REPAIR_CONTEXT, *PTR_REPAIR_CTX;
  471. BOOL
  472. TrInitializeRepairContext(
  473. IN PTR_REPAIR_CTX Ctx,
  474. IN FILE *LogFile
  475. )
  476. {
  477. ZeroMemory(Ctx, sizeof(TR_REPAIR_CONTEXT));
  478. Ctx->Heap = GetProcessHeap();
  479. Ctx->LogFile = LogFile;
  480. Ctx->RegDataSize = 1024;
  481. Ctx->RegData = HeapAlloc(Ctx->Heap, 0, Ctx->RegDataSize);
  482. *Ctx->EnumKeyName = 0;
  483. return (Ctx->RegData != NULL);
  484. }
  485. VOID
  486. TrCleanupRepairContext(
  487. IN PTR_REPAIR_CTX Ctx
  488. )
  489. {
  490. if (Ctx->RegData != NULL) {
  491. HeapFree(Ctx->Heap, 0, Ctx->RegData);
  492. Ctx->RegData = NULL;
  493. }
  494. }
  495. VOID
  496. TrLogAction(
  497. IN TR_LOG_ACTION Action,
  498. IN PTR_REPAIR_CTX Ctx,
  499. IN CONST TR_KEY_DESCRIPTOR *Kd,
  500. IN CONST TR_VALUE_DESCRIPTOR *Vd,
  501. IN DWORD RegType
  502. )
  503. {
  504. fprintf(Ctx->LogFile, "%s %s\\",
  505. LogActionPrefix[Action], Kd->ParentKeyName);
  506. if (Vd->SubKeyName != NULL) {
  507. fprintf(Ctx->LogFile, "%s\\", Vd->SubKeyName);
  508. }
  509. if (Kd->EnumKey) {
  510. fprintf(Ctx->LogFile, "%s\\", Ctx->EnumKeyName);
  511. }
  512. fprintf(Ctx->LogFile, "%s\n", Vd->ValueName);
  513. //
  514. // Show the value we are replacing.
  515. //
  516. if (TR_RESET == Action) {
  517. switch (RegType) {
  518. case REG_DWORD:
  519. fprintf(Ctx->LogFile, " old REG_DWORD = %d\n\n", *(PULONG)Ctx->RegData);
  520. break;
  521. case REG_EXPAND_SZ:
  522. fprintf(Ctx->LogFile, " old REG_EXPAND_SZ = %s\n\n", (PCSTR)Ctx->RegData);
  523. break;
  524. case REG_MULTI_SZ:
  525. {
  526. PCSTR Msz = (PCSTR)Ctx->RegData;
  527. fprintf(Ctx->LogFile, " old REG_MULTI_SZ =\n");
  528. if (*Msz) {
  529. while (*Msz) {
  530. fprintf(Ctx->LogFile, " %s\n", Msz);
  531. Msz += strlen(Msz) + 1;
  532. }
  533. } else {
  534. fprintf(Ctx->LogFile, " <empty>\n");
  535. }
  536. fprintf(Ctx->LogFile, "\n");
  537. break;
  538. }
  539. case REG_SZ:
  540. fprintf(Ctx->LogFile, " old REG_SZ = %s\n\n", (PCSTR)Ctx->RegData);
  541. break;
  542. default:
  543. break;
  544. }
  545. }
  546. }
  547. LONG
  548. TrReadRegData(
  549. IN PTR_REPAIR_CTX Ctx,
  550. IN HKEY Key,
  551. IN CONST TR_VALUE_DESCRIPTOR *Vd,
  552. OUT PULONG ReturnedSize
  553. )
  554. {
  555. LONG Error;
  556. ULONG Type, Size;
  557. *ReturnedSize = 0;
  558. Size = Ctx->RegDataSize;
  559. Error = RegQueryValueExA(Key, Vd->ValueName, NULL, &Type,
  560. Ctx->RegData, &Size);
  561. if (ERROR_MORE_DATA == Error) {
  562. HeapFree(Ctx->Heap, 0, Ctx->RegData);
  563. Ctx->RegDataSize = (Size + 63) & ~63;
  564. Ctx->RegData = HeapAlloc(Ctx->Heap, 0, Ctx->RegDataSize);
  565. if (Ctx->RegData != NULL) {
  566. Size = Ctx->RegDataSize;
  567. Error = RegQueryValueExA(Key, Vd->ValueName, NULL, &Type,
  568. Ctx->RegData, &Size);
  569. if (NOERROR != Error) {
  570. fprintf(Ctx->LogFile,
  571. " RegQueryValueEx still failed. error = %d\n",
  572. Error);
  573. } else {
  574. *ReturnedSize = Size;
  575. }
  576. } else {
  577. Error = ERROR_NOT_ENOUGH_MEMORY;
  578. }
  579. } else if (NOERROR == Error) {
  580. *ReturnedSize = Size;
  581. }
  582. return Error;
  583. }
  584. VOID
  585. TrSetRegData(
  586. IN HKEY Key,
  587. IN CONST TR_VALUE_DESCRIPTOR *Vd,
  588. IN DWORD RegType,
  589. IN TR_VALUE_DATA* Data,
  590. IN DWORD DataSize
  591. )
  592. {
  593. RegSetValueExA(Key, Vd->ValueName, 0, RegType,
  594. (REG_DWORD == RegType) ? (CONST BYTE*)&Data->Value
  595. : Data->Pointer,
  596. DataSize);
  597. }
  598. VOID
  599. TrProcessOpenKey(
  600. IN PTR_REPAIR_CTX Ctx,
  601. IN HKEY ParentKey,
  602. IN CONST TR_KEY_DESCRIPTOR *Kd
  603. )
  604. {
  605. LONG Error = NOERROR;
  606. ULONG i, Size;
  607. CONST TR_VALUE_DESCRIPTOR *Vd, *PrevVd;
  608. HKEY SubKey, UseKey;
  609. DWORD RegType;
  610. TR_VALUE_DATA Data;
  611. DWORD DataSize;
  612. PrevVd = NULL;
  613. SubKey = INVALID_HANDLE_VALUE;
  614. for (i = 0; Kd->Value[i].ValueName != NULL; i++) {
  615. Vd = &Kd->Value[i];
  616. if (Vd->SubKeyName == NULL) {
  617. UseKey = ParentKey;
  618. Error = NOERROR;
  619. }
  620. //
  621. // Open a subkey if needed, and only if its not the same as
  622. // the one already open.
  623. //
  624. else if (((PrevVd == NULL) || (Vd->SubKeyName != PrevVd->SubKeyName))) {
  625. if (SubKey != INVALID_HANDLE_VALUE) {
  626. RegCloseKey(SubKey);
  627. }
  628. Error = RegOpenKeyExA(ParentKey, Vd->SubKeyName, 0,
  629. SAM_DESIRED, &SubKey);
  630. if (NOERROR == Error) {
  631. UseKey = SubKey;
  632. } else {
  633. SubKey = INVALID_HANDLE_VALUE;
  634. }
  635. }
  636. if (NOERROR == Error) {
  637. Error = TrReadRegData(Ctx, UseKey, Vd, &Size);
  638. }
  639. //
  640. // If the key is handled specially, consult its conditional-routine
  641. // to obtain the settings to be used below. From here onwards,
  642. // all processing for this value must use the local variables
  643. // 'RegType', 'Data', and 'DataSize' rather than the corresponding
  644. // fields of 'Vd'.
  645. //
  646. // (Also see 'TrSetRegData' and 'TrLogAction'.)
  647. //
  648. if (Vd->Conditional) {
  649. Vd->ConditionalRoutine(Ctx, Kd, Vd, &RegType, &Data, &DataSize);
  650. } else {
  651. RegType = Vd->RegType;
  652. Data = Vd->Data;
  653. DataSize = Vd->DataSize;
  654. }
  655. if (ERROR_FILE_NOT_FOUND == Error) {
  656. if (REG_DELETE != RegType) {
  657. //
  658. // The value should exist, so set its default value.
  659. //
  660. TrSetRegData(UseKey, Vd, RegType, &Data, DataSize);
  661. TrLogAction(TR_ADDED, Ctx, Kd, Vd, RegType);
  662. }
  663. } else if (NOERROR == Error) {
  664. //
  665. // The value exists and we read its data.
  666. //
  667. if (REG_DELETE == RegType) {
  668. //
  669. // Need to delete the existing value.
  670. //
  671. RegDeleteValueA(UseKey, Vd->ValueName);
  672. TrLogAction(TR_DELETED, Ctx, Kd, Vd, RegType);
  673. } else {
  674. BOOL MisCompare = TRUE;
  675. //
  676. // Compare the value we read with the default value and reset
  677. // it if it is different.
  678. //
  679. if (Size == DataSize) {
  680. if (REG_DWORD == RegType) {
  681. MisCompare = (*(PULONG)Ctx->RegData != Data.Value);
  682. } else {
  683. MisCompare = memcmp(Ctx->RegData, Data.Pointer,
  684. Size);
  685. }
  686. }
  687. if (MisCompare) {
  688. TrSetRegData(UseKey, Vd, RegType, &Data, DataSize);
  689. TrLogAction(TR_RESET, Ctx, Kd, Vd, RegType);
  690. }
  691. }
  692. } else {
  693. fprintf(Ctx->LogFile, "\nerror reading registry value (%s) (%d)\n", Vd->ValueName, Error);
  694. }
  695. PrevVd = Vd;
  696. }
  697. if (SubKey != INVALID_HANDLE_VALUE) {
  698. RegCloseKey(SubKey);
  699. }
  700. }
  701. VOID
  702. TrProcessKey(
  703. IN PTR_REPAIR_CTX Ctx,
  704. IN CONST TR_KEY_DESCRIPTOR *Kd
  705. )
  706. {
  707. LONG Error;
  708. HKEY ParentKey;
  709. Error = RegOpenKeyExA(Kd->RootKey, Kd->ParentKeyName, 0,
  710. SAM_DESIRED, &ParentKey);
  711. if (NOERROR == Error) {
  712. if (Kd->EnumKey) {
  713. ULONG i;
  714. ULONG EnumKeyNameLen;
  715. FILETIME LastWriteTime;
  716. HKEY SubKey;
  717. for (i = 0; NOERROR == Error; i++) {
  718. EnumKeyNameLen = sizeof(Ctx->EnumKeyName);
  719. Error = RegEnumKeyExA(ParentKey, i, Ctx->EnumKeyName, &EnumKeyNameLen,
  720. NULL, NULL, NULL, &LastWriteTime);
  721. if (NOERROR != Error) {
  722. if (ERROR_NO_MORE_ITEMS != Error) {
  723. fprintf(Ctx->LogFile, "enum error = %d (index = %d)\n",
  724. Error, i);
  725. }
  726. break;
  727. }
  728. Error = RegOpenKeyExA(ParentKey, Ctx->EnumKeyName, 0,
  729. SAM_DESIRED, &SubKey);
  730. if (NOERROR == Error) {
  731. TrProcessOpenKey(Ctx, SubKey, Kd);
  732. RegCloseKey(SubKey);
  733. }
  734. }
  735. } else {
  736. TrProcessOpenKey(Ctx, ParentKey, Kd);
  737. }
  738. RegCloseKey(ParentKey);
  739. }
  740. }
  741. VOID
  742. TrProcessSet(
  743. IN PTR_REPAIR_CTX Ctx,
  744. IN CONST TR_KEY_DESCRIPTOR *Set[]
  745. )
  746. {
  747. ULONG i;
  748. //
  749. // Process each TR_KEY_DESCRIPTOR element in the set.
  750. //
  751. for (i = 0; Set[i] != NULL; i++) {
  752. TrProcessKey(Ctx, Set[i]);
  753. }
  754. }
  755. DWORD
  756. TrRepair(
  757. FILE* LogFile
  758. )
  759. {
  760. TR_REPAIR_CONTEXT Ctx;
  761. if (TrInitializeRepairContext(&Ctx, LogFile)) {
  762. TrProcessSet(&Ctx, TrRepairSet);
  763. NetCfgDiagRepairRegistryBindings(LogFile);
  764. TrCleanupRepairContext(&Ctx);
  765. }
  766. return NOERROR;
  767. }
  768. BOOLEAN
  769. IsRrasInstalled(
  770. IN CONST struct _TR_REPAIR_CONTEXT *Ctx,
  771. IN CONST struct _TR_KEY_DESCRIPTOR *Kd
  772. )
  773. {
  774. ULONG Error;
  775. BOOLEAN RrasInstalled;
  776. HKEY RrasKey;
  777. CONST CHAR RrasKeyName[] =
  778. "SYSTEM\\CurrentControlSet\\Services\\RemoteAccess";
  779. Error = RegOpenKeyExA(Kd->RootKey, RrasKeyName, 0, SAM_DESIRED, &RrasKey);
  780. if (NOERROR != Error) {
  781. RrasInstalled = FALSE;
  782. } else {
  783. DWORD ConfigurationFlags;
  784. DWORD Size;
  785. DWORD Type;
  786. Size = sizeof(DWORD);
  787. Error = RegQueryValueExA(RrasKey, "ConfigurationFlags", NULL, &Type,
  788. (LPBYTE)&ConfigurationFlags, &Size);
  789. if (NOERROR != Error) {
  790. RrasInstalled = FALSE;
  791. } else {
  792. RrasInstalled = (ConfigurationFlags != 0);
  793. }
  794. RegCloseKey(RrasKey);
  795. }
  796. return RrasInstalled;
  797. }
  798. BOOLEAN
  799. IsWanInterface(
  800. IN CONST struct _TR_REPAIR_CONTEXT *Ctx,
  801. IN CONST struct _TR_KEY_DESCRIPTOR *Kd
  802. )
  803. {
  804. HKEY AdaptersKey;
  805. CONST CHAR AdaptersKeyName[] =
  806. "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Adapters";
  807. LONG Error;
  808. BOOLEAN IsWan;
  809. HKEY Key;
  810. //
  811. // Open the TCP/IP adapters key.
  812. // If successful, look for a subkey with the same name
  813. // as the one in 'Kd'. If present, this is not a LAN interface.
  814. //
  815. Error = RegOpenKeyExA(Kd->RootKey, AdaptersKeyName, 0, SAM_DESIRED,
  816. &AdaptersKey);
  817. if (NOERROR != Error) {
  818. //
  819. // Assume this is a LAN interface.
  820. //
  821. IsWan = FALSE;
  822. } else {
  823. Error = RegOpenKeyExA(AdaptersKey, Ctx->EnumKeyName, 0, SAM_DESIRED,
  824. &Key);
  825. if (NOERROR != Error) {
  826. IsWan = TRUE;
  827. } else {
  828. IsWan = FALSE;
  829. RegCloseKey(Key);
  830. }
  831. RegCloseKey(AdaptersKey);
  832. }
  833. return IsWan;
  834. }
  835. VOID
  836. TrTcpipWanConditionalRoutine(
  837. IN CONST struct _TR_REPAIR_CONTEXT *Ctx,
  838. IN CONST struct _TR_KEY_DESCRIPTOR *Kd,
  839. IN CONST struct _TR_VALUE_DESCRIPTOR *Vd,
  840. OUT DWORD *RegType,
  841. OUT TR_VALUE_DATA *Data,
  842. OUT DWORD *DataSize
  843. )
  844. {
  845. //
  846. // Return the appropriate setting for the given registry value,
  847. // based on whether its key is for a WAN or LAN interface.
  848. //
  849. if (IsWanInterface(Ctx, Kd)) {
  850. switch((TR_TCPIP_VALUE)Vd->ConditionalData.Value) {
  851. case TrAddressTypeTcpipValue:
  852. case TrDefaultGatewayMetricTcpipValue:
  853. case TrDisableDynamicUpdateTcpipValue:
  854. case TrNameServerTcpipValue:
  855. case TrRawIpAllowedProtocolsTcpipValue:
  856. case TrTcpAllowedPortsTcpipValue:
  857. case TrUdpAllowedPortsTcpipValue:
  858. default:
  859. *RegType = REG_DELETE;
  860. break;
  861. case TrEnableDhcpTcpipValue:
  862. case TrDontAddDefaultGatewayTcpipValue:
  863. *RegType = REG_DWORD;
  864. Data->Value = 0;
  865. *DataSize = sizeof(DWORD);
  866. break;
  867. }
  868. } else {
  869. switch((TR_TCPIP_VALUE)Vd->ConditionalData.Value) {
  870. case TrDontAddDefaultGatewayTcpipValue:
  871. default:
  872. *RegType = REG_DELETE;
  873. break;
  874. case TrAddressTypeTcpipValue:
  875. case TrDisableDynamicUpdateTcpipValue:
  876. *RegType = REG_DWORD;
  877. Data->Value = 0;
  878. *DataSize = sizeof(DWORD);
  879. break;
  880. case TrEnableDhcpTcpipValue:
  881. *RegType = REG_DWORD;
  882. Data->Value = 1;
  883. *DataSize = sizeof(DWORD);
  884. break;
  885. case TrNameServerTcpipValue:
  886. *RegType = REG_SZ;
  887. Data->Pointer = Empty;
  888. *DataSize = sizeof(Empty);
  889. break;
  890. case TrDefaultGatewayMetricTcpipValue:
  891. case TrRawIpAllowedProtocolsTcpipValue:
  892. case TrTcpAllowedPortsTcpipValue:
  893. case TrUdpAllowedPortsTcpipValue:
  894. *RegType = REG_MULTI_SZ;
  895. Data->Pointer = Empty;
  896. *DataSize = sizeof(Empty);
  897. break;
  898. }
  899. }
  900. }
  901. VOID
  902. TrTcpipRrasConditionalRoutine(
  903. IN CONST struct _TR_REPAIR_CONTEXT *Ctx,
  904. IN CONST struct _TR_KEY_DESCRIPTOR *Kd,
  905. IN CONST struct _TR_VALUE_DESCRIPTOR *Vd,
  906. OUT DWORD *RegType,
  907. OUT TR_VALUE_DATA *Data,
  908. OUT DWORD *DataSize
  909. )
  910. {
  911. //
  912. // Return the appropriate setting for the given registry value,
  913. // based on whether RRAS is installed.
  914. //
  915. // N.B. The setting for 'DontAddDefaultGateway' is further dependent
  916. // on whether the key is for a WAN or LAN interface.
  917. //
  918. if (IsRrasInstalled(Ctx, Kd)) {
  919. switch((TR_TCPIP_VALUE)Vd->ConditionalData.Value) {
  920. case TrDontAddDefaultGatewayTcpipValue:
  921. if (IsWanInterface(Ctx, Kd)) {
  922. *RegType = REG_DWORD;
  923. Data->Value = 1;
  924. *DataSize = sizeof(DWORD);
  925. } else {
  926. *RegType = REG_DELETE;
  927. }
  928. break;
  929. case TrEnableDeadGwDetectTcpipValue:
  930. *RegType = REG_DWORD;
  931. Data->Value = 0;
  932. *DataSize = sizeof(DWORD);
  933. break;
  934. default:
  935. *RegType = REG_DELETE;
  936. break;
  937. }
  938. } else {
  939. switch((TR_TCPIP_VALUE)Vd->ConditionalData.Value) {
  940. case TrDontAddDefaultGatewayTcpipValue:
  941. case TrEnableDeadGwDetectTcpipValue:
  942. default:
  943. *RegType = REG_DELETE;
  944. break;
  945. }
  946. }
  947. }