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.

358 lines
8.5 KiB

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