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.

258 lines
6.9 KiB

  1. /*++
  2. Copyright (c) 1992-1996 Microsoft Corporation
  3. Module Name:
  4. resolve.c
  5. Abstract:
  6. High level routines to process the variable binding list.
  7. Environment:
  8. User Mode - Win32
  9. Revision History:
  10. 10-May-1996 DonRyan
  11. Removed banner from Technology Dynamics, Inc.
  12. --*/
  13. //--------------------------- WINDOWS DEPENDENCIES --------------------------
  14. //--------------------------- STANDARD DEPENDENCIES -- #include<xxxxx.h> ----
  15. #include <stdio.h>
  16. //--------------------------- MODULE DEPENDENCIES -- #include"xxxxx.h" ------
  17. #include <snmp.h>
  18. #include <snmputil.h>
  19. #include "mib.h"
  20. #include "mibfuncs.h"
  21. //--------------------------- SELF-DEPENDENCY -- ONE #include"module.h" -----
  22. //--------------------------- PUBLIC VARIABLES --(same as in module.h file)--
  23. //--------------------------- PRIVATE CONSTANTS -----------------------------
  24. //--------------------------- PRIVATE STRUCTS -------------------------------
  25. //--------------------------- PRIVATE VARIABLES -----------------------------
  26. //--------------------------- PRIVATE PROTOTYPES ----------------------------
  27. AsnInteger ResolveVarBind(
  28. IN RFC1157VarBind *VarBind, // Variable Binding to resolve
  29. IN UINT PduAction // Action specified in PDU
  30. );
  31. SNMPAPI SnmpExtensionQuery(
  32. IN BYTE ReqType, // 1157 Request type
  33. IN OUT RFC1157VarBindList *VarBinds, // Var Binds to resolve
  34. OUT AsnInteger *ErrorStatus, // Error status returned
  35. OUT AsnInteger *ErrorIndex // Var Bind containing error
  36. );
  37. //--------------------------- PRIVATE PROCEDURES ----------------------------
  38. //
  39. // ResolveVarBind
  40. // Resolve a variable binding.
  41. //
  42. // Notes:
  43. //
  44. // Return Codes:
  45. // None.
  46. //
  47. // Error Codes:
  48. // None.
  49. //
  50. AsnInteger ResolveVarBind(
  51. IN RFC1157VarBind *VarBind, // Variable Binding to resolve
  52. IN UINT PduAction // Action specified in PDU
  53. )
  54. {
  55. MIB_ENTRY *MibPtr;
  56. AsnObjectIdentifier TempOid;
  57. AsnInteger nResult;
  58. // Lookup OID in MIB
  59. MibPtr = MIB_get_entry( &VarBind->name );
  60. // Check to see if OID is between LM variables
  61. if ( MibPtr == NULL && PduAction == MIB_ACTION_GETNEXT )
  62. {
  63. UINT I;
  64. //
  65. // OPENISSUE - Should change to binary search
  66. //
  67. // Search through MIB to see if OID is within the LM MIB's scope
  68. I = 0;
  69. while ( MibPtr == NULL && I < MIB_num_variables )
  70. {
  71. // Construct OID with complete prefix for comparison purposes
  72. if (SnmpUtilOidCpy( &TempOid, &MIB_OidPrefix ) == SNMPAPI_ERROR)
  73. {
  74. nResult = SNMP_ERRORSTATUS_RESOURCEUNAVAILABLE;
  75. goto Exit;
  76. }
  77. if (SnmpUtilOidAppend( &TempOid, &Mib[I].Oid ) == SNMPAPI_ERROR)
  78. {
  79. SnmpUtilOidFree( &TempOid );
  80. nResult = SNMP_ERRORSTATUS_RESOURCEUNAVAILABLE;
  81. goto Exit;
  82. }
  83. // Check for OID in MIB
  84. if ( 0 > SnmpUtilOidCmp(&VarBind->name, &TempOid) )
  85. {
  86. MibPtr = &Mib[I];
  87. PduAction = MIB_ACTION_GETFIRST;
  88. }
  89. // Free OID memory before copying another
  90. SnmpUtilOidFree( &TempOid );
  91. I++;
  92. } // while
  93. } // if
  94. // If OID not within scope of LM MIB, then no such name
  95. if ( MibPtr == NULL )
  96. {
  97. nResult = SNMP_ERRORSTATUS_NOSUCHNAME;
  98. goto Exit;
  99. }
  100. // Call MIB function to apply requested operation
  101. if ( MibPtr->MibFunc == NULL )
  102. {
  103. // If not GET-NEXT, then error
  104. if ( PduAction != MIB_ACTION_GETNEXT && PduAction != MIB_ACTION_GETFIRST )
  105. {
  106. nResult = SNMP_ERRORSTATUS_NOSUCHNAME;
  107. goto Exit;
  108. }
  109. // Since this is AGGREGATE, use GET-FIRST on next variable, then return
  110. nResult = (*MibPtr->MibNext->MibFunc)( MIB_ACTION_GETFIRST,
  111. MibPtr->MibNext, VarBind );
  112. }
  113. else
  114. {
  115. // Make complete OID of MIB name
  116. if (SnmpUtilOidCpy( &TempOid, &MIB_OidPrefix ) == SNMPAPI_ERROR)
  117. {
  118. nResult = SNMP_ERRORSTATUS_RESOURCEUNAVAILABLE;
  119. goto Exit;
  120. }
  121. if (SnmpUtilOidAppend( &TempOid, &MibPtr->Oid ) == SNMPAPI_ERROR)
  122. {
  123. SnmpUtilOidFree( &TempOid );
  124. nResult = SNMP_ERRORSTATUS_RESOURCEUNAVAILABLE;
  125. goto Exit;
  126. }
  127. if ( MibPtr->Type == MIB_TABLE && !SnmpUtilOidCmp(&TempOid, &VarBind->name) )
  128. {
  129. if ( PduAction == MIB_ACTION_GETNEXT )
  130. {
  131. // Supports GET-NEXT on a MIB table's root node
  132. PduAction = MIB_ACTION_GETFIRST;
  133. }
  134. else
  135. {
  136. nResult = SNMP_ERRORSTATUS_NOSUCHNAME;
  137. SnmpUtilOidFree( &TempOid );
  138. goto Exit;
  139. }
  140. }
  141. nResult = (*MibPtr->MibFunc)( PduAction, MibPtr, VarBind );
  142. // Free temp memory
  143. SnmpUtilOidFree( &TempOid );
  144. }
  145. Exit:
  146. return nResult;
  147. } // ResolveVarBind
  148. //--------------------------- PUBLIC PROCEDURES -----------------------------
  149. //
  150. // SnmpExtensionQuery
  151. // Loop through var bind list resolving each var bind name to an entry
  152. // in the LAN Manager MIB.
  153. //
  154. // Notes:
  155. // Table sets are handled on a case by case basis, because in some cases
  156. // more than one entry in the Var Bind list will be needed to perform a
  157. // single SET on the LM MIB. This is due to the LM API calls.
  158. //
  159. // Return Codes:
  160. // SNMPAPI_NOERROR
  161. // SNMPAPI_ERROR
  162. //
  163. // Error Codes:
  164. // None.
  165. //
  166. SNMPAPI SnmpExtensionQuery(
  167. IN BYTE ReqType, // 1157 Request type
  168. IN OUT RFC1157VarBindList *VarBinds, // Var Binds to resolve
  169. OUT AsnInteger *ErrorStatus, // Error status returned
  170. OUT AsnInteger *ErrorIndex // Var Bind containing error
  171. )
  172. {
  173. UINT I;
  174. SNMPAPI nResult;
  175. //
  176. //
  177. // OPENISSUE - Support is not available for TABLE SETS.
  178. //
  179. //
  180. nResult = SNMPAPI_NOERROR;
  181. *ErrorIndex = 0;
  182. // Loop through Var Bind list resolving var binds
  183. for ( I=0;I < VarBinds->len;I++ )
  184. {
  185. *ErrorStatus = ResolveVarBind( &VarBinds->list[I], ReqType );
  186. // Check for GET-NEXT past end of MIB
  187. if ( *ErrorStatus == SNMP_ERRORSTATUS_NOSUCHNAME &&
  188. ReqType == MIB_ACTION_GETNEXT )
  189. {
  190. *ErrorStatus = SNMP_ERRORSTATUS_NOERROR;
  191. // Set Var Bind pointing to next enterprise past LM MIB
  192. SnmpUtilOidFree( &VarBinds->list[I].name );
  193. SnmpUtilOidCpy( &VarBinds->list[I].name, &MIB_OidPrefix );
  194. VarBinds->list[I].name.ids[MIB_PREFIX_LEN-1] ++;
  195. }
  196. if ( *ErrorStatus != SNMP_ERRORSTATUS_NOERROR )
  197. {
  198. *ErrorIndex = I+1;
  199. goto Exit;
  200. }
  201. }
  202. Exit:
  203. return nResult;
  204. } // SnmpExtensionQuery
  205. //-------------------------------- END --------------------------------------