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.

260 lines
8.9 KiB

  1. /*++
  2. Copyright (c) 1991-92 Microsoft Corporation
  3. Module Name:
  4. SrvGtInf.c
  5. Abstract:
  6. This file contains the RpcXlate code to handle the NetServer APIs
  7. that can't be handled by simple calls to RxRemoteApi.
  8. Author:
  9. John Rogers (JohnRo) 02-May-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. 02-May-1991 JohnRo
  15. Created.
  16. 06-May-1991 JohnRo
  17. Added some assertion checks.
  18. 14-May-1991 JohnRo
  19. Can't always do assertion on TotalAvail.
  20. 14-May-1991 JohnRo
  21. Pass 3 aux descriptors to RxRemoteApi.
  22. 26-May-1991 JohnRo
  23. Added incomplete output parm to RxGetServerInfoLevelEquivalent.
  24. 17-Jul-1991 JohnRo
  25. Extracted RxpDebug.h from Rxp.h.
  26. 07-Feb-1992 JohnRo
  27. Use NetApiBufferAllocate() instead of private version.
  28. 15-Apr-1992 JohnRo
  29. FORMAT_POINTER is obsolete.
  30. --*/
  31. // These must be included first:
  32. #include <windef.h>
  33. #include <lmcons.h>
  34. #include <rap.h> // LPDESC, etc (needed by rxserver.h).
  35. // These may be included in any order:
  36. #include <apinums.h>
  37. #include <dlserver.h> // Old info level structures & conv routines.
  38. // Also DL_REM_ equates.
  39. #include <lmapibuf.h> // NetApiBufferAllocate(), NetApiBufferFree().
  40. #include <lmerr.h> // NERR_ and ERROR_ equates.
  41. #include <lmserver.h> // Real API prototypes and #defines.
  42. #include <names.h> // NetpIsComputerNameValid().
  43. #include <netdebug.h> // NetpKdPrint(()), FORMAT_ equates, etc.
  44. #include <remdef.h> // REM16_, REM32_, and REMSmb_ equates.
  45. #include <rx.h> // RxRemoteApi().
  46. #include <rxp.h> // RxpFatalErrorCode().
  47. #include <rxpdebug.h> // IF_DEBUG().
  48. #include <rxserver.h> // My prototype.
  49. NET_API_STATUS
  50. RxNetServerGetInfo (
  51. IN LPTSTR UncServerName,
  52. IN DWORD Level,
  53. OUT LPBYTE *BufPtr
  54. )
  55. /*++
  56. Routine Description:
  57. RxNetServerGetInfo performs the same function as NetServerGetInfo,
  58. except that the server name is known to refer to a downlevel server.
  59. Arguments:
  60. (Same as NetServerGetInfo, except UncServerName must not be null, and
  61. must not refer to the local computer.)
  62. Return Value:
  63. (Same as NetServerGetInfo.)
  64. --*/
  65. {
  66. LPBYTE NewApiBuffer; // Buffer to be returned to caller.
  67. DWORD NewFixedSize;
  68. DWORD NewStringSize;
  69. LPBYTE OldApiBuffer; // Buffer with old info level.
  70. DWORD OldApiBufferSize;
  71. LPDESC OldDataDesc16;
  72. LPDESC OldDataDesc32; // Desc for 32-bit (old info level).
  73. LPDESC OldDataDescSmb;
  74. DWORD OldLevel; // old (LanMan 2.x) level equiv to new.
  75. LPDESC ParmDesc16 = REM16_NetServerGetInfo_P;
  76. NET_API_STATUS Status;
  77. DWORD TotalAvail;
  78. IF_DEBUG(SERVER) {
  79. NetpKdPrint((
  80. "RxNetServerGetInfo: starting, server=" FORMAT_LPTSTR
  81. ", lvl=" FORMAT_DWORD ".\n",
  82. UncServerName, Level));
  83. }
  84. NetpAssert(UncServerName != NULL);
  85. NetpAssert(NetpIsUncComputerNameValid(UncServerName));
  86. if (BufPtr == NULL) {
  87. return (ERROR_INVALID_PARAMETER);
  88. }
  89. //
  90. // Decide what to do based on the info level. Note that normally we'd
  91. // be using REM16_, REM32_, and REMSmb_ descriptors here. However,
  92. // the REM16_ and REM32_ ones have been modified to reflect a nonexistant
  93. // field (svX_platform_id). This messes up the automatic conversions
  94. // done by RxRemoteApi. So, we use the original descriptors (REMSmb_)
  95. // and do our own conversion later. (RxRemoteApi does byte swapping if
  96. // necessary, but the rest is up to us.)
  97. //
  98. if (! NetpIsNewServerInfoLevel(Level)) {
  99. IF_DEBUG(SERVER) {
  100. NetpKdPrint(("RxNetServerGetInfo: "
  101. "caller didn't ask for new level.\n"));
  102. }
  103. *BufPtr = NULL;
  104. return (ERROR_INVALID_LEVEL);
  105. }
  106. Status = RxGetServerInfoLevelEquivalent (
  107. Level, // from level
  108. TRUE, // from native
  109. TRUE, // to native
  110. & OldLevel, // to level
  111. & OldDataDesc16, // to data desc 16
  112. & OldDataDesc32, // to data desc 32
  113. & OldDataDescSmb, // to data desc SMB
  114. NULL, // don't need from max size
  115. & NewFixedSize, // from fixed size
  116. & NewStringSize, // from string size
  117. & OldApiBufferSize, // to max size
  118. NULL, // don't need to fixed size
  119. NULL, // don't need to string size
  120. NULL); // don't need to know if this is incomplete
  121. if (Status == ERROR_INVALID_LEVEL) {
  122. IF_DEBUG(SERVER) {
  123. NetpKdPrint(("RxNetServerGetInfo: "
  124. "RxGetServerInfoLevelEquivalent says bad level.\n"));
  125. }
  126. *BufPtr = NULL;
  127. return (ERROR_INVALID_LEVEL);
  128. }
  129. NetpAssert(Status == NERR_Success);
  130. NetpAssert(NetpIsOldServerInfoLevel(OldLevel));
  131. //
  132. // Ok, we know we're dealing with a valid info level, so allocate the
  133. // buffer for the get-info struct (for old info level).
  134. //
  135. IF_DEBUG(SERVER) {
  136. NetpKdPrint(("RxNetServerGetInfo: old api buff size (32-bit) is "
  137. FORMAT_DWORD "\n", OldApiBufferSize));
  138. }
  139. Status = NetApiBufferAllocate( OldApiBufferSize, (LPVOID *)&OldApiBuffer );
  140. if (Status != NERR_Success) {
  141. *BufPtr = NULL;
  142. return (Status);
  143. }
  144. //
  145. // Get old info level data from the other machine.
  146. //
  147. IF_DEBUG(SERVER) {
  148. TotalAvail = 11223344; // Just some value I can see hasn't changed.
  149. }
  150. Status = RxRemoteApi(
  151. API_WServerGetInfo, // API number
  152. UncServerName, // server name (with \\)
  153. ParmDesc16, // parm desc (16-bit)
  154. OldDataDesc16, // data desc (16-bit)
  155. OldDataDesc32, // data desc (32-bit)
  156. OldDataDescSmb, // data desc (SMB version)
  157. NULL, // no aux desc 16
  158. NULL, // no aux desc 32
  159. NULL, // no aux desc SMB
  160. FALSE, // not a "no perm req" API
  161. // LanMan 2.x args to NetServerGetInfo, in 32-bit form:
  162. OldLevel, // level (pretend)
  163. OldApiBuffer, // ptr to get 32-bit old info
  164. OldApiBufferSize, // size of OldApiBuffer
  165. & TotalAvail); // total available (set)
  166. IF_DEBUG(SERVER) {
  167. NetpKdPrint(("RxNetServerGetInfo(" FORMAT_DWORD
  168. "): back from RxRemoteApi, status=" FORMAT_API_STATUS
  169. ", total_avail=" FORMAT_DWORD ".\n",
  170. Level, Status, TotalAvail));
  171. }
  172. if (RxpFatalErrorCode(Status)) {
  173. (void) NetApiBufferFree(OldApiBuffer);
  174. *BufPtr = NULL;
  175. return (Status);
  176. }
  177. // We allocated buffer, so we "know" it's large enough:
  178. NetpAssert(Status != ERROR_MORE_DATA);
  179. NetpAssert(Status != NERR_BufTooSmall);
  180. if (Status == NERR_Success) {
  181. NetpAssert(TotalAvail <= OldApiBufferSize);
  182. }
  183. //
  184. // Now we have to convert old info level stuff to new info level.
  185. //
  186. Status = NetApiBufferAllocate(
  187. NewFixedSize+NewStringSize,
  188. (LPVOID *)&NewApiBuffer);
  189. if (Status != NERR_Success) {
  190. (void) NetApiBufferFree(OldApiBuffer);
  191. *BufPtr = NULL;
  192. return (Status);
  193. }
  194. IF_DEBUG(SERVER) {
  195. NetpKdPrint(("RxNetServerGetInfo: alloced new buf at "
  196. FORMAT_LPVOID ".\n", (LPVOID) NewApiBuffer));
  197. }
  198. Status = NetpConvertServerInfo(
  199. OldLevel, // from level
  200. OldApiBuffer, // from structure
  201. TRUE, // from native format
  202. Level, // to level
  203. NewApiBuffer, // to info
  204. NewFixedSize, // to fixed size
  205. NewStringSize, // to string size
  206. TRUE, // to native format
  207. NULL); // use default string area
  208. if (Status != NERR_Success) {
  209. (void) NetApiBufferFree(OldApiBuffer);
  210. *BufPtr = NULL;
  211. return (Status);
  212. }
  213. NetpAssert(NewApiBuffer != NULL);
  214. (void) NetApiBufferFree(OldApiBuffer);
  215. *BufPtr = NewApiBuffer;
  216. return (Status);
  217. } // RxNetServerGetInfo