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.

251 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. WsStats.c
  5. Abstract:
  6. Contains workstation service half of the Net statistics routine:
  7. NetrWorkstationStatisticsGet
  8. (GetStatisticsFromRedir)
  9. Author:
  10. Richard L Firth (rfirth) 12-05-1991
  11. Revision History:
  12. 12-05-1991 rfirth
  13. Created
  14. --*/
  15. #include <nt.h>
  16. #include <ntrtl.h>
  17. #include <nturtl.h>
  18. #include <windows.h>
  19. #include <lmcons.h>
  20. #include <lmerr.h>
  21. #include <lmwksta.h>
  22. #include <lmstats.h>
  23. #include <ntddnfs.h>
  24. #include <memory.h>
  25. #include <netlibnt.h>
  26. #include <ntrpcp.h>
  27. #include "wsdevice.h"
  28. //
  29. // debugging
  30. //
  31. #ifdef DBG
  32. #define STATIC
  33. #ifdef DBGSTATS
  34. BOOL DbgStats = TRUE;
  35. #else
  36. BOOL DbgStats = FALSE;
  37. #endif
  38. #ifdef UNICODE
  39. #define PERCENT_S "%ws"
  40. #else
  41. #define PERCENT_S "%s"
  42. #endif
  43. #else
  44. #define STATIC static
  45. #endif
  46. //
  47. // private prototypes
  48. //
  49. static
  50. NTSTATUS
  51. GetStatisticsFromRedir(
  52. OUT PREDIR_STATISTICS pStats
  53. );
  54. //
  55. // functions
  56. //
  57. NET_API_STATUS
  58. NET_API_FUNCTION
  59. NetrWorkstationStatisticsGet(
  60. IN LPTSTR ServerName,
  61. IN LPTSTR ServiceName,
  62. IN DWORD Level,
  63. IN DWORD Options,
  64. OUT LPBYTE* Buffer
  65. )
  66. /*++
  67. Routine Description:
  68. Returns workstation statistics to the caller. This is the server part of
  69. the request. Parameters have been validated by the client routine
  70. Arguments:
  71. ServerName - IGNORED
  72. ServiceName - IGNORED
  73. Level - of information required. MBZ (IGNORED)
  74. Options - MBZ
  75. Buffer - pointer to pointer to returned buffer
  76. Return Value:
  77. NET_API_STATUS
  78. Success - NERR_Success
  79. Failure - ERROR_INVALID_LEVEL
  80. Level not 0
  81. ERROR_INVALID_PARAMETER
  82. Unsupported options requested
  83. ERROR_NOT_ENOUGH_MEMORY
  84. For API buffer
  85. --*/
  86. {
  87. NET_API_STATUS status;
  88. NTSTATUS ntStatus;
  89. PREDIR_STATISTICS stats;
  90. UNREFERENCED_PARAMETER(ServerName);
  91. UNREFERENCED_PARAMETER(ServiceName);
  92. #if DBG
  93. if (DbgStats) {
  94. DbgPrint("NetrWorkstationStatisticsGet: ServerName=" PERCENT_S "\n"
  95. "ServiceName=" PERCENT_S "\n"
  96. "Level=%d\n"
  97. "Options=%x\n",
  98. ServerName,
  99. ServiceName,
  100. Level,
  101. Options
  102. );
  103. }
  104. #endif
  105. if (Level) {
  106. return ERROR_INVALID_LEVEL;
  107. }
  108. //
  109. // we don't even allow clearing of stats any more
  110. //
  111. if (Options) {
  112. return ERROR_INVALID_PARAMETER;
  113. }
  114. //
  115. // get the redir statistics then munge them into API format
  116. //
  117. stats = (PREDIR_STATISTICS)MIDL_user_allocate(sizeof(*stats));
  118. if (stats == NULL) {
  119. return ERROR_NOT_ENOUGH_MEMORY;
  120. }
  121. ntStatus = GetStatisticsFromRedir(stats);
  122. if (NT_SUCCESS(ntStatus)) {
  123. *Buffer = (LPBYTE)stats;
  124. status = NERR_Success;
  125. } else {
  126. MIDL_user_free(stats);
  127. status = NetpNtStatusToApiStatus(ntStatus);
  128. }
  129. #if DBG
  130. if (DbgStats) {
  131. DbgPrint("NetrWorkstationStatisticsGet: returning %x\n", status);
  132. }
  133. #endif
  134. return status;
  135. }
  136. static
  137. NTSTATUS
  138. GetStatisticsFromRedir(
  139. OUT PREDIR_STATISTICS pStats
  140. )
  141. /*++
  142. Routine Description:
  143. Reads the redir statistics from the Redirector File System Device
  144. Arguments:
  145. pStats - place to store statistics (fixed length buffer)
  146. Return Value:
  147. NTSTATUS
  148. Success - STATUS_SUCCESS
  149. *pStats contains redirector statistics
  150. Failure -
  151. --*/
  152. {
  153. HANDLE FileHandle;
  154. NTSTATUS Status;
  155. IO_STATUS_BLOCK IoStatusBlock;
  156. OBJECT_ATTRIBUTES Obja;
  157. UNICODE_STRING FileName;
  158. RtlInitUnicodeString(&FileName,DD_NFS_DEVICE_NAME_U);
  159. InitializeObjectAttributes(
  160. &Obja,
  161. &FileName,
  162. OBJ_CASE_INSENSITIVE,
  163. NULL,
  164. NULL
  165. );
  166. Status = NtCreateFile(
  167. &FileHandle,
  168. SYNCHRONIZE,
  169. &Obja,
  170. &IoStatusBlock,
  171. NULL,
  172. FILE_ATTRIBUTE_NORMAL,
  173. FILE_SHARE_READ | FILE_SHARE_WRITE,
  174. FILE_OPEN_IF,
  175. FILE_SYNCHRONOUS_IO_NONALERT,
  176. NULL,
  177. 0
  178. );
  179. if ( NT_SUCCESS(Status) ) {
  180. Status = NtFsControlFile(
  181. FileHandle,
  182. NULL,
  183. NULL,
  184. NULL,
  185. &IoStatusBlock,
  186. FSCTL_LMR_GET_STATISTICS,
  187. NULL,
  188. 0,
  189. pStats,
  190. sizeof(*pStats)
  191. );
  192. }
  193. NtClose(FileHandle);
  194. return Status;
  195. }
  196.