git-svn: trunk@2326
Nigel Horne authored on 2006/09/28 04:25:35... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Wed Sep 27 20:24:26 BST 2006 (njh) |
|
2 |
+---------------------------------- |
|
3 |
+ * libclamav/mbox.c: CL_EXPERIMENTAL: No longer uses curl, or falls back to |
|
4 |
+ external programs when curl isn't installed |
|
5 |
+ |
|
1 | 6 |
Wed Sep 27 20:15:20 BST 2006 (njh) |
2 | 7 |
---------------------------------- |
3 | 8 |
* libclamav/regex_list.c: Fix segfault on Solaris when running --debug |
... | ... |
@@ -16,7 +16,7 @@ |
16 | 16 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
17 | 17 |
* MA 02110-1301, USA. |
18 | 18 |
*/ |
19 |
-static char const rcsid[] = "$Id: mbox.c,v 1.346 2006/09/27 16:28:48 njh Exp $"; |
|
19 |
+static char const rcsid[] = "$Id: mbox.c,v 1.347 2006/09/27 19:23:44 njh Exp $"; |
|
20 | 20 |
|
21 | 21 |
#ifdef _MSC_VER |
22 | 22 |
#include <winsock.h> /* only needed in CL_EXPERIMENTAL */ |
... | ... |
@@ -110,6 +110,7 @@ typedef enum { FALSE = 0, TRUE = 1 } bool; |
110 | 110 |
|
111 | 111 |
#define SAVE_TO_DISC /* multipart/message are saved in a temporary file */ |
112 | 112 |
|
113 |
+#ifndef CL_EXPERIMENTAL |
|
113 | 114 |
/* |
114 | 115 |
* Code does exist to run FOLLOWURLS on systems without libcurl, however that |
115 | 116 |
* is not recommended so it is not compiled by default |
... | ... |
@@ -127,14 +128,15 @@ typedef enum { FALSE = 0, TRUE = 1 } bool; |
127 | 127 |
#if C_SOLARIS && __GNUC__ |
128 | 128 |
#undef WITH_CURL |
129 | 129 |
#endif |
130 |
+#endif |
|
130 | 131 |
|
131 |
-#ifdef WITH_CURL |
|
132 |
+/*#ifdef WITH_CURL*/ |
|
132 | 133 |
#define FOLLOWURLS 5 /* |
133 | 134 |
* Maximum number of URLs scanned in a message |
134 | 135 |
* part. Helps to find Dialer.gen-45. If |
135 | 136 |
* not defined, don't check any URLs |
136 | 137 |
*/ |
137 |
-#endif |
|
138 |
+/*#endif*/ |
|
138 | 139 |
|
139 | 140 |
#if defined(FOLLOWURLS) || defined(CL_EXPERIMENTAL) |
140 | 141 |
#include "htmlnorm.h" |
... | ... |
@@ -292,9 +294,9 @@ static blob* getHrefs(message* m,tag_arguments_t* hrefs); |
292 | 292 |
static void hrefs_done(blob *b,tag_arguments_t* hrefs); |
293 | 293 |
#endif |
294 | 294 |
|
295 |
-#ifdef WITH_CURL |
|
295 |
+#if defined(CL_EXPERIMENTAL) || (!defined(WITH_CURL)) |
|
296 | 296 |
struct arg { |
297 |
-#ifdef CL_EXPERIMENTAL |
|
297 |
+#ifdef CL_EXPERIMENTAL |
|
298 | 298 |
char *url; |
299 | 299 |
#else |
300 | 300 |
CURL *curl; |
... | ... |
@@ -3920,7 +3922,7 @@ do_checkURLs(message *m, const char *dir, tag_arguments_t *hrefs) |
3920 | 3920 |
{ |
3921 | 3921 |
table_t *t; |
3922 | 3922 |
int i, n; |
3923 |
-#if defined(WITH_CURL) && defined(CL_THREAD_SAFE) |
|
3923 |
+#ifdef CL_THREAD_SAFE |
|
3924 | 3924 |
pthread_t tid[FOLLOWURLS]; |
3925 | 3925 |
struct arg args[FOLLOWURLS]; |
3926 | 3926 |
#endif |
... | ... |
@@ -3941,19 +3943,9 @@ do_checkURLs(message *m, const char *dir, tag_arguments_t *hrefs) |
3941 | 3941 |
*/ |
3942 | 3942 |
if(strncasecmp("http://", url, 7) == 0) { |
3943 | 3943 |
char *ptr; |
3944 |
-#ifdef WITH_CURL |
|
3945 | 3944 |
#ifndef CL_THREAD_SAFE |
3946 | 3945 |
struct arg arg; |
3947 | 3946 |
#endif |
3948 |
- |
|
3949 |
-#else /*!WITH_CURL*/ |
|
3950 |
- size_t len; |
|
3951 |
-#ifdef CL_THREAD_SAFE |
|
3952 |
- static pthread_mutex_t system_mutex = PTHREAD_MUTEX_INITIALIZER; |
|
3953 |
-#endif |
|
3954 |
- struct stat statb; |
|
3955 |
- char cmd[512]; |
|
3956 |
-#endif /*WITH_CURL*/ |
|
3957 | 3947 |
char name[NAME_MAX + 1]; |
3958 | 3948 |
|
3959 | 3949 |
if(tableFind(t, url) == 1) { |
... | ... |
@@ -3983,7 +3975,6 @@ do_checkURLs(message *m, const char *dir, tag_arguments_t *hrefs) |
3983 | 3983 |
if(*ptr == '/') |
3984 | 3984 |
*ptr = '_'; |
3985 | 3985 |
|
3986 |
-#ifdef WITH_CURL |
|
3987 | 3986 |
#ifdef CL_THREAD_SAFE |
3988 | 3987 |
args[n].dir = dir; |
3989 | 3988 |
args[n].url = strdup(url); |
... | ... |
@@ -3994,47 +3985,14 @@ do_checkURLs(message *m, const char *dir, tag_arguments_t *hrefs) |
3994 | 3994 |
arg.dir = dir; |
3995 | 3995 |
arg.filename = name; |
3996 | 3996 |
getURL(&arg); |
3997 |
- curl_easy_cleanup(arg.curl); |
|
3998 | 3997 |
free(arg.url); |
3999 | 3998 |
#endif |
4000 |
- |
|
4001 |
-#else /*!WITH_CURL*/ |
|
4002 |
- cli_warnmsg("The use of mail-follow-urls without CURL being installed is deprecated\n"); |
|
4003 |
- /* |
|
4004 |
- * TODO: maximum size and timeouts |
|
4005 |
- */ |
|
4006 |
- len = sizeof(cmd) - 26 - strlen(dir) - strlen(name); |
|
4007 |
-#ifdef CL_DEBUG |
|
4008 |
- snprintf(cmd, sizeof(cmd) - 1, "GET -t10 \"%.*s\" >%s/%s", len, url, dir, name); |
|
4009 |
-#else |
|
4010 |
- snprintf(cmd, sizeof(cmd) - 1, "GET -t10 \"%.*s\" >%s/%s 2>/dev/null", len, url, dir, name); |
|
4011 |
-#endif |
|
4012 |
- cmd[sizeof(cmd) - 1] = '\0'; |
|
4013 |
- |
|
4014 |
- cli_dbgmsg("%s\n", cmd); |
|
4015 |
-#ifdef CL_THREAD_SAFE |
|
4016 |
- pthread_mutex_lock(&system_mutex); |
|
4017 |
-#endif |
|
4018 |
- system(cmd); |
|
4019 |
-#ifdef CL_THREAD_SAFE |
|
4020 |
- pthread_mutex_unlock(&system_mutex); |
|
4021 |
-#endif |
|
4022 |
- snprintf(cmd, sizeof(cmd), "%s/%s", dir, name); |
|
4023 |
- if(stat(cmd, &statb) >= 0) |
|
4024 |
- if(statb.st_size == 0) { |
|
4025 |
- cli_warnmsg("URL %s failed to download\n", url); |
|
4026 |
- /* |
|
4027 |
- * Don't bother scanning an empty file |
|
4028 |
- */ |
|
4029 |
- (void)unlink(cmd); |
|
4030 |
- } |
|
4031 |
-#endif |
|
4032 | 3999 |
++n; |
4033 | 4000 |
} |
4034 | 4001 |
} |
4035 | 4002 |
tableDestroy(t); |
4036 | 4003 |
|
4037 |
-#if defined(WITH_CURL) && defined(CL_THREAD_SAFE) |
|
4004 |
+#ifdef CL_THREAD_SAFE |
|
4038 | 4005 |
assert(n <= FOLLOWURLS); |
4039 | 4006 |
cli_dbgmsg("checkURLs: waiting for %d thread(s) to finish\n", n); |
4040 | 4007 |
while(--n >= 0) { |
... | ... |
@@ -4250,9 +4208,9 @@ checkURLs(message *m, mbox_ctx *mctx, int* rc, int is_html) |
4250 | 4250 |
* download them for scanning. But that will hit performance so there is |
4251 | 4251 |
* an issue here. |
4252 | 4252 |
*/ |
4253 |
-#ifdef WITH_CURL |
|
4254 | 4253 |
|
4255 |
-#ifdef CL_EXPERIMENTAL |
|
4254 |
+#if defined(CL_EXPERIMENTAL) || (!defined(WITH_CURL)) |
|
4255 |
+ |
|
4256 | 4256 |
/* |
4257 | 4257 |
* Removing the reliance on libcurl |
4258 | 4258 |
* Includes some of the freshclam hacks by Everton da Silva Marques |
... | ... |
@@ -4469,7 +4427,7 @@ getURL(struct arg *arg) |
4469 | 4469 |
snprintf(buf, sizeof(buf) - 1, |
4470 | 4470 |
"GET /%s HTTP/1.0\nUser-Agent: www.clamav.net\n\n", url); |
4471 | 4471 |
|
4472 |
- cli_dbgmsg("%s\n", buf); |
|
4472 |
+ /*cli_dbgmsg("%s", buf);*/ |
|
4473 | 4473 |
|
4474 | 4474 |
if(send(sd, buf, (int)strlen(buf), 0) < 0) { |
4475 | 4475 |
closesocket(sd); |
... | ... |
@@ -4912,7 +4870,7 @@ getURL(struct arg *arg) |
4912 | 4912 |
#endif |
4913 | 4913 |
|
4914 | 4914 |
#endif |
4915 |
-#endif |
|
4915 |
+ |
|
4916 | 4916 |
#ifdef HAVE_BACKTRACE |
4917 | 4917 |
static void |
4918 | 4918 |
sigsegv(int sig) |