[KERNEL32] Try to read 'DhcpDomain' registry value if present, otherwise return ...
authorAmine Khaldi <amine.khaldi@reactos.org>
Sun, 18 Sep 2016 12:55:45 +0000 (12:55 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Sun, 18 Sep 2016 12:55:45 +0000 (12:55 +0000)
svn path=/trunk/; revision=72722

reactos/dll/win32/kernel32/client/compname.c

index a336eaa..e9bcfc7 100644 (file)
@@ -137,6 +137,7 @@ GetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
     NTSTATUS Status;
     BOOL ret = TRUE;
     DWORD HostSize;
+    DWORD nBufferSize;
 
     if ((nSize == NULL) ||
         (lpBuffer == NULL && *nSize > 0))
@@ -155,11 +156,27 @@ GetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
                                                nSize);
 
         case ComputerNameDnsDomain:
-            return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
-                                               L"\\Services\\Tcpip\\Parameters",
-                                               L"Domain",
-                                               lpBuffer,
-                                               nSize);
+            /* Save original buffer size for the second call if neccessery */
+            nBufferSize = *nSize;
+            if (!GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
+                                             L"\\Services\\Tcpip\\Parameters",
+                                             L"DhcpDomain",
+                                             lpBuffer,
+                                             nSize))
+            {
+                /* The value is there, just the buffer is insufficient in length */
+                if (GetLastError() == ERROR_MORE_DATA)
+                    return FALSE;
+                /* Restore original buffer size for the second call */
+                *nSize = nBufferSize;
+                return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
+                                                   L"\\Services\\Tcpip\\Parameters",
+                                                   L"Domain",
+                                                   lpBuffer,
+                                                   nSize);
+            }
+            else
+                return TRUE;
 
         case ComputerNameDnsFullyQualified:
             ResultString.Length = 0;
@@ -195,7 +212,7 @@ GetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
                 RtlFreeUnicodeString(&DomainPart);
 
                 RtlInitUnicodeString(&DomainPart, NULL);
-                QueryTable[0].Name = L"Domain";
+                QueryTable[0].Name = L"DhcpDomain";
                 QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
                 QueryTable[0].EntryContext = &DomainPart;
 
@@ -207,7 +224,9 @@ GetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
                                                 NULL,
                                                 NULL);
 
-                if (NT_SUCCESS(Status))
+                if ((NT_SUCCESS(Status)) &&
+                    (DomainPart.Buffer != NULL) &&
+                    (wcslen(DomainPart.Buffer) > 0))
                 {
                     Status = RtlAppendUnicodeStringToString(&ResultString, &DomainPart);
                     if ((!NT_SUCCESS(Status)) || (!ret))
@@ -221,6 +240,36 @@ GetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
                     *nSize = ResultString.Length / sizeof(WCHAR) - 1;
                     return TRUE;
                 }
+                else
+                {
+                    RtlInitUnicodeString(&DomainPart, NULL);
+                    QueryTable[0].Name = L"Domain";
+                    QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
+                    QueryTable[0].EntryContext = &DomainPart;
+
+                    Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
+                                                    L"\\Registry\\Machine\\System"
+                                                    L"\\CurrentControlSet\\Services\\Tcpip"
+                                                    L"\\Parameters",
+                                                    QueryTable,
+                                                    NULL,
+                                                    NULL);
+
+                    if (NT_SUCCESS(Status))
+                    {
+                        Status = RtlAppendUnicodeStringToString(&ResultString, &DomainPart);
+                        if ((!NT_SUCCESS(Status)) || (!ret))
+                        {
+                            *nSize = HostSize + DomainPart.Length;
+                            SetLastError(ERROR_MORE_DATA);
+                            RtlFreeUnicodeString(&DomainPart);
+                            return FALSE;
+                        }
+                        RtlFreeUnicodeString(&DomainPart);
+                        *nSize = ResultString.Length / sizeof(WCHAR) - 1;
+                        return TRUE;
+                    }
+                }
             }
             return FALSE;
 
@@ -232,11 +281,9 @@ GetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
                                                nSize);
 
         case ComputerNamePhysicalDnsDomain:
-            return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
-                                               L"\\Services\\Tcpip\\Parameters",
-                                               L"Domain",
-                                               lpBuffer,
-                                               nSize);
+            return GetComputerNameExW(ComputerNameDnsDomain,
+                                      lpBuffer,
+                                      nSize);
 
         /* XXX Redo these */
         case ComputerNamePhysicalDnsFullyQualified: