示例#1
0
FTP_CLIENT_PROTO_CONF *ftpp_ui_client_lookup_find(CLIENT_LOOKUP *ClientLookup, 
                                            snort_ip_p Ip, int *iError)
{
    FTP_CLIENT_PROTO_CONF *ClientConf = NULL;

    if(!iError)
    {
        return NULL;
    }

    if(!ClientLookup)
    {
        *iError = FTPP_INVALID_ARG;
        return NULL;
    }

    *iError = FTPP_SUCCESS;

#ifdef SUP_IP6
    ClientConf = (FTP_CLIENT_PROTO_CONF *)sfrt_lookup((void *)Ip, ClientLookup);
#else
    ClientConf = (FTP_CLIENT_PROTO_CONF *)sfrt_lookup((void *)&Ip, ClientLookup);
#endif
    if (!ClientConf)
    {
        *iError = FTPP_NOT_FOUND;
    }

    return ClientConf;
}
示例#2
0
/**
**  Find a server configuration given a IP.
**
**  We look up a server configuration given an IP and return a pointer
**  to that server configuration if found.
**
**  @param ServerLookup pointer to the server lookup structure
**  @param Ip           the IP to lookup
**  @param iError       the error return code
**
**  @return integer
**
**  @retval HI_SUCCESS function sucessful
**  @retval HI_INVALID_ARG argument(s) are invalid
**  @retval HI_NOT_FOUND IP not found
*/
HTTPINSPECT_CONF  *hi_ui_server_lookup_find(SERVER_LOOKUP *ServerLookup,
                                            snort_ip_p Ip, int *iError)
{
    HTTPINSPECT_CONF *ServerConf;

    if(!iError)
    {
        return NULL;
    }

    if(!ServerLookup)
    {
        *iError = HI_INVALID_ARG;
        return NULL;
    }

    *iError = HI_SUCCESS;

#ifdef SUP_IP6
    ServerConf = (HTTPINSPECT_CONF *)sfrt_lookup((void *)Ip, ServerLookup);
#else
    ServerConf = (HTTPINSPECT_CONF *)sfrt_lookup((void *)&Ip, ServerLookup);
#endif
    if (!ServerConf)
    {
        *iError = HI_NOT_FOUND;
    }

    return ServerConf;
}
/*
 * Function: ftpp_ui_server_lookup_find(SERVER_LOOKUP *ServerLookup,
 *                                  snort_ip_p ip, int *iError)
 *
 * Purpose: Find a server configuration given a IP.
 *          We look up a server configuration given an IP and
 *          return a pointer to that server configuration if found.
 *
 * Arguments: ServerLookup => a pointer to the lookup structure
 *            IP           => the ftp server address
 *            iError       => a pointer to an error code
 *
 * Returns: int => return code indicating error or success
 *
 * Returns: FTP_SERVER_PROTO_CONF* => Pointer to server configuration
 *                            structure matching IP if found, NULL otherwise.
 *
 */
FTP_SERVER_PROTO_CONF *ftpp_ui_server_lookup_find(
    SERVER_LOOKUP *ServerLookup, snort_ip_p Ip, int *iError
)
{
    FTP_SERVER_PROTO_CONF *ServerConf = NULL;

    if(!iError)
    {
        return NULL;
    }

    if(!ServerLookup)
    {
        *iError = FTPP_INVALID_ARG;
        return NULL;
    }

    *iError = FTPP_SUCCESS;

#ifdef SUP_IP6
    ServerConf = (FTP_SERVER_PROTO_CONF *)sfrt_lookup((void *)Ip, ServerLookup);
#else
    ServerConf = (FTP_SERVER_PROTO_CONF *)sfrt_lookup((void *)&Ip, ServerLookup);
#endif
    if (!ServerConf)
    {
        *iError = FTPP_NOT_FOUND;
    }

    return ServerConf;
}
示例#4
0
FTP_CLIENT_PROTO_CONF *ftpp_ui_client_lookup_find(CLIENT_LOOKUP *ClientLookup,
                                            sfaddr_t* Ip, int *iError)
{
    FTP_CLIENT_PROTO_CONF *ClientConf = NULL;

    if(!iError)
    {
        return NULL;
    }

    if(!ClientLookup)
    {
        *iError = FTPP_INVALID_ARG;
        return NULL;
    }

    *iError = FTPP_SUCCESS;

    ClientConf = (FTP_CLIENT_PROTO_CONF *)sfrt_lookup(Ip, ClientLookup);
    if (!ClientConf)
    {
        *iError = FTPP_NOT_FOUND;
    }

    return ClientConf;
}
示例#5
0
/*
 * Function: ftpp_ui_server_lookup_find(SERVER_LOOKUP *ServerLookup,
 *                                  sfaddr_t* ip, int *iError)
 *
 * Purpose: Find a server configuration given a IP.
 *          We look up a server configuration given an IP and
 *          return a pointer to that server configuration if found.
 *
 * Arguments: ServerLookup => a pointer to the lookup structure
 *            IP           => the ftp server address
 *            iError       => a pointer to an error code
 *
 * Returns: int => return code indicating error or success
 *
 * Returns: FTP_SERVER_PROTO_CONF* => Pointer to server configuration
 *                            structure matching IP if found, NULL otherwise.
 *
 */
