Source code of Windows XP (NT5)
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.

194 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. vrputil.c
  5. Abstract:
  6. Contains 'private' Vdm Redir (Vrp) 32-bit side utility routines:
  7. VrpMapLastError
  8. VrpMapDosError
  9. VrpTranslateDosNetPath
  10. Author:
  11. Richard L Firth (rfirth) 13-Sep-1991
  12. Environment:
  13. 32-bit flat address space
  14. Revision History:
  15. 13-Sep-1991 RFirth
  16. Created
  17. --*/
  18. #include <stdio.h>
  19. #include <stdlib.h> // toupper
  20. #include <nt.h>
  21. #include <ntrtl.h> // ASSERT, DbgPrint
  22. #include <nturtl.h>
  23. #include <windows.h>
  24. #include <softpc.h> // x86 virtual machine definitions
  25. #include <vrdlctab.h>
  26. #include <vdmredir.h> // common Vr stuff
  27. #include <vrinit.h>
  28. #include "vrputil.h" // prototypes
  29. #include <lmcons.h>
  30. #include <lmerr.h>
  31. WORD
  32. VrpMapLastError(
  33. VOID
  34. )
  35. /*++
  36. Routine Description:
  37. Gets last error code returned by Win32 function and maps it to corresponding
  38. Dos error
  39. Arguments:
  40. None.
  41. Return Value:
  42. WORD - Dos equivalent error code
  43. --*/
  44. {
  45. DWORD LastError;
  46. LastError = GetLastError();
  47. #ifdef VR_DIAGNOSE
  48. DbgPrint("VrpMapLastError: last error was %d\n", LastError);
  49. #endif
  50. return VrpMapDosError(LastError);
  51. }
  52. WORD
  53. VrpMapDosError(
  54. IN DWORD ErrorCode
  55. )
  56. /*++
  57. Routine Description:
  58. Maps (DWORD) errors returned from Win32 routines to (WORD) Dos errors
  59. Arguments:
  60. ErrorCode - Error code returned from Win32 routine
  61. Return Value:
  62. WORD - Dos equivalent error code
  63. --*/
  64. {
  65. switch (ErrorCode) {
  66. case NERR_UseNotFound:
  67. ErrorCode = ERROR_PATH_NOT_FOUND;
  68. break;
  69. }
  70. return (WORD)ErrorCode;
  71. }
  72. WORD
  73. VrpTranslateDosNetPath(
  74. IN OUT LPSTR* InputString,
  75. OUT LPSTR* OutputString
  76. )
  77. /*++
  78. Routine Description:
  79. Converts a DOS net string: use UPPER CASE, convert / to \. Called with
  80. net strings, so validates them too - expects \\computername\share.
  81. computername is 1 <= name <= 15. sharename is 1 <= name <= 8. There must
  82. be 2 leading back-slashes
  83. BUGBUG: code page? Kanji? DBCS?
  84. Arguments:
  85. InputString - pointer to pointer to string in DOS memory <= LM20_PATHLEN
  86. OutputString - pointer to pointer to string in 32-bit memory
  87. Return Value:
  88. WORD
  89. Success = 0
  90. InputString points to one character past the end of the input string
  91. OutputString points to one character past the end of the output string
  92. Failure = ERROR_INVALID_PARAMETER
  93. --*/
  94. {
  95. char ch;
  96. char lastCh = 0;
  97. int state = 0; // 0 = leading slashes; 1 = computer name; 2 = share name
  98. int slashesToGo = 2;
  99. int charsToGo = 0;
  100. int maxLen = LM20_PATHLEN;
  101. while (ch = *((*InputString)++)) {
  102. --maxLen;
  103. if (maxLen < 0) {
  104. break;
  105. }
  106. if (ch == '/') {
  107. ch = '\\';
  108. } else {
  109. ch = (char)toupper(ch);
  110. }
  111. if (ch == '\\') {
  112. --slashesToGo;
  113. if (slashesToGo < 0) {
  114. break;
  115. }
  116. } else {
  117. if (lastCh == '\\') {
  118. if (slashesToGo) {
  119. break;
  120. } else {
  121. if (state == 0) {
  122. state = 1;
  123. charsToGo = LM20_CNLEN;
  124. slashesToGo = 1;
  125. } else if (state == 1) {
  126. state = 2;
  127. charsToGo = LM20_NNLEN;
  128. slashesToGo = 0;
  129. }
  130. }
  131. }
  132. --charsToGo;
  133. if (charsToGo < 0) {
  134. break;
  135. }
  136. }
  137. *((*OutputString)++) = ch;
  138. lastCh = ch;
  139. }
  140. *((*OutputString)++) = 0;
  141. return ch ? (WORD)ERROR_INVALID_PARAMETER : 0;
  142. }