Browse code

clamscan: merge win32 patches from NJH

git-svn: trunk@2864

Tomasz Kojm authored on 2007/02/25 11:54:38
Showing 10 changed files
... ...
@@ -1,3 +1,7 @@
1
+Sun Feb 25 01:58:55 CET 2007 (tk)
2
+---------------------------------
3
+  * clamscan: merge win32 patches from NJH
4
+
1 5
 Sat Feb 24 22:47:28 GMT 2007 (njh)
2 6
 ----------------------------------
3 7
   * libclamav/pdf.c:	Remove warning on FreeBSD4.11
... ...
@@ -135,6 +135,9 @@
135 135
 /* have gmp installed */
136 136
 #undef HAVE_GMP
137 137
 
138
+/* Define to 1 if you have the <grp.h> header file. */
139
+#undef HAVE_GRP_H
140
+
138 141
 /* Define to 1 if you have the <iconv.h> header file. */
139 142
 #undef HAVE_ICONV_H
140 143
 
... ...
@@ -192,6 +195,9 @@
192 192
 /* "pragma pack hppa/hp-ux style" */
193 193
 #undef HAVE_PRAGMA_PACK_HPPA
194 194
 
195
+/* Define to 1 if you have the <pwd.h> header file. */
196
+#undef HAVE_PWD_H
197
+
195 198
 /* readdir_r takes 2 arguments */
196 199
 #undef HAVE_READDIR_R_2
197 200
 
... ...
@@ -24,8 +24,14 @@
24 24
 #include <stdio.h>
25 25
 #include <stdlib.h>
26 26
 #include <string.h>
27
+#ifdef	HAVE_UNISTD_H
27 28
 #include <unistd.h>
29
+#endif
30
+#ifdef	C_WINDOWS
31
+#include <fcntl.h>
32
+#else
28 33
 #include <sys/time.h>
34
+#endif
29 35
 #include <time.h>
30 36
 #ifdef C_LINUX
31 37
 #include <sys/resource.h>
... ...
@@ -43,6 +49,10 @@
43 43
 
44 44
 void help(void);
45 45
 
46
+#if defined(C_WINDOWS) && defined(CL_DEBUG)
47
+#include <crtdbg.h>
48
+#endif
49
+
46 50
 struct s_info info;
47 51
 short recursion = 0, printinfected = 0, bell = 0;
48 52
 
... ...
@@ -51,10 +61,18 @@ int main(int argc, char **argv)
51 51
 	int ds, dms, ret;
52 52
 	double mb;
53 53
 	struct timeval t1, t2;
54
+#ifndef C_WINDOWS
54 55
 	struct timezone tz;
56
+#endif
55 57
 	struct optstruct *opt;
56 58
 	const char *pt;
57 59
 
60
+#if defined(C_WINDOWS) && defined(CL_THREAD_SAFE)
61
+    if(!pthread_win32_process_attach_np()) {
62
+	mprintf("!Can't start the win32 pthreads layer\n");
63
+	return 72;
64
+    }
65
+#endif
58 66
 
59 67
     opt = opt_parse(argc, argv, clamscan_shortopt, clamscan_longopt, NULL);
60 68
     if(!opt) {
... ...
@@ -180,11 +198,27 @@ int main(int argc, char **argv)
180 180
 
181 181
     memset(&info, 0, sizeof(struct s_info));
182 182
 
183
+#ifdef C_WINDOWS
184
+    _set_fmode(_O_BINARY);
185
+#ifdef CL_DEBUG
186
+    {
187
+	_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
188
+	_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
189
+    }
190
+#endif	
191
+    gettimeofday(&t1, NULL);
192
+#else
183 193
     gettimeofday(&t1, &tz);
194
+#endif
195
+
184 196
     ret = scanmanager(opt);
185 197
 
186 198
     if(!opt_check(opt, "disable-summary") && !opt_check(opt, "no-summary")) {
199
+#ifdef C_WINDOWS
200
+	gettimeofday(&t2, NULL);
201
+#else
187 202
 	gettimeofday(&t2, &tz);
203
+#endif
188 204
 	ds = t2.tv_sec - t1.tv_sec;
189 205
 	dms = t2.tv_usec - t1.tv_usec;
190 206
 	ds -= (dms < 0) ? (1):(0);
... ...
@@ -210,6 +244,14 @@ int main(int argc, char **argv)
210 210
     }
211 211
 
212 212
     opt_free(opt);
213
+
214
+#if defined(C_WINDOWS) && defined(CL_THREAD_SAFE)
215
+    if(!pthread_win32_process_detach_np()) {
216
+	logg("!Can't stop the win32 pthreads layer\n");
217
+	return 72;
218
+    }
219
+#endif
220
+
213 221
     return ret;
214 222
 }
