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.

951 lines
23 KiB

  1. /*++
  2. Copyright (c) 1992-1997 Microsoft Corporation
  3. Module Name:
  4. varbinds.c
  5. Abstract:
  6. Contains routines for manipulating varbinds.
  7. Environment:
  8. User Mode - Win32
  9. Revision History:
  10. 10-Feb-1997 DonRyan
  11. Rewrote to implement SNMPv2 support.
  12. --*/
  13. ///////////////////////////////////////////////////////////////////////////////
  14. // //
  15. // Include files //
  16. // //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #include "globals.h"
  19. #include "varbinds.h"
  20. #include "query.h"
  21. #include "snmpmgmt.h"
  22. ///////////////////////////////////////////////////////////////////////////////
  23. // //
  24. // Private procedures //
  25. // //
  26. ///////////////////////////////////////////////////////////////////////////////
  27. BOOL
  28. LoadVarBind(
  29. PNETWORK_LIST_ENTRY pNLE,
  30. UINT iVb
  31. )
  32. /*++
  33. Routine Description:
  34. Creates varbind list entry from varbind structure.
  35. Arguments:
  36. pNLE - pointer to network list entry.
  37. iVb - index of variable binding.
  38. Return Values:
  39. Returns true if successful.
  40. --*/
  41. {
  42. SnmpVarBind * pVb;
  43. PVARBIND_LIST_ENTRY pVLE = NULL;
  44. PMIB_REGION_LIST_ENTRY pRLE = NULL;
  45. BOOL fAnyOk;
  46. BOOL fOk;
  47. // allocate list entry
  48. if (fOk = AllocVLE(&pVLE)) {
  49. // save varbind list index
  50. pVLE->nErrorIndex = iVb + 1;
  51. // retrieve varbind pointer
  52. pVb = &pNLE->Pdu.Vbl.list[iVb];
  53. SNMPDBG((
  54. SNMP_LOG_TRACE,
  55. "SNMP: SVC: variable %d name %s.\n",
  56. pVLE->nErrorIndex,
  57. SnmpUtilOidToA(&pVb->name)
  58. ));
  59. // initialize type of resolved variable
  60. pVLE->ResolvedVb.value.asnType = ASN_NULL;
  61. // copy varbind name to working structure
  62. SnmpUtilOidCpy(&pVLE->ResolvedVb.name, &pVb->name);
  63. // see if specific object asked for
  64. fAnyOk = ((pNLE->Pdu.nType == SNMP_PDU_GETNEXT) ||
  65. (pNLE->Pdu.nType == SNMP_PDU_GETBULK));
  66. // attempt to lookup variable name in supported regions
  67. if (FindSupportedRegion(&pRLE, &pVb->name, fAnyOk)) {
  68. // save pointer to region
  69. pVLE->pCurrentRLE = pRLE;
  70. // structure has been initialized
  71. pVLE->nState = VARBIND_INITIALIZED;
  72. SNMPDBG((
  73. SNMP_LOG_TRACE,
  74. "SNMP: SVC: variable %d assigned to %s.\n",
  75. pVLE->nErrorIndex,
  76. pVLE->pCurrentRLE->pSLE->pPathname
  77. ));
  78. SNMPDBG((
  79. SNMP_LOG_VERBOSE,
  80. "SNMP: SVC: variable %d state '%s'.\n",
  81. pVLE->nErrorIndex,
  82. VARBINDSTATESTRING(pVLE->nState)
  83. ));
  84. // see if this is a getnext request
  85. if (pNLE->Pdu.nType == SNMP_PDU_GETNEXT) {
  86. // only need single rep
  87. pVLE->nMaxRepetitions = 1;
  88. } else if (pNLE->Pdu.nType == SNMP_PDU_GETBULK) {
  89. // see if this non-repeater which is in bounds
  90. if (pNLE->Pdu.Pdu.BulkPdu.nNonRepeaters > (int)iVb) {
  91. // only need single rep
  92. pVLE->nMaxRepetitions = 1;
  93. SNMPDBG((
  94. SNMP_LOG_VERBOSE,
  95. "SNMP: SVC: variable %d max repetitions %d.\n",
  96. pVLE->nErrorIndex,
  97. pVLE->nMaxRepetitions
  98. ));
  99. // see if max-repetitions is non-zero
  100. } else if (pNLE->Pdu.Pdu.BulkPdu.nMaxRepetitions > 0) {
  101. // set max-repetitions to value in getbulk pdu
  102. pVLE->nMaxRepetitions = pNLE->Pdu.Pdu.BulkPdu.nMaxRepetitions;
  103. SNMPDBG((
  104. SNMP_LOG_VERBOSE,
  105. "SNMP: SVC: variable %d max repetitions %d.\n",
  106. pVLE->nErrorIndex,
  107. pVLE->nMaxRepetitions
  108. ));
  109. } else {
  110. // modify state to resolved
  111. pVLE->nState = VARBIND_RESOLVED;
  112. SNMPDBG((
  113. SNMP_LOG_VERBOSE,
  114. "SNMP: SVC: variable %d state '%s'.\n",
  115. pVLE->nErrorIndex,
  116. VARBINDSTATESTRING(pVLE->nState)
  117. ));
  118. SNMPDBG((
  119. SNMP_LOG_VERBOSE,
  120. "SNMP: SVC: variable %d value NULL.\n",
  121. pVLE->nErrorIndex
  122. ));
  123. }
  124. } else if (pNLE->Pdu.nType == SNMP_PDU_SET) {
  125. // copy varbind value to working structure
  126. SnmpUtilAsnAnyCpy(&pVLE->ResolvedVb.value, &pVb->value);
  127. SNMPDBG((
  128. SNMP_LOG_VERBOSE,
  129. "SNMP: SVC: variable %d value %s.\n",
  130. pVLE->nErrorIndex,
  131. "<TBD>"
  132. ));
  133. }
  134. } else {
  135. // null pointer to region
  136. pVLE->pCurrentRLE = NULL;
  137. SNMPDBG((
  138. SNMP_LOG_TRACE,
  139. "SNMP: SVC: variable %d unable to be assigned.\n",
  140. pVLE->nErrorIndex
  141. ));
  142. // getbulk
  143. if (fAnyOk) {
  144. // modify state to resolved
  145. pVLE->nState = VARBIND_RESOLVED;
  146. // set the exception in the variable's type field
  147. pVLE->ResolvedVb.value.asnType = SNMP_EXCEPTION_ENDOFMIBVIEW;
  148. SNMPDBG((
  149. SNMP_LOG_VERBOSE,
  150. "SNMP: SVC: variable %d state '%s'.\n",
  151. pVLE->nErrorIndex,
  152. VARBINDSTATESTRING(pVLE->nState)
  153. ));
  154. SNMPDBG((
  155. SNMP_LOG_VERBOSE,
  156. "SNMP: SVC: variable %d value ENDOFMIBVIEW.\n",
  157. pVLE->nErrorIndex
  158. ));
  159. } else if (pNLE->Pdu.nType == SNMP_PDU_GET) {
  160. // modify state to resolved
  161. pVLE->nState = VARBIND_RESOLVED;
  162. // set the exception in the variable's type field
  163. pVLE->ResolvedVb.value.asnType = SNMP_EXCEPTION_NOSUCHOBJECT;
  164. SNMPDBG((
  165. SNMP_LOG_VERBOSE,
  166. "SNMP: SVC: variable %d state '%s'.\n",
  167. pVLE->nErrorIndex,
  168. VARBINDSTATESTRING(pVLE->nState)
  169. ));
  170. SNMPDBG((
  171. SNMP_LOG_VERBOSE,
  172. "SNMP: SVC: variable %d value NOSUCHOBJECT.\n",
  173. pVLE->nErrorIndex
  174. ));
  175. } else {
  176. // modify state to resolved
  177. //pVLE->nState = VARBIND_ABORTED;
  178. pVLE->nState = VARBIND_RESOLVED;
  179. // save error status in network list entry
  180. pNLE->Pdu.Pdu.NormPdu.nErrorStatus = SNMP_ERRORSTATUS_NOTWRITABLE;
  181. pNLE->Pdu.Pdu.NormPdu.nErrorIndex = pVLE->nErrorIndex;
  182. SNMPDBG((
  183. SNMP_LOG_VERBOSE,
  184. "SNMP: SVC: variable %d state '%s'.\n",
  185. pVLE->nErrorIndex,
  186. VARBINDSTATESTRING(pVLE->nState)
  187. ));
  188. SNMPDBG((
  189. SNMP_LOG_VERBOSE,
  190. "SNMP: SVC: variable %d error %s.\n",
  191. pVLE->nErrorIndex,
  192. SNMPERRORSTRING(pNLE->Pdu.Pdu.NormPdu.nErrorStatus)
  193. ));
  194. // failure
  195. //fOk = FALSE;
  196. }
  197. }
  198. // add to existing varbind list
  199. InsertTailList(&pNLE->Bindings, &pVLE->Link);
  200. }
  201. return fOk;
  202. }
  203. BOOL
  204. LoadVarBinds(
  205. PNETWORK_LIST_ENTRY pNLE
  206. )
  207. /*++
  208. Routine Description:
  209. Creates list of varbind entries from varbind structure.
  210. Arguments:
  211. pNLE - pointer to network list entry.
  212. Return Values:
  213. Returns true if successful.
  214. --*/
  215. {
  216. UINT iVb;
  217. BOOL fOk = TRUE;
  218. // process each varbind in list
  219. for (iVb = 0; (fOk && (iVb < pNLE->Pdu.Vbl.len)); iVb++) {
  220. // load individual varbind
  221. fOk = LoadVarBind(pNLE, iVb);
  222. }
  223. return fOk;
  224. }
  225. BOOL
  226. UnloadVarBinds(
  227. PNETWORK_LIST_ENTRY pNLE
  228. )
  229. /*++
  230. Routine Description:
  231. Destroys list of varbind entries.
  232. Arguments:
  233. pNLE - pointer to network list entry.
  234. Return Values:
  235. Returns true if successful.
  236. --*/
  237. {
  238. PLIST_ENTRY pLE;
  239. PVARBIND_LIST_ENTRY pVLE;
  240. // process each varbind entry
  241. while (!IsListEmpty(&pNLE->Bindings)) {
  242. // point to first varbind
  243. pLE = RemoveHeadList(&pNLE->Bindings);
  244. // retrieve pointer to varbind entry from link
  245. pVLE = CONTAINING_RECORD(pLE, VARBIND_LIST_ENTRY, Link);
  246. // release
  247. FreeVLE(pVLE);
  248. }
  249. return TRUE;
  250. }
  251. BOOL
  252. ValidateVarBinds(
  253. PNETWORK_LIST_ENTRY pNLE
  254. )
  255. /*++
  256. Routine Description:
  257. Updates error status based on query results and version.
  258. Arguments:
  259. pNLE - pointer to network list entry.
  260. Return Values:
  261. Returns true if successful.
  262. --*/
  263. {
  264. PLIST_ENTRY pLE;
  265. PVARBIND_LIST_ENTRY pVLE;
  266. // see if error has already report during processing
  267. if (pNLE->Pdu.Pdu.NormPdu.nErrorStatus == SNMP_ERRORSTATUS_NOERROR) {
  268. // point to first varbind
  269. pLE = pNLE->Bindings.Flink;
  270. // process each varbind entry
  271. while (pLE != &pNLE->Bindings) {
  272. // retrieve pointer to varbind entry from link
  273. pVLE = CONTAINING_RECORD(pLE, VARBIND_LIST_ENTRY, Link);
  274. // see if varbind has been resolved
  275. if (pVLE->nState != VARBIND_RESOLVED) {
  276. SNMPDBG((
  277. SNMP_LOG_WARNING,
  278. "SNMP: SVC: variable %d unresolved.\n",
  279. pVLE->nErrorIndex
  280. ));
  281. // report internal error has occurred
  282. pNLE->Pdu.Pdu.NormPdu.nErrorStatus = SNMP_ERRORSTATUS_GENERR;
  283. pNLE->Pdu.Pdu.NormPdu.nErrorIndex = pVLE->nErrorIndex;
  284. break; // bail...
  285. } else if (pNLE->nVersion == SNMP_VERSION_1) {
  286. // report error if exceptions are present instead of values
  287. if ((pVLE->ResolvedVb.value.asnType == SNMP_EXCEPTION_NOSUCHOBJECT) ||
  288. (pVLE->ResolvedVb.value.asnType == SNMP_EXCEPTION_NOSUCHINSTANCE) ||
  289. (pVLE->ResolvedVb.value.asnType == SNMP_EXCEPTION_ENDOFMIBVIEW)) {
  290. SNMPDBG((
  291. SNMP_LOG_WARNING,
  292. "SNMP: SVC: variable %d unresolved in SNMPv1.\n",
  293. pVLE->nErrorIndex
  294. ));
  295. // report that variable could not be found
  296. pNLE->Pdu.Pdu.NormPdu.nErrorStatus = SNMP_ERRORSTATUS_NOSUCHNAME;
  297. pNLE->Pdu.Pdu.NormPdu.nErrorIndex = pVLE->nErrorIndex;
  298. break; // bail...
  299. }
  300. }
  301. // next entry
  302. pLE = pLE->Flink;
  303. }
  304. }
  305. // see if this is first version
  306. if (pNLE->nVersion == SNMP_VERSION_1) {
  307. // adjust status code
  308. switch (pNLE->Pdu.Pdu.NormPdu.nErrorStatus) {
  309. case SNMP_ERRORSTATUS_NOERROR:
  310. case SNMP_ERRORSTATUS_TOOBIG:
  311. case SNMP_ERRORSTATUS_NOSUCHNAME:
  312. case SNMP_ERRORSTATUS_BADVALUE:
  313. case SNMP_ERRORSTATUS_READONLY:
  314. case SNMP_ERRORSTATUS_GENERR:
  315. break;
  316. case SNMP_ERRORSTATUS_NOACCESS:
  317. case SNMP_ERRORSTATUS_NOCREATION:
  318. case SNMP_ERRORSTATUS_NOTWRITABLE:
  319. case SNMP_ERRORSTATUS_AUTHORIZATIONERROR:
  320. case SNMP_ERRORSTATUS_INCONSISTENTNAME:
  321. pNLE->Pdu.Pdu.NormPdu.nErrorStatus = SNMP_ERRORSTATUS_NOSUCHNAME;
  322. break;
  323. case SNMP_ERRORSTATUS_WRONGTYPE:
  324. case SNMP_ERRORSTATUS_WRONGLENGTH:
  325. case SNMP_ERRORSTATUS_WRONGENCODING:
  326. case SNMP_ERRORSTATUS_WRONGVALUE:
  327. case SNMP_ERRORSTATUS_INCONSISTENTVALUE:
  328. pNLE->Pdu.Pdu.NormPdu.nErrorStatus = SNMP_ERRORSTATUS_BADVALUE;
  329. break;
  330. case SNMP_ERRORSTATUS_RESOURCEUNAVAILABLE:
  331. case SNMP_ERRORSTATUS_COMMITFAILED:
  332. case SNMP_ERRORSTATUS_UNDOFAILED:
  333. default:
  334. pNLE->Pdu.Pdu.NormPdu.nErrorStatus = SNMP_ERRORSTATUS_GENERR;
  335. break;
  336. }
  337. }
  338. return (pNLE->Pdu.Pdu.NormPdu.nErrorStatus == SNMP_ERRORSTATUS_NOERROR);
  339. }
  340. BOOL
  341. UpdateVarBindsFromResolvedVb(
  342. PNETWORK_LIST_ENTRY pNLE
  343. )
  344. /*++
  345. Routine Description:
  346. Updates varbinds with results containing single varbinds.
  347. Arguments:
  348. pNLE - pointer to network list entry.
  349. Return Values:
  350. Returns true if successful.
  351. --*/
  352. {
  353. PLIST_ENTRY pLE;
  354. PVARBIND_LIST_ENTRY pVLE;
  355. // point to first varbind
  356. pLE = pNLE->Bindings.Flink;
  357. // process each varbind entry
  358. while (pLE != &pNLE->Bindings) {
  359. // retrieve pointer to varbind entry from link
  360. pVLE = CONTAINING_RECORD(pLE, VARBIND_LIST_ENTRY, Link);
  361. SNMPDBG((
  362. SNMP_LOG_TRACE,
  363. "SNMP: SVC: variable %d resolved name %s.\n",
  364. pVLE->nErrorIndex,
  365. SnmpUtilOidToA(&pVLE->ResolvedVb.name)
  366. ));
  367. // release memory for original varbind
  368. SnmpUtilVarBindFree(&pNLE->Pdu.Vbl.list[pVLE->nErrorIndex - 1]);
  369. // copy resolved varbind structure into pdu varbindlist
  370. SnmpUtilVarBindCpy(&pNLE->Pdu.Vbl.list[pVLE->nErrorIndex - 1],
  371. &pVLE->ResolvedVb
  372. );
  373. // next entry
  374. pLE = pLE->Flink;
  375. }
  376. // success
  377. return TRUE;
  378. }
  379. BOOL
  380. UpdateVarBindsFromResolvedVbl(
  381. PNETWORK_LIST_ENTRY pNLE
  382. )
  383. /*++
  384. Routine Description:
  385. Updates varbinds with results containing multiple varbinds.
  386. Arguments:
  387. pNLE - pointer to network list entry.
  388. Return Values:
  389. Returns true if successful.
  390. --*/
  391. {
  392. UINT nRepeaters;
  393. UINT nNonRepeaters;
  394. UINT nMaxRepetitions;
  395. UINT nIterations;
  396. UINT nVarBindsLast;
  397. UINT nVarBinds = 0;
  398. SnmpVarBind * pVarBind;
  399. PVARBIND_LIST_ENTRY pVLE;
  400. PLIST_ENTRY pLE1;
  401. PLIST_ENTRY pLE2;
  402. // retrieve getbulk parameters from pdu
  403. nNonRepeaters = pNLE->Pdu.Pdu.BulkPdu.nNonRepeaters;
  404. nMaxRepetitions = pNLE->Pdu.Pdu.BulkPdu.nMaxRepetitions;
  405. nRepeaters = (pNLE->Pdu.Vbl.len >= nNonRepeaters)
  406. ? (pNLE->Pdu.Vbl.len - nNonRepeaters)
  407. : 0
  408. ;
  409. // see if we need to expand size of varbind list
  410. if ((nRepeaters > 0) && (nMaxRepetitions > 1)) {
  411. UINT nMaxVarBinds;
  412. SnmpVarBind * pVarBinds;
  413. // calculate maximum number of varbinds possible
  414. nMaxVarBinds = nNonRepeaters + (nMaxRepetitions * nRepeaters);
  415. // reallocate varbind list to fit maximum
  416. pVarBinds = SnmpUtilMemReAlloc(pNLE->Pdu.Vbl.list,
  417. nMaxVarBinds * sizeof(SnmpVarBind)
  418. );
  419. // validate pointer
  420. if (pVarBinds == NULL) {
  421. SNMPDBG((
  422. SNMP_LOG_ERROR,
  423. "SNMP: SVC: Could not re-allocate varbind list.\n"
  424. ));
  425. return FALSE; // bail...
  426. }
  427. // restore varbind pointer
  428. pNLE->Pdu.Vbl.list = pVarBinds;
  429. }
  430. // point to first varbind
  431. pLE1 = pNLE->Bindings.Flink;
  432. // process each varbind entry
  433. while (pLE1 != &pNLE->Bindings) {
  434. // retrieve pointer to varbind entry from link
  435. pVLE = CONTAINING_RECORD(pLE1, VARBIND_LIST_ENTRY, Link);
  436. // see if this is non-repeater
  437. if (pVLE->nMaxRepetitions == 1) {
  438. // release memory for original varbind
  439. SnmpUtilVarBindFree(&pNLE->Pdu.Vbl.list[nVarBinds]);
  440. // copy resolved varbind into pdu structure
  441. SnmpUtilVarBindCpy(&pNLE->Pdu.Vbl.list[nVarBinds++],
  442. &pVLE->ResolvedVb
  443. );
  444. } else {
  445. //
  446. // finished processing non-repeaters
  447. //
  448. break;
  449. }
  450. // next entry
  451. pLE1 = pLE1->Flink;
  452. }
  453. // initialize
  454. nIterations = 0;
  455. // store
  456. pLE2 = pLE1;
  457. // process any repeaters until max
  458. while (nIterations < nMaxRepetitions) {
  459. // restore
  460. pLE1 = pLE2;
  461. // process each varbind entry
  462. while (pLE1 != &pNLE->Bindings) {
  463. // retrieve pointer to varbind entry from link
  464. pVLE = CONTAINING_RECORD(pLE1, VARBIND_LIST_ENTRY, Link);
  465. // see if value stored in default
  466. if (pVLE->ResolvedVbl.len == 0) {
  467. // release memory for original varbind
  468. SnmpUtilVarBindFree(&pNLE->Pdu.Vbl.list[nVarBinds]);
  469. // copy resolved varbind into pdu varbind list
  470. SnmpUtilVarBindCpy(&pNLE->Pdu.Vbl.list[nVarBinds],
  471. &pVLE->ResolvedVb
  472. );
  473. // increment
  474. nVarBinds++;
  475. // see if value available in this iteration
  476. } else if (pVLE->ResolvedVbl.len > nIterations) {
  477. // release memory for original varbind
  478. SnmpUtilVarBindFree(&pNLE->Pdu.Vbl.list[nVarBinds]);
  479. // copy resolved varbind into pdu varbind list
  480. SnmpUtilVarBindCpy(&pNLE->Pdu.Vbl.list[nVarBinds],
  481. &pVLE->ResolvedVbl.list[nIterations]
  482. );
  483. // increment
  484. nVarBinds++;
  485. }
  486. // next entry
  487. pLE1 = pLE1->Flink;
  488. }
  489. // increment
  490. nIterations++;
  491. }
  492. // save new varbind count
  493. pNLE->Pdu.Vbl.len = nVarBinds;
  494. // success
  495. return TRUE;
  496. }
  497. BOOL
  498. UpdatePdu(
  499. PNETWORK_LIST_ENTRY pNLE,
  500. BOOL fOk
  501. )
  502. /*++
  503. Routine Description:
  504. Updates pdu with query results.
  505. Arguments:
  506. pNLE - pointer to network list entry.
  507. fOk - true if process succeeded to this point.
  508. Return Values:
  509. Returns true if successful.
  510. --*/
  511. {
  512. PLIST_ENTRY pLE;
  513. PVARBIND_LIST_ENTRY pVLE;
  514. // validate
  515. if (fOk) {
  516. // make sure varbinds valid
  517. fOk = ValidateVarBinds(pNLE);
  518. // validate
  519. if (fOk) {
  520. // see if pdu type is getnext or getbulk
  521. if (pNLE->Pdu.nType != SNMP_PDU_GETBULK) {
  522. // update varbinds with single result
  523. fOk = UpdateVarBindsFromResolvedVb(pNLE);
  524. } else {
  525. // update varbinds with multiple results
  526. fOk = UpdateVarBindsFromResolvedVbl(pNLE);
  527. }
  528. }
  529. }
  530. // trap internal errors that have not been accounted for as of yet
  531. if (!fOk && (pNLE->Pdu.Pdu.NormPdu.nErrorStatus == SNMP_ERRORSTATUS_NOERROR)) {
  532. // report status that was determined above
  533. pNLE->Pdu.Pdu.NormPdu.nErrorStatus = SNMP_ERRORSTATUS_GENERR;
  534. pNLE->Pdu.Pdu.NormPdu.nErrorIndex = 0;
  535. }
  536. if (pNLE->Pdu.Pdu.NormPdu.nErrorStatus == SNMP_ERRORSTATUS_NOERROR)
  537. {
  538. switch(pNLE->Pdu.nType)
  539. {
  540. case SNMP_PDU_GETNEXT:
  541. case SNMP_PDU_GETBULK:
  542. case SNMP_PDU_GET:
  543. // update counter for successful GET-NEXT GET-BULK
  544. mgmtCAdd(CsnmpInTotalReqVars, pNLE->Pdu.Vbl.len);
  545. break;
  546. case SNMP_PDU_SET:
  547. // update counter for successful SET
  548. mgmtCAdd(CsnmpInTotalSetVars, pNLE->Pdu.Vbl.len);
  549. break;
  550. }
  551. }
  552. else
  553. {
  554. // update here counters for all OUT errors
  555. mgmtUtilUpdateErrStatus(OUT_errStatus, pNLE->Pdu.Pdu.NormPdu.nErrorStatus);
  556. }
  557. return TRUE;
  558. }
  559. ///////////////////////////////////////////////////////////////////////////////
  560. // //
  561. // Public procedures //
  562. // //
  563. ///////////////////////////////////////////////////////////////////////////////
  564. BOOL
  565. AllocVLE(
  566. PVARBIND_LIST_ENTRY * ppVLE
  567. )
  568. /*++
  569. Routine Description:
  570. Allocates varbind structure and initializes.
  571. Arguments:
  572. ppVLE - pointer to receive pointer to entry.
  573. Return Values:
  574. Returns true if successful.
  575. --*/
  576. {
  577. BOOL fOk = FALSE;
  578. PVARBIND_LIST_ENTRY pVLE = NULL;
  579. // attempt to allocate structure
  580. pVLE = AgentMemAlloc(sizeof(VARBIND_LIST_ENTRY));
  581. // validate
  582. if (pVLE != NULL) {
  583. // success
  584. fOk = TRUE;
  585. } else {
  586. SNMPDBG((
  587. SNMP_LOG_ERROR,
  588. "SNMP: SVC: could not allocate varbind entry.\n"
  589. ));
  590. }
  591. // transfer
  592. *ppVLE = pVLE;
  593. return fOk;
  594. }
  595. BOOL
  596. FreeVLE(
  597. PVARBIND_LIST_ENTRY pVLE
  598. )
  599. /*++
  600. Routine Description:
  601. Releases varbind structure.
  602. Arguments:
  603. pVLE - pointer to list entry to be freed.
  604. Return Values:
  605. Returns true if successful.
  606. --*/
  607. {
  608. BOOL fOk = TRUE;
  609. // validate pointer
  610. if (pVLE != NULL) {
  611. // release current varbind
  612. SnmpUtilVarBindFree(&pVLE->ResolvedVb);
  613. // release current varbind list
  614. SnmpUtilVarBindListFree(&pVLE->ResolvedVbl);
  615. // release structure
  616. AgentMemFree(pVLE);
  617. }
  618. return TRUE;
  619. }
  620. BOOL
  621. ProcessVarBinds(
  622. PNETWORK_LIST_ENTRY pNLE
  623. )
  624. /*++
  625. Routine Description:
  626. Creates list of varbind entries from varbind structure.
  627. Arguments:
  628. pNLE - pointer to network list entry.
  629. Return Values:
  630. Returns true if successful.
  631. --*/
  632. {
  633. BOOL fOk = FALSE;
  634. // validate type before processing
  635. if ((pNLE->Pdu.nType == SNMP_PDU_SET) ||
  636. (pNLE->Pdu.nType == SNMP_PDU_GET) ||
  637. (pNLE->Pdu.nType == SNMP_PDU_GETNEXT) ||
  638. (pNLE->Pdu.nType == SNMP_PDU_GETBULK)) {
  639. // initialize varbinds
  640. if (LoadVarBinds(pNLE)) {
  641. // process queries
  642. fOk = ProcessQueries(pNLE);
  643. }
  644. // transfer results
  645. UpdatePdu(pNLE, fOk);
  646. // unload varbinds
  647. UnloadVarBinds(pNLE);
  648. // update management counters for accepted and processed requests
  649. switch(pNLE->Pdu.nType)
  650. {
  651. case SNMP_PDU_GET:
  652. mgmtCTick(CsnmpInGetRequests);
  653. break;
  654. case SNMP_PDU_GETNEXT:
  655. case SNMP_PDU_GETBULK:
  656. mgmtCTick(CsnmpInGetNexts);
  657. break;
  658. case SNMP_PDU_SET:
  659. mgmtCTick(CsnmpInSetRequests);
  660. break;
  661. }
  662. } else {
  663. SNMPDBG((
  664. SNMP_LOG_ERROR,
  665. "SNMP: SVC: ignoring unknown pdu type %d.\n",
  666. pNLE->Pdu.nType
  667. ));
  668. }
  669. return fOk;
  670. }