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.

218 lines
6.7 KiB

  1. /*++
  2. Copyright (c) 1991-92 Microsoft Corporation
  3. Module Name:
  4. SessGet.c
  5. Abstract:
  6. This file contains the RpcXlate code to handle the NetSession APIs
  7. that can't be handled by simple calls to RxRemoteApi.
  8. Author:
  9. John Rogers (JohnRo) 17-Oct-1991
  10. Environment:
  11. Portable to any flat, 32-bit environment. (Uses Win32 typedefs.)
  12. Requires ANSI C extensions: slash-slash comments, long external names.
  13. Revision History:
  14. 17-Oct-1991 JohnRo
  15. Created.
  16. 25-Oct-1991 JohnRo
  17. Fixed bug where null chars weren't treated correctly.
  18. 20-Nov-1991 JohnRo
  19. NetSessionGetInfo requires UncClientName and UserName.
  20. This fixes the AE (application error) in NetSess.exe.
  21. 21-Nov-1991 JohnRo
  22. Removed NT dependencies to reduce recompiles.
  23. 07-Feb-1992 JohnRo
  24. Use NetApiBufferAllocate() instead of private version.
  25. 08-Sep-1992 JohnRo
  26. Fixed __stdcall for RpcXlate workers.
  27. --*/
  28. // These must be included first:
  29. #include <windef.h> // IN, DWORD, etc.
  30. #include <lmcons.h> // NET_API_STATUS, etc.
  31. #include <lmshare.h> // Required by rxsess.h.
  32. // These may be included in any order:
  33. #include <apinums.h> // API_ equates.
  34. #include <lmapibuf.h> // NetApiBufferAllocate().
  35. #include <lmerr.h> // ERROR_ and NERR_ equates.
  36. #include <netdebug.h> // DBGSTATIC, NetpKdPrint(()), FORMAT_ equates.
  37. #include <netlib.h> // NetpPointerPlusSomeBytes, etc.
  38. #include <rap.h> // LPDESC.
  39. #include <remdef.h> // REMSmb_ equates.
  40. #include <rx.h> // RxRemoteApi().
  41. #include <rxpdebug.h> // IF_DEBUG().
  42. #include <rxsess.h> // My prototype.
  43. #include <strucinf.h> // NetpSessionStructureInfo().
  44. // VOID
  45. // NetpChangeNullCharToNullPtr(
  46. // IN OUT LPTSTR p
  47. // );
  48. //
  49. #define ChangeNullCharToNullPtr(p) \
  50. { \
  51. if ( ((p) != NULL) && (*(p) == '\0') ) { \
  52. (p) = NULL; \
  53. } \
  54. }
  55. NET_API_STATUS
  56. RxNetSessionGetInfo (
  57. IN LPTSTR UncServerName,
  58. IN LPTSTR UncClientName,
  59. IN LPTSTR UserName,
  60. IN DWORD LevelWanted,
  61. OUT LPBYTE *BufPtr
  62. )
  63. /*++
  64. Routine Description:
  65. RxNetSessionGetInfo performs the same function as NetSessionGetInfo,
  66. except that the server name is known to refer to a downlevel server.
  67. Arguments:
  68. (Same as NetSessionGetInfo, except UncServerName must not be null, and
  69. must not refer to the local computer.)
  70. Return Value:
  71. (Same as NetSessionGetInfo.)
  72. --*/
  73. {
  74. NET_API_STATUS ApiStatus;
  75. LPBYTE TempBuffer; // Buffer we'll use.
  76. DWORD TempBufferSize;
  77. LPDESC TempDataDesc16, TempDataDesc32, TempDataDescSmb;
  78. NET_API_STATUS TempStatus;
  79. DWORD TotalAvail;
  80. IF_DEBUG(SESSION) {
  81. NetpKdPrint(("RxNetSessionGetInfo: starting, server=" FORMAT_LPTSTR
  82. ", lvl=" FORMAT_DWORD ".\n", UncServerName, LevelWanted));
  83. }
  84. //
  85. // Update pointers if they point to null chars.
  86. //
  87. ChangeNullCharToNullPtr( UncClientName );
  88. ChangeNullCharToNullPtr( UserName );
  89. //
  90. // Error check DLL stub and the app.
  91. //
  92. NetpAssert(UncServerName != NULL);
  93. if (BufPtr == NULL) {
  94. return (ERROR_INVALID_PARAMETER);
  95. }
  96. *BufPtr = NULL; // assume error; it makes error handlers easy to code.
  97. // This also forces possible GP fault before we allocate memory.
  98. if ( (UncClientName == NULL) || (UserName == NULL) ) {
  99. return (ERROR_INVALID_PARAMETER);
  100. }
  101. //
  102. // Learn about temp info level (max superset of all levels).
  103. //
  104. TempStatus = NetpSessionStructureInfo (
  105. SESSION_SUPERSET_LEVEL, // level to learn about
  106. PARMNUM_ALL, // No parmnum with this.
  107. TRUE, // Need native sizes.
  108. & TempDataDesc16,
  109. & TempDataDesc32,
  110. & TempDataDescSmb,
  111. & TempBufferSize, // max buffer size (native)
  112. NULL, // don't need fixed size.
  113. NULL // don't need string size.
  114. );
  115. NetpAssert(TempStatus == NERR_Success);
  116. //
  117. // Allocate memory for 32-bit version of superset info level.
  118. //
  119. TempStatus = NetApiBufferAllocate(
  120. TempBufferSize,
  121. (LPVOID *) & TempBuffer);
  122. if (TempStatus != NERR_Success) {
  123. return (TempStatus);
  124. }
  125. IF_DEBUG(SESSION) {
  126. NetpKdPrint(( "RxNetSessionGetInfo: allocated temp buffer at "
  127. FORMAT_LPVOID "\n", (LPVOID) TempBuffer ));
  128. }
  129. //
  130. // Actually remote the API, which will get back the superset
  131. // data in native format.
  132. //
  133. ApiStatus = RxRemoteApi(
  134. API_WSessionGetInfo, // API number
  135. UncServerName, // Required, with \\name.
  136. REMSmb_NetSessionGetInfo_P, // parm desc
  137. TempDataDesc16,
  138. TempDataDesc32,
  139. TempDataDescSmb,
  140. NULL, // no aux data desc 16
  141. NULL, // no aux data desc 32
  142. NULL, // no aux data desc SMB
  143. 0, // Flags: normal
  144. // rest of API's arguments, in 32-bit LM 2.x format:
  145. UncClientName,
  146. SESSION_SUPERSET_LEVEL, // level with all possible fields
  147. TempBuffer,
  148. TempBufferSize,
  149. & TotalAvail); // total size
  150. NetpAssert( ApiStatus != ERROR_MORE_DATA );
  151. NetpAssert( ApiStatus != NERR_BufTooSmall );
  152. if (ApiStatus == NERR_Success) {
  153. DWORD EntriesSelected;
  154. //
  155. // Copy and convert from temp info level to level the caller wants.
  156. // Check for match on UncClientName and UserName first.
  157. //
  158. TempStatus = RxpCopyAndConvertSessions(
  159. (LPSESSION_SUPERSET_INFO) TempBuffer, // input "array"
  160. 1, // only one "entry" this time
  161. LevelWanted,
  162. UncClientName,
  163. UserName,
  164. (LPVOID *) BufPtr, // alloc'ed (may be NULL if no match)
  165. & EntriesSelected); // output entry count
  166. NetpAssert(TempStatus == NERR_Success);
  167. if (EntriesSelected == 0) {
  168. ApiStatus = RxpSessionMissingErrorCode( UncClientName, UserName );
  169. NetpAssert( ApiStatus != NERR_Success );
  170. }
  171. }
  172. (void) NetApiBufferFree( TempBuffer );
  173. return (ApiStatus);
  174. } // RxNetSessionGetInfo