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.

182 lines
4.5 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // iassnmp.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Defines the DLL entry points for the SNMP extension.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 09/10/1998 Original version.
  16. // 12/17/1998 Don't return error if OID out of range on GetNext.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <ias.h>
  20. #include <stats.h>
  21. #include <snmp.h>
  22. #include <snmputil.h>
  23. #include <acctmib.h>
  24. #include <authmib.h>
  25. UINT IDS_ourRegion[] = { OID_mgmt_mib_2, 67 };
  26. UINT IDS_nextRegion[] = { OID_mgmt_mib_2, 68 };
  27. AsnObjectIdentifier ourRegion = DEFINE_OID(IDS_ourRegion);
  28. AsnObjectIdentifier nextRegion = DEFINE_OID(IDS_nextRegion);
  29. extern "C"
  30. BOOL
  31. SNMP_FUNC_TYPE
  32. SnmpExtensionInit(
  33. DWORD dwUptimeReference,
  34. HANDLE * phSubagentTrapEvent,
  35. AsnObjectIdentifier * pFirstSupportedRegion
  36. )
  37. {
  38. if (!StatsOpen()) { return FALSE; }
  39. *phSubagentTrapEvent = NULL;
  40. *pFirstSupportedRegion = ourRegion;
  41. return TRUE;
  42. }
  43. extern "C"
  44. BOOL
  45. SNMP_FUNC_TYPE
  46. SnmpExtensionInitEx(
  47. AsnObjectIdentifier * pNextSupportedRegion
  48. )
  49. {
  50. return FALSE;
  51. }
  52. extern "C"
  53. BOOL
  54. SNMP_FUNC_TYPE
  55. SnmpExtensionQuery(
  56. BYTE bPduType,
  57. SnmpVarBindList * pVarBindList,
  58. AsnInteger32 * pErrorStatus,
  59. AsnInteger32 * pErrorIndex
  60. )
  61. {
  62. // We declare the current index at function scope since we'll need it
  63. // outside the try block.
  64. UINT idx = 0;
  65. // Initialize this to NOERROR just in case pVarBindList is zero length.
  66. *pErrorStatus = SNMP_ERRORSTATUS_NOERROR;
  67. // Lock the shared stats.
  68. StatsLock();
  69. try
  70. {
  71. // Each entry in the pVarBindList is processed independently.
  72. for ( ; idx < pVarBindList->len; ++idx)
  73. {
  74. // Pull out the (name, value) pair.
  75. SnmpOid name(pVarBindList->list[idx].name);
  76. AsnAny* value = &pVarBindList->list[idx].value;
  77. // Process the PDU. Technically, the switch should be outside the
  78. // for loop, but I thought it was more readable this way.
  79. switch (bPduType)
  80. {
  81. case SNMP_PDU_GET:
  82. {
  83. if (AuthServMIB::canGetSet(name))
  84. {
  85. *pErrorStatus = AuthServMIB::get(name, value);
  86. }
  87. else if (AcctServMIB::canGetSet(name))
  88. {
  89. *pErrorStatus = AcctServMIB::get(name, value);
  90. }
  91. else
  92. {
  93. *pErrorStatus = SNMP_ERRORSTATUS_NOSUCHNAME;
  94. }
  95. break;
  96. }
  97. case SNMP_PDU_GETNEXT:
  98. {
  99. if (AuthServMIB::canGetNext(name))
  100. {
  101. *pErrorStatus = AuthServMIB::getNext(name, value);
  102. }
  103. else if (AcctServMIB::canGetNext(name))
  104. {
  105. *pErrorStatus = AcctServMIB::getNext(name, value);
  106. }
  107. else
  108. {
  109. // On a failed GETNEXT, we set name to the next region.
  110. name = nextRegion;
  111. value->asnType = ASN_NULL;
  112. }
  113. break;
  114. }
  115. case SNMP_PDU_SET:
  116. {
  117. if (AuthServMIB::canGetSet(name))
  118. {
  119. *pErrorStatus = AuthServMIB::set(name, value);
  120. }
  121. else if (AcctServMIB::canGetSet(name))
  122. {
  123. *pErrorStatus = AcctServMIB::set(name, value);
  124. }
  125. else
  126. {
  127. *pErrorStatus = SNMP_ERRORSTATUS_NOSUCHNAME;
  128. }
  129. break;
  130. }
  131. default:
  132. {
  133. *pErrorStatus = SNMP_ERRORSTATUS_GENERR;
  134. }
  135. }
  136. // The first error halts processing.
  137. if (*pErrorStatus != SNMP_ERRORSTATUS_NOERROR) { break; }
  138. }
  139. }
  140. catch (...)
  141. {
  142. // We shouldn't end up here unless there was a memory allocation
  143. // failure.
  144. *pErrorStatus = SNMP_ERRORSTATUS_GENERR;
  145. }
  146. StatsUnlock();
  147. // Set the error index appropriately.
  148. *pErrorIndex = *pErrorStatus ? idx + 1 : 0;
  149. return TRUE;
  150. }
  151. extern "C"
  152. VOID
  153. SNMP_FUNC_TYPE
  154. SnmpExtensionClose(
  155. )
  156. {
  157. StatsClose();
  158. }