(file) Return to snmpDeliverTrap_netsnmp.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Handler / snmpIndicationHandler

Diff for /pegasus/src/Pegasus/Handler/snmpIndicationHandler/snmpDeliverTrap_netsnmp.cpp between version 1.24 and 1.25

version 1.24, 2009/05/05 09:01:35 version 1.25, 2010/12/22 12:19:06
Line 91 
Line 91 
     const Uint32& portNumber,     const Uint32& portNumber,
     const Uint16& snmpVersion,     const Uint16& snmpVersion,
     const String& engineID,     const String& engineID,
       const Uint8& snmpSecLevel,
       const Uint8& snmpSecAuthProto,
       const Array<Uint8>& snmpSecAuthKey,
       const Uint8& snmpSecPrivProto,
       const Array<Uint8>& snmpSecPrivKey,
     const Array<String>& vbOids,     const Array<String>& vbOids,
     const Array<String>& vbTypes,     const Array<String>& vbTypes,
     const Array<String>& vbValues)     const Array<String>& vbValues)
Line 104 
Line 109 
     struct snmp_pdu* snmpPdu;     struct snmp_pdu* snmpPdu;
  
     // Creates a SNMP session     // Creates a SNMP session
     _createSession(targetHost, targetHostFormat, portNumber, securityName,      _createSession(
                    sessionHandle, sessionPtr);          targetHost,
           targetHostFormat,
           portNumber,
           securityName,
           snmpVersion,
           engineID,
           snmpSecLevel,
           snmpSecAuthProto,
           snmpSecAuthKey,
           snmpSecPrivProto,
           snmpSecPrivKey,
           sessionHandle,
           sessionPtr);
  
     try     try
     {     {
Line 175 
Line 192 
     Uint16 targetHostFormat,     Uint16 targetHostFormat,
     Uint32 portNumber,     Uint32 portNumber,
     const String& securityName,     const String& securityName,
       Uint16 snmpVersion,
       const String& engineID,
       const Uint8& snmpSecLevel,
       const Uint8& snmpSecAuthProto,
       const Array<Uint8>& snmpSecAuthKey,
       const Uint8& snmpSecPrivProto,
       const Array<Uint8>& snmpSecPrivKey,
     void*& sessionHandle,     void*& sessionHandle,
     snmp_session*& sessionPtr)     snmp_session*& sessionPtr)
 { {
Line 195 
Line 219 
  
         // peername has format: targetHost:portNumber         // peername has format: targetHost:portNumber
         snmpSession.peername =         snmpSession.peername =
             (char*)malloc((size_t)(strlen(targetHostCStr) + 1 + 32));              (char*)calloc(1,strlen(targetHostCStr) + 1 + 32);
  
         if (targetHostFormat == _IPV6_ADDRESS)         if (targetHostFormat == _IPV6_ADDRESS)
         {         {
Line 254 
Line 278 
                 exceptionStr));                 exceptionStr));
         }         }
  
           free(snmpSession.peername);
   
           switch (snmpVersion)
           {
               case _SNMPv1_TRAP:
               {
                   sessionPtr->version = SNMP_VERSION_1;
                   _addCommunity(sessionPtr,securityName);
                  break;
   
               }
               case _SNMPv2C_TRAP:
               {
                   sessionPtr->version = SNMP_VERSION_2c;
                   _addCommunity(sessionPtr,securityName);
                   break;
               }
               case _SNMPv3_TRAP:
               {
                   sessionPtr->version = SNMP_VERSION_3;
                   CString securityNameCStr = securityName.getCString();
                   size_t securityNameLen = strlen(securityNameCStr);
                   SNMP_FREE(sessionPtr->securityName);
                   sessionPtr->securityName = (char *)calloc(1,securityNameLen+1);
                   sessionPtr->securityNameLen = securityNameLen;
                   memcpy(sessionPtr->securityName, (const char*)securityNameCStr,
                       securityNameLen);
   
                   CString engineIdCStr = engineID.getCString();
                   size_t engineIdHexLen = strlen(engineIdCStr);
                   size_t engineIdBinLen = 0;
                   u_char *engineIdBin = (u_char *)calloc(1,engineIdHexLen);
                   free(sessionPtr->securityEngineID);
                   if(!snmp_hex_to_binary(&engineIdBin, &engineIdHexLen,
                       &engineIdBinLen, 1,engineIdCStr))
                   {
                       PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,
                           "Snmp Indication Handler failed to generate binary"
                               " engine ID for sending the SNMPv3 trap.");
                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
                           MessageLoaderParms(
                               "Handler.snmpIndicationHandler."
                                   "snmpIndicationHandler."
                               "FAILED_TO_DELIVER_TRAP",
                           "Failed to deliver trap."));
                   }
                   sessionPtr->securityEngineIDLen = engineIdBinLen;
                   sessionPtr->securityEngineID = engineIdBin;
   
                   switch(snmpSecLevel)
                   {
                       case 1:
                           sessionPtr->securityLevel = SNMP_SEC_LEVEL_NOAUTH;
                           break;
                       case 2:
                           sessionPtr->securityLevel = SNMP_SEC_LEVEL_AUTHNOPRIV;
                           break;
                       case 3:
                           sessionPtr->securityLevel = SNMP_SEC_LEVEL_AUTHPRIV;
                           break;
                       default:
                           //use the dedault in the net-snmp conf file.
                           break;
                   }
   
                   SNMP_FREE(sessionPtr->securityAuthProto);
                   if(snmpSecAuthProto == 1) // MD5
                   {
                       sessionPtr->securityAuthProto = snmp_duplicate_objid(
                           usmHMACMD5AuthProtocol,
                           USM_AUTH_PROTO_MD5_LEN);
                       sessionPtr->securityAuthProtoLen = USM_AUTH_PROTO_MD5_LEN;
                   }
                   else if(snmpSecAuthProto == 2)// SHA
                   {
                       sessionPtr->securityAuthProto = snmp_duplicate_objid(
                           usmHMACSHA1AuthProtocol,
                           USM_AUTH_PROTO_SHA_LEN);
                       sessionPtr->securityAuthProtoLen = USM_AUTH_PROTO_SHA_LEN;
                   }
                   // use the default in net-snmp conf files.
   
                   if(snmpSecAuthKey.size() > 0)
                   {
                       for(Uint32 i=0;i<snmpSecAuthKey.size();i++)
                       {
                           sessionPtr->securityAuthKey[i] = snmpSecAuthKey[i];
                       }
                       sessionPtr->securityAuthKeyLen = snmpSecAuthKey.size();
                   }
   
                   SNMP_FREE(sessionPtr->securityPrivProto);
                   //Privacy
                   if(snmpSecPrivProto == 1) //DES
                   {
                       sessionPtr->securityPrivProto = snmp_duplicate_objid(
                           usmDESPrivProtocol,
                           USM_PRIV_PROTO_DES_LEN);
                       sessionPtr->securityPrivProtoLen = USM_PRIV_PROTO_DES_LEN;
                   }
                   else if(snmpSecPrivProto == 2) // AES
                   {
                       sessionPtr->securityPrivProto = snmp_duplicate_objid(
                           usmAESPrivProtocol,
                           USM_PRIV_PROTO_AES_LEN);
                       sessionPtr->securityPrivProtoLen = USM_PRIV_PROTO_AES_LEN;
                   }
                   // use the defaults in net-snmp conf files
   
                   // Privacy Key
                   if(snmpSecPrivKey.size() > 0)
                   {
                       for(Uint32 j=0;j<snmpSecPrivKey.size();j++)
                       {
                           sessionPtr->securityPrivKey[j] = snmpSecPrivKey[j];
                       }
                       sessionPtr->securityPrivKeyLen = snmpSecPrivKey.size();
                   }
                   break;
               }
               default:
               {
                   PEG_METHOD_EXIT();
                   throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_NOT_SUPPORTED,
                       MessageLoaderParms(
                           _MSG_VERSION_NOT_SUPPORTED_KEY,
                           _MSG_VERSION_NOT_SUPPORTED));
                   break;
               }
           }
   
       }
       catch (...)
       {
           _destroySession(sessionHandle);
   
           PEG_METHOD_EXIT();
           throw;
       }
   
       PEG_METHOD_EXIT();
   }
   
   void snmpDeliverTrap_netsnmp::_addCommunity(
       struct snmp_session*& sessionPtr,
       const String& securityName)
   {
       PEG_METHOD_ENTER(TRC_IND_HANDLER,
           "snmpDeliverTrap_netsnmp::_addCommunity");
   
         // Community Name, default is public         // Community Name, default is public
         String communityName;         String communityName;
         if (securityName.size() == 0)         if (securityName.size() == 0)
Line 265 
Line 439 
             communityName = securityName;             communityName = securityName;
         }         }
  
         free(snmpSession.peername);  
   
         free(sessionPtr->community);         free(sessionPtr->community);
  
         CString communityNameCStr = communityName.getCString();         CString communityNameCStr = communityName.getCString();
         size_t communityNameLen = strlen(communityNameCStr);         size_t communityNameLen = strlen(communityNameCStr);
  
         sessionPtr->community = (u_char*)malloc(communityNameLen);      sessionPtr->community = (u_char*)calloc(1,communityNameLen+1);
  
         memcpy(sessionPtr->community, (const char*)communityNameCStr,         memcpy(sessionPtr->community, (const char*)communityNameCStr,
                communityNameLen);                communityNameLen);
         sessionPtr->community_len = communityNameLen;  
     }  
     catch (...)  
     {  
         _destroySession(sessionHandle);  
   
         PEG_METHOD_EXIT();  
         throw;  
     }  
  
       sessionPtr->community_len = communityNameLen;
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
 } }
  
