Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
4.0 KiB

  1. /*++
  2. Copyright (c) 1991-1992 Microsoft Corporation
  3. Module Name:
  4. fmtncbna.c
  5. Abstract:
  6. Contains a function for formatting a name NCB_style.
  7. Author:
  8. Dan Lafferty (danl) 29-May-1991
  9. Environment:
  10. User Mode -Win32
  11. Revision History:
  12. 29-May-1991 danl
  13. ported from LM2.0
  14. 01-Oct-1991 danl
  15. Working toward UNICODE.
  16. --*/
  17. #include <nt.h> // needed by tstring.h
  18. #include <windef.h> // needed by tstring.h
  19. #include <nt.h> // (Needed by <tstring.h>.)
  20. #include <windef.h> // (Needed by <tstring.h>.)
  21. #include <tstring.h> // STRLEN
  22. #include "msrv.h" // For prototype definitions
  23. #include "msgdbg.h" // MSG_LOG
  24. #include <netdebug.h> // NetpAssert
  25. #include <netlib.h> // UNUSED macro
  26. #include <netlibnt.h> // NetpNtStatusToApiStatus
  27. #include <icanon.h> // Canonicalization Routines
  28. NET_API_STATUS
  29. MsgFmtNcbName(
  30. OUT PCHAR DestBuf,
  31. IN LPTSTR Name,
  32. IN DWORD Type)
  33. /*++
  34. Routine Description:
  35. FmtNcbName - format a name NCB-style
  36. Given a name, a name type, and a destination address, this
  37. function copies the name and the type to the destination in
  38. the format used in the name fields of a Network Control
  39. Block.
  40. SIDE EFFECTS
  41. Modifies 16 bytes starting at the destination address.
  42. Arguments:
  43. DestBuf - Pointer to the destination buffer.
  44. Name - Unicode NUL-terminated name string
  45. Type - Name type number (0, 3, 5, or 32) (3=NON_FWD, 5=FWD)
  46. Return Value:
  47. NERR_Success - The operation was successful
  48. Translated Return Code from the Rtl Translate routine.
  49. --*/
  50. {
  51. DWORD i; // Counter
  52. NTSTATUS ntStatus;
  53. NET_API_STATUS status;
  54. OEM_STRING ansiString;
  55. UNICODE_STRING unicodeString;
  56. PCHAR pAnsiString;
  57. //
  58. // Force the name to be upper case.
  59. //
  60. status = NetpNameCanonicalize(
  61. NULL,
  62. Name,
  63. Name,
  64. STRSIZE(Name),
  65. NAMETYPE_MESSAGEDEST,
  66. 0);
  67. if (status != NERR_Success) {
  68. return(status);
  69. }
  70. //
  71. // Convert the unicode name string into an ansi string - using the
  72. // current locale.
  73. //
  74. #ifdef UNICODE
  75. unicodeString.Length = (USHORT)(STRLEN(Name)*sizeof(WCHAR));
  76. unicodeString.MaximumLength = (USHORT)((STRLEN(Name)+1) * sizeof(WCHAR));
  77. unicodeString.Buffer = Name;
  78. ntStatus = RtlUnicodeStringToOemString(
  79. &ansiString,
  80. &unicodeString,
  81. TRUE); // Allocate the ansiString Buffer.
  82. if (!NT_SUCCESS(ntStatus))
  83. {
  84. MSG_LOG(ERROR,
  85. "FmtNcbName:RtlUnicodeStringToOemString Failed rc=%X\n",
  86. ntStatus);
  87. return NetpNtStatusToApiStatus(ntStatus);
  88. }
  89. pAnsiString = ansiString.Buffer;
  90. *(pAnsiString+ansiString.Length) = '\0';
  91. #else
  92. UNUSED(ntStatus);
  93. UNUSED(unicodeString);
  94. UNUSED(ansiString);
  95. pAnsiString = Name;
  96. #endif // UNICODE
  97. //
  98. // copy each character until a NUL is reached, or until NCBNAMSZ-1
  99. // characters have been copied.
  100. //
  101. for (i=0; i < NCBNAMSZ - 1; ++i) {
  102. if (*pAnsiString == '\0') {
  103. break;
  104. }
  105. //
  106. // Copy the Name
  107. //
  108. *DestBuf++ = *pAnsiString++;
  109. }
  110. //
  111. // Free the buffer that RtlUnicodeStringToOemString created for us.
  112. // NOTE: only the ansiString.Buffer portion is free'd.
  113. //
  114. #ifdef UNICODE
  115. RtlFreeOemString( &ansiString);
  116. #endif // UNICODE
  117. //
  118. // Pad the name field with spaces
  119. //
  120. for(; i < NCBNAMSZ - 1; ++i) {
  121. *DestBuf++ = ' ';
  122. }
  123. //
  124. // Set the name type.
  125. //
  126. NetpAssert( Type!=5 ); // 5 is not valid for NT.
  127. *DestBuf = (CHAR) Type; // Set name type
  128. return(NERR_Success);
  129. }