git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@1086 77e5149b-7576-45b1-b177-96237e5ba77b
Nigel Horne authored on 2004/11/12 18:46:01... | ... |
@@ -1,3 +1,11 @@ |
1 |
+Fri Nov 12 09:44:23 GMT 2004 (njh) |
|
2 |
+---------------------------------- |
|
3 |
+ * libclamav/mbox.c: Draft of RFC1341 support is now on by default. |
|
4 |
+ Fragments arriving out of order are not scanned (yet). |
|
5 |
+ If you use clamav-milter to load balance clamd across |
|
6 |
+ servers you will need to ensure that the partial |
|
7 |
+ directory is on a shared directory (e.g. NFS) |
|
8 |
+ |
|
1 | 9 |
Fri Nov 12 09:05:15 GMT 2004 (njh) |
2 | 10 |
---------------------------------- |
3 | 11 |
* libclamav/message.c: Parse some malformed binhex files |
... | ... |
@@ -17,6 +17,9 @@ |
17 | 17 |
* |
18 | 18 |
* Change History: |
19 | 19 |
* $Log: mbox.c,v $ |
20 |
+ * Revision 1.176 2004/11/12 09:41:45 nigelhorne |
|
21 |
+ * Parial mode now on by default |
|
22 |
+ * |
|
20 | 23 |
* Revision 1.175 2004/11/11 22:15:46 nigelhorne |
21 | 24 |
* Rewrite handling of folded headers |
22 | 25 |
* |
... | ... |
@@ -513,7 +516,7 @@ |
513 | 513 |
* Compilable under SCO; removed duplicate code with message.c |
514 | 514 |
* |
515 | 515 |
*/ |
516 |
-static char const rcsid[] = "$Id: mbox.c,v 1.175 2004/11/11 22:15:46 nigelhorne Exp $"; |
|
516 |
+static char const rcsid[] = "$Id: mbox.c,v 1.176 2004/11/12 09:41:45 nigelhorne Exp $"; |
|
517 | 517 |
|
518 | 518 |
#if HAVE_CONFIG_H |
519 | 519 |
#include "clamav-config.h" |
... | ... |
@@ -647,10 +650,10 @@ typedef enum { FALSE = 0, TRUE = 1 } bool; |
647 | 647 |
* (2) periodically trim the directory of old files |
648 | 648 |
* |
649 | 649 |
* If you use the load balancing feature of clamav-milter to run clamd on |
650 |
- * more than one machine you must make sure that /tmp/partial is on a shared |
|
650 |
+ * more than one machine you must make sure that .../partial is on a shared |
|
651 | 651 |
* network filesystem |
652 | 652 |
*/ |
653 |
-/*#define PARTIAL_DIR "/tmp/partial" /* FIXME: should be config based on TMPDIR */ |
|
653 |
+#define PARTIAL_DIR |
|
654 | 654 |
|
655 | 655 |
static message *parseEmailHeaders(const message *m, const table_t *rfc821Table); |
656 | 656 |
static int parseEmailHeader(message *m, const char *line, const table_t *rfc821Table); |
... | ... |
@@ -2883,28 +2886,56 @@ rfc1341(message *m, const char *dir) |
2883 | 2883 |
{ |
2884 | 2884 |
fileblob *fb; |
2885 | 2885 |
char *arg, *id, *number, *total, *oldfilename; |
2886 |
+ const char *tmpdir; |
|
2887 |
+ char *pdir; |
|
2888 |
+ |
|
2889 |
+#ifdef CYGWIN |
|
2890 |
+ if((tmpdir = getenv("TEMP")) == (char *)NULL) |
|
2891 |
+ if((tmpdir = getenv("TMP")) == (char *)NULL) |
|
2892 |
+ if((tmpdir = getenv("TMPDIR")) == (char *)NULL) |
|
2893 |
+ tmpdir = "C:\\"; |
|
2894 |
+#else |
|
2895 |
+ if((tmpdir = getenv("TMPDIR")) == (char *)NULL) |
|
2896 |
+ if((tmpdir = getenv("TMP")) == (char *)NULL) |
|
2897 |
+ if((tmpdir = getenv("TEMP")) == (char *)NULL) |
|
2898 |
+#ifdef P_tmpdir |
|
2899 |
+ tmpdir = P_tmpdir; |
|
2900 |
+#else |
|
2901 |
+ tmpdir = "/tmp"; |
|
2902 |
+#endif |
|
2903 |
+#endif |
|
2886 | 2904 |
|
2887 |
- if((mkdir(PARTIAL_DIR, 0700) < 0) && (errno != EEXIST)) { |
|
2888 |
- cli_errmsg("Can't create the directory '%s'\n", PARTIAL_DIR); |
|
2905 |
+ pdir = cli_malloc(strlen(tmpdir) + 16); |
|
2906 |
+ if(pdir == NULL) |
|
2907 |
+ return -1; |
|
2908 |
+ sprintf(pdir, "%s/clamav-partial", tmpdir); |
|
2909 |
+ |
|
2910 |
+ if((mkdir(pdir, 0700) < 0) && (errno != EEXIST)) { |
|
2911 |
+ cli_errmsg("Can't create the directory '%s'\n", pdir); |
|
2912 |
+ free(pdir); |
|
2889 | 2913 |
return -1; |
2890 | 2914 |
} else { |
2891 | 2915 |
struct stat statb; |
2892 | 2916 |
|
2893 |
- if(stat(PARTIAL_DIR, &statb) < 0) { |
|
2894 |
- cli_errmsg("Can't stat the directory '%s'\n", PARTIAL_DIR); |
|
2917 |
+ if(stat(pdir, &statb) < 0) { |
|
2918 |
+ cli_errmsg("Can't stat the directory '%s'\n", pdir); |
|
2919 |
+ free(pdir); |
|
2895 | 2920 |
return -1; |
2896 | 2921 |
} |
2897 | 2922 |
if(statb.st_mode & 077) |
2898 | 2923 |
cli_warnmsg("Insecure partial directory %s (mode 0%o)\n", |
2899 |
- PARTIAL_DIR, statb.st_mode & 0777); |
|
2924 |
+ pdir, statb.st_mode & 0777); |
|
2900 | 2925 |
} |
2901 | 2926 |
|
2902 | 2927 |
id = (char *)messageFindArgument(m, "id"); |
2903 |
- if(id == NULL) |
|
2928 |
+ if(id == NULL) { |
|
2929 |
+ free(pdir); |
|
2904 | 2930 |
return -1; |
2931 |
+ } |
|
2905 | 2932 |
number = (char *)messageFindArgument(m, "number"); |
2906 | 2933 |
if(number == NULL) { |
2907 | 2934 |
free(id); |
2935 |
+ free(pdir); |
|
2908 | 2936 |
return -1; |
2909 | 2937 |
} |
2910 | 2938 |
|
... | ... |
@@ -2922,9 +2953,10 @@ rfc1341(message *m, const char *dir) |
2922 | 2922 |
free(oldfilename); |
2923 | 2923 |
} |
2924 | 2924 |
|
2925 |
- if((fb = messageToFileblob(m, PARTIAL_DIR)) == NULL) { |
|
2925 |
+ if((fb = messageToFileblob(m, pdir)) == NULL) { |
|
2926 | 2926 |
free(id); |
2927 | 2927 |
free(number); |
2928 |
+ free(pdir); |
|
2928 | 2929 |
return -1; |
2929 | 2930 |
} |
2930 | 2931 |
|
... | ... |
@@ -2941,7 +2973,7 @@ rfc1341(message *m, const char *dir) |
2941 | 2941 |
* If it's the last one - reassemble it |
2942 | 2942 |
* FIXME: this assumes that we receive the parts in order |
2943 | 2943 |
*/ |
2944 |
- if((n == t) && ((dd = opendir(PARTIAL_DIR)) != NULL)) { |
|
2944 |
+ if((n == t) && ((dd = opendir(pdir)) != NULL)) { |
|
2945 | 2945 |
FILE *fout; |
2946 | 2946 |
char outname[NAME_MAX + 1]; |
2947 | 2947 |
|
... | ... |
@@ -2956,6 +2988,7 @@ rfc1341(message *m, const char *dir) |
2956 | 2956 |
free(total); |
2957 | 2957 |
free(number); |
2958 | 2958 |
closedir(dd); |
2959 |
+ free(pdir); |
|
2959 | 2960 |
return -1; |
2960 | 2961 |
} |
2961 | 2962 |
|
... | ... |
@@ -2982,6 +3015,7 @@ rfc1341(message *m, const char *dir) |
2982 | 2982 |
FILE *fin; |
2983 | 2983 |
char buffer[BUFSIZ]; |
2984 | 2984 |
int nblanks; |
2985 |
+ extern short cli_leavetemps_flag; |
|
2985 | 2986 |
|
2986 | 2987 |
if(dent->d_ino == 0) |
2987 | 2988 |
continue; |
... | ... |
@@ -2989,7 +3023,7 @@ rfc1341(message *m, const char *dir) |
2989 | 2989 |
if(strncmp(filename, dent->d_name, strlen(filename)) != 0) |
2990 | 2990 |
continue; |
2991 | 2991 |
|
2992 |
- sprintf(fullname, "%s/%s", PARTIAL_DIR, dent->d_name); |
|
2992 |
+ sprintf(fullname, "%s/%s", pdir, dent->d_name); |
|
2993 | 2993 |
fin = fopen(fullname, "rb"); |
2994 | 2994 |
if(fin == NULL) { |
2995 | 2995 |
cli_errmsg("Can't open '%s' for reading", fullname); |
... | ... |
@@ -2999,7 +3033,7 @@ rfc1341(message *m, const char *dir) |
2999 | 2999 |
free(total); |
3000 | 3000 |
free(number); |
3001 | 3001 |
closedir(dd); |
3002 |
- |
|
3002 |
+ free(pdir); |
|
3003 | 3003 |
return -1; |
3004 | 3004 |
} |
3005 | 3005 |
nblanks = 0; |
... | ... |
@@ -3018,8 +3052,10 @@ rfc1341(message *m, const char *dir) |
3018 | 3018 |
fputs(buffer, fout); |
3019 | 3019 |
} |
3020 | 3020 |
fclose(fin); |
3021 |
- /* FIXME: don't unlink if leave temps */ |
|
3022 |
- unlink(fullname); |
|
3021 |
+ |
|
3022 |
+ /* don't unlink if leave temps */ |
|
3023 |
+ if(!cli_leavetemps_flag) |
|
3024 |
+ unlink(fullname); |
|
3023 | 3025 |
break; |
3024 | 3026 |
} |
3025 | 3027 |
rewinddir(dd); |
... | ... |
@@ -3031,6 +3067,7 @@ rfc1341(message *m, const char *dir) |
3031 | 3031 |
} |
3032 | 3032 |
free(id); |
3033 | 3033 |
free(total); |
3034 |
+ free(pdir); |
|
3034 | 3035 |
|
3035 | 3036 |
return 0; |
3036 | 3037 |
} |