Source code of Windows XP (NT5)
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.

379 lines
10 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. MWKSTA.C
  5. Abstract:
  6. 32 bit version of mapping routines for NetWkstaGet/SetInfo API
  7. Author:
  8. Dan Hinsley (danhi) 06-Jun-1991
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. 24-Apr-1991 danhi
  13. Created
  14. 06-Jun-1991 Danhi
  15. Sweep to conform to NT coding style
  16. 15-Aug-1991 JohnRo
  17. Implement downlevel NetWksta APIs. (Moved DanHi's NetCmd/Map32/MWksta
  18. conversion stuff to NetLib.)
  19. Got rid of _DH hacks.
  20. Made some UNICODE changes.
  21. 16-Oct-1991 W-ShankN
  22. Added Unicode mapping layer.
  23. Cleaned up old excess baggage.
  24. --*/
  25. //
  26. // INCLUDES
  27. //
  28. #include <windef.h>
  29. #include <winerror.h>
  30. #include <stdio.h>
  31. #include <memory.h>
  32. #include <tstring.h>
  33. #include <malloc.h>
  34. #include <stddef.h>
  35. #include <excpt.h> // try, finally, etc.
  36. #include <lm.h>
  37. #include <mapsupp.h> // BUILD_LENGTH_ARRAY, NetpMoveStrings
  38. #include <dlwksta.h>
  39. #include "mwksta.h"
  40. NET_API_STATUS
  41. NetpMakeWkstaLevelForNT(
  42. DWORD Level,
  43. PWKSTA_INFO_101 pLevel101,
  44. PWKSTA_USER_INFO_1 pLevelUser_1,
  45. PWKSTA_INFO_502 pLevel502,
  46. PWKSTA_INFO_0 * ppLevel0
  47. );
  48. DWORD
  49. MNetWkstaGetInfo(
  50. IN DWORD nLevel,
  51. LPVOID * ppbBuffer
  52. )
  53. {
  54. NET_API_STATUS ReturnCode;
  55. LPWKSTA_INFO_502 pLevel502 = NULL;
  56. LPTSTR pLevel10;
  57. PWKSTA_INFO_101 pLevel101;
  58. PWKSTA_USER_INFO_1 pLevelUser_1;
  59. //
  60. // Get level 101 first, which will supply some of the
  61. // other information we'll need then User_1, then 502.
  62. //
  63. ReturnCode = NetWkstaGetInfo(NULL, 101, (LPBYTE *) &pLevel101);
  64. if (ReturnCode)
  65. {
  66. return ReturnCode;
  67. }
  68. NetpAssert(pLevel101 != NULL) ; // since API succeeded
  69. ReturnCode = NetWkstaUserGetInfo(NULL, 1, (LPBYTE *) &pLevelUser_1);
  70. if (ReturnCode)
  71. {
  72. NetApiBufferFree(pLevel101);
  73. return ReturnCode;
  74. }
  75. NetpAssert(pLevel101->wki101_platform_id == PLATFORM_ID_NT);
  76. //
  77. // This is to be able to call NetApiBufferFree no matter where I
  78. // exit from. Note the indentation level is not incremented for
  79. // the switch. No sense going too deep.
  80. //
  81. try
  82. {
  83. //
  84. // It all depends on what info level they've asked for:
  85. //
  86. switch(nLevel)
  87. {
  88. case 0:
  89. case 1:
  90. {
  91. PWKSTA_INFO_0 pLevel0or1;
  92. //
  93. // This depends on the platform id being 300 400 500
  94. //
  95. ReturnCode = NetWkstaGetInfo(NULL, 502, (LPBYTE*) &pLevel502);
  96. if (ReturnCode)
  97. {
  98. return ReturnCode;
  99. }
  100. //
  101. // Call the platform dependant worker function that builds
  102. // the old structure.
  103. //
  104. ReturnCode = NetpMakeWkstaLevelForNT(nLevel,
  105. pLevel101,
  106. pLevelUser_1,
  107. pLevel502,
  108. &pLevel0or1);
  109. if (ReturnCode)
  110. {
  111. return ReturnCode;
  112. }
  113. //
  114. // Put the pointer to the new structure in the user's pointer.
  115. //
  116. *ppbBuffer = pLevel0or1;
  117. break;
  118. }
  119. case 10:
  120. {
  121. DWORD Level10_101_Length[2];
  122. DWORD Level10_User_1_Length[3];
  123. DWORD i;
  124. DWORD BytesRequired = 0;
  125. LPBYTE pFloor;
  126. //
  127. // Everything needed for a level 10 is in level 101/User_1
  128. // This is pretty straightforward, let's just do it here.
  129. //
  130. // Initialize the Level10_xxx_Length array with the length of each
  131. // string in the input buffers, and allocate the new buffer
  132. // for WKSTA_INFO_10
  133. //
  134. BUILD_LENGTH_ARRAY(BytesRequired, 10, 101, Wksta)
  135. BUILD_LENGTH_ARRAY(BytesRequired, 10, User_1, Wksta)
  136. //
  137. // Allocate the new buffer which will be returned to the user.
  138. //
  139. ReturnCode = NetapipBufferAllocate(BytesRequired + sizeof(WKSTA_INFO_10),
  140. (LPVOID *) &pLevel10);
  141. if (ReturnCode)
  142. {
  143. return ERROR_NOT_ENOUGH_MEMORY;
  144. }
  145. //
  146. // First get the floor to start moving strings in at.
  147. //
  148. pFloor = (LPBYTE) pLevel10 + BytesRequired + sizeof(WKSTA_INFO_10);
  149. //
  150. // Now move the variable length entries into the new buffer from
  151. // the 101, 402 and User_1 data structures.
  152. //
  153. NetpMoveStrings((LPTSTR *)&pFloor, (LPTSTR) pLevel101, pLevel10,
  154. NetpWksta10_101, Level10_101_Length);
  155. NetpMoveStrings((LPTSTR *)&pFloor, (LPTSTR) pLevelUser_1, pLevel10,
  156. NetpWksta10_User_1, Level10_User_1_Length);
  157. //
  158. // Now set the rest of the fields in the fixed length portion
  159. // of the structure
  160. //
  161. ((PWKSTA_INFO_10) pLevel10)->wki10_ver_major =
  162. pLevel101->wki101_ver_major;
  163. ((PWKSTA_INFO_10) pLevel10)->wki10_ver_minor =
  164. pLevel101->wki101_ver_minor;
  165. //
  166. // Put the pointer to the new structure in the user's pointer.
  167. //
  168. *ppbBuffer = pLevel10;
  169. break;
  170. }
  171. //
  172. // Not a level I recognize
  173. //
  174. default:
  175. return ERROR_INVALID_LEVEL;
  176. } // end of the switch statement
  177. } // end of the try block
  178. finally
  179. {
  180. //
  181. // Free up the buffers returned by NetWkstaGetInfo
  182. //
  183. NetApiBufferFree((LPBYTE) pLevel101);
  184. NetApiBufferFree((LPBYTE) pLevelUser_1);
  185. if (pLevel502)
  186. {
  187. NetApiBufferFree((LPBYTE) pLevel502);
  188. }
  189. }
  190. return NERR_Success;
  191. }
  192. NET_API_STATUS
  193. NetpMakeWkstaLevelForNT(
  194. IN DWORD Level,
  195. PWKSTA_INFO_101 pLevel101,
  196. PWKSTA_USER_INFO_1 pLevelUser_1,
  197. PWKSTA_INFO_502 pLevel502,
  198. OUT PWKSTA_INFO_0 * ppLevel0
  199. )
  200. {
  201. DWORD BytesRequired = 0;
  202. DWORD ReturnCode;
  203. DWORD Level0_101_Length[3];
  204. DWORD Level0_User_1_Length[2];
  205. DWORD Level1_User_1_Length[2];
  206. DWORD i;
  207. LPBYTE pFloor;
  208. NetpAssert( (Level==0) || (Level==1) );
  209. //
  210. // Initialize the Level0_xxx_Length array with the length of each string
  211. // in the buffers, and allocate the new buffer for WKSTA_INFO_0
  212. //
  213. BUILD_LENGTH_ARRAY(BytesRequired, 0, 101, Wksta)
  214. BUILD_LENGTH_ARRAY(BytesRequired, 0, User_1, Wksta)
  215. //
  216. // If this is for a level 1, allocate the additional space for the extra
  217. // elements
  218. //
  219. if (Level == 1) {
  220. BUILD_LENGTH_ARRAY(BytesRequired, 1, User_1, Wksta)
  221. }
  222. //
  223. // Allocate the new buffer which will be returned to the user. Allocate
  224. // space for a level 1 just in case that's what we're doing.
  225. //
  226. ReturnCode = NetapipBufferAllocate(BytesRequired + sizeof(WKSTA_INFO_1),
  227. (LPVOID *) ppLevel0);
  228. if (ReturnCode) {
  229. return(ERROR_NOT_ENOUGH_MEMORY);
  230. }
  231. //
  232. // First get the floor to start moving strings in at.
  233. //
  234. pFloor = (LPBYTE) *ppLevel0 + BytesRequired + sizeof(WKSTA_INFO_1);
  235. //
  236. // Now move the variable length entries into the new buffer from the
  237. // 2 data structures.
  238. //
  239. NetpMoveStrings((LPTSTR*)&pFloor, (LPTSTR)pLevel101, (LPTSTR)*ppLevel0,
  240. NetpWksta0_101,
  241. Level0_101_Length);
  242. NetpMoveStrings((LPTSTR*)&pFloor, (LPTSTR)pLevelUser_1, (LPTSTR)*ppLevel0,
  243. NetpWksta0_User_1, Level0_User_1_Length);
  244. //
  245. // Now set the rest of the fields in the fixed length portion
  246. // of the structure. Most of these fields don't exist on NT, so
  247. // I'll just say BIG!
  248. //
  249. (*ppLevel0)->wki0_ver_major = pLevel101->wki101_ver_major;
  250. (*ppLevel0)->wki0_ver_minor = pLevel101->wki101_ver_minor;
  251. (*ppLevel0)->wki0_charwait = pLevel502->wki502_char_wait;
  252. (*ppLevel0)->wki0_chartime = pLevel502->wki502_collection_time;
  253. (*ppLevel0)->wki0_charcount =
  254. pLevel502->wki502_maximum_collection_count;
  255. (*ppLevel0)->wki0_keepconn = pLevel502->wki502_keep_conn;
  256. (*ppLevel0)->wki0_keepsearch = (ULONG)-1;
  257. (*ppLevel0)->wki0_maxthreads = pLevel502->wki502_max_threads;
  258. (*ppLevel0)->wki0_maxcmds = pLevel502->wki502_max_cmds;
  259. (*ppLevel0)->wki0_numworkbuf = (ULONG)-1;
  260. (*ppLevel0)->wki0_sizworkbuf = (ULONG)-1;
  261. (*ppLevel0)->wki0_maxwrkcache = (ULONG)-1;
  262. (*ppLevel0)->wki0_sesstimeout = pLevel502->wki502_sess_timeout;
  263. (*ppLevel0)->wki0_sizerror = (ULONG)-1;
  264. (*ppLevel0)->wki0_numalerts = (ULONG)-1;
  265. (*ppLevel0)->wki0_numservices = (ULONG)-1;
  266. (*ppLevel0)->wki0_errlogsz = (ULONG)-1;
  267. (*ppLevel0)->wki0_printbuftime = (ULONG)-1;
  268. (*ppLevel0)->wki0_numcharbuf = (ULONG)-1;
  269. (*ppLevel0)->wki0_sizcharbuf = pLevel502->wki502_siz_char_buf;
  270. (*ppLevel0)->wki0_wrkheuristics = NULL;
  271. (*ppLevel0)->wki0_mailslots = (ULONG)-1;
  272. //
  273. // If we're building a level 1, do the incremental fields
  274. //
  275. if (Level == 1) {
  276. //
  277. // Now finish up by moving in the level 1 stuff. This assumes that all
  278. // the offsets into the level 0 and level 1 structures are the same
  279. // except for the additional level 1 stuff
  280. //
  281. //
  282. // First the strings
  283. //
  284. NetpMoveStrings((LPTSTR*)&pFloor, (LPTSTR)pLevelUser_1, (LPTSTR)*ppLevel0,
  285. NetpWksta1_User_1, Level1_User_1_Length);
  286. //
  287. // No fixed length data
  288. //
  289. }
  290. return 0 ;
  291. }