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.

203 lines
5.9 KiB

  1. /*++ BUILD Version: 0001 // Increment this if a change has global effects
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. main.c
  5. Abstract:
  6. SNMP Extension Agent for Windows NT.
  7. Created:
  8. 18-Feb-1995
  9. Revision History:
  10. Murali R. Krishnan (MuraliK) 16-Nov-1995 Removed undoc apis
  11. --*/
  12. #include "mib.h"
  13. #include "apiutil.h"
  14. //
  15. // Extension Agent DLLs need access to elapsed time agent has been active.
  16. // This is implemented by initializing the Extension Agent with a time zero
  17. // reference, and allowing the agent to compute elapsed time by subtracting
  18. // the time zero reference from the current system time. This example
  19. // Extension Agent implements this reference with dwTimeZero.
  20. //
  21. DWORD dwTimeZero = 0;
  22. //
  23. // Extension Agent DLLs provide the following entry point to coordinate the
  24. // initializations of the Extension Agent and the Extendible Agent. The
  25. // Extendible Agent provides the Extension Agent with a time zero reference;
  26. // and the Extension Agent provides the Extendible Agent with an Event handle
  27. // for communicating occurence of traps, and an object identifier representing
  28. // the root of the MIB subtree that the Extension Agent supports.
  29. //
  30. BOOL
  31. SnmpExtensionInit(
  32. DWORD dwTimeZeroReference,
  33. HANDLE * hPollForTrapEvent,
  34. AsnObjectIdentifier * supportedView
  35. )
  36. {
  37. //
  38. // Record the time reference provided by the Extendible Agent.
  39. //
  40. dwTimeZero = dwTimeZeroReference;
  41. //
  42. // Indicate the MIB view supported by this Extension Agent, an object
  43. // identifier representing the sub root of the MIB that is supported.
  44. //
  45. *supportedView = MIB_OidPrefix; // NOTE! structure copy
  46. //
  47. // Indicate that Extension Agent initialization was sucessfull.
  48. //
  49. return TRUE;
  50. } // SnmpExtensionInit
  51. //
  52. // Extension Agent DLLs provide the following entry point to communcate traps
  53. // to the Extendible Agent. The Extendible Agent will query this entry point
  54. // when the trap Event (supplied at initialization time) is asserted, which
  55. // indicates that zero or more traps may have occured. The Extendible Agent
  56. // will repetedly call this entry point until FALSE is returned, indicating
  57. // that all outstanding traps have been processed.
  58. //
  59. BOOL
  60. SnmpExtensionTrap(
  61. AsnObjectIdentifier * enterprise,
  62. AsnInteger * genericTrap,
  63. AsnInteger * specificTrap,
  64. AsnTimeticks * timeStamp,
  65. RFC1157VarBindList * variableBindings
  66. )
  67. {
  68. //
  69. // We don't support traps (yet).
  70. //
  71. return FALSE;
  72. } // SnmpExtensionTrap
  73. //
  74. // Extension Agent DLLs provide the following entry point to resolve queries
  75. // for MIB variables in their supported MIB view (supplied at initialization
  76. // time). The requestType is Get/GetNext/Set.
  77. //
  78. BOOL
  79. SnmpExtensionQuery(
  80. BYTE requestType,
  81. RFC1157VarBindList * variableBindings,
  82. AsnInteger * errorStatus,
  83. AsnInteger * errorIndex
  84. )
  85. {
  86. LPFTP_STATISTICS_0 Statistics = NULL;
  87. NET_API_STATUS Status;
  88. UINT i;
  89. //
  90. // Try to query the statistics now so we'll have a consitent
  91. // view across all variable bindings.
  92. //
  93. Status = FtpQueryStatistics2( NULL, // pszServer
  94. 0, // Level,
  95. INET_INSTANCE_GLOBAL,
  96. 0,
  97. (LPBYTE *)&Statistics );
  98. try
  99. {
  100. //
  101. // Iterate through the variable bindings list to resolve individual
  102. // variable bindings.
  103. //
  104. for( i = 0 ; i < variableBindings->len ; i++ )
  105. {
  106. *errorStatus = ResolveVarBind( &variableBindings->list[i],
  107. requestType,
  108. Statistics );
  109. //
  110. // Test and handle case where Get Next past end of MIB view
  111. // supported by this Extension Agent occurs. Special
  112. // processing is required to communicate this situation to
  113. // the Extendible Agent so it can take appropriate action,
  114. // possibly querying other Extension Agents.
  115. //
  116. if( ( *errorStatus == SNMP_ERRORSTATUS_NOSUCHNAME ) &&
  117. ( requestType == MIB_GETNEXT ) )
  118. {
  119. *errorStatus = SNMP_ERRORSTATUS_NOERROR;
  120. //
  121. // Modify variable binding of such variables so the OID
  122. // points just outside the MIB view supported by this
  123. // Extension Agent. The Extendible Agent tests for this,
  124. // and takes appropriate action.
  125. //
  126. SNMP_oidfree( &variableBindings->list[i].name );
  127. SNMP_oidcpy( &variableBindings->list[i].name, &MIB_OidPrefix );
  128. variableBindings->list[i].name.ids[MIB_PREFIX_LEN-1]++;
  129. }
  130. //
  131. // If an error was indicated, communicate error status and error
  132. // index to the Extendible Agent. The Extendible Agent will
  133. // ensure that the origional variable bindings are returned in
  134. // the response packet.
  135. if( *errorStatus != SNMP_ERRORSTATUS_NOERROR )
  136. {
  137. *errorIndex = i+1;
  138. }
  139. else
  140. {
  141. *errorIndex = 0;
  142. }
  143. }
  144. }
  145. except( EXCEPTION_EXECUTE_HANDLER )
  146. {
  147. //
  148. // For now do nothing.
  149. //
  150. }
  151. //
  152. // Free the statistics structure if we managed to actually get one.
  153. //
  154. if( Statistics != NULL )
  155. {
  156. MIDL_user_free( (LPVOID)Statistics );
  157. }
  158. return SNMPAPI_NOERROR;
  159. } // SnmpExtensionQuery