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.

446 lines
11 KiB

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