From 887a1669806bea8241b7f54dd0258a55fc681979 Mon Sep 17 00:00:00 2001 From: Aleksey Bragin Date: Tue, 5 Jan 2010 16:37:32 +0000 Subject: [PATCH] Daniel Zimmermann - Implement RtlDnsHostNameToComputerName. See issue #5092 for more details. svn path=/trunk/; revision=44948 --- reactos/dll/ntdll/def/ntdll.pspec | 2 +- reactos/lib/rtl/unicode.c | 71 +++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/reactos/dll/ntdll/def/ntdll.pspec b/reactos/dll/ntdll/def/ntdll.pspec index 0af7647de74..905cfa63718 100644 --- a/reactos/dll/ntdll/def/ntdll.pspec +++ b/reactos/dll/ntdll/def/ntdll.pspec @@ -562,7 +562,7 @@ @ stdcall RtlDestroyQueryDebugBuffer(ptr) @ stdcall RtlDetermineDosPathNameType_U(wstr) @ stdcall RtlDllShutdownInProgress() -//@ stdcall RtlDnsHostNameToComputerName +@ stdcall RtlDnsHostNameToComputerName(ptr ptr long) @ stdcall RtlDoesFileExists_U(wstr) //@ stdcall RtlDosApplyFileIsolationRedirection_Ustr @ stdcall RtlDosPathNameToNtPathName_U(wstr ptr ptr ptr) diff --git a/reactos/lib/rtl/unicode.c b/reactos/lib/rtl/unicode.c index aa1c70e7439..4dd9d4fa5d6 100644 --- a/reactos/lib/rtl/unicode.c +++ b/reactos/lib/rtl/unicode.c @@ -2436,3 +2436,74 @@ RtlFindCharInUnicodeString(IN ULONG Flags, return STATUS_NOT_FOUND; } + +/* + * @implemented + * + * NOTES + * Get the maximum of MAX_COMPUTERNAME_LENGTH characters from the dns.host name until the dot is found. + * Convert is to an uppercase oem string and check for unmapped characters. + * Then convert the oem string back to an unicode string. + */ +NTSTATUS +NTAPI +RtlDnsHostNameToComputerName(PUNICODE_STRING ComputerName,PUNICODE_STRING DnsHostName,BOOLEAN AllocateComputerNameString) +{ + NTSTATUS Status; + ULONG Length; + ULONG ComputerNameLength; + ULONG ComputerNameOemNLength; + OEM_STRING ComputerNameOem; + CHAR ComputerNameOemN[MAX_COMPUTERNAME_LENGTH + 1]; + + Status = STATUS_INVALID_COMPUTER_NAME; + ComputerNameLength = DnsHostName->Length; + + /* find the first dot in the dns host name */ + for (Length = 0;Length < DnsHostName->Length/sizeof(WCHAR);Length++) + { + if (DnsHostName->Buffer[Length] == L'.') + { + /* dot found, so set the length for the oem translation */ + ComputerNameLength = Length*sizeof(WCHAR); + break; + } + } + + /* the computername must have one character */ + if (ComputerNameLength > 0) + { + ComputerNameOemNLength = 0; + /* convert to oem string and use uppercase letters */ + Status = RtlUpcaseUnicodeToOemN(ComputerNameOemN, + MAX_COMPUTERNAME_LENGTH, + &ComputerNameOemNLength, + DnsHostName->Buffer, + ComputerNameLength); + /* status STATUS_BUFFER_OVERFLOW is not a problem since the computername shoud only + have MAX_COMPUTERNAME_LENGTH characters */ + if ((Status == STATUS_SUCCESS) || + (Status == STATUS_BUFFER_OVERFLOW)) + { + /* set the termination for the oem string */ + ComputerNameOemN[MAX_COMPUTERNAME_LENGTH] = 0; + /* set status for the case the next function failed */ + Status = STATUS_INVALID_COMPUTER_NAME; + /* fillup the oem string structure with the converted computername + and check it for unmapped characters */ + ComputerNameOem.Buffer = ComputerNameOemN; + ComputerNameOem.Length = (USHORT)ComputerNameOemNLength; + ComputerNameOem.MaximumLength = (USHORT)(MAX_COMPUTERNAME_LENGTH + 1); + if (RtlpDidUnicodeToOemWork(DnsHostName, &ComputerNameOem) == TRUE) + { + /* no unmapped character so convert it back to an unicode string */ + Status = RtlOemStringToUnicodeString(ComputerName, + &ComputerNameOem, + AllocateComputerNameString); + } + } + } + + return Status; +} + -- 2.17.1