215 223
 
... ...
@@ -29,11 +29,22 @@
29 29
 #include <ctype.h>
30 30
 #include <sys/stat.h>
31 31
 #include <sys/types.h>
32
+#ifdef C_WINDOWS
33
+#include <sys/utime.h>
34
+#else
32 35
 #include <sys/wait.h>
33 36
 #include <utime.h>
37
+#endif
38
+#ifdef HAVE_GRP_H
34 39
 #include <grp.h>
40
+#endif
41
+#ifdef HAVE_PWD_H
42
+#include <pwd.h>
43
+#endif
35 44
 #include <fcntl.h>
45
+#ifdef	HAVE_UNISTD_H
36 46
 #include <unistd.h>
47
+#endif
37 48
 #include <sys/types.h>
38 49
 #include <signal.h>
39 50
 #include <errno.h>
... ...
@@ -57,6 +68,15 @@
57 57
 dev_t procdev;
58 58
 #endif
59 59
 
60
+#ifdef C_WINDOWS
61
+#undef P_tmpdir
62
+#define P_tmpdir    "C:\\WINDOWS\\TEMP"
63
+#endif
64
+
65
+#ifndef	O_BINARY
66
+#define	O_BINARY    0
67
+#endif
68
+
60 69
 static int scandirs(const char *dirname, struct cl_engine *engine, const struct passwd *user, const struct optstruct *opt, const struct cl_limits *limits, int options)
