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.

1360 lines
39 KiB

  1. /*
  2. * smint.c v0.12 Mar 12 1996
  3. *
  4. ****************************************************************************
  5. * *
  6. * (C) Copyright 1995, 1996 DIGITAL EQUIPMENT CORPORATION *
  7. * *
  8. * This software is an unpublished work protected under the *
  9. * the copyright laws of the United States of America, all *
  10. * rights reserved. *
  11. * *
  12. * In the event this software is licensed for use by the United *
  13. * States Government, all use, duplication or disclosure by the *
  14. * United States Government is subject to restrictions as set *
  15. * forth in either subparagraph (c)(1)(ii) of the Rights in *
  16. * Technical Data And Computer Software Clause at DFARS *
  17. * 252.227-7013, or the Commercial Computer Software Restricted *
  18. * Rights Clause at FAR 52.221-19, whichever is applicable. *
  19. * *
  20. ****************************************************************************
  21. *
  22. * Facility:
  23. *
  24. * SNMP Extension Agent
  25. *
  26. * Abstract:
  27. *
  28. * This module contains the SMI envelopes around the callout to the user's
  29. * get and set routines.
  30. *
  31. * SMIGetInteger
  32. * SMIGetNSMBoolean
  33. * SMIGetBIDTEnum
  34. * SMIGetOctetString
  35. * SMIGetObjectId
  36. * SMIGetCounter
  37. * SMIGetGauge
  38. * SMIGetTimeTicks
  39. * SMIGetIpAddress
  40. * SMIGetDispString
  41. * SMISetInteger
  42. * SMISetNSMBoolean
  43. * SMISetBIDTEnum
  44. * SMISetOctetString
  45. * SMISetObjectId
  46. * SMISetCounter
  47. * SMISetGauge
  48. * SMISetTimeTicks
  49. * SMISetIpAddress
  50. * SMISetDispString
  51. * SMIBuildInteger
  52. * SMIBuildDIDTEnum
  53. * SMIBuildOctetString
  54. * SMIBuildObjectId
  55. * SMIBuildCounter
  56. * SMIBuildGauge
  57. * SMIBuildTimeTicks
  58. * SMIBuildIpAddress
  59. * SMIBuildDispString
  60. * SMIFree
  61. *
  62. * Author:
  63. * Wayne Duso, Miriam Amos Nihart, Kathy Faust
  64. *
  65. * Date:
  66. * 2/17/95
  67. *
  68. * Revision History:
  69. * v0.1 Jul 20 95 AGS Added SMIGet/SetBoolean
  70. * v0.11 Feb 14 1996 AGS changed SMIGet/SetBoolean to SMIGet/SetNSMBoolean
  71. * v0.12 Mar 12, 1996 KKF set outvalue.length to 256 for SMISetOctetString,
  72. * SMISetDispString so that instrumentation code knows
  73. * max length of buffer.
  74. * v0.13 May 15, 1997 DDB To Microsoft: 6 changes of "malloc" to
  75. * "SNMP_malloc"
  76. */
  77. // Necessary includes.
  78. #include <snmp.h>
  79. #include <stdlib.h>
  80. #include <malloc.h>
  81. #include <memory.h>
  82. #include <string.h>
  83. #include "mib.h"
  84. #include "mib_xtrn.h"
  85. #include "smint.h" // Wayne's type def file
  86. /*
  87. * SMIGetInteger
  88. *
  89. * Encompasses the callouts to variables of the data type INTEGER.
  90. *
  91. * Arguments:
  92. *
  93. * VarBind pointer to the variable value pair
  94. * cindex index to the class of the request
  95. * vindex index to the variable of the request
  96. * instance address of the instance specification in the
  97. * form of ordered native datatypes
  98. *
  99. * Return Codes:
  100. *
  101. * Standard PDU error codes.
  102. *
  103. */
  104. UINT
  105. SMIGetInteger( IN OUT RFC1157VarBind *VarBind , // Variable Binding for get
  106. IN unsigned long int cindex ,
  107. IN unsigned long int vindex ,
  108. IN InstanceName *instance )
  109. {
  110. UINT result = SNMP_ERRORSTATUS_NOERROR ;
  111. Integer outvalue ;
  112. Access_Credential access ; // dummy holder for future use
  113. result = ( *class_info[ cindex ].variable[ vindex ].VarGet )( &outvalue ,
  114. &access ,
  115. instance ) ;
  116. if ( result == SNMP_ERRORSTATUS_NOERROR )
  117. {
  118. VarBind->value.asnType = ASN_INTEGER ;
  119. VarBind->value.asnValue.number = (AsnInteger)outvalue ;
  120. }
  121. return result ;
  122. } /* end of SMIGetInteger() */
  123. /*
  124. * SMIGetNSMBoolean
  125. *
  126. * Encompasses the callouts to variables of the data type Boolean.
  127. *
  128. * Arguments:
  129. *
  130. * VarBind pointer to the variable value pair
  131. * cindex index to the class of the request
  132. * vindex index to the variable of the request
  133. * instance address of the instance specification in the
  134. * form of ordered native datatypes
  135. *
  136. * In SNMPv1 true = 1 AND false = 2
  137. *
  138. * Return Codes:
  139. *
  140. * Standard PDU error codes.
  141. *
  142. */
  143. UINT
  144. SMIGetNSMBoolean( IN OUT RFC1157VarBind *VarBind , // Variable Binding for get
  145. IN unsigned long int cindex ,
  146. IN unsigned long int vindex ,
  147. IN InstanceName *instance )
  148. {
  149. UINT result = SNMP_ERRORSTATUS_NOERROR ;
  150. NSM_Boolean outvalue ; // nsm_true = 1, nsm_false = 2
  151. Access_Credential access ; // dummy holder for future use
  152. result = ( *class_info[ cindex ].variable[ vindex ].VarGet )( &outvalue ,
  153. &access ,
  154. instance ) ;
  155. if ( result == SNMP_ERRORSTATUS_NOERROR )
  156. {
  157. VarBind->value.asnType = ASN_INTEGER ;
  158. VarBind->value.asnValue.number = (AsnInteger)outvalue ;
  159. }
  160. return result ;
  161. } /* end of SMIGetNSMBoolean() */
  162. /*
  163. * SMIGetBIDTEnum
  164. *
  165. * Encompasses the callouts to variables of the data type INTEGER that
  166. * are enumerated.
  167. *
  168. * Arguments:
  169. *
  170. * VarBind pointer to the variable value pair
  171. * cindex index to the class of the request
  172. * vindex index to the variable of the request
  173. * instance address of the instance specification in the
  174. * form of ordered native datatypes
  175. *
  176. * Return Codes:
  177. *
  178. * Standard PDU error codes.
  179. *
  180. */
  181. UINT
  182. SMIGetBIDTEnum( IN OUT RFC1157VarBind *VarBind , // Variable Binding for get
  183. IN unsigned long int cindex ,
  184. IN unsigned long int vindex ,
  185. IN InstanceName *instance )
  186. {
  187. UINT result = SNMP_ERRORSTATUS_NOERROR ;
  188. BIDT_ENUMERATION outvalue ;
  189. Access_Credential access ; // dummy holder for future use
  190. result = ( *class_info[ cindex ].variable[ vindex ].VarGet )( &outvalue ,
  191. &access ,
  192. instance ) ;
  193. if ( result == SNMP_ERRORSTATUS_NOERROR )
  194. {
  195. VarBind->value.asnType = ASN_INTEGER ;
  196. VarBind->value.asnValue.number = (AsnInteger)outvalue ;
  197. }
  198. return result ;
  199. } /* end of SMIGetBIDTEnum() */
  200. /*
  201. * SMIGetOctetString
  202. *
  203. * Encompasses the callouts to variables of the data type OCTET STRING.
  204. *
  205. * Arguments:
  206. *
  207. * VarBind pointer to the variable value pair
  208. * cindex index to the class of the request
  209. * vindex index to the variable of the request
  210. * instance address of the instance specification in the
  211. * form of ordered native datatypes
  212. *
  213. * Return Codes:
  214. *
  215. * Standard PDU error codes.
  216. *
  217. */
  218. UINT
  219. SMIGetOctetString( IN OUT RFC1157VarBind *VarBind , // Variable Binding for get
  220. IN unsigned long int cindex ,
  221. IN unsigned long int vindex ,
  222. IN InstanceName *instance )
  223. {
  224. UINT result = SNMP_ERRORSTATUS_NOERROR ;
  225. OctetString outvalue ;
  226. char stream[ MAX_OCTET_STRING ] ;
  227. Access_Credential access ; // dummy holder for future use
  228. outvalue.string = stream ;
  229. result = ( *class_info[ cindex ].variable[ vindex ].VarGet )( &outvalue ,
  230. &access ,
  231. instance ) ;
  232. if ( result == SNMP_ERRORSTATUS_NOERROR )
  233. {
  234. VarBind->value.asnValue.string.length = outvalue.length ;
  235. VarBind->value.asnValue.string.stream =
  236. // malloc( outvalue.length * sizeof( char ) ) ;
  237. // Changed 5/15/97 DDB
  238. SNMP_malloc( outvalue.length * sizeof( char ) ) ;
  239. if ( VarBind->value.asnValue.string.stream == NULL )
  240. result = SNMP_ERRORSTATUS_GENERR ;
  241. else
  242. {
  243. memcpy( VarBind->value.asnValue.string.stream ,
  244. outvalue.string ,
  245. outvalue.length ) ;
  246. VarBind->value.asnType = ASN_OCTETSTRING ;
  247. VarBind->value.asnValue.string.dynamic = TRUE ;
  248. }
  249. }
  250. return result ;
  251. } /* end of SMIGetOctetString() */
  252. /*
  253. * SMIGetObjectId
  254. *
  255. * Encompasses the callouts to variables of the data type OBJECT IDENTIFIER.
  256. *
  257. * Arguments:
  258. *
  259. * VarBind pointer to the variable value pair
  260. * cindex index to the class of the request
  261. * vindex index to the variable of the request
  262. * instance address of the instance specification in the
  263. * form of ordered native datatypes
  264. *
  265. * Return Codes:
  266. *
  267. * Standard PDU error codes.
  268. *
  269. */
  270. UINT
  271. SMIGetObjectId( IN OUT RFC1157VarBind *VarBind , // Variable Binding for get
  272. IN unsigned long int cindex ,
  273. IN unsigned long int vindex ,
  274. IN InstanceName *instance )
  275. {
  276. UINT result = SNMP_ERRORSTATUS_NOERROR ;
  277. UINT status ;
  278. ObjectIdentifier outvalue ;
  279. Access_Credential access ; // dummy holder for future use
  280. memset( &outvalue, '\0', sizeof( ObjectIdentifier ) ) ;
  281. result = ( *class_info[ cindex ].variable[ vindex ].VarGet )( &outvalue ,
  282. &access ,
  283. instance ) ;
  284. if ( result == SNMP_ERRORSTATUS_NOERROR )
  285. {
  286. status = SNMP_oidcpy( &VarBind->value.asnValue.object, &outvalue ) ;
  287. if ( outvalue.idLength != 0 )
  288. SNMP_free( outvalue.ids ) ;
  289. if ( !status )
  290. result = SNMP_ERRORSTATUS_GENERR ;
  291. else
  292. {
  293. VarBind->value.asnType = ASN_OBJECTIDENTIFIER ;
  294. }
  295. }
  296. return result ;
  297. } /* end of SMIGetObjectId() */
  298. /*
  299. * SMIGetCounter
  300. *
  301. * Encompasses the callouts to variables of the data type COUNTER.
  302. *
  303. * Arguments:
  304. *
  305. * VarBind pointer to the variable value pair
  306. * cindex index to the class of the request
  307. * vindex index to the variable of the request
  308. * instance address of the instance specification in the
  309. * form of ordered native datatypes
  310. *
  311. * Return Codes:
  312. *
  313. * Standard PDU error codes.
  314. *
  315. */
  316. UINT
  317. SMIGetCounter( IN OUT RFC1157VarBind *VarBind , // Variable Binding for get
  318. IN unsigned long int cindex ,
  319. IN unsigned long int vindex ,
  320. IN InstanceName *instance )
  321. {
  322. UINT result = SNMP_ERRORSTATUS_NOERROR ;
  323. Counter outvalue ;
  324. Access_Credential access ; // dummy holder for future use
  325. result = ( *class_info[ cindex ].variable[ vindex ].VarGet )( &outvalue ,
  326. &access ,
  327. instance ) ;
  328. if ( result == SNMP_ERRORSTATUS_NOERROR )
  329. {
  330. VarBind->value.asnType = ASN_RFC1155_COUNTER ;
  331. VarBind->value.asnValue.counter = outvalue ;
  332. }
  333. return result ;
  334. } /* end of SMIGetCounter() */
  335. /*
  336. * SMIGetGauge
  337. *
  338. * Encompasses the callouts to variables of the data type GAUGE.
  339. *
  340. * Arguments:
  341. *
  342. * VarBind pointer to the variable value pair
  343. * cindex index to the class of the request
  344. * vindex index to the variable of the request
  345. * instance address of the instance specification in the
  346. * form of ordered native datatypes
  347. *
  348. * Return Codes:
  349. *
  350. * Standard PDU error codes.
  351. *
  352. */
  353. UINT
  354. SMIGetGauge( IN OUT RFC1157VarBind *VarBind , // Variable Binding for get
  355. IN unsigned long int cindex ,
  356. IN unsigned long int vindex ,
  357. IN InstanceName *instance )
  358. {
  359. UINT result = SNMP_ERRORSTATUS_NOERROR ;
  360. Gauge outvalue ;
  361. Access_Credential access ; // dummy holder for future use
  362. result = ( *class_info[ cindex ].variable[ vindex ].VarGet )( &outvalue ,
  363. &access ,
  364. instance ) ;
  365. if ( result == SNMP_ERRORSTATUS_NOERROR )
  366. {
  367. VarBind->value.asnType = ASN_RFC1155_GAUGE ;
  368. VarBind->value.asnValue.gauge = outvalue ;
  369. }
  370. return result ;
  371. } /* end of SMIGetGauge() */
  372. /*
  373. * SMIGetTimeTicks
  374. *
  375. * Encompasses the callouts to variables of the data type TIMETICKS.
  376. *
  377. * Arguments:
  378. *
  379. * VarBind pointer to the variable value pair
  380. * cindex index to the class of the request
  381. * vindex index to the variable of the request
  382. * instance address of the instance specification in the
  383. * form of ordered native datatypes
  384. *
  385. * Return Codes:
  386. *
  387. * Standard PDU error codes.
  388. *
  389. */
  390. UINT
  391. SMIGetTimeTicks( IN OUT RFC1157VarBind *VarBind , // Variable Binding for get
  392. IN unsigned long int cindex ,
  393. IN unsigned long int vindex ,
  394. IN InstanceName *instance )
  395. {
  396. UINT result = SNMP_ERRORSTATUS_NOERROR ;
  397. TimeTicks outvalue ;
  398. Access_Credential access ; // dummy holder for future use
  399. result = ( *class_info[ cindex ].variable[ vindex ].VarGet )( &outvalue ,
  400. &access ,
  401. instance ) ;
  402. if ( result == SNMP_ERRORSTATUS_NOERROR )
  403. {
  404. VarBind->value.asnType = ASN_RFC1155_TIMETICKS ;
  405. VarBind->value.asnValue.ticks = outvalue ;
  406. }
  407. return result ;
  408. } /* end of SMIGetTimeTicks() */
  409. /*
  410. * SMIGetIpAddress
  411. *
  412. * Encompasses the callouts to variables of the data type IP ADDRESS.
  413. *
  414. * Arguments:
  415. *
  416. * VarBind pointer to the variable value pair
  417. * cindex index to the class of the request
  418. * vindex index to the variable of the request
  419. * instance address of the instance specification in the
  420. * form of ordered native datatypes
  421. *
  422. * Return Codes:
  423. *
  424. * Standard PDU error codes.
  425. *
  426. */
  427. UINT
  428. SMIGetIpAddress( IN OUT RFC1157VarBind *VarBind , // Variable Binding for get
  429. IN unsigned long int cindex ,
  430. IN unsigned long int vindex ,
  431. IN InstanceName *instance )
  432. {
  433. UINT result = SNMP_ERRORSTATUS_NOERROR ;
  434. IpAddress outvalue ;
  435. Access_Credential access ; // dummy holder for future use
  436. result = ( *class_info[ cindex ].variable[ vindex ].VarGet )( &outvalue ,
  437. &access ,
  438. instance ) ;
  439. if ( result == SNMP_ERRORSTATUS_NOERROR )
  440. {
  441. VarBind->value.asnValue.address.length = 4 ;
  442. // VarBind->value.asnValue.address.stream = malloc( 4 * sizeof( char ) ) ;
  443. // Changed 5/15/97 DDB
  444. VarBind->value.asnValue.address.stream = SNMP_malloc( 4 * sizeof( char ) ) ;
  445. if ( VarBind->value.asnValue.address.stream == NULL )
  446. result = SNMP_ERRORSTATUS_GENERR ;
  447. else
  448. {
  449. memcpy( VarBind->value.asnValue.address.stream ,
  450. (BYTE *)(&outvalue),
  451. 4 ) ;
  452. VarBind->value.asnType = ASN_RFC1155_IPADDRESS ;
  453. VarBind->value.asnValue.address.dynamic = TRUE ;
  454. }
  455. }
  456. return result ;
  457. } /* end of SMIGetIpAddress() */
  458. /*
  459. * SMIGetDispString
  460. *
  461. * Encompasses the callouts to variables of the data type DISPLAY STRING.
  462. *
  463. * Arguments:
  464. *
  465. * VarBind pointer to the variable value pair
  466. * cindex index to the class of the request
  467. * vindex index to the variable of the request
  468. * instance address of the instance specification in the
  469. * form of ordered native datatypes
  470. *
  471. * Return Codes:
  472. *
  473. * Standard PDU error codes.
  474. *
  475. */
  476. UINT
  477. SMIGetDispString( IN OUT RFC1157VarBind *VarBind , // Variable Binding for get
  478. IN unsigned long int cindex ,
  479. IN unsigned long int vindex ,
  480. IN InstanceName *instance )
  481. {
  482. UINT result = SNMP_ERRORSTATUS_NOERROR ;
  483. Simple_DisplayString outvalue ;
  484. char stream[ MAX_OCTET_STRING ] ;
  485. Access_Credential access ; // dummy holder for future use
  486. outvalue.string = stream ;
  487. outvalue.length = 0 ;
  488. result = ( *class_info[ cindex ].variable[ vindex ].VarGet )( &outvalue ,
  489. &access ,
  490. instance ) ;
  491. if ( result == SNMP_ERRORSTATUS_NOERROR )
  492. {
  493. VarBind->value.asnValue.string.length = outvalue.length ;
  494. VarBind->value.asnValue.string.stream =
  495. // malloc( outvalue.length * sizeof( char ) ) ;
  496. // Changed 5/15/97 DDB
  497. SNMP_malloc( outvalue.length * sizeof( char ) ) ;
  498. if ( VarBind->value.asnValue.string.stream == NULL )
  499. result = SNMP_ERRORSTATUS_GENERR ;
  500. else
  501. {
  502. memcpy( VarBind->value.asnValue.string.stream ,
  503. outvalue.string ,
  504. VarBind->value.asnValue.string.length ) ;
  505. VarBind->value.asnType = ASN_RFC1213_DISPSTRING ;
  506. VarBind->value.asnValue.string.dynamic = TRUE ;
  507. }
  508. }
  509. return result ;
  510. } /* end of SMIGetDispString() */
  511. /*
  512. * SMISetInteger
  513. *
  514. * Encompasses the callouts to variables of the data type INTEGER.
  515. *
  516. * Arguments:
  517. *
  518. * VarBind pointer to the variable value pair
  519. * cindex index to the class of the request
  520. * vindex index to the variable of the request
  521. * instance address of the instance specification in the
  522. * form of ordered native datatypes
  523. *
  524. * Return Codes:
  525. *
  526. * Standard PDU error codes.
  527. *
  528. */
  529. UINT
  530. SMISetInteger( IN OUT RFC1157VarBind *VarBind , // Variable Binding for set
  531. IN unsigned long int cindex ,
  532. IN unsigned long int vindex ,
  533. IN InstanceName *instance )
  534. {
  535. UINT result = SNMP_ERRORSTATUS_NOERROR ;
  536. Integer *invalue ;
  537. Integer outvalue ;
  538. Access_Credential access ; // dummy holder for future use
  539. invalue = (Integer *)( &VarBind->value.asnValue.number ) ;
  540. result = ( *class_info[ cindex ].variable[ vindex ].VarSet )
  541. ( invalue, &outvalue, &access, instance ) ;
  542. return result ;
  543. } /* end of SMISetInteger() */
  544. /*
  545. * SMISetNSMBoolean
  546. *
  547. * Encompasses the callouts to variables of the data type Boolean
  548. *
  549. * Arguments:
  550. *
  551. * VarBind pointer to the variable value pair
  552. * cindex index to the class of the request
  553. * vindex index to the variable of the request
  554. * instance address of the instance specification in the
  555. * form of ordered native datatypes
  556. * In SNMPv1 true = 1 AND false = 2
  557. *
  558. * Return Codes:
  559. *
  560. * Standard PDU error codes.
  561. *
  562. */
  563. UINT
  564. SMISetNSMBoolean( IN OUT RFC1157VarBind *VarBind , // Variable Binding for set
  565. IN unsigned long int cindex ,
  566. IN unsigned long int vindex ,
  567. IN InstanceName *instance )
  568. {
  569. UINT result = SNMP_ERRORSTATUS_NOERROR ;
  570. NSM_Boolean *invalue ; // nsm_true = 1, nsm_false = 2
  571. NSM_Boolean outvalue ;
  572. Access_Credential access ; // dummy holder for future use
  573. invalue = (NSM_Boolean *)( &VarBind->value.asnValue.number ) ;
  574. result = ( *class_info[ cindex ].variable[ vindex ].VarSet )
  575. ( invalue, &outvalue, &access, instance ) ;
  576. return result ;
  577. } /* end of SMISetNSMBoolean() */
  578. /*
  579. * SMISetBIDTEmun
  580. *
  581. * Encompasses the callouts to variables of the data type INTEGER that
  582. * is enumerated.
  583. *
  584. * Arguments:
  585. *
  586. * VarBind pointer to the variable value pair
  587. * cindex index to the class of the request
  588. * vindex index to the variable of the request
  589. * instance address of the instance specification in the
  590. * form of ordered native datatypes
  591. *
  592. * Return Codes:
  593. *
  594. * Standard PDU error codes.
  595. *
  596. */
  597. UINT
  598. SMISetBIDTEnum( IN OUT RFC1157VarBind *VarBind , // Variable Binding for set
  599. IN unsigned long int cindex ,
  600. IN unsigned long int vindex ,
  601. IN InstanceName *instance )
  602. {
  603. UINT result = SNMP_ERRORSTATUS_NOERROR ;
  604. BIDT_ENUMERATION *invalue ;
  605. BIDT_ENUMERATION outvalue ;
  606. Access_Credential access ; // dummy holder for future use
  607. invalue = (BIDT_ENUMERATION *)( &VarBind->value.asnValue.number ) ;
  608. result = ( *class_info[ cindex ].variable[ vindex ].VarSet )
  609. ( invalue, &outvalue, &access, instance ) ;
  610. return result ;
  611. } /* end of SMISetBIDTEnum() */
  612. /*
  613. * SMISetOctetString
  614. *
  615. * Encompasses the callouts to variables of the data type OCTET STRING.
  616. *
  617. * Arguments:
  618. *
  619. * VarBind pointer to the variable value pair
  620. * cindex index to the class of the request
  621. * vindex index to the variable of the request
  622. * instance address of the instance specification in the
  623. * form of ordered native datatypes
  624. *
  625. * Return Codes:
  626. *
  627. * Standard PDU error codes.
  628. *
  629. */
  630. UINT
  631. SMISetOctetString( IN OUT RFC1157VarBind *VarBind , // Variable Binding for set
  632. IN unsigned long int cindex ,
  633. IN unsigned long int vindex ,
  634. IN InstanceName *instance )
  635. {
  636. UINT result = SNMP_ERRORSTATUS_NOERROR ;
  637. OctetString invalue ;
  638. OctetString outvalue ;
  639. char out_stream[ MAX_OCTET_STRING ] ;
  640. AsnOctetString *tmp ;
  641. Access_Credential access ; // dummy holder for future use
  642. tmp = &VarBind->value.asnValue.string ;
  643. invalue.length = tmp->length ;
  644. invalue.string = tmp->stream ;
  645. outvalue.string = out_stream ;
  646. outvalue.length = 256 ;
  647. result = ( *class_info[ cindex ].variable[ vindex ].VarSet )
  648. ( &invalue, &outvalue, &access, instance ) ;
  649. return result ;
  650. } /* end of SMISetOctetString() */
  651. /*
  652. * SMISetObjectId
  653. *
  654. * Encompasses the callouts to variables of the data type OBJECT IDENTIFIER.
  655. *
  656. * Arguments:
  657. *
  658. * VarBind pointer to the variable value pair
  659. * cindex index to the class of the request
  660. * vindex index to the variable of the request
  661. * instance address of the instance specification in the
  662. * form of ordered native datatypes
  663. *
  664. * Return Codes:
  665. *
  666. * Standard PDU error codes.
  667. *
  668. */
  669. UINT
  670. SMISetObjectId( IN OUT RFC1157VarBind *VarBind , // Variable Binding for set
  671. IN unsigned long int cindex ,
  672. IN unsigned long int vindex ,
  673. IN InstanceName *instance )
  674. {
  675. UINT result = SNMP_ERRORSTATUS_NOERROR ;
  676. ObjectIdentifier *invalue ;
  677. ObjectIdentifier outvalue ;
  678. Access_Credential access ; // dummy holder for future use
  679. invalue = &VarBind->value.asnValue.object ;
  680. memset( &outvalue, '\0', sizeof ( ObjectIdentifier ) ) ;
  681. result = ( *class_info[ cindex ].variable[ vindex ].VarSet )
  682. ( invalue, &outvalue, &access, instance ) ;
  683. if ( outvalue.idLength != 0 )
  684. SNMP_free( outvalue.ids ) ;
  685. return result ;
  686. } /* end of SMISetObjectId() */
  687. /*
  688. * SMISetCounter
  689. *
  690. * Encompasses the callouts to variables of the data type COUNTER.
  691. *
  692. * Arguments:
  693. *
  694. * VarBind pointer to the variable value pair
  695. * cindex index to the class of the request
  696. * vindex index to the variable of the request
  697. * instance address of the instance specification in the
  698. * form of ordered native datatypes
  699. *
  700. * Return Codes:
  701. *
  702. * Standard PDU error codes.
  703. *
  704. */
  705. UINT
  706. SMISetCounter( IN OUT RFC1157VarBind *VarBind , // Variable Binding for set
  707. IN unsigned long int cindex ,
  708. IN unsigned long int vindex ,
  709. IN InstanceName *instance )
  710. {
  711. UINT result = SNMP_ERRORSTATUS_NOERROR ;
  712. Counter *invalue ;
  713. Counter outvalue ;
  714. Access_Credential access ; // dummy holder for future use
  715. invalue = (Counter *)( &VarBind->value.asnValue.counter ) ;
  716. result = ( *class_info[ cindex ].variable[ vindex ].VarSet )
  717. ( invalue, &outvalue, &access, instance ) ;
  718. return result ;
  719. } /* end of SMISetCounter() */
  720. /*
  721. * SMISetGauge
  722. *
  723. * Encompasses the callouts to variables of the data type GAUGE.
  724. *
  725. * Arguments:
  726. *
  727. * VarBind pointer to the variable value pair
  728. * cindex index to the class of the request
  729. * vindex index to the variable of the request
  730. * instance address of the instance specification in the
  731. * form of ordered native datatypes
  732. *
  733. * Return Codes:
  734. *
  735. * Standard PDU error codes.
  736. *
  737. */
  738. UINT
  739. SMISetGauge( IN OUT RFC1157VarBind *VarBind , // Variable Binding for set
  740. IN unsigned long int cindex ,
  741. IN unsigned long int vindex ,
  742. IN InstanceName *instance )
  743. {
  744. UINT result = SNMP_ERRORSTATUS_NOERROR ;
  745. Gauge *invalue ;
  746. Gauge outvalue ;
  747. Access_Credential access ; // dummy holder for future use
  748. invalue = (Gauge *)( &VarBind->value.asnValue.gauge ) ;
  749. result = ( *class_info[ cindex ].variable[ vindex ].VarSet )
  750. ( invalue, &outvalue, &access, instance ) ;
  751. return result ;
  752. } /* end of SMISetGauge() */
  753. /*
  754. * SMISetTimeTicks
  755. *
  756. * Encompasses the callouts to variables of the data type TIMETICKS.
  757. *
  758. * Arguments:
  759. *
  760. * VarBind pointer to the variable value pair
  761. * cindex index to the class of the request
  762. * vindex index to the variable of the request
  763. * instance address of the instance specification in the
  764. * form of ordered native datatypes
  765. *
  766. * Return Codes:
  767. *
  768. * Standard PDU error codes.
  769. *
  770. */
  771. UINT
  772. SMISetTimeTicks( IN OUT RFC1157VarBind *VarBind , // Variable Binding for set
  773. IN unsigned long int cindex ,
  774. IN unsigned long int vindex ,
  775. IN InstanceName *instance )
  776. {
  777. UINT result = SNMP_ERRORSTATUS_NOERROR ;
  778. TimeTicks *invalue ;
  779. TimeTicks outvalue ;
  780. Access_Credential access ; // dummy holder for future use
  781. invalue = (TimeTicks *)( &VarBind->value.asnValue.ticks ) ;
  782. result = ( *class_info[ cindex ].variable[ vindex ].VarSet )
  783. ( invalue , &outvalue, &access, instance ) ;
  784. return result ;
  785. } /* end of SMISetTimeTicks() */
  786. /*
  787. * SMISetIpAddress
  788. *
  789. * Encompasses the callouts to variables of the data type IP ADDRESS.
  790. *
  791. * Arguments:
  792. *
  793. * VarBind pointer to the variable value pair
  794. * cindex index to the class of the request
  795. * vindex index to the variable of the request
  796. * instance address of the instance specification in the
  797. * form of ordered native datatypes
  798. *
  799. * Return Codes:
  800. *
  801. * Standard PDU error codes.
  802. *
  803. */
  804. UINT
  805. SMISetIpAddress( IN OUT RFC1157VarBind *VarBind , // Variable Binding for set
  806. IN unsigned long int cindex ,
  807. IN unsigned long int vindex ,
  808. IN InstanceName *instance )
  809. {
  810. UINT result = SNMP_ERRORSTATUS_NOERROR ;
  811. IpAddress invalue ;
  812. IpAddress outvalue ;
  813. Access_Credential access ; // dummy holder for future use
  814. memcpy( &invalue, VarBind->value.asnValue.address.stream , 4 ) ;
  815. result = ( *class_info[ cindex ].variable[ vindex ].VarSet )
  816. ( &invalue, &outvalue, &access, instance ) ;
  817. return result ;
  818. } /* end of SMISetIpAddress() */
  819. /*
  820. * SMISetDispString
  821. *
  822. * Encompasses the callouts to variables of the data type DISPLAY STRING.
  823. *
  824. * Arguments:
  825. *
  826. * VarBind pointer to the variable value pair
  827. * cindex index to the class of the request
  828. * vindex index to the variable of the request
  829. * instance address of the instance specification in the
  830. * form of ordered native datatypes
  831. *
  832. * Return Codes:
  833. *
  834. * Standard PDU error codes.
  835. *
  836. */
  837. UINT
  838. SMISetDispString( IN OUT RFC1157VarBind *VarBind , // Variable Binding for set
  839. IN unsigned long int cindex ,
  840. IN unsigned long int vindex ,
  841. IN InstanceName *instance )
  842. {
  843. UINT result = SNMP_ERRORSTATUS_NOERROR ;
  844. Simple_DisplayString invalue ;
  845. Simple_DisplayString outvalue ;
  846. char out_stream[ MAX_OCTET_STRING ] ;
  847. AsnOctetString *tmp ;
  848. Access_Credential access ; // dummy holder for future use
  849. tmp = &VarBind->value.asnValue.string ;
  850. invalue.length = tmp->length ;
  851. invalue.string = tmp->stream ;
  852. outvalue.string = out_stream ;
  853. outvalue.length = 256 ;
  854. result = ( *class_info[ cindex ].variable[ vindex ].VarSet )
  855. ( &invalue, &outvalue, &access, instance ) ;
  856. return result ;
  857. } /* end of SMISetDispString() */
  858. /*
  859. * SMIBuildInteger
  860. *
  861. * Places the variable of datatype INTEGER into a Variable Binding.
  862. *
  863. * Arguments:
  864. *
  865. * VarBind pointer to the variable value pair
  866. * invalue address of the data
  867. *
  868. * Return Codes:
  869. *
  870. * Standard PDU error codes.
  871. *
  872. */
  873. UINT
  874. SMIBuildInteger( IN OUT RFC1157VarBind *VarBind ,
  875. IN char *invalue )
  876. {
  877. Integer *svalue = (Integer *)invalue ;
  878. VarBind->value.asnType = ASN_INTEGER ;
  879. VarBind->value.asnValue.number = *svalue ;
  880. return SNMP_ERRORSTATUS_NOERROR ;
  881. } /* end of SMIBuildInteger() */
  882. /*
  883. * SMIBuildOctetString
  884. *
  885. * Places the variable of datatype OCTET STRING into a Variable Binding.
  886. *
  887. * Arguments:
  888. *
  889. * VarBind pointer to the variable value pair
  890. * invalue address of the data
  891. *
  892. * Return Codes:
  893. *
  894. * Standard PDU error codes.
  895. *
  896. */
  897. UINT
  898. SMIBuildOctetString( IN OUT RFC1157VarBind *VarBind ,
  899. IN char *invalue )
  900. {
  901. OctetString *svalue = (OctetString *)invalue ;
  902. UINT status = SNMP_ERRORSTATUS_NOERROR ;
  903. VarBind->value.asnValue.string.length = svalue->length ;
  904. VarBind->value.asnValue.string.stream =
  905. // malloc( svalue->length * sizeof( char ) ) ;
  906. // Changed 5/15/97 DDB
  907. SNMP_malloc( svalue->length * sizeof( char ) ) ;
  908. if ( VarBind->value.asnValue.string.stream == NULL )
  909. status = SNMP_ERRORSTATUS_GENERR ;
  910. else
  911. {
  912. memcpy( VarBind->value.asnValue.string.stream ,
  913. svalue->string ,
  914. svalue->length ) ;
  915. VarBind->value.asnType = ASN_OCTETSTRING ;
  916. VarBind->value.asnValue.string.dynamic = TRUE ;
  917. }
  918. return status ;
  919. } /* end of SMIBuildOctetString() */
  920. /*
  921. * SMIBuildObjectId
  922. *
  923. * Places the variable of datatype OBJECT IDENTIFIER into a Variable Binding.
  924. *
  925. * Arguments:
  926. *
  927. * VarBind pointer to the variable value pair
  928. * invalue address of the data
  929. *
  930. * Return Codes:
  931. *
  932. * Standard PDU error codes.
  933. *
  934. */
  935. UINT
  936. SMIBuildObjectId( IN OUT RFC1157VarBind *VarBind ,
  937. IN char *invalue )
  938. {
  939. ObjectIdentifier *svalue = (ObjectIdentifier *)invalue ;
  940. UINT status = SNMP_ERRORSTATUS_NOERROR ;
  941. UINT sts = TRUE ;
  942. sts = SNMP_oidcpy( &VarBind->value.asnValue.object ,
  943. (AsnObjectIdentifier *)svalue ) ;
  944. if ( !sts )
  945. status = SNMP_ERRORSTATUS_GENERR ;
  946. else
  947. VarBind->value.asnType = ASN_OBJECTIDENTIFIER ;
  948. return status ;
  949. } /* end of SMIBuildObjectId() */
  950. /*
  951. * SMIBuildCounter
  952. *
  953. * Places the variable of datatype COUNTER into a Variable Binding.
  954. *
  955. * Arguments:
  956. *
  957. * VarBind pointer to the variable value pair
  958. * invalue address of the data
  959. *
  960. * Return Codes:
  961. *
  962. * Standard PDU error codes.
  963. *
  964. */
  965. UINT
  966. SMIBuildCounter( IN OUT RFC1157VarBind *VarBind ,
  967. IN char *invalue )
  968. {
  969. Counter *svalue = (Counter *)invalue ;
  970. VarBind->value.asnType = ASN_RFC1155_COUNTER ;
  971. VarBind->value.asnValue.counter = *svalue ;
  972. return SNMP_ERRORSTATUS_NOERROR ;
  973. } /* end of SMIBuildCounter() */
  974. /*
  975. * SMIBuildGauge
  976. *
  977. * Places the variable of datatype GAUGE into a Variable Binding.
  978. *
  979. * Arguments:
  980. *
  981. * VarBind pointer to the variable value pair
  982. * svalue address of the data
  983. *
  984. * Return Codes:
  985. *
  986. * Standard PDU error codes.
  987. *
  988. */
  989. UINT
  990. SMIBuildGauge( IN OUT RFC1157VarBind *VarBind ,
  991. IN char *invalue )
  992. {
  993. Gauge *svalue = (Gauge *)invalue ;
  994. VarBind->value.asnType = ASN_RFC1155_GAUGE ;
  995. VarBind->value.asnValue.gauge = *svalue ;
  996. return SNMP_ERRORSTATUS_NOERROR ;
  997. } /* end of SMIBuildGauge() */
  998. /*
  999. * SMIBuildTimeTicks
  1000. *
  1001. * Places the variable of datatype TIME TICKS into a Variable Binding.
  1002. *
  1003. * Arguments:
  1004. *
  1005. * VarBind pointer to the variable value pair
  1006. * invalue address of the data
  1007. *
  1008. * Return Codes:
  1009. *
  1010. * Standard PDU error codes.
  1011. *
  1012. */
  1013. UINT
  1014. SMIBuildTimeTicks( IN OUT RFC1157VarBind *VarBind ,
  1015. IN char *invalue )
  1016. {
  1017. TimeTicks *svalue = (TimeTicks *)invalue ;
  1018. VarBind->value.asnType = ASN_RFC1155_TIMETICKS ;
  1019. VarBind->value.asnValue.ticks = *svalue ;
  1020. return SNMP_ERRORSTATUS_NOERROR ;
  1021. } /* end of SMIBuildTimeTicks() */
  1022. /*
  1023. * SMIBuildIpAddress
  1024. *
  1025. * Places the variable of datatype IpAddress into a Variable Binding.
  1026. *
  1027. * Arguments:
  1028. *
  1029. * VarBind pointer to the variable value pair
  1030. * invalue address of the data
  1031. *
  1032. * Return Codes:
  1033. *
  1034. * Standard PDU error codes.
  1035. *
  1036. */
  1037. UINT
  1038. SMIBuildIpAddress( IN OUT RFC1157VarBind *VarBind ,
  1039. IN char *invalue )
  1040. {
  1041. IpAddress *svalue = (IpAddress *)invalue;
  1042. UINT status = SNMP_ERRORSTATUS_NOERROR ;
  1043. VarBind->value.asnValue.address.stream = SNMP_malloc( 4 * sizeof( char ) ) ;
  1044. if ( VarBind->value.asnValue.address.stream == NULL )
  1045. status = SNMP_ERRORSTATUS_GENERR ;
  1046. else
  1047. {
  1048. memcpy( VarBind->value.asnValue.address.stream, (BYTE *)svalue, 4 ) ;
  1049. VarBind->value.asnValue.address.length = 4 ;
  1050. VarBind->value.asnType = ASN_RFC1155_IPADDRESS ;
  1051. VarBind->value.asnValue.address.dynamic = TRUE ;
  1052. }
  1053. return status ;
  1054. } /* end of SMIBuildIpAddress() */
  1055. /*
  1056. * SMIBuildDispString
  1057. *
  1058. * Places the variable of datatype DISPLAY STRING into a Variable Binding.
  1059. *
  1060. * Arguments:
  1061. *
  1062. * VarBind pointer to the variable value pair
  1063. * invalue address of the data
  1064. *
  1065. * Return Codes:
  1066. *
  1067. * Standard PDU error codes.
  1068. *
  1069. */
  1070. UINT
  1071. SMIBuildDispString( IN OUT RFC1157VarBind *VarBind ,
  1072. IN char *invalue )
  1073. {
  1074. Simple_DisplayString *svalue = (Simple_DisplayString *)invalue;
  1075. UINT status = SNMP_ERRORSTATUS_NOERROR ;
  1076. VarBind->value.asnValue.string.stream =
  1077. SNMP_malloc( svalue->length * sizeof( char ) ) ;
  1078. if ( VarBind->value.asnValue.string.stream == NULL )
  1079. status = SNMP_ERRORSTATUS_GENERR ;
  1080. else
  1081. {
  1082. memcpy( VarBind->value.asnValue.string.stream ,
  1083. svalue->string ,
  1084. svalue->length ) ;
  1085. VarBind->value.asnValue.string.length = svalue->length ;
  1086. VarBind->value.asnType = ASN_RFC1213_DISPSTRING ;
  1087. VarBind->value.asnValue.string.dynamic = TRUE ;
  1088. }
  1089. return status ;
  1090. } /* end of SMIBuildDispString() */
  1091. /* end of smi.c */
  1092. /* SMIFree
  1093. *
  1094. * Free the variable
  1095. *
  1096. * Arguments:
  1097. *
  1098. * invalue address of data
  1099. *
  1100. * Return Codes:
  1101. *
  1102. *
  1103. */
  1104. void
  1105. SMIFree( IN AsnAny *invalue )
  1106. {
  1107. switch (invalue->asnType) {
  1108. case ASN_OCTETSTRING:
  1109. case ASN_RFC1155_IPADDRESS:
  1110. if (invalue->asnValue.string.length != 0) {
  1111. invalue->asnValue.string.length = 0 ;
  1112. SNMP_free(invalue->asnValue.string.stream) ;
  1113. }
  1114. break;
  1115. case ASN_OBJECTIDENTIFIER:
  1116. if (invalue->asnValue.object.idLength != 0) {
  1117. invalue->asnValue.object.idLength = 0;
  1118. SNMP_free(invalue->asnValue.object.ids) ;
  1119. }
  1120. break ;
  1121. default:
  1122. break ;
  1123. }
  1124. } /* end of SMIFree */
  1125. /* end of smi.c */
  1126.