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.

218 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. testdll.c
  5. Abstract:
  6. Sample SNMP subagent.
  7. --*/
  8. #include "precomp.h"
  9. #pragma hdrstop
  10. #if defined( MIB_DEBUG )
  11. DWORD g_dwTraceId = INVALID_TRACEID;
  12. #endif
  13. MIB_SERVER_HANDLE g_hMIBServer = ( MIB_SERVER_HANDLE) NULL;
  14. //
  15. // Critical section to protect MIB server handle
  16. //
  17. CRITICAL_SECTION g_CS;
  18. //
  19. // Extension Agent DLLs need access to elapsed time agent has been active.
  20. // This is implemented by initializing the Extension Agent with a time zero
  21. // reference, and allowing the agent to compute elapsed time by subtracting
  22. // the time zero reference from the current system time.
  23. //
  24. DWORD g_uptimeReference = 0;
  25. //
  26. // Handle to Subagent Framework
  27. //
  28. SnmpTfxHandle g_tfxHandle;
  29. ///////////////////////////////////////////////////////////////////////////////
  30. // //
  31. // Subagent entry points //
  32. // //
  33. ///////////////////////////////////////////////////////////////////////////////
  34. BOOL
  35. SnmpExtensionInit(
  36. IN DWORD uptimeReference,
  37. OUT HANDLE * lpPollForTrapEvent,
  38. OUT AsnObjectIdentifier * lpFirstSupportedView
  39. )
  40. {
  41. DWORD dwRes = (DWORD) -1;
  42. #if defined( MIB_DEBUG )
  43. //
  44. // tracing for DEBUG
  45. //
  46. g_dwTraceId = TraceRegister( "IPRIPMIB" );
  47. #endif
  48. g_hMIBServer = (MIB_SERVER_HANDLE) NULL;
  49. //
  50. // Verify router service is running
  51. //
  52. if ( !MprAdminIsServiceRunning( NULL ) )
  53. {
  54. TRACE0( "Router Service not running" );
  55. }
  56. else {
  57. //
  58. // Connect to router. In case of error, set
  59. // connection handle to NULL. Connection can
  60. // be established later.
  61. //
  62. dwRes = MprAdminMIBServerConnect(
  63. NULL,
  64. &g_hMIBServer
  65. );
  66. if ( dwRes != NO_ERROR )
  67. {
  68. g_hMIBServer = (MIB_SERVER_HANDLE) NULL;
  69. TRACE1(
  70. "Error %d setting up DIM connection to MIB Server\n", dwRes
  71. );
  72. return FALSE;
  73. }
  74. }
  75. // save uptime reference
  76. g_uptimeReference = uptimeReference;
  77. // obtain handle to subagent framework
  78. g_tfxHandle = SnmpTfxOpen(1,&v_msiprip2);
  79. // validate handle
  80. if (g_tfxHandle == NULL) {
  81. return FALSE;
  82. }
  83. // pass back first view identifier to master
  84. *lpFirstSupportedView = v_msiprip2.viewOid;
  85. // traps not supported yet
  86. *lpPollForTrapEvent = NULL;
  87. return TRUE;
  88. }
  89. BOOL
  90. SnmpExtensionQuery(
  91. IN BYTE requestType,
  92. IN OUT RFC1157VarBindList * variableBindings,
  93. OUT AsnInteger * errorStatus,
  94. OUT AsnInteger * errorIndex
  95. )
  96. {
  97. // forward to framework
  98. return SnmpTfxQuery(
  99. g_tfxHandle,
  100. requestType,
  101. variableBindings,
  102. errorStatus,
  103. errorIndex
  104. );
  105. }
  106. BOOL
  107. SnmpExtensionTrap(
  108. OUT AsnObjectIdentifier *enterprise,
  109. OUT AsnInteger *genericTrap,
  110. OUT AsnInteger *specificTrap,
  111. OUT AsnTimeticks *timeStamp,
  112. OUT RFC1157VarBindList *variableBindings
  113. )
  114. {
  115. // no traps
  116. return FALSE;
  117. }
  118. BOOL WINAPI
  119. DllMain(
  120. HINSTANCE hInstDLL,
  121. DWORD fdwReason,
  122. LPVOID pReserved
  123. )
  124. {
  125. BOOL bRetVal = TRUE;
  126. switch ( fdwReason )
  127. {
  128. case DLL_PROCESS_ATTACH :
  129. {
  130. DisableThreadLibraryCalls( hInstDLL );
  131. try {
  132. InitializeCriticalSection( &g_CS );
  133. }
  134. except (EXCEPTION_EXECUTE_HANDLER) {
  135. bRetVal = FALSE;
  136. break;
  137. }
  138. break;
  139. }
  140. case DLL_PROCESS_DETACH :
  141. {
  142. //
  143. // Disconnect from router
  144. //
  145. if ( g_hMIBServer )
  146. {
  147. MprAdminMIBServerDisconnect( g_hMIBServer );
  148. }
  149. DeleteCriticalSection( &g_CS );
  150. #if defined( MIB_DEBUG )
  151. if ( g_dwTraceId != INVALID_TRACEID )
  152. {
  153. TraceDeregister( g_dwTraceId );
  154. }
  155. #endif
  156. break;
  157. }
  158. default :
  159. {
  160. break;
  161. }
  162. }
  163. return bRetVal;
  164. }