Changeset 1623

Show
Ignore:
Timestamp:
04/27/08 14:47:15 (2 weeks ago)
Author:
till
Message:

nebula
- cleanups for first release (0.2.2)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nebula/trunk/client/nebulaclient.c

    r1612 r1623  
    11/* nebula-client.c 
     2 * 
    23 * Copyright (C) 2008 Tillmann Werner <tillmann.werner@gmx.de> 
    34 * 
     
    5859                if (read_chars >= len-1) { 
    5960                        fprintf(stderr, "Error while reading from socket - Line exceeds buffer (%u bytes).\n", read_chars); 
    60 line[read_chars] = 0; 
    61 printf("line: %s\n", line); 
    6261                        exit(EXIT_FAILURE); 
    6362                } 
     
    117116 
    118117int main(int argc, char **argv) { 
     118        u_char                  verbose, time_sort, protocol, *cbuf, response[9]; 
     119        u_int16_t               hmac_port, port, send_len_short; 
     120        u_int32_t               send_len_long, nonce, nebula_port; 
     121        char                    option, *dirname, *curfile, *md5sum, *sha512sum, *nebula_host, *secret; 
     122        int                     i, n, sock_fd, total_files, num_of_files; 
     123        unsigned long           cbuf_len; 
     124        ssize_t                 bytes_read, total_bytes; 
    119125        struct hostent          *host; 
    120         u_int32_t               send_len_long; 
    121         unsigned long           cbuf_len; 
    122         u_char                  verbose, time_sort, protocol, *cbuf, response[9]; 
    123         u_int32_t               nonce, nebula_port; 
    124         u_int16_t               hmac_port, port, send_len_short; 
    125126        struct sockaddr_in      sock; 
    126         int                     i, n, sock_fd, total_files, num_of_files; 
    127         ssize_t                 bytes_read, total_bytes; 
    128         char                    option, *dirname, *curfile, *md5sum, *sha512sum, *nebula_host, *secret; 
     127        struct dirent           *dir_entry, **namelist; 
     128        DIR                     *dirp; 
    129129        bstring                 bstr; 
    130         struct dirent           *dir_entry; 
    131         DIR                     *dirp; 
    132         struct dirent           **namelist; 
    133130 
    134131        i                       = 0; 
  • nebula/trunk/configure.in

    r1618 r1623  
    2727 
    2828 
     29 
     30AC_CHECK_HEADER(zlib.h,, AC_MSG_ERROR([zlib headers not found.])) 
     31AC_CHECK_LIB(z, gzgets,, AC_MSG_ERROR([zlib not found.])) 
     32 
     33 
     34AC_CHECK_HEADER(pthread.h,, AC_MSG_ERROR([pthread headers not found.])) 
     35AC_CHECK_LIB(pthread, pthread_create,, AC_MSG_ERROR([pthread library not found.])) 
     36 
     37 
    2938# Check for electric fence malloc debugger 
    3039AC_ARG_ENABLE(efence, 
  • nebula/trunk/src/Makefile.am

    r1613 r1623  
    1 AM_CFLAGS=-Wall -Werror -D_GNU_SOURCE -g 
     1AM_CFLAGS=-Wall -Werror -D_GNU_SOURCE 
    22 
    33LIBS += -lm -lz -lpthread 
  • nebula/trunk/src/avl.c

    r1558 r1623  
    119119    
    120120        if (t->cmpfn((*n)->data, (*n)->size, a->data, a->size) > 0) { 
    121         /* insert into the left subtree */ 
     121        // insert into the left subtree 
    122122        if ((*n)->left) { 
    123123                if (avl_insert(t, &((*n)->left), a)) { 
     
    145145        } 
    146146   } else { 
    147         /* insert into the right subtree */ 
     147        // insert into the right subtree 
    148148        if ((*n)->right) { 
    149149                if (avl_insert(t, &((*n)->right), a)) { 
  • nebula/trunk/src/classify.c

    r1620 r1623  
    9898 
    9999        if ((t->data = calloc(1, sizeof(hash))) == NULL) { 
    100                 fprintf(stderr, "Error - Unable to allocate memory: %m.\n"); 
     100                fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
    101101                exit(EXIT_FAILURE); 
    102102        } 
     
    113113        // set spamsum hash 
    114114        if ((((hash*)t->data)->spamsum = spamsum(s->attack, s->attack_len, 0)) == NULL) { 
    115                 fprintf(stderr, "Error - Unable to allocate memoory: %m.\n"); 
     115                fprintf(stderr, "Error - Unable to allocate memoory: %s.\n", strerror(errno)); 
    116116                exit(EXIT_FAILURE); 
    117117        } 
  • nebula/trunk/src/cluster.c

    r1585 r1623  
    1919 */ 
    2020 
     21#include <errno.h> 
    2122#include <stdio.h> 
    2223#include <string.h> 
     
    3334        /* create new cluster */ 
    3435        if ((new = calloc(1, sizeof(cluster))) == NULL) { 
    35                 fprintf(stderr, "Error - Unable to allocate memory: %m.\n"); 
     36                fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
    3637                exit(EXIT_FAILURE); 
    3738        } 
    3839 
    3940        if (pthread_rwlock_init(&new->lock, NULL) != 0) { 
    40                 fprintf(stderr, "Error - Unable to initialize thread lock: %m.\n"); 
     41                fprintf(stderr, "Error - Unable to initialize thread lock: %s.\n", strerror(errno)); 
    4142                exit(EXIT_FAILURE); 
    4243        } 
  • nebula/trunk/src/cstr.c

    r1558 r1623  
    1919 */ 
    2020 
     21#include <errno.h> 
    2122#include <stdio.h> 
    2223#include <stdlib.h> 
     
    4546 
    4647        if ((list->elem = realloc(list->elem, (list->len + 1) * sizeof(substr))) == NULL) { 
    47                 fprintf(stderr, "Error - Unable to allocate memory: %m.\n"); 
     48                fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
    4849                exit(EXIT_FAILURE); 
    4950        } 
  • nebula/trunk/src/hash.c

    r1612 r1623  
    3131        hash *new; 
    3232        if ((new = calloc(1, sizeof(hash))) == NULL) { 
    33                 fprintf(stderr, "Error - Unable to allocate memory: %m.\n"); 
     33                fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
    3434                exit(EXIT_FAILURE); 
    3535        } 
  • nebula/trunk/src/nebula.c

    r1620 r1623  
    11/* nebula.c 
    22 * 
    3  * Copyright (C) 2007 Tillmann Werner <tillmann.werner@gmx.de> 
     3 * Copyright (C) 2007-2008 Tillmann Werner <tillmann.werner@gmx.de> 
    44 * 
    55 * This program is free software; you can redistribute it and/or modify 
     
    9191        pollfd_set_size         = 0; 
    9292 
    93         global_sid              = 2000000; 
    94  
    95         outlierq                = NULL; 
    96         clusterq                = NULL; 
    97         aconnq                  = NULL; 
     93        outlierq                = NULL;         // outlier queue 
     94        clusterq                = NULL;         // cluster queue 
    9895 
    9996        classifyq               = NULL;         // classification job queue 
     
    103100        qsize                   = 0; 
    104101 
    105         lock_mutex              = 1;    // if this is set, threads will lock mutexes 
    106  
    107  
    108         /* default values for parameters */ 
    109         rules_file             = NULL;         // a: NULL 
    110         clusterq_max           = 5000;         // C 
     102        lock_mutex              = 1;           // this flag is for avoiding deadlocks during shutdown 
     103                                                // if set threads will lock mutexes 
     104                                                // a shutdown routine should clean it before further operations 
     105 
     106        // default values for command line parameters 
     107        rules_file             = NULL;         // a: don't append snort rules to a file 
    111108        sim_threshold           = 70.0;         // c: 70% similarity as cluster criterion 
    112         daemonize               = 0;            // d: 0 
    113         clusterhashq_max        = 500000;       // E 
    114         gthread_no              = 1;            // g 
    115         snort_pid               = 0;            // h 
    116         outlierq_max            = 500000;       // O 
    117         port                    = 4712;         // p: 4712 
    118         secret                  = NULL;         // s: NULL 
     109        clusterq_max            = 5000;         // C: cluster queue size 
     110        daemonize               = 0;            // d: don't daemonize 
     111        min_sstr_ent            = 8;            // e: minimum substring entropy 
     112        clusterhashq_max        = 500000;       // E: cluster element queue size 
     113        gthread_no              = 1;            // g: spawn 1 signature generation thread 
     114        global_sid              = 2000000;      // i: initial snort ID (fist signature gets global_sid+1) 
     115        min_sstr_len            = 0;            // l: minimum substring length (0 == infinite)  
     116        outlierq_max            = 500000;       // O: outlier element queue size 
     117        port                    = 4712;         // p: listen on port 4712/tcp 
     118        snort_pid               = 0;            // r: PID of snort process for ruleset reloads (0 == off) 
     119        secret                  = NULL;         // s: don't use a secret 
     120        initial_threshold       = 30;           // t: initial cluster element threshold for signature generation 
    119121        verbose                 = 0;            // v: don't be verbose 
    120         initial_threshold       = 30;           // initial cluster element threshold for signature generation 
    121  
     122 
     123        // prepare tries for hash lookups 
    122124        memset(&md5sum_trie, 0, sizeof(trie_node)); 
    123125        memset(&spamsum_trie, 0, sizeof(trie_node)); 
     
    133135            pthread_mutex_init(&siggen_mutex, NULL) || 
    134136            pthread_mutex_init(&sigwrite_mutex, NULL)) { 
    135                 fprintf(stderr, "Error - Unable to initialize thread lock: %m.\n"); 
     137                fprintf(stderr, "Error - Unable to initialize thread lock: %s.\n", strerror(errno)); 
    136138                exit(EXIT_FAILURE); 
    137139        } 
     
    141143        if ((sem_init(&sessions_semaphore, 0, 0) == -1) || 
    142144            (sem_init(&sessions_semaphore, 0, 0) == -1)) { 
    143                 fprintf(stderr, "Error - Unable to initialize semaphore: %m.\n"); 
     145                fprintf(stderr, "Error - Unable to initialize semaphore: %s.\n", strerror(errno)); 
    144146                exit(EXIT_FAILURE); 
    145147        } 
     
    175177                                        fprintf(stderr, "Error - Minimum substring entropy cannot be negative.\n"); 
    176178                                        exit(EXIT_FAILURE); 
     179                                } else if (min_sstr_ent > 8) { 
     180                                        fprintf(stderr, "Error - Minimum substring entropy cannot be bigger than 8.\n"); 
     181                                        exit(EXIT_FAILURE); 
    177182                                } 
    178183                                break; 
     
    261266        } 
    262267        pthread_attr_destroy(&ptattr); 
    263  
    264268 
    265269 
     
    280284 
    281285 
    282         // increase maximum number of open files if necessary 
     286        // increase maximum number of open files if necessary (only needed for submission backlog queue) 
    283287        memset(&rlim, 0, sizeof(struct rlimit)); 
    284288        if (getrlimit(RLIMIT_NOFILE, &rlim) == -1) { 
     
    296300 
    297301 
    298         // initialize HMAC pads 
     302        // submissions are secured with HMAC, initialize HMAC pads 
    299303        memset(k_ipad, IPAD_VAL, HMAC_BLOCK_SIZE); 
    300304        memset(k_opad, OPAD_VAL, HMAC_BLOCK_SIZE); 
     
    304308        } 
    305309 
     310 
    306311        // initialize queues 
    307312        outlierq        = queue_new(); 
     
    314319        listen_fd = net_listen(port); 
    315320 
     321 
     322        // inform about configuration 
    316323        if (!secret) { 
    317324                printf("  Warning - No submission secret given.\n"); 
     
    329336                printf("  Accepting submissions on port %u/tcp.\n", port); 
    330337        } 
    331         putchar('\n'); 
     338        printf("\n[*] Ready.\n"); 
     339        fflush(stdout); 
    332340 
    333341 
    334342        // process incoming connections 
    335         printf("[*] Ready.\n"); 
    336         fflush(stdout); 
    337  
    338343        LISTEN_SOCK.fd          = listen_fd; 
    339344        LISTEN_SOCK.events      = POLLIN; 
    340  
    341345        for(;;) { 
    342346                switch (rv = poll(pfdset, pollfd_set_size+1, -1)) { 
     
    396400                                                break; 
    397401                                        case 1: 
    398                                                 // create clustering thread 
     402                                                // submission complete, create clustering thread 
    399403                                                if ((tmp_submission = calloc(1, sizeof(submission))) == NULL) { 
    400404                                                        fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
     
    451455        } 
    452456 
    453  
     457        // never reached 
    454458        cleanup(); 
    455          
    456459        return(EXIT_SUCCESS); 
    457460} 
  • nebula/trunk/src/nebula.h

    r1620 r1623  
    11/* nebula.h 
    22 * 
    3  * Copyright (C) 2007 Tillmann Werner <tillmann.werner@gmx.de> 
     3 * Copyright (C) 2007-2008 Tillmann Werner <tillmann.werner@gmx.de> 
    44 * 
    55 * This program is free software; you can redistribute it and/or modify 
     
    6060queue                   *clusterq; 
    6161queue                   *outlierq; 
    62 queue                   *aconnq; 
    6362 
    6463queue                   *classifyq;     // clustering job queue 
  • nebula/trunk/src/ngram.c

    r1373 r1623  
    5555        if (t->data == NULL) { 
    5656                if ((t->data = (void *) calloc(8, 1)) == NULL) { 
    57                         fprintf(stderr, "Error - Unable to allocate memory: %m.\n"); 
     57                        fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
    5858                        exit(EXIT_FAILURE); 
    5959                } 
  • nebula/trunk/src/queue.c

    r1566 r1623  
    139139        queue *q; 
    140140        if ((q = calloc(1, sizeof(queue))) == NULL) { 
    141                 fprintf(stderr, "Error - Unable to allocate memory: %m.\n"); 
     141                fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
    142142                exit(EXIT_FAILURE); 
    143143        } 
    144144        if (pthread_rwlock_init(&q->lock, NULL) != 0) { 
    145                 fprintf(stderr, "Error - Unable to initialize thread lock: %m.\n"); 
     145                fprintf(stderr, "Error - Unable to initialize thread lock: %s.\n", strerror(errno)); 
    146146                exit(EXIT_FAILURE); 
    147147        } 
  • nebula/trunk/src/session.c

    r1618 r1623  
    125125        } 
    126126 
    127  
     127        // this is a simple state machine for controlling submissions 
    128128        switch (s->state) { 
    129         case NEW: 
     129        case SS_NEW: 
    130130                // send random nonce 
    131131                srand(time(0)); 
     
    136136                } 
    137137                s->nonce        = ntohl(nonce); 
    138                 s->state        = NONCE_SENT; 
     138                s->state        = SS_NONCE_SENT; 
    139139                s->bytes_read   = 0; 
    140140 
    141141                break; 
    142         case NONCE_SENT: 
     142        case SS_NONCE_SENT: 
    143143                // read secret hash 
    144144                if ((rv = session_read_data(pfd->fd, s, (u_char *) s->secret_hash, 128)) == -1) { 
    145145                        return(-1); 
    146146                } else if (rv == 128) { 
    147                         s->state = UNAUTHENTICATED; 
     147                        s->state = SS_UNAUTHENTICATED; 
    148148 
    149149                        if (secret) { 
     
    169169                        if (!strncmp(sha512sum, s->secret_hash, 128)) { 
    170170                                if (verbose > 2) printf("    Valid secret hash read, session authenticated.\n"); 
    171                                 s->state        = AUTHENTICATED; 
     171                                s->state        = SS_AUTHENTICATED; 
    172172                                s->bytes_read   = 0; 
    173173                        } 
     
    175175                        free(sha512sum); 
    176176 
    177                         if (s->state != AUTHENTICATED) { 
     177                        if (s->state != SS_AUTHENTICATED) { 
    178178                                printf("[x] Secret mismatch, dropping session: %d.\n", pfd->fd); 
    179179                                fflush(stdout); 
     
    184184                } 
    185185                break; 
    186         case AUTHENTICATED: 
     186        case SS_AUTHENTICATED: 
    187187                // read md5 hash 
    188188                if (!s->md5sum && ((s->md5sum = calloc(sizeof(char), 33)) == NULL)) { 
     
    225225 
    226226                        if (verbose > 2) printf("    Unknown attack, submission requested.\n"); 
    227                         s->state        = REQUEST_SENT; 
    228                         s->bytes_read   = 0; 
    229                 } 
    230                 break; 
    231         case REQUEST_SENT: 
     227                        s->state        = SS_REQUEST_SENT; 
     228                        s->bytes_read   = 0; 
     229                } 
     230                break; 
     231        case SS_REQUEST_SENT: 
    232232                // read protocol 
    233233                if ((rv = session_read_data(pfd->fd, s, (u_char *) &(s->protocol), 1)) == -1) { 
     
    246246                                break; 
    247247                        } 
    248                         s->state        = PROTOCOL_READ; 
    249                         s->bytes_read   = 0; 
    250                 } 
    251                 break; 
    252         case PROTOCOL_READ: 
     248                        s->state        = SS_PROTOCOL_READ; 
     249                        s->bytes_read   = 0; 
     250                } 
     251                break; 
     252        case SS_PROTOCOL_READ: 
    253253                // read port 
    254254                if ((rv = session_read_data(pfd->fd, s, (u_char *) &(s->port), 2)) == -1) { 
     
    257257                        s->port = ntohs(s->port); 
    258258                        if (verbose > 2) printf("    Port: %u\n", s->port); 
    259                         s->state        = PORT_READ; 
    260                         s->bytes_read   = 0; 
    261                 } 
    262                 break; 
    263         case PORT_READ: 
     259                        s->state        = SS_PORT_READ; 
     260                        s->bytes_read   = 0; 
     261                } 
     262                break; 
     263        case SS_PORT_READ: 
    264264                // read length of attack data 
    265265                if ((rv = session_read_data(pfd->fd, s, (u_char *) &(s->attack_len), 4)) == -1) { 
     
    268268                        s->attack_len = ntohl(s->attack_len); 
    269269                        if (verbose > 2) printf("    Bytes of attack string: %lu\n", s->attack_len); 
    270                         s->state        = ATTACK_LEN_READ; 
    271                         s->bytes_read   = 0; 
    272                 } 
    273                 break; 
    274         case ATTACK_LEN_READ: 
     270                        s->state        = SS_ATTACK_LEN_READ; 
     271                        s->bytes_read   = 0; 
     272                } 
     273                break; 
     274        case SS_ATTACK_LEN_READ: 
    275275                // read length of compressed attack data 
    276276                if ((rv = session_read_data(pfd->fd, s, (u_char *) &(s->cattack_len), 4)) == -1) { 
     
    279279                        s->cattack_len = ntohl(s->cattack_len); 
    280280                        if (verbose > 2) printf("    Bytes of compressed attack string: %u\n", s->cattack_len); 
    281                         s->state        = CATTACK_LEN_READ; 
    282                         s->bytes_read   = 0; 
    283                 } 
    284                 break; 
    285         case CATTACK_LEN_READ: 
     281                        s->state        = SS_CATTACK_LEN_READ; 
     282                        s->bytes_read   = 0; 
     283                } 
     284                break; 
     285        case SS_CATTACK_LEN_READ: 
    286286                // read compressed attack 
    287287                if (!s->cattack && ((s->cattack = calloc(1, s->cattack_len)) == NULL)) { 
     
    293293                } else if (rv == s->cattack_len) { 
    294294                        if (verbose > 2) printf("    Attack read.\n"); 
    295                         s->state        = CATTACK_READ; 
     295                        s->state        = SS_CATTACK_READ; 
    296296                        s->bytes_read   = 0; 
    297297                } else return(2); 
    298         case CATTACK_READ: 
     298        case SS_CATTACK_READ: 
    299299                // read length of HMAC 
    300300                s->hmac_len = 0xffff; 
     
    304304                        s->hmac_len = ntohs(s->hmac_len); 
    305305                        if (verbose > 2) printf("    Length of HMAC: %u\n", s->hmac_len); 
    306                         s->state        = HMAC_LEN_READ; 
    307                         s->bytes_read   = 0; 
    308                 } 
    309                 break; 
    310         case HMAC_LEN_READ: 
     306                        s->state        = SS_HMAC_LEN_READ; 
     307                        s->bytes_read   = 0; 
     308                } 
     309                break; 
     310        case SS_HMAC_LEN_READ: 
    311311                if (!s->hmac && ((s->hmac = calloc(sizeof(u_char), s->hmac_len+1)) == NULL)) { 
    312312                        fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
     
    397397 
    398398                        s->bytes_read   = 0; 
    399                         s->state        = FINISHED; 
     399                        s->state        = SS_FINISHED; 
    400400 
    401401                        fflush(stdout); 
  • nebula/trunk/src/session.h

    r1612 r1623  
    4343// states 
    4444typedef enum sstate { 
    45         NEW = 0, 
    46         NONCE_SENT, 
    47         UNAUTHENTICATED, 
    48         AUTHENTICATED, 
    49         REQUEST_SENT, 
    50         PROTOCOL_READ, 
    51         PORT_READ, 
    52         ATTACK_LEN_READ, 
    53         CATTACK_LEN_READ, 
    54         CATTACK_READ, 
    55         HMAC_LEN_READ, 
    56         FINISHED 
     45        SS_NEW = 0, 
     46        SS_NONCE_SENT, 
     47        SS_UNAUTHENTICATED, 
     48        SS_AUTHENTICATED, 
     49        SS_REQUEST_SENT, 
     50        SS_PROTOCOL_READ, 
     51        SS_PORT_READ, 
     52        SS_ATTACK_LEN_READ, 
     53        SS_CATTACK_LEN_READ, 
     54        SS_CATTACK_READ, 
     55        SS_HMAC_LEN_READ, 
     56        SS_FINISHED 
    5757} sstate; 
    5858 
  • nebula/trunk/src/sig.c

    r1620 r1623  
    6262        // insert segment 
    6363        if ((*list = realloc(*list, (*num_frags + 1) * sizeof(sseg))) == NULL) { 
    64                 fprintf(stderr, "Error - Unable to allocate memory: %m.\n"); 
     64                fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
    6565                exit(EXIT_FAILURE); 
    6666        } 
     
    132132                // append next signature segment 
    133133                if ((sigdata = realloc(sigdata, sigdata_len + (2*sizeof(ssize_t)) + seglist[i-1].len)) == NULL) { 
    134                         fprintf(stderr, "Error - Unable to allocate memory: %m.\n"); 
     134                        fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
    135135                        free(seglist); 
    136136                        free(sigdata); 
     
    431431                // byte strlist[0] must not be used, it simplifies the GST algorithm which uses offset 0 for the root node 
    432432                if ((strlist = realloc(strlist, sizeof(lchar) * (strllen + attack->attack_len + 2))) == NULL) { 
    433                         fprintf(stderr, "Error - Unable to allocate memory: %m.\n"); 
     433                        fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
    434434                        exit(EXIT_FAILURE); 
    435435                } 
     
    437437                // extend string offset array 
    438438                if ((gst->string_offset = realloc(gst->string_offset, acnt * sizeof(u_int32_t))) == NULL) { 
    439                         fprintf(stderr, "Error - Unable to allocate memory: %m.\n"); 
     439                        fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
    440440                        exit(EXIT_FAILURE); 
    441441                } 
     
    498498        num_leaves      = 0; 
    499499        if ((leaves = calloc(1, sizeof(stnode *))) == NULL) { 
    500                 fprintf(stderr, "Error - Unable to allocate memory: %m.\n"); 
     500                fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
    501501                exit(EXIT_FAILURE); 
    502502        } 
  • nebula/trunk/src/signals.c

    r1620 r1623  
    11/* signals.c 
    22 * 
    3  * Copyright (C) 2007 Tillmann Werner <tillmann.werner@gmx.de> 
     3 * Copyright (C) 2007-2008 Tillmann Werner <tillmann.werner@gmx.de> 
    44 * 
    55 * This program is free software; you can redistribute it and/or modify 
     
    1919 */ 
    2020 
     21#include <errno.h> 
    2122#include <math.h> 
    2223#include <signal.h> 
     
    116117        for (i = 3; i < 8; i++) { 
    117118                if (sigaction(SIGRTMIN+i, &s_action, NULL) == -1) { 
    118                         fprintf(stdout, "  Error - Unable to install handler for signal %d: %m.\n", SIGRTMIN+i); 
     119                        fprintf(stdout, "  Error - Unable to install handler for signal %d: %s.\n", SIGRTMIN+i, strerror(errno)); 
    119120                        exit(EXIT_FAILURE); 
    120121                } 
     
    130131        for (i = 0; i < sizeof(termsigs)/sizeof(termsigs[0]); i++) { 
    131132                if (sigaction(termsigs[i], &s_action, NULL) == -1) { 
    132                         fprintf(stdout, "  Error - Unable to install handler for signal %d: %m.\n", termsigs[i]); 
     133                        fprintf(stdout, "  Error - Unable to install handler for signal %d: %s.\n", termsigs[i], strerror(errno)); 
    133134                        exit(EXIT_FAILURE); 
    134135                } 
  • nebula/trunk/src/spamsum.c

    r1414 r1623  
    1818 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
    1919 * 
    20  * This code is based Andrew Tridgell's spamsum routine. 
     20 * This code is based on Andrew Tridgell's spamsum routine. 
    2121 */ 
    2222 
  • nebula/trunk/src/stree.c

    r1570 r1623  
    1717 * along with this program; if not, write to the Free Software 
    1818 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
     19 * 
     20 * Some of this code is based on Shlomo Yona's suffix tree implementation. 
    1921 */ 
    2022 
     
    6769                        if (t->tree_string[start] && !(t->tree_string[start] & 0x000000ff)) { 
    6870                                if ((*leaves = realloc(*leaves, sizeof(stnode *) * ((*num_leaves)+1))) == NULL) { 
    69                                         fprintf(stderr, "Error - Unable to allocate memory: %m.\n"); 
     71                                        fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
    7072                                        exit(EXIT_FAILURE); 
    7173                                } 
     
    8789 
    8890        if ((node = calloc(1, sizeof(stnode))) == NULL) { 
    89                 fprintf(stderr, "Error - Unable to create tree node: %m.\n"); 
     91                fprintf(stderr, "Error - Unable to create tree node: %s.\n", strerror(errno)); 
    9092                exit(EXIT_FAILURE); 
    9193        } 
     
    442444        /* Allocating the tree */ 
    443445        if ((tree = calloc(1, sizeof(stree))) == NULL) { 
    444                 fprintf(stderr, "Error - Unable to allocate memory: %m.\n"); 
     446                fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
    445447                exit(EXIT_FAILURE); 
    446448        } 
     
    620622 
    621623        if ((l = calloc(num_of_files, sizeof(stnode *))) == NULL) { 
    622                 fprintf(stderr, "Error - Unable to allocate memory: %m.\n"); 
     624                fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
    623625                exit(EXIT_FAILURE); 
    624626        } 
  • nebula/trunk/src/stree.h

    r1614 r1623  
    1717 * along with this program; if not, write to the Free Software 
    1818 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
     19 * 
     20 * Some of this code is based on Shlomo Yona's suffix tree implementation. 
    1921 */ 
    2022 
  • nebula/trunk/src/trie.c

    r1414 r1623  
    105105                        if (node->childlist_len > i) memmove(&(node->childlist[i]), &(node->childlist[i+1]), (node->childlist_len-i) * sizeof(trie_node)); 
    106106                        if ((node->childlist = realloc(node->childlist, node->childlist_len * sizeof(trie_node))) == NULL) { 
    107                                 fprintf(stderr, "Error - Unable to reallocate memory: %m.\n"); 
     107                                fprintf(stderr, "Error - Unable to reallocate memory: %s.\n", strerror(errno)); 
    108108                                exit(EXIT_FAILURE); 
    109109                        } 
     
    127127 
    128128        if ((t = realloc(parent->childlist, sizeof(trie_node)*(parent->childlist_len+1))) == NULL) { 
    129                 fprintf(stderr, "Error - Unable to allocate memory: %m.\n"); 
     129                fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
    130130                exit(EXIT_FAILURE); 
    131131        } 
     
    176176                if ((target_node = trie_find_node(t->childlist, t->childlist_len, data[k])) == NULL) { 
    177177                        if ((t = trie_insert_node(t, data[k])) == NULL) { 
    178                                 fprintf(stderr, "Error - Unable to create new trie node: %m.\n"); 
     178                                fprintf(stderr, "Error - Unable to create new trie node: %s.\n", strerror(errno)); 
    179179                                exit(EXIT_FAILURE); 
    180180                        }  
  • nebula/trunk/src/util.c

    r1620 r1623  
    11/* util.c 
    22 * 
    3  * Copyright (C) 2007 Tillmann Werner <tillmann.werner@gmx.de> 
     3 * Copyright (C) 2007-2008 Tillmann Werner <tillmann.werner@gmx.de> 
    44 * 
    55 * This program is free software; you can redistribute it and/or modify 
     
    4747 
    4848        if (stat(e->d_name, &sta) != 0) { 
    49                 fprintf(stderr, "Error - Unable to get file status for %s: %m.\n", e->d_name); 
     49                fprintf(stderr, "Error - Unable to get file status for %s: %s.\n", e->d_name, strerror(errno)); 
    5050                exit(EXIT_FAILURE); 
    5151        } 
     
    6565 
    6666        if ((stat((*A)->d_name, &sta) != 0) || (stat((*B)->d_name, &stb) != 0)) { 
    67                 fprintf(stderr, "Error - Unable to get file status for %s, %s: %m.\n", (*A)->d_name, (*B)->d_name); 
     67                fprintf(stderr, "Error - Unable to get file status for %s, %s: %s.\n", (*A)->d_name, (*B)->d_name, strerror(errno)); 
    6868                exit(EXIT_FAILURE); 
    6969        } 
  • nebula/trunk/src/util.h

    r1566 r1623  
    11/* util.h 
    22 * 
    3  * Copyright (C) 2007 Tillmann Werner <tillmann.werner@gmx.de> 
     3 * Copyright (C) 2007-2008 Tillmann Werner <tillmann.werner@gmx.de> 
    44 * 
    55 * This program is free software; you can redistribute it and/or modify 
     
    2828#include <dirent.h> 
    2929 
    30 #define min(a,b) ((a) > (b) ? a : b
    31 #define max(a,b) ((a) > (b) ? a : b
     30#define min(a,b) ((a) > (b) ? (a) : (b)
     31#define max(a,b) ((a) > (b) ? (a) : (b)
    3232 
    3333typedef u_int32_t lchar;