Ejemplo n.º 1
0
int main( int argc, char ** argv )
{
    int    i,n=10;
    KMAP * km;
    char * p;
    char   str[80];

    printf("usage: kmap nkeys (default=10)\n\n");

    km = KMapNew( free );  /* use 'free' to free 'userdata' */

    KMapSetNoCase(km,1);  //need to add xlat....

    if( argc > 1 )
    {
        n = atoi(argv[1]);
    }

    for(i=1;i<=n;i++)
    {
        SnortSnprintf(str, sizeof(str), "KeyWord%d",i);
        KMapAdd( km, str, 0 /* strlen(str) */, strupr(strdup(str)) );
        printf("Adding Key=%s\n",str);
    }
    printf("xmem: %u bytes, %d chars\n",xmalloc_bytes(),km->nchars);

    printf("\nKey Find test...\n");
    for(i=1;i<=n;i++)
    {
        SnortSnprintf(str, sizeof(str), "KeyWord%d",i);
        p = (char*) KMapFind( km, str,  0 /*strlen(str) */ );
        if(p)printf("key=%s, data=%*s\n",str,strlen(str),p);
        else printf("'%s' NOT found.\n",str);
    }

    KMapSetNoCase(km,0);  // this should fail all key searches
    printf("\nKey Find test2...\n");
    for(i=1;i<=n;i++)
    {
        SnortSnprintf(str, sizeof(str), "KeyWord%d",i);
        p = (char*) KMapFind( km, str,  0 /*strlen(str) */ );
        if(p)printf("key=%s, data=%*s\n",str,strlen(str),p);
        else printf("'%s' NOT found.\n",str);
    }

    printf("\nKey FindFirst/Next test...\n");
    for(p = (char*) KMapFindFirst(km); p; p=(char*)KMapFindNext(km) )
        printf("data=%s\n",p);

    printf("\nKey FindFirst/Next test done.\n");

    KMapDelete( km );

    printf("xmem: %u bytes\n",xmalloc_bytes());

    printf("normal pgm finish.\n");

    return 0;
}
Ejemplo n.º 2
0
/*
 * Function: ftpp_ui_client_lookup_find(CLIENT_LOOKUP *ClientLookup,
 *                                  char *ip, int len,
 *                                  int *iError)
 *
 * Purpose: Find a client configuration given a IP.
 *          We look up a client configuration given an IP and
 *          return a pointer to that client configuration if found.
 *
 * Arguments: ClientLookup => a pointer to the lookup structure
 *            IP           => the ftp client address
 *            len          => Length of the address 
 *            iError       => a pointer to an error code
 *
 * Returns: int => return code indicating error or success
 *
 * Returns: FTP_CLIENT_PROTO_CONF* => Pointer to client configuration
 *                           structure matching IP if found, NULL otherwise.
 *
 */
FTP_CLIENT_PROTO_CONF *ftpp_ui_client_lookup_find(CLIENT_LOOKUP *ClientLookup, 
                                            unsigned long Ip, int *iError)
{
    FTP_CLIENT_PROTO_CONF *ClientConf = NULL;

    if(!iError)
    {
        return NULL;
    }

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

    *iError = FTPP_SUCCESS;

    /* TODO: change this to use a quick find of IP/mask */
    if(!(ClientConf = (FTP_CLIENT_PROTO_CONF *)
                        KMapFind(ClientLookup,(void *)&Ip,4)))
    {
        *iError = FTPP_NOT_FOUND;
    }

    return ClientConf;
}
Ejemplo n.º 3
0
/*
 * Function: ftp_bounce_lookup_find(BOUNCE_LOOKUP *BounceLookup,
 *                                  snort_ip_p ip, int *iError)
 *
 * Purpose: Find a bounce configuration given a IP.
 *          We look up a bounce configuration given an IP and
 *          return a pointer to that bounce configuration if found.
 *
 * Arguments: BounceLookup => a pointer to the lookup structure
 *            IP           => the ftp bounce address
 *            iError       => a pointer to an error code
 *
 * Returns: int => return code indicating error or success
 *
 * Returns: FTP_BOUNCE_TO* => Pointer to bounce configuration structure
 *                            matching IP if found, NULL otherwise.
 *
 */
