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.

347 lines
8.1 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // acctmib.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Defines the class AcctServMIB.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 09/10/1998 Original version.
  16. // 05/26/1999 Fix bug calling GetAcctClientLeaf.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <ias.h>
  20. #include <snmputil.h>
  21. #include <stats.h>
  22. #include <acctmib.h>
  23. ///////////////////////////////////////////////////////////////////////////////
  24. //
  25. // FUNCTION
  26. //
  27. // GetAcctServerLeaf
  28. //
  29. // DESCRIPION
  30. //
  31. // Computes the value of a server leaf.
  32. //
  33. ///////////////////////////////////////////////////////////////////////////////
  34. AsnInteger32
  35. WINAPI
  36. GetAcctServerLeaf(
  37. IN UINT leaf,
  38. OUT AsnAny* value
  39. )
  40. {
  41. switch (leaf)
  42. {
  43. case 1:
  44. GetServerIdentity(value);
  45. break;
  46. case 2:
  47. GetServerUpTime(value);
  48. break;
  49. case 3:
  50. GetServerResetTime(value);
  51. break;
  52. case 4:
  53. GetServerConfigReset(value);
  54. break;
  55. case 5:
  56. GetTotalCounter(radiusAccServRequests, value);
  57. break;
  58. case 6:
  59. GetServerCounter(radiusAccServTotalInvalidRequests, value);
  60. break;
  61. case 7:
  62. GetTotalCounter(radiusAccServDupRequests, value);
  63. break;
  64. case 8:
  65. GetTotalCounter(radiusAccServResponses, value);
  66. break;
  67. case 9:
  68. GetTotalCounter(radiusAccServMalformedRequests, value);
  69. break;
  70. case 10:
  71. GetTotalCounter(radiusAccServBadAuthenticators, value);
  72. break;
  73. case 11:
  74. GetTotalCounter(radiusAccServPacketsDropped, value);
  75. break;
  76. case 12:
  77. GetTotalCounter(radiusAccServNoRecord, value);
  78. break;
  79. case 13:
  80. GetTotalCounter(radiusAccServUnknownType, value);
  81. break;
  82. case 14:
  83. return SNMP_ERRORSTATUS_NOACCESS;
  84. default:
  85. return SNMP_ERRORSTATUS_NOSUCHNAME;
  86. }
  87. return SNMP_ERRORSTATUS_NOERROR;
  88. }
  89. ///////////////////////////////////////////////////////////////////////////////
  90. //
  91. // FUNCTION
  92. //
  93. // GetAcctClientLeaf
  94. //
  95. // DESCRIPION
  96. //
  97. // Computes the value of a client leaf.
  98. //
  99. ///////////////////////////////////////////////////////////////////////////////
  100. AsnInteger32
  101. WINAPI
  102. GetAcctClientLeaf(
  103. UINT client,
  104. UINT leaf,
  105. AsnAny* value
  106. )
  107. {
  108. // SNMP indices start from 1, but C++ indices start from 0.
  109. --client;
  110. switch (leaf)
  111. {
  112. case 1:
  113. return SNMP_ERRORSTATUS_NOACCESS;
  114. case 2:
  115. GetClientAddress(client, value);
  116. break;
  117. case 3:
  118. GetClientIdentity(client, value);
  119. break;
  120. case 4:
  121. GetClientCounter(client, radiusAccServPacketsDropped, value);
  122. break;
  123. case 5:
  124. GetClientCounter(client, radiusAccServRequests, value);
  125. break;
  126. case 6:
  127. GetClientCounter(client, radiusAccServDupRequests, value);
  128. break;
  129. case 7:
  130. GetClientCounter(client, radiusAccServResponses, value);
  131. break;
  132. case 8:
  133. GetClientCounter(client, radiusAccServBadAuthenticators, value);
  134. break;
  135. case 9:
  136. GetClientCounter(client, radiusAccServMalformedRequests, value);
  137. break;
  138. case 10:
  139. GetClientCounter(client, radiusAccServNoRecord, value);
  140. break;
  141. case 11:
  142. GetClientCounter(client, radiusAccServUnknownType, value);
  143. break;
  144. default:
  145. return SNMP_ERRORSTATUS_NOSUCHNAME;
  146. }
  147. return SNMP_ERRORSTATUS_NOERROR;
  148. }
  149. //////////
  150. // OID definitions.
  151. //////////
  152. #define OID_radiusAccounting OID_radiusMIB,2
  153. #define OID_radiusAccServMIB OID_radiusAccounting,1
  154. #define OID_radiusAccServMIBObjects OID_radiusAccServMIB,1
  155. #define OID_radiusAccServ OID_radiusAccServMIBObjects,1
  156. #define OID_radiusAccClientTable OID_radiusAccServ,14
  157. namespace {
  158. //////////
  159. // ID arrays.
  160. //////////
  161. UINT IDS_serverNode[] = { OID_radiusAccServ };
  162. UINT IDS_firstServerLeaf[] = { OID_radiusAccServ, 1 };
  163. UINT IDS_lastServerLeaf[] = { OID_radiusAccServ, 13 };
  164. UINT IDS_clientNode[] = { OID_radiusAccClientTable };
  165. UINT IDS_firstClientLeaf[] = { OID_radiusAccClientTable, 1, 2 };
  166. UINT IDS_lastClientLeaf[] = { OID_radiusAccClientTable, 1, 11 };
  167. UINT IDS_configReset[] = { OID_radiusAccServ, 4 };
  168. //////////
  169. // AsnObjectIdentifiers.
  170. //////////
  171. AsnObjectIdentifier serverNode = DEFINE_OID(IDS_serverNode);
  172. AsnObjectIdentifier firstServerLeaf = DEFINE_OID(IDS_firstServerLeaf);
  173. AsnObjectIdentifier lastServerLeaf = DEFINE_OID(IDS_lastServerLeaf);
  174. AsnObjectIdentifier clientNode = DEFINE_OID(IDS_clientNode);
  175. AsnObjectIdentifier firstClientLeaf = DEFINE_OID(IDS_firstClientLeaf);
  176. AsnObjectIdentifier lastClientLeaf = DEFINE_OID(IDS_lastClientLeaf);
  177. AsnObjectIdentifier configReset = DEFINE_OID(IDS_configReset);
  178. //////////
  179. // Lengths of valid leaf OID's.
  180. //////////
  181. const UINT serverLength = DEFINE_SIZEOF(IDS_firstServerLeaf);
  182. const UINT clientLength = DEFINE_SIZEOF(IDS_firstClientLeaf);
  183. }
  184. bool AcctServMIB::canGetSet(const SnmpOid& name) throw ()
  185. {
  186. return name.isChildOf(serverNode);
  187. }
  188. bool AcctServMIB::canGetNext(const SnmpOid& name) throw ()
  189. {
  190. if (theStats->dwNumClients)
  191. {
  192. // Update the last client leaf. This is the highest OID we support.
  193. lastClientLeaf.ids[clientLength - 2] = theStats->dwNumClients;
  194. return name < lastClientLeaf;
  195. }
  196. return name < lastServerLeaf;
  197. }
  198. AsnInteger32 AcctServMIB::get(
  199. const SnmpOid& name,
  200. AsnAny* value
  201. )
  202. {
  203. // Is it a client leaf ?
  204. if (name.isChildOf(clientNode))
  205. {
  206. if (name.length() == clientLength)
  207. {
  208. return GetAcctClientLeaf(
  209. name.id(1),
  210. name.id(0),
  211. value
  212. );
  213. }
  214. }
  215. // Is it a server leaf ?
  216. else if (name.length() == serverLength)
  217. {
  218. return GetAcctServerLeaf(
  219. name.id(0),
  220. value
  221. );
  222. }
  223. return SNMP_ERRORSTATUS_NOSUCHNAME;
  224. }
  225. AsnInteger32 AcctServMIB::getNext(
  226. SnmpOid& name,
  227. AsnAny* value
  228. )
  229. {
  230. if (name < firstServerLeaf)
  231. {
  232. name = firstServerLeaf;
  233. return GetAcctServerLeaf(
  234. name.id(0),
  235. value
  236. );
  237. }
  238. if (name < lastServerLeaf)
  239. {
  240. // We're in the middle of the server leaves, so just advance
  241. // to the next one.
  242. name.resize(serverLength);
  243. ++name.id(0);
  244. return GetAcctServerLeaf(
  245. name.id(0),
  246. value
  247. );
  248. }
  249. if (name < firstClientLeaf)
  250. {
  251. name = firstClientLeaf;
  252. return GetAcctClientLeaf(
  253. name.id(1),
  254. name.id(0),
  255. value
  256. );
  257. }
  258. /////////
  259. // If we made it here, we're in the middle of the client leaves.
  260. /////////
  261. name.resize(clientLength);
  262. if (name.id(0) < 2)
  263. {
  264. name.id(0) = 2;
  265. }
  266. else if (++name.id(0) > 11)
  267. {
  268. name.id(0) = 2;
  269. // We wrapped around to the next client.
  270. ++name.id(1);
  271. }
  272. return GetAcctClientLeaf(
  273. name.id(1),
  274. name.id(0),
  275. value
  276. );
  277. }
  278. AsnInteger32 AcctServMIB::set(
  279. const SnmpOid& name,
  280. AsnAny* value
  281. )
  282. {
  283. if (name == configReset)
  284. {
  285. return SetServerConfigReset(value);
  286. }
  287. return SNMP_ERRORSTATUS_READONLY;
  288. }