Leaked source code of windows server 2003

497 lines
14 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. AsnObjectIdentifier tmpOid;
  97. tmpOid = VarBind->name; // keep a copy (structure copy)
  98. if (! SnmpUtilOidCpy( &VarBind->name, &MIB_OidPrefix ))
  99. {
  100. VarBind->name = tmpOid; // restore
  101. ErrStat = SNMP_ERRORSTATUS_RESOURCEUNAVAILABLE;
  102. goto Exit;
  103. }
  104. if (! SnmpUtilOidAppend( &VarBind->name, &MIB_DomOtherDomainPrefix ))
  105. {
  106. SnmpUtilOidFree(&VarBind->name);
  107. VarBind->name = tmpOid; // restore
  108. ErrStat = SNMP_ERRORSTATUS_RESOURCEUNAVAILABLE;
  109. goto Exit;
  110. }
  111. if (! SnmpUtilOidAppend( &VarBind->name, &FieldOid ))
  112. {
  113. SnmpUtilOidFree(&VarBind->name);
  114. VarBind->name = tmpOid; // restore
  115. ErrStat = SNMP_ERRORSTATUS_RESOURCEUNAVAILABLE;
  116. goto Exit;
  117. }
  118. if (! SnmpUtilOidAppend( &VarBind->name, &MIB_DomOtherDomainTable.Table[0].Oid ))
  119. {
  120. SnmpUtilOidFree(&VarBind->name);
  121. VarBind->name = tmpOid; // restore
  122. ErrStat = SNMP_ERRORSTATUS_RESOURCEUNAVAILABLE;
  123. goto Exit;
  124. }
  125. // free the original VarBind->name
  126. SnmpUtilOidFree(&tmpOid);
  127. }
  128. //
  129. // Let fall through on purpose
  130. //
  131. case MIB_ACTION_GET:
  132. ErrStat = MIB_odoms_get( VarBind );
  133. break;
  134. case MIB_ACTION_GETNEXT:
  135. // Fill the Other Domain Table with the info from server
  136. if ( SNMPAPI_ERROR == MIB_odoms_lmget() )
  137. {
  138. ErrStat = SNMP_ERRORSTATUS_GENERR;
  139. goto Exit;
  140. }
  141. // Determine which field
  142. Field = VarBind->name.ids[ODOM_FIELD_SUBID];
  143. // Lookup OID in table
  144. if (Field < ODOM_FIRST_FIELD)
  145. {
  146. Entry = 0; // will take the first entry into the table
  147. Field = ODOM_FIRST_FIELD; // and the first column of the table
  148. Found = MIB_TBL_POS_BEFORE;
  149. }
  150. else if (Field > ODOM_LAST_FIELD)
  151. Found = MIB_TBL_POS_END;
  152. else
  153. Found = MIB_odoms_match( &VarBind->name, &Entry );
  154. // Index not found, but could be more fields to base GET on
  155. if ((Found == MIB_TBL_POS_BEFORE && MIB_DomOtherDomainTable.Len == 0) ||
  156. Found == MIB_TBL_POS_END )
  157. {
  158. // Index not found in table, get next from field
  159. // Field ++;
  160. // Make sure not past last field
  161. // if ( Field > ODOM_LAST_FIELD )
  162. // {
  163. // Get next VAR in MIB
  164. ErrStat = (*MibPtr->MibNext->MibFunc)( MIB_ACTION_GETFIRST,
  165. MibPtr->MibNext,
  166. VarBind );
  167. break;
  168. // }
  169. }
  170. // Get next TABLE entry
  171. if ( Found == MIB_TBL_POS_FOUND )
  172. {
  173. Entry ++;
  174. if ( Entry > MIB_DomOtherDomainTable.Len-1 )
  175. {
  176. Entry = 0;
  177. Field ++;
  178. if ( Field > ODOM_LAST_FIELD )
  179. {
  180. // Get next VAR in MIB
  181. ErrStat = (*MibPtr->MibNext->MibFunc)( MIB_ACTION_GETFIRST,
  182. MibPtr->MibNext,
  183. VarBind );
  184. break;
  185. }
  186. }
  187. }
  188. //
  189. // Place correct OID in VarBind
  190. // Assuming the first field in the first record is the "start"
  191. {
  192. UINT temp_subs[1];
  193. AsnObjectIdentifier FieldOid;
  194. AsnObjectIdentifier tmpOid;
  195. temp_subs[0] = Field;
  196. FieldOid.idLength = 1;
  197. FieldOid.ids = temp_subs;
  198. tmpOid = VarBind->name; // keep a copy (structure copy)
  199. if (! SnmpUtilOidCpy( &VarBind->name, &MIB_OidPrefix ))
  200. {
  201. VarBind->name = tmpOid; // restore
  202. ErrStat = SNMP_ERRORSTATUS_RESOURCEUNAVAILABLE;
  203. goto Exit;
  204. }
  205. if (! SnmpUtilOidAppend( &VarBind->name, &MIB_DomOtherDomainPrefix ))
  206. {
  207. SnmpUtilOidFree(&VarBind->name);
  208. VarBind->name = tmpOid; // restore
  209. ErrStat = SNMP_ERRORSTATUS_RESOURCEUNAVAILABLE;
  210. goto Exit;
  211. }
  212. if (! SnmpUtilOidAppend( &VarBind->name, &FieldOid ))
  213. {
  214. SnmpUtilOidFree(&VarBind->name);
  215. VarBind->name = tmpOid; // restore
  216. ErrStat = SNMP_ERRORSTATUS_RESOURCEUNAVAILABLE;
  217. goto Exit;
  218. }
  219. if (! SnmpUtilOidAppend( &VarBind->name, &MIB_DomOtherDomainTable.Table[Entry].Oid ))
  220. {
  221. SnmpUtilOidFree(&VarBind->name);
  222. VarBind->name = tmpOid; // restore
  223. ErrStat = SNMP_ERRORSTATUS_RESOURCEUNAVAILABLE;
  224. goto Exit;
  225. }
  226. // free the original VarBind->name
  227. SnmpUtilOidFree(&tmpOid);
  228. }
  229. ErrStat = MIB_odoms_copyfromtable( Entry, Field, VarBind );
  230. break;
  231. case MIB_ACTION_SET:
  232. // Make sure OID is long enough
  233. if ( ODOM_FIELD_SUBID + 1 > VarBind->name.idLength )
  234. {
  235. ErrStat = SNMP_ERRORSTATUS_NOSUCHNAME;
  236. goto Exit;
  237. }
  238. // Get field number
  239. Field = VarBind->name.ids[ODOM_FIELD_SUBID];
  240. // If the field being set is not the NAME field, error
  241. if ( Field != ODOM_NAME_FIELD )
  242. {
  243. ErrStat = SNMP_ERRORSTATUS_NOSUCHNAME;
  244. goto Exit;
  245. }
  246. // Check for proper type before setting
  247. if ( ASN_RFC1213_DISPSTRING != VarBind->value.asnType )
  248. {
  249. ErrStat = SNMP_ERRORSTATUS_BADVALUE;
  250. goto Exit;
  251. }
  252. // Call LM set routine
  253. ErrStat = MIB_odoms_lmset( &VarBind->name, Field, &VarBind->value );
  254. break;
  255. default:
  256. ErrStat = SNMP_ERRORSTATUS_GENERR;
  257. }
  258. Exit:
  259. return ErrStat;
  260. } // MIB_odoms_func
  261. //
  262. // MIB_odoms_get
  263. // Retrieve Other Domain Table information.
  264. //
  265. // Notes:
  266. //
  267. // Return Codes:
  268. // None.
  269. //
  270. // Error Codes:
  271. // None.
  272. //
  273. UINT MIB_odoms_get(
  274. IN OUT RFC1157VarBind *VarBind
  275. )
  276. {
  277. UINT Entry;
  278. int Found;
  279. UINT ErrStat;
  280. if (VarBind->name.ids[ODOM_FIELD_SUBID] < ODOM_FIRST_FIELD ||
  281. VarBind->name.ids[ODOM_FIELD_SUBID] > ODOM_LAST_FIELD)
  282. {
  283. ErrStat = SNMP_ERRORSTATUS_NOSUCHNAME;
  284. goto Exit;
  285. }
  286. // Fill the Other Domain Table with the info from server
  287. if ( SNMPAPI_ERROR == MIB_odoms_lmget() )
  288. {
  289. ErrStat = SNMP_ERRORSTATUS_GENERR;
  290. goto Exit;
  291. }
  292. Found = MIB_odoms_match( &VarBind->name, &Entry );
  293. // Look for a complete OID match
  294. if ( Found != MIB_TBL_POS_FOUND )
  295. {
  296. ErrStat = SNMP_ERRORSTATUS_NOSUCHNAME;
  297. goto Exit;
  298. }
  299. // Copy data from table
  300. ErrStat = MIB_odoms_copyfromtable( Entry,
  301. VarBind->name.ids[ODOM_FIELD_SUBID],
  302. VarBind );
  303. Exit:
  304. return ErrStat;
  305. } // MIB_odoms_get
  306. //
  307. // MIB_odoms_match
  308. // Match the target OID with a location in the Other Domain Table
  309. //
  310. // Notes:
  311. //
  312. // Return Codes:
  313. // None.
  314. //
  315. // Error Codes:
  316. // None
  317. //
  318. int MIB_odoms_match(
  319. IN AsnObjectIdentifier *Oid,
  320. OUT UINT *Pos
  321. )
  322. {
  323. AsnObjectIdentifier TempOid;
  324. int nResult;
  325. // Remove prefix including field reference
  326. TempOid.idLength = Oid->idLength - MIB_OidPrefix.idLength -
  327. MIB_DomOtherDomainPrefix.idLength - 1;
  328. TempOid.ids = &Oid->ids[MIB_OidPrefix.idLength+MIB_DomOtherDomainPrefix.idLength+1];
  329. *Pos = 0;
  330. while ( *Pos < MIB_DomOtherDomainTable.Len )
  331. {
  332. nResult = SnmpUtilOidCmp( &TempOid, &MIB_DomOtherDomainTable.Table[*Pos].Oid );
  333. if ( !nResult )
  334. {
  335. nResult = MIB_TBL_POS_FOUND;
  336. goto Exit;
  337. }
  338. if ( nResult < 0 )
  339. {
  340. nResult = MIB_TBL_POS_BEFORE;
  341. goto Exit;
  342. }
  343. (*Pos)++;
  344. }
  345. nResult = MIB_TBL_POS_END;
  346. Exit:
  347. return nResult;
  348. }
  349. //
  350. // MIB_odoms_copyfromtable
  351. // Copy requested data from table structure into Var Bind.
  352. //
  353. // Notes:
  354. //
  355. // Return Codes:
  356. // None.
  357. //
  358. // Error Codes:
  359. // None.
  360. //
  361. UINT MIB_odoms_copyfromtable(
  362. IN UINT Entry,
  363. IN UINT Field,
  364. OUT RFC1157VarBind *VarBind
  365. )
  366. {
  367. UINT ErrStat;
  368. // Get the requested field and save in var bind
  369. switch( Field )
  370. {
  371. case ODOM_NAME_FIELD:
  372. // Alloc space for string
  373. VarBind->value.asnValue.string.stream = SnmpUtilMemAlloc( sizeof(char)
  374. * MIB_DomOtherDomainTable.Table[Entry].domOtherName.length );
  375. if ( VarBind->value.asnValue.string.stream == NULL )
  376. {
  377. ErrStat = SNMP_ERRORSTATUS_GENERR;
  378. goto Exit;
  379. }
  380. // Copy string into return position
  381. memcpy( VarBind->value.asnValue.string.stream,
  382. MIB_DomOtherDomainTable.Table[Entry].domOtherName.stream,
  383. MIB_DomOtherDomainTable.Table[Entry].domOtherName.length );
  384. // Set string length
  385. VarBind->value.asnValue.string.length =
  386. MIB_DomOtherDomainTable.Table[Entry].domOtherName.length;
  387. VarBind->value.asnValue.string.dynamic = TRUE;
  388. // Set type of var bind
  389. VarBind->value.asnType = ASN_RFC1213_DISPSTRING;
  390. break;
  391. default:
  392. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: Internal Error Other Domain Table\n" ));
  393. ErrStat = SNMP_ERRORSTATUS_GENERR;
  394. goto Exit;
  395. }
  396. ErrStat = SNMP_ERRORSTATUS_NOERROR;
  397. Exit:
  398. return ErrStat;
  399. } // MIB_odoms_copyfromtable
  400. //-------------------------------- END --------------------------------------