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.

411 lines
11 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. SetOperation :: SetOperation (
  42. IN SnmpSession &sessionArg ,
  43. IN SnmpSetResponseEventObject *eventObjectArg
  44. ) : SnmpSetOperation ( sessionArg ) ,
  45. session ( & sessionArg ) ,
  46. varBindsReceived ( 0 ) ,
  47. erroredVarBindsReceived ( 0 ) ,
  48. eventObject ( eventObjectArg ) ,
  49. m_PropertyContainer ( NULL ) ,
  50. m_PropertyContainerLength ( 0 )
  51. {
  52. }
  53. SetOperation :: ~SetOperation ()
  54. {
  55. delete [] m_PropertyContainer ;
  56. session->DestroySession () ;
  57. }
  58. void SetOperation :: ReceiveResponse ()
  59. {
  60. // Inform creator all is done
  61. eventObject->ReceiveComplete () ;
  62. }
  63. void SetOperation :: ReceiveVarBindResponse (
  64. IN const ULONG &var_bind_index,
  65. IN const SnmpVarBind &requestVarBind ,
  66. IN const SnmpVarBind &replyVarBind ,
  67. IN const SnmpErrorReport &error
  68. )
  69. {
  70. varBindsReceived ++ ;
  71. }
  72. #pragma warning (disable:4065)
  73. void SetOperation :: ReceiveErroredVarBindResponse(
  74. IN const ULONG &var_bind_index,
  75. IN const SnmpVarBind &requestVarBind ,
  76. IN const SnmpErrorReport &error
  77. )
  78. {
  79. erroredVarBindsReceived ++ ;
  80. WbemSnmpProperty *property = m_PropertyContainer [ var_bind_index - 1 ] ;
  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. eventObject->GetErrorObject ().SetStatus ( WBEM_SNMP_E_TRANSPORT_ERROR ) ;
  97. eventObject->GetErrorObject ().SetWbemStatus ( WBEM_E_FAILED ) ;
  98. wchar_t *prefix = UnicodeStringAppend ( L"Agent reported No Such Name for property \'" , property->GetName () ) ;
  99. wchar_t *stringBuffer = UnicodeStringAppend ( prefix , L"\'" ) ;
  100. delete [] prefix ;
  101. eventObject->GetErrorObject ().SetMessage ( stringBuffer ) ;
  102. delete [] stringBuffer ;
  103. // Invalid property requested
  104. property->AddQualifier ( WBEM_QUALIFIER_NOT_AVAILABLE ) ;
  105. WbemSnmpQualifier *qualifier = property->FindQualifier ( WBEM_QUALIFIER_NOT_AVAILABLE ) ;
  106. if ( qualifier )
  107. {
  108. SnmpIntegerType integer ( 1 , NULL ) ;
  109. if ( qualifier->SetValue ( &integer ) )
  110. {
  111. }
  112. else
  113. {
  114. // Problem Here
  115. }
  116. }
  117. else
  118. {
  119. // Problem Here
  120. }
  121. }
  122. break ;
  123. case Snmp_Bad_Value:
  124. {
  125. wchar_t *prefix = UnicodeStringAppend ( L"Agent reported Bad Value for property \'" , property->GetName () ) ;
  126. wchar_t *stringBuffer = UnicodeStringAppend ( prefix , L"\'" ) ;
  127. delete [] prefix ;
  128. eventObject->GetErrorObject ().SetMessage ( stringBuffer ) ;
  129. delete [] stringBuffer ;
  130. eventObject->GetErrorObject ().SetStatus ( WBEM_SNMP_E_TRANSPORT_ERROR ) ;
  131. eventObject->GetErrorObject ().SetWbemStatus ( WBEM_E_FAILED ) ;
  132. }
  133. break ;
  134. case Snmp_Read_Only:
  135. {
  136. eventObject->GetErrorObject ().SetStatus ( WBEM_SNMP_E_TRANSPORT_ERROR ) ;
  137. eventObject->GetErrorObject ().SetWbemStatus ( WBEM_E_FAILED ) ;
  138. wchar_t *prefix = UnicodeStringAppend ( L"Agent reported Read Only for property \'" , property->GetName () ) ;
  139. wchar_t *stringBuffer = UnicodeStringAppend ( prefix , L"\'" ) ;
  140. delete [] prefix ;
  141. eventObject->GetErrorObject ().SetMessage ( stringBuffer ) ;
  142. delete [] stringBuffer ;
  143. }
  144. break ;
  145. case Snmp_Gen_Error:
  146. {
  147. eventObject->GetErrorObject ().SetStatus ( WBEM_SNMP_E_TRANSPORT_ERROR ) ;
  148. eventObject->GetErrorObject ().SetWbemStatus ( WBEM_E_FAILED ) ;
  149. wchar_t *prefix = UnicodeStringAppend ( L"Agent reported General Error for property \'" , property->GetName () ) ;
  150. wchar_t *stringBuffer = UnicodeStringAppend ( prefix , L"\'" ) ;
  151. delete [] prefix ;
  152. eventObject->GetErrorObject ().SetMessage ( stringBuffer ) ;
  153. delete [] stringBuffer ;
  154. }
  155. break ;
  156. case Snmp_Too_Big:
  157. {
  158. property->SetTag ( FALSE ) ;
  159. eventObject->SnmpTooBig () ;
  160. }
  161. break ;
  162. default:
  163. {
  164. eventObject->GetErrorObject ().SetStatus ( WBEM_SNMP_E_TRANSPORT_ERROR ) ;
  165. eventObject->GetErrorObject ().SetWbemStatus ( WBEM_E_FAILED ) ;
  166. eventObject->GetErrorObject ().SetMessage ( L"Unknown transport failure" ) ;
  167. }
  168. break ;
  169. }
  170. }
  171. break ;
  172. case Snmp_Transport:
  173. {
  174. switch ( error.GetStatus () )
  175. {
  176. default:
  177. {
  178. eventObject->GetErrorObject ().SetStatus ( WBEM_SNMP_E_TRANSPORT_ERROR ) ;
  179. eventObject->GetErrorObject ().SetWbemStatus ( WBEM_E_FAILED ) ;
  180. eventObject->GetErrorObject ().SetMessage ( L"Unknown transport failure" ) ;
  181. }
  182. break ;
  183. }
  184. }
  185. break ;
  186. default:
  187. {
  188. // Cannot Happen
  189. }
  190. break ;
  191. }
  192. }
  193. #pragma warning (default:4065)
  194. void SetOperation :: FrameTooBig ()
  195. {
  196. eventObject->SnmpTooBig () ;
  197. CancelRequest () ;
  198. }
  199. void SetOperation :: FrameOverRun ()
  200. {
  201. eventObject->SnmpTooBig () ;
  202. #if 0
  203. eventObject->GetErrorObject ().SetStatus ( WBEM_SNMP_E_TRANSPORT_ERROR ) ;
  204. eventObject->GetErrorObject ().SetWbemStatus ( WBEM_E_FAILED ) ;
  205. eventObject->GetErrorObject ().SetMessage ( L"Set Request could not fit into single SNMP PDU" ) ;
  206. #endif
  207. CancelRequest () ;
  208. }
  209. void SetOperation :: Send ( const ULONG &a_NumberToSend )
  210. {
  211. // Send Variable Bindings for requested properties
  212. SnmpVarBindList varBindList ;
  213. SnmpObjectIdentifier instanceObjectIdentifier ( NULL , 0 ) ;
  214. SnmpSetClassObject *snmpObject = ( SnmpSetClassObject * ) eventObject->GetSnmpClassObject () ;
  215. if ( snmpObject )
  216. {
  217. // Encode Variable Binding instance for all key properties
  218. if ( snmpObject->GetKeyPropertyCount () )
  219. {
  220. WbemSnmpProperty *property ;
  221. snmpObject->ResetKeyProperty () ;
  222. while ( property = snmpObject->NextKeyProperty () )
  223. {
  224. instanceObjectIdentifier = property->GetValue()->Encode ( instanceObjectIdentifier ) ;
  225. }
  226. }
  227. else
  228. {
  229. SnmpIntegerType integerType ( ( LONG ) 0 , NULL ) ;
  230. instanceObjectIdentifier = integerType.Encode ( instanceObjectIdentifier ) ;
  231. }
  232. if ( ! m_PropertyContainer )
  233. {
  234. WbemSnmpProperty *property ;
  235. snmpObject->ResetProperty () ;
  236. while ( property = snmpObject->NextProperty () )
  237. {
  238. if ( snmpObject->IsWritable ( property ) )
  239. {
  240. BOOL t_Status = ( snmpObject->GetSnmpVersion () == 1 ) && ( property->IsSNMPV1Type () ) ;
  241. t_Status = t_Status || ( ( snmpObject->GetSnmpVersion () == 2 ) && ( property->IsSNMPV2CType () ) ) ;
  242. if ( t_Status )
  243. {
  244. if ( property->IsVirtualKey () == FALSE )
  245. {
  246. m_PropertyContainerLength ++ ;
  247. }
  248. }
  249. }
  250. }
  251. m_PropertyContainer = new WbemSnmpProperty * [ m_PropertyContainerLength ] ;
  252. }
  253. // Add Variable binding to Variable binding list
  254. ULONG t_Count = 0 ;
  255. /*
  256. * First add row status property
  257. */
  258. WbemSnmpProperty *property ;
  259. snmpObject->ResetProperty () ;
  260. while ( property = snmpObject->NextProperty () )
  261. {
  262. if ( ( typeid ( *property->GetValue () ) == typeid ( SnmpRowStatusType ) ) & ( ! property->GetTag () ) )
  263. {
  264. property->SetTag ( TRUE ) ;
  265. WbemSnmpQualifier *qualifier = property->FindQualifier ( WBEM_QUALIFIER_OBJECT_IDENTIFIER ) ;
  266. if ( qualifier )
  267. {
  268. SnmpInstanceType *value = qualifier->GetValue () ;
  269. if ( typeid ( *value ) == typeid ( SnmpObjectIdentifierType ) )
  270. {
  271. SnmpObjectIdentifierType *objectIdentifierType = ( SnmpObjectIdentifierType * ) value ;
  272. SnmpObjectIdentifier *objectIdentifier = ( SnmpObjectIdentifier * ) objectIdentifierType->GetValueEncoding () ;
  273. SnmpObjectIdentifier requestIdentifier = *objectIdentifier + instanceObjectIdentifier ;
  274. SnmpObjectIdentifierType requestIdentifierType ( requestIdentifier ) ;
  275. // Create queue of properties which have duplicate object identifiers
  276. m_PropertyContainer [ t_Count ] = property ;
  277. const SnmpValue *snmpValue = property->GetValue()->GetValueEncoding () ;
  278. SnmpVarBind varBind ( requestIdentifier , *snmpValue ) ;
  279. varBindList.Add ( varBind ) ;
  280. t_Count ++ ;
  281. }
  282. }
  283. }
  284. }
  285. snmpObject->ResetProperty () ;
  286. while ( ( property = snmpObject->NextProperty () ) && ( a_NumberToSend == 0xffffffff ) || ( ( a_NumberToSend != 0xffffffff ) && ( t_Count < a_NumberToSend ) ) )
  287. {
  288. if ( ! property->GetTag () )
  289. {
  290. BOOL t_Status = ( snmpObject->GetSnmpVersion () == 1 ) && ( property->IsSNMPV1Type () ) ;
  291. t_Status = t_Status || ( ( snmpObject->GetSnmpVersion () == 2 ) && ( property->IsSNMPV2CType () ) ) ;
  292. if ( t_Status )
  293. {
  294. if ( property->IsVirtualKey () == FALSE )
  295. {
  296. if ( snmpObject->IsWritable ( property ) )
  297. {
  298. //now that we've checked that it is writable set it and mark it set
  299. property->SetTag ( TRUE ) ;
  300. WbemSnmpQualifier *qualifier = property->FindQualifier ( WBEM_QUALIFIER_OBJECT_IDENTIFIER ) ;
  301. if ( qualifier )
  302. {
  303. SnmpInstanceType *value = qualifier->GetValue () ;
  304. if ( typeid ( *value ) == typeid ( SnmpObjectIdentifierType ) )
  305. {
  306. SnmpObjectIdentifierType *objectIdentifierType = ( SnmpObjectIdentifierType * ) value ;
  307. SnmpObjectIdentifier *objectIdentifier = ( SnmpObjectIdentifier * ) objectIdentifierType->GetValueEncoding () ;
  308. SnmpObjectIdentifier requestIdentifier = *objectIdentifier + instanceObjectIdentifier ;
  309. SnmpObjectIdentifierType requestIdentifierType ( requestIdentifier ) ;
  310. // Create queue of properties which have duplicate object identifiers
  311. m_PropertyContainer [ t_Count ] = property ;
  312. const SnmpValue *snmpValue = property->GetValue()->GetValueEncoding () ;
  313. SnmpVarBind varBind ( requestIdentifier , *snmpValue ) ;
  314. varBindList.Add ( varBind ) ;
  315. t_Count ++ ;
  316. }
  317. else
  318. {
  319. // Problem Here
  320. }
  321. }
  322. else
  323. {
  324. // Problem Here
  325. }
  326. }
  327. }
  328. }
  329. }
  330. }
  331. // Finally Send request
  332. SendRequest ( varBindList ) ;
  333. }
  334. else
  335. {
  336. // Problem Here
  337. }
  338. }