Changeset 1623
- Timestamp:
- 04/27/08 14:47:15 (2 weeks ago)
- Files:
-
- nebula/trunk/client/nebulaclient.c (modified) (3 diffs)
- nebula/trunk/configure.in (modified) (1 diff)
- nebula/trunk/src/Makefile.am (modified) (1 diff)
- nebula/trunk/src/avl.c (modified) (2 diffs)
- nebula/trunk/src/classify.c (modified) (2 diffs)
- nebula/trunk/src/cluster.c (modified) (2 diffs)
- nebula/trunk/src/cstr.c (modified) (2 diffs)
- nebula/trunk/src/hash.c (modified) (1 diff)
- nebula/trunk/src/nebula.c (modified) (14 diffs)
- nebula/trunk/src/nebula.h (modified) (2 diffs)
- nebula/trunk/src/ngram.c (modified) (1 diff)
- nebula/trunk/src/queue.c (modified) (1 diff)
- nebula/trunk/src/session.c (modified) (13 diffs)
- nebula/trunk/src/session.h (modified) (1 diff)
- nebula/trunk/src/sig.c (modified) (5 diffs)
- nebula/trunk/src/signals.c (modified) (4 diffs)
- nebula/trunk/src/spamsum.c (modified) (1 diff)
- nebula/trunk/src/stree.c (modified) (5 diffs)
- nebula/trunk/src/stree.h (modified) (1 diff)
- nebula/trunk/src/trie.c (modified) (3 diffs)
- nebula/trunk/src/util.c (modified) (3 diffs)
- nebula/trunk/src/util.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
nebula/trunk/client/nebulaclient.c
r1612 r1623 1 1 /* nebula-client.c 2 * 2 3 * Copyright (C) 2008 Tillmann Werner <tillmann.werner@gmx.de> 3 4 * … … 58 59 if (read_chars >= len-1) { 59 60 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);62 61 exit(EXIT_FAILURE); 63 62 } … … 117 116 118 117 int 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; 119 125 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;125 126 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; 129 129 bstring bstr; 130 struct dirent *dir_entry;131 DIR *dirp;132 struct dirent **namelist;133 130 134 131 i = 0; nebula/trunk/configure.in
r1618 r1623 27 27 28 28 29 30 AC_CHECK_HEADER(zlib.h,, AC_MSG_ERROR([zlib headers not found.])) 31 AC_CHECK_LIB(z, gzgets,, AC_MSG_ERROR([zlib not found.])) 32 33 34 AC_CHECK_HEADER(pthread.h,, AC_MSG_ERROR([pthread headers not found.])) 35 AC_CHECK_LIB(pthread, pthread_create,, AC_MSG_ERROR([pthread library not found.])) 36 37 29 38 # Check for electric fence malloc debugger 30 39 AC_ARG_ENABLE(efence, nebula/trunk/src/Makefile.am
r1613 r1623 1 AM_CFLAGS=-Wall -Werror -D_GNU_SOURCE -g1 AM_CFLAGS=-Wall -Werror -D_GNU_SOURCE 2 2 3 3 LIBS += -lm -lz -lpthread nebula/trunk/src/avl.c
r1558 r1623 119 119 120 120 if (t->cmpfn((*n)->data, (*n)->size, a->data, a->size) > 0) { 121 / * insert into the left subtree */121 // insert into the left subtree 122 122 if ((*n)->left) { 123 123 if (avl_insert(t, &((*n)->left), a)) { … … 145 145 } 146 146 } else { 147 / * insert into the right subtree */147 // insert into the right subtree 148 148 if ((*n)->right) { 149 149 if (avl_insert(t, &((*n)->right), a)) { nebula/trunk/src/classify.c
r1620 r1623 98 98 99 99 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)); 101 101 exit(EXIT_FAILURE); 102 102 } … … 113 113 // set spamsum hash 114 114 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)); 116 116 exit(EXIT_FAILURE); 117 117 } nebula/trunk/src/cluster.c
r1585 r1623 19 19 */ 20 20 21 #include <errno.h> 21 22 #include <stdio.h> 22 23 #include <string.h> … … 33 34 /* create new cluster */ 34 35 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)); 36 37 exit(EXIT_FAILURE); 37 38 } 38 39 39 40 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)); 41 42 exit(EXIT_FAILURE); 42 43 } nebula/trunk/src/cstr.c
r1558 r1623 19 19 */ 20 20 21 #include <errno.h> 21 22 #include <stdio.h> 22 23 #include <stdlib.h> … … 45 46 46 47 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)); 48 49 exit(EXIT_FAILURE); 49 50 } nebula/trunk/src/hash.c
r1612 r1623 31 31 hash *new; 32 32 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)); 34 34 exit(EXIT_FAILURE); 35 35 } nebula/trunk/src/nebula.c
r1620 r1623 1 1 /* nebula.c 2 2 * 3 * Copyright (C) 2007 Tillmann Werner <tillmann.werner@gmx.de>3 * Copyright (C) 2007-2008 Tillmann Werner <tillmann.werner@gmx.de> 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify … … 91 91 pollfd_set_size = 0; 92 92 93 global_sid = 2000000; 94 95 outlierq = NULL; 96 clusterq = NULL; 97 aconnq = NULL; 93 outlierq = NULL; // outlier queue 94 clusterq = NULL; // cluster queue 98 95 99 96 classifyq = NULL; // classification job queue … … 103 100 qsize = 0; 104 101 105 lock_mutex = 1; // if this is set, threads will lock mutexes106 107 108 /* default values for parameters */ 109 rules_file = NULL; // a: NULL110 clusterq_max = 5000; // C102 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 111 108 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 119 121 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 122 124 memset(&md5sum_trie, 0, sizeof(trie_node)); 123 125 memset(&spamsum_trie, 0, sizeof(trie_node)); … … 133 135 pthread_mutex_init(&siggen_mutex, NULL) || 134 136 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)); 136 138 exit(EXIT_FAILURE); 137 139 } … … 141 143 if ((sem_init(&sessions_semaphore, 0, 0) == -1) || 142 144 (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)); 144 146 exit(EXIT_FAILURE); 145 147 } … … 175 177 fprintf(stderr, "Error - Minimum substring entropy cannot be negative.\n"); 176 178 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); 177 182 } 178 183 break; … … 261 266 } 262 267 pthread_attr_destroy(&ptattr); 263 264 268 265 269 … … 280 284 281 285 282 // increase maximum number of open files if necessary 286 // increase maximum number of open files if necessary (only needed for submission backlog queue) 283 287 memset(&rlim, 0, sizeof(struct rlimit)); 284 288 if (getrlimit(RLIMIT_NOFILE, &rlim) == -1) { … … 296 300 297 301 298 // initialize HMAC pads302 // submissions are secured with HMAC, initialize HMAC pads 299 303 memset(k_ipad, IPAD_VAL, HMAC_BLOCK_SIZE); 300 304 memset(k_opad, OPAD_VAL, HMAC_BLOCK_SIZE); … … 304 308 } 305 309 310 306 311 // initialize queues 307 312 outlierq = queue_new(); … … 314 319 listen_fd = net_listen(port); 315 320 321 322 // inform about configuration 316 323 if (!secret) { 317 324 printf(" Warning - No submission secret given.\n"); … … 329 336 printf(" Accepting submissions on port %u/tcp.\n", port); 330 337 } 331 putchar('\n'); 338 printf("\n[*] Ready.\n"); 339 fflush(stdout); 332 340 333 341 334 342 // process incoming connections 335 printf("[*] Ready.\n");336 fflush(stdout);337 338 343 LISTEN_SOCK.fd = listen_fd; 339 344 LISTEN_SOCK.events = POLLIN; 340 341 345 for(;;) { 342 346 switch (rv = poll(pfdset, pollfd_set_size+1, -1)) { … … 396 400 break; 397 401 case 1: 398 // create clustering thread402 // submission complete, create clustering thread 399 403 if ((tmp_submission = calloc(1, sizeof(submission))) == NULL) { 400 404 fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); … … 451 455 } 452 456 453 457 // never reached 454 458 cleanup(); 455 456 459 return(EXIT_SUCCESS); 457 460 } nebula/trunk/src/nebula.h
r1620 r1623 1 1 /* nebula.h 2 2 * 3 * Copyright (C) 2007 Tillmann Werner <tillmann.werner@gmx.de>3 * Copyright (C) 2007-2008 Tillmann Werner <tillmann.werner@gmx.de> 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify … … 60 60 queue *clusterq; 61 61 queue *outlierq; 62 queue *aconnq;63 62 64 63 queue *classifyq; // clustering job queue nebula/trunk/src/ngram.c
r1373 r1623 55 55 if (t->data == NULL) { 56 56 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)); 58 58 exit(EXIT_FAILURE); 59 59 } nebula/trunk/src/queue.c
r1566 r1623 139 139 queue *q; 140 140 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)); 142 142 exit(EXIT_FAILURE); 143 143 } 144 144 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)); 146 146 exit(EXIT_FAILURE); 147 147 } nebula/trunk/src/session.c
r1618 r1623 125 125 } 126 126 127 127 // this is a simple state machine for controlling submissions 128 128 switch (s->state) { 129 case NEW:129 case SS_NEW: 130 130 // send random nonce 131 131 srand(time(0)); … … 136 136 } 137 137 s->nonce = ntohl(nonce); 138 s->state = NONCE_SENT;138 s->state = SS_NONCE_SENT; 139 139 s->bytes_read = 0; 140 140 141 141 break; 142 case NONCE_SENT:142 case SS_NONCE_SENT: 143 143 // read secret hash 144 144 if ((rv = session_read_data(pfd->fd, s, (u_char *) s->secret_hash, 128)) == -1) { 145 145 return(-1); 146 146 } else if (rv == 128) { 147 s->state = UNAUTHENTICATED;147 s->state = SS_UNAUTHENTICATED; 148 148 149 149 if (secret) { … … 169 169 if (!strncmp(sha512sum, s->secret_hash, 128)) { 170 170 if (verbose > 2) printf(" Valid secret hash read, session authenticated.\n"); 171 s->state = AUTHENTICATED;171 s->state = SS_AUTHENTICATED; 172 172 s->bytes_read = 0; 173 173 } … … 175 175 free(sha512sum); 176 176 177 if (s->state != AUTHENTICATED) {177 if (s->state != SS_AUTHENTICATED) { 178 178 printf("[x] Secret mismatch, dropping session: %d.\n", pfd->fd); 179 179 fflush(stdout); … … 184 184 } 185 185 break; 186 case AUTHENTICATED:186 case SS_AUTHENTICATED: 187 187 // read md5 hash 188 188 if (!s->md5sum && ((s->md5sum = calloc(sizeof(char), 33)) == NULL)) { … … 225 225 226 226 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: 232 232 // read protocol 233 233 if ((rv = session_read_data(pfd->fd, s, (u_char *) &(s->protocol), 1)) == -1) { … … 246 246 break; 247 247 } 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: 253 253 // read port 254 254 if ((rv = session_read_data(pfd->fd, s, (u_char *) &(s->port), 2)) == -1) { … … 257 257 s->port = ntohs(s->port); 258 258 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: 264 264 // read length of attack data 265 265 if ((rv = session_read_data(pfd->fd, s, (u_char *) &(s->attack_len), 4)) == -1) { … … 268 268 s->attack_len = ntohl(s->attack_len); 269 269 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: 275 275 // read length of compressed attack data 276 276 if ((rv = session_read_data(pfd->fd, s, (u_char *) &(s->cattack_len), 4)) == -1) { … … 279 279 s->cattack_len = ntohl(s->cattack_len); 280 280 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: 286 286 // read compressed attack 287 287 if (!s->cattack && ((s->cattack = calloc(1, s->cattack_len)) == NULL)) { … … 293 293 } else if (rv == s->cattack_len) { 294 294 if (verbose > 2) printf(" Attack read.\n"); 295 s->state = CATTACK_READ;295 s->state = SS_CATTACK_READ; 296 296 s->bytes_read = 0; 297 297 } else return(2); 298 case CATTACK_READ:298 case SS_CATTACK_READ: 299 299 // read length of HMAC 300 300 s->hmac_len = 0xffff; … … 304 304 s->hmac_len = ntohs(s->hmac_len); 305 305 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: 311 311 if (!s->hmac && ((s->hmac = calloc(sizeof(u_char), s->hmac_len+1)) == NULL)) { 312 312 fprintf(stderr, "Error - Unable to allocate memory: %s.\n", strerror(errno)); … … 397 397 398 398 s->bytes_read = 0; 399 s->state = FINISHED;399 s->state = SS_FINISHED; 400 400 401 401 fflush(stdout); nebula/trunk/src/session.h
r1612 r1623 43 43 // states 44 44 typedef 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 FINISHED45 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 57 57 } sstate; 58 58 nebula/trunk/src/sig.c
r1620 r1623 62 62 // insert segment 63 63 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)); 65 65 exit(EXIT_FAILURE); 66 66 } … … 132 132 // append next signature segment 133 133 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)); 135 135 free(seglist); 136 136 free(sigdata); … … 431 431 // byte strlist[0] must not be used, it simplifies the GST algorithm which uses offset 0 for the root node 432 432 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)); 434 434 exit(EXIT_FAILURE); 435 435 } … … 437 437 // extend string offset array 438 438 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)); 440 440 exit(EXIT_FAILURE); 441 441 } … … 498 498 num_leaves = 0; 499 499 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)); 501 501 exit(EXIT_FAILURE); 502 502 } nebula/trunk/src/signals.c
r1620 r1623 1 1 /* signals.c 2 2 * 3 * Copyright (C) 2007 Tillmann Werner <tillmann.werner@gmx.de>3 * Copyright (C) 2007-2008 Tillmann Werner <tillmann.werner@gmx.de> 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify … … 19 19 */ 20 20 21 #include <errno.h> 21 22 #include <math.h> 22 23 #include <signal.h> … … 116 117 for (i = 3; i < 8; i++) { 117 118 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)); 119 120 exit(EXIT_FAILURE); 120 121 } … … 130 131 for (i = 0; i < sizeof(termsigs)/sizeof(termsigs[0]); i++) { 131 132 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)); 133 134 exit(EXIT_FAILURE); 134 135 } nebula/trunk/src/spamsum.c
r1414 r1623 18 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 19 * 20 * This code is based Andrew Tridgell's spamsum routine.20 * This code is based on Andrew Tridgell's spamsum routine. 21 21 */ 22 22 nebula/trunk/src/stree.c
r1570 r1623 17 17 * along with this program; if not, write to the Free Software 18 18 * 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. 19 21 */ 20 22 … … 67 69 if (t->tree_string[start] && !(t->tree_string[start] & 0x000000ff)) { 68 70 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)); 70 72 exit(EXIT_FAILURE); 71 73 } … … 87 89 88 90 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)); 90 92 exit(EXIT_FAILURE); 91 93 } … … 442 444 /* Allocating the tree */ 443 445 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)); 445 447 exit(EXIT_FAILURE); 446 448 } … … 620 622 621 623 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)); 623 625 exit(EXIT_FAILURE); 624 626 } nebula/trunk/src/stree.h
r1614 r1623 17 17 * along with this program; if not, write to the Free Software 18 18 * 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. 19 21 */ 20 22 nebula/trunk/src/trie.c
r1414 r1623 105 105 if (node->childlist_len > i) memmove(&(node->childlist[i]), &(node->childlist[i+1]), (node->childlist_len-i) * sizeof(trie_node)); 106 106 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)); 108 108 exit(EXIT_FAILURE); 109 109 } … … 127 127 128 128 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)); 130 130 exit(EXIT_FAILURE); 131 131 } … … 176 176 if ((target_node = trie_find_node(t->childlist, t->childlist_len, data[k])) == NULL) { 177 177 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)); 179 179 exit(EXIT_FAILURE); 180 180 } nebula/trunk/src/util.c
r1620 r1623 1 1 /* util.c 2 2 * 3 * Copyright (C) 2007 Tillmann Werner <tillmann.werner@gmx.de>3 * Copyright (C) 2007-2008 Tillmann Werner <tillmann.werner@gmx.de> 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify … … 47 47 48 48 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)); 50 50 exit(EXIT_FAILURE); 51 51 } … … 65 65 66 66 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)); 68 68 exit(EXIT_FAILURE); 69 69 } nebula/trunk/src/util.h
r1566 r1623 1 1 /* util.h 2 2 * 3 * Copyright (C) 2007 Tillmann Werner <tillmann.werner@gmx.de>3 * Copyright (C) 2007-2008 Tillmann Werner <tillmann.werner@gmx.de> 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify … … 28 28 #include <dirent.h> 29 29 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)) 32 32 33 33 typedef u_int32_t lchar;
