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.

247 lines
5.7 KiB

  1. //***************************************************************************
  2. //
  3. // MINISERV.CPP
  4. //
  5. // Module: OLE MS SNMP Property Provider
  6. //
  7. // Purpose: Implementation for the SnmpGetEventObject class.
  8. //
  9. // Copyright (c) 1996-2001 Microsoft Corporation, All Rights Reserved
  10. //
  11. //***************************************************************************
  12. #include "precomp.h"
  13. #include <provexpt.h>
  14. #include <snmptempl.h>
  15. #include <snmpmt.h>
  16. #include <typeinfo.h>
  17. #include <process.h>
  18. #include <objbase.h>
  19. #include <stdio.h>
  20. #include <wbemidl.h>
  21. #include "classfac.h"
  22. #include "guids.h"
  23. #include <snmpcont.h>
  24. #include <snmpevt.h>
  25. #include <snmpthrd.h>
  26. #include <snmplog.h>
  27. #include <snmpcl.h>
  28. #include <instpath.h>
  29. #include <snmptype.h>
  30. #include <snmpauto.h>
  31. #include <snmpobj.h>
  32. #include <genlex.h>
  33. #include <sql_1.h>
  34. #include <objpath.h>
  35. #include "propprov.h"
  36. #include "propsnmp.h"
  37. #include "propget.h"
  38. #include "propset.h"
  39. #include "snmpget.h"
  40. #include "snmpset.h"
  41. #include "snmpqset.h"
  42. SetQueryOperation :: SetQueryOperation (
  43. IN SnmpSession &sessionArg ,
  44. IN SnmpSetResponseEventObject *eventObjectArg
  45. ) : SnmpGetOperation ( sessionArg ) ,
  46. session ( &sessionArg ) ,
  47. eventObject ( eventObjectArg ) ,
  48. rowReceived ( FALSE )
  49. {
  50. }
  51. SetQueryOperation :: ~SetQueryOperation ()
  52. {
  53. session->DestroySession () ;
  54. }
  55. void SetQueryOperation :: ReceiveResponse ()
  56. {
  57. eventObject->ReceiveComplete () ;
  58. }
  59. void SetQueryOperation :: ReceiveVarBindResponse (
  60. IN const ULONG &var_bind_index,
  61. IN const SnmpVarBind &requestVarBind ,
  62. IN const SnmpVarBind &replyVarBind ,
  63. IN const SnmpErrorReport &error
  64. )
  65. {
  66. if ( ( typeid ( replyVarBind.GetValue () ) == typeid ( SnmpNoSuchObject ) ) || ( typeid ( replyVarBind.GetValue () ) == typeid ( SnmpNoSuchInstance ) ) )
  67. {
  68. }
  69. else
  70. {
  71. rowReceived = TRUE ;
  72. }
  73. }
  74. #pragma warning (disable:4065)
  75. void SetQueryOperation :: ReceiveErroredVarBindResponse(
  76. IN const ULONG &var_bind_index,
  77. IN const SnmpVarBind &requestVarBind ,
  78. IN const SnmpErrorReport &error
  79. )
  80. {
  81. switch ( error.GetError () )
  82. {
  83. case Snmp_Error:
  84. {
  85. switch ( error.GetStatus () )
  86. {
  87. case Snmp_No_Response:
  88. {
  89. eventObject->GetErrorObject ().SetStatus ( WBEM_SNMP_E_TRANSPORT_NO_RESPONSE ) ;
  90. eventObject->GetErrorObject ().SetWbemStatus ( WBEM_E_FAILED ) ;
  91. eventObject->GetErrorObject ().SetMessage ( L"No Response from device" ) ;
  92. }
  93. break;
  94. case Snmp_No_Such_Name:
  95. {
  96. // Invalid property requested
  97. }
  98. break ;
  99. default:
  100. {
  101. eventObject->GetErrorObject ().SetStatus ( WBEM_SNMP_E_TRANSPORT_ERROR ) ;
  102. eventObject->GetErrorObject ().SetWbemStatus ( WBEM_E_FAILED ) ;
  103. eventObject->GetErrorObject ().SetMessage ( L"Unknown transport failure" ) ;
  104. }
  105. break ;
  106. }
  107. }
  108. break ;
  109. case Snmp_Transport:
  110. {
  111. switch ( error.GetStatus () )
  112. {
  113. default:
  114. {
  115. eventObject->GetErrorObject ().SetStatus ( WBEM_SNMP_E_TRANSPORT_ERROR ) ;
  116. eventObject->GetErrorObject ().SetWbemStatus ( WBEM_E_FAILED ) ;
  117. eventObject->GetErrorObject ().SetMessage ( L"Unknown transport failure" ) ;
  118. }
  119. break ;
  120. }
  121. }
  122. break ;
  123. default:
  124. {
  125. // Cannot Happen
  126. }
  127. break ;
  128. }
  129. }
  130. #pragma warning (default:4065)
  131. void SetQueryOperation :: Send ()
  132. {
  133. // Send Variable Bindings for requested properties
  134. SnmpVarBindList varBindList ;
  135. SnmpNull snmpNull ;
  136. // Create class object for subsequent receipt of response
  137. // Add Variable binding to Variable binding list
  138. SnmpClassObject *snmpObject = eventObject->GetSnmpClassObject () ;
  139. if ( snmpObject )
  140. {
  141. // Encode Variable Binding instance for all key properties
  142. SnmpObjectIdentifier instanceObjectIdentifier ( NULL , 0 ) ;
  143. if ( snmpObject->GetKeyPropertyCount () )
  144. {
  145. WbemSnmpProperty *property ;
  146. snmpObject->ResetKeyProperty () ;
  147. while ( property = snmpObject->NextKeyProperty () )
  148. {
  149. instanceObjectIdentifier = property->GetValue()->Encode ( instanceObjectIdentifier ) ;
  150. }
  151. }
  152. else
  153. {
  154. SnmpIntegerType integerType ( ( LONG ) 0 , NULL ) ;
  155. instanceObjectIdentifier = integerType.Encode ( instanceObjectIdentifier ) ;
  156. }
  157. WbemSnmpProperty *property ;
  158. snmpObject->ResetProperty () ;
  159. while ( property = snmpObject->NextProperty () )
  160. {
  161. if ( property->IsReadable () )
  162. {
  163. BOOL t_Status = ( snmpObject->GetSnmpVersion () == 1 ) && ( property->IsSNMPV1Type () ) ;
  164. t_Status = t_Status || ( ( snmpObject->GetSnmpVersion () == 2 ) && ( property->IsSNMPV2CType () ) ) ;
  165. if ( t_Status )
  166. {
  167. if ( property->IsVirtualKey () == FALSE )
  168. {
  169. WbemSnmpQualifier *qualifier = property->FindQualifier ( WBEM_QUALIFIER_OBJECT_IDENTIFIER ) ;
  170. if ( qualifier )
  171. {
  172. SnmpInstanceType *value = qualifier->GetValue () ;
  173. if ( typeid ( *value ) == typeid ( SnmpObjectIdentifierType ) )
  174. {
  175. SnmpObjectIdentifierType *objectIdentifierType = ( SnmpObjectIdentifierType * ) value ;
  176. SnmpObjectIdentifier *objectIdentifier = ( SnmpObjectIdentifier * ) objectIdentifierType->GetValueEncoding () ;
  177. SnmpObjectIdentifier requestIdentifier = *objectIdentifier + instanceObjectIdentifier ;
  178. SnmpObjectIdentifierType requestIdentifierType ( requestIdentifier ) ;
  179. // Add Variable binding to list
  180. SnmpVarBind varBind ( requestIdentifier , snmpNull ) ;
  181. varBindList.Add ( varBind ) ;
  182. }
  183. else
  184. {
  185. // Problem Here
  186. }
  187. }
  188. else
  189. {
  190. // Problem Here
  191. }
  192. }
  193. else
  194. {
  195. // Don't Send properties marked as virtual key
  196. }
  197. }
  198. }
  199. }
  200. // Finally Send request
  201. SendRequest ( varBindList ) ;
  202. }
  203. else
  204. {
  205. }
  206. }