📄 pxy3_chk.c
字号:
EBufferUsed (&pPkt->community)); mpModel = SNMP_VERSION_3; secModel = pPkt->msg_sec_model; EBufferAllocateLoad (BFL_IS_STATIC, &secName, EBufferStart (&pPkt->msg_sec_name), EBufferUsed (&pPkt->msg_sec_name)); if ((pPkt->msg_flags & ETC_V3_AUTH) != 0) { if ((pPkt->msg_flags & ETC_V3_PRIV) != 0) secLevel = ETC_SEC_LEVEL_PRIV; else secLevel = ETC_SEC_LEVEL_AUTH; } else secLevel = ETC_SEC_LEVEL_NONE; break; default: return (ENVOY_ERR_NO_TARGET); } for (pProxy = root_proxy; pProxy != 0; pProxy = SNMP_Proxy_Next_Proxy (pProxy)) { /* Step 0: Skip inactive proxy objects */ if (SNMP_Proxy_Get_Status (pProxy) != ETC_RS_ACTIVE) continue; /* Step 1: Check to see if the PDU type matches this proxy object */ switch (SNMP_Proxy_Get_Proxy_Type (pProxy)) { case PROXY_TYPE_READ: if ((pPkt->pdu_type != GET_REQUEST_PDU) && (pPkt->pdu_type != GET_NEXT_REQUEST_PDU) && (pPkt->pdu_type != GET_BULK_REQUEST_PDU)) continue; break; case PROXY_TYPE_WRITE: if (pPkt->pdu_type != SET_REQUEST_PDU) continue; break; default: continue; } /* * Step 2: Check to see if the context engine id of the PDU * matches that of this proxy object */ if ((EBufferUsed (&contextEngineID) != SNMP_Proxy_Get_Context_Engine_ID_Len (pProxy)) || (MEMCMP (EBufferStart (&contextEngineID), SNMP_Proxy_Get_Context_Engine_ID (pProxy), EBufferUsed (&contextEngineID)) != 0)) continue; /* Step 3: Check to see if the context names match */ if ((EBufferUsed (&contextName) != SNMP_Proxy_Get_Context_Name_Len (pProxy)) || (MEMCMP_NULLOK (EBufferStart (&contextName), SNMP_Proxy_Get_Context_Name (pProxy), EBufferUsed (&contextName)) != 0)) continue; /* * Step 4: Look up the entry in the snmpTargetParamsTable * to check remaining parameters. */ pParams = SNMP_Target_Params_Lookup (SNMP_Proxy_Get_Target_Params_In (pProxy), SNMP_Proxy_Get_Target_Params_In_Len (pProxy)); if ((pParams == 0) || (SNMP_Target_Params_Get_Status (pParams) != ETC_RS_ACTIVE)) continue; /* * Step 5: Check the message processing model, security level, * security model, and security name. */ if ((mpModel == SNMP_Target_Params_Get_MP_Model (pParams)) && (secLevel == SNMP_Target_Params_Get_Sec_Level (pParams)) && (secModel == SNMP_Target_Params_Get_Sec_Model (pParams)) && (EBufferUsed (&secName) == SNMP_Target_Params_Get_Sec_Name_Len (pParams)) && (MEMCMP (EBufferStart (&secName), SNMP_Target_Params_Get_Sec_Name (pParams), EBufferUsed (&secName)) == 0)) break; } if ((pProxy == 0) || (SNMP_Proxy_Get_Single_Target_Out_Len (pProxy) == 0)) { EBufferClean (&contextEngineID); EBufferClean (&contextName); EBufferClean (&secName);#if INSTALL_ENVOY_SNMP_COEXISTENCE EBufferClean (&communityString);#endif return (ENVOY_ERR_NO_TARGET); } /* * If we made it this far, we have a valid proxy object. * Now we need to look up a target and see if it's valid. */ pTaddr = SNMP_Target_Addr_Lookup (SNMP_Proxy_Get_Single_Target_Out (pProxy), SNMP_Proxy_Get_Single_Target_Out_Len (pProxy)); if ((pTaddr == 0) || (SNMP_Target_Addr_Get_Status (pTaddr) != ETC_RS_ACTIVE)) { EBufferClean (&contextEngineID); EBufferClean (&contextName); EBufferClean (&secName);#if INSTALL_ENVOY_SNMP_COEXISTENCE EBufferClean (&communityString);#endif return (ENVOY_ERR_NO_TARGET); } /* We need a valid target addr and target params */ pParams = SNMP_Target_Params_Lookup (SNMP_Target_Addr_Get_Params (pTaddr), SNMP_Target_Addr_Get_Params_Len (pTaddr)); if ((pParams == 0) || (SNMP_Target_Params_Get_Status (pParams) != ETC_RS_ACTIVE)) { EBufferClean (&contextEngineID); EBufferClean (&contextName); EBufferClean (&secName);#if INSTALL_ENVOY_SNMP_COEXISTENCE EBufferClean (&communityString);#endif return (ENVOY_ERR_NO_TARGET); }#if INSTALL_ENVOY_SNMP_COEXISTENCE /* * If our target is not an SNMPv3 target, we need to look up * a community object to see if we have the necessary information */ if (SNMP_Target_Params_Get_MP_Model (pParams) != SNMP_VERSION_3) { for (pCommunity = SNMP_Community_Next_Community ((SNMP_COMMUNITY_T *) 0) ; pCommunity != 0 ; pCommunity = SNMP_Community_Next_Community (pCommunity)) { if ((SNMP_Community_Get_Sec_Name_Len (pCommunity) != SNMP_Target_Params_Get_Sec_Name_Len (pParams)) || (SNMP_Community_Get_Con_ID_Len (pCommunity) != EBufferUsed (&contextEngineID)) || (SNMP_Community_Get_Con_Name_Len (pCommunity) != EBufferUsed (&contextName)) || (MEMCMP (SNMP_Community_Get_Sec_Name (pCommunity), SNMP_Target_Params_Get_Sec_Name (pParams), SNMP_Community_Get_Sec_Name_Len (pCommunity)) != 0) || (MEMCMP (SNMP_Community_Get_Con_ID (pCommunity), EBufferStart (&contextEngineID), EBufferUsed (&contextEngineID)) != 0) || (MEMCMP_NULLOK (SNMP_Community_Get_Con_Name (pCommunity), EBufferStart (&contextName), EBufferUsed (&contextName)) != 0)) continue; /* We have found a match. Overwrite previous information, * if there was any. */ EBufferAllocateLoad (BFL_IS_ALLOC, &communityString, SNMP_Community_Get_Name (pCommunity), SNMP_Community_Get_Name_Len (pCommunity)); EBufferAllocateLoad (BFL_IS_ALLOC, &pPkt->comm_entry, SNMP_Community_Get_Index (pCommunity), SNMP_Community_Get_Index_Len(pCommunity)); break; } if (pCommunity == 0) { EBufferClean (&contextEngineID); EBufferClean (&contextName); EBufferClean (&secName);#if INSTALL_ENVOY_SNMP_COEXISTENCE EBufferClean (&communityString);#endif return (ENVOY_ERR_NO_TARGET); } }#if !INSTALL_ENVOY_SNMP_USE_V2_TYPES /* * If our target is an SNMPv1 target, then we need to make sure we're * not sending it any Counter64 objects. We only need to check * set requests. */ if ((SNMP_Target_Params_Get_MP_Model (pParams) == SNMP_VERSION_1) && (pPkt->pdu_type == SET_REQUEST_PDU)) { for (vbCount = 0, pVb = pPkt->pdu.std_pdu.std_vbl.vblist ; vbCount < pPkt->pdu.std_pdu.std_vbl.vbl_count ; vbCount++, pVb++) { if (pVb->vb_data_flags_n_type == VT_COUNTER64) { EBufferClean (&contextEngineID); EBufferClean (&contextName); EBufferClean (&secName); EBufferClean (&communityString); return (ENVOY_ERR_NO_TARGET); } } }#endif /* #if !INSTALL_ENVOY_SNMP_USE_V2_TYPES */#endif /* #if INSTALL_ENVOY_SNMP_COEXISTENCE */ /* * Now we just assemble the information we need to create a new * Request-PDU. */ pTargList = SNMP_memory_alloc (sizeof (TARGET_LIST_T)); if (pTargList == 0) { EBufferClean (&contextEngineID); EBufferClean (&contextName); EBufferClean (&secName);#if INSTALL_ENVOY_SNMP_COEXISTENCE EBufferClean (&communityString);#endif return (ENVOY_ERR_INSUFFICIENT_MEMORY); } init_target_list (pTargList); pTargList->next = 0; pTargList->timeout = SNMP_Target_Addr_Get_Timeout (pTaddr); pTargList->mp_model = SNMP_Target_Params_Get_MP_Model (pParams); pTargList->sec_level = SNMP_Target_Params_Get_Sec_Level (pParams); pTargList->sec_model = SNMP_Target_Params_Get_Sec_Model (pParams); if ((build_object_id (SNMP_Target_Addr_Get_TDomain (pTaddr)->num_components, SNMP_Target_Addr_Get_TDomain (pTaddr)->component_list, &(pTargList->tdomain)) != 0) || (EBufferAllocateLoad (BFL_IS_ALLOC, &(pTargList->taddress), SNMP_Target_Addr_Get_TAddress (pTaddr), SNMP_Target_Addr_Get_TAddress_Len (pTaddr)) != 0) || (EBufferAllocateLoad (BFL_IS_ALLOC, &(pTargList->sec_name), SNMP_Target_Params_Get_Sec_Name (pParams), SNMP_Target_Params_Get_Sec_Name_Len (pParams)) != 0)) { clean_target_list (pTargList); EBufferClean (&contextEngineID); EBufferClean (&contextName); EBufferClean (&secName);#if INSTALL_ENVOY_SNMP_COEXISTENCE EBufferClean (&communityString);#endif return (ENVOY_ERR_INSUFFICIENT_MEMORY); }#if (INSTALL_ENVOY_SNMP_LOCK) /* * We've loaded all the information we need to build the new packet into * pTargList. Now we can safely unlock the databases and proceed with * building the new packet. We're going to release the coarse lock at * this point. */ ENVOY_SNMP_RELEASE_READ_LOCK (SNMP_CoarseLock); /* And just to be safe, we clean the PDU's lock field */ pPkt->coarse_lock = 0;#endif /* #if (INSTALL_ENVOY_SNMP_LOCK) */ /* allocate a proxy control block */ pProxyBlock = SNMP_memory_alloc (sizeof (SNMP_PROXY_CB_T)); if (pProxyBlock == 0) { clean_target_list (pTargList); EBufferClean (&contextEngineID); EBufferClean (&contextName); EBufferClean (&secName);#if INSTALL_ENVOY_SNMP_COEXISTENCE EBufferClean (&communityString);#endif return (ENVOY_ERR_INSUFFICIENT_MEMORY); } MEMSET (pProxyBlock, 0, sizeof (SNMP_PROXY_CB_T)); /* * We have a proxy block, so let's dump responsibility for these * EBuffers we've been carrying around onto them. */ MEMCPY (&(pProxyBlock->contextEngineID), &contextEngineID, sizeof (EBUFFER_T)); MEMCPY (&(pProxyBlock->contextName), &contextName, sizeof (EBUFFER_T)); MEMCPY (&(pProxyBlock->secName), &secName, sizeof (EBUFFER_T));#if INSTALL_ENVOY_SNMP_COEXISTENCE MEMCPY (&(pProxyBlock->communityString), &communityString, sizeof (EBUFFER_T));#endif /* grab the retrans lock briefly to get a new msgid */#if (INSTALL_ENVOY_SNMP_LOCK) if (ENVOY_SNMP_GET_WRITE_LOCK (SNMP_V3_Retrans_Lock)) { BUG (BUG_ENVOY_LOCKING, BUG_CONTINUABLE, 0, (BUG_OUT, "snmpProxyV3Request: retrans lock broken", 0)); clean_target_list (pTargList); proxyBlockClean (pProxyBlock); return (ENVOY_ERR_LOCK_FAILED); }#endif /* #if (INSTALL_ENVOY_SNMP_LOCK) */ ENVOY_SET_PROXY_MSGID (pProxyBlock);#if (INSTALL_ENVOY_SNMP_LOCK) ENVOY_SNMP_RELEASE_WRITE_LOCK (SNMP_V3_Retrans_Lock);#endif /* #if (INSTALL_ENVOY_SNMP_LOCK) */ pProxyBlock->expires = 0; pProxyBlock->targetList = pTargList; /* * Create a request packet. We do this using information that's been * safely placed into targList, so that we can call the Create * function without holding any locks. */ switch (pTargList->mp_model) {#if INSTALL_ENVOY_SNMP_COEXISTENCE case SNMP_VERSION_1: pNewPkt = SNMP_Create_Request2 (((pPkt->pdu_type == GET_BULK_REQUEST_PDU) ? GET_NEXT_REQUEST_PDU : pPkt->pdu_type), pTargList->mp_model, EBufferUsed (&pProxyBlock->communityString), (sbits8_t *) EBufferStart (&pProxyBlock->communityString), pProxyBlock->msgID, 0, 0, 0); if (pNewPkt == 0) { proxyBlockClean (pProxyBlock); return (ENVOY_ERR_UNKNOWN);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -