git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@744 77e5149b-7576-45b1-b177-96237e5ba77b
Nigel Horne authored on 2004/08/12 19:37:53... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Thu Aug 12 11:36:36 BST 2004 (njh) |
|
2 |
+---------------------------------- |
|
3 |
+ * libclamav/mbox.c: checkURLs code (not compiled by default) can now |
|
4 |
+ download using LIBCURL |
|
5 |
+ |
|
1 | 6 |
Wed Aug 11 16:29:05 BST 2004 (njh) |
2 | 7 |
---------------------------------- |
3 | 8 |
* libclamav/mbox.c: No longer needs curl.h to compile (thanks to TK) |
... | ... |
@@ -17,6 +17,9 @@ |
17 | 17 |
* |
18 | 18 |
* Change History: |
19 | 19 |
* $Log: mbox.c,v $ |
20 |
+ * Revision 1.100 2004/08/12 10:36:09 nigelhorne |
|
21 |
+ * LIBCURL completed |
|
22 |
+ * |
|
20 | 23 |
* Revision 1.99 2004/08/11 15:28:39 nigelhorne |
21 | 24 |
* No longer needs curl.h |
22 | 25 |
* |
... | ... |
@@ -285,7 +288,7 @@ |
285 | 285 |
* Compilable under SCO; removed duplicate code with message.c |
286 | 286 |
* |
287 | 287 |
*/ |
288 |
-static char const rcsid[] = "$Id: mbox.c,v 1.99 2004/08/11 15:28:39 nigelhorne Exp $"; |
|
288 |
+static char const rcsid[] = "$Id: mbox.c,v 1.100 2004/08/12 10:36:09 nigelhorne Exp $"; |
|
289 | 289 |
|
290 | 290 |
#if HAVE_CONFIG_H |
291 | 291 |
#include "clamav-config.h" |
... | ... |
@@ -358,16 +361,18 @@ static void print_trace(int use_syslog); |
358 | 358 |
#undef FALSE |
359 | 359 |
#endif |
360 | 360 |
|
361 |
+typedef enum { FALSE = 0, TRUE = 1 } bool; |
|
362 |
+ |
|
361 | 363 |
#define SAVE_TO_DISC /* multipart/message are saved in a temporary file */ |
362 | 364 |
/*#define CHECKURLS /* If an email contains URLs, check them */ |
363 |
-/*#define LIBCURL /* Needs support from "configure" */ |
|
365 |
+/*#define LIBCURL /* To build with LIBCURL: |
|
366 |
+ * LDFLAGS=`curl-config --libs` ./configure ... |
|
367 |
+ */ |
|
364 | 368 |
|
365 | 369 |
#ifdef LIBCURL |
366 | 370 |
#include <curl/curl.h> |
367 | 371 |
#endif |
368 | 372 |
|
369 |
-typedef enum { FALSE = 0, TRUE = 1 } bool; |
|
370 |
- |
|
371 | 373 |
static message *parseEmailHeaders(message *m, const table_t *rfc821Table, bool destroy); |
372 | 374 |
static int parseEmailHeader(message *m, const char *line, const table_t *rfc821Table); |
373 | 375 |
static int parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, const char *dir, table_t *rfc821Table, table_t *subtypeTable, unsigned int options); |
... | ... |
@@ -588,7 +593,8 @@ cli_mbox(const char *dir, int desc, unsigned int options) |
588 | 588 |
*/ |
589 | 589 |
while(strchr("\r\n", buffer[0]) && |
590 | 590 |
(fgets(buffer, sizeof(buffer), fd) != NULL)) |
591 |
- ; |
|
591 |
+ ; |
|
592 |
+ |
|
592 | 593 |
/* |
593 | 594 |
* FIXME: files full of new lines and nothing else are |
594 | 595 |
* handled ungracefully... |
... | ... |
@@ -1989,7 +1995,7 @@ strip(char *buf, int len) |
1989 | 1989 |
do |
1990 | 1990 |
if(*ptr) |
1991 | 1991 |
*ptr = '\0'; |
1992 |
- while((--len >= 0) && !isgraph(*--ptr) && (*ptr != '\n') && (*ptr != '\r')); |
|
1992 |
+ while((--len >= 0) && (!isgraph(*--ptr)) && (*ptr != '\n') && (*ptr != '\r')); |
|
1993 | 1993 |
#else /* more characters can be displayed on DOS */ |
1994 | 1994 |
do |
1995 | 1995 |
#ifndef REAL_MODE_DOS |
... | ... |
@@ -2264,14 +2270,22 @@ checkURLs(message *m, const char *dir) |
2264 | 2264 |
blob *b = messageToBlob(m); |
2265 | 2265 |
char *ptr; |
2266 | 2266 |
size_t len; |
2267 |
- table_t *t = tableCreate(); |
|
2267 |
+ table_t *t; |
|
2268 | 2268 |
|
2269 | 2269 |
if(b == NULL) |
2270 | 2270 |
return; |
2271 | 2271 |
|
2272 |
- ptr = blobGetData(b); |
|
2272 |
+ ptr = (char *)blobGetData(b); |
|
2273 | 2273 |
len = blobGetDataSize(b); |
2274 | 2274 |
|
2275 |
+ /* TODO: make this size customisable */ |
|
2276 |
+ if(len > 100*1024) { |
|
2277 |
+ cli_warnmsg("Viruses pointed to by URL not scanned in large message\n"); |
|
2278 |
+ blobDestroy(b); |
|
2279 |
+ } |
|
2280 |
+ |
|
2281 |
+ t = tableCreate(); |
|
2282 |
+ |
|
2275 | 2283 |
/* |
2276 | 2284 |
* cli_memstr(ptr, len, "<a href=", 8) |
2277 | 2285 |
* Don't use cli_memstr() until bounds problem sorted, it becomes |
... | ... |
@@ -2280,13 +2294,16 @@ checkURLs(message *m, const char *dir) |
2280 | 2280 |
while(len >= 8) { |
2281 | 2281 |
/* FIXME: allow any number of white space */ |
2282 | 2282 |
if(strncasecmp(ptr, "<a href=", 8) == 0) { |
2283 |
+#ifndef LIBCURL |
|
2283 | 2284 |
#ifdef CL_THREAD_SAFE |
2284 | 2285 |
static pthread_mutex_t system_mutex = PTHREAD_MUTEX_INITIALIZER; |
2285 | 2286 |
#endif |
2287 |
+ struct stat statb; |
|
2288 |
+ char cmd[512]; |
|
2289 |
+#endif |
|
2286 | 2290 |
char *p2 = &ptr[8]; |
2287 | 2291 |
char *p3; |
2288 |
- char cmd[512], name[512]; |
|
2289 |
- struct stat statb; |
|
2292 |
+ char name[512]; |
|
2290 | 2293 |
|
2291 | 2294 |
len -= 8; |
2292 | 2295 |
while((len > 0) && ((*p2 == '\"') || isspace(*p2))) { |
... | ... |
@@ -2356,21 +2373,25 @@ static void |
2356 | 2356 |
getURL(const char *url, const char *dir, const char *filename) |
2357 | 2357 |
{ |
2358 | 2358 |
char *fout; |
2359 |
- static CURL *curl; |
|
2359 |
+ CURL *curl; |
|
2360 | 2360 |
FILE *fp; |
2361 |
+ struct curl_slist *headers; |
|
2362 |
+ static int initialised = 0; |
|
2361 | 2363 |
|
2362 |
- if(curl == NULL) { |
|
2364 |
+ if(!initialised) { |
|
2363 | 2365 |
if(curl_global_init(CURL_GLOBAL_NOTHING) != 0) |
2364 | 2366 |
return; |
2365 |
- /* easy isn't the word I'd use... */ |
|
2366 |
- curl = curl_easy_init(); |
|
2367 |
- if(curl == NULL) { |
|
2368 |
- curl_global_cleanup(); |
|
2369 |
- return; |
|
2370 |
- } |
|
2371 |
- (void)curl_easy_setopt(curl, CURLOPT_USERAGENT, "www.clamav.net"); |
|
2372 |
- |
|
2367 |
+ initialised = 1; |
|
2373 | 2368 |
} |
2369 |
+ /* easy isn't the word I'd use... */ |
|
2370 |
+ curl = curl_easy_init(); |
|
2371 |
+ if(curl == NULL) |
|
2372 |
+ return; |
|
2373 |
+ (void)curl_easy_setopt(curl, CURLOPT_USERAGENT, "www.clamav.net"); |
|
2374 |
+ |
|
2375 |
+ if(curl_easy_setopt(curl, CURLOPT_URL, url) != 0) |
|
2376 |
+ return; |
|
2377 |
+ |
|
2374 | 2378 |
fout = cli_malloc(strlen(dir) + strlen(filename) + 2); |
2375 | 2379 |
|
2376 | 2380 |
if(fout == NULL) |
... | ... |
@@ -2385,12 +2406,31 @@ getURL(const char *url, const char *dir, const char *filename) |
2385 | 2385 |
free(fout); |
2386 | 2386 |
return; |
2387 | 2387 |
} |
2388 |
- free(fout); |
|
2388 |
+ /* |
|
2389 |
+ * If an item is in squid's cache get it from there (TCP_HIT/200) but |
|
2390 |
+ * by default curl doesn't (TCP_CLIENT_REFRESH_MISS/200) |
|
2391 |
+ */ |
|
2392 |
+ headers = curl_slist_append(NULL, "Pragma:"); |
|
2393 |
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); |
|
2389 | 2394 |
|
2390 |
- if(curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp) != 0) |
|
2395 |
+ if(curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp) != 0) { |
|
2396 |
+ fclose(fp); |
|
2397 |
+ free(fout); |
|
2391 | 2398 |
return; |
2399 |
+ } |
|
2400 |
+ |
|
2401 |
+ /* These should be customisable */ |
|
2402 |
+ curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30); |
|
2403 |
+ curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10); |
|
2392 | 2404 |
|
2393 |
- (void)curl_easy_perform(curl); |
|
2405 |
+ if(curl_easy_perform(curl) != CURLE_OK) { |
|
2406 |
+ cli_warnmsg("URL %s failed to download\n", url); |
|
2407 |
+ unlink(fout); |
|
2408 |
+ } |
|
2409 |
+ |
|
2410 |
+ fclose(fp); |
|
2411 |
+ curl_easy_cleanup(curl); |
|
2412 |
+ free(fout); |
|
2394 | 2413 |
} |
2395 | 2414 |
#endif |
2396 | 2415 |
|