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.

225 lines
7.2 KiB

  1. /*++
  2. Copyright (c) 1991-92 Microsoft Corporation
  3. Module Name:
  4. SessEnum.c
  5. Abstract:
  6. This file contains the RpcXlate code to handle the Session APIs.
  7. Author:
  8. John Rogers (JohnRo) 17-Oct-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. 17-Oct-1991 JohnRo
  14. Created.
  15. 18-Oct-1991 JohnRo
  16. Removed incorrect assertion on status from RxpCopyAndConvertSessions().
  17. 21-Nov-1991 JohnRo
  18. Removed NT dependencies to reduce recompiles.
  19. 07-Feb-1992 JohnRo
  20. Fixed bug where temp array was often allocated too small.
  21. Fixed bug where temp array was freed when it might not exist.
  22. --*/
  23. #include "downlevl.h"
  24. #include "rxshare.h"
  25. #include <lmshare.h> // typedefs for SHARE_INFO etc.
  26. #include <rap.h> // LPDESC.
  27. #include <rxsess.h> // My prototype(s).
  28. #include <strucinf.h> // NetpSessionStructureInfo().
  29. #include <winerror.h> // ERROR_, NO_ERROR equates.
  30. #define SESSION_ARRAY_OVERHEAD_SIZE 0
  31. NET_API_STATUS
  32. RxNetSessionEnum (
  33. IN LPTSTR UncServerName,
  34. IN LPTSTR ClientName OPTIONAL,
  35. IN LPTSTR UserName OPTIONAL,
  36. IN DWORD LevelWanted,
  37. OUT LPBYTE *BufPtr,
  38. IN DWORD PreferedMaximumSize,
  39. OUT LPDWORD EntriesRead,
  40. OUT LPDWORD TotalEntries,
  41. IN OUT LPDWORD ResumeHandle OPTIONAL
  42. )
  43. /*++
  44. Routine Description:
  45. RxNetSessionEnum performs the same function as NetSessionEnum,
  46. except that the server name is known to refer to a downlevel server.
  47. Arguments:
  48. (Same as NetSessionEnum, except UncServerName must not be null, and
  49. must not refer to the local computer.)
  50. Return Value:
  51. (Same as NetSessionEnum.)
  52. --*/
  53. {
  54. NET_API_STATUS ApiStatus;
  55. DWORD EntriesToAllocate;
  56. const DWORD TempLevel = 2; // Superset info level.
  57. LPBYTE TempArray = NULL; // Buffer we'll use.
  58. DWORD TempArraySize; // Byte count for TempArray.
  59. LPDESC TempDataDesc16, TempDataDesc32, TempDataDescSmb;
  60. DWORD TempMaxEntrySize;
  61. NET_API_STATUS TempStatus;
  62. UNREFERENCED_PARAMETER(ResumeHandle);
  63. // Make sure caller didn't mess up.
  64. NetpAssert(UncServerName != NULL);
  65. if (BufPtr == NULL) {
  66. return (ERROR_INVALID_PARAMETER);
  67. }
  68. // Assume something might go wrong, and make error paths easier to
  69. // code. Also, check for bad pointers before we do anything.
  70. *BufPtr = NULL;
  71. *EntriesRead = 0;
  72. *TotalEntries = 0;
  73. //
  74. // Find out about superset info level.
  75. //
  76. TempStatus = NetpSessionStructureInfo (
  77. TempLevel,
  78. PARMNUM_ALL, // want all fields.
  79. TRUE, // want native sizes.
  80. & TempDataDesc16,
  81. & TempDataDesc32,
  82. & TempDataDescSmb,
  83. & TempMaxEntrySize, // total buffer size (native)
  84. NULL, // don't need fixed size
  85. NULL // don't need string size
  86. );
  87. if (TempStatus != NO_ERROR) {
  88. *BufPtr = NULL;
  89. return (TempStatus);
  90. }
  91. //
  92. // Downlevel servers don't support resume handles, and we don't
  93. // have a way to say "close this resume handle" even if we wanted to
  94. // emulate them here. Therefore we have to do everthing in one shot.
  95. // So, the first time around, we'll try using the caller's prefered
  96. // maximum, but we will enlarge that until we can get everything in one
  97. // buffer.
  98. //
  99. // First time: try caller's prefered maximum.
  100. NetpAdjustPreferedMaximum (
  101. PreferedMaximumSize, // caller's request
  102. TempMaxEntrySize, // byte count per array element
  103. SESSION_ARRAY_OVERHEAD_SIZE,// num bytes to show array end
  104. NULL, // we'll compute byte counts ourselves.
  105. & EntriesToAllocate); // num of entries we can get.
  106. //
  107. // Loop until we have enough memory or we die for some other reason.
  108. //
  109. do {
  110. // Figure out how much memory we need.
  111. TempArraySize = (EntriesToAllocate * TempMaxEntrySize)
  112. + SESSION_ARRAY_OVERHEAD_SIZE;
  113. if (TempArraySize > MAX_TRANSACT_RET_DATA_SIZE) {
  114. //
  115. // Try once more with the maximum-size buffer
  116. //
  117. TempArraySize = MAX_TRANSACT_RET_DATA_SIZE;
  118. }
  119. //
  120. // Remote the API, which will allocate the array for us.
  121. //
  122. ApiStatus = RxRemoteApi(
  123. API_WSessionEnum, // api number
  124. UncServerName, // \\servername
  125. REMSmb_NetSessionEnum_P,// parm desc (SMB version)
  126. TempDataDesc16,
  127. TempDataDesc32,
  128. TempDataDescSmb,
  129. NULL, // no aux desc 16
  130. NULL, // no aux desc 32
  131. NULL, // no aux desc SMB
  132. ALLOCATE_RESPONSE, // flags: allocate buffer for us
  133. // rest of API's arguments in 32-bit LM 2.x format:
  134. TempLevel, // sLevel: info level (superset!)
  135. & TempArray, // Buffer: array (alloc for us)
  136. TempArraySize, // Buffer: array size in bytes
  137. EntriesRead, // pcEntriesRead
  138. TotalEntries); // pcTotalAvail
  139. if (ApiStatus == ERROR_MORE_DATA) {
  140. (void) NetApiBufferFree( TempArray );
  141. TempArray = NULL;
  142. if (TempArraySize >= MAX_TRANSACT_RET_DATA_SIZE) {
  143. //
  144. // No point in trying with a larger buffer
  145. //
  146. break;
  147. }
  148. NetpAssert( EntriesToAllocate < *TotalEntries );
  149. EntriesToAllocate = *TotalEntries;
  150. }
  151. } while (ApiStatus == ERROR_MORE_DATA);
  152. if (ApiStatus == NO_ERROR) {
  153. LPVOID RealArray;
  154. DWORD EntriesSelected;
  155. //
  156. // Handle UserName and ClientName sematics. Also convert to the
  157. // wanted info level.
  158. //
  159. TempStatus = RxpCopyAndConvertSessions(
  160. (LPSESSION_SUPERSET_INFO) TempArray, // input array
  161. *EntriesRead, // input entry count
  162. LevelWanted, // want output in this info level
  163. ClientName, // select this client optional any)
  164. UserName, // select this user name (optional)
  165. & RealArray, // alloc'ed, converted, selected array
  166. & EntriesSelected); // count of entries selected
  167. //
  168. // Note that EntriesSelected may be 0 and RealArray may be NULL.
  169. //
  170. *BufPtr = RealArray;
  171. *EntriesRead = EntriesSelected;
  172. *TotalEntries = EntriesSelected;
  173. (void) NetApiBufferFree( TempArray );
  174. }
  175. return (ApiStatus);
  176. } // RxNetSessionEnum