
mikhail at nessus
Sep 12, 2006, 2:46 AM
Views: 610
Permalink
|
|
nessus-libraries/libnessus arglists.c, 1.17, 1.18 bpf_share.c, 1.60, 1.61 harglists.c, 1.38, 1.39 ids_send.c, 1.27, 1.28 network.c, 1.151, 1.152 network.h, 1.10, 1.11 pcap.c, 1.31, 1.32 plugutils.c, 1.138, 1.139 services.h, 1.8, 1.9 services1.c, 1.17, 1.1
|
|
Update of /usr/local/cvs/nessus-libraries/libnessus In directory raccoon.nessus.org:/tmp/cvs-serv3875/nessus-libraries/libnessus Modified Files: arglists.c bpf_share.c harglists.c ids_send.c network.c network.h pcap.c plugutils.c services.h services1.c store.c www_funcs.c Log Message: Synchronize back DEVEL with 2.2 Index: arglists.c =================================================================== RCS file: /usr/local/cvs/nessus-libraries/libnessus/arglists.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- arglists.c 25 Nov 2004 11:28:04 -0000 1.17 +++ arglists.c 12 Sep 2006 09:46:01 -0000 1.18 @@ -26,16 +26,16 @@ * when calling arg_get_value() */ #define HASH_MAX 2713 -static int mkhash_arglists(const char * name) +static int mkhash(const char * name) { - unsigned long h = 0; - const unsigned char *p = (const unsigned char*) name; - - if (name == NULL) return 0; - - while (*p != '\0') - h = (h * 129) + *p++; - return h % HASH_MAX; + int h = 0; + int i; + + for(i=0;name[i] != '\0';i++) + { + h = ((h * 128) + name[i]) % HASH_MAX; + } + return h; } /* @@ -69,9 +69,11 @@ } static struct name_cache * -cache_get_name(const char* name, int h) +cache_get_name(name) + char * name; { struct name_cache * nc; + int h; if(cache_inited == 0) cache_init(); @@ -79,6 +81,8 @@ if(!name) return NULL; + h = mkhash(name); + nc = cache[h].next; while(nc != NULL) @@ -93,14 +97,20 @@ } static struct name_cache * -cache_add_name(const char* name, int h) +cache_add_name(name) + char * name; { struct name_cache * nc; + int h; + if(name == NULL) return NULL; + h = mkhash(name); + + nc = emalloc(sizeof(struct name_cache)); nc->next = cache[h].next; nc->prev = NULL; @@ -115,25 +125,27 @@ } static char * -cache_inc(const char * name, int h) +cache_inc(name) + char * name; { - struct name_cache * nc = cache_get_name(name, h); + struct name_cache * nc = cache_get_name(name); if(nc != NULL) nc->occurences ++; else - nc = cache_add_name(name, h); + nc = cache_add_name(name); return nc->name; } static void -cache_dec(const char * name, int h) +cache_dec(name) + char * name; { struct name_cache* nc; if(!name) return; - nc = cache_get_name(name, h); + nc = cache_get_name(name); if( nc == NULL) { /* @@ -144,6 +156,7 @@ nc->occurences --; if( nc->occurences == 0 ){ + int h = mkhash(name); efree(&nc->name); if(nc->next != NULL) nc->next->prev = nc->prev; @@ -164,8 +177,12 @@ arg_free_name(name) char * name; { - cache_dec(name, mkhash_arglists(name)); + cache_dec(name); } + + + + ExtFunc void @@ -176,8 +193,6 @@ long length; void * value; { - int h; - if(!arglst)return; while(arglst->next)arglst = arglst->next; @@ -187,25 +202,24 @@ value = new_val; } - h = mkhash_arglists(name); - arglst->name = cache_inc(name, h); + arglst->name = cache_inc(name); arglst->value = value; arglst->length = length; arglst->type = type; arglst->next = emalloc(sizeof(struct arglist)); - arglst->hash = h; + arglst->hash = mkhash(arglst->name); } static struct arglist * arg_get(struct arglist * arg, const char * name) { - int h = mkhash_arglists(name); + int h = mkhash(name); if(arg == NULL) return NULL; while(arg->next != NULL) { - if(arg->hash == h && strcmp(arg->name, name) == 0) + if(arg->hash == h && strcmp(arg->name, name) == 0) return arg; else arg = arg->next; @@ -314,7 +328,7 @@ while(src->next) { - dst->name = cache_inc(src->name, mkhash_arglists(src->name)); + dst->name = cache_inc(src->name); dst->type = src->type; dst->length = src->length; dst->hash = src->hash; @@ -404,7 +418,7 @@ while(arg) { struct arglist * next = arg->next; - cache_dec(arg->name, mkhash_arglists(arg->name)); + cache_dec(arg->name); efree(&arg); arg = next; } @@ -429,7 +443,7 @@ efree(&arg->value); break; } - cache_dec(arg->name, mkhash_arglists(arg->name)); + cache_dec(arg->name); efree(&arg); arg = next; } Index: bpf_share.c =================================================================== RCS file: /usr/local/cvs/nessus-libraries/libnessus/bpf_share.c,v retrieving revision 1.60 retrieving revision 1.61 diff -u -d -r1.60 -r1.61 --- bpf_share.c 5 May 2005 12:42:01 -0000 1.60 +++ bpf_share.c 12 Sep 2006 09:46:01 -0000 1.61 @@ -138,11 +138,12 @@ next = bpc->next; pcap_close(bpc->pcap); efree(&bpc); - if ( prev ) prev->next = bpc->next; + if ( prev ) prev->next = next; else pcaps = next; } prev = bpc; - bpc = bpc->next; + if ( bpc != NULL ) + bpc = bpc->next; } } @@ -505,14 +506,14 @@ { fd_set rd; struct timeval tv = {0,0}; - int clnt; + unsigned int clnt; FD_ZERO(&rd); FD_SET(soc, &rd); if(select(soc+1, &rd, &rd, &rd, &tv) > 0) { struct sockaddr_un soca; - int len = sizeof(soca); + unsigned int len = sizeof(soca); clnt = accept(soc, (struct sockaddr*)&soca,&len); if(clnt > 0) { @@ -937,7 +938,7 @@ if(iface == NULL) iface = pcap_lookupdev(errbuf); - ret = pcap_open_live(iface, 1500, 0, 100, errbuf); + ret = pcap_open_live(iface, 1500, 0, 1, errbuf); if(ret == NULL) { printf("%s\n", errbuf); @@ -974,10 +975,24 @@ { u_char * p = NULL; struct pcap_pkthdr head; + struct timeval timeout, now; + timeout.tv_sec += tv->tv_sec; + timeout.tv_usec += tv->tv_usec; + while ( timeout.tv_usec >= 1000000 ) { + timeout.tv_sec ++; + timeout.tv_usec -= 1000000; + } - p = (u_char*)pcap_next(pcaps[bpf], &head); - *caplen = head.caplen; + do { + p = (u_char*)pcap_next(pcaps[bpf], &head); + *caplen = head.caplen; + if ( p != NULL ) break; + gettimeofday(&now, NULL); + } while ( !((now.tv_sec > timeout.tv_sec) || + (now.tv_sec == timeout.tv_sec && now.tv_usec >= timeout.tv_usec ) )); + + return p; } Index: harglists.c =================================================================== RCS file: /usr/local/cvs/nessus-libraries/libnessus/harglists.c,v retrieving revision 1.38 retrieving revision 1.39 diff -u -d -r1.38 -r1.39 Index: ids_send.c =================================================================== RCS file: /usr/local/cvs/nessus-libraries/libnessus/ids_send.c,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- ids_send.c 19 Jan 2004 20:32:30 -0000 1.27 +++ ids_send.c 12 Sep 2006 09:46:02 -0000 1.28 @@ -387,9 +387,9 @@ int ret = 0; int len; char * buf = (char*)buf0; - int sz = sizeof(sockaddr); + unsigned int sz = sizeof(sockaddr); int e; - const char * packet; + unsigned char * packet; int bpf; bzero(&sockaddr, sizeof(sockaddr)); @@ -519,7 +519,7 @@ ret = open_sock_tcp(args, port, timeout); if(ret >= 0) { - const char * packet = bpf_next(bpf, &len); + unsigned char * packet = bpf_next(bpf, &len); if(packet) { char *pkt_ip; Index: network.c =================================================================== RCS file: /usr/local/cvs/nessus-libraries/libnessus/network.c,v retrieving revision 1.151 retrieving revision 1.152 diff -u -d -r1.151 -r1.152 --- network.c 8 May 2005 11:14:04 -0000 1.151 +++ network.c 12 Sep 2006 09:46:02 -0000 1.152 @@ -66,11 +66,10 @@ int last_ssl_err; /* Last SSL error code */ #endif pid_t pid; /* Owner - for debugging only */ -#if 0 - int last_sock_err; /* last socket level error */ -#endif + char* buf; /* NULL if unbuffered */ int bufsz, bufcnt, bufptr; + int last_err; } nessus_connection; /* @@ -154,6 +153,23 @@ } /* data_left */ #endif +int +stream_get_err(fd) + int fd; +{ + nessus_connection *p; + + if(!NESSUS_STREAM(fd)) + { + errno = EINVAL; + return -1; + } + + + p = &(connections[fd - NESSUS_FD_OFF]); + return p->last_err; +} + /* * Returns a free file descriptor */ @@ -177,6 +193,8 @@ return -1; } + + static int release_connection_fd(fd) int fd; @@ -252,6 +270,7 @@ p->port = 0; /* just used for debug */ p->fd = s; p->transport = (ssl != NULL) ? NESSUS_ENCAPS_SSLv23 : NESSUS_ENCAPS_IP; + p->last_err = 0; return fd; } @@ -609,7 +628,10 @@ { d = tictac + timeout - time(NULL); if (d <= 0) + { + fp->last_err = ETIMEDOUT; return -1; + } to.tv_sec = d; to.tv_usec = 0; errno = 0; @@ -622,7 +644,10 @@ } while (ret < 0 && errno == EINTR); if (ret <= 0) + { + fp->last_err = ETIMEDOUT; return -1; + } } /*NOTREACHED*/ } @@ -721,6 +746,7 @@ fp->transport = transport; fp->timeout = timeout; fp->port = port; + fp->last_err = 0; set_ids_evasion_mode(args, fp); if(fp->options & NESSUS_CNX_IDS_EVASION_FAKE_RST) @@ -739,7 +765,6 @@ case NESSUS_ENCAPS_SSLv23: case NESSUS_ENCAPS_SSLv3: case NESSUS_ENCAPS_TLSv1: - case NESSUS_ENCAPS_TLSv11: renice_myself(); cert = kb_item_get_str(plug_get_kb(args), "SSL/cert"); key = kb_item_get_str(plug_get_kb(args), "SSL/key"); @@ -782,50 +807,50 @@ int timeout, * p; int *delta_t; /* time, in micro-seconds */ { - int fd; - int i; + int fd; + int i; struct timeval tv1, tv2; - static int encaps[] = { + static int encaps[] = { #ifdef HAVE_SSL - NESSUS_ENCAPS_SSLv2, - NESSUS_ENCAPS_TLSv1, - NESSUS_ENCAPS_SSLv3, + NESSUS_ENCAPS_SSLv2, + NESSUS_ENCAPS_TLSv1, + NESSUS_ENCAPS_SSLv3, #endif NESSUS_ENCAPS_IP }; #if DEBUG_SSL > 2 - fprintf(stderr, "[%d] open_stream_connection_unknown_encaps: TCP:%d; %d\n", - getpid(), port,timeout); + fprintf(stderr, "[%d] open_stream_connection_unknown_encaps: TCP:%d; %d\n", + getpid(), port,timeout); #endif - for (i = 0; i < sizeof(encaps) / sizeof(*encaps); i ++) + for (i = 0; i < sizeof(encaps) / sizeof(*encaps); i ++) { if (delta_t != NULL) (void) gettimeofday(&tv1, NULL); - if ((fd = open_stream_connection(args, port, encaps[i], timeout)) >= 0) - { - *p = encaps[i]; + if ((fd = open_stream_connection(args, port, encaps[i], timeout)) >= 0) + { + *p = encaps[i]; #if DEBUG_SSL > 2 - fprintf(stderr, "[%d] open_stream_connection_unknown_encaps: TCP:%d -> transport=%d\n", getpid(), port, *p); + fprintf(stderr, "[%d] open_stream_connection_unknown_encaps: TCP:%d -> transport=%d\n", getpid(), port, *p); #endif if (delta_t != NULL) { (void) gettimeofday(&tv2, NULL); *delta_t = (tv2.tv_sec - tv1.tv_sec) * 1000000 + (tv2.tv_usec - tv1.tv_usec); } - return fd; - } - else if (__port_closed) - { + return fd; + } + else if (__port_closed) + { #if DEBUG_SSL > 2 - fprintf(stderr, "[%d] open_stream_connection_unknown_encaps: TCP:%d -> closed\n", getpid(), port); + fprintf(stderr, "[%d] open_stream_connection_unknown_encaps: TCP:%d -> closed\n", getpid(), port); #endif - return -1; - } + return -1; + } } return -1; -} - + } + ExtFunc int open_stream_connection_unknown_encaps(args, port, timeout, p) struct arglist * args; @@ -942,6 +967,7 @@ fp = &(connections[fd - NESSUS_FD_OFF]); trp = fp->transport; realfd = fp->fd; + fp->last_err = 0; if (fp->timeout != -2) timeout = fp->timeout; } @@ -992,11 +1018,17 @@ ret = recv(realfd, buf + total, max_len - total, waitall); if (ret < 0) if (errno != EINTR) + { + fp->last_err = errno; return total; + } else ret = 0; else if (ret == 0) /* EOF */ + { + fp->last_err = EPIPE; return total; + } /*ret > 0*/ total += ret; if (min_len > 0 && total >= min_len) @@ -1004,6 +1036,7 @@ flag = 0; } } + if ( t >= timeout ) fp->last_err = ETIMEDOUT; return total; } @@ -1028,7 +1061,7 @@ FD_SET(realfd, &fdr); FD_SET(realfd, &fdw); now = then = time(NULL); for (t = 0; timeout <= 0 || t < timeout; t = now - then ) - { + { now = time(NULL); tv.tv_sec = INCR_TIMEOUT; tv.tv_usec = 0; select_status = select ( realfd + 1, &fdr, &fdw, NULL, &tv ); @@ -1075,12 +1108,14 @@ #if DEBUG_SSL > 2 fprintf(stderr, "SSL_Connect[%d]: SSL_ERROR_ZERO_RETURN\n", getpid()); #endif + fp->last_err = EPIPE; return total; default: #if DEBUG_SSL > 0 sslerror2("SSL_read", err); #endif + fp->last_err = EPIPE; return total; } } @@ -1097,6 +1132,7 @@ else if (total >= min_len) return total; } + if ( t >= timeout ) fp->last_err = ETIMEDOUT; return total; #endif default : @@ -1208,6 +1244,7 @@ } fp = &(connections[fd - NESSUS_FD_OFF]); + fp->last_err = 0; #if DEBUG_SSL > 8 fprintf(stderr, "> write_stream_connection(%d, 0x%x, %d, 0x%x) \tE=%d 0=0x%x\n", @@ -1232,7 +1269,11 @@ ret = send(fp->fd, buf + count, n - count, i_opt); if(ret <= 0) - break; + { + if ( ret < 0 ) fp->last_err = errno; + else fp->last_err = EPIPE; + break; + } count += ret; } @@ -1275,6 +1316,7 @@ #if DEBUG_SSL > 0 sslerror2("SSL_write", err); #endif + fp->last_err = EPIPE; break; } if (fp->timeout >= 0) @@ -1293,6 +1335,7 @@ #if DEBUG_SSL > 0 nessus_perror("select"); #endif + fp->last_err = ETIMEDOUT; break; } } @@ -1469,8 +1512,6 @@ return "SSLv3"; case NESSUS_ENCAPS_TLSv1: return "TLSv1"; - case NESSUS_ENCAPS_TLSv11: - return "TLSv11"; default: snprintf(str, sizeof(str), "[unknown transport layer - code %d (0x%x)]", code, code); return str; @@ -1490,7 +1531,6 @@ case NESSUS_ENCAPS_SSLv23: case NESSUS_ENCAPS_SSLv3: case NESSUS_ENCAPS_TLSv1: - case NESSUS_ENCAPS_TLSv11: return " through SSL"; default: snprintf(str, sizeof(str), " through unknown transport layer - code %d (0x%x)", code, code); @@ -1505,7 +1545,8 @@ fd_set fd_w; struct timeval to; int soc, x; - int opt, opt_sz; + int opt; + unsigned int opt_sz; __port_closed = 0; @@ -1529,7 +1570,7 @@ #if defined NESSUS_CNX_LOCK if (lock_cnt == 0) - { +{ lock_fd = open(NESSUS_CNX_LOCK, O_RDWR|O_CREAT); if (lock_fd < 0) nessus_perror(NESSUS_CNX_LOCK); @@ -1601,7 +1642,6 @@ socket_close(soc); return -1; } - if (opt == 0) break; #if DEBUG_SSL > 2 @@ -2242,7 +2282,7 @@ if ( len >= sz ) { sz = len + 1; - buf = erealloc( buf, len ); + buf = erealloc( buf, sz ); } if ( len > 0 ) @@ -2272,44 +2312,22 @@ return -1; } -int -get_and_clear_stream_socket_errno(int fd) -{ - nessus_connection *fp = NULL; - int err, opt_sz = sizeof(err); - if (NESSUS_STREAM(fd)) - { - fp = connections + (fd - NESSUS_FD_OFF); - if (fp->fd < 0) - { - fprintf(stderr, - "[%d] get_and_clear_last_socket_error: closed Nessus fd <%d>\n", getpid(), fd); - errno = EINVAL; - return -1; - } - } -#if DEBUG_SSL > 0 - else - fprintf(stderr, - "[%d] get_and_clear_last_socket_error: not a Nessus fd <%d>\n", getpid(), fd); -#endif +ExtFunc int stream_pending(int fd) +{ + nessus_connection * fp; + if ( ! NESSUS_STREAM(fd) ) + { + errno = EINVAL; + return -1; + } + fp = &(connections[fd - NESSUS_FD_OFF]); -#if 0 - if (fp->last_sock_err != 0) - { - err = fp->last_sock_err; - fp->last_sock_err = 0; - return err; - } + if ( fp->bufcnt ) + return fp->bufcnt; +#ifdef HAVE_SSL + else if ( fp->transport != NESSUS_ENCAPS_IP ) + return SSL_pending(fp->ssl); #endif - if (getsockopt(fp != NULL ? fp->fd : fd, - SOL_SOCKET, SO_ERROR, &err, &opt_sz) < 0) - { - nessus_perror("getsockopt"); - return -1; - } - else - return err; + return 0; } - Index: network.h =================================================================== RCS file: /usr/local/cvs/nessus-libraries/libnessus/network.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- network.h 8 May 2005 11:14:04 -0000 1.10 +++ network.h 12 Sep 2006 09:46:02 -0000 1.11 @@ -41,7 +41,7 @@ struct in_addr socket_get_next_source_addr(); int set_socket_source_addr(int, int); void socket_source_init(struct in_addr *); -int get_and_clear_stream_socket_errno(int); + #ifdef HAVE_SSL X509* stream_get_server_certificate(int); Index: pcap.c =================================================================== RCS file: /usr/local/cvs/nessus-libraries/libnessus/pcap.c,v retrieving revision 1.31 retrieving revision 1.32 diff -u -d -r1.31 -r1.32 --- pcap.c 19 Apr 2005 11:06:48 -0000 1.31 +++ pcap.c 12 Sep 2006 09:46:02 -0000 1.32 @@ -356,7 +356,7 @@ int getsourceip(struct in_addr *src, struct in_addr *dst) { int sd; struct sockaddr_in sock; - int socklen = sizeof(struct sockaddr_in); + unsigned int socklen = sizeof(struct sockaddr_in); unsigned short p1; Index: plugutils.c =================================================================== RCS file: /usr/local/cvs/nessus-libraries/libnessus/plugutils.c,v retrieving revision 1.138 retrieving revision 1.139 diff -u -d -r1.138 -r1.139 --- plugutils.c 1 Sep 2005 12:46:24 -0000 1.138 +++ plugutils.c 12 Sep 2006 09:46:02 -0000 1.139 @@ -549,7 +549,10 @@ struct arglist * plug_get_deps(desc) struct arglist * desc; { + return _plug_get_deps(desc); +#if 0 return store_fetch_dependencies(desc); +#endif } ExtFunc @@ -573,7 +576,10 @@ int plug_get_timeout(desc) struct arglist * desc; { + return _plug_get_timeout(desc); +#if 0 return store_fetch_timeout(desc); +#endif } @@ -636,7 +642,8 @@ char * plug_get_name(desc) struct arglist * desc; { - return store_fetch_name(desc); + return _plug_get_name(desc); + /*return store_fetch_name(desc);*/ } @@ -1287,7 +1294,9 @@ pref = emalloc(strlen(p_name)+10+strlen(type)+strlen(cname)); sprintf(pref, "%s[%s]:%s", p_name, type, cname); - arg_add_value(prefs, pref, ARG_STRING, strlen(defaul), estrdup(defaul)); + if ( arg_get_value(prefs, pref) == NULL ) + arg_add_value(prefs, pref, ARG_STRING, strlen(defaul), estrdup(defaul)); + efree(&cname); efree(&pref); } @@ -1432,10 +1441,9 @@ efree(&buf); return (void*)ret; } - err: - if ( buf != NULL ) efree(&buf); - return NULL; + if ( buf != NULL )efree(&buf); + return NULL; } static void plug_set_replace_key(args, name, type, value, replace) @@ -1645,7 +1653,7 @@ int upstream = 0; char * buf = NULL; int bufsz = 0; - int myrand = lrand48(); + if ( type != NULL ) *type = -1; @@ -1682,7 +1690,6 @@ while( res != NULL ) { pid_t pid; - myrand += lrand48(); socketpair(AF_UNIX, SOCK_STREAM, 0, sockpair); if ( (pid = fork()) == 0 ) { @@ -1706,9 +1713,8 @@ if ( to != NULL ) tictac = atoi(to); } - /* Desynchronize random generator from father - this should be enough */ - srand48(myrand); - + srand48(getpid() + getppid() + time(NULL)); + sig_term(_exit); sig_alarm(_exit); alarm(120); @@ -1998,7 +2004,7 @@ } } #if 0 - fprintf(stderr, "find_in_path: No %s\n", cmd); + fprintf(stderr, "find_in_path: No %s\n", cmd); #endif } return NULL; @@ -2016,7 +2022,8 @@ ExtFunc int shared_socket_register ( struct arglist * args, int fd, char * name ) { int soc; - int type, opt_len = sizeof(type); + int type; + unsigned int opt_len = sizeof(type); int e; soc = (int)arg_get_value(args, "SOCKET"); if ( fd_is_stream(fd) ) Index: services.h =================================================================== RCS file: /usr/local/cvs/nessus-libraries/libnessus/services.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- services.h 31 Dec 2003 17:44:59 -0000 1.8 +++ services.h 12 Sep 2006 09:46:02 -0000 1.9 @@ -34,7 +34,7 @@ /* **** FILES **** */ -#define NESSUS_SERVICES CONF_DIR "/nessus-services" +#define NESSUS_SERVICES NESSUS_STATE_DIR "/nessus/nessus-services" /* If you want Nessus to use a second input file, uncomment next line */ /*#define NESSUS_IANA_PORTS CONF_DIR "/iana-port-numbers"*/ Index: services1.c =================================================================== RCS file: /usr/local/cvs/nessus-libraries/libnessus/services1.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- services1.c 1 Jun 2005 15:44:24 -0000 1.17 +++ services1.c 12 Sep 2006 09:46:02 -0000 1.18 @@ -1,6 +1,8 @@ /* * Copyright (C) 2002 Michel Arboi * + * Some modifications (C) Tenable Network Security + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either @@ -18,6 +20,7 @@ * TCP/IP service functions (getservent enhancement) */ + #define EXPORTING #include "includes.h" #include <stdarg.h> @@ -26,7 +29,6 @@ #include <unistd.h> #include "services.h" -#include "libnessus.h" #ifndef MAP_FAILED #define MAP_FAILED (void*)(-1) @@ -39,9 +41,6 @@ struct my_svc { FILE *fp; -#ifdef NESSUS_SVC_SORT_FILES - int po; /* 1 if popen/pclose */ -#endif int port; /* 2 * port + proto_idx (0 = tcp, 1 = udp) */ char name[128]; /* Debug */ @@ -54,40 +53,12 @@ { char line[256], proto[32], *p; -#ifdef NESSUS_SVC_READS_ETC_SERVICES - if (psvc->fp == (void*) 1) - { - struct servent *psve; - - if ((psve = getservent()) == NULL) - { - endservent(); - return 0; - } - else - { - psvc->name[ sizeof(psvc->name) - 1 ] = '\0'; - strncpy(psvc->name, psve->s_name, sizeof(psvc->name) - 1); - psvc->port = (unsigned short) ntohs(psve->s_port); - psvc->port *= 2; - if (strcmp(psve->s_proto, "udp") == 0) - psvc->port ++; - psvc->line ++; - return 1; - } - } -#endif for (;;) { do { if (fgets(line, sizeof(line), psvc->fp) == NULL) { -#ifdef NESSUS_SVC_SORT_FILES - if (psvc->po) - pclose(psvc->fp); - else -#endif fclose(psvc->fp); return 0; } @@ -101,9 +72,6 @@ continue; *p = '\0'; if (sscanf(p+1, "%d/%s", &psvc->port, proto) == 2 -#ifdef NESSUS_SVC_SORT_FILES - || sscanf(p+1, "%d %s", &psvc->port, proto) == 2 -#endif ) { psvc->port *= 2; @@ -127,9 +95,7 @@ nessus_init_svc() { static int flag = 0; - char *p; int l, error_flag = 0, rebuild = 0; - char nmap_svc_path[MAXPATHLEN]; #define N_SVC_F 5 struct my_svc svc[N_SVC_F]; int nf = 0, i, j, prev_p, prev_p_udp; @@ -137,28 +103,12 @@ struct nessus_service ness_svc; struct stat st; time_t t; -#ifdef NESSUS_SVC_SORT_FILES -#error "Too ugly. I refuse to compile that" -#define SORT_CMD "cat %s | tr / ' ' | sort -k 2n -k 3" - char cmd[MAXPATHLEN + sizeof(SORT_CMD)]; -#endif + + bzero(&ness_svc, sizeof(ness_svc)); if (flag) return 0; - *nmap_svc_path = '\0'; - p = find_in_path("nmap", 0); /* returns a pointer to a static array */ - if (p != NULL) - { - l = strlen(p); - if (l >= 4 && l < MAXPATHLEN - 21 && strcmp(p + l - 4, "/bin") == 0) - { - strncpy(nmap_svc_path, p, sizeof(nmap_svc_path) - 1); - strncpy(nmap_svc_path + l - 4, "/share/nmap/nmap-services", sizeof(nmap_svc_path) - l + 4 - 1); - nmap_svc_path[sizeof(nmap_svc_path) - 1] = '\0'; - } - } - /* Verify files date */ if (stat(NESSUS_SERVICES_TCP, &st) < 0) @@ -183,6 +133,7 @@ munmap(buf, len); } close(fd); + fd = -1; } t = st.st_mtime; if (stat(NESSUS_SERVICES_UDP, & st) < 0) @@ -191,19 +142,13 @@ t = st.st_mtime; } -#ifdef NESSUS_SVC_READS_ETC_SERVICES - if (stat("/etc/services", &st) >= 0 && (unsigned)st.st_mtime > (unsigned)t) - rebuild ++; -#endif - if (*nmap_svc_path != '\0' && stat(nmap_svc_path, &st) >= 0 && - (unsigned)st.st_mtime > (unsigned)t) - rebuild ++; + if ( stat(NESSUS_SERVICES, &st) < 0 ) + { + fprintf(stderr, "**** %s could not be found. Install it and try again\n", NESSUS_SERVICES); + exit(1); + } if (stat(NESSUS_SERVICES, &st) >= 0 && (unsigned)st.st_mtime > (unsigned)t) rebuild ++; -#ifdef NESSUS_IANA_PORTS - if (stat(NESSUS_IANA_PORTS, &st) >= 0 && (unsigned)st.st_mtime > (unsigned)t) - rebuild ++; -#endif if (! rebuild) return 0; @@ -220,33 +165,6 @@ * call getservent because the system may implement yellow pages or * some other kind of database. getservent() is supposed to walk through it. */ -#ifdef NESSUS_SVC_READS_ETC_SERVICES - setservent(0); - svc[nf].fp = (void*) 1; - if (get_next_svc(&svc[nf])) - { - svc[nf].filename = "services"; - nf ++; - } - -#ifdef NESSUS_SVC_SORT_FILES - snprintf(cmd, sizeof(cmd), SORT_CMD, "/etc/services"); - if ((svc[nf].fp = popen(cmd, "r")) == NULL) - perror(cmd); - else - svc[nf].po = 1; - if (! svc[nf].po) -#endif - if ((svc[nf].fp = fopen("/etc/services", "r")) == NULL) - perror("/etc/services"); - if (svc[nf].fp != NULL) - if (get_next_svc(&svc[nf])) - { - svc[nf].filename = "/etc/services"; - nf ++; - } -#endif - /* nessus-services file is supposed to be sorted */ if ((svc[nf].fp = fopen(NESSUS_SERVICES, "r")) != NULL) { @@ -257,37 +175,7 @@ } } -#ifdef NESSUS_IANA_PORTS - /* Nessus iana-port-numbers file is supposed to be sorted */ - if ((svc[nf].fp = fopen(NESSUS_IANA_PORTS, "r")) != NULL) - { - if (get_next_svc(&svc[nf])) - { - svc[nf].filename = NESSUS_IANA_PORTS; - nf ++; - } - } -#endif - if (*nmap_svc_path != '\0') - { -#ifdef NESSUS_SVC_SORT_FILES - snprintf(cmd, sizeof(cmd), SORT_CMD, nmap_svc_path); - if ((svc[nf].fp = popen(cmd, "r")) == NULL) - perror(cmd); - else - svc[nf].po = 1; - if (! svc[nf].po) -#endif - if ((svc[nf].fp = fopen(nmap_svc_path, "r")) == NULL) - perror(nmap_svc_path); - if (svc[nf].fp != NULL) - if (get_next_svc(&svc[nf])) - { - svc[nf].filename = nmap_svc_path; - nf ++; - } - } if (nf > 0) { @@ -384,19 +272,11 @@ { for (i = 0; i < nf; i ++) if (svc[i].fp != NULL && svc[i].fp != (void*) 1) -#ifdef NESSUS_SVC_SORT_FILES - if (svc[i].po) - pclose(svc[i].fp); - else -#endif fclose(svc[i].fp); unlink(NESSUS_SERVICES_TCP); unlink(NESSUS_SERVICES_UDP); unlink(NESSUS_SERVICES_TXT); } -#ifdef NESSUS_SVC_READS_ETC_SERVICES - endservent(); -#endif return error_flag ? -1 : 0; } Index: store.c =================================================================== RCS file: /usr/local/cvs/nessus-libraries/libnessus/store.c,v retrieving revision 1.31 retrieving revision 1.32 diff -u -d -r1.31 -r1.32 --- store.c 13 Aug 2005 19:04:12 -0000 1.31 +++ store.c 12 Sep 2006 09:46:02 -0000 1.32 @@ -254,13 +254,13 @@ bzero(pp, sizeof(pp)); snprintf(desc_file, sizeof(desc_file), "%s/.desc/%s", dir, file); - str = strrchr(desc_file, '.'); if( str != NULL ) { str[0] = '\0'; if( strlen(desc_file) + 6 < sizeof(desc_file) ) strcat(desc_file, ".desc"); + } snprintf(plug_file, sizeof(plug_file), "%s/%s", dir, file); @@ -268,6 +268,10 @@ stat(desc_file, &st2) < 0 ) return NULL; + /* + * Look if the plugin is newer, and if that's the case also make sure that + * the plugin mtime is not in the future... + */ if ( st1.st_mtime > st2.st_mtime && st1.st_mtime <= time(NULL) ) return NULL; @@ -286,6 +290,7 @@ plug_set_category(ret, p.category); plug_set_fname(ret, file); plug_set_path(ret, p.path); + plug_set_family(ret, p.family, NULL); al = str2arglist(p.required_ports); if ( al != NULL ) arg_add_value(ret, "required_ports", ARG_ARGLIST, -1, al); @@ -300,6 +305,14 @@ al = str2arglist(p.excluded_keys); if ( al != NULL ) arg_add_value(ret, "excluded_keys", ARG_ARGLIST, -1, al); + al = str2arglist(p.dependencies); + if ( al != NULL ) arg_add_value(ret, "DEPENDENCIES", ARG_ARGLIST, -1, al); + + + if ( p.timeout != 0 ) arg_add_value(ret, "TIMEOUT", ARG_INT, -1, (void*)p.timeout); + + arg_add_value(ret, "NAME", ARG_STRING, strlen(p.name), estrdup(p.name)); + arg_add_value(ret, "preferences", ARG_ARGLIST, -1, prefs); @@ -515,15 +528,10 @@ close(fd); - ret = emalloc(sizeof(struct arglist)); - plug_set_id(ret, _plug_get_id(plugin)); - plug_set_category(ret, _plug_get_category(plugin)); - plug_set_fname(ret, file); - plug_set_path(ret, path); - arg_add_value(ret, "preferences", ARG_ARGLIST, -1, arg_get_value(plugin, "preferences")); + arg_set_value(plugin, "preferences", -1, NULL); arg_free_all(plugin); - return ret; + return NULL; } Index: www_funcs.c =================================================================== RCS file: /usr/local/cvs/nessus-libraries/libnessus/www_funcs.c,v retrieving revision 1.66 retrieving revision 1.67 diff -u -d -r1.66 -r1.67 --- www_funcs.c 12 Jun 2004 14:11:40 -0000 1.66 +++ www_funcs.c 12 Sep 2006 09:46:03 -0000 1.67 @@ -636,56 +636,3 @@ } -ExtFunc int http_recv_headers(int soc, char ** result, int * len) -{ - char tmp[2048]; - int sz = 4096; - int n; - char * buf; - int lines = 0; - int num = 0; - - *result = NULL; - *len = 0; - - buf = emalloc(sz); - tmp[ sizeof(tmp) - 1 ] = '\0'; - - for(;;) - { - n = recv_line(soc, tmp, sizeof(tmp) - 1); - lines ++; - if( n <= 0 )break; - - if(!strcmp(tmp, "\r\n")|| - !strcmp(tmp, "\n"))break; - else - { - num += n; - if(num < sz) - strcat(buf, tmp); - else - { - if(sz > 1024 * 1024) - break; - else - sz = sz * 2; - - - buf = erealloc(buf, sz); - strcat(buf, tmp); - if(lines > 100)break; - } - } - } - - if(num == 0) - { - efree(&buf); - } - - *result = buf; - *len = num; - return 0; -} - _______________________________________________ Nessus-cvs mailing list Nessus-cvs [at] list http://mail.nessus.org/mailman/listinfo/nessus-cvs
|