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.

281 lines
8.3 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. perfbrws.c
  5. Abstract:
  6. This file implements a Performance Object that presents
  7. Browser Performance object data
  8. Created:
  9. Bob Watson 22-Oct-1996
  10. Revision History
  11. --*/
  12. //
  13. // Include Files
  14. //
  15. #include <nt.h>
  16. #include <ntrtl.h>
  17. #include <nturtl.h>
  18. #include <windows.h>
  19. #include <assert.h>
  20. #include <winperf.h>
  21. #include <lmcons.h>
  22. #include <lmerr.h>
  23. #include <lmapibuf.h>
  24. #include <lmwksta.h>
  25. #include <lmbrowsr.h>
  26. #include <ntprfctr.h>
  27. #include <perfutil.h>
  28. #include "perfnet.h"
  29. #include "netsvcmc.h"
  30. #include "databrws.h"
  31. // BrowserStatFunction is used for collecting Browser Statistic Data
  32. typedef NET_API_STATUS (*PBROWSERQUERYSTATISTIC) (
  33. IN LPTSTR servername OPTIONAL,
  34. OUT LPBROWSER_STATISTICS *statistics
  35. );
  36. static PBROWSERQUERYSTATISTIC BrowserStatFunction = NULL;
  37. static HANDLE dllHandle = NULL;
  38. static BOOL bInitOk = FALSE;
  39. DWORD APIENTRY
  40. OpenBrowserObject (
  41. IN LPWSTR lpValueName
  42. )
  43. /*++
  44. GetBrowserStatistic - Get the I_BrowserQueryStatistics entry point
  45. --*/
  46. {
  47. UINT dwOldMode;
  48. LONG status = ERROR_SUCCESS;
  49. UNREFERENCED_PARAMETER (lpValueName);
  50. dwOldMode = SetErrorMode( SEM_FAILCRITICALERRORS );
  51. bInitOk = TRUE;
  52. //
  53. // Dynamically link to netapi32.dll. If it's not there just return.
  54. //
  55. dllHandle = LoadLibraryW((LPCWSTR)L"NetApi32.Dll") ;
  56. if ( !dllHandle || dllHandle == INVALID_HANDLE_VALUE ) {
  57. status = GetLastError();
  58. ReportEvent (hEventLog,
  59. EVENTLOG_ERROR_TYPE,
  60. 0,
  61. PERFNET_UNABLE_OPEN_NETAPI32_DLL,
  62. NULL,
  63. 0,
  64. sizeof(DWORD),
  65. NULL,
  66. (LPVOID)&status);
  67. BrowserStatFunction = NULL;
  68. bInitOk = FALSE;
  69. } else {
  70. //
  71. // Get the address of the service's main entry point. This
  72. // entry point has a well-known name.
  73. //
  74. BrowserStatFunction = (PBROWSERQUERYSTATISTIC)GetProcAddress (
  75. dllHandle, "I_BrowserQueryStatistics") ;
  76. if (BrowserStatFunction == NULL) {
  77. status = GetLastError();
  78. ReportEvent (hEventLog,
  79. EVENTLOG_ERROR_TYPE,
  80. 0,
  81. PERFNET_UNABLE_LOCATE_BROWSER_PERF_FN,
  82. NULL,
  83. 0,
  84. sizeof(DWORD),
  85. NULL,
  86. (LPVOID)&status);
  87. bInitOk = FALSE;
  88. }
  89. }
  90. SetErrorMode( dwOldMode );
  91. return status;
  92. }
  93. DWORD APIENTRY
  94. CollectBrowserObjectData(
  95. IN OUT LPVOID *lppData,
  96. IN OUT LPDWORD lpcbTotalBytes,
  97. IN OUT LPDWORD lpNumObjectTypes
  98. )
  99. /*++
  100. Routine Description:
  101. This routine will return the data for the Physical Disk object
  102. Arguments:
  103. IN OUT LPVOID *lppData
  104. IN: pointer to the address of the buffer to receive the completed
  105. PerfDataBlock and subordinate structures. This routine will
  106. append its data to the buffer starting at the point referenced
  107. by *lppData.
  108. OUT: points to the first byte after the data structure added by this
  109. routine. This routine updated the value at lppdata after appending
  110. its data.
  111. IN OUT LPDWORD lpcbTotalBytes
  112. IN: the address of the DWORD that tells the size in bytes of the
  113. buffer referenced by the lppData argument
  114. OUT: the number of bytes added by this routine is writted to the
  115. DWORD pointed to by this argument
  116. IN OUT LPDWORD NumObjectTypes
  117. IN: the address of the DWORD to receive the number of objects added
  118. by this routine
  119. OUT: the number of objects added by this routine is writted to the
  120. DWORD pointed to by this argument
  121. Returns:
  122. 0 if successful, else Win 32 error code of failure
  123. --*/
  124. {
  125. DWORD TotalLen; // Length of the total return block
  126. NTSTATUS Status = ERROR_SUCCESS;
  127. BROWSER_DATA_DEFINITION *pBrowserDataDefinition;
  128. BROWSER_COUNTER_DATA *pBCD;
  129. BROWSER_STATISTICS BrowserStatistics;
  130. LPBROWSER_STATISTICS pBrowserStatistics = &BrowserStatistics;
  131. //
  132. // Check for sufficient space for browser data
  133. //
  134. if (!bInitOk) {
  135. // function didn't initialize so bail out here
  136. *lpcbTotalBytes = (DWORD) 0;
  137. *lpNumObjectTypes = (DWORD) 0;
  138. return ERROR_SUCCESS;
  139. }
  140. TotalLen = sizeof(BROWSER_DATA_DEFINITION) +
  141. sizeof(BROWSER_COUNTER_DATA);
  142. if ( *lpcbTotalBytes < TotalLen ) {
  143. // not enough room in the buffer for 1 instance
  144. // so bail
  145. *lpcbTotalBytes = (DWORD) 0;
  146. *lpNumObjectTypes = (DWORD) 0;
  147. return ERROR_MORE_DATA;
  148. }
  149. //
  150. // Define objects data block
  151. //
  152. pBrowserDataDefinition = (BROWSER_DATA_DEFINITION *) *lppData;
  153. memcpy (pBrowserDataDefinition,
  154. &BrowserDataDefinition,
  155. sizeof(BROWSER_DATA_DEFINITION));
  156. //
  157. // Format and collect browser data
  158. //
  159. pBCD = (PBROWSER_COUNTER_DATA)&pBrowserDataDefinition[1];
  160. // test for quadword alignment of the structure
  161. assert (((DWORD)(pBCD) & 0x00000007) == 0);
  162. memset (pBrowserStatistics, 0, sizeof (BrowserStatistics));
  163. if ( BrowserStatFunction != NULL ) {
  164. Status = (*BrowserStatFunction) (NULL,
  165. &pBrowserStatistics
  166. );
  167. } else {
  168. Status = STATUS_INVALID_ADDRESS;
  169. }
  170. if (NT_SUCCESS(Status)) {
  171. pBCD->CounterBlock.ByteLength = sizeof(BROWSER_COUNTER_DATA);
  172. pBCD->TotalAnnounce =
  173. pBCD->ServerAnnounce = BrowserStatistics.NumberOfServerAnnouncements.QuadPart;
  174. pBCD->TotalAnnounce +=
  175. pBCD->DomainAnnounce = BrowserStatistics.NumberOfDomainAnnouncements.QuadPart;
  176. pBCD->ElectionPacket = BrowserStatistics.NumberOfElectionPackets;
  177. pBCD->MailslotWrite = BrowserStatistics.NumberOfMailslotWrites;
  178. pBCD->ServerList = BrowserStatistics.NumberOfGetBrowserServerListRequests;
  179. pBCD->ServerEnum = BrowserStatistics.NumberOfServerEnumerations;
  180. pBCD->DomainEnum = BrowserStatistics.NumberOfDomainEnumerations;
  181. pBCD->OtherEnum = BrowserStatistics.NumberOfOtherEnumerations;
  182. pBCD->TotalEnum = BrowserStatistics.NumberOfServerEnumerations
  183. + BrowserStatistics.NumberOfDomainEnumerations
  184. + BrowserStatistics.NumberOfOtherEnumerations;
  185. pBCD->ServerAnnounceMiss = BrowserStatistics.NumberOfMissedServerAnnouncements;
  186. pBCD->MailslotDatagramMiss = BrowserStatistics.NumberOfMissedMailslotDatagrams;
  187. pBCD->ServerListMiss = BrowserStatistics.NumberOfMissedGetBrowserServerListRequests;
  188. pBCD->ServerAnnounceAllocMiss = BrowserStatistics.NumberOfFailedServerAnnounceAllocations;
  189. pBCD->MailslotAllocFail = BrowserStatistics.NumberOfFailedMailslotAllocations;
  190. pBCD->MailslotReceiveFail = BrowserStatistics.NumberOfFailedMailslotReceives;
  191. pBCD->MailslotWriteFail = BrowserStatistics.NumberOfFailedMailslotWrites;
  192. pBCD->MailslotOpenFail = BrowserStatistics.NumberOfFailedMailslotOpens;
  193. pBCD->MasterAnnounceDup = BrowserStatistics.NumberOfDuplicateMasterAnnouncements;
  194. pBCD->DatagramIllegal = BrowserStatistics.NumberOfIllegalDatagrams.QuadPart;
  195. } else {
  196. if (BrowserStatFunction != NULL) {
  197. ReportEvent (hEventLog,
  198. EVENTLOG_ERROR_TYPE,
  199. 0,
  200. PERFNET_UNABLE_LOCATE_BROWSER_PERF_FN,
  201. NULL,
  202. 0,
  203. sizeof(DWORD),
  204. NULL,
  205. (LPVOID)&Status);
  206. }
  207. //
  208. // Failure to access Browser: clear counters to 0
  209. //
  210. memset(pBCD, 0, sizeof(BROWSER_COUNTER_DATA));
  211. pBCD->CounterBlock.ByteLength = sizeof(BROWSER_COUNTER_DATA);
  212. }
  213. *lppData = (LPVOID)&pBCD[1];
  214. *lpcbTotalBytes =
  215. (DWORD)((LPBYTE)&pBCD[1] -
  216. (LPBYTE)pBrowserDataDefinition);
  217. *lpNumObjectTypes = 1;
  218. return ERROR_SUCCESS;
  219. }
  220. DWORD APIENTRY
  221. CloseBrowserObject ()
  222. {
  223. if (dllHandle != NULL) {
  224. FreeLibrary (dllHandle);
  225. dllHandle = NULL;
  226. BrowserStatFunction = NULL;
  227. }
  228. return ERROR_SUCCESS;
  229. }