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.

291 lines
6.9 KiB

  1. /*++
  2. Copyright (c) 1992-1996 Microsoft Corporation
  3. Module Name:
  4. dlog_lm.c
  5. Abstract:
  6. This file contains MIB_dlog_lmget, which actually call lan manager
  7. for the dloge table, copies it into structures, and sorts it to
  8. return ready to use by the higher level functions.
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. 10-May-1996 DonRyan
  13. Removed banner from Technology Dynamics, Inc.
  14. --*/
  15. //--------------------------- WINDOWS DEPENDENCIES --------------------------
  16. //--------------------------- STANDARD DEPENDENCIES -- #include<xxxxx.h> ----
  17. #ifdef WIN32
  18. #include <windows.h>
  19. #include <lm.h>
  20. #endif
  21. #include <string.h>
  22. #include <search.h>
  23. #include <stdlib.h>
  24. //--------------------------- MODULE DEPENDENCIES -- #include"xxxxx.h" ------
  25. #include "mib.h"
  26. #include "mibfuncs.h"
  27. #include "dlog_tbl.h"
  28. //--------------------------- SELF-DEPENDENCY -- ONE #include"module.h" -----
  29. //--------------------------- PUBLIC VARIABLES --(same as in module.h file)--
  30. //--------------------------- PRIVATE CONSTANTS -----------------------------
  31. //--------------------------- PRIVATE STRUCTS -------------------------------
  32. //--------------------------- PRIVATE VARIABLES -----------------------------
  33. //--------------------------- PRIVATE PROTOTYPES ----------------------------
  34. int dlog_entry_cmp(
  35. IN DOM_LOGON_ENTRY *A,
  36. IN DOM_LOGON_ENTRY *B
  37. ) ;
  38. void build_dlog_entry_oids( );
  39. //--------------------------- PRIVATE PROCEDURES ----------------------------
  40. //--------------------------- PUBLIC PROCEDURES -----------------------------
  41. //
  42. // MIB_dlog_lmget
  43. // Retrieve dlogion table information from Lan Manager.
  44. // If not cached, sort it and then
  45. // cache it.
  46. //
  47. // Notes:
  48. //
  49. // Return Codes:
  50. // SNMPAPI_NOERROR
  51. // SNMPAPI_ERROR
  52. //
  53. // Error Codes:
  54. // None.
  55. //
  56. SNMPAPI MIB_dlogons_lmget(
  57. )
  58. {
  59. SNMPAPI nResult = SNMPAPI_NOERROR;
  60. #if 0
  61. DWORD entriesread;
  62. DWORD totalentries;
  63. LPBYTE bufptr;
  64. unsigned lmCode;
  65. unsigned i;
  66. SHARE_INFO_2 *DataTable;
  67. DOM_LOGON_ENTRY *MIB_DomLogonTableElement ;
  68. int First_of_this_block;
  69. DWORD resumehandle=0;
  70. //
  71. //
  72. // If cached, return piece of info.
  73. //
  74. //
  75. //
  76. //
  77. // Do network call to gather information and put it in a nice array
  78. //
  79. //
  80. // free the old table LOOK OUT!!
  81. // init the length
  82. MIB_DomLogonTable.Len = 0;
  83. First_of_this_block = 0;
  84. do { // as long as there is more data to process
  85. lmCode =
  86. NetShareEnum(NULL, // local server
  87. 2, // level 2,
  88. &bufptr, // data structure to return
  89. MAX_PREFERRED_LENGTH,
  90. &entriesread,
  91. &totalentries,
  92. &resumehandle // resume handle
  93. );
  94. //
  95. // Filter out all the Admin shares (name ending with $).
  96. //
  97. AdminFilter(2,&entriesread,bufptr);
  98. DataTable = (SHARE_INFO_2 *) bufptr ;
  99. if((NERR_Success == lmCode) || (ERROR_MORE_DATA == lmCode))
  100. { // valid so process it, otherwise error
  101. if(0 == MIB_DomLogonTable.Len) { // 1st time, alloc the whole table
  102. // alloc the table space
  103. MIB_DomLogonTable.Table = SnmpUtilMemAlloc(totalentries *
  104. sizeof(DOM_LOGON_ENTRY) );
  105. }
  106. MIB_DomLogonTableElement = MIB_DomLogonTable.Table + First_of_this_block ;
  107. for(i=0; i<entriesread; i++) { // once for each entry in the buffer
  108. // increment the entry number
  109. MIB_DomLogonTable.Len ++;
  110. // Stuff the data into each item in the table
  111. // dloge name
  112. MIB_DomLogonTableElement->svShareName.stream = SnmpUtilMemAlloc (
  113. strlen( DataTable->shi2_netname ) ) ;
  114. MIB_DomLogonTableElement->svShareName.length =
  115. strlen( DataTable->shi2_netname ) ;
  116. MIB_DomLogonTableElement->svShareName.dynamic = TRUE;
  117. memcpy( MIB_DomLogonTableElement->svShareName.stream,
  118. DataTable->shi2_netname,
  119. strlen( DataTable->shi2_netname ) ) ;
  120. // Share Path
  121. MIB_DomLogonTableElement->svSharePath.stream = SnmpUtilMemAlloc (
  122. strlen( DataTable->shi2_path ) ) ;
  123. MIB_DomLogonTableElement->svSharePath.length =
  124. strlen( DataTable->shi2_path ) ;
  125. MIB_DomLogonTableElement->svSharePath.dynamic = TRUE;
  126. memcpy( MIB_DomLogonTableElement->svSharePath.stream,
  127. DataTable->shi2_path,
  128. strlen( DataTable->shi2_path ) ) ;
  129. // Share Comment/Remark
  130. MIB_DomLogonTableElement->svShareComment.stream = SnmpUtilMemAlloc (
  131. strlen( DataTable->shi2_remark ) ) ;
  132. MIB_DomLogonTableElement->svShareComment.length =
  133. strlen( DataTable->shi2_remark ) ;
  134. MIB_DomLogonTableElement->svShareComment.dynamic = TRUE;
  135. memcpy( MIB_DomLogonTableElement->svShareComment.stream,
  136. DataTable->shi2_remark,
  137. strlen( DataTable->shi2_remark ) ) ;
  138. DataTable ++ ; // advance pointer to next dlog entry in buffer
  139. MIB_DomLogonTableElement ++ ; // and table entry
  140. } // for each entry in the data table
  141. // indicate where to start adding on next pass, if any
  142. First_of_this_block = i ;
  143. } // if data is valid to process
  144. else
  145. {
  146. // Signal error
  147. nResult = SNMPAPI_ERROR;
  148. goto Exit;
  149. }
  150. } while (ERROR_MORE_DATA == lmCode) ;
  151. // iterate over the table populating the Oid field
  152. build_dlog_entry_oids();
  153. // Sort the table information using MSC QuickSort routine
  154. qsort( &MIB_DomLogonTable.Table[0], MIB_DomLogonTable.Len,
  155. sizeof(DOM_LOGON_ENTRY), dlog_entry_cmp );
  156. //
  157. //
  158. // Cache table
  159. //
  160. //
  161. //
  162. //
  163. // Return piece of information requested
  164. //
  165. //
  166. Exit:
  167. #endif
  168. return nResult;
  169. } // MIB_dlog_get
  170. //
  171. // MIB_dlog_cmp
  172. // Routine for sorting the dlogion table.
  173. //
  174. // Notes:
  175. //
  176. // Return Codes:
  177. // SNMPAPI_NOERROR
  178. // SNMPAPI_ERROR
  179. //
  180. // Error Codes:
  181. // None.
  182. //
  183. int dlog_entry_cmp(
  184. IN DOM_LOGON_ENTRY *A,
  185. IN DOM_LOGON_ENTRY *B
  186. )
  187. {
  188. // Compare the OID's
  189. return SnmpUtilOidCmp( &A->Oid, &B->Oid );
  190. } // MIB_dlog_cmp
  191. //
  192. // None.
  193. //
  194. void build_dlog_entry_oids(
  195. )
  196. {
  197. #if 0
  198. AsnOctetString OSA ;
  199. char StrA[MIB_SHARE_NAME_LEN];
  200. DOM_LOGON_ENTRY *ShareEntry ;
  201. unsigned i;
  202. // start pointer at 1st guy in the table
  203. ShareEntry = MIB_DomLogonTable.Table ;
  204. // now iterate over the table, creating an oid for each entry
  205. for( i=0; i<MIB_DomLogonTable.Len ; i++) {
  206. // for each entry in the dlogion table
  207. // Make string to use as index
  208. memcpy( StrA, ShareEntry->svShareName.stream,
  209. ShareEntry->svShareName.length );
  210. OSA.stream = StrA ;
  211. OSA.length = ShareEntry->svShareName.length ;
  212. OSA.dynamic = FALSE;
  213. // Make the entry's OID from string index
  214. MakeOidFromStr( &OSA, &ShareEntry->Oid );
  215. ShareEntry++; // point to the next guy in the table
  216. } // for
  217. #endif
  218. } // build_dlog_entry_oids
  219. //-------------------------------- END --------------------------------------