Changeset 1585

Show
Ignore:
Timestamp:
03/02/08 17:50:20 (7 months ago)
Author:
till
Message:

nebula
- thread synchronization improved
- segfault on empty secret fixed
- cluster size management corrected

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nebula/trunk/src/classify.c

    r1584 r1585  
    6363        hash            *tmp_hash; 
    6464        u_char          *tmpbuf; 
    65         qelem           *cur_cqelem, *tmp_cqelem, *cur_hqelem, *tmp_hqelem
     65        qelem           *cur_cqelem, *tmp_cqelem, *cur_hqelem, *tmp_hqelem, *qtail
    6666        double          score, max_score; 
    6767        pthread_t       ntid; 
    6868        pthread_attr_t  ptattr; 
    6969 
     70        qtail           = NULL; 
    7071        tmpbuf          = NULL; 
    7172        max_score       = 0.0; 
     
    7677        } 
    7778 
    78         pthread_rwlock_rdlock(&md5sum_trie_lock); 
    79         t = trie_find_memstr(&md5sum_trie, (u_char *) s->md5sum, strlen(s->md5sum)); 
     79        // create new element in md5sum trie 
     80        pthread_rwlock_wrlock(&md5sum_trie_lock); 
     81        t = trie_memins(&md5sum_trie, (u_char *) s->md5sum, strlen(s->md5sum), NULL); 
    8082        pthread_rwlock_unlock(&md5sum_trie_lock); 
    8183 
    82         if (t != NULL) { 
    83                 // md5sum is already in trie 
    84                 ((hash*)t->data)->cnt++; 
    85                  
    86                 if (verbose > 1) printf("    MD5 hash is %s (%u instances)\n", ((hash*)t->data)->md5sum, ((hash*)t->data)->cnt); 
    87                 if (verbose) printf("    Absolute MD5 match found.\n"); 
    88                 return(0); 
    89         } else { 
    90                 // md5sum not in trie, create new element 
    91                 pthread_rwlock_wrlock(&md5sum_trie_lock); 
    92                 t = trie_memins(&md5sum_trie, (u_char *) s->md5sum, strlen(s->md5sum), NULL); 
    93                 pthread_rwlock_unlock(&md5sum_trie_lock); 
    94  
    95                 if ((t->data = calloc(1, sizeof(hash))) == NULL) { 
    96                         fprintf(stderr, "Error - Unable to allocate memory: %m.\n"); 
    97                         exit(EXIT_FAILURE); 
    98                 } 
    99                 ((hash*)t->data)->hashlen       = 32; 
    100                 ((hash*)t->data)->md5sum        = s->md5sum; 
    101  
    102                 if ((((hash*)t->data)->submission = calloc(1, sizeof(submission))) == NULL) { 
    103                         fprintf(stderr, "Error - Unable to allocate memory: m.\n"); 
    104                         exit(EXIT_FAILURE); 
    105                 } 
    106                 memcpy(((hash*)t->data)->submission, s, sizeof(submission)); 
    107                 ((hash*)t->data)->cnt++; 
    108  
    109                 // set spamsum hash 
    110                 if ((((hash*)t->data)->spamsum = spamsum(s->attack, s->attack_len, 0)) == NULL) { 
    111                         fprintf(stderr, "Error - Unable to allocate memoory: %m.\n"); 
    112                         exit(EXIT_FAILURE); 
    113                 } 
    114                 if (verbose > 1) printf("    MD5 hash is %s (%u instances)\n", ((hash*)t->data)->md5sum, ((hash*)t->data)->cnt); 
    115  
    116  
    117                 Q_WLOCK(&clusterq->lock); 
    118  
    119                 // connect all clusters within range 
    120                 for (cur_cqelem = clusterq->head; cur_cqelem; cur_cqelem = cur_cqelem->next) { 
    121                         for (cur_hqelem = ((cluster *)cur_cqelem->data)->hq->head; cur_hqelem; cur_hqelem = cur_hqelem->next) { 
    122                                 if ((score = spamsum_match(((hash*)t->data)->spamsum, ((hash*)cur_hqelem->data)->spamsum)) >= cluster_radius) { 
    123                                         if (!((hash*)t->data)->cl) { 
    124                                                 add_entry_to_cluster((cluster *)cur_cqelem->data, (hash*)t->data); 
    125                                                 if (verbose) printf("    Cluster has now %u elements (threshold is %lu).\n", 
    126                                                         ((hash*)t->data)->cl->cnt, ((hash*)t->data)->cl->threshold); 
    127                                                 break; 
    128                                         } else { 
    129                                                 if ((cluster *) cur_cqelem->data != ((hash*)t->data)->cl) 
    130                                                         clusters_merge(clusterq, (cluster *) cur_cqelem->data, ((hash*)t->data)->cl); 
    131                                                 break; 
    132                                         } 
    133                                 } else if (score > max_score) max_score = score; 
    134                         } 
    135                 } 
    136  
    137                 // connect all outliers within range 
    138                 for (cur_hqelem = outlierq->head; cur_hqelem; cur_hqelem = cur_hqelem->next) { 
     84        if ((t->data = calloc(1, sizeof(hash))) == NULL) { 
     85                fprintf(stderr, "Error - Unable to allocate memory: %m.\n"); 
     86                exit(EXIT_FAILURE); 
     87        } 
     88        ((hash*)t->data)->hashlen       = 32; 
     89        ((hash*)t->data)->md5sum        = s->md5sum; 
     90 
     91        if ((((hash*)t->data)->submission = calloc(1, sizeof(submission))) == NULL) { 
     92                fprintf(stderr, "Error - Unable to allocate memory: m.\n"); 
     93                exit(EXIT_FAILURE); 
     94        } 
     95        memcpy(((hash*)t->data)->submission, s, sizeof(submission)); 
     96        ((hash*)t->data)->cnt++; 
     97 
     98        // set spamsum hash 
     99        if ((((hash*)t->data)->spamsum = spamsum(s->attack, s->attack_len, 0)) == NULL) { 
     100                fprintf(stderr, "Error - Unable to allocate memoory: %m.\n"); 
     101                exit(EXIT_FAILURE); 
     102        } 
     103        if (verbose > 1) printf("    MD5 hash is %s (%u instances)\n", ((hash*)t->data)->md5sum, ((hash*)t->data)->cnt); 
     104 
     105 
     106        Q_RLOCK(&clusterq->lock); 
     107 
     108        // connect all clusters within range 
     109        for (cur_cqelem = clusterq->head; cur_cqelem; cur_cqelem = cur_cqelem->next) { 
     110                for (cur_hqelem = ((cluster *)cur_cqelem->data)->hq->head; cur_hqelem; cur_hqelem = cur_hqelem->next) { 
    139111                        if ((score = spamsum_match(((hash*)t->data)->spamsum, ((hash*)cur_hqelem->data)->spamsum)) >= cluster_radius) { 
    140                                 // unlink match from outlier list 
    141  
    142                                 tmp_hqelem = cur_hqelem; 
    143                                 cur_hqelem = cur_hqelem->next; 
    144                                 if ((tmp_hash = queue_unlink(outlierq, tmp_hqelem)) == NULL) { 
    145                                         fprintf(stderr, "Error - Unable to unlink outlier from queue.\n"); 
    146                                         exit(EXIT_FAILURE); 
    147                                 } 
    148                                 if (((hash*)t->data)->cl) { 
    149                                         // add other outliers to cluster 
    150                                         if (add_entry_to_cluster(((hash*)t->data)->cl, tmp_hash) == NULL) { 
     112                                if (!((hash*)t->data)->cl) { 
     113                                        Q_ULOCK(&clusterq->lock); 
     114                                        Q_WLOCK(&clusterq->lock); 
     115                                        if ((qtail = add_entry_to_cluster((cluster *)cur_cqelem->data, (hash*)t->data, clusterhashq_max)) != NULL) { 
     116                                                tmp_hash = qtail->data; 
    151117 
    152118                                                pthread_rwlock_wrlock(&md5sum_trie_lock); 
     
    159125 
    160126                                                hash_free(tmp_hash); 
    161  
    162  
    163                                         } else if (verbose) printf("    Cluster has now %u elements (threshold is %lu).\n", 
    164                                                 ((hash*)t->data)->cl->cnt, ((hash*)t->data)->cl->threshold); 
     127                                        } 
     128                                        Q_ULOCK(&clusterq->lock); 
     129                                        Q_RLOCK(&clusterq->lock); 
     130                                        if (verbose) printf("    Cluster has now %u elements (threshold is %lu).\n", 
     131                                                ((hash*)t->data)->cl->hq->size, ((hash*)t->data)->cl->threshold); 
     132                                        break; 
    165133                                } else { 
    166                                         // create new cluster of two outliers 
    167                                         if ((tmp_cqelem = queue_ins(clusterq, create_cluster(((hash*)t->data), tmp_hash), clusterq_max)) != NULL) { 
    168                                                 /* cluster queue is full, last element was dropped and must be free()d */ 
    169                                                  
    170                                                 /* first remove hashes from tries */ 
    171                                                 for (tmp_hqelem = ((cluster *)tmp_cqelem->data)->hq->head; tmp_hqelem; tmp_hqelem=tmp_hqelem->next) { 
    172  
    173                                                         pthread_rwlock_wrlock(&md5sum_trie_lock); 
    174                                                         trie_del_memstr(&md5sum_trie, (u_char *) ((hash *)tmp_hqelem->data)->md5sum, 
    175                                                                 strlen(((hash *)tmp_hqelem->data)->md5sum)); 
    176                                                         pthread_rwlock_unlock(&md5sum_trie_lock); 
    177  
    178                                                         pthread_rwlock_wrlock(&spamsum_trie_lock); 
    179                                                         trie_del_memstr(&spamsum_trie, (u_char *) ((hash *)tmp_hqelem->data)->spamsum, 
    180                                                                 strlen(((hash *)tmp_hqelem->data)->spamsum)); 
    181                                                         pthread_rwlock_unlock(&spamsum_trie_lock); 
    182                                                 } 
    183                                                 /* now free cluster */ 
    184                                                 cluster_free((cluster *)tmp_cqelem->data); 
    185                                                 free(tmp_cqelem); 
    186                                         } 
    187                                         /* set cluster element's parent pointer to cluster queue head 
    188                                          * we need this to be able to unlink a cluster from the queue */ 
    189                                         ((cluster *) clusterq->head->data)->parent = clusterq->head; 
    190  
    191                                         if (verbose) printf("    New Cluster created.\n"); 
     134                                        if ((cluster *) cur_cqelem->data != ((hash*)t->data)->cl) 
     135                                                clusters_merge(clusterq, (cluster *) cur_cqelem->data, ((hash*)t->data)->cl); 
     136                                        break; 
    192137                                } 
    193138                        } else if (score > max_score) max_score = score; 
    194                         if (!cur_hqelem) break; 
    195                 } 
    196  
    197  
    198                 Q_ULOCK(&clusterq->lock); 
    199  
    200  
    201                          
    202                 if (verbose > 1) printf("    Spamsum is %s (%u instances)\n", ((hash*)t->data)->spamsum, ((hash*)t->data)->cnt); 
    203  
    204                 if (!((hash*)t->data)->cl) { 
    205                         // insert outlier into queue 
    206                         if (outlierq->size >= outlierq_max) { 
    207                                 tmp_hash = queue_unlink(outlierq, outlierq->tail); 
    208  
    209                                 pthread_rwlock_wrlock(&md5sum_trie_lock); 
    210                                 trie_del_memstr(&md5sum_trie, (u_char *) tmp_hash->md5sum, strlen(tmp_hash->md5sum)); 
    211                                 pthread_rwlock_unlock(&md5sum_trie_lock); 
    212  
    213                                 pthread_rwlock_wrlock(&spamsum_trie_lock); 
    214                                 trie_del_memstr(&spamsum_trie, (u_char *) tmp_hash->spamsum, strlen(tmp_hash->spamsum)); 
    215                                 pthread_rwlock_unlock(&spamsum_trie_lock); 
    216  
    217                                 hash_free(tmp_hash); 
     139                } 
     140        } 
     141 
     142        // connect all outliers within range 
     143        for (cur_hqelem = outlierq->head; cur_hqelem; cur_hqelem = cur_hqelem->next) { 
     144                if ((score = spamsum_match(((hash*)t->data)->spamsum, ((hash*)cur_hqelem->data)->spamsum)) >= cluster_radius) { 
     145                // unlink match from outlier list 
     146 
     147                        tmp_hqelem = cur_hqelem; 
     148                        cur_hqelem = cur_hqelem->next; 
     149                        if ((tmp_hash = queue_unlink(outlierq, tmp_hqelem)) == NULL) { 
     150                                fprintf(stderr, "Error - Unable to unlink outlier from queue.\n"); 
     151                                exit(EXIT_FAILURE); 
    218152                        } 
    219                         queue_ins(outlierq, t->data, outlierq_max); 
    220  
    221                         if (verbose) printf("    Input added to outlier queue (maximum score: %1f, outlier queue size: %lu).\n", 
    222                                 max_score, outlierq->size); 
    223                 } 
     153                        if (((hash*)t->data)->cl) { 
     154                                // add other outliers to cluster 
     155                                Q_ULOCK(&clusterq->lock); 
     156                                Q_WLOCK(&clusterq->lock); 
     157                                if ((qtail = add_entry_to_cluster(((hash*)t->data)->cl, tmp_hash, outlierq_max)) != NULL) { 
     158                                        tmp_hash = qtail->data; 
     159 
     160                                        pthread_rwlock_wrlock(&md5sum_trie_lock); 
     161                                        trie_del_memstr(&md5sum_trie, (u_char *) tmp_hash->md5sum, strlen(tmp_hash->md5sum)); 
     162                                        pthread_rwlock_unlock(&md5sum_trie_lock); 
     163 
     164                                        pthread_rwlock_wrlock(&spamsum_trie_lock); 
     165                                        trie_del_memstr(&spamsum_trie, (u_char *) tmp_hash->spamsum, strlen(tmp_hash->spamsum)); 
     166                                        pthread_rwlock_unlock(&spamsum_trie_lock); 
     167 
     168                                        hash_free(tmp_hash); 
     169                                        free(qtail); 
     170                                } else if (verbose) printf("    Cluster has now %u elements (threshold is %lu).\n", 
     171                                        ((hash*)t->data)->cl->hq->size, ((hash*)t->data)->cl->threshold); 
     172                        } else { 
     173                                // create new cluster of two outliers 
     174                                Q_ULOCK(&clusterq->lock); 
     175                                Q_WLOCK(&clusterq->lock); 
     176                                if ((tmp_cqelem = queue_ins(clusterq, create_cluster(((hash*)t->data), tmp_hash, clusterhashq_max), 
     177                                        clusterq_max)) != NULL) { 
     178                                        /* cluster queue is full, last element was dropped and must be free()d */ 
     179                                         
     180                                        /* first remove hashes from tries */ 
     181                                        for (tmp_hqelem = ((cluster *)tmp_cqelem->data)->hq->head; tmp_hqelem; tmp_hqelem=tmp_hqelem->next) { 
     182 
     183                                                pthread_rwlock_wrlock(&md5sum_trie_lock); 
     184                                                trie_del_memstr(&md5sum_trie, (u_char *) ((hash *)tmp_hqelem->data)->md5sum, 
     185                                                        strlen(((hash *)tmp_hqelem->data)->md5sum)); 
     186                                                pthread_rwlock_unlock(&md5sum_trie_lock); 
     187 
     188                                                pthread_rwlock_wrlock(&spamsum_trie_lock); 
     189                                                trie_del_memstr(&spamsum_trie, (u_char *) ((hash *)tmp_hqelem->data)->spamsum, 
     190                                                        strlen(((hash *)tmp_hqelem->data)->spamsum)); 
     191                                                pthread_rwlock_unlock(&spamsum_trie_lock); 
     192                                        } 
     193                                        /* now free cluster */ 
     194                                        cluster_free((cluster *)tmp_cqelem->data); 
     195                                        free(tmp_cqelem); 
     196                                } 
     197                                /* set cluster element's parent pointer to cluster queue head 
     198                                 * we need this to be able to unlink a cluster from the queue */ 
     199                                ((cluster *) clusterq->head->data)->parent = clusterq->head; 
     200 
     201                                if (verbose) printf("    New Cluster created.\n"); 
     202                        } 
     203                        Q_ULOCK(&clusterq->lock); 
     204                        Q_RLOCK(&clusterq->lock); 
     205                } else if (score > max_score) max_score = score; 
     206                if (!cur_hqelem) break; 
     207        } 
     208 
     209        Q_ULOCK(&clusterq->lock); 
     210 
     211                 
     212        if (verbose > 1) printf("    Spamsum is %s (%u instances)\n", ((hash*)t->data)->spamsum, ((hash*)t->data)->cnt); 
     213 
     214        if (!((hash*)t->data)->cl) { 
     215                // insert outlier into queue 
     216                if (outlierq->size >= outlierq_max) { 
     217                        tmp_hash = queue_unlink(outlierq, outlierq->tail); 
     218 
     219                        pthread_rwlock_wrlock(&md5sum_trie_lock); 
     220                        trie_del_memstr(&md5sum_trie, (u_char *) tmp_hash->md5sum, strlen(tmp_hash->md5sum)); 
     221                        pthread_rwlock_unlock(&md5sum_trie_lock); 
     222 
     223                        pthread_rwlock_wrlock(&spamsum_trie_lock); 
     224                        trie_del_memstr(&spamsum_trie, (u_char *) tmp_hash->spamsum, strlen(tmp_hash->spamsum)); 
     225                        pthread_rwlock_unlock(&spamsum_trie_lock); 
     226 
     227                        hash_free(tmp_hash); 
     228                        free(qtail); 
     229                } 
     230                queue_ins(outlierq, t->data, outlierq_max); 
     231 
     232                if (verbose) printf("    Input added to outlier queue (maximum score: %.1f, outlier queue size: %lu).\n", 
     233                        max_score, (long unsigned) outlierq->size); 
    224234        } 
    225235 
    226236        // check for signature generation criterion here 
    227         if ((((hash*)t->data)->cl) && ((hash*)t->data)->cl->cnt >= ((hash*)t->data)->cl->threshold) { 
     237        if ((((hash*)t->data)->cl) && ((hash*)t->data)->cl->hq->size >= ((hash*)t->data)->cl->threshold) { 
    228238                printf("[=] Cluster size (%u) hit threshold (%lu), generating signature.\n", 
    229                         ((hash*)t->data)->cl->cnt, ((hash*)t->data)->cl->threshold); 
     239                        ((hash*)t->data)->cl->hq->size, ((hash*)t->data)->cl->threshold); 
    230240 
    231241                // set threshold to current size plus 1 
    232                 ((hash*)t->data)->cl->threshold = ((hash*)t->data)->cl->cnt + 1; 
     242                ((hash*)t->data)->cl->threshold = ((hash*)t->data)->cl->hq->size + 1; 
    233243 
    234244                if (pthread_attr_init(&ptattr) || 
  • nebula/trunk/src/cluster.c

    r1566 r1585  
    6868 
    6969 
    70 cluster *add_entry_to_cluster(cluster *cl, hash *entry) { 
     70qelem *add_entry_to_cluster(cluster *cl, hash *entry, const ssize_t max_size) { 
    7171        qelem   *new; 
    7272 
    7373        CL_WLOCK(cl); 
    74         if (cl->hq->size < clusterhashq_max) { 
    75                 // set cluster pointer in hash struct 
    76                 entry->cl = cl; 
    7774 
    78                 // add hash to queue 
    79                 if ((new = queue_prepend(cl->hq, entry)) == NULL) { 
    80                         fprintf(stderr, "Error - Could not add entry to cluster.\n"); 
    81                         exit(EXIT_FAILURE); 
    82                 } 
    83                 cl->cnt++; 
    84         } else { 
    85                 if (verbose) fprintf(stderr, "Warning - Could not add hash to cluster queue: Maximum size reached.\n"); 
    86                 return(NULL); 
     75        // set cluster pointer in hash struct 
     76        entry->cl = cl; 
     77 
     78        // add hash as new head to queue 
     79        if ((new = queue_prepend(cl->hq, entry)) == NULL) { 
     80                fprintf(stderr, "Error - Could not add entry to cluster.\n"); 
     81                exit(EXIT_FAILURE); 
    8782        } 
     83 
     84        if (max_size && cl->hq->size > max_size) { 
     85                // max queue size reached, drop and return tail element 
     86                if (verbose > 1) fprintf(stderr, "    Maximum queue size reached, dropping tail.\n"); 
     87                CL_ULOCK(cl); 
     88                return(queue_cuttail(cl->hq)); 
     89        } 
     90 
    8891        CL_ULOCK(cl); 
    89  
    90         return(cl); 
     92        return(NULL); 
    9193} 
    9294 
    9395 
    94 cluster *create_cluster(hash *l1, hash *l2) { 
     96cluster *create_cluster(hash *l1, hash *l2, const ssize_t max_size) { 
    9597        cluster *cl = cluster_new(); 
    9698 
    97         add_entry_to_cluster(cl, l1); 
    98         add_entry_to_cluster(cl, l2); 
     99        add_entry_to_cluster(cl, l1, max_size); 
     100        add_entry_to_cluster(cl, l2, max_size); 
    99101 
    100102        return(cl); 
     
    113115                dst->hq->size += src->hq->size; 
    114116 
    115                 // add thresholds 
    116                 dst->threshold += max(src->threshold, src->cnt); 
     117                // calculate new thresholds 
     118                if (src->hq->size + dst->hq->size >= max(src->threshold, dst->threshold)) 
     119                        dst->threshold += src->threshold; 
     120                else 
     121                        dst->threshold = max(src->threshold, dst->threshold); 
    117122 
    118123                // let elements of src point to dst 
  • nebula/trunk/src/cluster.h

    r1566 r1585  
    5959 
    6060inline cluster *create_hashlist(hash *hl1, hash *hl2); 
    61 cluster *add_entry_to_cluster(cluster *cl, hash *entry); 
    62 cluster *create_cluster(hash *l1, hash *l2); 
     61qelem *add_entry_to_cluster(cluster *cl, hash *entry, const ssize_t max_size); 
     62cluster *create_cluster(hash *l1, hash *l2, const ssize_t max_size); 
    6363cluster *clusters_merge(queue *q, cluster *dst, cluster *src); 
    6464void clusterlist_delete(cluster *list); 
  • nebula/trunk/src/nebula.c

    r1583 r1585  
    105105        snort_pid               = 0;            // h 
    106106        outlierq_max            = 500000;       // O 
    107         port                    = 12346;       // p: 12345 
     107        port                    = 4712;                // p: 4712 
    108108        secret                  = NULL;         // s: NULL 
    109109        verbose                 = 0;            // v: don't be verbose 
     
    239239                printf("  Initial cluster size threshold: %lu\n", initial_threshold); 
    240240                printf("  Cluster criterion (minimal similarity): %.1f percent\n", cluster_radius); 
     241                printf("  Accepting submissions on port %u/tcp.\n", port); 
    241242        } 
    242243        printf("\n"); 
  • nebula/trunk/src/queue.h

    r1566 r1585  
    5050void queue_free(queue *q, void(*cbfn)(void *data)); 
    5151qelem *queue_ins(queue *q, void *data, ssize_t max_size); 
     52inline qelem *queue_cuttail(queue *q); 
    5253void *queue_unlink(queue *q, qelem *e); 
    5354inline qelem *queue_prepend(queue *q, void *data); 
  • nebula/trunk/src/session.c

    r1584 r1585  
    147147                        s->state = UNAUTHENTICATED; 
    148148 
    149                         if ((secret_nonce = calloc(1, strlen(secret) + 4)) == NULL) { 
    150                                 fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
    151                                 return(-1); 
    152                         } 
    153                         memcpy(secret_nonce, secret, strlen(secret)); 
    154                         memcpy(&secret_nonce[strlen(secret)], &s->nonce, 4); 
    155  
    156                         if ((sha512sum = mem_sha512sum((u_char *) secret_nonce, strlen(secret)+4)) == NULL) { 
    157                                 fprintf(stderr, "Error - Unable to hash secret.\n"); 
    158                                 return(-1); 
    159                         } 
    160                         free(secret_nonce); 
     149                        if (secret) { 
     150                                if ((secret_nonce = calloc(1, strlen(secret) + 4)) == NULL) { 
     151                                        fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
     152                                        return(-1); 
     153                                } 
     154                                memcpy(secret_nonce, secret, strlen(secret)); 
     155                                memcpy(&secret_nonce[strlen(secret)], &s->nonce, 4); 
     156 
     157                                if ((sha512sum = mem_sha512sum((u_char *) secret_nonce, strlen(secret)+4)) == NULL) { 
     158                                        fprintf(stderr, "Error - Unable to hash secret.\n"); 
     159                                        return(-1); 
     160                                } 
     161                                free(secret_nonce); 
     162                        } else { 
     163                                if ((sha512sum = mem_sha512sum((u_char *) &s->nonce, 4)) == NULL) { 
     164                                        fprintf(stderr, "Error - Unable to hash secret.\n"); 
     165                                        return(-1); 
     166                                } 
     167                        } 
    161168 
    162169                        if (!strncmp(sha512sum, s->secret_hash, 128)) { 
  • nebula/trunk/src/sig.c

    r1583 r1585  
    150150 
    151151                // increase size threshold for this cluster 
    152                 cl->threshold *= 1.5; 
     152                if (cl->threshold >= cl->hq->size) cl->threshold = cl->hq->size; 
     153                else cl->threshold *= 1.5; 
    153154 
    154155                free(sigdata); 
     
    164165 
    165166                // increment size threshold 
    166                 cl->threshold *= 1.1; 
     167                if (cl->threshold >= cl->hq->size) cl->threshold = cl->hq->size; 
     168                else cl->threshold *= 1.1; 
    167169        } 
    168170        free(sigdata); 
     
    334336        } 
    335337 
    336 //     Q_RLOCK(&clusterq->lock); 
     338       CL_RLOCK(attacks); 
    337339        for (qe = attacks->hq->head; qe; qe = qe->next) { 
    338340                attack = ((hash *)qe->data)->submission; 
     
    370372                strllen++; 
    371373        } 
    372 //     Q_ULOCK(&clusterq->lock); 
     374       CL_ULOCK(attacks); 
    373375 
    374376        // print concatenated string 
     
    390392        if (verbose) printf("Constructing generalized suffix tree.\n"); 
    391393        pthread_mutex_lock(&siggen_mutex); 
    392         // if cluster threshold has increased in the meantime, return 
    393394        if ((gst = ST_AddStringList(gst, strlist, strllen)) == NULL) { 
    394395                fprintf(stderr, "Error - Unable to add attack to suffix tree.\n"); 
  • nebula/trunk/src/signals.c

    r1583 r1585  
    6666                if (cluster_radius > 5.0) { 
    6767                        cluster_radius -= 5.0; 
    68                         write(STDOUT_FILENO, "[*] Cluster criterion decreased by 5 percent\n", 44); 
     68                        write(STDOUT_FILENO, "[*] Cluster criterion decreased by 5 percent\n", 45); 
    6969                } else { 
    7070                        cluster_radius = 0.0; 
    71                         write(STDOUT_FILENO, "[*] Cluster criterion decreased to 0 percent\n", 44); 
     71                        write(STDOUT_FILENO, "[*] Cluster criterion decreased to 0 percent\n", 45); 
    7272                } 
    7373                return;