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.

203 lines
5.8 KiB

  1. /*++
  2. Copyright (c) 1991-1992 Microsoft Corporation
  3. Module Name:
  4. DiskEnum.c
  5. Abstract:
  6. This file supports downlevel server handling of disk enum requests.
  7. Author:
  8. John Rogers (JohnRo) 03-May-1991
  9. Environment:
  10. Portable to any flat, 32-bit environment. (Uses Win32 typedefs.)
  11. Requires ANSI C extensions: slash-slash comments, long external names.
  12. Revision History:
  13. 03-May-1991 JohnRo
  14. Created.
  15. 09-May-1991 JohnRo
  16. Fixed bug where list wasn't terminated with null string.
  17. 09-May-1991 JohnRo
  18. Made changes suggested by LINT.
  19. 14-May-1991 JohnRo
  20. Pass 3 aux descriptors to RxRemoteApi.
  21. 24-Oct-1991 JohnRo
  22. Handle UNICODE conversion of array at end.
  23. 07-Feb-1992 JohnRo
  24. Use NetApiBufferAllocate() instead of private version.
  25. 05-Jun-1992 JohnRo
  26. RAID 11253: NetConfigGetAll fails when remoted to downlevel.
  27. --*/
  28. // These must be included first:
  29. #include <windef.h> // IN, LPTSTR, etc.
  30. #include <lmcons.h> // NET_API_STATUS, etc.
  31. // These may be included in any order:
  32. #include <apinums.h> // API_WServerDiskEnum.
  33. #include <lmapibuf.h> // NetApiBufferAllocate(), NetApiBufferFree().
  34. #include <lmerr.h> // NERR_ and ERROR_ equates.
  35. #include <netdebug.h> // NetpAssert().
  36. #include <remdef.h> // REM16_, REMSmb_, REM32_ equates.
  37. #include <rx.h> // RxRemoteApi().
  38. #include <rxserver.h> // My prototype.
  39. #include <strarray.h> // NetpCopyStrArrayToTStrArray().
  40. // Level 0 entries are 3 chars ("D:\0") each.
  41. #define LEVEL_0_LENGTH 3
  42. // Define max size of return area. 26 drives, 3 chars ("D:\0") each.
  43. // Also include 1 null char at end of list.
  44. #define MAX_RETURN_BUFF_SIZE ( ((26*LEVEL_0_LENGTH)+1) * sizeof(TCHAR) )
  45. NET_API_STATUS
  46. RxNetServerDiskEnum (
  47. IN LPTSTR UncServerName,
  48. IN DWORD Level,
  49. OUT LPBYTE *BufPtr,
  50. IN DWORD PrefMaxSize,
  51. OUT LPDWORD EntriesRead,
  52. OUT LPDWORD TotalEntries,
  53. IN OUT LPDWORD Resume_Handle OPTIONAL
  54. )
  55. /*++
  56. Routine Description:
  57. RxNetServerDiskEnum performs the equivalent of NetServerDiskEnum,
  58. except that UncServerName is known to be a downlevel server.
  59. Arguments:
  60. Same as NetServerDiskEnum.
  61. Return Value:
  62. Same as NetServerDiskEnum.
  63. --*/
  64. {
  65. DWORD Status;
  66. LPVOID TempBuff = NULL;
  67. // This version always returns maximum amount of data available, since
  68. // that would only be (26 * 3) + 1 = 79 bytes. Even in Unicode it would
  69. // still only be 158 bytes. (If we do decide to use the PrefMaxSize parm,
  70. // then we would call NetpAdjustPreferedMaximum here.)
  71. DBG_UNREFERENCED_PARAMETER(PrefMaxSize);
  72. // This version only supports 1 call to enumerate disks, so resume handle
  73. // should never be set to nonzero. But let's check, so caller finds out
  74. // they have a buggy program.
  75. if (Resume_Handle != NULL) {
  76. if (*Resume_Handle != 0) {
  77. return (ERROR_INVALID_PARAMETER);
  78. }
  79. }
  80. // Check for other caller's errors.
  81. if (Level != 0) {
  82. return (ERROR_INVALID_LEVEL);
  83. }
  84. //
  85. // Allocate space for entire area. (Note that we can't reply on
  86. // RxRemoteApi's neat new ALLOCATE_RESPONSE handling because the buffer
  87. // sent across the wire doesn't include the null at the end of the
  88. // array.)
  89. //
  90. Status = NetApiBufferAllocate(MAX_RETURN_BUFF_SIZE, & TempBuff);
  91. if (Status != NERR_Success) {
  92. return (Status);
  93. }
  94. NetpAssert(TempBuff != NULL);
  95. //
  96. // Ask downlevel server to enumerate disks for us.
  97. //
  98. Status = RxRemoteApi(
  99. API_WServerDiskEnum, // api number
  100. UncServerName, // where to execute the API
  101. REMSmb_NetServerDiskEnum_P, // parm desc
  102. REM16_server_diskenum_0, // data desc (16 bit local)
  103. REM16_server_diskenum_0, // data desc (32 bit local)
  104. REMSmb_server_diskenum_0, // data desc (SMB version)
  105. NULL, // no aux desc 16
  106. NULL, // no aux desc 32
  107. NULL, // no aux desc SMB
  108. 0, // flags: normal
  109. // rest of API's arguments in LM 2.x format:
  110. Level,
  111. TempBuff,
  112. (DWORD) MAX_RETURN_BUFF_SIZE,
  113. EntriesRead,
  114. TotalEntries);
  115. // We've allocated space for maximum data, so shouldn't get this...
  116. NetpAssert(Status != ERROR_MORE_DATA);
  117. if (Status != NERR_Success) {
  118. (void) NetApiBufferFree(TempBuff);
  119. *BufPtr = NULL;
  120. } else {
  121. LPSTR TempCharArray = TempBuff;
  122. //
  123. // For some reason, the LM 2.x support for this API doesn't send the
  124. // null character which terminates the list. So, we have to force it
  125. // in ourselves.
  126. //
  127. TempCharArray[ (*EntriesRead) * LEVEL_0_LENGTH ] = '\0';
  128. #ifdef UNICODE
  129. {
  130. LPVOID UnicodeBuff;
  131. //
  132. // Allocate space for UNICODE version of array.
  133. //
  134. Status = NetApiBufferAllocate(MAX_RETURN_BUFF_SIZE, & UnicodeBuff);
  135. if (Status != NERR_Success) {
  136. return (Status);
  137. }
  138. NetpAssert(UnicodeBuff != NULL);
  139. //
  140. // Translate result array to Unicode.
  141. //
  142. NetpCopyStrArrayToTStrArray(
  143. UnicodeBuff, // dest (in UNICODE)
  144. TempCharArray); // src array (in codepage)
  145. (void) NetApiBufferFree( TempBuff );
  146. *BufPtr = UnicodeBuff;
  147. }
  148. #else // not UNICODE
  149. *BufPtr = TempBuff;
  150. #endif // not UNICODE
  151. }
  152. return (Status);
  153. }