wsnmp_db.c
Upload User: caisha3
Upload Date: 2013-09-21
Package Size: 208739k
Code Size: 7k
Category:

Windows Develop

Development Platform:

Visual C++

  1. // wsnmp_db.c
  2. //
  3. // WinSNMP Local Database Functions and helpers
  4. // Copyright 1995-1997 ACE*COMM Corp
  5. // Rleased to Microsoft under Contract
  6. // Beta 1 version, 970228
  7. // Bob Natale (bnatale@acecomm.com)
  8. //
  9. #include "winsnmp.inc"
  10. SNMPAPI_STATUS SNMPAPI_CALL
  11.    SnmpGetVendorInfo (OUT smiLPVENDORINFO vendorInfo)
  12. {
  13. SNMPAPI_STATUS lError;
  14. if (TaskData.hTask == 0)
  15.    {
  16.    lError = SNMPAPI_NOT_INITIALIZED;
  17.    goto ERROR_OUT;
  18.    }
  19. if (vendorInfo == NULL)
  20.    {
  21.    lError = SNMPAPI_NOOP;
  22.    goto ERROR_OUT;
  23.    }
  24. if (IsBadWritePtr(vendorInfo, sizeof(smiVENDORINFO)))
  25.    {
  26.    lError = SNMPAPI_ALLOC_ERROR;
  27.    goto ERROR_OUT;
  28.    }
  29. // Max len = 64
  30. lstrcpy (&vendorInfo->vendorName[0], "Microsoft Corporation");
  31. lstrcpy (&vendorInfo->vendorContact[0], "snmpinfo@microsoft.com");
  32. // Max len = 32
  33. lstrcpy (&vendorInfo->vendorVersionId[0], "v2.32.19980808");
  34. lstrcpy (&vendorInfo->vendorVersionDate[0], "August 8, 1998");
  35. vendorInfo->vendorEnterprise = 311;
  36. return (SNMPAPI_SUCCESS);
  37. //
  38. ERROR_OUT:
  39. return (SaveError (0, lError));
  40. } // end_SnmpGetVendorInfo()
  41. SNMPAPI_STATUS SNMPAPI_CALL
  42.    SnmpGetTranslateMode (OUT smiLPUINT32 nTranslateMode)
  43. {
  44. SNMPAPI_STATUS lError;
  45. if (TaskData.hTask == 0)
  46.    {
  47.    lError = SNMPAPI_NOT_INITIALIZED;
  48.    goto ERROR_OUT;
  49.    }
  50. // Must have some place to write answer to...
  51. if (IsBadWritePtr (nTranslateMode, sizeof(smiUINT32)))
  52.    {
  53.    lError = SNMPAPI_ALLOC_ERROR;
  54.    goto ERROR_OUT;
  55.    }
  56. // Ok to write value
  57. *nTranslateMode = TaskData.nTranslateMode;
  58. return (SNMPAPI_SUCCESS);
  59. //
  60. ERROR_OUT:
  61. return (SaveError (0, lError));
  62. } // end_SnmpGetTranslateMode()
  63. SNMPAPI_STATUS SNMPAPI_CALL
  64.    SnmpSetTranslateMode (IN smiUINT32 nTranslateMode)
  65. {
  66. SNMPAPI_STATUS lError;
  67. if (TaskData.hTask == 0)
  68.    {
  69.    lError = SNMPAPI_NOT_INITIALIZED;
  70.    goto ERROR_OUT;
  71.    }
  72. switch (nTranslateMode)
  73.    {
  74.    case SNMPAPI_TRANSLATED:
  75.    case SNMPAPI_UNTRANSLATED_V1:
  76.    case SNMPAPI_UNTRANSLATED_V2:
  77.    EnterCriticalSection (&cs_TASK);
  78.    TaskData.nTranslateMode = nTranslateMode;
  79.    LeaveCriticalSection (&cs_TASK);
  80.    break;
  81.    default:
  82.    lError = SNMPAPI_MODE_INVALID;
  83.    goto ERROR_OUT;
  84.    }
  85. return (SNMPAPI_SUCCESS);
  86. //
  87. ERROR_OUT:
  88. return (SaveError (0, lError));
  89. } // end_SnmpSetTranslateMode()
  90. SNMPAPI_STATUS SNMPAPI_CALL
  91.    SnmpGetRetransmitMode (OUT smiLPUINT32 nRetransmitMode)
  92. {
  93. SNMPAPI_STATUS lError;
  94. if (TaskData.hTask == 0)
  95.    {
  96.    lError = SNMPAPI_NOT_INITIALIZED;
  97.    goto ERROR_OUT;
  98.    }
  99. // Must have some place to write answer to...
  100. if (IsBadWritePtr (nRetransmitMode, sizeof(smiUINT32)))
  101.    {
  102.    lError = SNMPAPI_ALLOC_ERROR;
  103.    goto ERROR_OUT;
  104.    }
  105. // Ok to write value
  106. *nRetransmitMode = TaskData.nRetransmitMode;
  107. return (SNMPAPI_SUCCESS);
  108. //
  109. ERROR_OUT:
  110. return (SaveError (0, lError));
  111. } // end_SnmpGetRetransmitMode()
  112. SNMPAPI_STATUS SNMPAPI_CALL
  113.    SnmpSetRetransmitMode (IN smiUINT32 nRetransmitMode)
  114. {
  115. SNMPAPI_STATUS lError;
  116. if (TaskData.hTask == 0)
  117.    {
  118.    lError = SNMPAPI_NOT_INITIALIZED;
  119.    goto ERROR_OUT;
  120.    }
  121. if (nRetransmitMode != SNMPAPI_OFF && nRetransmitMode != SNMPAPI_ON)
  122.    {
  123.    lError = SNMPAPI_MODE_INVALID;
  124.    goto ERROR_OUT;
  125.    }
  126. EnterCriticalSection (&cs_TASK);
  127. TaskData.nRetransmitMode = nRetransmitMode;
  128. LeaveCriticalSection (&cs_TASK);
  129. return (SNMPAPI_SUCCESS);
  130. //
  131. ERROR_OUT:
  132. return (SaveError (0, lError));
  133. } // end_SnmpSetRetransmitMode()
  134. SNMPAPI_STATUS SNMPAPI_CALL
  135.    SnmpGetTimeout (IN  HSNMP_ENTITY hEntity,
  136.                    OUT smiLPTIMETICKS nPolicyTimeout,
  137.                    OUT smiLPTIMETICKS nActualTimeout)
  138. {
  139. DWORD nEntity;
  140. SNMPAPI_STATUS lError;
  141. LPENTITY pEntity;
  142. if (TaskData.hTask == 0)
  143.    {
  144.    lError = SNMPAPI_NOT_INITIALIZED;
  145.    goto ERROR_OUT;
  146.    }
  147. nEntity = HandleToUlong(hEntity) - 1;
  148. if (!snmpValidTableEntry(&EntsDescr, nEntity))
  149.    {
  150.    lError = SNMPAPI_ENTITY_INVALID;
  151.    goto ERROR_OUT;
  152.    }
  153. pEntity = snmpGetTableEntry(&EntsDescr, nEntity);
  154. if (!nPolicyTimeout && !nActualTimeout)
  155.    {
  156.    lError = SNMPAPI_NOOP;
  157.    goto ERROR_OUT;
  158.    }
  159. // Intervals are specified and stored as centiseconds
  160. if (nPolicyTimeout)
  161.    {
  162.    if (IsBadWritePtr (nPolicyTimeout, sizeof(smiTIMETICKS)))
  163.       {
  164.       lError  = SNMPAPI_ALLOC_ERROR;
  165.       goto ERROR_OUT;
  166.       }
  167.    *nPolicyTimeout = pEntity->nPolicyTimeout;
  168.    }
  169. if (nActualTimeout)
  170.    {
  171.    if (IsBadWritePtr (nActualTimeout, sizeof(smiTIMETICKS)))
  172.       {
  173.       lError  = SNMPAPI_ALLOC_ERROR;
  174.       goto ERROR_OUT;
  175.       }
  176.    *nActualTimeout = pEntity->nActualTimeout;
  177.    }
  178. return (SNMPAPI_SUCCESS);
  179. //
  180. ERROR_OUT:
  181. return (SaveError (0, lError));
  182. } // end_SnmpGetTimeout()
  183. SNMPAPI_STATUS SNMPAPI_CALL
  184.    SnmpSetTimeout (IN HSNMP_ENTITY hEntity,
  185.                    IN smiTIMETICKS nPolicyTimeout)
  186. {
  187. DWORD nEntity;
  188. SNMPAPI_STATUS lError;
  189. LPENTITY pEntity;
  190. if (TaskData.hTask == 0)
  191.    {
  192.    lError = SNMPAPI_NOT_INITIALIZED;
  193.    goto ERROR_OUT;
  194.    }
  195. nEntity = HandleToUlong(hEntity) - 1;
  196. if (!snmpValidTableEntry(&EntsDescr, nEntity))
  197.    {
  198.    lError = SNMPAPI_ENTITY_INVALID;
  199.    goto ERROR_OUT;
  200.    }
  201. pEntity = snmpGetTableEntry(&EntsDescr, nEntity);
  202. EnterCriticalSection (&cs_ENTITY);
  203. // Timeout interval is specified and stored in centiseconds
  204. pEntity->nPolicyTimeout = nPolicyTimeout;
  205. LeaveCriticalSection (&cs_ENTITY);
  206. return (SNMPAPI_SUCCESS);
  207. //
  208. ERROR_OUT:
  209. return (SaveError (0, lError));
  210. } // end_SnmpSetTimeout()
  211. SNMPAPI_STATUS SNMPAPI_CALL
  212.    SnmpGetRetry (IN HSNMP_ENTITY hEntity,
  213.                  OUT smiLPUINT32 nPolicyRetry,
  214.                  OUT smiLPUINT32 nActualRetry)
  215. {
  216. DWORD nEntity;
  217. SNMPAPI_STATUS lError;
  218. LPENTITY pEntity;
  219. if (TaskData.hTask == 0)
  220.    {
  221.    lError = SNMPAPI_NOT_INITIALIZED;
  222.    goto ERROR_OUT;
  223.    }
  224. nEntity = HandleToUlong(hEntity) - 1;
  225. if (!snmpValidTableEntry(&EntsDescr, nEntity))
  226.    {
  227.    lError = SNMPAPI_ENTITY_INVALID;
  228.    goto ERROR_OUT;
  229.    }
  230. pEntity = snmpGetTableEntry(&EntsDescr, nEntity);
  231. if (!nPolicyRetry && !nActualRetry)
  232.    {
  233.    lError = SNMPAPI_NOOP;
  234.    goto ERROR_OUT;
  235.    }
  236. if (nPolicyRetry)
  237.    {
  238.    if (IsBadWritePtr (nPolicyRetry, sizeof(smiUINT32)))
  239.       {
  240.       lError = SNMPAPI_ALLOC_ERROR;
  241.       goto ERROR_OUT;
  242.       }
  243.    *nPolicyRetry = pEntity->nPolicyRetry;
  244.    }
  245. if (nActualRetry)
  246.    {
  247.    if (IsBadWritePtr (nActualRetry, sizeof(smiUINT32)))
  248.       {
  249.       lError = SNMPAPI_ALLOC_ERROR;
  250.       goto ERROR_OUT;
  251.       }
  252.    *nActualRetry = pEntity->nActualRetry;
  253.    }
  254. return (SNMPAPI_SUCCESS);
  255. ERROR_OUT:
  256. return (SaveError (0, lError));
  257. } // end_SnmpGetRetry()
  258. SNMPAPI_STATUS SNMPAPI_CALL
  259.    SnmpSetRetry (IN HSNMP_ENTITY hEntity,
  260.                  IN smiUINT32 nPolicyRetry)
  261. {
  262. DWORD nEntity;
  263. SNMPAPI_STATUS lError;
  264. LPENTITY pEntity;
  265. if (TaskData.hTask == 0)
  266.    {
  267.    lError = SNMPAPI_NOT_INITIALIZED;
  268.    goto ERROR_OUT;
  269.    }
  270. nEntity = HandleToUlong(hEntity) - 1;
  271. if (!snmpValidTableEntry(&EntsDescr, nEntity))
  272.    {
  273.    lError = SNMPAPI_ENTITY_INVALID;
  274.    goto ERROR_OUT;
  275.    }
  276. pEntity = snmpGetTableEntry(&EntsDescr, nEntity);
  277. EnterCriticalSection (&cs_ENTITY);
  278. pEntity->nPolicyRetry = nPolicyRetry;
  279. LeaveCriticalSection (&cs_ENTITY);
  280. return (SNMPAPI_SUCCESS);
  281. //
  282. ERROR_OUT:
  283. return (SaveError (0, lError));
  284. } // end_SnmpSetRetry()