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.

228 lines
5.7 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. ApiConn.c
  5. Abstract:
  6. This module contains individual API handlers for the NetConnection APIs.
  7. SUPPORTED : NetConnectionEnum.
  8. Author:
  9. Shanku Niyogi (w-shanku) 26-Feb-1991
  10. Revision History:
  11. --*/
  12. #include "XactSrvP.h"
  13. //
  14. // Declaration of descriptor strings.
  15. //
  16. STATIC const LPDESC Desc16_connection_info_0 = REM16_connection_info_0;
  17. STATIC const LPDESC Desc32_connection_info_0 = REM32_connection_info_0;
  18. STATIC const LPDESC Desc16_connection_info_1 = REM16_connection_info_1;
  19. STATIC const LPDESC Desc32_connection_info_1 = REM32_connection_info_1;
  20. NTSTATUS
  21. XsNetConnectionEnum (
  22. API_HANDLER_PARAMETERS
  23. )
  24. /*++
  25. Routine Description:
  26. This routine handles a call to NetConnectionEnum.
  27. Arguments:
  28. API_HANDLER_PARAMETERS - information about the API call. See
  29. XsTypes.h for details.
  30. Return Value:
  31. NTSTATUS - STATUS_SUCCESS or reason for failure.
  32. --*/
  33. {
  34. NET_API_STATUS status;
  35. PXS_NET_CONNECTION_ENUM parameters = Parameters;
  36. LPTSTR nativeQualifier = NULL; // Native parameters
  37. LPVOID outBuffer = NULL;
  38. DWORD entriesRead;
  39. DWORD totalEntries;
  40. WORD bufferLength;
  41. DWORD entriesFilled = 0; // Conversion variables
  42. DWORD bytesRequired = 0;
  43. LPDESC nativeStructureDesc;
  44. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  45. IF_DEBUG(CONNECTION) {
  46. NetpKdPrint(( "XsNetConnectionEnum: header at %lx, params at %lx, "
  47. "level %ld, buf size %ld\n",
  48. Header, parameters, SmbGetUshort( &parameters->Level ),
  49. SmbGetUshort( &parameters->BufLen )));
  50. }
  51. try {
  52. //
  53. // Translate parameters, check for errors.
  54. //
  55. if ( XsWordParamOutOfRange( parameters->Level, 0, 1 )) {
  56. Header->Status = (WORD)ERROR_INVALID_LEVEL;
  57. goto cleanup;
  58. }
  59. XsConvertTextParameter(
  60. nativeQualifier,
  61. (LPSTR)XsSmbGetPointer( &parameters->Qualifier )
  62. );
  63. bufferLength = SmbGetUshort( &parameters->BufLen );
  64. //
  65. // Make the local call.
  66. //
  67. status = NetConnectionEnum(
  68. NULL,
  69. nativeQualifier,
  70. (DWORD)SmbGetUshort( &parameters->Level ),
  71. (LPBYTE *)&outBuffer,
  72. XsNativeBufferSize( bufferLength ),
  73. &entriesRead,
  74. &totalEntries,
  75. NULL
  76. );
  77. if ( !XsApiSuccess( status )) {
  78. IF_DEBUG(API_ERRORS) {
  79. NetpKdPrint(( "XsNetConnectionEnum: NetConnectionEnum failed: "
  80. "%X\n", status ));
  81. }
  82. Header->Status = (WORD)status;
  83. goto cleanup;
  84. }
  85. IF_DEBUG(CONNECTION) {
  86. NetpKdPrint(( "XsNetConnectionEnum: received %ld entries at %lx\n",
  87. entriesRead, outBuffer ));
  88. }
  89. //
  90. // Use the requested level to determine the format of the
  91. // data structure.
  92. //
  93. switch ( SmbGetUshort( &parameters->Level ) ) {
  94. case 0:
  95. nativeStructureDesc = Desc32_connection_info_0;
  96. StructureDesc = Desc16_connection_info_0;
  97. break;
  98. case 1:
  99. nativeStructureDesc = Desc32_connection_info_1;
  100. StructureDesc = Desc16_connection_info_1;
  101. break;
  102. }
  103. //
  104. // Do the actual conversion from the 32-bit structures to 16-bit
  105. // structures.
  106. //
  107. XsFillEnumBuffer(
  108. outBuffer,
  109. entriesRead,
  110. nativeStructureDesc,
  111. (LPVOID)XsSmbGetPointer( &parameters->Buffer ),
  112. (LPVOID)XsSmbGetPointer( &parameters->Buffer ),
  113. (DWORD)bufferLength,
  114. StructureDesc,
  115. NULL, // verify function
  116. &bytesRequired,
  117. &entriesFilled,
  118. NULL
  119. );
  120. IF_DEBUG(CONNECTION) {
  121. NetpKdPrint(( "32-bit data at %lx, 16-bit data at %lx, %ld BR,"
  122. " Entries %ld of %ld\n",
  123. outBuffer, SmbGetUlong( &parameters->Buffer ),
  124. bytesRequired, entriesFilled, totalEntries ));
  125. }
  126. //
  127. // If all the entries could not be filled, return ERROR_MORE_DATA,
  128. // and return the buffer as is. Otherwise, the data needs to be
  129. // packed so that we don't send too much useless data.
  130. //
  131. if ( (entriesFilled < totalEntries) ||
  132. (bytesRequired > bufferLength) ) {
  133. Header->Status = ERROR_MORE_DATA;
  134. } else {
  135. Header->Converter = XsPackReturnData(
  136. (LPVOID)XsSmbGetPointer( &parameters->Buffer ),
  137. bufferLength,
  138. StructureDesc,
  139. entriesFilled
  140. );
  141. }
  142. //
  143. // Set up the response parameters.
  144. //
  145. SmbPutUshort( &parameters->EntriesRead, (WORD)entriesFilled );
  146. SmbPutUshort( &parameters->TotalAvail, (WORD)totalEntries );
  147. cleanup:
  148. ;
  149. } except( EXCEPTION_EXECUTE_HANDLER ) {
  150. Header->Status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  151. }
  152. NetApiBufferFree( outBuffer );
  153. NetpMemoryFree( nativeQualifier );
  154. //
  155. // Determine return buffer size.
  156. //
  157. XsSetDataCount(
  158. &parameters->BufLen,
  159. StructureDesc,
  160. Header->Converter,
  161. entriesFilled,
  162. Header->Status
  163. );
  164. return STATUS_SUCCESS;
  165. } //XsNetConnectionEnum