Line 319 
Line 483 
     {     {
         case _SNMPv1_TRAP:         case _SNMPv1_TRAP:
         {         {
   
             sessionPtr->version = SNMP_VERSION_1;  
   
             // Create the PDU             // Create the PDU
             snmpPdu = snmp_pdu_create(SNMP_MSG_TRAP);             snmpPdu = snmp_pdu_create(SNMP_MSG_TRAP);
  
Line 360 
Line 521 
             break;             break;
         }         }
         case _SNMPv2C_TRAP:         case _SNMPv2C_TRAP:
           case _SNMPv3_TRAP:
         {         {
             sessionPtr->version = SNMP_VERSION_2c;  
   
             // Create the PDU             // Create the PDU
             snmpPdu = snmp_pdu_create(SNMP_MSG_TRAP2);             snmpPdu = snmp_pdu_create(SNMP_MSG_TRAP2);
  
Line 465 
Line 625 
     CString trapOidCStr = trapOid.getCString();     CString trapOidCStr = trapOid.getCString();
  
     char* trapOidCopy = strdup(trapOidCStr);     char* trapOidCopy = strdup(trapOidCStr);
     char* numericEntOid = (char*) malloc(strlen(trapOidCStr));      char* numericEntOid = (char*) malloc(strlen(trapOidCStr)+1);
  
     try     try
     {     {
Line 565 
Line 725 
  
         }         }
  
           SNMP_FREE(snmpPdu->enterprise);
         snmpPdu->enterprise = (oid*) malloc(enterpriseOidLength * sizeof(oid));         snmpPdu->enterprise = (oid*) malloc(enterpriseOidLength * sizeof(oid));
         memcpy(snmpPdu->enterprise, enterpriseOid,         memcpy(snmpPdu->enterprise, enterpriseOid,
             enterpriseOidLength * sizeof(oid));             enterpriseOidLength * sizeof(oid));


Legend:
Removed from v.1.24  
changed lines
  Added in v.1.25

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2