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.

319 lines
8.4 KiB

  1. /*++
  2. Copyright (c) 1991-92 Microsoft Corporation
  3. Module Name:
  4. rxchdev.c
  5. Abstract:
  6. Contains RxNetCharDev routines:
  7. RxNetCharDevControl
  8. RxNetCharDevEnum
  9. RxNetCharDevGetInfo
  10. Author:
  11. Richard Firth (rfirth) 20-May-1991
  12. Environment:
  13. Win-32/flat address space
  14. Notes:
  15. Routines in this module assume that caller-supplied parameters have
  16. already been verified. No effort is made to further check the veracity
  17. of parms. Any actions causing exceptions must be trapped at a higher
  18. level. This applies to ALL parameters - strings, pointers, buffers, etc.
  19. Revision History:
  20. 20-May-1991 RFirth
  21. Created
  22. 13-Sep-1991 JohnRo
  23. Made changes suggested by PC-LINT.
  24. 25-Sep-1991 JohnRo
  25. Fixed MIPS build problems.
  26. 05-Dec-1991 RFirth
  27. Enum returns in TotalEntries (or EntriesLeft) the number of items to
  28. be enumerated BEFORE this call. Used to be number left after this call
  29. 07-Feb-1992 JohnRo
  30. Use NetApiBufferAllocate() instead of private version.
  31. --*/
  32. #include "downlevl.h"
  33. #include <rxchdev.h>
  34. #include <lmchdev.h>
  35. NET_API_STATUS
  36. RxNetCharDevControl(
  37. IN LPTSTR ServerName,
  38. IN LPTSTR DeviceName,
  39. IN DWORD Opcode
  40. )
  41. /*++
  42. Routine Description:
  43. Remotely applies a control action to a shared device. This particular
  44. routine deals with down-level Lanman servers
  45. Arguments:
  46. ServerName - Where to run the remoted API
  47. DeviceName - Name of device for which to issue control
  48. Opcode - Action to apply
  49. Return Value:
  50. NET_API_STATUS
  51. Success - NERR_Success
  52. Failure - ERROR_INVALID_PARAMETER
  53. DeviceName invalid
  54. (return code from remoted API)
  55. --*/
  56. {
  57. if (STRLEN(DeviceName) > LM20_DEVLEN) {
  58. return ERROR_INVALID_PARAMETER;
  59. }
  60. return RxRemoteApi(API_WCharDevControl, // API #
  61. ServerName, // where to run the API
  62. REMSmb_NetCharDevControl_P, // parameter string
  63. NULL, NULL, NULL, // no primary data structures
  64. NULL, NULL, NULL, // no aux. data structures
  65. FALSE, // caller needs to be logged on
  66. DeviceName, // API parameters...
  67. Opcode
  68. );
  69. }
  70. NET_API_STATUS
  71. RxNetCharDevEnum(
  72. IN LPTSTR ServerName,
  73. IN DWORD Level,
  74. OUT LPBYTE* Buffer,
  75. IN DWORD PrefMaxLen,
  76. OUT LPDWORD EntriesRead,
  77. OUT LPDWORD EntriesLeft,
  78. IN OUT LPDWORD ResumeHandle OPTIONAL
  79. )
  80. /*++
  81. Routine Description:
  82. Returns a buffer containing a list of information structures detailing the
  83. shared communications devices at a down-level Lanman server
  84. Arguments:
  85. ServerName - Where to run the remoted API
  86. Level - Of info requested - 0 or 1
  87. Buffer - Pointer to returned pointer to buffer containing info
  88. PrefMaxLen - Caller's preferred maximum returned buffer size
  89. EntriesRead - Pointer to returned number of structures in Buffer
  90. EntriesLeft - Pointer to returned number of structures left to enumerate
  91. ResumeHandle- Pointer to returned handle for continuing enumeration. IGNORED
  92. Return Value:
  93. NET_API_STATUS
  94. Success - NERR_Success
  95. Failure - ERROR_INVALID_PARAMETER
  96. DeviceName invalid
  97. ResumeHandle not 0 or NULL
  98. (return code from remoted API)
  99. --*/
  100. {
  101. DWORD entries_read, total_avail;
  102. LPDESC pDesc16, pDesc32, pDescSmb;
  103. LPBYTE bufptr;
  104. NET_API_STATUS rc;
  105. UNREFERENCED_PARAMETER(PrefMaxLen);
  106. //
  107. // test out the caller supplied arguments. This should be done at the outer
  108. // level
  109. //
  110. *Buffer = NULL;
  111. *EntriesRead = *EntriesLeft = 0;
  112. if (!NULL_REFERENCE(ResumeHandle)) {
  113. return ERROR_INVALID_PARAMETER;
  114. }
  115. switch (Level) {
  116. case 0:
  117. pDesc16 = REM16_chardev_info_0;
  118. pDesc32 = REM32_chardev_info_0;
  119. pDescSmb = REMSmb_chardev_info_0;
  120. break;
  121. case 1:
  122. pDesc16 = REM16_chardev_info_1;
  123. pDesc32 = REM32_chardev_info_1;
  124. pDescSmb = REMSmb_chardev_info_1;
  125. break;
  126. default:
  127. return ERROR_INVALID_LEVEL;
  128. }
  129. //
  130. // In the Enum case, since we don't know how much data will come back, we
  131. // leave the returned buffer allocation to the lower levels of software.
  132. // Thus we get back an exact amount of data, not a horrendous maximum
  133. //
  134. bufptr = NULL;
  135. rc = RxRemoteApi(API_NetCharDevEnum, // API #
  136. ServerName, // where to remote it
  137. REMSmb_NetCharDevEnum_P, // parameter descriptor
  138. pDesc16, pDesc32, pDescSmb, // primary structure descriptors
  139. NULL, NULL, NULL, // no aux data structures
  140. ALLOCATE_RESPONSE,
  141. Level, // API parameters start here...
  142. &bufptr, // RxRemoteApi will allocate buffer
  143. 65535, // maximum 16-bit SMB receive buffer
  144. &entries_read,
  145. &total_avail
  146. );
  147. if (rc) {
  148. //
  149. // If a buffer was allocated on our behalf by RxRemoteApi before it
  150. // went under then free it
  151. //
  152. if (bufptr) {
  153. (void) NetApiBufferFree(bufptr);
  154. }
  155. } else {
  156. *Buffer = bufptr;
  157. *EntriesRead = entries_read;
  158. *EntriesLeft = total_avail;
  159. }
  160. return rc;
  161. }
  162. NET_API_STATUS
  163. RxNetCharDevGetInfo(
  164. IN LPTSTR ServerName,
  165. IN LPTSTR DeviceName,
  166. IN DWORD Level,
  167. OUT LPBYTE* Buffer
  168. )
  169. /*++
  170. Routine Description:
  171. Returns an information structure detailing a particular shared comms device
  172. at a down-level server
  173. Arguments:
  174. ServerName - Where to run the remoted API
  175. DeviceName - Name of device for which to get info
  176. Level - Of info required - 0 or 1
  177. Buffer - Pointer to returned pointer to buffer containing info
  178. Return Value:
  179. NET_API_STATUS
  180. Success - NERR_Success
  181. Failure - ERROR_INVALID_PARAMETER
  182. DeviceName too long
  183. ERROR_INVALID_LEVEL
  184. Level parameter not allowed
  185. (return code from remoted API)
  186. --*/
  187. {
  188. DWORD buflen, total_avail;
  189. LPDESC pDesc16, pDesc32, pDescSmb;
  190. LPBYTE bufptr;
  191. NET_API_STATUS rc;
  192. //
  193. // test out the caller supplied arguments. This should be done at the outer
  194. // level
  195. //
  196. *Buffer = NULL;
  197. if (STRLEN(DeviceName) > LM20_DEVLEN) {
  198. return ERROR_INVALID_PARAMETER;
  199. }
  200. switch (Level) {
  201. case 0:
  202. pDesc16 = REM16_chardev_info_0;
  203. pDesc32 = REM32_chardev_info_0;
  204. pDescSmb = REMSmb_chardev_info_0;
  205. buflen = sizeof(CHARDEV_INFO_0) + STRING_SPACE_REQD(DEVLEN + 1);
  206. break;
  207. case 1:
  208. pDesc16 = REM16_chardev_info_1;
  209. pDesc32 = REM32_chardev_info_1;
  210. pDescSmb = REMSmb_chardev_info_1;
  211. buflen = sizeof(CHARDEV_INFO_1) + STRING_SPACE_REQD(DEVLEN + 1) +
  212. STRING_SPACE_REQD(UNLEN + 1);
  213. break;
  214. default:
  215. return ERROR_INVALID_LEVEL;
  216. }
  217. //
  218. // In the GetInfo case we are content to pre-allocate the return buffer
  219. // because we know how large it should be (although we actually allocate
  220. // the maximum size for a particular GetInfo structure level)
  221. //
  222. if (rc = NetApiBufferAllocate(buflen, (LPVOID *) &bufptr)) {
  223. return rc;
  224. }
  225. rc = RxRemoteApi(API_NetCharDevGetInfo, // API #
  226. ServerName, // where to remote it
  227. REMSmb_NetCharDevGetInfo_P, // parameter descriptor
  228. pDesc16, pDesc32, pDescSmb, // primary structure descriptors
  229. NULL, NULL, NULL, // no aux data structures
  230. FALSE, // can't use NULL session
  231. DeviceName, // API parameters start here...
  232. Level,
  233. bufptr,
  234. buflen, // supplied by us
  235. &total_avail // not used by 32-bit API
  236. );
  237. if (rc) {
  238. (void) NetApiBufferFree(bufptr);
  239. } else {
  240. *Buffer = bufptr;
  241. }
  242. return rc;
  243. }