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.

420 lines
11 KiB

  1. /*++
  2. Copyright (c) 1992-1996 Microsoft Corporation
  3. Module Name:
  4. srvr_tbl.c
  5. Abstract:
  6. Routines to perform operations on the Domain Server Table.
  7. Environment:
  8. User Mode - Win32
  9. Revision History:
  10. 10-May-1996 DonRyan
  11. Removed banner from Technology Dynamics, Inc.
  12. --*/
  13. //--------------------------- WINDOWS DEPENDENCIES --------------------------
  14. //--------------------------- STANDARD DEPENDENCIES -- #include<xxxxx.h> ----
  15. #include <stdio.h>
  16. #include <memory.h>
  17. //--------------------------- MODULE DEPENDENCIES -- #include"xxxxx.h" ------
  18. #include <snmp.h>
  19. #include <snmputil.h>
  20. #include "mibfuncs.h"
  21. //--------------------------- SELF-DEPENDENCY -- ONE #include"module.h" -----
  22. #include "srvr_tbl.h"
  23. //--------------------------- PUBLIC VARIABLES --(same as in module.h file)--
  24. // Prefix to the Domain Server table
  25. static UINT svsondSubids[] = { 4, 6, 1 };
  26. static AsnObjectIdentifier MIB_DomServerPrefix = { 3, svsondSubids };
  27. DOM_SERVER_TABLE MIB_DomServerTable = { 0, NULL };
  28. //--------------------------- PRIVATE CONSTANTS -----------------------------
  29. #define SRVR_FIELD_SUBID (MIB_DomServerPrefix.idLength+MIB_OidPrefix.idLength)
  30. #define SRVR_FIRST_FIELD SRVR_NAME_FIELD
  31. #define SRVR_LAST_FIELD SRVR_NAME_FIELD
  32. //--------------------------- PRIVATE STRUCTS -------------------------------
  33. //--------------------------- PRIVATE VARIABLES -----------------------------
  34. //--------------------------- PRIVATE PROTOTYPES ----------------------------
  35. UINT MIB_svsond_get(
  36. IN OUT RFC1157VarBind *VarBind
  37. );
  38. int MIB_svsond_match(
  39. IN AsnObjectIdentifier *Oid,
  40. OUT UINT *Pos
  41. );
  42. UINT MIB_svsond_copyfromtable(
  43. IN UINT Entry,
  44. IN UINT Field,
  45. OUT RFC1157VarBind *VarBind
  46. );
  47. //--------------------------- PRIVATE PROCEDURES ----------------------------
  48. //--------------------------- PUBLIC PROCEDURES -----------------------------
  49. //
  50. // MIB_svsond_func
  51. // High level routine for handling operations on the Domain Server table
  52. //
  53. // Notes:
  54. //
  55. // Return Codes:
  56. // SNMPAPI_NOERROR
  57. // SNMPAPI_ERROR
  58. //
  59. // Error Codes:
  60. // None.
  61. //
  62. UINT MIB_svsond_func(
  63. IN UINT Action,
  64. IN MIB_ENTRY *MibPtr,
  65. IN OUT RFC1157VarBind *VarBind
  66. )
  67. {
  68. int Found;
  69. UINT Entry;
  70. UINT Field;
  71. UINT ErrStat;
  72. switch ( Action )
  73. {
  74. case MIB_ACTION_GETFIRST:
  75. // Fill the Domain Server table with the info from server
  76. if ( SNMPAPI_ERROR == MIB_svsond_lmget() )
  77. {
  78. ErrStat = SNMP_ERRORSTATUS_GENERR;
  79. goto Exit;
  80. }
  81. // If no elements in table, then return next MIB var, if one
  82. if ( MIB_DomServerTable.Len == 0 )
  83. {
  84. if ( MibPtr->MibNext == NULL )
  85. {
  86. ErrStat = SNMP_ERRORSTATUS_NOSUCHNAME;
  87. goto Exit;
  88. }
  89. // Do get first on the next MIB var
  90. ErrStat = (*MibPtr->MibNext->MibFunc)( Action, MibPtr->MibNext,
  91. VarBind );
  92. break;
  93. }
  94. //
  95. // Place correct OID in VarBind
  96. // Assuming the first field in the first record is the "start"
  97. {
  98. UINT temp_subs[] = { SRVR_FIRST_FIELD };
  99. AsnObjectIdentifier FieldOid = { 1, temp_subs };
  100. SnmpUtilOidFree( &VarBind->name );
  101. SnmpUtilOidCpy( &VarBind->name, &MIB_OidPrefix );
  102. SnmpUtilOidAppend( &VarBind->name, &MIB_DomServerPrefix );
  103. SnmpUtilOidAppend( &VarBind->name, &FieldOid );
  104. SnmpUtilOidAppend( &VarBind->name, &MIB_DomServerTable.Table[0].Oid );
  105. }
  106. //
  107. // Let fall through on purpose
  108. //
  109. case MIB_ACTION_GET:
  110. ErrStat = MIB_svsond_get( VarBind );
  111. break;
  112. case MIB_ACTION_GETNEXT:
  113. // Fill the Domain Server table with the info from server
  114. if ( SNMPAPI_ERROR == MIB_svsond_lmget() )
  115. {
  116. ErrStat = SNMP_ERRORSTATUS_GENERR;
  117. goto Exit;
  118. }
  119. // Determine which field
  120. Field = VarBind->name.ids[SRVR_FIELD_SUBID];
  121. // Lookup OID in table
  122. if (Field < SRVR_FIRST_FIELD)
  123. {
  124. Entry = 0; // will take the first entry into the table
  125. Field = SRVR_FIRST_FIELD; // and the first column of the table
  126. Found = MIB_TBL_POS_BEFORE;
  127. }
  128. else if (Field > SRVR_LAST_FIELD)
  129. Found = MIB_TBL_POS_END;
  130. else
  131. Found = MIB_svsond_match( &VarBind->name, &Entry );
  132. // Index not found, but could be more fields to base GET on
  133. if ((Found == MIB_TBL_POS_BEFORE && MIB_DomServerTable.Len == 0) ||
  134. Found == MIB_TBL_POS_END )
  135. {
  136. // Index not found in table, get next from field
  137. // Field ++;
  138. // Make sure not past last field
  139. // if ( Field > SRVR_LAST_FIELD )
  140. // {
  141. if ( MibPtr->MibNext == NULL )
  142. {
  143. ErrStat = SNMP_ERRORSTATUS_NOSUCHNAME;
  144. goto Exit;
  145. }
  146. // Get next VAR in MIB
  147. ErrStat = (*MibPtr->MibNext->MibFunc)( MIB_ACTION_GETFIRST,
  148. MibPtr->MibNext,
  149. VarBind );
  150. break;
  151. // }
  152. }
  153. // Get next TABLE entry
  154. if ( Found == MIB_TBL_POS_FOUND )
  155. {
  156. Entry ++;
  157. if ( Entry > MIB_DomServerTable.Len-1 )
  158. {
  159. Entry = 0;
  160. Field ++;
  161. if ( Field > SRVR_LAST_FIELD )
  162. {
  163. if ( MibPtr->MibNext == NULL )
  164. {
  165. ErrStat = SNMP_ERRORSTATUS_NOSUCHNAME;
  166. goto Exit;
  167. }
  168. // Get next VAR in MIB
  169. ErrStat = (*MibPtr->MibNext->MibFunc)( MIB_ACTION_GETFIRST,
  170. MibPtr->MibNext,
  171. VarBind );
  172. break;
  173. }
  174. }
  175. }
  176. //
  177. // Place correct OID in VarBind
  178. // Assuming the first field in the first record is the "start"
  179. {
  180. UINT temp_subs[1];
  181. AsnObjectIdentifier FieldOid;
  182. temp_subs[0] = Field;
  183. FieldOid.idLength = 1;
  184. FieldOid.ids = temp_subs;
  185. SnmpUtilOidFree( &VarBind->name );
  186. SnmpUtilOidCpy( &VarBind->name, &MIB_OidPrefix );
  187. SnmpUtilOidAppend( &VarBind->name, &MIB_DomServerPrefix );
  188. SnmpUtilOidAppend( &VarBind->name, &FieldOid );
  189. SnmpUtilOidAppend( &VarBind->name, &MIB_DomServerTable.Table[Entry].Oid );
  190. }
  191. ErrStat = MIB_svsond_copyfromtable( Entry, Field, VarBind );
  192. break;
  193. case MIB_ACTION_SET:
  194. ErrStat = SNMP_ERRORSTATUS_NOSUCHNAME;
  195. break;
  196. default:
  197. ErrStat = SNMP_ERRORSTATUS_GENERR;
  198. }
  199. Exit:
  200. return ErrStat;
  201. } // MIB_svsond_func
  202. //
  203. // MIB_svsond_get
  204. // Retrieve Domain Server table information.
  205. //
  206. // Notes:
  207. //
  208. // Return Codes:
  209. //
  210. // Error Codes:
  211. // None.
  212. //
  213. UINT MIB_svsond_get(
  214. IN OUT RFC1157VarBind *VarBind
  215. )
  216. {
  217. UINT Entry;
  218. int Found;
  219. UINT ErrStat;
  220. if (VarBind->name.ids[SRVR_FIELD_SUBID] < SRVR_FIRST_FIELD ||
  221. VarBind->name.ids[SRVR_FIELD_SUBID] > SRVR_LAST_FIELD)
  222. {
  223. ErrStat = SNMP_ERRORSTATUS_NOSUCHNAME;
  224. goto Exit;
  225. }
  226. // Fill the Domain Server table with the info from server
  227. if ( SNMPAPI_ERROR == MIB_svsond_lmget() )
  228. {
  229. ErrStat = SNMP_ERRORSTATUS_GENERR;
  230. goto Exit;
  231. }
  232. Found = MIB_svsond_match( &VarBind->name, &Entry );
  233. // Look for a complete OID match
  234. if ( Found != MIB_TBL_POS_FOUND )
  235. {
  236. ErrStat = SNMP_ERRORSTATUS_NOSUCHNAME;
  237. goto Exit;
  238. }
  239. // Copy data from table
  240. ErrStat = MIB_svsond_copyfromtable( Entry, VarBind->name.ids[SRVR_FIELD_SUBID],
  241. VarBind );
  242. Exit:
  243. return ErrStat;
  244. } // MIB_svsond_get
  245. //
  246. // MIB_svsond_match
  247. // Match the target OID with a location in the Domain Server table
  248. //
  249. // Notes:
  250. //
  251. // Return Codes:
  252. //
  253. // Error Codes:
  254. // None
  255. //
  256. int MIB_svsond_match(
  257. IN AsnObjectIdentifier *Oid,
  258. OUT UINT *Pos
  259. )
  260. {
  261. AsnObjectIdentifier TempOid;
  262. int nResult;
  263. // Remove prefix including field reference
  264. TempOid.idLength = Oid->idLength - MIB_OidPrefix.idLength -
  265. MIB_DomServerPrefix.idLength - 1;
  266. TempOid.ids = &Oid->ids[MIB_OidPrefix.idLength+MIB_DomServerPrefix.idLength+1];
  267. *Pos = 0;
  268. while ( *Pos < MIB_DomServerTable.Len )
  269. {
  270. nResult = SnmpUtilOidCmp( &TempOid, &MIB_DomServerTable.Table[*Pos].Oid );
  271. if ( !nResult )
  272. {
  273. nResult = MIB_TBL_POS_FOUND;
  274. goto Exit;
  275. }
  276. if ( nResult < 0 )
  277. {
  278. nResult = MIB_TBL_POS_BEFORE;
  279. goto Exit;
  280. }
  281. (*Pos)++;
  282. }
  283. nResult = MIB_TBL_POS_END;
  284. Exit:
  285. return nResult;
  286. }
  287. UINT MIB_svsond_copyfromtable(
  288. IN UINT Entry,
  289. IN UINT Field,
  290. OUT RFC1157VarBind *VarBind
  291. )
  292. {
  293. UINT ErrStat;
  294. // Get the requested field and save in var bind
  295. switch( Field )
  296. {
  297. case SRVR_NAME_FIELD:
  298. // Alloc space for string
  299. VarBind->value.asnValue.string.stream = SnmpUtilMemAlloc( sizeof(char)
  300. * MIB_DomServerTable.Table[Entry].domServerName.length );
  301. if ( VarBind->value.asnValue.string.stream == NULL )
  302. {
  303. ErrStat = SNMP_ERRORSTATUS_GENERR;
  304. goto Exit;
  305. }
  306. // Copy string into return position
  307. memcpy( VarBind->value.asnValue.string.stream,
  308. MIB_DomServerTable.Table[Entry].domServerName.stream,
  309. MIB_DomServerTable.Table[Entry].domServerName.length );
  310. // Set string length
  311. VarBind->value.asnValue.string.length =
  312. MIB_DomServerTable.Table[Entry].domServerName.length;
  313. VarBind->value.asnValue.string.dynamic = TRUE;
  314. // Set type of var bind
  315. VarBind->value.asnType = ASN_RFC1213_DISPSTRING;
  316. break;
  317. default:
  318. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: Internal Error Domain Server Table\n" ));
  319. ErrStat = SNMP_ERRORSTATUS_GENERR;
  320. goto Exit;
  321. }
  322. ErrStat = SNMP_ERRORSTATUS_NOERROR;
  323. Exit:
  324. return ErrStat;
  325. } // MIB_svsond_copyfromtable
  326. //-------------------------------- END --------------------------------------