Author: cgutman
Date: Fri Jul 23 22:30:27 2010
New Revision: 48215
URL:
http://svn.reactos.org/svn/reactos?rev=48215&view=rev
Log:
[NETCFGX]
- Create the DhcpEnabled value in the registry
[TCPIP]
- Apply the static IP address configuration data
[DHCPCSVC]
- Remove the static IP address code
Modified:
trunk/reactos/dll/win32/dhcpcsvc/dhcp/adapter.c
trunk/reactos/dll/win32/netcfgx/netcfgx.c
trunk/reactos/drivers/network/tcpip/datalink/lan.c
Modified: trunk/reactos/dll/win32/dhcpcsvc/dhcp/adapter.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/dhcpcsvc/dhcp/ad…
==============================================================================
--- trunk/reactos/dll/win32/dhcpcsvc/dhcp/adapter.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/dhcpcsvc/dhcp/adapter.c [iso-8859-1] Fri Jul 23 22:30:27 2010
@@ -102,7 +102,8 @@
"SYSTEM\\CurrentControlSet\\Control\\Class\\"
"{4D36E972-E325-11CE-BFC1-08002BE10318}";
PCHAR TargetKeyNameStart =
-
"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
+ "SYSTEM\\CurrentControlSet\\Services\\";
+ PCHAR TargetKeyNameEnd = "\\Parameters\\Tcpip";
PCHAR TargetKeyName = NULL;
PCHAR *EnumKeysLinkage = GetSubkeyNames( EnumKeyName, "\\Linkage" );
PCHAR *EnumKeysTop = GetSubkeyNames( EnumKeyName, "" );
@@ -124,10 +125,10 @@
!strcmp( RootDevice, Adapter->DhclientInfo.name ) ) {
TargetKeyName =
(CHAR*) malloc( strlen( TargetKeyNameStart ) +
- strlen( RootDevice ) + 1);
+ strlen( RootDevice ) + strlen( TargetKeyNameEnd ) + 1);
if( !TargetKeyName ) goto cleanup;
- sprintf( TargetKeyName, "%s%s",
- TargetKeyNameStart, RootDevice );
+ sprintf( TargetKeyName, "%s%s%s",
+ TargetKeyNameStart, RootDevice, TargetKeyNameEnd );
Error = RegCreateKeyExA( HKEY_LOCAL_MACHINE, TargetKeyName, 0, NULL, 0,
KEY_READ, NULL, &OutKey, NULL );
break;
} else {
@@ -145,10 +146,8 @@
}
BOOL PrepareAdapterForService( PDHCP_ADAPTER Adapter ) {
- HKEY AdapterKey = NULL;
- PCHAR IPAddress = NULL, Netmask = NULL, DefaultGateway = NULL;
- NTSTATUS Status = STATUS_SUCCESS;
- DWORD Error = ERROR_SUCCESS;
+ HKEY AdapterKey;
+ DWORD Error = ERROR_SUCCESS, DhcpEnabled;
Adapter->DhclientState.config = &Adapter->DhclientConfig;
strncpy(Adapter->DhclientInfo.name, (char*)Adapter->IfMib.bDescr,
@@ -156,53 +155,31 @@
AdapterKey = FindAdapterKey( Adapter );
if( AdapterKey )
- IPAddress = RegReadString( AdapterKey, NULL, "IPAddress" );
-
- if( IPAddress && strcmp( IPAddress, "0.0.0.0" ) ) {
+ {
+ Error = RegQueryValueEx(AdapterKey, "DhcpEnabled", NULL, NULL,
(LPBYTE)&DhcpEnabled, NULL);
+
+ if (Error != ERROR_SUCCESS)
+ DhcpEnabled = 1;
+
+ CloseHandle(AdapterKey);
+ }
+ else
+ {
+ /* DHCP enabled by default */
+ DhcpEnabled = 1;
+ }
+
+ if( !DhcpEnabled ) {
/* Non-automatic case */
- DH_DbgPrint
- (MID_TRACE,("Adapter Name: [%s] (Bind Status %x) (static %s)\n",
- Adapter->DhclientInfo.name,
- Adapter->BindStatus,
- IPAddress));
+ DbgPrint("DHCPCSVC: Adapter Name: [%s] (static)\n",
Adapter->DhclientInfo.name);
Adapter->DhclientState.state = S_STATIC;
-
- Netmask = RegReadString( AdapterKey, NULL, "Subnetmask" );
-
- Status = AddIPAddress( inet_addr( IPAddress ),
- inet_addr( Netmask ? Netmask : "255.255.255.0"
),
- Adapter->IfMib.dwIndex,
- &Adapter->NteContext,
- &Adapter->NteInstance );
-
- DefaultGateway = RegReadString( AdapterKey, NULL, "DefaultGateway" );
-
- if( DefaultGateway ) {
- Adapter->RouterMib.dwForwardDest = 0;
- Adapter->RouterMib.dwForwardMask = 0;
- Adapter->RouterMib.dwForwardMetric1 = 1;
- Adapter->RouterMib.dwForwardIfIndex = Adapter->IfMib.dwIndex;
- Adapter->RouterMib.dwForwardNextHop = inet_addr(DefaultGateway);
- Error = CreateIpForwardEntry( &Adapter->RouterMib );
- if( Error )
- warning("Failed to set default gateway %s: %ld\n",
- DefaultGateway, Error);
- }
-
- if( DefaultGateway ) free( DefaultGateway );
- if( Netmask ) free( Netmask );
} else {
/* Automatic case */
- DH_DbgPrint
- (MID_TRACE,("Adapter Name: [%s] (Bind Status %x) (dynamic)\n",
- Adapter->DhclientInfo.name,
- Adapter->BindStatus));
+ DbgPrint("DHCPCSVC: Adapter Name: [%s] (dynamic)\n",
Adapter->DhclientInfo.name);
Adapter->DhclientInfo.client->state = S_INIT;
}
-
- if( IPAddress ) free( IPAddress );
return TRUE;
}
@@ -350,7 +327,6 @@
ApiLock();
InsertTailList( &AdapterList, &Adapter->ListEntry );
- DbgPrint("DHCPCSVC: Discovered new adapter [%s]\n",
Adapter->DhclientInfo.name);
AdapterCount++;
SetEvent(AdapterStateChangedEvent);
ApiUnlock();
Modified: trunk/reactos/dll/win32/netcfgx/netcfgx.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/netcfgx/netcfgx.…
==============================================================================
--- trunk/reactos/dll/win32/netcfgx/netcfgx.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/netcfgx/netcfgx.c [iso-8859-1] Fri Jul 23 22:30:27 2010
@@ -336,7 +336,7 @@
HKEY hNetworkKey = NULL;
HKEY hLinkageKey = NULL;
HKEY hConnectionKey = NULL;
- DWORD dwShowIcon, dwLength;
+ DWORD dwShowIcon, dwLength, dwValue;
/* Get Instance ID */
if (SetupDiGetDeviceInstanceIdW(DeviceInfoSet, DeviceInfoData, NULL, 0, &dwLength))
@@ -417,6 +417,13 @@
goto cleanup;
}
rc = RegSetValueExW(hKey, L"SubnetMask", 0, REG_SZ, (const
BYTE*)L"0.0.0.0", (wcslen(L"0.0.0.0") + 1) * sizeof(WCHAR));
+ if (rc != ERROR_SUCCESS)
+ {
+ DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
+ goto cleanup;
+ }
+ dwValue = 1;
+ rc = RegSetValueExW(hKey, L"DhcpEnabled", 0, REG_DWORD, (const
BYTE*)&dwValue, sizeof(DWORD));
if (rc != ERROR_SUCCESS)
{
DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
Modified: trunk/reactos/drivers/network/tcpip/datalink/lan.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/network/tcpip/data…
==============================================================================
--- trunk/reactos/drivers/network/tcpip/datalink/lan.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/network/tcpip/datalink/lan.c [iso-8859-1] Fri Jul 23 22:30:27
2010
@@ -946,9 +946,17 @@
PIP_INTERFACE IF;
NDIS_STATUS NdisStatus;
LLIP_BIND_INFO BindInfo;
- IP_ADDRESS DefaultMask;
- ULONG Lookahead = LOOKAHEAD_SIZE;
+ IP_ADDRESS DefaultMask, Router;
+ ULONG Lookahead = LOOKAHEAD_SIZE, Unused;
NTSTATUS Status;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ HANDLE ParameterHandle;
+ PKEY_VALUE_PARTIAL_INFORMATION KeyValueInfo;
+ UNICODE_STRING IPAddress = RTL_CONSTANT_STRING(L"IPAddress");
+ UNICODE_STRING Netmask = RTL_CONSTANT_STRING(L"SubnetMask");
+ UNICODE_STRING Gateway = RTL_CONSTANT_STRING(L"DefaultGateway");
+ UNICODE_STRING RegistryDataU;
+ ANSI_STRING RegistryDataA;
TI_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
@@ -1001,10 +1009,105 @@
TI_DbgPrint(DEBUG_DATALINK,("Adapter Description: %wZ\n",
&IF->Description));
+ DbgPrint("Opening %wZ\n", RegistryPath);
+
+ InitializeObjectAttributes(&ObjectAttributes,
+ RegistryPath,
+ OBJ_CASE_INSENSITIVE,
+ 0,
+ NULL);
+
AddrInitIPv4(&DefaultMask, 0);
- IF->Unicast = DefaultMask;
- IF->Netmask = DefaultMask;
+ Status = ZwOpenKey(&ParameterHandle, KEY_READ, &ObjectAttributes);
+ if (!NT_SUCCESS(Status))
+ {
+ IF->Unicast = DefaultMask;
+ IF->Netmask = DefaultMask;
+ }
+ else
+ {
+ KeyValueInfo = ExAllocatePool(PagedPool, sizeof(KEY_VALUE_PARTIAL_INFORMATION) +
16 * sizeof(WCHAR));
+ if (!KeyValueInfo)
+ {
+ ZwClose(ParameterHandle);
+ IPDestroyInterface(IF);
+ return FALSE;
+ }
+
+ RegistryDataU.MaximumLength = 16 + sizeof(WCHAR);
+ RegistryDataU.Buffer = (PWCHAR)KeyValueInfo->Data;
+
+ Status = ZwQueryValueKey(ParameterHandle,
+ &IPAddress,
+ KeyValuePartialInformation,
+ KeyValueInfo,
+ sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 16 *
sizeof(WCHAR),
+ &Unused);
+ if (NT_SUCCESS(Status))
+ {
+ RegistryDataU.Length = KeyValueInfo->DataLength;
+
+ RtlUnicodeStringToAnsiString(&RegistryDataA,
+ &RegistryDataU,
+ TRUE);
+
+ AddrInitIPv4(&IF->Unicast, inet_addr(RegistryDataA.Buffer));
+
+ RtlFreeAnsiString(&RegistryDataA);
+
+ }
+ else
+ {
+ IF->Unicast = DefaultMask;
+ }
+
+ Status = ZwQueryValueKey(ParameterHandle,
+ &Netmask,
+ KeyValuePartialInformation,
+ KeyValueInfo,
+ sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 16 *
sizeof(WCHAR),
+ &Unused);
+ if (NT_SUCCESS(Status))
+ {
+ RegistryDataU.Length = KeyValueInfo->DataLength;
+
+ RtlUnicodeStringToAnsiString(&RegistryDataA,
+ &RegistryDataU,
+ TRUE);
+
+ AddrInitIPv4(&IF->Netmask, inet_addr(RegistryDataA.Buffer));
+
+ RtlFreeAnsiString(&RegistryDataA);
+ }
+ else
+ {
+ IF->Netmask = DefaultMask;
+ }
+
+ Status = ZwQueryValueKey(ParameterHandle,
+ &Gateway,
+ KeyValuePartialInformation,
+ KeyValueInfo,
+ sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 16 *
sizeof(WCHAR),
+ &Unused);
+ if (NT_SUCCESS(Status))
+ {
+ RegistryDataU.Length = KeyValueInfo->DataLength;
+
+ RtlUnicodeStringToAnsiString(&RegistryDataA,
+ &RegistryDataU,
+ TRUE);
+
+ AddrInitIPv4(&Router, inet_addr(RegistryDataA.Buffer));
+
+ RtlFreeAnsiString(&RegistryDataA);
+
+ if (!AddrIsUnspecified(&Router)) RouterCreateRoute(&DefaultMask,
&DefaultMask, &Router, IF, 1);
+ }
+
+ ZwClose(ParameterHandle);
+ }
IF->Broadcast.Type = IP_ADDRESS_V4;
IF->Broadcast.Address.IPv4Address =