ULONG ReturnSize;
NTSTATUS Status;
+ if (lpBuffer != NULL && *nSize > 0)
+ lpBuffer[0] = 0;
+
RtlInitUnicodeString(&KeyName, RegistryKey);
InitializeObjectAttributes(&ObjectAttributes,
&KeyName,
if (!NT_SUCCESS(Status))
{
- *nSize = ReturnSize;
+ *nSize = (ReturnSize - FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data)) / sizeof(WCHAR);
goto failed;
}
if (!lpBuffer || *nSize < (KeyInfo->DataLength / sizeof(WCHAR)))
{
- *nSize = ReturnSize;
+ *nSize = (ReturnSize - FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data)) / sizeof(WCHAR);
Status = STATUS_BUFFER_OVERFLOW;
goto failed;
}
NTSTATUS Status;
BOOL ret = TRUE;
DWORD HostSize;
+ DWORD nBufferSize;
+
+ if ((nSize == NULL) ||
+ (lpBuffer == NULL && *nSize > 0))
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
switch (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;
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;
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))
*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;
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:
UNICODE_STRING UnicodeString;
ANSI_STRING AnsiString;
BOOL Result;
- PWCHAR TempBuffer = RtlAllocateHeap( RtlGetProcessHeap(), 0, *nSize * sizeof(WCHAR) );
+ PWCHAR TempBuffer = NULL;
- if (!TempBuffer)
+ if ((nSize == NULL) ||
+ (lpBuffer == NULL && *nSize > 0))
{
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
+ if (*nSize > 0)
+ {
+ TempBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, *nSize * sizeof(WCHAR));
+ if (!TempBuffer)
+ {
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ return FALSE;
+ }
+ }
+
AnsiString.MaximumLength = (USHORT)*nSize;
AnsiString.Length = 0;
AnsiString.Buffer = lpBuffer;
if (Result)
{
UnicodeString.MaximumLength = (USHORT)*nSize * sizeof(WCHAR) + sizeof(WCHAR);
- UnicodeString.Length = (USHORT)*nSize * sizeof(WCHAR) + sizeof(WCHAR);
+ UnicodeString.Length = (USHORT)*nSize * sizeof(WCHAR);
UnicodeString.Buffer = TempBuffer;
RtlUnicodeStringToAnsiString(&AnsiString,