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.

2691 lines
108 KiB

  1. /*++
  2. Copyright (c) 1992-1996 Microsoft Corporation
  3. Module Name:
  4. mibfuncs.c
  5. Abstract:
  6. Contains MIB functions for GET's and SET's for LM MIB.
  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. #ifdef DOS
  16. #if 0
  17. #define INCL_NETWKSTA
  18. #define INCL_NETERRORS
  19. #include <lan.h>
  20. #endif
  21. #endif
  22. #ifdef WIN32
  23. #include <windows.h>
  24. #include <lm.h>
  25. #endif
  26. #include <tchar.h>
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include <stdlib.h>
  30. #include <time.h>
  31. //--------------------------- MODULE DEPENDENCIES -- #include"xxxxx.h" ------
  32. #include <snmp.h>
  33. #include <snmputil.h>
  34. //---ft:07/13---LsaGetUserName substitutes NetWkstaGetUserInfo
  35. #include <subauth.h> // needed for the definition of PUNICODE_STRING
  36. #include <ntlsa.h> // LSA APIs
  37. //---tf---
  38. #include "mib.h"
  39. #include "lmcache.h"
  40. //--------------------------- SELF-DEPENDENCY -- ONE #include"module.h" -----
  41. #include "mibfuncs.h"
  42. #include "odom_tbl.h"
  43. #include "user_tbl.h"
  44. #include "shar_tbl.h"
  45. #include "srvr_tbl.h"
  46. #include "prnt_tbl.h"
  47. #include "uses_tbl.h"
  48. //--------------------------- PUBLIC VARIABLES --(same as in module.h file)--
  49. //--------------------------- PRIVATE CONSTANTS -----------------------------
  50. #define SafeBufferFree(x) if(NULL != x) NetApiBufferFree( x )
  51. //--------------------------- PRIVATE STRUCTS -------------------------------
  52. //--------------------------- PRIVATE VARIABLES -----------------------------
  53. //--------------------------- PRIVATE PROTOTYPES ----------------------------
  54. //--------------------------- PRIVATE PROCEDURES ----------------------------
  55. //--------------------------- PUBLIC PROCEDURES -----------------------------
  56. void * MIB_common_func(
  57. IN UINT Action, // Action to perform on Data
  58. IN LDATA LMData, // LM Data to manipulate
  59. IN void *SetData
  60. )
  61. {
  62. SNMPAPI nResult;
  63. unsigned lmCode;
  64. WKSTA_INFO_101 *wksta_info_one;
  65. SERVER_INFO_102 *server_info_two;
  66. STAT_SERVER_0 *server_stats_zero;
  67. STAT_WORKSTATION_0 *wrk_stats_zero;
  68. LPBYTE bufptr = NULL;
  69. lan_return_info_type *retval=NULL;
  70. BYTE *stream;
  71. char temp[80];
  72. BOOL cache_it = FALSE ;
  73. time_t curr_time ;
  74. UNREFERENCED_PARAMETER(SetData);
  75. time(&curr_time); // get the time
  76. switch ( Action )
  77. {
  78. case MIB_ACTION_GET:
  79. // Check to see if data is cached
  80. //if ( Cached )
  81. //{
  82. // Retrieve from cache
  83. //}
  84. //else
  85. //{
  86. // Call LM call to get data
  87. // Put data in cache
  88. //}
  89. // See if data is supported
  90. switch ( LMData )
  91. {
  92. case MIB_LM_COMVERSIONMAJ:
  93. if((NULL == cache_table[C_NETWKSTAGETINFO].bufptr) ||
  94. (curr_time >
  95. (cache_table[C_NETWKSTAGETINFO].acquisition_time
  96. + cache_expire[C_NETWKSTAGETINFO] ) ) )
  97. { // it has expired!
  98. //
  99. // remember to free the existing data
  100. //
  101. SafeBufferFree( cache_table[C_NETWKSTAGETINFO].bufptr ) ;
  102. cache_table[C_NETWKSTAGETINFO].bufptr = NULL;
  103. //
  104. lmCode =
  105. NetWkstaGetInfo( NULL, // local server
  106. 101, // level 10, no admin priv.
  107. &bufptr // data structure to return
  108. );
  109. cache_it = TRUE ;
  110. } else {
  111. lmCode = 0 ; // fake a sucessful lan man call
  112. bufptr = cache_table[C_NETWKSTAGETINFO].bufptr ;
  113. cache_it = FALSE ;
  114. }
  115. if(lmCode == 0) { // valid so return it, otherwise error NULL
  116. if(NULL ==
  117. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  118. )
  119. goto Exit ;
  120. retval->data_element_type = ASN_OCTETSTRING ;
  121. wksta_info_one = (WKSTA_INFO_101 *) bufptr ;
  122. _itoa(wksta_info_one->wki101_ver_major,temp,10) ;
  123. if(NULL ==
  124. (stream = SnmpUtilMemAlloc( strlen(temp) ))
  125. ) {
  126. SnmpUtilMemFree(retval);
  127. retval=NULL;
  128. goto Exit ;
  129. }
  130. memcpy(stream,&temp,strlen(temp));
  131. retval->d.octstrval.stream = stream;
  132. retval->d.octstrval.length = strlen(temp);
  133. retval->d.octstrval.dynamic = TRUE;
  134. if(cache_it) {
  135. // now save it in the cache
  136. cache_table[C_NETWKSTAGETINFO].acquisition_time =
  137. curr_time ;
  138. cache_table[C_NETWKSTAGETINFO].bufptr = bufptr ;
  139. } // if (cache_it)
  140. }
  141. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_COMVERSIONMAJ.\n" ));
  142. break;
  143. case MIB_LM_COMVERSIONMIN:
  144. if((NULL == cache_table[C_NETWKSTAGETINFO].bufptr) ||
  145. (curr_time >
  146. (cache_table[C_NETWKSTAGETINFO].acquisition_time
  147. + cache_expire[C_NETWKSTAGETINFO] ) ) )
  148. { // it has expired!
  149. //
  150. // remember to free the existing data
  151. //
  152. SafeBufferFree( cache_table[C_NETWKSTAGETINFO].bufptr ) ;
  153. //
  154. lmCode =
  155. NetWkstaGetInfo( NULL, // local server
  156. 101, // level 10, no admin priv.
  157. &bufptr // data structure to return
  158. );
  159. cache_it = TRUE ;
  160. } else {
  161. lmCode = 0 ; // fake a sucessful lan man call
  162. bufptr = cache_table[C_NETWKSTAGETINFO].bufptr ;
  163. cache_it = FALSE ;
  164. }
  165. if(lmCode == 0) { // valid so return it, otherwise error NULL
  166. if(NULL ==
  167. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  168. )
  169. goto Exit ;
  170. retval->data_element_type = ASN_OCTETSTRING ;
  171. wksta_info_one = (WKSTA_INFO_101 *) bufptr ;
  172. _itoa(wksta_info_one->wki101_ver_minor,temp,10) ;
  173. if(NULL ==
  174. (stream = SnmpUtilMemAlloc( strlen(temp) ))
  175. ){
  176. SnmpUtilMemFree(retval);
  177. retval=NULL;
  178. goto Exit ;
  179. }
  180. memcpy(stream,&temp,strlen(temp));
  181. retval->d.octstrval.stream = stream;
  182. retval->d.octstrval.length = strlen(temp);
  183. retval->d.octstrval.dynamic = TRUE;
  184. if(cache_it) {
  185. // now save it in the cache
  186. cache_table[C_NETWKSTAGETINFO].acquisition_time =
  187. curr_time ;
  188. cache_table[C_NETWKSTAGETINFO].bufptr = bufptr ;
  189. } // if (cache_it)
  190. }
  191. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_COMVERSIONMIN.\n" ));
  192. break;
  193. case MIB_LM_COMTYPE:
  194. if((NULL == cache_table[C_NETSERVERGETINFO].bufptr) ||
  195. (curr_time >
  196. (cache_table[C_NETSERVERGETINFO].acquisition_time
  197. + cache_expire[C_NETSERVERGETINFO] ) ) )
  198. { // it has expired!
  199. //
  200. // remember to free the existing data
  201. //
  202. SafeBufferFree( cache_table[C_NETSERVERGETINFO].bufptr ) ;
  203. cache_table[C_NETSERVERGETINFO].bufptr = NULL;
  204. lmCode =
  205. NetServerGetInfo( NULL, // local server
  206. 102, // level 10, no admin priv.
  207. &bufptr // data structure to return
  208. );
  209. cache_it = TRUE ;
  210. } else {
  211. lmCode = 0 ; // fake a sucessful lan man call
  212. bufptr = cache_table[C_NETSERVERGETINFO].bufptr ;
  213. cache_it = FALSE ;
  214. }
  215. if(lmCode == 0) { // valid so return it, otherwise error NULL
  216. if(NULL ==
  217. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  218. )
  219. goto Exit ;
  220. retval->data_element_type = ASN_OCTETSTRING ;
  221. server_info_two = (SERVER_INFO_102 *) bufptr ;
  222. if(NULL ==
  223. (stream = SnmpUtilMemAlloc( 4 * sizeof(BYTE) ))
  224. ){
  225. SnmpUtilMemFree(retval);
  226. retval=NULL;
  227. goto Exit ;
  228. }
  229. *(DWORD*)stream=server_info_two->sv102_type & 0x000000FF;
  230. retval->d.octstrval.stream = stream;
  231. retval->d.octstrval.length = 4 * sizeof(BYTE);
  232. retval->d.octstrval.dynamic = TRUE;
  233. if(cache_it) {
  234. // now save it in the cache
  235. cache_table[C_NETSERVERGETINFO].acquisition_time =
  236. curr_time ;
  237. cache_table[C_NETSERVERGETINFO].bufptr = bufptr ;
  238. } // if (cache_it)
  239. }
  240. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_COMTYPE.\n" ));
  241. break;
  242. case MIB_LM_COMSTATSTART:
  243. if((NULL == cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ||
  244. (curr_time >
  245. (cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time
  246. + cache_expire[C_NETSTATISTICSGET_SERVER] ) ) )
  247. { // it has expired!
  248. //
  249. // remember to free the existing data
  250. //
  251. SafeBufferFree( cache_table[C_NETSTATISTICSGET_SERVER].bufptr);
  252. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = NULL;
  253. lmCode =
  254. NetStatisticsGet( NULL, // local server
  255. SERVICE_SERVER, // get server stats
  256. 0, // level 0
  257. 0, // don't clear stats
  258. &bufptr // data structure to return
  259. );
  260. cache_it = TRUE ;
  261. } else {
  262. lmCode = 0 ; // fake a sucessful lan man call
  263. bufptr = cache_table[C_NETSTATISTICSGET_SERVER].bufptr ;
  264. cache_it = FALSE ;
  265. }
  266. if(lmCode == 0) { // valid so return it, otherwise error NULL
  267. if(NULL ==
  268. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  269. )
  270. goto Exit ;
  271. retval->data_element_type = ASN_INTEGER ;
  272. server_stats_zero = (STAT_SERVER_0 *) bufptr ;
  273. retval->d.intval = server_stats_zero->sts0_start;
  274. if(cache_it) {
  275. // now save it in the cache
  276. cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time =
  277. curr_time ;
  278. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = bufptr ;
  279. } // if (cache_it)
  280. }
  281. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_STATSTART.\n" ));
  282. break;
  283. case MIB_LM_COMSTATNUMNETIOS:
  284. if((NULL == cache_table[C_NETSTATISTICSGET_WORKST].bufptr) ||
  285. (curr_time >
  286. (cache_table[C_NETSTATISTICSGET_WORKST].acquisition_time
  287. + cache_expire[C_NETSTATISTICSGET_WORKST] ) ) )
  288. { // it has expired!
  289. //
  290. // remember to free the existing data
  291. //
  292. SafeBufferFree( cache_table[C_NETSTATISTICSGET_WORKST].bufptr);
  293. cache_table[C_NETSTATISTICSGET_WORKST].bufptr = NULL;
  294. lmCode =
  295. NetStatisticsGet( NULL, // local server
  296. SERVICE_WORKSTATION, // get server stats
  297. 0, // level 0
  298. 0, // don't clear stats
  299. &bufptr // data structure to return
  300. );
  301. cache_it = TRUE ;
  302. } else {
  303. lmCode = 0 ; // fake a sucessful lan man call
  304. bufptr = cache_table[C_NETSTATISTICSGET_WORKST].bufptr ;
  305. cache_it = FALSE ;
  306. }
  307. if(lmCode == 0) { // valid so return it, otherwise error NULL
  308. if(NULL ==
  309. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  310. )
  311. goto Exit ;
  312. retval->data_element_type = ASN_INTEGER ;
  313. wrk_stats_zero = (STAT_WORKSTATION_0 *) bufptr ;
  314. retval->d.intval =
  315. (wrk_stats_zero->SmbsReceived).LowPart +
  316. (wrk_stats_zero->SmbsTransmitted).LowPart;
  317. if(cache_it) {
  318. // now save it in the cache
  319. cache_table[C_NETSTATISTICSGET_WORKST].acquisition_time =
  320. curr_time ;
  321. cache_table[C_NETSTATISTICSGET_WORKST].bufptr = bufptr ;
  322. } // if (cache_it)
  323. }
  324. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_STATNUMNETIOS.\n" ));
  325. break;
  326. case MIB_LM_COMSTATFINETIOS:
  327. if((NULL == cache_table[C_NETSTATISTICSGET_WORKST].bufptr) ||
  328. (curr_time >
  329. (cache_table[C_NETSTATISTICSGET_WORKST].acquisition_time
  330. + cache_expire[C_NETSTATISTICSGET_WORKST] ) ) )
  331. { // it has expired!
  332. //
  333. // remember to free the existing data
  334. //
  335. SafeBufferFree( cache_table[C_NETSTATISTICSGET_WORKST].bufptr);
  336. cache_table[C_NETSTATISTICSGET_WORKST].bufptr = NULL;
  337. lmCode =
  338. NetStatisticsGet( NULL, // local server
  339. SERVICE_WORKSTATION, // get server stats
  340. 0, // level 0
  341. 0, // don't clear stats
  342. &bufptr // data structure to return
  343. );
  344. cache_it = TRUE ;
  345. } else {
  346. lmCode = 0 ; // fake a sucessful lan man call
  347. bufptr = cache_table[C_NETSTATISTICSGET_WORKST].bufptr ;
  348. cache_it = FALSE ;
  349. }
  350. if(lmCode == 0) { // valid so return it, otherwise error NULL
  351. if(NULL ==
  352. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  353. )
  354. goto Exit ;
  355. retval->data_element_type = ASN_INTEGER ;
  356. wrk_stats_zero = (STAT_WORKSTATION_0 *) bufptr ;
  357. retval->d.intval = wrk_stats_zero->InitiallyFailedOperations;
  358. if(cache_it) {
  359. // now save it in the cache
  360. cache_table[C_NETSTATISTICSGET_WORKST].acquisition_time =
  361. curr_time ;
  362. cache_table[C_NETSTATISTICSGET_WORKST].bufptr = bufptr ;
  363. } // if (cache_it)
  364. }
  365. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_STATFINETIOS.\n" ));
  366. break;
  367. case MIB_LM_COMSTATFCNETIOS:
  368. if((NULL == cache_table[C_NETSTATISTICSGET_WORKST].bufptr) ||
  369. (curr_time >
  370. (cache_table[C_NETSTATISTICSGET_WORKST].acquisition_time
  371. + cache_expire[C_NETSTATISTICSGET_WORKST] ) ) )
  372. { // it has expired!
  373. //
  374. // remember to free the existing data
  375. //
  376. SafeBufferFree( cache_table[C_NETSTATISTICSGET_WORKST].bufptr);
  377. cache_table[C_NETSTATISTICSGET_WORKST].bufptr = NULL;
  378. lmCode =
  379. NetStatisticsGet( NULL, // local server
  380. SERVICE_WORKSTATION, // get server stats
  381. 0, // level 0
  382. 0, // don't clear stats
  383. &bufptr // data structure to return
  384. );
  385. cache_it = TRUE ;
  386. } else {
  387. lmCode = 0 ; // fake a sucessful lan man call
  388. bufptr = cache_table[C_NETSTATISTICSGET_WORKST].bufptr ;
  389. cache_it = FALSE ;
  390. }
  391. if(lmCode == 0) { // valid so return it, otherwise error NULL
  392. if(NULL ==
  393. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  394. )
  395. goto Exit ;
  396. retval->data_element_type = ASN_INTEGER ;
  397. wrk_stats_zero = (STAT_WORKSTATION_0 *) bufptr ;
  398. retval->d.intval = wrk_stats_zero->FailedCompletionOperations;
  399. if(cache_it) {
  400. // now save it in the cache
  401. cache_table[C_NETSTATISTICSGET_WORKST].acquisition_time =
  402. curr_time ;
  403. cache_table[C_NETSTATISTICSGET_WORKST].bufptr = bufptr ;
  404. } // if (cache_it)
  405. }
  406. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_STATFCNETIOS.\n" ));
  407. break;
  408. default:
  409. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: Data not supported by function.\n" ));
  410. nResult = SNMPAPI_ERROR;
  411. goto Exit;
  412. }
  413. break;
  414. case MIB_ACTION_SET:
  415. break;
  416. default:
  417. // Signal an error
  418. nResult = SNMPAPI_ERROR;
  419. goto Exit;
  420. }
  421. return retval /*nResult*/;
  422. Exit:
  423. if (cache_it)
  424. {
  425. SafeBufferFree(bufptr);
  426. }
  427. return retval /*nResult*/;
  428. } // MIB_common_func
  429. void * MIB_server_func(
  430. IN UINT Action, // Action to perform on Data
  431. IN LDATA LMData, // LM Data to manipulate
  432. IN void *SetData
  433. )
  434. {
  435. lan_return_info_type *retval=NULL;
  436. SERVER_INFO_102 *server_info_two;
  437. SERVER_INFO_102 server_info_10two;
  438. STAT_SERVER_0 *server_stats_zero;
  439. SERVER_INFO_102 *server_info_102 ;
  440. SERVER_INFO_403 *server_info_four ;
  441. SESSION_INFO_2 * session_info_two;
  442. SERVER_INFO_402 *server_info_402 ;
  443. #if 1
  444. USER_INFO_0 *user_info_zero ;
  445. #endif
  446. unsigned lmCode;
  447. BYTE *stream;
  448. AsnOctetString *strvalue;
  449. AsnInteger intvalue;
  450. DWORD entriesread;
  451. DWORD totalentries;
  452. SNMPAPI nResult;
  453. LPBYTE bufptr = NULL;
  454. BOOL cache_it = FALSE;
  455. time_t curr_time ;
  456. #ifdef UNICODE
  457. LPWSTR unitemp ;
  458. #endif
  459. time(&curr_time); // get the time
  460. switch ( Action )
  461. {
  462. case MIB_ACTION_GET:
  463. // Check to see if data is cached
  464. //if ( Cached )
  465. //{
  466. // Retrieve from cache
  467. //}
  468. //else
  469. //{
  470. // Call LM call to get data
  471. // Put data in cache
  472. //}
  473. // See if data is supported
  474. switch ( LMData )
  475. {
  476. case MIB_LM_SVDESCRIPTION:
  477. if((NULL == cache_table[C_NETSERVERGETINFO].bufptr) ||
  478. (curr_time >
  479. (cache_table[C_NETSERVERGETINFO].acquisition_time
  480. + cache_expire[C_NETSERVERGETINFO] ) ) )
  481. { // it has expired!
  482. //
  483. // remember to free the existing data
  484. //
  485. SafeBufferFree( cache_table[C_NETSERVERGETINFO].bufptr );
  486. cache_table[C_NETSERVERGETINFO].bufptr = NULL;
  487. lmCode =
  488. NetServerGetInfo( NULL, // local server
  489. 102, // level 10, no admin priv.
  490. &bufptr // data structure to return
  491. );
  492. cache_it = TRUE ;
  493. } else {
  494. lmCode = 0 ; // fake a sucessful lan man call
  495. bufptr = cache_table[C_NETSERVERGETINFO].bufptr ;
  496. cache_it = FALSE ;
  497. }
  498. if(lmCode == 0) { // valid so return it, otherwise error NULL
  499. if(NULL ==
  500. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  501. )
  502. goto Exit ;
  503. retval->data_element_type = ASN_OCTETSTRING ;
  504. server_info_two = (SERVER_INFO_102 *) bufptr ;
  505. #ifdef UNICODE
  506. if (SnmpUtilUnicodeToUTF8(
  507. &stream,
  508. server_info_two->sv102_comment,
  509. TRUE))
  510. {
  511. SnmpUtilMemFree(retval);
  512. retval = NULL;
  513. goto Exit;
  514. }
  515. #else
  516. if(NULL ==
  517. (stream = SnmpUtilMemAlloc( strlen(server_info_two->sv102_comment) + 1 ))
  518. ) {
  519. SnmpUtilMemFree(retval);
  520. retval=NULL;
  521. goto Exit ;
  522. }
  523. memcpy(stream,server_info_two->sv102_comment,
  524. strlen(server_info_two->sv102_comment));
  525. #endif
  526. retval->d.octstrval.stream = stream;
  527. retval->d.octstrval.length =
  528. strlen(stream);
  529. retval->d.octstrval.dynamic = TRUE;
  530. if(cache_it) {
  531. // now save it in the cache
  532. cache_table[C_NETSERVERGETINFO].acquisition_time =
  533. curr_time ;
  534. cache_table[C_NETSERVERGETINFO].bufptr = bufptr ;
  535. } // if (cache_it)
  536. }
  537. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVDESCRIPTION.\n" ));
  538. break;
  539. case MIB_LM_SVSVCNUMBER:
  540. if((NULL == cache_table[C_NETSERVICEENUM].bufptr) ||
  541. (curr_time >
  542. (cache_table[C_NETSERVICEENUM].acquisition_time
  543. + cache_expire[C_NETSERVICEENUM] ) ) )
  544. { // it has expired!
  545. //
  546. // remember to free the existing data
  547. //
  548. SafeBufferFree( cache_table[C_NETSERVICEENUM].bufptr) ;
  549. cache_table[C_NETSERVICEENUM].bufptr = NULL;
  550. lmCode =
  551. NetServiceEnum( NULL, // local server
  552. 0, // level 0
  553. &bufptr, // data structure to return
  554. MAX_PREFERRED_LENGTH,
  555. &entriesread,
  556. &totalentries,
  557. NULL);
  558. cache_it = TRUE ;
  559. } else {
  560. lmCode = 0 ; // fake a sucessful lan man call
  561. bufptr = cache_table[C_NETSERVICEENUM].bufptr ;
  562. totalentries = cache_table[C_NETSERVICEENUM].totalentries ;
  563. entriesread = cache_table[C_NETSERVICEENUM].entriesread ;
  564. cache_it = FALSE ;
  565. }
  566. if(lmCode == 0) { // valid so return it, otherwise error NULL
  567. if(NULL ==
  568. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  569. )
  570. goto Exit ;
  571. retval->data_element_type = ASN_INTEGER ;
  572. retval->d.intval = totalentries; // LOOK OUT!!
  573. if(cache_it) {
  574. // now save it in the cache
  575. cache_table[C_NETSERVICEENUM].acquisition_time =
  576. curr_time ;
  577. cache_table[C_NETSERVICEENUM].bufptr = bufptr ;
  578. cache_table[C_NETSERVICEENUM].totalentries =
  579. totalentries ;
  580. cache_table[C_NETSERVICEENUM].entriesread =
  581. entriesread ;
  582. } // if (cache_it)
  583. }
  584. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVSVCNUMBER.\n" ));
  585. break;
  586. case MIB_LM_SVSTATOPENS:
  587. if((NULL == cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ||
  588. (curr_time >
  589. (cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time
  590. + cache_expire[C_NETSTATISTICSGET_SERVER] ) ) )
  591. { // it has expired!
  592. //
  593. // remember to free the existing data
  594. //
  595. SafeBufferFree( cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ;
  596. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = NULL;
  597. lmCode =
  598. NetStatisticsGet( NULL, // local server
  599. SERVICE_SERVER, // get server stats
  600. 0, // level 0
  601. 0, // don't clear stats
  602. &bufptr // data structure to return
  603. );
  604. cache_it = TRUE ;
  605. } else {
  606. lmCode = 0 ; // fake a sucessful lan man call
  607. bufptr = cache_table[C_NETSTATISTICSGET_SERVER].bufptr ;
  608. cache_it = FALSE ;
  609. }
  610. if(lmCode == 0) { // valid so return it, otherwise error NULL
  611. if(NULL ==
  612. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  613. )
  614. goto Exit ;
  615. retval->data_element_type = ASN_INTEGER ;
  616. server_stats_zero = (STAT_SERVER_0 *) bufptr ;
  617. retval->d.intval = server_stats_zero->sts0_fopens;
  618. if(cache_it) {
  619. // now save it in the cache
  620. cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time =
  621. curr_time ;
  622. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = bufptr ;
  623. } // if (cache_it)
  624. }
  625. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVSTATOPENS.\n" ));
  626. break;
  627. case MIB_LM_SVSTATDEVOPENS:
  628. if((NULL == cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ||
  629. (curr_time >
  630. (cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time
  631. + cache_expire[C_NETSTATISTICSGET_SERVER] ) ) )
  632. { // it has expired!
  633. //
  634. // remember to free the existing data
  635. //
  636. SafeBufferFree( cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ;
  637. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = NULL;
  638. lmCode =
  639. NetStatisticsGet( NULL, // local server
  640. SERVICE_SERVER, // get server stats
  641. 0, // level 0
  642. 0, // don't clear stats
  643. &bufptr // data structure to return
  644. );
  645. cache_it = TRUE ;
  646. } else {
  647. lmCode = 0 ; // fake a sucessful lan man call
  648. bufptr = cache_table[C_NETSTATISTICSGET_SERVER].bufptr ;
  649. cache_it = FALSE ;
  650. }
  651. if(lmCode == 0) { // valid so return it, otherwise error NULL
  652. if(NULL ==
  653. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  654. )
  655. goto Exit ;
  656. retval->data_element_type = ASN_INTEGER ;
  657. server_stats_zero = (STAT_SERVER_0 *) bufptr ;
  658. retval->d.intval = server_stats_zero->sts0_devopens;
  659. if(cache_it) {
  660. // now save it in the cache
  661. cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time =
  662. curr_time ;
  663. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = bufptr ;
  664. } // if (cache_it)
  665. }
  666. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVSTATDEVOPENS.\n" ));
  667. break;
  668. case MIB_LM_SVSTATQUEUEDJOBS:
  669. if((NULL == cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ||
  670. (curr_time >
  671. (cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time
  672. + cache_expire[C_NETSTATISTICSGET_SERVER] ) ) )
  673. { // it has expired!
  674. //
  675. // remember to free the existing data
  676. //
  677. SafeBufferFree( cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ;
  678. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = NULL;
  679. lmCode =
  680. NetStatisticsGet( NULL, // local server
  681. SERVICE_SERVER, // get server stats
  682. 0, // level 0
  683. 0, // don't clear stats
  684. &bufptr // data structure to return
  685. );
  686. cache_it = TRUE ;
  687. } else {
  688. lmCode = 0 ; // fake a sucessful lan man call
  689. bufptr = cache_table[C_NETSTATISTICSGET_SERVER].bufptr ;
  690. cache_it = FALSE ;
  691. }
  692. if(lmCode == 0) { // valid so return it, otherwise error NULL
  693. if(NULL ==
  694. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  695. )
  696. goto Exit ;
  697. retval->data_element_type = ASN_INTEGER ;
  698. server_stats_zero = (STAT_SERVER_0 *) bufptr ;
  699. retval->d.intval = server_stats_zero->sts0_jobsqueued;
  700. if(cache_it) {
  701. // now save it in the cache
  702. cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time =
  703. curr_time ;
  704. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = bufptr ;
  705. } // if (cache_it)
  706. }
  707. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVSTATQUEUEDJOBS.\n" ));
  708. break;
  709. case MIB_LM_SVSTATSOPENS:
  710. if((NULL == cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ||
  711. (curr_time >
  712. (cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time
  713. + cache_expire[C_NETSTATISTICSGET_SERVER] ) ) )
  714. { // it has expired!
  715. //
  716. // remember to free the existing data
  717. //
  718. SafeBufferFree( cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ;
  719. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = NULL;
  720. lmCode =
  721. NetStatisticsGet( NULL, // local server
  722. SERVICE_SERVER, // get server stats
  723. 0, // level 0
  724. 0, // don't clear stats
  725. &bufptr // data structure to return
  726. );
  727. cache_it = TRUE ;
  728. } else {
  729. lmCode = 0 ; // fake a sucessful lan man call
  730. bufptr = cache_table[C_NETSTATISTICSGET_SERVER].bufptr ;
  731. cache_it = FALSE ;
  732. }
  733. if(lmCode == 0) { // valid so return it, otherwise error NULL
  734. if(NULL ==
  735. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  736. )
  737. goto Exit ;
  738. retval->data_element_type = ASN_INTEGER ;
  739. server_stats_zero = (STAT_SERVER_0 *) bufptr ;
  740. retval->d.intval = server_stats_zero->sts0_sopens;
  741. if(cache_it) {
  742. // now save it in the cache
  743. cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time =
  744. curr_time ;
  745. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = bufptr ;
  746. } // if (cache_it)
  747. }
  748. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVSTATSOPENS.\n" ));
  749. break;
  750. case MIB_LM_SVSTATERROROUTS:
  751. if((NULL == cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ||
  752. (curr_time >
  753. (cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time
  754. + cache_expire[C_NETSTATISTICSGET_SERVER] ) ) )
  755. { // it has expired!
  756. //
  757. // remember to free the existing data
  758. //
  759. SafeBufferFree( cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ;
  760. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = NULL;
  761. lmCode =
  762. NetStatisticsGet( NULL, // local server
  763. SERVICE_SERVER, // get server stats
  764. 0, // level 0
  765. 0, // don't clear stats
  766. &bufptr // data structure to return
  767. );
  768. cache_it = TRUE ;
  769. } else {
  770. lmCode = 0 ; // fake a sucessful lan man call
  771. bufptr = cache_table[C_NETSTATISTICSGET_SERVER].bufptr ;
  772. cache_it = FALSE ;
  773. }
  774. if(lmCode == 0) { // valid so return it, otherwise error NULL
  775. if(NULL ==
  776. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  777. )
  778. goto Exit ;
  779. retval->data_element_type = ASN_INTEGER ;
  780. server_stats_zero = (STAT_SERVER_0 *) bufptr ;
  781. retval->d.intval = server_stats_zero->sts0_serrorout;
  782. if(cache_it) {
  783. // now save it in the cache
  784. cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time =
  785. curr_time ;
  786. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = bufptr ;
  787. } // if (cache_it)
  788. }
  789. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVSTATSERROROUTS.\n" ));
  790. break;
  791. case MIB_LM_SVSTATPWERRORS:
  792. if((NULL == cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ||
  793. (curr_time >
  794. (cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time
  795. + cache_expire[C_NETSTATISTICSGET_SERVER] ) ) )
  796. { // it has expired!
  797. //
  798. // remember to free the existing data
  799. //
  800. SafeBufferFree( cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ;
  801. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = NULL;
  802. lmCode =
  803. NetStatisticsGet( NULL, // local server
  804. SERVICE_SERVER, // get server stats
  805. 0, // level 0
  806. 0, // don't clear stats
  807. &bufptr // data structure to return
  808. );
  809. cache_it = TRUE ;
  810. } else {
  811. lmCode = 0 ; // fake a sucessful lan man call
  812. bufptr = cache_table[C_NETSTATISTICSGET_SERVER].bufptr ;
  813. cache_it = FALSE ;
  814. }
  815. if(lmCode == 0) { // valid so return it, otherwise error NULL
  816. if(NULL ==
  817. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  818. )
  819. goto Exit ;
  820. retval->data_element_type = ASN_INTEGER ;
  821. server_stats_zero = (STAT_SERVER_0 *) bufptr ;
  822. retval->d.intval = server_stats_zero->sts0_pwerrors;
  823. if(cache_it) {
  824. // now save it in the cache
  825. cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time =
  826. curr_time ;
  827. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = bufptr ;
  828. } // if (cache_it)
  829. }
  830. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVSTATPWERRORS.\n" ));
  831. break;
  832. case MIB_LM_SVSTATPERMERRORS:
  833. if((NULL == cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ||
  834. (curr_time >
  835. (cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time
  836. + cache_expire[C_NETSTATISTICSGET_SERVER] ) ) )
  837. { // it has expired!
  838. //
  839. // remember to free the existing data
  840. //
  841. SafeBufferFree( cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ;
  842. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = NULL;
  843. lmCode =
  844. NetStatisticsGet( NULL, // local server
  845. SERVICE_SERVER, // get server stats
  846. 0, // level 0
  847. 0, // don't clear stats
  848. &bufptr // data structure to return
  849. );
  850. cache_it = TRUE ;
  851. } else {
  852. lmCode = 0 ; // fake a sucessful lan man call
  853. bufptr = cache_table[C_NETSTATISTICSGET_SERVER].bufptr ;
  854. cache_it = FALSE ;
  855. }
  856. if(lmCode == 0) { // valid so return it, otherwise error NULL
  857. if(NULL ==
  858. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  859. )
  860. goto Exit ;
  861. retval->data_element_type = ASN_INTEGER ;
  862. server_stats_zero = (STAT_SERVER_0 *) bufptr ;
  863. retval->d.intval = server_stats_zero->sts0_permerrors;
  864. if(cache_it) {
  865. // now save it in the cache
  866. cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time =
  867. curr_time ;
  868. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = bufptr ;
  869. } // if (cache_it)
  870. }
  871. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVSTATPERMERRORS.\n" ));
  872. break;
  873. case MIB_LM_SVSTATSYSERRORS:
  874. if((NULL == cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ||
  875. (curr_time >
  876. (cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time
  877. + cache_expire[C_NETSTATISTICSGET_SERVER] ) ) )
  878. { // it has expired!
  879. //
  880. // remember to free the existing data
  881. //
  882. SafeBufferFree( cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ;
  883. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = NULL;
  884. lmCode =
  885. NetStatisticsGet( NULL, // local server
  886. SERVICE_SERVER, // get server stats
  887. 0, // level 0
  888. 0, // don't clear stats
  889. &bufptr // data structure to return
  890. );
  891. cache_it = TRUE ;
  892. } else {
  893. lmCode = 0 ; // fake a sucessful lan man call
  894. bufptr = cache_table[C_NETSTATISTICSGET_SERVER].bufptr ;
  895. cache_it = FALSE ;
  896. }
  897. if(lmCode == 0) { // valid so return it, otherwise error NULL
  898. if(NULL ==
  899. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  900. )
  901. goto Exit ;
  902. retval->data_element_type = ASN_INTEGER ;
  903. server_stats_zero = (STAT_SERVER_0 *) bufptr ;
  904. retval->d.intval = server_stats_zero->sts0_syserrors;
  905. if(cache_it) {
  906. // now save it in the cache
  907. cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time =
  908. curr_time ;
  909. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = bufptr ;
  910. } // if (cache_it)
  911. }
  912. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVSTATSYSERRORS.\n" ));
  913. break;
  914. case MIB_LM_SVSTATSENTBYTES:
  915. if((NULL == cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ||
  916. (curr_time >
  917. (cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time
  918. + cache_expire[C_NETSTATISTICSGET_SERVER] ) ) )
  919. { // it has expired!
  920. //
  921. // remember to free the existing data
  922. //
  923. SafeBufferFree( cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ;
  924. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = NULL;
  925. lmCode =
  926. NetStatisticsGet( NULL, // local server
  927. SERVICE_SERVER, // get server stats
  928. 0, // level 0
  929. 0, // don't clear stats
  930. &bufptr // data structure to return
  931. );
  932. cache_it = TRUE ;
  933. } else {
  934. lmCode = 0 ; // fake a sucessful lan man call
  935. bufptr = cache_table[C_NETSTATISTICSGET_SERVER].bufptr ;
  936. cache_it = FALSE ;
  937. }
  938. if(lmCode == 0) { // valid so return it, otherwise error NULL
  939. if(NULL ==
  940. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  941. )
  942. goto Exit ;
  943. retval->data_element_type = ASN_INTEGER ;
  944. server_stats_zero = (STAT_SERVER_0 *) bufptr ;
  945. retval->d.intval = server_stats_zero->sts0_bytessent_low;
  946. if(cache_it) {
  947. // now save it in the cache
  948. cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time =
  949. curr_time ;
  950. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = bufptr ;
  951. } // if (cache_it)
  952. }
  953. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVSTATSENTBYTES.\n" ));
  954. break;
  955. case MIB_LM_SVSTATRCVDBYTES:
  956. if((NULL == cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ||
  957. (curr_time >
  958. (cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time
  959. + cache_expire[C_NETSTATISTICSGET_SERVER] ) ) )
  960. { // it has expired!
  961. //
  962. // remember to free the existing data
  963. //
  964. SafeBufferFree( cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ;
  965. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = NULL;
  966. lmCode =
  967. NetStatisticsGet( NULL, // local server
  968. SERVICE_SERVER, // get server stats
  969. 0, // level 0
  970. 0, // don't clear stats
  971. &bufptr // data structure to return
  972. );
  973. cache_it = TRUE ;
  974. } else {
  975. lmCode = 0 ; // fake a sucessful lan man call
  976. bufptr = cache_table[C_NETSTATISTICSGET_SERVER].bufptr ;
  977. cache_it = FALSE ;
  978. }
  979. if(lmCode == 0) { // valid so return it, otherwise error NULL
  980. if(NULL ==
  981. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  982. )
  983. goto Exit ;
  984. retval->data_element_type = ASN_INTEGER ;
  985. server_stats_zero = (STAT_SERVER_0 *) bufptr ;
  986. retval->d.intval = server_stats_zero->sts0_bytesrcvd_low;
  987. if(cache_it) {
  988. // now save it in the cache
  989. cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time =
  990. curr_time ;
  991. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = bufptr ;
  992. } // if (cache_it)
  993. }
  994. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVSTATRCVDBYTES.\n" ));
  995. break;
  996. case MIB_LM_SVSTATAVRESPONSE:
  997. if((NULL == cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ||
  998. (curr_time >
  999. (cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time
  1000. + cache_expire[C_NETSTATISTICSGET_SERVER] ) ) )
  1001. { // it has expired!
  1002. //
  1003. // remember to free the existing data
  1004. //
  1005. SafeBufferFree( cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ;
  1006. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = NULL;
  1007. lmCode =
  1008. NetStatisticsGet( NULL, // local server
  1009. SERVICE_SERVER, // get server stats
  1010. 0, // level 0
  1011. 0, // don't clear stats
  1012. &bufptr // data structure to return
  1013. );
  1014. cache_it = TRUE ;
  1015. } else {
  1016. lmCode = 0 ; // fake a sucessful lan man call
  1017. bufptr = cache_table[C_NETSTATISTICSGET_SERVER].bufptr ;
  1018. cache_it = FALSE ;
  1019. }
  1020. if(lmCode == 0) { // valid so return it, otherwise error NULL
  1021. if(NULL ==
  1022. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1023. )
  1024. goto Exit ;
  1025. retval->data_element_type = ASN_INTEGER ;
  1026. server_stats_zero = (STAT_SERVER_0 *) bufptr ;
  1027. retval->d.intval = server_stats_zero->sts0_avresponse;
  1028. if(cache_it) {
  1029. // now save it in the cache
  1030. cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time =
  1031. curr_time ;
  1032. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = bufptr ;
  1033. } // if (cache_it)
  1034. }
  1035. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVSTATAVRESPONSE.\n" ));
  1036. break;
  1037. case MIB_LM_SVSECURITYMODE:
  1038. // hard code USER security per dwaink
  1039. //
  1040. if(NULL ==
  1041. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1042. )
  1043. goto Exit ;
  1044. retval->data_element_type = ASN_INTEGER ;
  1045. retval->d.intval = 2 ;
  1046. #if 0
  1047. if((NULL == cache_table[C_NETSERVERGETINFO_403].bufptr) ||
  1048. (curr_time >
  1049. (cache_table[C_NETSERVERGETINFO_403].acquisition_time
  1050. + cache_expire[C_NETSERVERGETINFO_403] ) ) )
  1051. { // it has expired!
  1052. //
  1053. // remember to free the existing data
  1054. //
  1055. SafeBufferFree( cache_table[C_NETSERVERGETINFO_403].bufptr) ;
  1056. lmCode =
  1057. NetServerGetInfo( NULL, // local server
  1058. 403, // level 10, no admin priv.
  1059. &bufptr // data structure to return
  1060. );
  1061. cache_it = TRUE ;
  1062. } else {
  1063. lmCode = 0 ; // fake a sucessful lan man call
  1064. bufptr = cache_table[C_NETSERVERGETINFO_403].bufptr ;
  1065. cache_it = FALSE ;
  1066. }
  1067. if(lmCode == 0) { // valid so return it, otherwise error NULL
  1068. if(NULL ==
  1069. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1070. )
  1071. goto Exit ;
  1072. retval->data_element_type = ASN_INTEGER ;
  1073. server_info_four = (SERVER_INFO_403 *) bufptr ;
  1074. retval->d.intval = server_info_four->sv403_security;
  1075. if(cache_it) {
  1076. // now save it in the cache
  1077. cache_table[C_NETSERVERGETINFO_403].acquisition_time =
  1078. curr_time ;
  1079. cache_table[C_NETSERVERGETINFO_403].bufptr = bufptr ;
  1080. } // if (cache_it)
  1081. }
  1082. #endif
  1083. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVSECURITYMODE.\n" ));
  1084. break;
  1085. case MIB_LM_SVUSERS:
  1086. if((NULL == cache_table[C_NETSERVERGETINFO].bufptr) ||
  1087. (curr_time >
  1088. (cache_table[C_NETSERVERGETINFO].acquisition_time
  1089. + cache_expire[C_NETSERVERGETINFO] ) ) )
  1090. { // it has expired!
  1091. //
  1092. // remember to free the existing data
  1093. //
  1094. SafeBufferFree( cache_table[C_NETSERVERGETINFO].bufptr) ;
  1095. cache_table[C_NETSERVERGETINFO].bufptr = NULL;
  1096. lmCode =
  1097. NetServerGetInfo( NULL, // local server
  1098. 102, // level 10, no admin priv.
  1099. &bufptr // data structure to return
  1100. );
  1101. cache_it = TRUE ;
  1102. } else {
  1103. lmCode = 0 ; // fake a sucessful lan man call
  1104. bufptr = cache_table[C_NETSERVERGETINFO].bufptr ;
  1105. cache_it = FALSE ;
  1106. }
  1107. if(lmCode == 0) { // valid so return it, otherwise error NULL
  1108. if(NULL ==
  1109. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1110. )
  1111. goto Exit ;
  1112. retval->data_element_type = ASN_INTEGER ;
  1113. server_info_102 = (SERVER_INFO_102 *) bufptr ;
  1114. retval->d.intval = server_info_102->sv102_users;
  1115. if(cache_it) {
  1116. // now save it in the cache
  1117. cache_table[C_NETSERVERGETINFO].acquisition_time =
  1118. curr_time ;
  1119. cache_table[C_NETSERVERGETINFO].bufptr = bufptr ;
  1120. } // if (cache_it)
  1121. }
  1122. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVUSERS.\n" ));
  1123. break;
  1124. case MIB_LM_SVSTATREQBUFSNEEDED:
  1125. if((NULL == cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ||
  1126. (curr_time >
  1127. (cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time
  1128. + cache_expire[C_NETSTATISTICSGET_SERVER] ) ) )
  1129. { // it has expired!
  1130. //
  1131. // remember to free the existing data
  1132. //
  1133. SafeBufferFree( cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ;
  1134. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = NULL;
  1135. lmCode =
  1136. NetStatisticsGet( NULL, // local server
  1137. SERVICE_SERVER, // get server stats
  1138. 0, // level 0
  1139. 0, // don't clear stats
  1140. &bufptr // data structure to return
  1141. );
  1142. cache_it = TRUE ;
  1143. } else {
  1144. lmCode = 0 ; // fake a sucessful lan man call
  1145. bufptr = cache_table[C_NETSTATISTICSGET_SERVER].bufptr ;
  1146. cache_it = FALSE ;
  1147. }
  1148. if(lmCode == 0) { // valid so return it, otherwise error NULL
  1149. if(NULL ==
  1150. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1151. )
  1152. goto Exit ;
  1153. retval->data_element_type = ASN_INTEGER ;
  1154. server_stats_zero = (STAT_SERVER_0 *) bufptr ;
  1155. retval->d.intval = server_stats_zero->sts0_reqbufneed;
  1156. if(cache_it) {
  1157. // now save it in the cache
  1158. cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time =
  1159. curr_time ;
  1160. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = bufptr ;
  1161. } // if (cache_it)
  1162. }
  1163. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVSTATREQBUFSNEEDED.\n" ));
  1164. break;
  1165. case MIB_LM_SVSTATBIGBUFSNEEDED:
  1166. if((NULL == cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ||
  1167. (curr_time >
  1168. (cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time
  1169. + cache_expire[C_NETSTATISTICSGET_SERVER] ) ) )
  1170. { // it has expired!
  1171. //
  1172. // remember to free the existing data
  1173. //
  1174. SafeBufferFree( cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ;
  1175. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = NULL;
  1176. lmCode =
  1177. NetStatisticsGet( NULL, // local server
  1178. SERVICE_SERVER, // get server stats
  1179. 0, // level 0
  1180. 0, // don't clear stats
  1181. &bufptr // data structure to return
  1182. );
  1183. cache_it = TRUE ;
  1184. } else {
  1185. lmCode = 0 ; // fake a sucessful lan man call
  1186. bufptr = cache_table[C_NETSTATISTICSGET_SERVER].bufptr ;
  1187. cache_it = FALSE ;
  1188. }
  1189. if(lmCode == 0) { // valid so return it, otherwise error NULL
  1190. if(NULL ==
  1191. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1192. )
  1193. goto Exit ;
  1194. retval->data_element_type = ASN_INTEGER ;
  1195. server_stats_zero = (STAT_SERVER_0 *) bufptr ;
  1196. retval->d.intval = server_stats_zero->sts0_bigbufneed;
  1197. if(cache_it) {
  1198. // now save it in the cache
  1199. cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time =
  1200. curr_time ;
  1201. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = bufptr ;
  1202. } // if (cache_it)
  1203. }
  1204. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVSTATBIGBUFNEEDED.\n" ));
  1205. break;
  1206. case MIB_LM_SVSESSIONNUMBER:
  1207. if((NULL == cache_table[C_NETSESSIONENUM].bufptr) ||
  1208. (curr_time >
  1209. (cache_table[C_NETSESSIONENUM].acquisition_time
  1210. + cache_expire[C_NETSESSIONENUM] ) ) )
  1211. { // it has expired!
  1212. //
  1213. // remember to free the existing data
  1214. //
  1215. SafeBufferFree( cache_table[C_NETSESSIONENUM].bufptr) ;
  1216. cache_table[C_NETSESSIONENUM].bufptr = NULL;
  1217. lmCode =
  1218. NetSessionEnum( NULL, // local server
  1219. NULL, // get server stats
  1220. NULL,
  1221. 2, // level
  1222. &bufptr, // data structure to return
  1223. MAX_PREFERRED_LENGTH,
  1224. &entriesread,
  1225. &totalentries,
  1226. NULL // no resume handle
  1227. );
  1228. cache_it = TRUE ;
  1229. } else {
  1230. lmCode = 0 ; // fake a sucessful lan man call
  1231. bufptr = cache_table[C_NETSESSIONENUM].bufptr ;
  1232. totalentries = cache_table[C_NETSESSIONENUM].totalentries ;
  1233. entriesread = cache_table[C_NETSESSIONENUM].entriesread ;
  1234. cache_it = FALSE ;
  1235. }
  1236. if(lmCode == 0) { // valid so return it, otherwise error NULL
  1237. if(NULL ==
  1238. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1239. )
  1240. goto Exit ;
  1241. retval->data_element_type = ASN_INTEGER ;
  1242. session_info_two = (SESSION_INFO_2 *) bufptr ;
  1243. retval->d.intval = totalentries;
  1244. if(cache_it) {
  1245. // now save it in the cache
  1246. cache_table[C_NETSESSIONENUM].acquisition_time =
  1247. curr_time ;
  1248. cache_table[C_NETSESSIONENUM].bufptr = bufptr ;
  1249. cache_table[C_NETSESSIONENUM].totalentries =
  1250. totalentries ;
  1251. cache_table[C_NETSESSIONENUM].entriesread =
  1252. entriesread ;
  1253. } // if (cache_it)
  1254. }
  1255. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVSESSIONNUMBER.\n" ));
  1256. break;
  1257. case MIB_LM_SVAUTODISCONNECTS:
  1258. if((NULL == cache_table[C_NETSTATISTICSGET_SERVER].bufptr) ||
  1259. (curr_time >
  1260. (cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time
  1261. + cache_expire[C_NETSTATISTICSGET_SERVER] ) ) )
  1262. { // it has expired!
  1263. //
  1264. // remember to free the existing data
  1265. //
  1266. SafeBufferFree( cache_table[C_NETSTATISTICSGET_SERVER].bufptr);
  1267. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = NULL;
  1268. lmCode =
  1269. NetStatisticsGet( NULL, // local server
  1270. SERVICE_SERVER, // get server stats
  1271. 0, // level 0
  1272. 0, // don't clear stats
  1273. &bufptr // data structure to return
  1274. );
  1275. cache_it = TRUE ;
  1276. } else {
  1277. lmCode = 0 ; // fake a sucessful lan man call
  1278. bufptr = cache_table[C_NETSTATISTICSGET_SERVER].bufptr ;
  1279. cache_it = FALSE ;
  1280. }
  1281. if(lmCode == 0) { // valid so return it, otherwise error NULL
  1282. if(NULL ==
  1283. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1284. )
  1285. goto Exit ;
  1286. retval->data_element_type = ASN_INTEGER ;
  1287. server_stats_zero = (STAT_SERVER_0 *) bufptr ;
  1288. retval->d.intval = server_stats_zero->sts0_stimedout;
  1289. if(cache_it) {
  1290. // now save it in the cache
  1291. cache_table[C_NETSTATISTICSGET_SERVER].acquisition_time =
  1292. curr_time ;
  1293. cache_table[C_NETSTATISTICSGET_SERVER].bufptr = bufptr ;
  1294. } // if (cache_it)
  1295. }
  1296. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVSTATAUTODISCONNECT.\n" ));
  1297. break;
  1298. case MIB_LM_SVDISCONTIME:
  1299. if((NULL == cache_table[C_NETSERVERGETINFO].bufptr) ||
  1300. (curr_time >
  1301. (cache_table[C_NETSERVERGETINFO].acquisition_time
  1302. + cache_expire[C_NETSERVERGETINFO] ) ) )
  1303. { // it has expired!
  1304. //
  1305. // remember to free the existing data
  1306. //
  1307. SafeBufferFree( cache_table[C_NETSERVERGETINFO].bufptr) ;
  1308. cache_table[C_NETSERVERGETINFO].bufptr = NULL;
  1309. lmCode =
  1310. NetServerGetInfo( NULL, // local server
  1311. 102, // level 10, no admin priv.
  1312. &bufptr // data structure to return
  1313. );
  1314. cache_it = TRUE ;
  1315. } else {
  1316. lmCode = 0 ; // fake a sucessful lan man call
  1317. bufptr = cache_table[C_NETSERVERGETINFO].bufptr ;
  1318. cache_it = FALSE ;
  1319. }
  1320. if(lmCode == 0) { // valid so return it, otherwise error NULL
  1321. if(NULL ==
  1322. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1323. )
  1324. goto Exit ;
  1325. retval->data_element_type = ASN_INTEGER ;
  1326. server_info_102 = (SERVER_INFO_102 *) bufptr ;
  1327. retval->d.intval = server_info_102->sv102_disc ;
  1328. if(cache_it) {
  1329. // now save it in the cache
  1330. cache_table[C_NETSERVERGETINFO].acquisition_time =
  1331. curr_time ;
  1332. cache_table[C_NETSERVERGETINFO].bufptr = bufptr ;
  1333. } // if (cache_it)
  1334. }
  1335. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVDISCONTIME.\n" ));
  1336. break;
  1337. case MIB_LM_SVAUDITLOGSIZE:
  1338. {
  1339. HANDLE hEventLog;
  1340. DWORD cRecords;
  1341. hEventLog = OpenEventLog( NULL,
  1342. TEXT("APPLICATION"));
  1343. if (NULL == hEventLog)
  1344. {
  1345. goto Exit;
  1346. }
  1347. if(NULL ==
  1348. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1349. )
  1350. {
  1351. CloseEventLog( hEventLog );
  1352. goto Exit ;
  1353. }
  1354. retval->data_element_type = ASN_INTEGER ;
  1355. if(GetNumberOfEventLogRecords( hEventLog, &cRecords )){
  1356. retval->d.intval = cRecords ;
  1357. } else {
  1358. retval->d.intval = 0 ;
  1359. }
  1360. CloseEventLog( hEventLog );
  1361. }
  1362. #if 0
  1363. if((NULL == cache_table[C_NETSERVERGETINFO_402].bufptr) ||
  1364. (curr_time >
  1365. (cache_table[C_NETSERVERGETINFO_402].acquisition_time
  1366. + cache_expire[C_NETSERVERGETINFO_402] ) ) )
  1367. { // it has expired!
  1368. //
  1369. // remember to free the existing data
  1370. //
  1371. SafeBufferFree( cache_table[C_NETSERVERGETINFO_402].bufptr) ;
  1372. lmCode =
  1373. NetServerGetInfo( NULL, // local server
  1374. 402, // level 10, no admin priv.
  1375. &bufptr // data structure to return
  1376. );
  1377. cache_it = TRUE ;
  1378. } else {
  1379. lmCode = 0 ; // fake a sucessful lan man call
  1380. bufptr = cache_table[C_NETSERVERGETINFO_402].bufptr ;
  1381. cache_it = FALSE ;
  1382. }
  1383. if(lmCode == 0) { // valid so return it, otherwise error NULL
  1384. if(NULL ==
  1385. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1386. )
  1387. goto Exit ;
  1388. retval->data_element_type = ASN_INTEGER ;
  1389. server_info_402 = (SERVER_INFO_402 *) bufptr ;
  1390. retval->d.intval = server_info_402->sv402_maxauditsz ;
  1391. if(cache_it) {
  1392. // now save it in the cache
  1393. cache_table[C_NETSERVERGETINFO_402].acquisition_time =
  1394. curr_time ;
  1395. cache_table[C_NETSERVERGETINFO_402].bufptr = bufptr ;
  1396. } // if (cache_it)
  1397. }
  1398. #endif
  1399. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVAUDITLOGSIZE.\n" ));
  1400. break;
  1401. case MIB_LM_SVUSERNUMBER:
  1402. MIB_users_lmget(); // fire off the table get
  1403. if(NULL ==
  1404. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1405. )
  1406. goto Exit ;
  1407. retval->data_element_type = ASN_INTEGER ;
  1408. retval->d.intval = MIB_UserTable.Len;
  1409. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVUSERNUMBER.\n" ));
  1410. break;
  1411. case MIB_LM_SVSHARENUMBER:
  1412. MIB_shares_lmget(); // fire off the table get
  1413. if(NULL ==
  1414. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ) )
  1415. )
  1416. goto Exit ;
  1417. retval->data_element_type = ASN_INTEGER ;
  1418. retval->d.intval = MIB_ShareTable.Len;
  1419. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_SVSHARENUMBER.\n" ));
  1420. break;
  1421. case MIB_LM_SVPRINTQNUMBER:
  1422. MIB_prntq_lmget(); // fire off the table get
  1423. if(NULL ==
  1424. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1425. )
  1426. goto Exit ;
  1427. retval->data_element_type = ASN_INTEGER ;
  1428. retval->d.intval = MIB_PrintQTable.Len;
  1429. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_PRINTQNUMBER.\n" ));
  1430. break;
  1431. default:
  1432. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: Data not supported by function.\n" ));
  1433. nResult = SNMPAPI_ERROR;
  1434. goto Exit;
  1435. }
  1436. break;
  1437. case MIB_ACTION_SET:
  1438. switch ( LMData )
  1439. {
  1440. case MIB_LM_SVDESCRIPTION:
  1441. // retrieve string to be written
  1442. strvalue = (AsnOctetString *) SetData ;
  1443. // convert it to zero terminated string
  1444. stream = SnmpUtilMemAlloc( strvalue->length+1 );
  1445. if (stream == NULL) {
  1446. retval = (void *) FALSE;
  1447. break;
  1448. }
  1449. memcpy(stream,strvalue->stream,strvalue->length);
  1450. stream[strvalue->length] = 0;
  1451. SNMPDBG((
  1452. SNMP_LOG_TRACE,
  1453. "LMMIB2: changing server description to %s.\n",
  1454. stream
  1455. ));
  1456. #ifdef UNICODE
  1457. if (SnmpUtilUTF8ToUnicode(&unitemp,
  1458. stream,
  1459. TRUE
  1460. )) {
  1461. SnmpUtilMemFree(stream);
  1462. retval = (void *) FALSE;
  1463. break;
  1464. }
  1465. SnmpUtilMemFree(stream);
  1466. stream = (LPBYTE)unitemp;
  1467. #endif
  1468. lmCode = NetServerSetInfo(
  1469. NULL, // this server
  1470. SV_COMMENT_INFOLEVEL, // level
  1471. (LPBYTE)&stream, // data
  1472. NULL ); // option
  1473. SnmpUtilMemFree(stream);
  1474. if(NERR_Success == lmCode) {
  1475. retval = (void *) TRUE;
  1476. cache_table[C_NETSERVERGETINFO].acquisition_time = 0;
  1477. SNMPDBG((
  1478. SNMP_LOG_TRACE,
  1479. "LMMIB2: server description changed, invalidating cache.\n"
  1480. ));
  1481. } else {
  1482. retval = (void *) FALSE;
  1483. SNMPDBG((
  1484. SNMP_LOG_TRACE,
  1485. "LMMIB2: server description not changed 0x%08lx.\n",
  1486. lmCode
  1487. ));
  1488. }
  1489. break ;
  1490. case MIB_LM_SVDISCONTIME:
  1491. intvalue = (AsnInteger)((ULONG_PTR) SetData) ;
  1492. memset(&server_info_10two,0,sizeof(server_info_10two));
  1493. server_info_10two.sv102_disc = intvalue ;
  1494. lmCode = NetServerSetInfo(
  1495. NULL, // this server
  1496. SV_DISC_INFOLEVEL, // level
  1497. (LPBYTE)&server_info_10two, // data
  1498. NULL ); // option
  1499. if(NERR_Success == lmCode) {
  1500. retval = (void *)TRUE;
  1501. } else {
  1502. retval = (void *) FALSE;
  1503. }
  1504. break ;
  1505. case MIB_LM_SVAUDITLOGSIZE:
  1506. retval = (void *) FALSE;
  1507. break ;
  1508. } // switch(LMData)
  1509. break;
  1510. default:
  1511. // Signal an error
  1512. nResult = SNMPAPI_ERROR;
  1513. goto Exit;
  1514. }
  1515. return retval /*nResult*/;
  1516. Exit:
  1517. if (cache_it)
  1518. {
  1519. SafeBufferFree(bufptr);
  1520. }
  1521. return retval /*nResult*/;
  1522. } // MIB_server_func
  1523. void * MIB_workstation_func(
  1524. IN UINT Action, // Action to perform on Data
  1525. IN LDATA LMData, // LM Data to manipulate
  1526. IN void *SetData
  1527. )
  1528. {
  1529. SNMPAPI nResult;
  1530. unsigned lmCode;
  1531. STAT_WORKSTATION_0 *wrk_stats_zero;
  1532. WKSTA_INFO_502 *wksta_info_five;
  1533. LPBYTE bufptr = NULL;
  1534. lan_return_info_type *retval=NULL;
  1535. DWORD entriesread;
  1536. DWORD totalentries;
  1537. BOOL cache_it = FALSE;
  1538. time_t curr_time ;
  1539. UNREFERENCED_PARAMETER(SetData);
  1540. time(&curr_time); // get the time
  1541. switch ( Action )
  1542. {
  1543. case MIB_ACTION_GET:
  1544. // Check to see if data is cached
  1545. //if ( Cached )
  1546. //{
  1547. // Retrieve from cache
  1548. //}
  1549. //else
  1550. //{
  1551. // Call LM call to get data
  1552. // Put data in cache
  1553. //}
  1554. // See if data is supported
  1555. switch ( LMData )
  1556. {
  1557. case MIB_LM_WKSTASTATSESSSTARTS:
  1558. if((NULL == cache_table[C_NETSTATISTICSGET_WORKST].bufptr) ||
  1559. (curr_time >
  1560. (cache_table[C_NETSTATISTICSGET_WORKST].acquisition_time
  1561. + cache_expire[C_NETSTATISTICSGET_WORKST] ) ) )
  1562. { // it has expired!
  1563. //
  1564. // remember to free the existing data
  1565. //
  1566. SafeBufferFree(cache_table[C_NETSTATISTICSGET_WORKST].bufptr);
  1567. cache_table[C_NETSTATISTICSGET_WORKST].bufptr = NULL;
  1568. lmCode =
  1569. NetStatisticsGet( NULL, // local server
  1570. SERVICE_WORKSTATION, // get server stats
  1571. 0, // level 0
  1572. 0, // don't clear stats
  1573. &bufptr // data structure to return
  1574. );
  1575. cache_it = TRUE ;
  1576. } else {
  1577. lmCode = 0 ; // fake a sucessful lan man call
  1578. bufptr = cache_table[C_NETSTATISTICSGET_WORKST].bufptr ;
  1579. cache_it = FALSE ;
  1580. }
  1581. if(lmCode == 0) { // valid so return it, otherwise error NULL
  1582. if(NULL ==
  1583. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1584. )
  1585. goto Exit ;
  1586. retval->data_element_type = ASN_INTEGER ;
  1587. wrk_stats_zero = (STAT_WORKSTATION_0 *) bufptr ;
  1588. retval->d.intval = wrk_stats_zero->Sessions;
  1589. if(cache_it) {
  1590. // now save it in the cache
  1591. cache_table[C_NETSTATISTICSGET_WORKST].acquisition_time =
  1592. curr_time ;
  1593. cache_table[C_NETSTATISTICSGET_WORKST].bufptr = bufptr ;
  1594. } // if (cache_it)
  1595. }
  1596. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_WKSTASTATSESSSTARTS.\n" ));
  1597. break;
  1598. case MIB_LM_WKSTASTATSESSFAILS:
  1599. if((NULL == cache_table[C_NETSTATISTICSGET_WORKST].bufptr) ||
  1600. (curr_time >
  1601. (cache_table[C_NETSTATISTICSGET_WORKST].acquisition_time
  1602. + cache_expire[C_NETSTATISTICSGET_WORKST] ) ) )
  1603. { // it has expired!
  1604. //
  1605. // remember to free the existing data
  1606. //
  1607. SafeBufferFree(cache_table[C_NETSTATISTICSGET_WORKST].bufptr);
  1608. cache_table[C_NETSTATISTICSGET_WORKST].bufptr = NULL;
  1609. lmCode =
  1610. NetStatisticsGet( NULL, // local server
  1611. SERVICE_WORKSTATION, // get server stats
  1612. 0, // level 0
  1613. 0, // don't clear stats
  1614. &bufptr // data structure to return
  1615. );
  1616. cache_it = TRUE ;
  1617. } else {
  1618. lmCode = 0 ; // fake a sucessful lan man call
  1619. bufptr = cache_table[C_NETSTATISTICSGET_WORKST].bufptr ;
  1620. cache_it = FALSE ;
  1621. }
  1622. if(lmCode == 0) { // valid so return it, otherwise error NULL
  1623. if(NULL ==
  1624. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1625. )
  1626. goto Exit ;
  1627. retval->data_element_type = ASN_INTEGER ;
  1628. wrk_stats_zero = (STAT_WORKSTATION_0 *) bufptr ;
  1629. retval->d.intval = wrk_stats_zero->FailedSessions;
  1630. if(cache_it) {
  1631. // now save it in the cache
  1632. cache_table[C_NETSTATISTICSGET_WORKST].acquisition_time =
  1633. curr_time ;
  1634. cache_table[C_NETSTATISTICSGET_WORKST].bufptr = bufptr ;
  1635. } // if (cache_it)
  1636. }
  1637. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_WKSTASTATSESSFAILS.\n" ));
  1638. break;
  1639. case MIB_LM_WKSTASTATUSES:
  1640. if((NULL == cache_table[C_NETSTATISTICSGET_WORKST].bufptr) ||
  1641. (curr_time >
  1642. (cache_table[C_NETSTATISTICSGET_WORKST].acquisition_time
  1643. + cache_expire[C_NETSTATISTICSGET_WORKST] ) ) )
  1644. { // it has expired!
  1645. //
  1646. // remember to free the existing data
  1647. //
  1648. SafeBufferFree(cache_table[C_NETSTATISTICSGET_WORKST].bufptr);
  1649. cache_table[C_NETSTATISTICSGET_WORKST].bufptr = NULL;
  1650. lmCode =
  1651. NetStatisticsGet( NULL, // local server
  1652. SERVICE_WORKSTATION, // get server stats
  1653. 0, // level 0
  1654. 0, // don't clear stats
  1655. &bufptr // data structure to return
  1656. );
  1657. cache_it = TRUE ;
  1658. } else {
  1659. lmCode = 0 ; // fake a sucessful lan man call
  1660. bufptr = cache_table[C_NETSTATISTICSGET_WORKST].bufptr ;
  1661. cache_it = FALSE ;
  1662. }
  1663. if(lmCode == 0) { // valid so return it, otherwise error NULL
  1664. if(NULL ==
  1665. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1666. )
  1667. goto Exit ;
  1668. retval->data_element_type = ASN_INTEGER ;
  1669. wrk_stats_zero = (STAT_WORKSTATION_0 *) bufptr ;
  1670. retval->d.intval = wrk_stats_zero->UseCount;
  1671. if(cache_it) {
  1672. // now save it in the cache
  1673. cache_table[C_NETSTATISTICSGET_WORKST].acquisition_time =
  1674. curr_time ;
  1675. cache_table[C_NETSTATISTICSGET_WORKST].bufptr = bufptr ;
  1676. } // if (cache_it)
  1677. }
  1678. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_WKSTASTATUSES.\n" ));
  1679. break;
  1680. case MIB_LM_WKSTASTATUSEFAILS:
  1681. if((NULL == cache_table[C_NETSTATISTICSGET_WORKST].bufptr) ||
  1682. (curr_time >
  1683. (cache_table[C_NETSTATISTICSGET_WORKST].acquisition_time
  1684. + cache_expire[C_NETSTATISTICSGET_WORKST] ) ) )
  1685. { // it has expired!
  1686. //
  1687. // remember to free the existing data
  1688. //
  1689. SafeBufferFree(cache_table[C_NETSTATISTICSGET_WORKST].bufptr);
  1690. cache_table[C_NETSTATISTICSGET_WORKST].bufptr = NULL;
  1691. lmCode =
  1692. NetStatisticsGet( NULL, // local server
  1693. SERVICE_WORKSTATION, // get server stats
  1694. 0, // level 0
  1695. 0, // don't clear stats
  1696. &bufptr // data structure to return
  1697. );
  1698. cache_it = TRUE ;
  1699. } else {
  1700. lmCode = 0 ; // fake a sucessful lan man call
  1701. bufptr = cache_table[C_NETSTATISTICSGET_WORKST].bufptr ;
  1702. cache_it = FALSE ;
  1703. }
  1704. if(lmCode == 0) { // valid so return it, otherwise error NULL
  1705. if(NULL ==
  1706. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1707. )
  1708. goto Exit ;
  1709. retval->data_element_type = ASN_INTEGER ;
  1710. wrk_stats_zero = (STAT_WORKSTATION_0 *) bufptr ;
  1711. retval->d.intval = wrk_stats_zero->FailedUseCount;
  1712. if(cache_it) {
  1713. // now save it in the cache
  1714. cache_table[C_NETSTATISTICSGET_WORKST].acquisition_time =
  1715. curr_time ;
  1716. cache_table[C_NETSTATISTICSGET_WORKST].bufptr = bufptr ;
  1717. } // if (cache_it)
  1718. }
  1719. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_WKSTASTATUSEFAILS.\n" ));
  1720. break;
  1721. case MIB_LM_WKSTASTATAUTORECS:
  1722. if((NULL == cache_table[C_NETSTATISTICSGET_WORKST].bufptr) ||
  1723. (curr_time >
  1724. (cache_table[C_NETSTATISTICSGET_WORKST].acquisition_time
  1725. + cache_expire[C_NETSTATISTICSGET_WORKST] ) ) )
  1726. { // it has expired!
  1727. //
  1728. // remember to free the existing data
  1729. //
  1730. SafeBufferFree(cache_table[C_NETSTATISTICSGET_WORKST].bufptr);
  1731. cache_table[C_NETSTATISTICSGET_WORKST].bufptr = NULL;
  1732. lmCode =
  1733. NetStatisticsGet( NULL, // local server
  1734. SERVICE_WORKSTATION, // get server stats
  1735. 0, // level 0
  1736. 0, // don't clear stats
  1737. &bufptr // data structure to return
  1738. );
  1739. cache_it = TRUE ;
  1740. } else {
  1741. lmCode = 0 ; // fake a sucessful lan man call
  1742. bufptr = cache_table[C_NETSTATISTICSGET_WORKST].bufptr ;
  1743. cache_it = FALSE ;
  1744. }
  1745. if(lmCode == 0) { // valid so return it, otherwise error NULL
  1746. if(NULL ==
  1747. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1748. )
  1749. goto Exit ;
  1750. retval->data_element_type = ASN_INTEGER ;
  1751. wrk_stats_zero = (STAT_WORKSTATION_0 *) bufptr ;
  1752. retval->d.intval = wrk_stats_zero->Reconnects;
  1753. if(cache_it) {
  1754. // now save it in the cache
  1755. cache_table[C_NETSTATISTICSGET_WORKST].acquisition_time =
  1756. curr_time ;
  1757. cache_table[C_NETSTATISTICSGET_WORKST].bufptr = bufptr ;
  1758. } // if (cache_it)
  1759. }
  1760. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_WKSTASTATAUTORECS.\n" ));
  1761. break;
  1762. case MIB_LM_WKSTAERRORLOGSIZE:
  1763. if((NULL == cache_table[C_NETWKSTAGETINFO_502].bufptr) ||
  1764. (curr_time >
  1765. (cache_table[C_NETWKSTAGETINFO_502].acquisition_time
  1766. + cache_expire[C_NETWKSTAGETINFO_502] ) ) )
  1767. { // it has expired!
  1768. //
  1769. // remember to free the existing data
  1770. //
  1771. SafeBufferFree(cache_table[C_NETWKSTAGETINFO_502].bufptr) ;
  1772. cache_table[C_NETWKSTAGETINFO_502].bufptr = NULL;
  1773. lmCode =
  1774. NetWkstaGetInfo( NULL, // local server
  1775. 502, // level 10, no admin priv.
  1776. &bufptr // data structure to return
  1777. );
  1778. cache_it = TRUE ;
  1779. } else {
  1780. lmCode = 0 ; // fake a sucessful lan man call
  1781. bufptr = cache_table[C_NETWKSTAGETINFO_502].bufptr ;
  1782. cache_it = FALSE ;
  1783. }
  1784. if(lmCode == 0) { // valid so return it, otherwise error NULL
  1785. if(NULL ==
  1786. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1787. )
  1788. goto Exit ;
  1789. retval->data_element_type = ASN_INTEGER ;
  1790. wksta_info_five = (WKSTA_INFO_502 *) bufptr ;
  1791. retval->d.intval =
  1792. wksta_info_five->wki502_maximum_collection_count ;
  1793. if(cache_it) {
  1794. // now save it in the cache
  1795. cache_table[C_NETWKSTAGETINFO_502].acquisition_time =
  1796. curr_time ;
  1797. cache_table[C_NETWKSTAGETINFO_502].bufptr = bufptr ;
  1798. } // if (cache_it)
  1799. }
  1800. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_WKSTAERRORLOGSIZE.\n" ));
  1801. break;
  1802. case MIB_LM_WKSTAUSENUMBER:
  1803. MIB_wsuses_lmget(); // fire off the table get
  1804. if(NULL ==
  1805. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1806. )
  1807. goto Exit ;
  1808. retval->data_element_type = ASN_INTEGER ;
  1809. retval->d.intval = MIB_WkstaUsesTable.Len;
  1810. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_WKSTAUSENUMBER.\n" ));
  1811. break;
  1812. default:
  1813. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: Data not supported by function.\n" ));
  1814. nResult = SNMPAPI_ERROR;
  1815. goto Exit;
  1816. }
  1817. break;
  1818. case MIB_ACTION_SET:
  1819. switch ( LMData )
  1820. {
  1821. case MIB_LM_WKSTAERRORLOGSIZE:
  1822. ;
  1823. }
  1824. break;
  1825. default:
  1826. // Signal an error
  1827. nResult = SNMPAPI_ERROR;
  1828. goto Exit;
  1829. }
  1830. return retval /*nResult*/;
  1831. Exit:
  1832. if (cache_it)
  1833. {
  1834. SafeBufferFree(bufptr);
  1835. }
  1836. return retval /*nResult*/;
  1837. }
  1838. void * MIB_domain_func(
  1839. IN UINT Action, // Action to perform on Data
  1840. IN LDATA LMData, // LM Data to manipulate
  1841. void *SetData
  1842. )
  1843. {
  1844. SNMPAPI nResult;
  1845. unsigned lmCode;
  1846. WKSTA_INFO_101 *wksta_info_one;
  1847. LPBYTE bufptr = NULL;
  1848. lan_return_info_type *retval=NULL;
  1849. DWORD entriesread;
  1850. DWORD totalentries;
  1851. BYTE *stream;
  1852. BOOL cache_it = FALSE;
  1853. time_t curr_time ;
  1854. UNREFERENCED_PARAMETER(SetData);
  1855. time(&curr_time); // get the time
  1856. switch ( Action )
  1857. {
  1858. case MIB_ACTION_GET:
  1859. // Check to see if data is cached
  1860. //if ( Cached )
  1861. //{
  1862. // Retrieve from cache
  1863. //}
  1864. //else
  1865. //{
  1866. // Call LM call to get data
  1867. // Put data in cache
  1868. //}
  1869. // See if data is supported
  1870. switch ( LMData )
  1871. {
  1872. case MIB_LM_DOMPRIMARYDOMAIN:
  1873. if((NULL == cache_table[C_NETWKSTAGETINFO_101].bufptr) ||
  1874. (curr_time >
  1875. (cache_table[C_NETWKSTAGETINFO_101].acquisition_time
  1876. + cache_expire[C_NETWKSTAGETINFO_101] ) ) )
  1877. { // it has expired!
  1878. //
  1879. // remember to free the existing data
  1880. //
  1881. SafeBufferFree(cache_table[C_NETWKSTAGETINFO_101].bufptr) ;
  1882. cache_table[C_NETWKSTAGETINFO_101].bufptr = NULL;
  1883. lmCode =
  1884. NetWkstaGetInfo( NULL, // local server
  1885. 101, // level 101,
  1886. &bufptr // data structure to return
  1887. );
  1888. cache_it = TRUE ;
  1889. } else {
  1890. lmCode = 0 ; // fake a sucessful lan man call
  1891. bufptr = cache_table[C_NETWKSTAGETINFO_101].bufptr ;
  1892. cache_it = FALSE ;
  1893. }
  1894. if(lmCode == 0) { // valid so return it, otherwise error NULL
  1895. if(NULL ==
  1896. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  1897. )
  1898. goto Exit ;
  1899. retval->data_element_type = ASN_OCTETSTRING ;
  1900. wksta_info_one = (WKSTA_INFO_101 *) bufptr ;
  1901. #ifdef UNICODE
  1902. if (SnmpUtilUnicodeToUTF8(
  1903. &stream,
  1904. wksta_info_one->wki101_langroup,
  1905. TRUE))
  1906. {
  1907. SnmpUtilMemFree(retval);
  1908. retval=NULL;
  1909. goto Exit ;
  1910. }
  1911. #else
  1912. if(NULL ==
  1913. (stream = SnmpUtilMemAlloc( strlen(wksta_info_one->wki101_langroup)+2 ))){
  1914. SnmpUtilMemFree(retval);
  1915. retval=NULL;
  1916. goto Exit ;
  1917. }
  1918. memcpy(stream,
  1919. wksta_info_one->wki101_langroup,
  1920. strlen(wksta_info_one->wki101_langroup));
  1921. #endif
  1922. retval->d.octstrval.stream = stream;
  1923. retval->d.octstrval.length = strlen(stream);
  1924. retval->d.octstrval.dynamic = TRUE;
  1925. if(cache_it) {
  1926. // now save it in the cache
  1927. cache_table[C_NETWKSTAGETINFO_101].acquisition_time =
  1928. curr_time ;
  1929. cache_table[C_NETWKSTAGETINFO_101].bufptr = bufptr ;
  1930. } // if (cache_it)
  1931. }
  1932. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_DOMPRIMARYDOMAIN.\n" ));
  1933. break;
  1934. case MIB_LM_DOMLOGONDOMAIN:
  1935. if((NULL == cache_table[C_NETWKSTAUSERGETINFO].bufptr) ||
  1936. (curr_time >
  1937. (cache_table[C_NETWKSTAUSERGETINFO].acquisition_time
  1938. + cache_expire[C_NETWKSTAUSERGETINFO] ) ) )
  1939. {
  1940. // it has expired!
  1941. PLSA_UNICODE_STRING logonUserName, logonDomainName;
  1942. //
  1943. // remember to free the existing data
  1944. //
  1945. SafeBufferFree(cache_table[C_NETWKSTAUSERGETINFO].bufptr) ;
  1946. cache_table[C_NETWKSTAUSERGETINFO].bufptr = NULL;
  1947. logonUserName = logonDomainName = NULL;
  1948. // sensible point. Hard to get a call that is returning the logonDomainName:
  1949. // NetWkstaUserGetInfo() is returning NO_LOGON_SESSION (for level 1)
  1950. // LsaGetUserName() is returning inaccurate info when running from service controller.
  1951. lmCode = LsaGetUserName( &logonUserName, &logonDomainName);
  1952. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: got '%c'\n", (LPBYTE)(logonDomainName->Buffer)[0] ));
  1953. if (lmCode == 0)
  1954. {
  1955. DWORD cbLogonDomainName;
  1956. // save a copy of the logonDomainName
  1957. cbLogonDomainName = (wcslen(logonDomainName->Buffer) + 1) * sizeof(WCHAR);
  1958. if (NetApiBufferAllocate(cbLogonDomainName, &bufptr) == NERR_Success)
  1959. {
  1960. memcpy(bufptr, logonDomainName->Buffer, cbLogonDomainName);
  1961. // see BUG# 598384 and 587627 for detail on
  1962. // why we free the Buffer member
  1963. if (logonUserName)
  1964. {
  1965. LsaFreeMemory(logonUserName->Buffer);
  1966. LsaFreeMemory(logonUserName);
  1967. }
  1968. if (logonDomainName)
  1969. {
  1970. LsaFreeMemory(logonDomainName->Buffer);
  1971. LsaFreeMemory(logonDomainName);
  1972. }
  1973. }
  1974. else
  1975. {
  1976. // see BUG# 598384 and 587627 for detail on
  1977. // why we free the Buffer member
  1978. if (logonUserName)
  1979. {
  1980. LsaFreeMemory(logonUserName->Buffer);
  1981. LsaFreeMemory(logonUserName);
  1982. }
  1983. if (logonDomainName)
  1984. {
  1985. LsaFreeMemory(logonDomainName->Buffer);
  1986. LsaFreeMemory(logonDomainName);
  1987. }
  1988. goto Exit;
  1989. }
  1990. }
  1991. cache_it = TRUE ;
  1992. }
  1993. else
  1994. {
  1995. lmCode = 0 ; // fake a sucessful lan man call
  1996. bufptr = cache_table[C_NETWKSTAUSERGETINFO].bufptr ;
  1997. cache_it = FALSE ;
  1998. }
  1999. if(lmCode == 0)
  2000. {
  2001. // valid so return it, otherwise error NULL
  2002. if(NULL == (retval = SnmpUtilMemAlloc(sizeof(lan_return_info_type))) )
  2003. goto Exit ;
  2004. retval->data_element_type = ASN_OCTETSTRING ;
  2005. #ifdef UNICODE
  2006. if (SnmpUtilUnicodeToUTF8(
  2007. &stream,
  2008. (LPWSTR)bufptr,
  2009. TRUE))
  2010. {
  2011. SnmpUtilMemFree(retval);
  2012. retval=NULL;
  2013. goto Exit ;
  2014. }
  2015. #else
  2016. if(NULL == (stream = SnmpUtilMemAlloc(strlen((LPWSTR)bufptr)+2)) )
  2017. {
  2018. SnmpUtilMemFree(retval);
  2019. retval=NULL;
  2020. goto Exit ;
  2021. }
  2022. memcpy(stream,
  2023. bufptr,
  2024. strlen(bufptr));
  2025. #endif
  2026. retval->d.octstrval.stream = stream;
  2027. retval->d.octstrval.length = strlen(stream);
  2028. retval->d.octstrval.dynamic = TRUE;
  2029. if(cache_it)
  2030. {
  2031. // now save it in the cache
  2032. cache_table[C_NETWKSTAUSERGETINFO].acquisition_time = curr_time ;
  2033. cache_table[C_NETWKSTAUSERGETINFO].bufptr = bufptr ;
  2034. } // if (cache_it)
  2035. }
  2036. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_DOMLOGONDOMAIN.\n" ));
  2037. break;
  2038. case MIB_LM_DOMOTHERDOMAINNUMBER:
  2039. MIB_odoms_lmget(); // fire off the table get
  2040. if(NULL ==
  2041. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  2042. )
  2043. goto Exit ;
  2044. retval->data_element_type = ASN_INTEGER ;
  2045. retval->d.intval = MIB_DomOtherDomainTable.Len;
  2046. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_DOMOTHERDOMAINNUMBER.\n" ));
  2047. break;
  2048. case MIB_LM_DOMSERVERNUMBER:
  2049. MIB_svsond_lmget(); // fire off the table get
  2050. if(NULL ==
  2051. (retval = SnmpUtilMemAlloc( sizeof(lan_return_info_type) ))
  2052. )
  2053. goto Exit ;
  2054. retval->data_element_type = ASN_INTEGER ;
  2055. retval->d.intval = MIB_DomServerTable.Len;
  2056. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: processing MIB_LM_DOMSERVERNUMBER.\n" ));
  2057. break;
  2058. //
  2059. // OPENISSUE --> NETLOGONENUM permanently eliminated
  2060. //
  2061. #if 0
  2062. // did some of these guys get lost ???
  2063. // double check there is a mistake in the mib table
  2064. //
  2065. case MIB_LM_DOMLOGONNUMBER:
  2066. case MIB_LM_DOMLOGONTABLE:
  2067. case MIB_LM_DOMLOGONENTRY:
  2068. case MIB_LM_DOMLOGONUSER:
  2069. case MIB_LM_DOMLOGONMACHINE:
  2070. #endif
  2071. default:
  2072. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: Data not supported by function.\n" ));
  2073. nResult = SNMPAPI_ERROR;
  2074. goto Exit;
  2075. }
  2076. break;
  2077. case MIB_ACTION_SET:
  2078. switch ( LMData )
  2079. {
  2080. case MIB_LM_DOMOTHERNAME:
  2081. ;
  2082. }
  2083. break;
  2084. default:
  2085. // Signal an error
  2086. nResult = SNMPAPI_ERROR;
  2087. goto Exit;
  2088. }
  2089. return retval /*nResult*/;
  2090. Exit:
  2091. if (cache_it)
  2092. {
  2093. SafeBufferFree(bufptr);
  2094. }
  2095. return retval /*nResult*/;
  2096. }
  2097. //
  2098. // MIB_leaf_func
  2099. // Performs actions on LEAF variables in the MIB.
  2100. //
  2101. // Notes:
  2102. //
  2103. // Return Codes:
  2104. // None.
  2105. //
  2106. // Error Codes:
  2107. // None.
  2108. //
  2109. UINT MIB_leaf_func(
  2110. IN UINT Action,
  2111. IN MIB_ENTRY *MibPtr,
  2112. IN RFC1157VarBind *VarBind
  2113. )
  2114. {
  2115. lan_return_info_type *MibVal;
  2116. UINT nResult;
  2117. switch ( Action )
  2118. {
  2119. case MIB_ACTION_GETNEXT:
  2120. if ( MibPtr->MibNext == NULL )
  2121. {
  2122. nResult = SNMP_ERRORSTATUS_NOSUCHNAME;
  2123. goto Exit;
  2124. }
  2125. nResult = (*MibPtr->MibNext->MibFunc)( MIB_ACTION_GETFIRST,
  2126. MibPtr->MibNext, VarBind );
  2127. break;
  2128. case MIB_ACTION_GETFIRST:
  2129. // Check to see if this variable is accessible for GET
  2130. if ( MibPtr->Access != MIB_ACCESS_READ &&
  2131. MibPtr->Access != MIB_ACCESS_READWRITE )
  2132. {
  2133. if ( MibPtr->MibNext != NULL )
  2134. {
  2135. nResult = (*MibPtr->MibNext->MibFunc)( Action,
  2136. MibPtr->MibNext,
  2137. VarBind );
  2138. }
  2139. else
  2140. {
  2141. nResult = SNMP_ERRORSTATUS_NOSUCHNAME;
  2142. }
  2143. break;
  2144. }
  2145. else
  2146. {
  2147. // Place correct OID in VarBind
  2148. AsnObjectIdentifier tmpOid;
  2149. tmpOid = VarBind->name; // keep a copy (structure copy)
  2150. if (!SnmpUtilOidCpy( &VarBind->name, &MIB_OidPrefix ))
  2151. {
  2152. VarBind->name = tmpOid; // restore
  2153. nResult = SNMP_ERRORSTATUS_RESOURCEUNAVAILABLE;
  2154. goto Exit;
  2155. }
  2156. if (!SnmpUtilOidAppend( &VarBind->name, &MibPtr->Oid ))
  2157. {
  2158. SnmpUtilOidFree(&VarBind->name);
  2159. VarBind->name = tmpOid; // restore
  2160. nResult = SNMP_ERRORSTATUS_RESOURCEUNAVAILABLE;
  2161. goto Exit;
  2162. }
  2163. // free the original VarBind->name
  2164. SnmpUtilOidFree(&tmpOid);
  2165. }
  2166. // Purposefully let fall through to GET
  2167. case MIB_ACTION_GET:
  2168. // Make sure that this variable is GET'able
  2169. if ( MibPtr->Access != MIB_ACCESS_READ &&
  2170. MibPtr->Access != MIB_ACCESS_READWRITE )
  2171. {
  2172. nResult = SNMP_ERRORSTATUS_NOSUCHNAME;
  2173. goto Exit;
  2174. }
  2175. // Call the LM call to get data
  2176. MibVal = (*MibPtr->LMFunc)( MIB_ACTION_GET, MibPtr->LMData, NULL );
  2177. if ( MibVal == NULL )
  2178. {
  2179. nResult = SNMP_ERRORSTATUS_GENERR;
  2180. goto Exit;
  2181. }
  2182. // Setup varbind's return value
  2183. VarBind->value.asnType = MibPtr->Type;
  2184. switch ( MibPtr->Type )
  2185. {
  2186. case ASN_RFC1155_COUNTER:
  2187. case ASN_RFC1155_GAUGE:
  2188. case ASN_RFC1155_TIMETICKS:
  2189. case ASN_INTEGER:
  2190. VarBind->value.asnValue.number = MibVal->d.intval;
  2191. break;
  2192. case ASN_RFC1155_IPADDRESS:
  2193. case ASN_RFC1155_OPAQUE:
  2194. case ASN_OCTETSTRING:
  2195. // This is non-standard copy of structure
  2196. VarBind->value.asnValue.string = MibVal->d.octstrval;
  2197. break;
  2198. default:
  2199. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: Internal Error Processing LAN Manager LEAF Variable\n" ));
  2200. nResult = SNMP_ERRORSTATUS_GENERR;
  2201. SnmpUtilMemFree( MibVal );
  2202. goto Exit;
  2203. } // type switch
  2204. // Free memory alloc'ed by LM API call
  2205. SnmpUtilMemFree( MibVal );
  2206. nResult = SNMP_ERRORSTATUS_NOERROR;
  2207. break;
  2208. case MIB_ACTION_SET:
  2209. // Check for writable attribute
  2210. if ( MibPtr->Access != MIB_ACCESS_READWRITE &&
  2211. MibPtr->Access != MIB_ACCESS_WRITE )
  2212. {
  2213. nResult = SNMP_ERRORSTATUS_NOSUCHNAME;
  2214. goto Exit;
  2215. }
  2216. // Check for proper type before setting
  2217. if ( MibPtr->Type != VarBind->value.asnType )
  2218. {
  2219. nResult = SNMP_ERRORSTATUS_BADVALUE;
  2220. goto Exit;
  2221. }
  2222. // Call LM routine to set variable
  2223. switch ( VarBind->value.asnType )
  2224. {
  2225. case ASN_RFC1155_COUNTER:
  2226. case ASN_INTEGER:
  2227. if ( SNMPAPI_ERROR ==
  2228. (*MibPtr->LMFunc)(MIB_ACTION_SET, MibPtr->LMData,
  2229. (void *)&VarBind->value.asnValue.number) )
  2230. {
  2231. nResult = SNMP_ERRORSTATUS_GENERR;
  2232. goto Exit;
  2233. }
  2234. break;
  2235. case ASN_OCTETSTRING: // This entails ASN_RFC1213_DISPSTRING also
  2236. if ( SNMPAPI_ERROR ==
  2237. (*MibPtr->LMFunc)(MIB_ACTION_SET, MibPtr->LMData,
  2238. (void *)&VarBind->value.asnValue.string) )
  2239. {
  2240. nResult = SNMP_ERRORSTATUS_GENERR;
  2241. goto Exit;
  2242. }
  2243. break;
  2244. default:
  2245. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: Internal Error Processing LAN Manager LEAF Variable\n" ));
  2246. nResult = SNMP_ERRORSTATUS_GENERR;
  2247. goto Exit;
  2248. }
  2249. nResult = SNMP_ERRORSTATUS_NOERROR;
  2250. break;
  2251. default:
  2252. SNMPDBG(( SNMP_LOG_TRACE, "LMMIB2: Internal Error Processing LAN Manager LEAF Variable\n" ));
  2253. nResult = SNMP_ERRORSTATUS_GENERR;
  2254. } // switch
  2255. Exit:
  2256. return nResult;
  2257. } // MIB_leaf_func
  2258. //-------------------------------- END --------------------------------------