61 70
 {
62 71
     return treewalk(dirname, engine, user, opt, limits, options, 1);
... ...
@@ -132,7 +152,7 @@ int scanmanager(const struct optstruct *opt)
132 132
 
133 133
 
134 134
 /* njh@bandsman.co.uk: BeOS */
135
-#if !defined(C_CYGWIN) && !defined(C_OS2) && !defined(C_BEOS)
135
+#if !defined(C_CYGWIN) && !defined(C_OS2) && !defined(C_BEOS) && !defined(C_WINDOWS)
136 136
     if(!geteuid()) {
137 137
 	if((user = getpwnam(CLAMAVUSER)) == NULL) {
138 138
 	    logg("!Can't get information about user "CLAMAVUSER"\n");
... ...
@@ -388,6 +408,15 @@ int scanmanager(const struct optstruct *opt)
388 388
  * -3 -> external signal
389 389
  * 0 -> OK
390 390
  */
391
+
392
+#ifdef C_WINDOWS
393
+static int clamav_unpack(const char *prog, char **args, const char *tmpdir, const struct passwd *user, const struct optstruct *opt)
394
+{
395
+    /* TODO: use spamvp(P_WAIT, prog, args); */
396
+    cli_errmsg("clamav_unpack is not supported under Windows yet\n");
397
+    return -1;
398
+}
399
+#else
391 400
 static int clamav_unpack(const char *prog, char **args, const char *tmpdir, const struct passwd *user, const struct optstruct *opt)
392 401
 {
393 402
 	pid_t pid;
... ...
@@ -495,6 +524,7 @@ static int clamav_unpack(const char *prog, char **args, const char *tmpdir, cons
495 495
 
496 496
     return 0;
497 497
 }
498
+#endif
498 499
 
499 500
 static void move_infected(const char *filename, const struct optstruct *opt)
500 501
 {
... ...
@@ -610,7 +640,7 @@ static int checkfile(const char *filename, const struct cl_engine *engine, const
610 610
 
611 611
     logg("*Scanning %s\n", filename);
612 612
 
613
-    if((fd = open(filename, O_RDONLY)) == -1) {
613
+    if((fd = open(filename, O_RDONLY|O_BINARY)) == -1) {
614 614
 	logg("^Can't open file %s\n", filename);
615 615
 	return 54;
616 616
     }
... ...
@@ -671,7 +701,8 @@ static int scancompressed(const char *filename, struct cl_engine *engine, const
671 671
 	exit(63); /* critical */
672 672
     }
673 673
 
674
-#ifndef C_OS2
674
+#if !defined(C_OS2) && !defined(C_WINDOWS)
675
+    /* FIXME: do the correct native windows way */
675 676
     if(user)
676 677
 	chown(gendir, user->pw_uid, user->pw_gid);
677 678
 #endif
... ...
@@ -886,7 +917,7 @@ static int scandenied(const char *filename, struct cl_engine *engine, const stru
886 886
 
887 887
     fixperms(gendir);
888 888
 
889
-#ifndef C_OS2
889
+#if !defined(C_OS2) && !defined(C_WINDOWS)
890 890
     if(user) {
891 891
 	chown(gendir, user->pw_uid, user->pw_gid);
892 892
 	chown(tmpfile, user->pw_uid, user->pw_gid);
... ...
@@ -970,12 +1001,14 @@ int scanfile(const char *filename, struct cl_engine *engine, const struct passwd
970 970
 	return 0;
971 971
     }
972 972
 
973
+#ifndef C_WINDOWS
973 974
     if(geteuid())
974 975
 	if(checkaccess(filename, NULL, R_OK) != 1) {
975 976
 	    if(!printinfected)
976 977
 		logg("%s: Access denied\n", filename);
977 978
 	    return 0;
978 979
 	}
980
+#endif
979 981
 
980 982
     info.files++;
981 983
 
... ...
@@ -20,7 +20,13 @@
20 20
 #ifndef __MANAGER_H
21 21
 #define __MANAGER_H
22 22
 
23
+#if HAVE_CONFIG_H
24
+#include "clamav-config.h"
25
+#endif
26
+
27
+#ifdef HAVE_PWD_H
23 28
 #include <pwd.h>
29
+#endif
24 30
 
25 31
 #include "libclamav/clamav.h"
26 32
 #include "shared/options.h"
... ...
@@ -26,13 +26,19 @@
26 26
 #include <stdlib.h>
27 27
 #include <string.h>
28 28
 #include <ctype.h>
29
+#ifdef HAVE_UNISTD_H
29 30
 #include <unistd.h>
31
+#endif
30 32
 #include <errno.h>
33
+#ifdef HAVE_PWD_H
31 34
 #include <pwd.h>
35
+#endif
32 36
 #include <sys/types.h>
33 37
 #include <sys/stat.h>
38
+#ifndef C_WINDOWS
34 39
 #include <sys/wait.h>
35 40
 #include <sys/time.h>
41
+#endif
36 42
 #include <time.h>
37 43
 #include <fcntl.h>
38 44
 #include <signal.h>
... ...
@@ -70,6 +76,13 @@ int fileinfo(const char *filename, short i)
70 70
     }
71 71
 }
72 72
 
73
+#ifdef C_WINDOWS
74
+/* FIXME: Handle users correctly */
75
+int checkaccess(const char *path, const char *username, int mode)
76
+{
77
+    return _access(path, mode);
78
+}
79
+#else
73 80
 int checkaccess(const char *path, const char *username, int mode)
74 81
 {
75 82
 	struct passwd *user;
... ...
@@ -114,6 +127,7 @@ int checkaccess(const char *path, const char *username, int mode)
114 114
 
115 115
     return ret;
116 116
 }
117
+#endif
117 118
 
118 119
 int match_regex(const char *filename, const char *pattern)
119 120
 {
... ...
@@ -24,12 +24,23 @@
24 24
 #include <stdio.h>
25 25
 #include <stdlib.h>
26 26
 #include <string.h>
27
+#ifdef	HAVE_UNISTD_H
27 28
 #include <unistd.h>
29
+#endif
28 30
 #include <sys/stat.h>
29 31
 #include <sys/types.h>
32
+#ifndef C_WINDOWS
30 33
 #include <sys/wait.h>
34
+#endif
35
+#ifdef HAVE_PWD_H
36
+#include <pwd.h>
37
+#endif
38
+#ifdef HAVE_GRP_H
31 39
 #include <grp.h>
40
+#endif
41
+#ifndef C_WINDOWS
32 42
 #include <dirent.h>
43
+#endif
33 44
 #include <errno.h>
34 45
 
35 46
 #include "global.h"
... ...
@@ -99,7 +110,7 @@ int treewalk(const char *dirname, struct cl_engine *engine, const struct passwd
99 99
 
100 100
     if((dd = opendir(dirname)) != NULL) {
101 101
 	while((dent = readdir(dd))) {
102
-#ifndef C_INTERIX
102
+#if !defined(C_INTERIX) && !defined(C_WINDOWS) && !defined(C_CYGWIN)
103 103
 	    if(dent->d_ino)
104 104
 #endif
105 105
 	    {
... ...
@@ -138,6 +149,12 @@ int treewalk(const char *dirname, struct cl_engine *engine, const struct passwd
138 138
 
139 139
 }
140 140
 
141
+#ifdef C_WINDOWS
142
+int clamav_rmdirs(const char *dir)
143
+{
144
+    return cli_rmdirs(dir);
145
+}
146
+#else
141 147
 int clamav_rmdirs(const char *dir)
142 148
 {
143 149
 #ifndef C_CYGWIN
... ...
@@ -185,6 +202,7 @@ int clamav_rmdirs(const char *dir)
185 185
 		return -2;
186 186
     }
187 187
 }
188
+#endif
188 189
 
189 190
 int fixperms(const char *dirname)
190 191
 {
... ...
@@ -196,7 +214,7 @@ int fixperms(const char *dirname)
196 196
 
197 197
     if((dd = opendir(dirname)) != NULL) {
198 198
 	while((dent = readdir(dd))) {
199
-#ifndef C_INTERIX
199
+#if !defined(C_INTERIX) && !defined(C_WINDOWS) && !defined(C_CYGWIN)
200 200
 	    if(dent->d_ino)
201 201
 #endif
202 202
 	    {
... ...
@@ -242,7 +260,7 @@ int du(const char *dirname, struct s_du *n)
242 242
 
243 243
     if((dd = opendir(dirname)) != NULL) {
244 244
 	while((dent = readdir(dd))) {
245
-#ifndef C_INTERIX
245
+#if !defined(C_INTERIX) && !defined(C_WINDOWS) && !defined(C_CYGWIN)
246 246
 	    if(dent->d_ino)
247 247
 #endif
248 248
 	    {
... ...
@@ -20,7 +20,14 @@
20 20
 #ifndef __TREEWALK_H
21 21
 #define __TREEWALK_H
22 22
 
23
+#if HAVE_CONFIG_H
24
+#include "clamav-config.h"
25
+#endif
26
+
27
+#ifdef HAVE_PWD_H
23 28
 #include <pwd.h>
29
+#endif
30
+
24 31
 #include "libclamav/clamav.h"
25 32
 #include "shared/options.h"
26 33
 
... ...
@@ -19734,7 +19734,9 @@ fi
19734 19734
 
19735 19735
 
19736 19736
 
19737
-for ac_header in stdint.h unistd.h sys/int_types.h dlfcn.h inttypes.h sys/inttypes.h memory.h ndir.h stdlib.h strings.h string.h sys/mman.h sys/param.h sys/stat.h sys/types.h malloc.h poll.h regex.h limits.h sys/filio.h sys/uio.h termios.h iconv.h stdbool.h
19737
+
19738
+
19739
+for ac_header in stdint.h unistd.h sys/int_types.h dlfcn.h inttypes.h sys/inttypes.h memory.h ndir.h stdlib.h strings.h string.h sys/mman.h sys/param.h sys/stat.h sys/types.h malloc.h poll.h regex.h limits.h sys/filio.h sys/uio.h termios.h iconv.h stdbool.h pwd.h grp.h
19738 19740
 do
19739 19741
 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
19740 19742
 if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
... ...
@@ -40,7 +40,7 @@ AC_DEFINE(SCANBUFF, 131072, [scan buffer size])
40 40
 AC_DEFINE(FILEBUFF, 8192,   [file i/o buffer size])
41 41
 
42 42
 AC_HEADER_STDC
43
-AC_CHECK_HEADERS(stdint.h unistd.h sys/int_types.h dlfcn.h inttypes.h sys/inttypes.h memory.h ndir.h stdlib.h strings.h string.h sys/mman.h sys/param.h sys/stat.h sys/types.h malloc.h poll.h regex.h limits.h sys/filio.h sys/uio.h termios.h iconv.h stdbool.h)
43
+AC_CHECK_HEADERS(stdint.h unistd.h sys/int_types.h dlfcn.h inttypes.h sys/inttypes.h memory.h ndir.h stdlib.h strings.h string.h sys/mman.h sys/param.h sys/stat.h sys/types.h malloc.h poll.h regex.h limits.h sys/filio.h sys/uio.h termios.h iconv.h stdbool.h pwd.h grp.h)
44 44
 AC_CHECK_HEADER(syslog.h,AC_DEFINE(USE_SYSLOG,1,[use syslog]),)
45 45
 
46 46
 AC_TYPE_OFF_T