- Fix epic naming fail (DhcpEnabled -> EnableDHCP
authorCameron Gutman <aicommander@gmail.com>
Sat, 24 Jul 2010 00:25:59 +0000 (00:25 +0000)
committerCameron Gutman <aicommander@gmail.com>
Sat, 24 Jul 2010 00:25:59 +0000 (00:25 +0000)
[DHCPCSVC]: Verify that the length is correct
[TCPIP]: Make sure DHCP is enabled before reading IP information

svn path=/trunk/; revision=48221

reactos/dll/win32/dhcpcsvc/dhcp/adapter.c
reactos/dll/win32/netcfgx/netcfgx.c
reactos/drivers/network/tcpip/datalink/lan.c

index ad18dfa..c0ba02d 100644 (file)
@@ -147,7 +147,7 @@ cleanup:
 
 BOOL PrepareAdapterForService( PDHCP_ADAPTER Adapter ) {
     HKEY AdapterKey;
-    DWORD Error = ERROR_SUCCESS, DhcpEnabled;
+    DWORD Error = ERROR_SUCCESS, DhcpEnabled, Length;
 
     Adapter->DhclientState.config = &Adapter->DhclientConfig;
     strncpy(Adapter->DhclientInfo.name, (char*)Adapter->IfMib.bDescr,
@@ -156,9 +156,9 @@ BOOL PrepareAdapterForService( PDHCP_ADAPTER Adapter ) {
     AdapterKey = FindAdapterKey( Adapter );
     if( AdapterKey )
     {
-        Error = RegQueryValueEx(AdapterKey, "DhcpEnabled", NULL, NULL, (LPBYTE)&DhcpEnabled, NULL);
+        Error = RegQueryValueEx(AdapterKey, "EnableDHCP", NULL, NULL, (LPBYTE)&DhcpEnabled, &Length);
 
-        if (Error != ERROR_SUCCESS)
+        if (Error != ERROR_SUCCESS || Length != sizeof(DWORD))
             DhcpEnabled = 1;
 
         CloseHandle(AdapterKey);
index d0df451..1fb9fc1 100644 (file)
@@ -423,7 +423,7 @@ InstallNetDevice(
                goto cleanup;
        }
         dwValue = 1;
-       rc = RegSetValueExW(hKey, L"DhcpEnabled", 0, REG_DWORD, (const BYTE*)&dwValue, sizeof(DWORD));
+       rc = RegSetValueExW(hKey, L"EnableDHCP", 0, REG_DWORD, (const BYTE*)&dwValue, sizeof(DWORD));
        if (rc != ERROR_SUCCESS)
        {
                DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
index 7b186d9..2d44955 100644 (file)
@@ -955,6 +955,7 @@ BOOLEAN BindAdapter(
     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 EnableDhcp = RTL_CONSTANT_STRING(L"EnableDHCP");
     UNICODE_STRING RegistryDataU;
     ANSI_STRING RegistryDataA;
 
@@ -1033,75 +1034,89 @@ BOOLEAN BindAdapter(
             return FALSE;
         }
 
-        RegistryDataU.MaximumLength = 16 + sizeof(WCHAR);
-        RegistryDataU.Buffer = (PWCHAR)KeyValueInfo->Data;
-
         Status = ZwQueryValueKey(ParameterHandle,
-                                 &IPAddress,
+                                 &EnableDhcp,
                                  KeyValuePartialInformation,
                                  KeyValueInfo,
-                                 sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 16 * sizeof(WCHAR),
+                                 sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(ULONG),
                                  &Unused);
-        if (NT_SUCCESS(Status))
+        if (NT_SUCCESS(Status) && KeyValueInfo->DataLength == sizeof(ULONG) && (*(PULONG)KeyValueInfo->Data) != 0)
         {
-            RegistryDataU.Length = KeyValueInfo->DataLength;
+            RegistryDataU.MaximumLength = 16 + sizeof(WCHAR);
+            RegistryDataU.Buffer = (PWCHAR)KeyValueInfo->Data;
 
-            RtlUnicodeStringToAnsiString(&RegistryDataA,
-                                         &RegistryDataU,
-                                         TRUE);
+            Status = ZwQueryValueKey(ParameterHandle,
+                                     &IPAddress,
+                                     KeyValuePartialInformation,
+                                     KeyValueInfo,
+                                     sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 16 * sizeof(WCHAR),
+                                     &Unused);
+            if (NT_SUCCESS(Status))
+            {
+                RegistryDataU.Length = KeyValueInfo->DataLength;
 
-            AddrInitIPv4(&IF->Unicast, inet_addr(RegistryDataA.Buffer));
+                RtlUnicodeStringToAnsiString(&RegistryDataA,
+                                             &RegistryDataU,
+                                             TRUE);
 
-            RtlFreeAnsiString(&RegistryDataA);
+                AddrInitIPv4(&IF->Unicast, inet_addr(RegistryDataA.Buffer));
 
-        }
-        else
-        {
-            IF->Unicast = DefaultMask;
-        }
+                RtlFreeAnsiString(&RegistryDataA);
 
-        Status = ZwQueryValueKey(ParameterHandle,
-                                 &Netmask,
-                                 KeyValuePartialInformation,
-                                 KeyValueInfo,
-                                 sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 16 * sizeof(WCHAR),
-                                 &Unused);
-        if (NT_SUCCESS(Status))
-        {
-            RegistryDataU.Length = KeyValueInfo->DataLength;
+            }
+            else
+            {
+                IF->Unicast = DefaultMask;
+            }
 
-            RtlUnicodeStringToAnsiString(&RegistryDataA,
-                                         &RegistryDataU,
-                                         TRUE);
+            Status = ZwQueryValueKey(ParameterHandle,
+                                     &Netmask,
+                                     KeyValuePartialInformation,
+                                     KeyValueInfo,
+                                     sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 16 * sizeof(WCHAR),
+                                     &Unused);
+            if (NT_SUCCESS(Status))
+            {
+                RegistryDataU.Length = KeyValueInfo->DataLength;
 
-            AddrInitIPv4(&IF->Netmask, inet_addr(RegistryDataA.Buffer));
+                RtlUnicodeStringToAnsiString(&RegistryDataA,
+                                             &RegistryDataU,
+                                             TRUE);
 
-            RtlFreeAnsiString(&RegistryDataA);
-        }
-        else
-        {
-            IF->Netmask = DefaultMask;
-        }
+                AddrInitIPv4(&IF->Netmask, inet_addr(RegistryDataA.Buffer));
 
-        Status = ZwQueryValueKey(ParameterHandle,
-                                 &Gateway,
-                                 KeyValuePartialInformation,
-                                 KeyValueInfo,
-                                 sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 16 * sizeof(WCHAR),
-                                 &Unused);
-        if (NT_SUCCESS(Status))
-        {
-            RegistryDataU.Length = KeyValueInfo->DataLength;
+                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);
+                RtlUnicodeStringToAnsiString(&RegistryDataA,
+                                             &RegistryDataU,
+                                             TRUE);
 
-            AddrInitIPv4(&Router, inet_addr(RegistryDataA.Buffer));
+                AddrInitIPv4(&Router, inet_addr(RegistryDataA.Buffer));
 
-            RtlFreeAnsiString(&RegistryDataA);
+                RtlFreeAnsiString(&RegistryDataA);
 
-            if (!AddrIsUnspecified(&Router)) RouterCreateRoute(&DefaultMask, &DefaultMask, &Router, IF, 1);
+                if (!AddrIsUnspecified(&Router)) RouterCreateRoute(&DefaultMask, &DefaultMask, &Router, IF, 1);
+            }
+        }
+        else
+        {
+            IF->Unicast = DefaultMask;
+            IF->Netmask = DefaultMask;
         }
 
         ZwClose(ParameterHandle);