git-svn: trunk@737
Nigel Horne authored on 2004/08/10 17:17:19... | ... |
@@ -1,3 +1,9 @@ |
1 |
+Tue Aug 10 09:15:17 BST 2004 (njh) |
|
2 |
+---------------------------------- |
|
3 |
+ * libclamav/mbox.c: checkURLs code now enabled. CL_MAILURL option not |
|
4 |
+ yet supported - all emails are scanned, needs |
|
5 |
+ the GET command for now (link to lwp-request(1)) |
|
6 |
+ |
|
1 | 7 |
Mon Aug 9 23:31:53 CEST 2004 (tk) |
2 | 8 |
---------------------------------- |
3 | 9 |
* libclamav: add new option CL_MAILURL |
... | ... |
@@ -17,6 +17,9 @@ |
17 | 17 |
* |
18 | 18 |
* Change History: |
19 | 19 |
* $Log: mbox.c,v $ |
20 |
+ * Revision 1.96 2004/08/10 08:14:00 nigelhorne |
|
21 |
+ * Enable CHECKURL |
|
22 |
+ * |
|
20 | 23 |
* Revision 1.95 2004/08/09 21:37:21 kojm |
21 | 24 |
* libclamav: add new option CL_MAILURL |
22 | 25 |
* |
... | ... |
@@ -273,7 +276,7 @@ |
273 | 273 |
* Compilable under SCO; removed duplicate code with message.c |
274 | 274 |
* |
275 | 275 |
*/ |
276 |
-static char const rcsid[] = "$Id: mbox.c,v 1.95 2004/08/09 21:37:21 kojm Exp $"; |
|
276 |
+static char const rcsid[] = "$Id: mbox.c,v 1.96 2004/08/10 08:14:00 nigelhorne Exp $"; |
|
277 | 277 |
|
278 | 278 |
#if HAVE_CONFIG_H |
279 | 279 |
#include "clamav-config.h" |
... | ... |
@@ -304,6 +307,8 @@ static char const rcsid[] = "$Id: mbox.c,v 1.95 2004/08/09 21:37:21 kojm Exp $"; |
304 | 304 |
#include <sys/param.h> |
305 | 305 |
#include <clamav.h> |
306 | 306 |
|
307 |
+#include <curl/curl.h> |
|
308 |
+ |
|
307 | 309 |
#ifdef CL_THREAD_SAFE |
308 | 310 |
#include <pthread.h> |
309 | 311 |
#endif |
... | ... |
@@ -346,6 +351,10 @@ static void print_trace(int use_syslog); |
346 | 346 |
#undef FALSE |
347 | 347 |
#endif |
348 | 348 |
|
349 |
+#define SAVE_TO_DISC /* multipart/message are saved in a temporary file */ |
|
350 |
+#define CHECKURLS /* If an email contains URLs, check them */ |
|
351 |
+/*#define LIBCURL /* Needs support from "configure" */ |
|
352 |
+ |
|
349 | 353 |
typedef enum { FALSE = 0, TRUE = 1 } bool; |
350 | 354 |
|
351 | 355 |
static message *parseEmailHeaders(message *m, const table_t *rfc821Table, bool destroy); |
... | ... |
@@ -360,7 +369,14 @@ static bool continuationMarker(const char *line); |
360 | 360 |
static int parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const char *arg); |
361 | 361 |
static void saveTextPart(message *m, const char *dir); |
362 | 362 |
static bool saveFile(const blob *b, const char *dir); |
363 |
+ |
|
364 |
+#ifdef CHECKURLS |
|
363 | 365 |
static void checkURLs(message *m, const char *dir); |
366 |
+#ifdef LIBCURL |
|
367 |
+static void getURL(const char *url, const char *dir, const char *filename); |
|
368 |
+#endif |
|
369 |
+#endif |
|
370 |
+ |
|
364 | 371 |
|
365 | 372 |
/* Maximum number of attachments that we accept */ |
366 | 373 |
#define MAX_ATTACHMENTS 10 |
... | ... |
@@ -438,9 +454,6 @@ static table_t *rfc821Table, *subtypeTable; |
438 | 438 |
#define O_BINARY 0 |
439 | 439 |
#endif |
440 | 440 |
|
441 |
-#define SAVE_TO_DISC /* multipart/message are saved in a temporary file */ |
|
442 |
-#define SCAN_MAILURL (options & CL_MAILURL) |
|
443 |
- |
|
444 | 441 |
/* |
445 | 442 |
* TODO: when signal handling is added, need to remove temp files when a |
446 | 443 |
* signal is received |
... | ... |
@@ -1269,7 +1282,7 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con |
1269 | 1269 |
addAttachment = TRUE; |
1270 | 1270 |
} |
1271 | 1271 |
} else { |
1272 |
- if(SCAN_MAILURL) |
|
1272 |
+ /*if(options&CL_MAILURL) */ |
|
1273 | 1273 |
checkURLs(aMessage, dir); |
1274 | 1274 |
messageAddArgument(aMessage, "filename=textportion"); |
1275 | 1275 |
addAttachment = TRUE; |
... | ... |
@@ -1343,8 +1356,8 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con |
1343 | 1343 |
messageDestroy(mainMessage); |
1344 | 1344 |
|
1345 | 1345 |
/*t = messageToText(body); |
1346 |
- rc = parseEmailBody(body, blobs, nBlobs, t, dir, rfc821Table, subtypeTable);*/ |
|
1347 |
- rc = parseEmailBody(body, blobs, nBlobs, aText, dir, rfc821Table, subtypeTable); |
|
1346 |
+ rc = parseEmailBody(body, blobs, nBlobs, t, dir, rfc821Table, subtypeTable, options);*/ |
|
1347 |
+ rc = parseEmailBody(body, blobs, nBlobs, aText, dir, rfc821Table, subtypeTable, options); |
|
1348 | 1348 |
/*textDestroy(t);*/ |
1349 | 1349 |
|
1350 | 1350 |
cli_dbgmsg("Finished recursion\n"); |
... | ... |
@@ -2205,6 +2218,7 @@ saveFile(const blob *b, const char *dir) |
2205 | 2205 |
return (close(fd) >= 0); |
2206 | 2206 |
} |
2207 | 2207 |
|
2208 |
+#ifdef CHECKURLS |
|
2208 | 2209 |
static void |
2209 | 2210 |
checkURLs(message *m, const char *dir) |
2210 | 2211 |
{ |
... | ... |
@@ -2220,8 +2234,8 @@ checkURLs(message *m, const char *dir) |
2220 | 2220 |
|
2221 | 2221 |
/* |
2222 | 2222 |
* cli_memstr(ptr, len, "<a href=", 8) |
2223 |
- * Don't use cli_memstr() until bounds problem sorted and it becomes |
|
2224 |
- * case independant |
|
2223 |
+ * Don't use cli_memstr() until bounds problem sorted, it becomes |
|
2224 |
+ * case independant and it returns the place that the 'needle' was found |
|
2225 | 2225 |
*/ |
2226 | 2226 |
while(len >= 8) { |
2227 | 2227 |
/* FIXME: allow any number of white space */ |
... | ... |
@@ -2257,6 +2271,12 @@ checkURLs(message *m, const char *dir) |
2257 | 2257 |
if(*p3 == '/') |
2258 | 2258 |
*p3 = '_'; |
2259 | 2259 |
|
2260 |
+#ifdef LIBCURL |
|
2261 |
+ getURL(p2, dir, name); |
|
2262 |
+#else |
|
2263 |
+ /* |
|
2264 |
+ * TODO: maximum size and timeouts |
|
2265 |
+ */ |
|
2260 | 2266 |
snprintf(cmd, sizeof(cmd), "GET %s > %s/%s", p2, dir, name); |
2261 | 2267 |
cli_dbgmsg("%s\n", cmd); |
2262 | 2268 |
#ifdef CL_THREAD_SAFE |
... | ... |
@@ -2275,6 +2295,7 @@ checkURLs(message *m, const char *dir) |
2275 | 2275 |
*/ |
2276 | 2276 |
(void)unlink(cmd); |
2277 | 2277 |
} |
2278 |
+#endif |
|
2278 | 2279 |
} |
2279 | 2280 |
ptr++; |
2280 | 2281 |
len--; |
... | ... |
@@ -2282,6 +2303,56 @@ checkURLs(message *m, const char *dir) |
2282 | 2282 |
blobDestroy(b); |
2283 | 2283 |
} |
2284 | 2284 |
|
2285 |
+#ifdef LIBCURL |
|
2286 |
+static void |
|
2287 |
+getURL(const char *url, const char *dir, const char *filename) |
|
2288 |
+{ |
|
2289 |
+ char *fout; |
|
2290 |
+ static CURL *curl; |
|
2291 |
+ FILE *fp; |
|
2292 |
+ |
|
2293 |
+ if(curl == NULL) { |
|
2294 |
+ if(curl_global_init(CURL_GLOBAL_NOTHING) != 0) |
|
2295 |
+ return; |
|
2296 |
+ /* easy isn't the word I'd use... */ |
|
2297 |
+ curl = curl_easy_init(); |
|
2298 |
+ if(curl == NULL) { |
|
2299 |
+ curl_global_cleanup(); |
|
2300 |
+ return; |
|
2301 |
+ } |
|
2302 |
+ (void)curl_easy_setopt(curl, CURLOPT_USERAGENT, "www.clamav.net"); |
|
2303 |
+ |
|
2304 |
+ } |
|
2305 |
+ fout = cli_malloc(strlen(dir) + strlen(filename) + 2); |
|
2306 |
+ |
|
2307 |
+ if(fout == NULL) |
|
2308 |
+ return; |
|
2309 |
+ |
|
2310 |
+ sprintf(fout, "%s/%s", dir, filename); |
|
2311 |
+ |
|
2312 |
+ fp = fopen(fout, "w"); |
|
2313 |
+ |
|
2314 |
+ if(fp == NULL) { |
|
2315 |
+ perror(fout); |
|
2316 |
+ free(fout); |
|
2317 |
+ return; |
|
2318 |
+ } |
|
2319 |
+ free(fout); |
|
2320 |
+ |
|
2321 |
+ if(curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp) != 0) |
|
2322 |
+ return; |
|
2323 |
+ |
|
2324 |
+ (void)curl_easy_perform(curl); |
|
2325 |
+} |
|
2326 |
+#endif |
|
2327 |
+ |
|
2328 |
+#else |
|
2329 |
+static void |
|
2330 |
+checkURLs(message *m, const char *dir) |
|
2331 |
+{ |
|
2332 |
+} |
|
2333 |
+#endif |
|
2334 |
+ |
|
2285 | 2335 |
#ifdef HAVE_BACKTRACE |
2286 | 2336 |
static void |
2287 | 2337 |
sigsegv(int sig) |