⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 winextdll.c

📁 开发snmp的开发包有两个开放的SNMP开发库
💻 C
📖 第 1 页 / 共 5 页
字号:
          case ASN_TIMETICKS:          case ASN_OPAQUE:                                pVarBindList.list->value.asnValue.number = *(var->val.integer);            break;                        case ASN_OBJECT_ID:                        // Convert OID from Net-SNMP to Windows            temp_oid = var->val.objid;            temp_oid_length = var->val_len / sizeof(oid);                                   DEBUGMSGTL(("winExtDLL","Sizeof var->val.objid: %d\n", temp_oid_length));            DEBUGMSGTL(("winExtDLL","OID: from user "));            DEBUGMSGOID(("winExtDLL", temp_oid, temp_oid_length));            DEBUGMSG(("winExtDLL","\n"));                        mySnmpVarBind->name.ids = (UINT *) SnmpUtilMemAlloc(sizeof (UINT) * temp_oid_length);            if (mySnmpVarBind->name.ids) {              // Actual copy              for (i = 0; i < temp_oid_length; i++) {                mySnmpVarBind->name.ids[i] = (UINT)temp_oid[i];              }              mySnmpVarBind->name.idLength = i;                            // Print OID              DEBUGMSGTL(("winExtDLL","Windows OID length: %d\n",mySnmpVarBind->name.idLength));              DEBUGMSGTL(("winExtDLL","Windows OID: "));              DEBUGMSGWINOID(("winExtDLL", mySnmpVarBind));              DEBUGMSG(("winExtDLL", "\n"));            }            else {              DEBUGMSGTL(("winExtDLL", "\nyCould not allocate memory for Windows SNMP varbind.\n"));              return SNMP_ERR_GENERR;            }            SnmpUtilOidCpy(&pVarBindList.list->value.asnValue.object, &mySnmpVarBind->name);            //pVarBindList.list->value.asnValue.object = mySnmpVarBind->name;            if (mySnmpVarBind)              SnmpUtilVarBindFree(mySnmpVarBind);                      default:            break;              }          if (xSnmpExtensionQueryEx) {          DEBUGMSGTL(("winExtDLL", "Calling xSnmpExtensionQueryEx\n"));          result = xSnmpExtensionQueryEx(SNMP_PDU_SET, 1, &pVarBindList, NULL, &pErrorStatus, &pErrorIndex);        }        else {           DEBUGMSGTL(("winExtDLL", "Calling xSnmpExtensionQuery\n"));          result = xSnmpExtensionQuery(SNMP_PDU_SET, &pVarBindList, &pErrorStatus, &pErrorIndex);        }        DEBUGMSGTL(("winExtDLL", "win: Result of xSnmpExtensionQuery: %d\n",result));                DEBUGMSGTL(("winExtDLL", "win: Error status of xSnmpExtensionQuery: %d\n",pErrorStatus));        DEBUGMSGTL(("winExtDLL", "win: asnType: %d\n",pVarBindList.list->value.asnType));        if (result == 0) {          DEBUGMSGTL(("winExtDLL", "\nyxWindows SnmpExtensionQuery failure.\n"));          return SNMP_ERR_GENERR;        }                if (&pVarBindList)          SnmpUtilVarBindListFree(&pVarBindList);        if (pErrorStatus) {          switch (pErrorStatus) {            case SNMP_ERRORSTATUS_INCONSISTENTNAME:              return SNMP_ERR_GENERR;            default:              return pErrorStatus;              break;          }        }      }      break;         case MODE_SET_UNDO:    case MODE_SET_COMMIT:    case MODE_SET_FREE:      break;          default:        snmp_log(LOG_WARNING, "unsupported mode for winExtDLL called (%d)\n",                               reqinfo->mode);        return SNMP_ERR_NOERROR;    }    return SNMP_ERR_NOERROR;}void winExtDLL_free_config_winExtDLL(void) {}void read_ExtensionAgents_list() {  HKEY          hKey;   unsigned char * key_value = NULL;  DWORD         key_value_size = 0;  DWORD         key_value_type = 0;  DWORD         valueSize = MAX_VALUE_NAME;   int           i;  TCHAR         valueName[MAX_VALUE_NAME];  TCHAR         valueName2[MAX_VALUE_NAME];  DWORD         retCode;    DEBUGMSGTL(("winExtDLL", "read_ExtensionAgents_list called\n"));  /* The Windows SNMP service stores the list of extension agents to be loaded in the   * registry under HKLM\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\ExtensionAgents.   * This list contains a list of other keys that contain the actual file path to the DLL.   */  /* Open SYSTEM\\CurrentControlSet\\Services\\SNMP\\Parameters\\ExtensionAgent */  retCode = RegOpenKeyExA(      HKEY_LOCAL_MACHINE,       "SYSTEM\\CurrentControlSet\\Services\\SNMP\\Parameters\\ExtensionAgents",       0,       KEY_QUERY_VALUE,       &hKey);    if (retCode == ERROR_SUCCESS) {    /* Enumerate list of extension agents.  This is a list of other keys that contain the     * actual filename of the extension agent.  */    for (i=0; retCode==ERROR_SUCCESS; i++)     {       valueSize = MAX_VALUE_NAME;       valueName[0] = '\0';       retCode = RegEnumValue(          hKey,          i,          valueName,           &valueSize,           NULL,           NULL,          NULL,          NULL);            if (retCode == ERROR_SUCCESS )       {         /* Get key name that contains the actual filename of the extension agent */        DEBUGMSGTL(("winExtDLL", "-----------------------------------------\n"));        DEBUGMSGTL(("winExtDLL", "Registry: (%d) %s\n", i+1, valueName));                key_value_size = MAX_VALUE_NAME;        if (RegQueryValueExA(              hKey,               valueName,               NULL,               &key_value_type,               valueName2,               &key_value_size) == ERROR_SUCCESS) {        }        DEBUGMSGTL(("winExtDLL", "key_value: %s\n",valueName2));        read_ExtensionAgents_list2(valueName2);        extDLLs_index++;      }    }    if (extDLLs_index)      extDLLs_index--;  }}void read_ExtensionAgents_list2(const TCHAR *keyName) {  HKEY          hKey;   unsigned char * key_value = NULL;  DWORD         key_value_size = 0;  DWORD         key_value_type = 0;  DWORD         valueSize = MAX_VALUE_NAME;   TCHAR         valueName[MAX_VALUE_NAME];  TCHAR         valueNameExpanded[MAX_VALUE_NAME];  int           i;  DWORD         retCode;    DEBUGMSGTL(("winExtDLL", "read_ExtensionAgents_list2 called\n"));  DEBUGMSGTL(("winExtDLL", "Registry: Opening key %s\n", keyName));  /* Open extension agent's key */  retCode = RegOpenKeyExA(      HKEY_LOCAL_MACHINE,       keyName,       0,       KEY_QUERY_VALUE,       &hKey);    if (retCode == ERROR_SUCCESS) {    /* Read Pathname value */    DEBUGMSGTL(("winExtDLL", "Registry: Reading value for %s\n", keyName));           key_value_size = MAX_VALUE_NAME;    retCode = RegQueryValueExA(        hKey,         "Pathname",         NULL,         &key_value_type,         valueName,         &key_value_size);        if (retCode == ERROR_SUCCESS) {      valueName[key_value_size-1] = NULL;               /* Make sure last element is a NULL */              DEBUGMSGTL(("winExtDLL", "Extension agent Pathname size: %d\n",key_value_size));      DEBUGMSGTL(("winExtDLL", "Extension agent Pathname: %s\n",valueName));      if (ExpandEnvironmentStrings(valueName, valueNameExpanded, MAX_VALUE_NAME)) {        DEBUGMSGTL(("winExtDLL", "Extension agent Pathname expanded: %s\n",valueNameExpanded));        if (extDLLs_index < MAX_WINEXT_DLLS) {          extDLLs[extDLLs_index] = strdup(valueNameExpanded);                    if (extDLLs[extDLLs_index]) {            strcpy(extDLLs[extDLLs_index], valueNameExpanded );            DEBUGMSGTL(("winExtDLL", "Extension agent Pathname expanded extDLLs: %s\n",extDLLs[extDLLs_index]));            DEBUGMSGTL(("winExtDLL", "Extension agent Pathname size: %d\n",strlen(extDLLs[extDLLs_index])));          }          else {            DEBUGMSGTL(("winExtDLL", "Could not allocate memory for extDLLs[%d]\n",extDLLs_index));          }        }      }      else {        DEBUGMSGTL(("winExtDLL", "ExpandEnvironmentStrings failed\n"));      }          }  }}// Called by alarm to check for traps waiting to be processed.void subagentTrapCheck() {  DWORD dwWaitResult;  BOOL bResult;  int i;  netsnmp_variable_list *notification_vars = NULL;  // Windows SNMP  AsnObjectIdentifier   pEnterprise;  AsnInteger            pGenericTrap;  AsnInteger            pSpecificTrap;  AsnTimeticks          pTimeStamp;  SnmpVarBindList       pVariableBindings;   DEBUGMSGTL(("winExtDLL", "subagentTrapMonitor called\n"));  dwWaitResult = WaitForMultipleObjects(      subagentTrapEvents_index,      subagentTrapEvents,      FALSE,      0);  if (! (dwWaitResult) || (dwWaitResult == WAIT_TIMEOUT))    return;    DEBUGMSGTL(("winExtDLL", "---------------------------------------------\n"));  DEBUGMSGTL(("winExtDLL", "subagentTrapCheck found a trap event (index: %d)\n",dwWaitResult));    /* Loop through all the winExtensionAgent's looking for a matching handler */  for (i=0;  winExtensionAgent[i].xSnmpExtensionInit && i < MAX_WINEXT_DLLS; i++) {    DEBUGMSGTL(("winExtDLL", "Looping through all the winExtensionAgent's looking for a matching trap handler.\n"));    if (winExtensionAgent[i].subagentTrapEvent == subagentTrapEvents[dwWaitResult]) {      DEBUGMSGTL(("winExtDLL", "Found match: "));      DEBUGMSGOID(("winExtDLL", winExtensionAgent[i].name, winExtensionAgent[i].name_length));      DEBUGMSG(("winExtDLL", "\n"));      if (winExtensionAgent[i].xSnmpExtensionTrap)        DEBUGMSGTL(("winExtDLL", "xSnmpExtensionTrap exists for this subagent\n"));      else {        DEBUGMSGTL(("winExtDLL", "xSnmpExtensionTrap does NOT exist for this subagent\n"));        continue;      }      pEnterprise.ids = NULL;      pEnterprise.idLength = 0;      pGenericTrap = pSpecificTrap = NULL;      pTimeStamp = 0;      pVariableBindings.list = NULL;      pVariableBindings.len = 0;      DEBUGMSGTL(("winExtDLL", "Calling SnmpExtensionTrap\n"));      bResult = winExtensionAgent[i].xSnmpExtensionTrap(          &pEnterprise,          &pGenericTrap,          &pSpecificTrap,          &pTimeStamp,          &pVariableBindings);            DEBUGMSGTL(("winExtDLL", "result of SnmpExtensionTrap call:  %d\n",bResult));            DEBUGMSGTL(("winExtDLL", "GenericTrap: %d\n",pGenericTrap));      DEBUGMSGTL(("winExtDLL", "SpecificTrap: %d\n",pSpecificTrap));      if (pEnterprise.idLength)        DEBUGMSGTL(("winExtDLL", "pEnterprise is not 0\n"));      else        DEBUGMSGTL(("winExtDLL", "pEnterprise is 0\n"));      // Assume that if enterprise length is >0, it's a real trap and not a cleanup call      // FIXME:  Not sure if this is correct.  Need to test with agent that sends a non-enterprise trap      if (pEnterprise.idLength) {                // Send the trap        send_trap(            &pEnterprise,             &pGenericTrap,             &pSpecificTrap,             &pTimeStamp,            &pVariableBindings);      }      // Look for more traps from this agent (if result is TRUE there are more traps)      while(bResult) {        DEBUGMSGTL(("winExtDLL", "More traps to process.  Calling SnmpExtensionTrap again\n"));        pEnterprise.ids = NULL;        pEnterprise.idLength = 0;        pGenericTrap = pSpecificTrap = NULL;        pTimeStamp = 0;        pVariableBindings.list = NULL;        pVariableBindings.len = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -