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.

461 lines
12 KiB

  1. /*++
  2. Copyright (c) 1992-1996 Microsoft Corporation
  3. Module Name:
  4. uses_tbl.c
  5. Abstract:
  6. Routines to perform operations on the Workstation Uses 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 "uses_tbl.h"
  23. //--------------------------- PUBLIC VARIABLES --(same as in module.h file)--
  24. // Prefix to the Uses table
  25. static UINT usesSubids[] = { 3, 8, 1 };
  26. static AsnObjectIdentifier MIB_UsesPrefix = { 3, usesSubids };
  27. WKSTA_USES_TABLE MIB_WkstaUsesTable = { 0, NULL };
  28. //--------------------------- PRIVATE CONSTANTS -----------------------------
  29. #define USES_FIELD_SUBID (MIB_UsesPrefix.idLength+MIB_OidPrefix.idLength)
  30. #define USES_FIRST_FIELD USES_LOCAL_FIELD
  31. #define USES_LAST_FIELD USES_STATUS_FIELD
  32. //--------------------------- PRIVATE STRUCTS -------------------------------
  33. //--------------------------- PRIVATE VARIABLES -----------------------------
  34. //--------------------------- PRIVATE PROTOTYPES ----------------------------
  35. UINT MIB_wsuses_get(
  36. IN OUT RFC1157VarBind *VarBind
  37. );
  38. int MIB_wsuses_match(
  39. IN AsnObjectIdentifier *Oid,
  40. OUT UINT *Pos,
  41. IN BOOL Next
  42. );
  43. UINT MIB_wsuses_copyfromtable(
  44. IN UINT Entry,
  45. IN UINT Field,
  46. OUT RFC1157VarBind *VarBind
  47. );
  48. //--------------------------- PRIVATE PROCEDURES ----------------------------
  49. //--------------------------- PUBLIC PROCEDURES -----------------------------
  50. //
  51. // MIB_wsuses_func
  52. // High level routine for handling operations on the uses table
  53. //
  54. // Notes:
  55. //
  56. // Return Codes:
  57. // None.
  58. //
  59. // Error Codes:
  60. // None.
  61. //
  62. UINT MIB_wsuses_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 Uses table with the info from server
  76. if ( SNMPAPI_ERROR == MIB_wsuses_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_WkstaUsesTable.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[] = { USES_FIRST_FIELD };
  99. AsnObjectIdentifier FieldOid = { 1, temp_subs };
  100. SnmpUtilOidFree( &VarBind->name );
  101. SnmpUtilOidCpy( &VarBind->name, &MIB_OidPrefix );
  102. SnmpUtilOidAppend( &VarBind->name, &MIB_UsesPrefix );
  103. SnmpUtilOidAppend( &VarBind->name, &FieldOid );
  104. SnmpUtilOidAppend( &VarBind->name, &MIB_WkstaUsesTable.Table[0].Oid );
  105. }
  106. //
  107. // Let fall through on purpose
  108. //
  109. case MIB_ACTION_GET:
  110. ErrStat = MIB_wsuses_get( VarBind );
  111. break;
  112. case MIB_ACTION_GETNEXT:
  113. // Fill the Uses table with the info from server
  114. if ( SNMPAPI_ERROR == MIB_wsuses_lmget() )
  115. {
  116. ErrStat = SNMP_ERRORSTATUS_GENERR;
  117. goto Exit;
  118. }
  119. // Determine which field
  120. Field = VarBind->name.ids[USES_FIELD_SUBID];
  121. // Lookup OID in table
  122. if (Field < USES_FIRST_FIELD)
  123. {
  124. Entry = 0; // will take the first entry into the table
  125. Field = USES_FIRST_FIELD; // and the first column of the table
  126. Found = MIB_TBL_POS_BEFORE;
  127. }
  128. else if (Field > USES_LAST_FIELD)
  129. Found = MIB_TBL_POS_END;
  130. else
  131. Found = MIB_wsuses_match( &VarBind->name, &Entry, TRUE );
  132. // Index not found, but could be more fields to base GET on
  133. if ((Found == MIB_TBL_POS_BEFORE && MIB_WkstaUsesTable.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 > USES_LAST_FIELD )
  140. // {
  141. // Get next VAR in MIB
  142. ErrStat = (*MibPtr->MibNext->MibFunc)( MIB_ACTION_GETFIRST,
  143. MibPtr->MibNext,
  144. VarBind );
  145. break;
  146. // }
  147. }
  148. // Get next TABLE entry
  149. if ( Found == MIB_TBL_POS_FOUND )
  150. {
  151. Entry ++;
  152. if ( Entry > MIB_WkstaUsesTable.Len-1 )
  153. {
  154. Entry = 0;
  155. Field ++;
  156. if ( Field > USES_LAST_FIELD )
  157. {
  158. // Get next VAR in MIB
  159. ErrStat = (*MibPtr->MibNext->MibFunc)( MIB_ACTION_GETFIRST,
  160. MibPtr->MibNext,
  161. VarBind );
  162. break;
  163. }
  164. }
  165. }
  166. //
  167. // Place correct OID in VarBind
  168. // Assuming the first field in the first record is the "start"
  169. {
  170. UINT temp_subs[1];
  171. AsnObjectIdentifier FieldOid;
  172. temp_subs[0] = Field;
  173. FieldOid.idLength = 1;
  174. FieldOid.ids = temp_subs;
  175. SnmpUtilOidFree( &VarBind->name );
  176. SnmpUtilOidCpy( &VarBind->name, &MIB_OidPrefix );
  177. SnmpUtilOidAppend( &VarBind->name, &MIB_UsesPrefix );
  178. SnmpUtilOidAppend( &VarBind->name, &FieldOid );
  179. SnmpUtilOidAppend( &VarBind->name, &MIB_WkstaUsesTable.Table[Entry].Oid );
  180. }
  181. ErrStat = MIB_wsuses_copyfromtable( Entry, Field, VarBind );
  182. break;
  183. case MIB_ACTION_SET:
  184. ErrStat = SNMP_ERRORSTATUS_NOSUCHNAME;
  185. break;
  186. default:
  187. ErrStat = SNMP_ERRORSTATUS_GENERR;
  188. }
  189. Exit:
  190. return ErrStat;
  191. } // MIB_wsuses_func
  192. //
  193. // MIB_wsuses_get
  194. // Retrieve Uses table information.
  195. //
  196. // Notes:
  197. //
  198. // Return Codes:
  199. // None.
  200. //
  201. // Error Codes:
  202. // None.
  203. //
  204. UINT MIB_wsuses_get(
  205. IN OUT RFC1157VarBind *VarBind
  206. )
  207. {
  208. UINT Entry;
  209. int Found;
  210. UINT ErrStat;
  211. if (VarBind->name.ids[USES_FIELD_SUBID] < USES_FIRST_FIELD ||
  212. VarBind->name.ids[USES_FIELD_SUBID] > USES_LAST_FIELD)
  213. {
  214. ErrStat = SNMP_ERRORSTATUS_NOSUCHNAME;
  215. goto Exit;
  216. }
  217. // Fill the Uses table with the info from server
  218. if ( SNMPAPI_ERROR == MIB_wsuses_lmget() )
  219. {
  220. ErrStat = SNMP_ERRORSTATUS_GENERR;
  221. goto Exit;
  222. }
  223. Found = MIB_wsuses_match( &VarBind->name, &Entry, FALSE );
  224. // Look for a complete OID match
  225. if ( Found != MIB_TBL_POS_FOUND )
  226. {
  227. ErrStat = SNMP_ERRORSTATUS_NOSUCHNAME;
  228. goto Exit;
  229. }
  230. // Copy data from table
  231. ErrStat = MIB_wsuses_copyfromtable( Entry, VarBind->name.ids[USES_FIELD_SUBID],
  232. VarBind );
  233. Exit:
  234. return ErrStat;
  235. } // MIB_wsuses_get
  236. //
  237. // MIB_wsuses_match
  238. // Match the target OID with a location in the Uses table
  239. //
  240. // Notes:
  241. //
  242. // Return Codes:
  243. // None.
  244. //
  245. // Error Codes:
  246. // None
  247. //
  248. int MIB_wsuses_match(
  249. IN AsnObjectIdentifier *Oid,
  250. OUT UINT *Pos,
  251. IN BOOL Next
  252. )
  253. {
  254. AsnObjectIdentifier TempOid;
  255. int nResult;
  256. // Remove prefix including field reference
  257. TempOid.idLength = Oid->idLength - MIB_OidPrefix.idLength -
  258. MIB_UsesPrefix.idLength - 1;
  259. TempOid.ids = &Oid->ids[MIB_OidPrefix.idLength+MIB_UsesPrefix.idLength+1];
  260. *Pos = 0;
  261. while ( *Pos < MIB_WkstaUsesTable.Len )
  262. {
  263. nResult = SnmpUtilOidCmp( &TempOid, &MIB_WkstaUsesTable.Table[*Pos].Oid );
  264. if ( !nResult )
  265. {
  266. nResult = MIB_TBL_POS_FOUND;
  267. if (Next) {
  268. while ( ( (*Pos) + 1 < MIB_WkstaUsesTable.Len ) &&
  269. !SnmpUtilOidCmp( &TempOid, &MIB_WkstaUsesTable.Table[(*Pos)+1].Oid)) {
  270. (*Pos)++;
  271. }
  272. }
  273. goto Exit;
  274. }
  275. if ( nResult < 0 )
  276. {
  277. nResult = MIB_TBL_POS_BEFORE;
  278. goto Exit;
  279. }
  280. (*Pos)++;
  281. }
  282. nResult = MIB_TBL_POS_END;
  283. Exit:
  284. return nResult;
  285. } // MIB_wsuses_match
  286. //
  287. // MIB_wsuses_copyfromtable
  288. // Copy requested data from table structure into Var Bind.
  289. //
  290. // Notes:
  291. //
  292. // Return Codes:
  293. // None.
  294. //
  295. // Error Codes:
  296. // None.
  297. //
  298. UINT MIB_wsuses_copyfromtable(
  299. IN UINT Entry,
  300. IN UINT Field,
  301. OUT RFC1157VarBind *VarBind
  302. )
  303. {
  304. UINT ErrStat;
  305. // Get the requested field and save in var bind
  306. switch( Field )
  307. {
  308. case USES_LOCAL_FIELD:
  309. // Alloc space for string
  310. VarBind->value.asnValue.string.stream = SnmpUtilMemAlloc( sizeof(char)
  311. * MIB_WkstaUsesTable.Table[Entry].useLocalName.length );
  312. if ( VarBind->value.asnValue.string.stream == NULL )
  313. {
  314. ErrStat = SNMP_ERRORSTATUS_GENERR;
  315. goto Exit;
  316. }
  317. // Copy string into return position
  318. memcpy( VarBind->value.asnValue.string.stream,
  319. MIB_WkstaUsesTable.Table[Entry].useLocalName.stream,
  320. MIB_WkstaUsesTable.Table[Entry].useLocalName.length );
  321. // Set string length
  322. VarBind->value.asnValue.string.length =
  323. MIB_WkstaUsesTable.Table[Entry].useLocalName.length;
  324. VarBind->value.asnValue.string.dynamic = TRUE;
  325. // Set type of var bind
  326. VarBind->value.asnType = ASN_RFC1213_DISPSTRING;
  327. break;
  328. case USES_REMOTE_FIELD:
  329. // Alloc space for string
  330. VarBind->value.asnValue.string.stream = SnmpUtilMemAlloc( sizeof(char)
  331. * MIB_WkstaUsesTable.Table[Entry].useRemote.length );
  332. if ( VarBind->value.asnValue.string.stream == NULL )
  333. {
  334. ErrStat = SNMP_ERRORSTATUS_GENERR;
  335. goto Exit;
  336. }
  337. // Copy string into return position
  338. memcpy( VarBind->value.asnValue.string.stream,
  339. MIB_WkstaUsesTable.Table[Entry].useRemote.stream,
  340. MIB_WkstaUsesTable.Table[Entry].useRemote.length );
  341. // Set string length
  342. VarBind->value.asnValue.string.length =
  343. MIB_WkstaUsesTable.Table[Entry].useRemote.length;
  344. VarBind->value.asnValue.string.dynamic = TRUE;
  345. // Set type of var bind
  346. VarBind->value.asnType = ASN_RFC1213_DISPSTRING;
  347. break;
  348. case USES_STATUS_FIELD:
  349. VarBind->value.asnValue.number =
  350. MIB_WkstaUsesTable.Table[Entry].useStatus;
  351. VarBind->value.asnType = ASN_INTEGER;
  352. break;
  353. default:
  354. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: Internal Error WorkstationUses Table\n" ));
  355. ErrStat = SNMP_ERRORSTATUS_GENERR;
  356. goto Exit;
  357. }
  358. ErrStat = SNMP_ERRORSTATUS_NOERROR;
  359. Exit:
  360. return ErrStat;
  361. } // MIB_wsuses_copyfromtable
  362. //-------------------------------- END --------------------------------------