From: Russ Combs (rucombs) Date: Fri, 19 Apr 2019 18:36:03 +0000 (-0400) Subject: Merge pull request #1585 in SNORT/snort3 from ~RUCOMBS/snort3:mainz to master X-Git-Tag: 3.0.0-254~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23172580c9f0a30c766a37d093283f87d5783f4e;p=thirdparty%2Fsnort3.git Merge pull request #1585 in SNORT/snort3 from ~RUCOMBS/snort3:mainz to master Squashed commit of the following: commit 908ec9dc090b12b4d788385fe82c3d866d5c4f50 Author: russ Date: Fri Apr 19 11:51:28 2019 -0400 test: remove cruft --- diff --git a/src/events/sfeventq.cc b/src/events/sfeventq.cc index eb31ae364..3cf79e441 100644 --- a/src/events/sfeventq.cc +++ b/src/events/sfeventq.cc @@ -263,110 +263,3 @@ int sfeventq_action(SF_EVENTQ* eq, int (* action_func)(void*, void*), void* user return 1; } -//#define I_WANT_MY_MAIN -#ifdef I_WANT_MY_MAIN - -#include -#include - -int myaction(void* event, void* user) -{ - int* e; - - if (!event) - return 1; - - e = (int*)event; - - printf("-- EVENT: %d\n", *e); - - return 0; -} - -int main(int argc, char** argv) -{ - int max_events; - int log_events; - int add_events; - int* event; - int iCtr; - SF_EVENTQ* eq; - - if (argc < 4) - { - printf("-- Not enough args\n"); - return 1; - } - - max_events = atoi(argv[1]); - if (max_events <= 0) - { - printf("-- max_events invalid.\n"); - return 1; - } - - log_events = atoi(argv[2]); - if (log_events <= 0) - { - printf("-- log_events invalid.\n"); - return 1; - } - - add_events = atoi(argv[3]); - if (add_events <= 0) - { - printf("-- add_events invalid.\n"); - return 1; - } - - if (max_events < log_events) - { - printf("-- log_events greater than max_events\n"); - return 1; - } - - srandom(time(NULL)); - - eq = sfeventq_new(max_events, log_events, sizeof(int)); - if (eq == NULL) - { - printf("Couldn't allocate the event queue\n"); - return 1; - } - - do - { - printf("-- Event Queue Test --\n\n"); - - for (iCtr = 0; iCtr < add_events; iCtr++) - { - event = (int*)sfeventq_event_alloc(eq); - if (!event) - { - printf("-- event allocation failed\n"); - return 1; - } - - *event = (int)(random()%3); - - sfeventq_add(eq, event); - printf("-- added %d\n", *event); - } - - printf("\n-- Logging\n\n"); - - if (sfeventq_action(eq, myaction, NULL)) - { - printf("-- There was a problem.\n"); - return 1; - } - - sfeventq_reset(eq); - } - while (getc(stdin) < 14); - - return 0; -} - -#endif - diff --git a/src/hash/xhash.cc b/src/hash/xhash.cc index 41b248e04..e3e74b438 100644 --- a/src/hash/xhash.cc +++ b/src/hash/xhash.cc @@ -1029,143 +1029,3 @@ void xhash_set_keyops(XHash* h, hash_func hash_fcn, keycmp_func keycmp_fcn) } } // namespace snort -/* - * ----------------------------------------------------------------------------------------- - * Test Driver for Hashing - * ----------------------------------------------------------------------------------------- - */ -#ifdef XHash_MAIN - -/* - This is called when the user releases a node or kills the table -*/ -int usrfree(void* key, void* data) -{ - /* Release any data you need to */ - return 0; -} - -/* - Auto Node Recovery Callback - optional - - This is called to ask the user to kill a node, if it returns !0 than the hash - library does not kill this node. If the user os willing to let the node die, - the user must do any freeing or clean up on the node during this call. -*/ -int anrfree(void* key, void* data) -{ - static int bx = 0; // test only - - /* Decide if we can free this node. */ - - bx++; if(bx == 4 )bx=0; /* for testing */ - - /* if we are allowing the node to die, kill it */ - if ( !bx ) - usrfree(key, data); - - return bx; /* Allow the caller to kill this nodes data + key */ -} - -/* - * Hash test program : use 'sfxhash 1000 50000' to stress the Auto_NodeRecover feature - */ -int main(int argc, char** argv) -{ - int i; - XHash* t; - XHashNode* n; - char strkey[256], strdata[256]; - int num = 100; - int mem = 0; - - memset(strkey,0,20); - memset(strdata,0,20); - - if ( argc > 1 ) - { - num = atoi(argv[1]); - } - - if ( argc > 2 ) - { - mem = atoi(argv[2]); - } - - /* Create a Hash Table */ - t = xhash_new(100, /* one row per element in table, when possible */ - 20, /* key size : padded with zeros */ - 20, /* data size: padded with zeros */ - mem, /* max bytes, 0=no max */ - 1, /* enable AutoNodeRecovery */ - anrfree, /* provide a function to let user know we want to kill a node */ - usrfree, /* provide a function to release user memory */ - 1); /* Recycle nodes */ - if (!t) - { - printf("Low Memory\n"); - exit(0); - } - /* Add Nodes to the Hash Table */ - for (i=0; imc); - printf("...******\n"); - - /* Display All Nodes in the Hash Table findfirst/findnext */ - printf("\n...FINDFIRST / FINDNEXT TEST\n"); - for ( n = xhash_findfirst(t); - n != 0; - n = xhash_findnext(t) ) - { - printf("hash-findfirst/next: n=%p, key=%s, data=%s\n", n, n->key, n->data); - - /* - remove node we are looking at, this is first/next safe. - */ - if ( xhash_remove(t,n->key) ) - { - printf("...ERROR: Could not remove the key node\n"); - } - else - { - printf("...key node removed\n"); - } - } - - printf("...Auto-Node-Recovery: %u recycle attempts, %u completions.\n",t->anr_tries, - t->anr_count); - - /* Free the table and it's user data */ - printf("...xhash_delete\n"); - - xhash_delete(t); - - printf("\nnormal pgm finish\n\n"); - - return 0; -} - -#endif - diff --git a/src/ips_options/asn1_util.cc b/src/ips_options/asn1_util.cc index 9fab0ccb7..414b68e11 100644 --- a/src/ips_options/asn1_util.cc +++ b/src/ips_options/asn1_util.cc @@ -1006,94 +1006,3 @@ int asn1_print_types(ASN1_TYPE* asn1_type, void* user) return 0; } -#ifdef I_WANT_MAIN_DAMMIT -static int BitStringOverflow(ASN1_TYPE* asn1_type) -{ - if (!asn1_type) - return 0; - - if (asn1_type->ident.tag == SF_ASN1_TAG_BIT_STR && !asn1_type->ident.flag) - { - if (((asn1_type->len.size - 1)*8) < (u_int)asn1_type->data[0]) - { - return 1; - } - } - - return 0; -} - -/* -** Program reads from stdin and decodes the hexadecimal ASN.1 stream -** into identifier,len,data. -*/ -int main(int argc, char** argv) -{ - ASN1_TYPE* asn1_type; - char line[10000]; - u_int ctmp; - char* buf; - int buf_size; - int iCtr; - int iRet; - - fgets(line, sizeof(line), stdin); - buf_size = strlen(line); - - while (buf_size && line[buf_size-1] <= 0x20) - { - buf_size--; - line[buf_size] = 0x00; - } - - if (!buf_size) - { - printf("** No valid characters in data string.\n"); - return 1; - } - - if (buf_size % 2) - { - printf("** Data must be represent in hex, meaning that there is an " - "odd number of characters in the data string.\n"); - return 1; - } - - buf_size >>= 1; - - buf = snort_calloc(buf_size + 1); - - for (iCtr = 0; iCtr < buf_size; iCtr++) - { - if (!(isxdigit(line[iCtr*2]) && isxdigit(line[(iCtr*2)+1]))) - { - printf("** Data stream is not all hex digits.\n"); - return 1; - } - - sscanf(&line[iCtr*2], "%2x", &ctmp); - buf[iCtr] = (char)ctmp; - } - - buf[iCtr] = 0x00; - - asn1_init_mem(256); - - iRet = asn1_decode(buf, buf_size, &asn1_type); - if (iRet && !asn1_type) - { - printf("** FAILED\n"); - return 1; - } - - printf("** iRet = %d\n", iRet); - - asn1_print_types(asn1_type, 0); - - snort_free(buf); - - return 0; -} - -#endif - diff --git a/src/ips_options/extract.cc b/src/ips_options/extract.cc index e1add9d4d..dd7e2001b 100644 --- a/src/ips_options/extract.cc +++ b/src/ips_options/extract.cc @@ -347,177 +347,5 @@ TEST_CASE("ips options vars") REQUIRE((GetVarValueByIndex(&dst, NUM_IPS_OPTIONS_VARS) == IPS_OPTIONS_NO_VAR)); REQUIRE((SetVarValueByIndex(0, NUM_IPS_OPTIONS_VARS) == IPS_OPTIONS_NO_VAR)); } - #endif -#ifdef TEST_BYTE_EXTRACT -#include - -void test_extract() -{ - int i; - uint32_t ret; - - uint8_t value1[2]; - uint8_t value2[2]; - uint8_t value3[4]; - - value1[0] = 0; - value1[1] = 0xff; - - value2[0] = 0xff; - value2[1] = 0x01; - - value3[0] = 0xff; - value3[1] = 0xff; - value3[2] = 0x00; - value3[3] = 0x00; - - if (byte_extract(ENDIAN_BIG, 2, value1, value1, value1 + 2, &ret)) - { - printf("test 1 failed\n"); - } - else - { - printf("test 1: value: %x %u\n", ret, ret); - } - - if (byte_extract(ENDIAN_LITTLE, 2, value1, value1, value1 + 2, &ret)) - { - printf("test 2 failed\n"); - } - else - { - printf("test 2: value: %x %u\n", ret, ret); - } - - if (byte_extract(ENDIAN_LITTLE, 2, value1 + 2, value1, value1 + 2, &ret)) - { - printf("test 3 failed correctly\n"); - } - else - { - printf("test 3: value: %x %u\n", ret, ret); - } - - if (byte_extract(ENDIAN_BIG, 2, value2, value2, value2 + 2, &ret)) - { - printf("test 1 failed\n"); - } - else - { - printf("test 1: value: %x %u\n", ret, ret); - } - - if (byte_extract(ENDIAN_LITTLE, 2, value2, value2, value2 + 2, &ret)) - { - printf("test 2 failed\n"); - } - else - { - printf("test 2: value: %x %u\n", ret, ret); - } - - if (byte_extract(ENDIAN_LITTLE, 2, value2 + 2, value2, value2 + 2, &ret)) - { - printf("test 3 failed correctly\n"); - } - else - { - printf("test 3: value: %x %u\n", ret, ret); - } - - if (byte_extract(ENDIAN_BIG, 4, value3, value3, value3 + 4, &ret)) - { - printf("test 1 failed\n"); - } - else - { - printf("test 1: value: %x %u\n", ret, ret); - } - - if (byte_extract(ENDIAN_LITTLE, 4, value3, value3, value3 + 4, &ret)) - { - printf("test 2 failed\n"); - } - else - { - printf("test 2: value: %x %u\n", ret, ret); - } - - if (byte_extract(ENDIAN_LITTLE, 4, value3 + 2, value3, value3 + 4, &ret)) - { - printf("test 3 failed correctly\n"); - } - else - { - printf("test 3: value: %x %u\n", ret, ret); - } - - printf("-----------------------------\n"); - - for (i=0; i<10; i++) - { - if (byte_extract(ENDIAN_LITTLE, 4, value3 + i, value3, value3 + 4, &ret)) - { - printf("[loop] %d failed correctly\n", i); - } - else - { - printf("[loop] value: %x %x\n", ret, *(uint32_t*)&value3); - } - } -} - -void test_string() -{ - char* stringdata = "21212312412"; - int datalen = strlen(stringdata); - uint32_t ret; - - if (string_extract(4, 10, stringdata, stringdata, stringdata + datalen, &ret) < 0) - { - printf("TS1: Failed\n"); - } - else - { - printf("TS1: value %x %u\n", ret, ret); - } - - if (string_extract(10, 10, stringdata, stringdata, stringdata + datalen, &ret) < 0) - { - printf("TS2: Failed\n"); - } - else - { - printf("TS2: value %x %u\n", ret, ret); - } - - if (string_extract(9, 10, stringdata, stringdata, stringdata + datalen, &ret) < 0) - { - printf("TS3: Failed\n"); - } - else - { - printf("TS3: value %x %u\n", ret, ret); - } - - if (string_extract(19, 10, stringdata, stringdata, stringdata + datalen, &ret) < 0) - { - printf("TS4: Failed Normally\n"); - } - else - { - printf("TS4: value %x %u\n", ret, ret); - } -} - -int main() -{ - test_extract(); - test_string(); - return 0; -} - -#endif /* TEST_BYTE_EXTRACT */ - diff --git a/src/network_inspectors/port_scan/ipobj.cc b/src/network_inspectors/port_scan/ipobj.cc index c610ea7c0..cc947b326 100644 --- a/src/network_inspectors/port_scan/ipobj.cc +++ b/src/network_inspectors/port_scan/ipobj.cc @@ -424,254 +424,3 @@ int ipset_parse(IPSET* ipset, const char* ipstr) return 0; } -#ifdef MAIN_IP -#include - -#define rand random -#define srand srandom - -#define MAXIP 100 - -#include "sflsq.c" - -void test_ip4_parsing() -{ - unsigned host, mask, not_flag; - PORTSET portset; - char** curip; - IPADDRESS* adp; - char* ips[] = - { - "138.26.1.24:25", - "1.1.1.1/255.255.255.0:444", - "1.1.1.1/16:25-28", - "1.1.1.1/255.255.255.255:25 27-29", - "z/24", - "0/0", - "0.0.0.0/0.0.0.0:25-26 28-29 31", - "0.0.0.0/0.0.2.0", - nullptr - }; - - for (curip = ips; curip[0]; curip++) - { - portset_init(&portset); - - /* network byte order stuff */ - if (int ret = ip4_parse(curip[0], 1, ¬_flag, &host, &mask, &portset)) - { - fprintf(stderr, "Unable to parse %s with ret %d\n", curip[0], ret); - } - else - { - printf("%c", not_flag ? '!' : ' '); - printf("%s/", inet_ntoa(*(struct in_addr*)&host)); - printf("%s", inet_ntoa(*(struct in_addr*)&mask)); - printf(" parsed successfully\n"); - } - - /* host byte order stuff */ - if (int ret = ip4_parse(curip[0], 0, ¬_flag, &host, &mask, &portset)) - { - fprintf(stderr, "Unable to parse %s with ret %d\n", curip[0], ret); - } - else - { - adp = ip_new(IPV4_FAMILY); - ip_set(adp, &host, IPV4_FAMILY); - ip_fprint(stdout, adp); - fprintf(stdout, "*****************\n"); - ip_free(adp); - } - } -} - -void test_ip4set_parsing() -{ - char** curip; - char* ips[] = - { - "12.24.24.1/32,!24.24.24.1", - "[0.0.0.0/0.0.2.0,241.242.241.22]", - "138.26.1.24", - "1.1.1.1", - "1.1.1.1/16", - "1.1.1.1/255.255.255.255", - "z/24", - "0/0", - "0.0.0.0/0.0.0.0", - "0.0.0.0/0.0.2.0", - nullptr - }; - - for (curip = ips; curip[0]; curip++) - { - IPSET* ipset = ipset_new(IPV4_FAMILY); - - /* network byte order stuff */ - if (int ret = ip4_setparse(ipset, curip[0])) - { - ipset_free(ipset); - fprintf(stderr, "Unable to parse %s with ret %d\n", curip[0], ret); - } - else - { - printf("-[%s]\n ", curip[0]); - ipset_print(ipset); - printf("---------------------\n "); - } - } -} - -// ----------------------------- -void test_ip() -{ - int i,k; - IPADDRESS* ipa[MAXIP]; - unsigned ipaddress,ipx; - unsigned short ipaddress6[8], ipx6[8]; - - printf("IPADDRESS testing\n"); - - srand(time(0) ); - - for (i=0; iacsmNextState; - printf("Dump DFA - %d active states\n",acsm->acsmNumStates); - - FILE* fp = fopen(f,"wb"); - - if (!fp) - { - printf("WARNING: could not write dfa to file - %s.\n",f); - return; - } - - fwrite( &acsm->acsmNumStates, 4, 1, fp); - - for (int k=0; kacsmNumStates; k++) - { - acstate_t* p = NextState[k]; - - if ( !p ) - continue; - - acstate_t fmt = *p++; - acstate_t bmatch = *p++; - - fwrite(&fmt, sizeof(acstate_t), 1, fp); - fwrite(&bmatch, sizeof(acstate_t), 1, fp); - - if ( fmt == ACF_SPARSE ) - { - acstate_t n = *p++; - fwrite(&n, sizeof(acstate_t), 1, fp); - fwrite(p, n*2*sizeof(acstate_t), 1, fp); - } - else if ( fmt ==ACF_BANDED ) - { - acstate_t n = *p++; - fwrite(&n, sizeof(acstate_t), 1, fp); - - acstate_t index = *p++; - fwrite(&index, sizeof(acstate_t), 1, fp); - - fwrite(p, sizeof(acstate_t), n, fp); - } - else if ( fmt ==ACF_SPARSE_BANDS ) - { - acstate_t nb = *p++; - fwrite(&nb, sizeof(acstate_t), 1, fp); - - for (int i=0; iacsmAlphabetSize, fp); - } - - //Print_DFA_MatchList( acsm, k); - } - - fclose(fp); -} - -static int acsmSearch2( - ACSM_STRUCT2* acsm, uint8_t* Tx, int n, MpseMatch match, - void* context, int* current_state) -{ - if ( !acsm->dfa ) - return acsm_search_nfa(acsm, Tx, n, match, context, current_state); - - switch ( acsm->acsmFormat ) - { - case ACF_FULL: - return acsm_search_dfa_full(acsm, Tx, n, match, context, current_state); - - case ACF_BANDED: - return acsm_search_dfa_banded(acsm, Tx, n, match, context, current_state); - - case ACF_SPARSE: - case ACF_SPARSE_BANDS: - return acsm_search_dfa_sparse(acsm, Tx, n, match, context, current_state); - } - return 0; -} - -/* -* Text Data Buffer -*/ -uint8_t text[512]; - -/* -* A Match is found -*/ -int MatchFound(void* id, int index, void* data) -{ - fprintf (stdout, "%s\n", (char*)id); - return 0; -} - -int main(int argc, char** argv) -{ - int i, nc, nocase = 0; - ACSM_STRUCT2* acsm; - char* p; - - if (argc < 3) - { - fprintf (stderr,"Usage: %s search-text pattern +pattern... [flags]\n",argv[0]); - fprintf (stderr, " flags: -nfa -nocase -full -sparse -bands -sparsebands " - "-z zcnt (sparsebands) -sparsetree -v\n"); - exit (0); - } - - acsm = acsmNew2 (); - - if ( !acsm ) - { - printf("acsm-no memory\n"); - exit(0); - } - - strncpy (text, argv[1], sizeof(text) - 1); - text[sizeof(text) - 1] = '\0'; - - acsm->acsmFormat = ACF_FULL; - - for (i = 1; i < argc; i++) - { - if (strcmp (argv[i], "-nocase") == 0) - { - nocase = 1; - } - if (strcmp (argv[i], "-full") == 0) - { - acsm->acsmFormat = ACF_FULL; - } - if (strcmp (argv[i], "-sparse") == 0) - { - acsm->acsmFormat = ACF_SPARSE; - acsm->acsmSparseMaxRowNodes = 10; - } - if (strcmp (argv[i], "-bands") == 0) - { - acsm->acsmFormat = ACF_BANDED; - } - - if (strcmp (argv[i], "-sparsebands") == 0) - { - acsm->acsmFormat = ACF_SPARSE_BANDS; - acsm->acsmSparseMaxZcnt = 10; - } - if (strcmp (argv[i], "-z") == 0) - { - acsm->acsmSparseMaxZcnt = atoi(argv[++i]); - } - } - - for (i = 2; i < argc; i++) - { - if (argv[i][0] == '-') - continue; - - p = argv[i]; - - if ( *p == '+') - { - nc=1; - p++; - } - else - { - nc = nocase; - } - - acsmAddPattern2 (acsm, (uint8_t*)p, strlen(p), nc, 0, 0,(void*)p, i - 2); - } - - Print_DFA (acsm); - - acsmCompile2 (acsm); - - Write_DFA(acsm, "acsmx2-snort.dfa"); - - acsmPrintSummaryInfo2(acsm); - - acsmSearch2 (acsm, text, strlen (text), MatchFound, (void*)0); - - acsmFree2 (acsm); - - printf ("normal pgm end\n"); - - return 0; -} - -#endif - diff --git a/src/search_engines/bnfa_search.cc b/src/search_engines/bnfa_search.cc index 366219119..8d100de66 100644 --- a/src/search_engines/bnfa_search.cc +++ b/src/search_engines/bnfa_search.cc @@ -2084,257 +2084,3 @@ void bnfaAccumInfo(bnfa_struct_t* p) px->failstate_memory += p->failstate_memory; } -#ifdef BNFA_MAIN -#include -/* -* BNFA Search Function -* -* bnfa - state machine -* Tx - text buffer to search -* n - number of bytes in Tx -* Match - function to call when a match is found -* data - user supplied data that is passed to the Match function -* sindex - state tracker, set value to zero to reset the state machine, -* zero should be the value passed in on the 1st buffer or each buffer -* that is to be analyzed on its own, the state machine updates this -* during searches. This allows for sequential buffer searches without -* resetting the state machine. Save this value as returned from the -* previous search for the next search. -* -* returns -* The state or sindex of the state machine. This can than be passed back -* in on the next search, if desired. -*/ - -static unsigned bnfaSearch( - bnfa_struct_t* bnfa, uint8_t* Tx, int n, MpseMatch match, - void* context, unsigned sindex, int* current_state) -{ - assert(current_state); - int ret = 0; - - if (current_state) - { - sindex = (unsigned)*current_state; - } - -#ifdef ALLOW_NFA_FULL - if ( bnfa->bnfaFormat == BNFA_SPARSE ) - { - if ( bnfa->bnfaCaseMode == BNFA_PER_PAT_CASE ) - { - if (bnfa->bnfaMethod) - { - ret = _bnfa_search_csparse_nfa( - bnfa, Tx, n, match, context, sindex, current_state); - } - else - { - ret = _bnfa_search_csparse_nfa_q( - bnfa, Tx, n, match, context, sindex, current_state); - } - } - else if ( bnfa->bnfaCaseMode == BNFA_CASE ) - { - ret = _bnfa_search_csparse_nfa_case( - bnfa, Tx, n, match, context, sindex, current_state); - } - else /* NOCASE */ - { - ret = _bnfa_search_csparse_nfa_nocase( - bnfa, Tx, n, match, context, sindex, current_state); - } - } - else if ( bnfa->bnfaFormat == BNFA_FULL ) - { - if ( bnfa->bnfaCaseMode == BNFA_PER_PAT_CASE ) - { - ret = _bnfa_search_full_nfa( - bnfa, Tx, n, match, context, (bnfa_state_t)sindex, current_state); - } - else if ( bnfa->bnfaCaseMode == BNFA_CASE ) - { - ret = _bnfa_search_full_nfa_case( - bnfa, Tx, n, match, context, (bnfa_state_t)sindex, current_state); - } - else - { - ret = _bnfa_search_full_nfa_nocase( - bnfa, Tx, n, match, context, (bnfa_state_t)sindex, current_state); - } - } -#else - if ( bnfa->bnfaCaseMode == BNFA_PER_PAT_CASE ) - { - if (bnfa->bnfaMethod) - { - ret = _bnfa_search_csparse_nfa( - bnfa, Tx, n, match, context, sindex, current_state); - } - else - { - ret = _bnfa_search_csparse_nfa_q( - bnfa, Tx, n, match, context, sindex, current_state); - } - } - else if ( bnfa->bnfaCaseMode == BNFA_CASE ) - { - ret = _bnfa_search_csparse_nfa_case( - bnfa, Tx, n, match, context, sindex, current_state); - } - else /* NOCASE */ - { - ret = _bnfa_search_csparse_nfa_nocase( - bnfa, Tx, n, match, context, sindex, current_state); - } -#endif - return ret; -} - -/* -* Text Data Buffer -*/ -static uint8_t text[512]; -static uint8_t text2[512]; -static int s_verbose=0; - -/* -* A Match is found -*/ -static int MatchFound(void* id, void* tree, int index, void* data, void* neglist) -{ - fprintf (stdout, "%s\n", (char*)data); - return 0; -} - -static void objfree(void** obj) -{ -} - -static int buildtree(void* id, void** existing) -{ - return 1; -} - -static int neglist(void* id, void** list) -{ - return 1; -} - -static void LogMessage(const char* format,...) -{ - va_list ap; - va_start(ap, format); - vfprintf(stderr, format, ap); - va_end(ap); -} - -static SnortConfig sc; -static SnortConfig* snort_conf; - -/* -* -*/ -int main(int argc, char** argv) -{ - int i, nc, nocase = 0; - bnfa_struct_t* bnfa; - int current_state = 0; - bool split_search = false; - char* p; - - if (argc < 3) - { - fprintf (stderr,"Usage: %s search-text pattern +pattern... [flags]\n",argv[0]); - fprintf (stderr," flags: -q -nocase -splitsearch -v\n"); - exit (0); - } - - memset(&sc, 0, sizeof(SnortConfig)); - snort_conf = ≻ - - bnfa = bnfaNew(free, objfree, objfree); - if ( !bnfa ) - { - printf("bnfa-no memory\n"); - exit(0); - } - - strncpy (text, argv[1], sizeof(text) - 1); - text[sizeof(text) - 1] = '\0'; - - bnfa->bnfaMethod = 1; - - for (i = 1; i < argc; i++) - { - if (strcmp (argv[i], "-nocase") == 0) - { - nocase = 1; - } - if (strcmp (argv[i], "-v") == 0) - { - s_verbose=1; - } - if (strcmp (argv[i], "-splitsearch") == 0) - { - int len2 = strlen(text)/2; - split_search =true; - strncpy(text2, &text[len2], sizeof(text2) -1); - text[len2] = '\0'; - text2[len2] = '\0'; - } - - if (strcmp (argv[i], "-q") == 0) - { - bnfa->bnfaMethod = 0; - } - } - - for (i = 2; i < argc; i++) - { - if (argv[i][0] == '-') - continue; - - p = argv[i]; - - if ( *p == '+') - { - nc=1; - p++; - } - else - { - nc = nocase; - } - - bnfaAddPattern (bnfa, (uint8_t*)p, strlen(p), nc, 0, (void*)NULL); - } - - if (s_verbose) - printf("Patterns added\n"); - - //Print_DFA (acsm); - - bnfaCompile (bnfa, buildtree, neglist); - - //Write_DFA(acsm, "bnfa-snort.dfa") ; - - if (s_verbose) - printf("Patterns compiled--written to file.\n"); - - bnfaPrintInfo (bnfa); - bnfaPrintSummary ( ); - - bnfaSearch (bnfa, text, strlen (text), MatchFound, NULL, current_state, ¤t_state); - - if (split_search) - bnfaSearch (bnfa, text2, strlen (text2), MatchFound, NULL, current_state, ¤t_state); - - bnfaFree (bnfa); - - printf ("normal pgm end\n"); - - return (0); -} -#endif - diff --git a/src/sfrt/sfrt.cc b/src/sfrt/sfrt.cc index 7afb4d4c0..b4d5fce17 100644 --- a/src/sfrt/sfrt.cc +++ b/src/sfrt/sfrt.cc @@ -598,55 +598,3 @@ static inline int allocateTableIndex(table_t* table) return 0; } -#ifdef DEBUG_SFRT - -#define NUM_IPS 32 -#define NUM_DATA 4 - -int main() -{ - uint32_t ip_list[NUM_IPS]; /* entirely arbitrary */ - char data[NUM_DATA]; /* also entirely arbitrary */ - - for (uint32_t index=0; index %c\n", index, ip_list[index], - data[index%NUM_DATA], *(uint32_t*)sfrt_lookup(&ip_list[index], dir)); - } - - for (uint32_t index=0; index < NUM_IPS; index++) - { - uint32_t val = *(uint32_t*)sfrt_lookup(&ip_list[index], dir); - printf("\t@%u\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; -} - -#endif /* DEBUG_SFRT */ - diff --git a/src/utils/kmap.cc b/src/utils/kmap.cc index 0502aebf9..f25481a92 100644 --- a/src/utils/kmap.cc +++ b/src/utils/kmap.cc @@ -408,74 +408,3 @@ void* KMapFindNext(KMAP* km) } //namespace snort -#ifdef KMAP_MAIN -/* -* -*/ -using namespace snort; -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(snort_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; -} - -#endif - diff --git a/src/utils/util_jsnorm.cc b/src/utils/util_jsnorm.cc index 90fbf10f8..7d3cbceb6 100644 --- a/src/utils/util_jsnorm.cc +++ b/src/utils/util_jsnorm.cc @@ -1280,54 +1280,6 @@ int JSNormalizeDecode(const char* src, uint16_t srclen, char* dst, uint16_t dest return RET_OK; } +} -/* -int main(int argc, char *argv[]) -{ - FILE *iFile = NULL; - FILE *oFile = NULL; - char input[65535]; - char output[65535]; - int bytes_copied = 0; - int bytes_read = 0; - int ret = 0; - char *ptr = input; - JSState js; - - if( argc == 3 ) - { - iFile = fopen(argv[1], "r"); - oFile = fopen(argv[2], "w"); - } - - if(!oFile || !iFile) - { - fprintf(stderr, "usage: %s \n", argv[0]); - return -1; - } - - bytes_read = fread(input, 1, sizeof(input), iFile); - js.allowed_spaces = 3; - js.allowed_levels = 1; - js.alerts = 0; - - ret = JSNormalizeDecode(input, bytes_read, output, sizeof(output),&ptr, &bytes_copied, &js, NULL); - if( ret == RET_OK) - { - fwrite( output, 1, bytes_copied, oFile); - printf("OUTPUT IS %.*s\n",bytes_copied,output); - printf("REMAINING is %s\n",ptr); - if( js.alerts & ALERT_MIXED_ENCODINGS ) - printf("ALERT MIXED ENCODINGS\n"); - if(js.alerts & ALERT_SPACES_EXCEEDED) - printf("ALERT SPACES EXCEEDED\n"); - if(js.alerts & ALERT_LEVELS_EXCEEDED) - printf("ALERT LEVELS EXCEEDED\n"); - } - fclose(iFile); - fclose(oFile); - return 0; - -}*/ -}