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.

285 lines
8.1 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. ApiStats.c
  5. Abstract:
  6. This module contains individual API handlers for the NetStatistics APIs.
  7. SUPPORTED : NetStatisticsGet2.
  8. Author:
  9. Shanku Niyogi (w-shanku) 04-Apr-1991
  10. Revision History:
  11. --*/
  12. #define LM20_WORKSTATION_STATISTICS
  13. #include "XactSrvP.h"
  14. #include <ntddnfs.h>
  15. #include <lmstats.h>
  16. //
  17. // Declaration of descriptor strings.
  18. //
  19. STATIC const LPDESC Desc16_stat_server_0 = REM16_stat_server_0;
  20. STATIC const LPDESC Desc32_stat_server_0 = REM32_stat_server_0;
  21. STATIC const LPDESC Desc16_stat_workstation_0 = REM16_stat_workstation_0;
  22. STATIC const LPDESC Desc32_stat_workstation_0 = REM32_stat_workstation_0;
  23. NTSTATUS
  24. XsNetStatisticsGet2 (
  25. API_HANDLER_PARAMETERS
  26. )
  27. /*++
  28. Routine Description:
  29. This routine handles a call to NetStatisticsGet.
  30. Arguments:
  31. API_HANDLER_PARAMETERS - information about the API call. See
  32. XsTypes.h for details.
  33. Return Value:
  34. NTSTATUS - STATUS_SUCCESS or reason for failure.
  35. --*/
  36. {
  37. NET_API_STATUS status;
  38. PXS_NET_STATISTICS_GET_2 parameters = Parameters;
  39. LPTSTR nativeService = NULL; // Native parameters
  40. LPVOID outBuffer = NULL;
  41. LPVOID statBuffer = NULL;
  42. LPBYTE stringLocation = NULL; // Conversion variables
  43. DWORD bytesRequired = 0;
  44. DWORD options;
  45. LPDESC actualStructureDesc;
  46. LPDESC nativeStructureDesc;
  47. STAT_WORKSTATION_0 wkstaStats;
  48. PREDIR_STATISTICS ntRedirStats;
  49. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  50. IF_DEBUG(STATISTICS) {
  51. NetpKdPrint(( "XsNetStatisticsGet2: header at %lx, "
  52. "params at %lx, level %ld\n",
  53. Header, parameters, SmbGetUshort( &parameters->Level ) ));
  54. }
  55. try {
  56. //
  57. // Translate parameters, check for errors.
  58. //
  59. if ( SmbGetUshort( &parameters->Level ) != 0
  60. || SmbGetUlong( &parameters->Reserved ) != 0 ) {
  61. Header->Status = ERROR_INVALID_LEVEL;
  62. goto cleanup;
  63. }
  64. //
  65. // No options currently supported by both rdr and srv
  66. //
  67. if ( SmbGetUlong( &parameters->Options ) != 0 ) {
  68. Header->Status = ERROR_NOT_SUPPORTED;
  69. goto cleanup;
  70. }
  71. XsConvertTextParameter(
  72. nativeService,
  73. (LPSTR)XsSmbGetPointer( &parameters->Service )
  74. );
  75. //
  76. // Make the local call.
  77. //
  78. status = NetStatisticsGet(
  79. NULL,
  80. XS_MAP_SERVICE_NAME( nativeService ),
  81. (DWORD)SmbGetUshort( &parameters->Level ),
  82. 0, // Options MBZ
  83. (LPBYTE *)&outBuffer
  84. );
  85. if ( !XsApiSuccess( status )) {
  86. IF_DEBUG(API_ERRORS) {
  87. NetpKdPrint(( "XsNetStatisticsGet2: NetStatisticsGet failed: "
  88. "%X\n", status ));
  89. }
  90. Header->Status = (WORD)status;
  91. goto cleanup;
  92. }
  93. //
  94. // Use the name of the service to determine the format of the 32-bit
  95. // structure we got back from NetStatisticsGet, and the format of what
  96. // the resulting 16-bit structure should be. If the service name is not
  97. // one supported in LM2.x, return ERROR_NOT_SUPPORTED now, as required.
  98. //
  99. if ( !_stricmp( (LPSTR)XsSmbGetPointer( &parameters->Service ), "SERVER" )) {
  100. statBuffer = outBuffer;
  101. nativeStructureDesc = Desc32_stat_server_0;
  102. actualStructureDesc = Desc16_stat_server_0;
  103. } else if ( !_stricmp( (LPSTR)XsSmbGetPointer( &parameters->Service ),
  104. "WORKSTATION" )) {
  105. //
  106. // The structure we got back is an nt structure. We need to convert
  107. // it by hand here.
  108. //
  109. statBuffer = &wkstaStats;
  110. ntRedirStats = (PREDIR_STATISTICS)outBuffer;
  111. RtlZeroMemory(
  112. &wkstaStats,
  113. sizeof(STAT_WORKSTATION_0)
  114. );
  115. (VOID)RtlTimeToSecondsSince1970(
  116. &ntRedirStats->StatisticsStartTime,
  117. &wkstaStats.stw0_start
  118. );
  119. wkstaStats.stw0_sesstart = ntRedirStats->Sessions;
  120. wkstaStats.stw0_sessfailcon = ntRedirStats->FailedSessions;
  121. wkstaStats.stw0_sessbroke = ntRedirStats->ServerDisconnects +
  122. ntRedirStats->HungSessions;
  123. wkstaStats.stw0_uses =
  124. ntRedirStats->CoreConnects +
  125. ntRedirStats->Lanman20Connects +
  126. ntRedirStats->Lanman21Connects +
  127. ntRedirStats->LanmanNtConnects;
  128. wkstaStats.stw0_usefail = ntRedirStats->FailedUseCount;
  129. wkstaStats.stw0_autorec = ntRedirStats->Reconnects;
  130. wkstaStats.stw0_bytessent_r_hi =
  131. ntRedirStats->BytesTransmitted.HighPart;
  132. wkstaStats.stw0_bytessent_r_lo =
  133. ntRedirStats->BytesTransmitted.LowPart;
  134. wkstaStats.stw0_bytesrcvd_r_hi =
  135. ntRedirStats->BytesReceived.HighPart;
  136. wkstaStats.stw0_bytesrcvd_r_lo =
  137. ntRedirStats->BytesReceived.LowPart;
  138. nativeStructureDesc = Desc32_stat_workstation_0;
  139. actualStructureDesc = Desc16_stat_workstation_0;
  140. } else {
  141. Header->Status = ERROR_NOT_SUPPORTED;
  142. goto cleanup;
  143. }
  144. //
  145. // Convert the structure returned by the 32-bit call to a 16-bit
  146. // structure. The last possible location for variable data is
  147. // calculated from buffer location and length.
  148. //
  149. stringLocation = (LPBYTE)( XsSmbGetPointer( &parameters->Buffer )
  150. + SmbGetUshort( &parameters->BufLen ) );
  151. status = RapConvertSingleEntry(
  152. statBuffer,
  153. nativeStructureDesc,
  154. FALSE,
  155. (LPBYTE)XsSmbGetPointer( &parameters->Buffer ),
  156. (LPBYTE)XsSmbGetPointer( &parameters->Buffer ),
  157. actualStructureDesc,
  158. TRUE,
  159. &stringLocation,
  160. &bytesRequired,
  161. Response,
  162. NativeToRap
  163. );
  164. if ( status != NERR_Success ) {
  165. IF_DEBUG(ERRORS) {
  166. NetpKdPrint(( "XsNetStatisticsGet2: RapConvertSingleEntry failed: "
  167. "%X\n", status ));
  168. }
  169. Header->Status = NERR_InternalError;
  170. goto cleanup;
  171. }
  172. IF_DEBUG(STATISTICS) {
  173. NetpKdPrint(( "32-bit data at %lx, 16-bit data at %lx, %ld BR\n",
  174. outBuffer, SmbGetUlong( &parameters->Buffer ),
  175. bytesRequired ));
  176. }
  177. //
  178. // Determine return code based on the size of the buffer. Statistics
  179. // structures don't have any variable data to pack.
  180. //
  181. if ( !XsCheckBufferSize(
  182. SmbGetUshort( &parameters->BufLen ),
  183. actualStructureDesc,
  184. FALSE // not in native format
  185. )) {
  186. IF_DEBUG(ERRORS) {
  187. NetpKdPrint(( "XsNetStatisticsGet2: Buffer too small.\n" ));
  188. }
  189. Header->Status = NERR_BufTooSmall;
  190. }
  191. //
  192. // Set up the response parameters.
  193. //
  194. SmbPutUshort( &parameters->TotalAvail, (WORD)bytesRequired );
  195. cleanup:
  196. ;
  197. } except( EXCEPTION_EXECUTE_HANDLER ) {
  198. Header->Status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  199. }
  200. NetApiBufferFree( outBuffer );
  201. NetpMemoryFree( nativeService );
  202. //
  203. // Determine return buffer size.
  204. //
  205. XsSetDataCount(
  206. &parameters->BufLen,
  207. actualStructureDesc,
  208. Header->Converter,
  209. 1,
  210. Header->Status
  211. );
  212. return STATUS_SUCCESS;
  213. } // XsNetStatisticsGet2