Author: akhaldi
Date: Sun Sep 18 12:55:45 2016
New Revision: 72722

URL: http://svn.reactos.org/svn/reactos?rev=72722&view=rev
Log:
[KERNEL32] Try to read 'DhcpDomain' registry value if present, otherwise return 
'Domain' one, when domain part is requested from GetComputerNameEx(). By Peter 
Hater. CORE-10440

Modified:
    trunk/reactos/dll/win32/kernel32/client/compname.c

Modified: trunk/reactos/dll/win32/kernel32/client/compname.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/compname.c?rev=72722&r1=72721&r2=72722&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/compname.c  [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/compname.c  [iso-8859-1] Sun Sep 18 
12:55:45 2016
@@ -137,6 +137,7 @@
     NTSTATUS Status;
     BOOL ret = TRUE;
     DWORD HostSize;
+    DWORD nBufferSize;
 
     if ((nSize == NULL) ||
         (lpBuffer == NULL && *nSize > 0))
@@ -155,11 +156,27 @@
                                                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 @@
                 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 @@
                                                 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 @@
                     *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 @@
                                                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:


Reply via email to