
mikhail at nessus
Sep 12, 2006, 2:49 AM
Post #1 of 1
(585 views)
Permalink
|
|
nessus-core/nessus-fetch nessus-fetch.c,1.12,1.13
|
|
Update of /usr/local/cvs/nessus-core/nessus-fetch In directory raccoon.nessus.org:/tmp/cvs-serv4246/nessus-core/nessus-fetch Modified Files: nessus-fetch.c Log Message: Synchronize back DEVEL with 2.2 Index: nessus-fetch.c =================================================================== RCS file: /usr/local/cvs/nessus-core/nessus-fetch/nessus-fetch.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- nessus-fetch.c 21 Jul 2005 16:34:39 -0000 1.12 +++ nessus-fetch.c 12 Sep 2006 09:49:06 -0000 1.13 @@ -38,6 +38,8 @@ #define SUCCESS_MSG "@SUCCESS@" #define CONFIG_FILE "nessus-fetch.rc" +#define SEGSIZE 1024 + #ifndef INADDR_NONE #define INADDR_NONE 0xffffffff #endif @@ -76,6 +78,58 @@ return 0; } +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) > ( num + 1 ) ? (sz * 2) : (num + 1); + + buf = erealloc(buf, sz); + strcat(buf, tmp); + if(lines > 100)break; + } + } + } + + if(num == 0) + { + efree(&buf); + } + + *result = buf; + *len = num; + return 0; +} + /*------------------------------------------------------------------------- @@ -239,6 +293,7 @@ char * proxy_port; char * proxy_username; char * proxy_password; + char * user_agent; }; int proxy_connect_method(char * hostname, int port, struct preferences * prefs, struct arglist * hostinfo); @@ -265,6 +320,8 @@ prefs->proxy_username ? prefs->proxy_username:"", prefs->proxy_password ? prefs->proxy_password : ""); + if ( prefs->user_agent != NULL ) + fprintf(fp, "user_agent=%s\n", prefs->user_agent); fclose(fp); chmod(path, 0600); @@ -314,6 +371,9 @@ else if ( strncmp(buf, "proxy_password=", strlen("proxy_password=") ) == 0 ) prefs->proxy_password = shift_pref(buf, "proxy_password="); + + else if ( strncmp(buf, "user_agent=", strlen("user_agent=") ) == 0 ) + prefs->user_agent = shift_pref(buf, "user_agent="); } fclose(fp); @@ -367,7 +427,9 @@ n = 0; do { int e = 0; - e = read_stream_connection_min(fd, mybuf + sz + n, total_len + 2 - n, total_len + 2 - n ); + int l; + l = total_len + 2 - n > SEGSIZE ? SEGSIZE : total_len + 2 - n; + e = read_stream_connection_min(fd, mybuf + sz + n, 1, l ); if ( e <= 0 ) break; n += e; } while ( n != total_len + 2); @@ -426,8 +488,8 @@ int e; int readsz; - readsz = (len - n) > 65535 ? 65535 : (len - n); - e = read_stream_connection_min(fd, retbuf + headers_len + n, readsz, readsz); + readsz = (len - n) > SEGSIZE ? SEGSIZE : (len - n); + e = read_stream_connection_min(fd, retbuf + headers_len + n, 1, readsz); if ( e <= 0 ) break; else n += e; } @@ -449,9 +511,8 @@ } else { -#define CHUNKSZ 16384 int len = headers_len; - int bufsz = len + CHUNKSZ * 5; + int bufsz = len + SEGSIZE * 5; char * buf = emalloc( bufsz ); int n; @@ -459,11 +520,11 @@ for (n = 0;; ) { int e; - e = read_stream_connection(fd, buf + headers_len + n, CHUNKSZ); + e = read_stream_connection_min(fd, buf + headers_len + n, 1, SEGSIZE ); if ( e <= 0 ) break; else { len += e; n += e; } - if ( len + CHUNKSZ >= bufsz ) + if ( len + SEGSIZE >= bufsz ) { if ( bufsz > MAX_SIZE ) break; bufsz *= 2; @@ -487,6 +548,7 @@ struct preferences prefs; char proxy_auth[1024]; char auth[1024]; + char ua[512]; load_preferences(&prefs); @@ -510,16 +572,18 @@ } else auth[0] = '\0'; + snprintf(ua, sizeof(ua), "Nessus-Fetch/%s", nessuslib_version()); sprintf(str, "GET %s HTTP/1.1\r\n\ Connection: Close\r\n\ Host: %s\r\n\ Pragma: no-cache\r\n\ -User-Agent: Nessus-Fetch/%s\r\n\ +User-Agent: %s\r\n\ +X-Nessus: %s\r\n\ %s%sAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*\r\n\ Accept-Language: en\r\n\ Accept-Charset: iso-8859-1,*,utf-8\r\n\r\n", - path, hostname, nessuslib_version(), proxy_auth[0] ? proxy_auth:"", auth[0] ? auth:""); + path, hostname, ( prefs.user_agent != NULL && prefs.user_agent[0] != '\0' ) ? prefs.user_agent : ua, nessuslib_version(), proxy_auth[0] ? proxy_auth:"", auth[0] ? auth:""); return str; } @@ -655,7 +719,7 @@ fprintf(stderr, "could not connect to %s - %s\n", plug_get_hostname(hostinfo), strerror(errno)); exit(1); } - stream_set_buffer(soc, 65535); + stream_set_buffer(soc, 0); write_stream_connection(soc, req, strlen(req)); @@ -908,7 +972,7 @@ } if (strstr(result, SUCCESS_MSG) != NULL ) { - fprintf(stderr, "nessus-fetch is properly configured to receive a direct plugin feed\n"); + fprintf(stderr, "nessus-fetch is properly configured to receive a plugin feed\n"); exit(0); } else if ( strstr(result, ERROR_PREFIX ) != NULL ) @@ -919,7 +983,7 @@ } } else { - fprintf(stderr, "nessus-fetch is not configured to receive a direct plugin feed\n"); + fprintf(stderr, "nessus-fetch is not configured to receive a plugin feed\n"); exit(1); } _______________________________________________ Nessus-cvs mailing list Nessus-cvs [at] list http://mail.nessus.org/mailman/listinfo/nessus-cvs
|