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.

346 lines
13 KiB

  1. /*++
  2. Copyright (c) 1991-92 Microsoft Corporation
  3. Module Name:
  4. SrvStInf.c
  5. Abstract:
  6. This module only contains RxNetServerSetInfo.
  7. Author:
  8. John Rogers (JohnRo) 05-Jun-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. 05-Jun-1991 JohnRo
  14. Created.
  15. 07-Jun-1991 JohnRo
  16. PC-LINT found a bug calling RapTotalSize().
  17. 14-Jun-1991 JohnRo
  18. Call RxRemoteApi (to get old info) instead of RxNetServerGetInfo;
  19. this will allow incomplete info level conversions to work.
  20. 10-Jul-1991 JohnRo
  21. Added more parameters to RxpSetField.
  22. 17-Jul-1991 JohnRo
  23. Extracted RxpDebug.h from Rxp.h.
  24. 21-Nov-1991 JohnRo
  25. Removed NT dependencies to reduce recompiles.
  26. 04-Dec-1991 JohnRo
  27. Change RxNetServerSetInfo() to new-style interface.
  28. 07-Feb-1992 JohnRo
  29. Use NetApiBufferAllocate() instead of private version.
  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> // API_ equates.
  37. #include <dlserver.h> // NetpConvertServerInfo().
  38. #include <lmapibuf.h> // NetApiBufferAllocate(), NetApiBufferFree().
  39. #include <lmerr.h> // NERR_ and ERROR_ equates.
  40. #include <netdebug.h> // NetpAssert(), FORMAT_ equates, etc.
  41. #include <netlib.h> // NetpSetParmError().
  42. #include <remdef.h>
  43. #include <rx.h> // RxRemoteApi().
  44. #include <rxp.h> // RxpSetField().
  45. #include <rxpdebug.h> // IF_DEBUG().
  46. #include <rxserver.h> // My prototype, etc.
  47. NET_API_STATUS
  48. RxNetServerSetInfo (
  49. IN LPTSTR UncServerName,
  50. IN DWORD Level, // level and/or ParmNum.
  51. IN LPBYTE Buf,
  52. OUT LPDWORD ParmError OPTIONAL // name required by NetpSetParmError macro.
  53. )
  54. /*++
  55. Routine Description:
  56. RxNetServerSetInfo performs the same function as NetServerSetInfo,
  57. except that the server name is known to refer to a downlevel server.
  58. Arguments:
  59. (Same as NetServerSetInfo, except UncServerName must not be null, and
  60. must not refer to the local computer.)
  61. Return Value:
  62. (Same as NetServerSetInfo.)
  63. --*/
  64. {
  65. BOOL IncompleteOutput;
  66. LPDESC EquivDataDesc16;
  67. LPDESC EquivDataDesc32;
  68. LPDESC EquivDataDescSmb;
  69. DWORD EquivLevel;
  70. DWORD EquivFixedSize;
  71. DWORD EquivMaxNativeSize;
  72. DWORD EquivStringSize;
  73. DWORD NewLevelOnly;
  74. DWORD ParmNum;
  75. NET_API_STATUS Status;
  76. // It's easiest to assume failure, and correct that assumption later.
  77. NetpSetParmError( PARM_ERROR_UNKNOWN );
  78. NetpAssert(UncServerName != NULL);
  79. if (Level < PARMNUM_BASE_INFOLEVEL) {
  80. NewLevelOnly = Level;
  81. ParmNum = PARMNUM_ALL;
  82. } else {
  83. NewLevelOnly = NEW_SERVER_SUPERSET_LEVEL;
  84. ParmNum = Level - PARMNUM_BASE_INFOLEVEL;
  85. }
  86. if (!NetpIsNewServerInfoLevel(NewLevelOnly)) {
  87. return (ERROR_INVALID_LEVEL);
  88. }
  89. if (ParmNum > 99) {
  90. return (ERROR_INVALID_LEVEL);
  91. }
  92. //
  93. // Need lots of data on the requested info level and the equivalent
  94. // old info level...
  95. //
  96. Status = RxGetServerInfoLevelEquivalent(
  97. NewLevelOnly, // from level
  98. TRUE, // from native
  99. TRUE, // to native
  100. & EquivLevel, // to level
  101. & EquivDataDesc16,
  102. & EquivDataDesc32,
  103. & EquivDataDescSmb,
  104. NULL, // don't need native size of from
  105. NULL, // don't need from fixed size
  106. NULL, // don't need from string size
  107. & EquivMaxNativeSize, // max native size of to level
  108. & EquivFixedSize, // to fixed size
  109. & EquivStringSize, // to string size
  110. & IncompleteOutput); // is output not fully in input?
  111. NetpAssert(Status == NERR_Success); // Already checked Level!
  112. NetpAssert( NetpIsOldServerInfoLevel( EquivLevel ) );
  113. if( Status != NERR_Success )
  114. {
  115. return Status;
  116. }
  117. //
  118. // Depending on ParmNum, either we're setting the entire thing, or just
  119. // one field.
  120. //
  121. if (ParmNum == PARMNUM_ALL) {
  122. LPVOID EquivInfo; // Ptr to native "old" info.
  123. DWORD EquivActualSize32;
  124. if ( Buf == NULL )
  125. return ERROR_INVALID_PARAMETER;
  126. if (! IncompleteOutput) {
  127. // Have all the data we need, so alloc memory for conversion.
  128. Status = NetApiBufferAllocate( EquivMaxNativeSize, & EquivInfo );
  129. if (Status != NERR_Success) {
  130. return (Status);
  131. }
  132. // Convert caller's server info to an info level understood by
  133. // downlevel.
  134. Status = NetpConvertServerInfo (
  135. NewLevelOnly, // input level
  136. Buf, // input structure
  137. TRUE, // input is native format
  138. EquivLevel, // output will be equiv level
  139. EquivInfo, // output info
  140. EquivFixedSize,
  141. EquivStringSize,
  142. TRUE, // want output in native format
  143. NULL); // use default string area
  144. if (Status != NERR_Success) {
  145. NetpKdPrint(( "RxNetServerSetInfo: convert failed, stat="
  146. FORMAT_API_STATUS ".\n", Status));
  147. (void) NetApiBufferFree( EquivInfo );
  148. return (Status);
  149. }
  150. } else {
  151. DWORD TotalAvail;
  152. // Don't have enough data, so we have to do a get info. This will
  153. // allocate the "old" info level buffer for us.
  154. EquivInfo = NetpMemoryAllocate( EquivMaxNativeSize );
  155. if (EquivInfo == NULL) {
  156. return (ERROR_NOT_ENOUGH_MEMORY);
  157. }
  158. Status = RxRemoteApi(
  159. API_WServerGetInfo, // API number
  160. UncServerName, // server name (with \\)
  161. REMSmb_NetServerGetInfo_P, // parm desc (16-bit)
  162. EquivDataDesc16, // data desc (16-bit)
  163. EquivDataDesc32, // data desc (32-bit)
  164. EquivDataDescSmb, // data desc (SMB version)
  165. NULL, // no aux desc 16
  166. NULL, // no aux desc 32
  167. NULL, // no aux desc SMB
  168. FALSE, // not a "no perm req" API
  169. // LanMan 2.x args to NetServerGetInfo, in 32-bit form:
  170. EquivLevel, // level (pretend)
  171. EquivInfo, // ptr to get 32-bit old info
  172. EquivMaxNativeSize, // size of OldApiBuffer
  173. & TotalAvail); // total available (set)
  174. if (Status != NERR_Success) {
  175. NetpKdPrint(( "RxNetServerSetInfo: get info failed, stat="
  176. FORMAT_API_STATUS ".\n", Status));
  177. (void) NetApiBufferFree( EquivInfo );
  178. return (Status);
  179. }
  180. //
  181. // Overlay the caller's data into the equivalent info structure,
  182. // which contains items that we want to preserve.
  183. //
  184. // Note that this code takes advantage of the fact that a downlevel
  185. // server doesn't really set all of the fields just because we send
  186. // an entire structure. The server just sets the settable fields
  187. // from that structure. And the settable fields are defined by
  188. // the parmnums we can set. So, we don't bother copying all of
  189. // the fields here. (DanHi says this is OK.) --JohnRo 26-May-1991
  190. //
  191. // Also, when we do strings like this, we just point from one buffer
  192. // to the other buffer.
  193. //
  194. switch (NewLevelOnly) {
  195. case 102 :
  196. {
  197. LPSERVER_INFO_2 psv2 = (LPVOID) EquivInfo;
  198. LPSERVER_INFO_102 psv102 = (LPVOID) Buf;
  199. NetpAssert( EquivLevel == 2 );
  200. psv2->sv2_comment = psv102->sv102_comment;
  201. psv2->sv2_disc = psv102->sv102_disc;
  202. if (psv102->sv102_hidden) {
  203. psv2->sv2_hidden = SV_HIDDEN;
  204. } else {
  205. psv2->sv2_hidden = SV_VISIBLE;
  206. }
  207. psv2->sv2_announce = psv102->sv102_announce;
  208. psv2->sv2_anndelta = psv102->sv102_anndelta;
  209. }
  210. break;
  211. case 402 : // 402 and 403 have same settable fields...
  212. case 403 :
  213. {
  214. LPSERVER_INFO_2 psv2 = (LPVOID) EquivInfo;
  215. LPSERVER_INFO_402 psv402 = (LPVOID) Buf;
  216. NetpAssert( (EquivLevel == 2) || (EquivLevel == 3) );
  217. psv2->sv2_alerts = psv402->sv402_alerts;
  218. psv2->sv2_alertsched = psv402->sv402_alertsched;
  219. psv2->sv2_erroralert = psv402->sv402_erroralert;
  220. psv2->sv2_logonalert = psv402->sv402_logonalert;
  221. psv2->sv2_accessalert = psv402->sv402_accessalert;
  222. psv2->sv2_diskalert = psv402->sv402_diskalert;
  223. psv2->sv2_netioalert = psv402->sv402_netioalert;
  224. psv2->sv2_maxauditsz = psv402->sv402_maxauditsz;
  225. }
  226. break;
  227. default :
  228. NetpAssert( 0==1 );
  229. (void) NetApiBufferFree( EquivInfo );
  230. return (NERR_InternalError);
  231. }
  232. }
  233. NetpAssert( EquivInfo != NULL );
  234. EquivActualSize32 = RapTotalSize(
  235. EquivInfo, // in struct
  236. EquivDataDesc32, // in desc
  237. EquivDataDesc32, // out desc
  238. FALSE, // no meaningless input ptrs
  239. Both, // transmission mode
  240. NativeToNative); // conversion mode
  241. IF_DEBUG(SERVER) {
  242. NetpKdPrint(( "RxNetServerSetInfo(all): equiv actual size (32) is "
  243. FORMAT_DWORD ".\n", EquivActualSize32 ));
  244. }
  245. NetpAssert( EquivActualSize32 <= EquivMaxNativeSize );
  246. // Remote the API.
  247. Status = RxRemoteApi(
  248. API_WServerSetInfo, // api num
  249. UncServerName,
  250. REMSmb_NetServerSetInfo_P, // parm desc (SMB version)
  251. EquivDataDesc16,
  252. EquivDataDesc32,
  253. EquivDataDescSmb,
  254. NULL, // no aux desc 16
  255. NULL, // no aux desc 32
  256. NULL, // no aux desc SMB
  257. FALSE, // not a null perm req API
  258. // rest of API's arguments in 32-bit, native, LM 2.x format:
  259. EquivLevel,
  260. EquivInfo,
  261. EquivActualSize32,
  262. ParmNum);
  263. (void) NetApiBufferFree( EquivInfo );
  264. } else {
  265. // ParmNum indicates only one field, so set it.
  266. Status = RxpSetField(
  267. API_WServerSetInfo, // api number
  268. UncServerName,
  269. NULL, // no specific object (dest)
  270. NULL, // no specific object to set
  271. REMSmb_NetServerSetInfo_P, // parm desc (SMB version)
  272. EquivDataDesc16, // data desc 16
  273. EquivDataDesc32, // data desc 32
  274. EquivDataDescSmb, // data desc SMB version
  275. Buf, // native (old) info buffer
  276. ParmNum, // parm num to send
  277. ParmNum, // field index
  278. EquivLevel); // old info level
  279. }
  280. if (Status == NERR_Success) {
  281. NetpSetParmError(PARM_ERROR_NONE);
  282. } else if (Status == ERROR_INVALID_PARAMETER) {
  283. NetpSetParmError(ParmNum);
  284. } else {
  285. NetpSetParmError(PARM_ERROR_UNKNOWN);
  286. }
  287. return (Status);
  288. }