FTP_BOUNCE_TO  *ftp_bounce_lookup_find(
        BOUNCE_LOOKUP *BounceLookup, snort_ip_p Ip, int *iError ) 
{
    FTP_BOUNCE_TO *BounceTo = NULL;

    if(!iError)
    {
        return NULL;
    }

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

    *iError = FTPP_SUCCESS;

    BounceTo = (FTP_BOUNCE_TO *)KMapFind(BounceLookup, (void*)IP_PTR(Ip), IP_SIZE(Ip));
    if (!BounceTo)
    {
        *iError = FTPP_NOT_FOUND;
    }

    return BounceTo;
}
Ejemplo n.º 4
0
/*
 * Function: ftp_cmd_lookup_find(CMD_LOOKUP *CmdLookup,
 *                                  char *ip, int len,
 *                                  int *iError)
 *
 * Purpose: Find a cmd configuration given a IP.
 *          We look up a cmd configuration given an FTP cmd and
 *          return a pointer to that cmd configuration if found.
 *
 * Arguments: CmdLookup    => a pointer to the lookup structure
 *            cmd          => the ftp cmd
 *            len          => Length of the cmd
 *            iError       => a pointer to an error code
 *
 * Returns: int => return code indicating error or success
 *
 * Returns: FTP_CMD_CONF* => Pointer to cmd configuration structure
 *                            matching IP if found, NULL otherwise.
 *
 */
FTP_CMD_CONF  *ftp_cmd_lookup_find(CMD_LOOKUP *CmdLookup,
                                            const char *cmd, int len, int *iError)
{
    FTP_CMD_CONF *FTPCmd = NULL;

    if(!iError)
    {
        return NULL;
    }

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

    *iError = FTPP_SUCCESS;

    FTPCmd = (FTP_CMD_CONF *)KMapFind(CmdLookup,(void *)cmd,len);
    if (!FTPCmd)
    {
        *iError = FTPP_NOT_FOUND;
    }

    return FTPCmd;
}
Ejemplo n.º 5
0
/*
 * Function: ftp_bounce_lookup_find(BOUNCE_LOOKUP *BounceLookup,
 *                                  char *ip, int len,
 *                                  int *iError)
 *
 * Purpose: Find a bounce configuration given a IP.
 *          We look up a bounce configuration given an IP and
 *          return a pointer to that bounce configuration if found.
 *
 * Arguments: BounceLookup => a pointer to the lookup structure
 *            IP           => the ftp bounce address
 *            len          => Length of the address 
 *            iError       => a pointer to an error code
 *
 * Returns: int => return code indicating error or success
 *
 * Returns: FTP_BOUNCE_TO* => Pointer to bounce configuration structure
 *                            matching IP if found, NULL otherwise.
 *
 */
FTP_BOUNCE_TO  *ftp_bounce_lookup_find(BOUNCE_LOOKUP *BounceLookup, 
                                       char *ip, int len, int *iError)
{
    FTP_BOUNCE_TO *BounceTo = NULL;

    if(!iError)
    {
        return NULL;
    }

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

    *iError = FTPP_SUCCESS;

    BounceTo = (FTP_BOUNCE_TO *)KMapFind(BounceLookup,(void *)ip,len);
    if (!BounceTo)
    {
        *iError = FTPP_NOT_FOUND;
    }

    return BounceTo;
}
Ejemplo n.º 6
0
/*
 * Function: http_cmd_lookup_find(CMD_LOOKUP *CmdLookup,
 *                                  char *ip, int len,
 *                                  int *iError)
 *
 * Purpose: Find a cmd configuration given a IP.
 *          We look up a cmd configuration given an HTTP cmd and
 *          return a pointer to that cmd configuration if found.
 *
 * Arguments: CmdLookup    => a pointer to the lookup structure
 *            cmd          => the http cmd
 *            len          => Length of the cmd
 *            iError       => a pointer to an error code
 *
 * Returns: int => return code indicating error or success
 *
 * Returns: HTTP_CMD_CONF* => Pointer to cmd configuration structure
 *                            matching IP if found, NULL otherwise.
 *
 */
HTTP_CMD_CONF  *http_cmd_lookup_find(CMD_LOOKUP *CmdLookup,
                                            const char *cmd, int len, int *iError)
{
    HTTP_CMD_CONF *HTTPCmd = NULL;

    if(!iError)
    {
        return NULL;
    }

    if(!CmdLookup)
    {
        *iError = -1;
        return NULL;
    }

    *iError = 0;

    HTTPCmd = (HTTP_CMD_CONF *)KMapFind(CmdLookup,(void *)cmd,len);
    if (!HTTPCmd)
    {
        *iError = -1;
    }

    return HTTPCmd;
}
Ejemplo n.º 7
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, 
                                            unsigned long Ip, int *iError)
{
    HTTPINSPECT_CONF *ServerConf;

    if(!iError)
    {
        return NULL;
    }

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

    *iError = HI_SUCCESS;

    ServerConf = (HTTPINSPECT_CONF *)KMapFind(ServerLookup,(void *)&Ip,4);
    if (!ServerConf)
    {
        *iError = HI_NOT_FOUND;
    }

    return ServerConf;
}