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.

316 lines
9.7 KiB

  1. /*
  2. * HrStorage.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 HrStorage. 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 Original Creation: Thu Nov 07 16:39:42 1996
  47. *
  48. */
  49. #include <windows.h>
  50. #include <malloc.h>
  51. #include <snmp.h>
  52. #include "mib.h"
  53. #include "smint.h"
  54. #include "hostmsmi.h"
  55. #include "user.h" /* Developer supplied include file */
  56. /*
  57. * GetHrMemorySize
  58. * The amount of physical main memory contained by the host.
  59. *
  60. * Gets the value for HrMemorySize.
  61. *
  62. * Arguments:
  63. *
  64. * outvalue address to return variable value
  65. * accesss Reserved for future security use
  66. * instance address of instance name as ordered native
  67. * data type(s)
  68. *
  69. * Return Codes:
  70. *
  71. * Standard PDU error codes.
  72. *
  73. * SNMP_ERRORSTATUS_NOERROR Successful get
  74. * SNMP_ERRORSTATUS_GENERR Catch-all failure code
  75. * mibtget.c v0.10
  76. *
  77. | =============== From WebEnable Design Spec Rev 3 04/11/97==================
  78. | hrMemorySize
  79. |
  80. | ACCESS SYNTAX
  81. | read-only KBytes
  82. |
  83. | "The amount of physical main memory contained by the host."
  84. |
  85. | DISCUSSION:
  86. |
  87. | Win32 API function "GlobalMemoryStatus" is invoked and the value returned
  88. | in structure MEMORYSTATUS for cell "dwTotalPhys" is used to compute the value
  89. | returned for this attribute.
  90. |
  91. |============================================================================
  92. | 1.3.6.1.2.1.25.2.2.0
  93. | | |
  94. | | *-hrMemorySize
  95. | *-hrStorage
  96. */
  97. UINT
  98. GetHrMemorySize(
  99. OUT KBytes *outvalue ,
  100. IN Access_Credential *access ,
  101. IN InstanceName *instance )
  102. {
  103. MEMORYSTATUSEX mem_status; /* For "GlobalMemoryStatusEx()" call */
  104. /* Get the "mem_status" structure filled in */
  105. mem_status.dwLength = sizeof(MEMORYSTATUSEX);
  106. if (!GlobalMemoryStatusEx(&mem_status))
  107. {
  108. RtlZeroMemory(&mem_status, sizeof(MEMORYSTATUSEX));
  109. }
  110. // the maximum amount we can return is 2147483647 KBytes (i.e. INT_MAX)
  111. // 0x1FFFFFFFC00 = 2147483647 * 1024
  112. if (mem_status.ullTotalPhys > 0x1FFFFFFFC00)
  113. {
  114. mem_status.ullTotalPhys = 0x1FFFFFFFC00;
  115. }
  116. /* Return total available physical bytes reduced to 1024 blocks */
  117. *outvalue = (KBytes)(mem_status.ullTotalPhys / 1024);
  118. return SNMP_ERRORSTATUS_NOERROR ;
  119. } /* end of GetHrMemorySize() */
  120. /*
  121. * HrStorageFindInstance
  122. *
  123. * This routine is used to verify that the specified instance is
  124. * valid.
  125. *
  126. * Arguments:
  127. *
  128. * FullOid Address for the full oid - group, variable,
  129. * and instance information
  130. * instance Address for instance specification as an oid
  131. *
  132. * Return Codes:
  133. *
  134. * SNMP_ERRORSTATUS_NOERROR Instance found and valid
  135. * SNMP_ERRORSTATUS_NOSUCHNAME Invalid instance
  136. *
  137. */
  138. UINT
  139. HrStorageFindInstance( IN ObjectIdentifier *FullOid ,
  140. IN OUT ObjectIdentifier *instance )
  141. {
  142. UINT tmp_instance ;
  143. //
  144. // Developer instrumentation code to find appropriate instance goes here.
  145. // For non-tables, it is not necessary to modify this routine.
  146. // However, if there is any context that needs to be set, it can be done
  147. // here.
  148. if ( FullOid->idLength <= HRSTORAGE_VAR_INDEX )
  149. // No instance was specified
  150. return SNMP_ERRORSTATUS_NOSUCHNAME ;
  151. else if ( FullOid->idLength != HRSTORAGE_VAR_INDEX + 1 )
  152. // Instance length is more than 1
  153. return SNMP_ERRORSTATUS_NOSUCHNAME ;
  154. else
  155. // The only valid instance for a non-table are instance 0. If this
  156. // is a non-table, the following code validates the instances. If this
  157. // is a table, developer modification is necessary below.
  158. tmp_instance = FullOid->ids[ HRSTORAGE_VAR_INDEX ] ;
  159. if ( tmp_instance )
  160. return SNMP_ERRORSTATUS_NOSUCHNAME ;
  161. else
  162. {
  163. // the instance is valid. Create the instance portion of the OID
  164. // to be returned from this call.
  165. instance->ids[ 0 ] = tmp_instance ;
  166. instance->idLength = 1 ;
  167. }
  168. return SNMP_ERRORSTATUS_NOERROR ;
  169. } /* end of HrStorageFindInstance() */
  170. /*
  171. * HrStorageFindNextInstance
  172. *
  173. * This routine is called to get the next instance. If no instance
  174. * was passed than return the first instance (1).
  175. *
  176. * Arguments:
  177. *
  178. * FullOid Address for the full oid - group, variable,
  179. * and instance information
  180. * instance Address for instance specification as an oid
  181. *
  182. * Return Codes:
  183. *
  184. * SNMP_ERRORSTATUS_NOERROR Instance found and valid
  185. * SNMP_ERRORSTATUS_NOSUCHNAME Invalid instance
  186. *
  187. */
  188. UINT
  189. HrStorageFindNextInstance( IN ObjectIdentifier *FullOid ,
  190. IN OUT ObjectIdentifier *instance )
  191. {
  192. //
  193. // Developer supplied code to find the next instance of class goes here.
  194. // If this is a class with cardinality 1, no modification of this routine
  195. // is necessary unless additional context needs to be set.
  196. // If the FullOid does not specify an instance, then the only instance
  197. // of the class is returned. If this is a table, the first row of the
  198. // table is returned.
  199. //
  200. // If an instance is specified and this is a non-table class, then
  201. // NOSUCHNAME is returned so that correct MIB rollover processing occurs.
  202. //
  203. // If this is a table, then the next instance is the one following the
  204. // current instance.
  205. //
  206. // If there are no more instances in the table, return NOSUCHNAME.
  207. //
  208. if ( FullOid->idLength <= HRSTORAGE_VAR_INDEX )
  209. {
  210. instance->ids[ 0 ] = 0 ;
  211. instance->idLength = 1 ;
  212. }
  213. else
  214. return SNMP_ERRORSTATUS_NOSUCHNAME ;
  215. return SNMP_ERRORSTATUS_NOERROR ;
  216. } /* end of HrStorageFindNextInstance() */
  217. /*
  218. * HrStorageConvertInstance
  219. *
  220. * This routine is used to convert the object id specification of an
  221. * instance into an ordered native representation. The object id format
  222. * is that object identifier that is returned from the Find Instance
  223. * or Find Next Instance routines. It is NOT the full object identifier
  224. * that contains the group and variable object ids as well. The native
  225. * representation is an argc/argv-like structure that contains the
  226. * ordered variables that define the instance. This is specified by
  227. * the MIB's INDEX clause. See RFC 1212 for information about the INDEX
  228. * clause.
  229. *
  230. *
  231. * Arguments:
  232. *
  233. * oid_spec Address of the object id instance specification
  234. * native_spec Address to return the ordered native instance
  235. * specification
  236. *
  237. * Return Codes:
  238. *
  239. * SUCCESS Conversion complete successfully
  240. * FAILURE Unable to convert object id into native format
  241. *
  242. */
  243. UINT
  244. HrStorageConvertInstance( IN ObjectIdentifier *oid_spec ,
  245. IN OUT InstanceName *native_spec )
  246. {
  247. //
  248. // Developer supplied code to convert instance identifer to native
  249. // specification of instance names goes here.
  250. //
  251. return SUCCESS ;
  252. } /* end of HrStorageConvertInstance() */
  253. /*
  254. * HrStorageFreeInstance
  255. *
  256. * This routine is used to free an ordered native representation of an
  257. * instance name.
  258. *
  259. * Arguments:
  260. *
  261. * instance Address to return the ordered native instance
  262. * specification
  263. *
  264. * Return Codes:
  265. *
  266. *
  267. */
  268. void
  269. HrStorageFreeInstance( IN OUT InstanceName *instance )
  270. {
  271. //
  272. // Developer supplied code to free native representation of instance name goes here.
  273. //
  274. } /* end of HrStorageFreeInstance() */