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.

883 lines
28 KiB

  1. /*
  2. * HrSystem.c v0.10
  3. * Generated in conjunction with Management Factory scripts:
  4. * script version: SNMPv1, 0.16, Apr 25, 1996
  5. * project: D:\TEMP\EXAMPLE\HOSTMIB
  6. ****************************************************************************
  7. * *
  8. * (C) Copyright 1995 DIGITAL EQUIPMENT CORPORATION *
  9. * *
  10. * This software is an unpublished work protected under the *
  11. * the copyright laws of the United States of America, all *
  12. * rights reserved. *
  13. * *
  14. * In the event this software is licensed for use by the United *
  15. * States Government, all use, duplication or disclosure by the *
  16. * United States Government is subject to restrictions as set *
  17. * forth in either subparagraph (c)(1)(ii) of the Rights in *
  18. * Technical Data And Computer Software Clause at DFARS *
  19. * 252.227-7013, or the Commercial Computer Software Restricted *
  20. * Rights Clause at FAR 52.221-19, whichever is applicable. *
  21. * *
  22. ****************************************************************************
  23. *
  24. * Facility:
  25. *
  26. * Windows NT SNMP Extension Agent
  27. *
  28. * Abstract:
  29. *
  30. * This module contains the code for dealing with the get, set, and
  31. * instance name routines for the HrSystem. Actual instrumentation code is
  32. * supplied by the developer.
  33. *
  34. * Functions:
  35. *
  36. * A get and set routine for each attribute in the class.
  37. *
  38. * The routines for instances within the class.
  39. *
  40. * Author:
  41. *
  42. * D. D. Burns @ Webenable Inc
  43. *
  44. * Revision History:
  45. *
  46. * V1.00 - 04/17/97 D. D. Burns Genned: Thu Nov 07 16:39:21 1996
  47. *
  48. *
  49. */
  50. #include <windows.h>
  51. #include <malloc.h>
  52. #include <snmp.h>
  53. #include <lmcons.h> /* for NET_API_STATUS */
  54. #include <lmwksta.h> /* For NetWkStaGetInfo() */
  55. #include <lmapibuf.h> /* For NetApiBufferFree()*/
  56. #include <lmerr.h> /* For NERR_Success */
  57. #include <winsock.h> /* For htons() */
  58. #include "mib.h"
  59. #include "smint.h"
  60. #include "hostmsmi.h"
  61. #include "user.h" /* Developer supplied include file */
  62. #include "HMCACHE.H" /* For "hrSystemInitialLoadDevice" */
  63. /*
  64. * GetHrSystemUptime
  65. * The amount of time since this host was last initialized.
  66. *
  67. * Gets the value for HrSystemUptime.
  68. *
  69. * Arguments:
  70. *
  71. * outvalue address to return variable value
  72. * accesss Reserved for future security use
  73. * instance address of instance name as ordered native
  74. * data type(s)
  75. *
  76. * Return Codes:
  77. *
  78. * Standard PDU error codes.
  79. *
  80. * SNMP_ERRORSTATUS_NOERROR Successful get
  81. * SNMP_ERRORSTATUS_GENERR Catch-all failure code
  82. * mibtget.c v0.10
  83. *
  84. | =============== From WebEnable Design Spec Rev 3 04/11/97==================
  85. | hrSystemUptime
  86. |
  87. | ACCESS SYNTAX
  88. | read-only TimeTicks
  89. |
  90. | "The amount of time since this host was last initialized. Note that this is
  91. | different from sysUpTime in MIB-II [3] because sysUpTime is the uptime of
  92. | the network management portion of the system."
  93. |
  94. | DISCUSSION:
  95. |
  96. | Win32 API function "GetTickCount" is used to obtain the value returned for a
  97. | GET on this variable.
  98. |
  99. |============================================================================
  100. | 1.3.6.1.2.1.25.1.1.0
  101. | | |
  102. | | *-hrSystemUptime
  103. | *---hrSystem
  104. */
  105. UINT
  106. GetHrSystemUptime(
  107. OUT TimeTicks *outvalue ,
  108. IN Access_Credential *access ,
  109. IN InstanceName *instance )
  110. {
  111. *outvalue = GetTickCount();
  112. return SNMP_ERRORSTATUS_NOERROR ;
  113. } /* end of GetHrSystemUptime() */
  114. /*
  115. * GetHrSystemDate
  116. * The host's notion of the local date and time of day.
  117. *
  118. * Gets the value for HrSystemDate.
  119. *
  120. * Arguments:
  121. *
  122. * outvalue address to return variable value
  123. * accesss Reserved for future security use
  124. * instance address of instance name as ordered native
  125. * data type(s)
  126. *
  127. * Return Codes:
  128. *
  129. * Standard PDU error codes.
  130. *
  131. * SNMP_ERRORSTATUS_NOERROR Successful get
  132. * SNMP_ERRORSTATUS_GENERR Catch-all failure code
  133. * mibtget.c v0.10
  134. *
  135. | =============== From WebEnable Design Spec Rev 3 04/11/97==================
  136. | hrSystemDate
  137. |
  138. | ACCESS SYNTAX
  139. | read-write DateAndTime
  140. |
  141. | "The host's notion of the local date and time of day."
  142. |
  143. | DISCUSSION:
  144. |
  145. | Win32 API function "GetLocalTime" is used to obtain the value returned for a
  146. | GET on this variable.
  147. |
  148. | Since this variable is "read-write", this implies that the system time can
  149. | be set by a SET request. This is done with a Win32 API function
  150. | "SetLocalTime".
  151. |
  152. | <POA-1> Issuing "SetLocalTime" requires that the issuing process have the
  153. | "SE_SYSTEMTIME_NAME" privilege which is not the default. Are there any
  154. | security concerns about issuing the necessary Win32 API function call
  155. | "AdjustTokenPrivileges" from inside the SNMP agent to enable setting of
  156. | the system time? Any other problems?
  157. |
  158. | RESOLVED >>>>>>>
  159. | <POA-1> Let's leave this read-only.
  160. | RESOLVED >>>>>>>
  161. |
  162. |========================== From RFC1514 ====================================
  163. |
  164. | DateAndTime ::= OCTET STRING (SIZE (8 | 11))
  165. | -- A date-time specification for the local time of day.
  166. | -- This data type is intended to provide a consistent
  167. | -- method of reporting date information.
  168. | --
  169. | -- field octets contents range
  170. | -- _____ ______ ________ _____
  171. | -- 1 1-2 year 0..65536
  172. | -- (in network byte order)
  173. | -- 2 3 month 1..12
  174. | -- 3 4 day 1..31
  175. | -- 4 5 hour 0..23
  176. | -- 5 6 minutes 0..59
  177. | -- 6 7 seconds 0..60
  178. | -- (use 60 for leap-second)
  179. | -- 7 8 deci-seconds 0..9
  180. | -- 8 9 direction from UTC "+" / "-"
  181. | -- (in ascii notation)
  182. | -- 9 10 hours from UTC 0..11
  183. | -- 10 11 minutes from UTC 0..59
  184. | --
  185. | -- Note that if only local time is known, then
  186. | -- timezone information (fields 8-10) is not present.
  187. |
  188. |============================================================================
  189. | 1.3.6.1.2.1.25.1.2.0
  190. | | |
  191. | | *-hrSystemDate
  192. | *---hrSystem
  193. */
  194. UINT
  195. GetHrSystemDate(
  196. OUT DateAndTime *outvalue ,
  197. IN Access_Credential *access ,
  198. IN InstanceName *instance )
  199. {
  200. SYSTEMTIME localtime; // Where we retrieve current local time
  201. USHORT year_networkbyteorder; // Network byte order of year
  202. static
  203. char octet_time[8]; // OCTET STRING format of "time"
  204. GetLocalTime(&localtime);
  205. year_networkbyteorder = htons(localtime.wYear);
  206. //
  207. // Format "dateandtime" according to RFC1514
  208. //
  209. octet_time[0] = (year_networkbyteorder & 0xFF);
  210. octet_time[1] = (year_networkbyteorder >> 8);
  211. octet_time[2] = (char) localtime.wMonth;
  212. octet_time[3] = (char) localtime.wDay;
  213. octet_time[4] = (char) localtime.wHour;
  214. octet_time[5] = (char) localtime.wMinute;
  215. octet_time[6] = (char) localtime.wSecond;
  216. octet_time[7] = localtime.wMilliseconds / 100;
  217. outvalue->length = 8;
  218. outvalue->string = octet_time;
  219. return SNMP_ERRORSTATUS_NOERROR ;
  220. } /* end of GetHrSystemDate() */
  221. /*
  222. * GetHrSystemInitialLoadDevice
  223. * The index of the hrDeviceEntry for the device from which this host is
  224. * configured to load its initial operating system configurat
  225. *
  226. * Gets the value for HrSystemInitialLoadDevice.
  227. *
  228. * Arguments:
  229. *
  230. * outvalue address to return variable value
  231. * accesss Reserved for future security use
  232. * instance address of instance name as ordered native
  233. * data type(s)
  234. *
  235. * Return Codes:
  236. *
  237. * Standard PDU error codes.
  238. *
  239. * SNMP_ERRORSTATUS_NOERROR Successful get
  240. * SNMP_ERRORSTATUS_GENERR Catch-all failure code
  241. * mibtget.c v0.10
  242. *
  243. | =============== From WebEnable Design Spec Rev 3 04/11/97==================
  244. | hrSystemInitialLoadDevice
  245. |
  246. | ACCESS SYNTAX
  247. | read-write INTEGER (1..2147483647)
  248. |
  249. | "The index of the hrDeviceEntry for the device from which this host is
  250. | configured to load its initial operating system configuration."
  251. |
  252. | DISCUSSION:
  253. |
  254. | <POA-2> It seems that RFC1514 is attempting to allow the setting and resetting
  255. | of the default operating system to be booted thru the combination of this
  256. | attribute and "hrSystemInitialLoadParameters" (below).
  257. |
  258. | While generic PC hardware typically boots from a hard disk partition that is
  259. | going to wind up being labelled as drive "C:", these two variables speak to a
  260. | more general situation in which a hardware bootstrap loader can be set to
  261. | point to almost any system image on a "permanent file system" (to use the unix
  262. | phrase). It is apparent that we must attempt to approximate this in some way.
  263. |
  264. | I note that a system file named "Boot.ini" resides on the bootable partition
  265. | of an Intel NT system. The one on my system looks like:
  266. |
  267. | >>>>>>>>
  268. | [boot loader]
  269. | timeout=30
  270. | default=multi(0)disk(0)rdisk(0)partition(1)\WINNT35
  271. | [operating systems]
  272. | multi(0)disk(0)rdisk(0)partition(1)\WINNT35="Windows NT Server Version 3.51"
  273. | multi(0)disk(0)rdisk(0)partition(1)\WINNT35="Windows NT Server Version 3.51 [VGA mode]" /basevideo /sos
  274. | <<<<<<<<
  275. |
  276. | The contents of this file seems to be the source of the menu that appears
  277. | during the NT boot process. Programming a selection from this menu is a close
  278. | approximation to the flexibility hinted at thru the combination of these
  279. | two SNMP attributes, "hrSystemInitialLoadDevice" and
  280. | "hrSystemInitialLoadParameters".
  281. |
  282. | For the purposes of "GET", given the "default" shown in the "Boot.ini" file
  283. | above, it would seem that the string "multi(0)disk(0)rdisk(0)partition(1)"
  284. | constitutes a passing resemblance to "hrSystemInitialLoadDevice" while the
  285. | string "\WINNT35" seems to be a good candidate for the value of
  286. | "hrSystemInitialLoadParameters" (where both of these are drawn from the value
  287. | specified for "default" under "[boot loader]").
  288. |
  289. | For the purposes of "SET", we would be required to modify this file according
  290. | to the values received. I note that the file on my system is write-protected
  291. | and clearly this poses a problem if we allow the SNMP agent to attempt to
  292. | modify it. Additionally, there is the problem of error-checking any value
  293. | provided from an SNMP SET request (I do not know the exact semantic
  294. | significance of "multi(0)disk(0)rdisk(0)partition(1)" and I do not know how
  295. | to error-check a received value).
  296. |
  297. | RESOLVED >>>>>>>
  298. | <POA-2> Call GetWindowsDirectory and work backwards from that (get the
  299. | device name, e.g. D, then do a QueryDosDevice to get the underlying
  300. | partition information). Much more accurate than trying to parse boot.ini,
  301. | and portable to Alpha. Leave read-only.
  302. | RESOLVED >>>>>>>
  303. |============================================================================
  304. | 1.3.6.1.2.1.25.1.3.0
  305. | | |
  306. | | *-hrSystemInitialLoadDevice
  307. | *---hrSystem
  308. */
  309. UINT
  310. GetHrSystemInitialLoadDevice(
  311. OUT Integer *outvalue ,
  312. IN Access_Credential *access ,
  313. IN InstanceName *instance )
  314. {
  315. /*
  316. | Fetch this magic index from static storage in "HRDEVENT.C".
  317. */
  318. *outvalue = InitLoadDev_index;
  319. return SNMP_ERRORSTATUS_NOERROR ;
  320. } /* end of GetHrSystemInitialLoadDevice() */
  321. /*
  322. * SetHrSystemInitialLoadDevice
  323. * The index of the hrDeviceEntry for the device from which this host is
  324. * configured to load its initial operating system configurat
  325. *
  326. * Sets the HrSystemInitialLoadDevice value.
  327. *
  328. * Arguments:
  329. *
  330. * invalue address of value to set the variable
  331. * outvalue address to return the set variable value
  332. * access Reserved for future security use
  333. * instance address of instance name as ordered native
  334. * data type(s)
  335. *
  336. * Return Codes:
  337. *
  338. * Standard PDU error codes.
  339. *
  340. * SNMP_ERRORSTATUS_NOERROR Successful get
  341. * SNMP_ERRORSTATUS_BADVALUE Set value not in range
  342. * SNMP_ERRORSTATUS_GENERR Catch-all failure code
  343. * mibtset.ntc v0.10
  344. */
  345. UINT
  346. SetHrSystemInitialLoadDevice(
  347. IN Integer *invalue ,
  348. OUT Integer *outvalue ,
  349. IN Access_Credential *access ,
  350. IN InstanceName *instance )
  351. {
  352. return SNMP_ERRORSTATUS_NOSUCHNAME ;
  353. } /* end of SetHrSystemInitialLoadDevice() */
  354. /*
  355. * GetHrSystemInitialLoadParameters
  356. * This object contains the paramets (e.g. a pathname and parameter)
  357. * supplied to the load device when requesting the initial operat
  358. *
  359. * Gets the value for HrSystemInitialLoadParameters.
  360. *
  361. * Arguments:
  362. *
  363. * outvalue address to return variable value
  364. * accesss Reserved for future security use
  365. * instance address of instance name as ordered native
  366. * data type(s)
  367. *
  368. * Return Codes:
  369. *
  370. * Standard PDU error codes.
  371. *
  372. * SNMP_ERRORSTATUS_NOERROR Successful get
  373. * SNMP_ERRORSTATUS_GENERR Catch-all failure code
  374. * mibtget.c v0.10
  375. *
  376. | =============== From WebEnable Design Spec Rev 3 04/11/97==================
  377. | hrSystemInitialLoadParameters
  378. |
  379. | ACCESS SYNTAX
  380. | read-write InternationalDisplayString (SIZE (0..128))
  381. |
  382. | "This object contains the parameters (e.g. a pathname and parameter) supplied
  383. | to the load device when requesting the initial operating system configuration
  384. | from that device."
  385. |
  386. | DISCUSSION:
  387. |
  388. | (See discussion for "hrSystemInitialLoadDevice" above).
  389. |
  390. | For initial version, we return a zero length string, and it is not SETable.
  391. |
  392. |============================================================================
  393. | 1.3.6.1.2.1.25.1.4.0
  394. | | |
  395. | | *-hrSystemInitialLoadParameters
  396. | *---hrSystem
  397. */
  398. UINT
  399. GetHrSystemInitialLoadParameters(
  400. OUT InternationalDisplayString *outvalue ,
  401. IN Access_Credential *access ,
  402. IN InstanceName *instance )
  403. {
  404. // (No parameter-string returned for initial release)
  405. outvalue->length = 0;
  406. outvalue->string = NULL;
  407. return SNMP_ERRORSTATUS_NOERROR ;
  408. } /* end of GetHrSystemInitialLoadParameters() */
  409. /*
  410. * SetHrSystemInitialLoadParameters
  411. * This object contains the paramets (e.g. a pathname and parameter)
  412. * supplied to the load device when requesting the initial operat
  413. *
  414. * Sets the HrSystemInitialLoadParameters value.
  415. *
  416. * Arguments:
  417. *
  418. * invalue address of value to set the variable
  419. * outvalue address to return the set variable value
  420. * access Reserved for future security use
  421. * instance address of instance name as ordered native
  422. * data type(s)
  423. *
  424. * Return Codes:
  425. *
  426. * Standard PDU error codes.
  427. *
  428. * SNMP_ERRORSTATUS_NOERROR Successful get
  429. * SNMP_ERRORSTATUS_BADVALUE Set value not in range
  430. * SNMP_ERRORSTATUS_GENERR Catch-all failure code
  431. * mibtset.ntc v0.10
  432. */
  433. UINT
  434. SetHrSystemInitialLoadParameters(
  435. IN InternationalDisplayString *invalue ,
  436. OUT InternationalDisplayString *outvalue ,
  437. IN Access_Credential *access ,
  438. IN InstanceName *instance )
  439. {
  440. return SNMP_ERRORSTATUS_NOSUCHNAME ;
  441. } /* end of SetHrSystemInitialLoadParameters() */
  442. /*
  443. * GetHrSystemNumUsers
  444. * The number of user sessions for which this host is storing state
  445. * information.
  446. *
  447. * Gets the value for HrSystemNumUsers.
  448. *
  449. * Arguments:
  450. *
  451. * outvalue address to return variable value
  452. * accesss Reserved for future security use
  453. * instance address of instance name as ordered native
  454. * data type(s)
  455. *
  456. * Return Codes:
  457. *
  458. * Standard PDU error codes.
  459. *
  460. * SNMP_ERRORSTATUS_NOERROR Successful get
  461. * SNMP_ERRORSTATUS_GENERR Catch-all failure code
  462. * mibtget.c v0.10
  463. *
  464. | =============== From WebEnable Design Spec Rev 3 04/11/97==================
  465. | hrSystemNumUsers
  466. |
  467. | ACCESS SYNTAX
  468. | read-only Gauge
  469. |
  470. | "The number of user sessions for which this host is storing state information.
  471. | A session is a collection of processes requiring a single act of user
  472. | authentication and possibly subject to collective job control."
  473. |
  474. | DISCUSSION:
  475. |
  476. | <POA-3> This metric does not seem to be directly available thru a standard
  477. | Win32 API function. I note that what appears to be logon information seems to
  478. | be stored in the registry under:
  479. |
  480. | "HKEY_LOCAL_MACHINE\microsoft\windows nt\winlogon".
  481. |
  482. | + Should I use this as a source for this SNMP attribute?
  483. | + If this registry entry is the proper place to acquire this information, what
  484. | is the full and proper way to parse this entry? (By this I mean if more
  485. | than one user is logged on, how does this single registry entry reflect
  486. | multiple users?)
  487. | + Does it reflect other users logged in via a network connection?
  488. |
  489. | RESOLVED >>>>>>>
  490. | <POA-3> There is going to be either one interactive user or none. Use
  491. | NetWkstaGetInfo to try to determine the name of the currently logged on
  492. | interactive user and if this succeeds then it is the former.
  493. | RESOLVED >>>>>>>
  494. |
  495. |=============================================================================
  496. | 1.3.6.1.2.1.25.1.5.0
  497. | | |
  498. | | *-hrSystemNumUsers
  499. | *---hrSystem
  500. */
  501. UINT
  502. GetHrSystemNumUsers(
  503. OUT Gauge *outvalue ,
  504. IN Access_Credential *access ,
  505. IN InstanceName *instance )
  506. {
  507. LPBYTE info; /* Where we get logged-on information */
  508. // Attempt to get the number of logged-on users . . .
  509. if (NetWkstaGetInfo(NULL, /* "Local" computer */
  510. 102, /* Info Level 102 */
  511. &info) != NERR_Success) {
  512. return SNMP_ERRORSTATUS_GENERR ;
  513. }
  514. /* Just return it */
  515. *outvalue = ((LPWKSTA_INFO_102) info)->wki102_logged_on_users;
  516. /* Free the Net API Buffer */
  517. NetApiBufferFree(info);
  518. return SNMP_ERRORSTATUS_NOERROR ;
  519. } /* end of GetHrSystemNumUsers() */
  520. /*
  521. * GetHrSystemProcesses
  522. * The number of process contexts currently loaded or running on this system.
  523. *
  524. * Gets the value for HrSystemProcesses.
  525. *
  526. * Arguments:
  527. *
  528. * outvalue address to return variable value
  529. * accesss Reserved for future security use
  530. * instance address of instance name as ordered native
  531. * data type(s)
  532. *
  533. * Return Codes:
  534. *
  535. * Standard PDU error codes.
  536. *
  537. * SNMP_ERRORSTATUS_NOERROR Successful get
  538. * SNMP_ERRORSTATUS_GENERR Catch-all failure code
  539. * mibtget.c v0.10
  540. *
  541. |=============== From WebEnable Design Spec Rev 3 04/11/97==================
  542. | hrSystemProcesses
  543. |
  544. | ACCESS SYNTAX
  545. | read-only Gauge
  546. |
  547. | "The number of process contexts currently loaded or running on this system."
  548. |
  549. | DISCUSSION:
  550. |
  551. | The sample-code "Process Viewer" (PVIEWER.EXE) that is part of the Win32 SDK
  552. | infers a list of active processes from performance information that is stored
  553. | in the registry. We use this approach (and borrowed code) to obtaining a
  554. | count of active processes.
  555. |
  556. |-- (The foregoing approach is abandoned for a direct "beyond-the-veil" call
  557. |-- to NtQuerySystemInfo()).
  558. |=============================================================================
  559. | 1.3.6.1.2.1.25.1.6.0
  560. | | |
  561. | | *-hrSystemNumUsers
  562. | *---hrSystem
  563. */
  564. UINT
  565. GetHrSystemProcesses(
  566. OUT Gauge *outvalue ,
  567. IN Access_Credential *access ,
  568. IN InstanceName *instance )
  569. {
  570. ULONG process_count;
  571. // If we failed to get the Process Count successfully . . .
  572. if ((process_count = Spt_GetProcessCount()) == 0) {
  573. return SNMP_ERRORSTATUS_GENERR ;
  574. }
  575. // Return the value
  576. *outvalue = process_count;
  577. return SNMP_ERRORSTATUS_NOERROR ;
  578. } /* end of GetHrSystemProcesses() */
  579. /*
  580. * GetHrSystemMaxProcesses
  581. * The maximum number of process contexts this system can support. If there
  582. * is no fixed maximum, the value should be zero.
  583. *
  584. * Gets the value for HrSystemMaxProcesses.
  585. *
  586. * Arguments:
  587. *
  588. * outvalue address to return variable value
  589. * accesss Reserved for future security use
  590. * instance address of instance name as ordered native
  591. * data type(s)
  592. *
  593. * Return Codes:
  594. *
  595. * Standard PDU error codes.
  596. *
  597. * SNMP_ERRORSTATUS_NOERROR Successful get
  598. * SNMP_ERRORSTATUS_GENERR Catch-all failure code
  599. * mibtget.c v0.10
  600. *
  601. |=============== From WebEnable Design Spec Rev 3 04/11/97==================
  602. | hrSystemMaxProcesses
  603. |
  604. | ACCESS SYNTAX
  605. | read-only INTEGER (0..2147483647)
  606. |
  607. | "The maximum number of process contexts this system can support. If there is
  608. | no fixed maximum, the value should be zero. On systems that have a fixed
  609. | maximum, this object can help diagnose failures that occur when this maximum
  610. | is reached."
  611. |
  612. | DISCUSSION:
  613. |
  614. | My understanding is there is no fixed maximum, as the effective maximum is
  615. | main-memory dependent. We return 0 for the value of this attribute.
  616. |
  617. |=============================================================================
  618. | 1.3.6.1.2.1.25.1.7.0
  619. | | |
  620. | | *-hrSystemNumUsers
  621. | *---hrSystem
  622. */
  623. UINT
  624. GetHrSystemMaxProcesses(
  625. OUT Integer *outvalue ,
  626. IN Access_Credential *access ,
  627. IN InstanceName *instance )
  628. {
  629. *outvalue = 0;
  630. return SNMP_ERRORSTATUS_NOERROR ;
  631. } /* end of GetHrSystemMaxProcesses() */
  632. /*
  633. * HrSystemFindInstance
  634. *
  635. * This routine is used to verify that the specified instance is
  636. * valid.
  637. *
  638. * Arguments:
  639. *
  640. * FullOid Address for the full oid - group, variable,
  641. * and instance information
  642. * instance Address for instance specification as an oid
  643. *
  644. * Return Codes:
  645. *
  646. * SNMP_ERRORSTATUS_NOERROR Instance found and valid
  647. * SNMP_ERRORSTATUS_NOSUCHNAME Invalid instance
  648. *
  649. */
  650. UINT
  651. HrSystemFindInstance( IN ObjectIdentifier *FullOid ,
  652. IN OUT ObjectIdentifier *instance )
  653. {
  654. UINT tmp_instance ;
  655. //
  656. // Developer instrumentation code to find appropriate instance goes here.
  657. // For non-tables, it is not necessary to modify this routine. However,
  658. // if there is any context that needs to be set, it can be done here.
  659. //
  660. if ( FullOid->idLength <= HRSYSTEM_VAR_INDEX )
  661. // No instance was specified
  662. return SNMP_ERRORSTATUS_NOSUCHNAME ;
  663. else if ( FullOid->idLength != HRSYSTEM_VAR_INDEX + 1 )
  664. // Instance length is more than 1
  665. return SNMP_ERRORSTATUS_NOSUCHNAME ;
  666. else
  667. // The only valid instance for a non-table are instance 0. If this
  668. // is a non-table, the following code validates the instances. If this
  669. // is a table, developer modification is necessary below.
  670. tmp_instance = FullOid->ids[ HRSYSTEM_VAR_INDEX ] ;
  671. if ( tmp_instance )
  672. return SNMP_ERRORSTATUS_NOSUCHNAME ;
  673. else
  674. {
  675. // the instance is valid. Create the instance portion of the OID
  676. // to be returned from this call.
  677. instance->ids[ 0 ] = tmp_instance ;
  678. instance->idLength = 1 ;
  679. }
  680. return SNMP_ERRORSTATUS_NOERROR ;
  681. } /* end of HrSystemFindInstance() */
  682. /*
  683. * HrSystemFindNextInstance
  684. *
  685. * This routine is called to get the next instance. If no instance
  686. * was passed than return the first instance (1).
  687. *
  688. * Arguments:
  689. *
  690. * FullOid Address for the full oid - group, variable,
  691. * and instance information
  692. * instance Address for instance specification as an oid
  693. *
  694. * Return Codes:
  695. *
  696. * SNMP_ERRORSTATUS_NOERROR Instance found and valid
  697. * SNMP_ERRORSTATUS_NOSUCHNAME Invalid instance
  698. *
  699. */
  700. UINT
  701. HrSystemFindNextInstance( IN ObjectIdentifier *FullOid ,
  702. IN OUT ObjectIdentifier *instance )
  703. {
  704. //
  705. // Developer supplied code to find the next instance of class goes here.
  706. // If this is a class with cardinality 1, no modification of this routine
  707. // is necessary unless additional context needs to be set.
  708. // If the FullOid does not specify an instance, then the only instance
  709. // of the class is returned. If this is a table, the first row of the
  710. // table is returned.
  711. //
  712. // If an instance is specified and this is a non-table class, then NOSUCHNAME
  713. // is returned so that correct MIB rollover processing occurs. If this is
  714. // a table, then the next instance is the one following the current instance.
  715. // If there are no more instances in the table, return NOSUCHNAME.
  716. //
  717. if ( FullOid->idLength <= HRSYSTEM_VAR_INDEX )
  718. {
  719. instance->ids[ 0 ] = 0 ;
  720. instance->idLength = 1 ;
  721. }
  722. else
  723. return SNMP_ERRORSTATUS_NOSUCHNAME ;
  724. return SNMP_ERRORSTATUS_NOERROR ;
  725. } /* end of HrSystemFindNextInstance() */
  726. /*
  727. * HrSystemConvertInstance
  728. *
  729. * This routine is used to convert the object id specification of an
  730. * instance into an ordered native representation. The object id format
  731. * is that object identifier that is returned from the Find Instance
  732. * or Find Next Instance routines. It is NOT the full object identifier
  733. * that contains the group and variable object ids as well. The native
  734. * representation is an argc/argv-like structure that contains the
  735. * ordered variables that define the instance. This is specified by
  736. * the MIB's INDEX clause. See RFC 1212 for information about the INDEX
  737. * clause.
  738. *
  739. *
  740. * Arguments:
  741. *
  742. * oid_spec Address of the object id instance specification
  743. * native_spec Address to return the ordered native instance
  744. * specification
  745. *
  746. * Return Codes:
  747. *
  748. * SUCCESS Conversion complete successfully
  749. * FAILURE Unable to convert object id into native format
  750. *
  751. */
  752. UINT
  753. HrSystemConvertInstance( IN ObjectIdentifier *oid_spec ,
  754. IN OUT InstanceName *native_spec )
  755. {
  756. //
  757. // Developer supplied code to convert instance identifer to native
  758. // specification of instance names goes here.
  759. //
  760. return SUCCESS ;
  761. } /* end of HrSystemConvertInstance() */
  762. /*
  763. * HrSystemFreeInstance
  764. *
  765. * This routine is used to free an ordered native representation of an
  766. * instance name.
  767. *
  768. * Arguments:
  769. *
  770. * instance Address to return the ordered native instance
  771. * specification
  772. *
  773. * Return Codes:
  774. *
  775. *
  776. */
  777. void
  778. HrSystemFreeInstance( IN OUT InstanceName *instance )
  779. {
  780. //
  781. // Developer supplied code to free native representation of instance name goes here.
  782. //
  783. } /* end of HrSystemFreeInstance() */