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.

206 lines
5.8 KiB

  1. /*++
  2. Copyright (c) 1992-1997 Microsoft Corporation
  3. Module Name:
  4. snmpmgmt.h
  5. Abstract:
  6. Contains functions for handling/updating
  7. snmp management variables (defined in RFC1213)
  8. Environment:
  9. User Mode - Win32
  10. Revision History:
  11. 30-Mar-1998 FlorinT
  12. --*/
  13. #include <snmputil.h>
  14. #include "snmpmgmt.h"
  15. SNMP_MGMTVARS snmpMgmtBase; // instance of the service management variables
  16. /*++
  17. Initializes the management variable arrays.
  18. --*/
  19. void mgmtInit()
  20. {
  21. int i;
  22. for (i=0; i<NC_MAX_COUNT; i++)
  23. {
  24. snmpMgmtBase.AsnCounterPool[i].asnType = ASN_COUNTER32;
  25. snmpMgmtBase.AsnCounterPool[i].asnValue.counter = 0;
  26. }
  27. for (i=0; i<NI_MAX_COUNT; i++)
  28. {
  29. snmpMgmtBase.AsnIntegerPool[i].asnType = ASN_INTEGER;
  30. snmpMgmtBase.AsnIntegerPool[i].asnValue.number = 0;
  31. }
  32. for (i=0; i<NO_MAX_COUNT; i++)
  33. {
  34. snmpMgmtBase.AsnObjectIDs[i].asnType = ASN_OBJECTIDENTIFIER;
  35. snmpMgmtBase.AsnObjectIDs[i].asnValue.object.idLength = 0;
  36. snmpMgmtBase.AsnObjectIDs[i].asnValue.object.ids = NULL;
  37. }
  38. // particular case: default the IsnmpEnableAuthenTraps to TRUE
  39. snmpMgmtBase.AsnIntegerPool[IsnmpEnableAuthenTraps].asnValue.number = 1;
  40. // particular case: default the IsnmpNameResolutionRetries to 0
  41. snmpMgmtBase.AsnIntegerPool[IsnmpNameResolutionRetries].asnValue.number = 0;
  42. // particular case: default the OsnmpSysObjectID to the hard coded value given by SvcGetEnterpriseOID
  43. mgmtOSet(OsnmpSysObjectID, SnmpSvcGetEnterpriseOID(), TRUE);
  44. }
  45. /*++
  46. Releases any memory that has been allocated for the management variables
  47. --*/
  48. void mgmtCleanup()
  49. {
  50. int i;
  51. for (i=0; i<NO_MAX_COUNT; i++)
  52. {
  53. SnmpUtilOidFree(&(snmpMgmtBase.AsnObjectIDs[i].asnValue.object));
  54. }
  55. }
  56. /*++
  57. Increment the specified Counter variable
  58. Returns:
  59. ERROR_SUCCESS on success;
  60. ERROR_INVALID_INDEX if index out of range;
  61. ERROR_ARITHMETIC_OVERFLOW if overflowing the MAXINT value.
  62. --*/
  63. int mgmtCTick(int index)
  64. {
  65. AsnCounter oldValue;
  66. if (index < 0 || index >= NC_MAX_COUNT)
  67. return ERROR_INVALID_INDEX ;
  68. oldValue = snmpMgmtBase.AsnCounterPool[index].asnValue.counter;
  69. snmpMgmtBase.AsnCounterPool[index].asnValue.counter++;
  70. return snmpMgmtBase.AsnCounterPool[index].asnValue.counter > oldValue ? ERROR_SUCCESS : ERROR_ARITHMETIC_OVERFLOW;
  71. }
  72. /*++
  73. Add a value to a counter
  74. Returns:
  75. ERROR_SUCCESS on success;
  76. ERROR_INVALID_INDEX if index out of range;
  77. ERROR_ARITHMETIC_OVERFLOW if overflowing the MAXINT value.
  78. --*/
  79. int mgmtCAdd(int index, AsnCounter value)
  80. {
  81. AsnCounter oldValue;
  82. if (index < 0 || index >= NC_MAX_COUNT)
  83. return ERROR_INVALID_INDEX;
  84. oldValue = snmpMgmtBase.AsnCounterPool[index].asnValue.counter;
  85. snmpMgmtBase.AsnCounterPool[index].asnValue.counter += value;
  86. return snmpMgmtBase.AsnCounterPool[index].asnValue.counter > oldValue ? ERROR_SUCCESS : ERROR_ARITHMETIC_OVERFLOW;
  87. }
  88. /*++
  89. Set the value of a certain AsnInteger mgmt variable
  90. Returns:
  91. ERROR_SUCCESS on success;
  92. ERROR_INVALID_INDEX if index out of range;
  93. --*/
  94. int mgmtISet(int index, AsnInteger value)
  95. {
  96. if (index < 0 || index > NI_MAX_COUNT)
  97. return ERROR_INVALID_INDEX;
  98. snmpMgmtBase.AsnIntegerPool[index].asnValue.number = value;
  99. return ERROR_SUCCESS;
  100. }
  101. /*++
  102. Set the value of a certain AsnObjectIdentifier mgmt variable
  103. Returns:
  104. ERROR_SUCCESS on success;
  105. ERROR_INVALID_INDEX if index out of range;
  106. other WinErr if smth else went wrong
  107. Remarks:
  108. If bAlloc = TRUE, the variable is moved (no mem is allocated) to the management variable
  109. If bAlloc = FALSE the value of the input variable is copied (and mem is allocated) to the mgmt variable
  110. ---*/
  111. int mgmtOSet(int index, AsnObjectIdentifier *pValue, BOOL bAlloc)
  112. {
  113. AsnObjectIdentifier oldObject;
  114. if (index < 0 || index > NO_MAX_COUNT)
  115. return ERROR_INVALID_INDEX;
  116. if (pValue == NULL)
  117. return ERROR_INVALID_PARAMETER;
  118. // make a backup of the original object. If something goes wrong, the original object will not be free-ed.
  119. oldObject.idLength = snmpMgmtBase.AsnObjectIDs[index].asnValue.object.idLength;
  120. oldObject.ids = snmpMgmtBase.AsnObjectIDs[index].asnValue.object.ids;
  121. if (bAlloc)
  122. {
  123. // the object is to be copied and mem is to be allocated
  124. if (SnmpUtilOidCpy(&(snmpMgmtBase.AsnObjectIDs[index].asnValue.object), pValue) != SNMPAPI_NOERROR)
  125. return GetLastError();
  126. }
  127. else
  128. {
  129. // the object is to be moved, no mem will be allocated
  130. snmpMgmtBase.AsnObjectIDs[index].asnValue.object.idLength = pValue->idLength;
  131. snmpMgmtBase.AsnObjectIDs[index].asnValue.object.ids = pValue->ids;
  132. }
  133. // everything went fine, so release the memory for the previous value
  134. SnmpUtilOidFree(&oldObject);
  135. return ERROR_SUCCESS;
  136. }
  137. /*++
  138. Updates the MIB counters for the IN_errStatus or OUT_errStatus value
  139. Returns:
  140. void
  141. --*/
  142. void mgmtUtilUpdateErrStatus(UINT flag, DWORD errStatus)
  143. {
  144. UINT index;
  145. switch(errStatus)
  146. {
  147. case SNMP_ERRORSTATUS_TOOBIG:
  148. index = flag == IN_errStatus ? CsnmpInTooBigs : CsnmpOutTooBigs;
  149. break;
  150. case SNMP_ERRORSTATUS_NOSUCHNAME:
  151. index = flag == IN_errStatus ? CsnmpInNoSuchNames : CsnmpOutNoSuchNames;
  152. break;
  153. case SNMP_ERRORSTATUS_BADVALUE:
  154. index = flag == IN_errStatus ? CsnmpInBadValues : CsnmpOutBadValues;
  155. break;
  156. case SNMP_ERRORSTATUS_READONLY:
  157. if (flag != IN_errStatus)
  158. return;
  159. index = CsnmpInReadOnlys;
  160. break;
  161. case SNMP_ERRORSTATUS_GENERR:
  162. index = flag == IN_errStatus ? CsnmpInGenErrs : CsnmpOutGenErrs;
  163. break;
  164. default:
  165. return;
  166. }
  167. mgmtCTick(index);
  168. }