FTP_SERVER_PROTO_CONF *ftpp_ui_server_lookup_find(
    SERVER_LOOKUP *ServerLookup, sfaddr_t* Ip, int *iError
)
{
    FTP_SERVER_PROTO_CONF *ServerConf = NULL;

    if(!iError)
    {
        return NULL;
    }

    if(!ServerLookup)
    {
        *iError = FTPP_INVALID_ARG;
        return NULL;
    }

    *iError = FTPP_SUCCESS;

    ServerConf = (FTP_SERVER_PROTO_CONF *)sfrt_lookup(Ip, ServerLookup);
    if (!ServerConf)
    {
        *iError = FTPP_NOT_FOUND;
    }

    return ServerConf;
}
示例#6
0
文件: sfrt.c 项目: jasonish/snort
int main()
{
    table_t *dir;
    uint32_t ip_list[NUM_IPS];  /* entirely arbitrary */
    char data[NUM_DATA];     /* also entirely arbitrary */
    uint32_t index, val;

    for(index=0; index<NUM_IPS; index++)
    {
        ip_list[index] = (uint32_t)rand()%NUM_IPS;
        data[index%NUM_DATA] = index%26 + 65;    /* Random letter */
    }

    dir = sfrt_new(DIR_16x2, IPv4, NUM_IPS, 20);

    if(!dir)
    {
        printf("Failed to create DIR\n");
        return 1;
    }

    for(index=0; index < NUM_IPS; index++)
    {
        if(sfrt_insert(&ip_list[index], 32, &data[index%NUM_DATA],
                       RT_FAVOR_SPECIFIC, dir) != RT_SUCCESS)
        {
            printf("DIR Insertion failure\n");
            return 1;
        }

        printf("%d\t %x: %c -> %c\n", index, ip_list[index],
              data[index%NUM_DATA], *(uint32_t*)sfrt_lookup(&ip_list[index], dir));

    }

    for(index=0; index < NUM_IPS; index++)
    {
        val = *(uint32_t*)sfrt_lookup(&ip_list[index], dir);
        printf("\t@%d\t%x: %c.  originally:\t%c\n",
                            index, ip_list[index], val, data[index%NUM_DATA]);
    }

    printf("Usage: %d bytes\n", ((dir_table_t*)(dir->rt))->allocated);

    sfrt_free(dir);
    return 0;
}
示例#7
0
static int AddIPtoList(sfip_t *ipAddr, void *info, ReputationConfig *config)
{
    int iRet;
    int iFinalRet = IP_INSERT_SUCCESS;
    /*This variable is used to check whether a more generic address
     * overrides specific address
     */
    uint32_t usageBeforeAdd;
    uint32_t usageAfterAdd;

#ifndef SUP_IP6
    if (ipAddr->family == AF_INET6)
    {
        return RT_INSERT_FAILURE;
    }
#endif
    if (ipAddr->family == AF_INET)
    {
        ipAddr->ip32[0] = ntohl(ipAddr->ip32[0]);
    }
    else if (ipAddr->family == AF_INET6)
    {
        int i;
        for(i = 0; i < 4 ; i++)
            ipAddr->ip32[i] = ntohl(ipAddr->ip32[i]);
    }
#ifdef DEBUG_MSGS

    if (NULL != sfrt_lookup((void *)ipAddr, config->iplist))
    {
        DebugMessage(DEBUG_REPUTATION, "Find address before insert: %s \n",sfip_to_str(ipAddr) );

    }
    else
    {
        DebugMessage(DEBUG_REPUTATION, "Can't find address before insert: %s \n",sfip_to_str(ipAddr) );

    }
#endif
    usageBeforeAdd =  sfrt_usage(config->iplist);

    /*Check whether the same or more generic address is already in the table*/
    if (NULL != sfrt_lookup((void *)ipAddr, config->iplist))
    {
        iFinalRet = IP_INSERT_DUPLICATE;
    }


#ifdef SUP_IP6
    iRet = sfrt_insert((void *)ipAddr, (unsigned char)ipAddr->bits, (void *)info, RT_FAVOR_TIME, config->iplist);
#else
    iRet = sfrt_insert((void *)&(ipAddr->ip.u6_addr32[0]), (unsigned char)ipAddr->bits, (void *)info, RT_FAVOR_TIME, config->iplist);
#endif

    if (RT_SUCCESS == iRet)
    {
        totalNumEntries++;
#ifdef DEBUG_MSGS

        DebugMessage(DEBUG_REPUTATION, "Number of entries input: %d, in table: %d \n",
                totalNumEntries,sfrt_num_entries(config->iplist) );
        DebugMessage(DEBUG_REPUTATION, "Memory allocated: %d \n",sfrt_usage(config->iplist) );
        if (NULL != sfrt_lookup((void *)ipAddr, config->iplist))
        {
            DebugMessage(DEBUG_REPUTATION, "Find address after insert: %s \n",sfip_to_str(ipAddr) );

        }
#endif
    }
    else if (MEM_ALLOC_FAILURE == iRet)
    {
        iFinalRet = IP_MEM_ALLOC_FAILURE;
        DEBUG_WRAP( DebugMessage(DEBUG_REPUTATION, "Insert error: %d for address: %s \n",iRet, sfip_to_str(ipAddr) ););