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.

448 lines
11 KiB

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