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.

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