Browse code

improved OS/2 support

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@1205 77e5149b-7576-45b1-b177-96237e5ba77b

Tomasz Kojm authored on 2004/12/20 10:37:36
Showing 15 changed files
... ...
@@ -87,6 +87,7 @@ Tom G. Christensen <tgc*statsbiblioteket.dk>
87 87
 Eugene Crosser <crosser*rol.ru>
88 88
 Damien Curtain <damien*pagefault.org>
89 89
 Michael Dankov <misha*btrc.ru>
90
+Yuri Dario <mc6530*mclink.it>
90 91
 David <djgardner*users.sourceforge.net>
91 92
 Maxim Dounin <mdounin*rambler-co.ru>
92 93
 Alejandro Dubrovsky <s328940*student.uq.edu.au>
... ...
@@ -1,3 +1,7 @@
1
+Mon Dec 20 02:32:30 CET 2004 (tk)
2
+---------------------------------
3
+  * improved OS/2 support (thanks to Yuri Dario <mc6530*mclink.it>)
4
+
1 5
 Sun Dec 19 17:01:56 GMT 2004 (njh)
2 6
 ----------------------------------
3 7
   * clamav-milter: Correctly warn that --max_childen must be given in SESSION
... ...
@@ -57,6 +57,9 @@
57 57
 /* target is linux */
58 58
 #undef C_LINUX
59 59
 
60
+/* os is OS/2 */
61
+#undef C_OS2
62
+
60 63
 /* os is solaris */
61 64
 #undef C_SOLARIS
62 65
 
... ...
@@ -136,7 +136,7 @@ void clamd(struct optstruct *opt)
136 136
 
137 137
     if((cpt = cfgopt(copt, "LogFile"))) {
138 138
 	logg_file = cpt->strarg;
139
-	if(logg_file[0] != '/') {
139
+	if(strlen(logg_file) < 2 || (logg_file[0] != '/' && logg_file[0] != '\\' && logg_file[1] != ':')) {
140 140
 	    fprintf(stderr, "ERROR: LogFile requires full path.\n");
141 141
 	    exit(1);
142 142
 	}
... ...
@@ -274,12 +274,10 @@ void clamd(struct optstruct *opt)
274 274
 	exit(1);
275 275
     }
276 276
 
277
-
278 277
     /* fork into background */
279 278
     if(!cfgopt(copt, "Foreground"))
280 279
 	daemonize();
281 280
 
282
-
283 281
     if(tcpsock)
284 282
 	ret = tcpserver(opt, copt, root);
285 283
     else
... ...
@@ -312,6 +310,10 @@ void daemonize(void)
312 312
 	int i;
313 313
 
314 314
 
315
+#ifdef C_OS2
316
+    return;
317
+#else
318
+
315 319
     if((i = open("/dev/null", O_WRONLY)) == -1) {
316 320
 	logg("!Cannot open /dev/null. Only use Debug if Foreground is enabled.\n");
317 321
 	for(i = 0; i <= 2; i++)
... ...
@@ -330,4 +332,5 @@ void daemonize(void)
330 330
 	exit(0);
331 331
 
332 332
     setsid();
333
+#endif
333 334
 }
... ...
@@ -562,12 +562,15 @@ int acceptloop_th(int socketd, struct cl_node *root, const struct cfgstruct *cop
562 562
     shutdown(socketd, 2);
563 563
     logg("*Closing the main socket.\n");
564 564
     close(socketd);
565
+
566
+#ifndef C_OS2
565 567
     if((cpt = cfgopt(copt, "LocalSocket"))) {
566 568
 	if(unlink(cpt->strarg) == -1)
567 569
 	    logg("!Can't unlink the socket file %s\n", cpt->strarg);
568 570
 	else
569 571
 	     logg("Socket file removed.\n");
570
-	}
572
+    }
573
+#endif
571 574
 
572 575
     if((cpt = cfgopt(copt, "PidFile"))) {
573 576
 	if(unlink(cpt->strarg) == -1)
... ...
@@ -312,6 +312,9 @@ int dconnect(const struct optstruct *opt)
312 312
 	return -1;
313 313
     }
314 314
 
315
+    memset((char *) &server, 0, sizeof(server));
316
+    memset((char *) &server2, 0, sizeof(server2));
317
+
315 318
     /* Set default address to connect to */
316 319
     server2.sin_addr.s_addr = inet_addr("127.0.0.1");    
317 320
 
... ...
@@ -435,7 +438,7 @@ int client(const struct optstruct *opt, int *infected)
435 435
 		perror(fullpath);
436 436
 		errors++;
437 437
 	    } else {
438
-		if(fullpath[0] != '/') {
438
+		if(strlen(fullpath) < 2 || (fullpath[0] != '/' && fullpath[0] != '\\' && fullpath[1] != ':')) {
439 439
 		    fullpath = abpath(thefilename);
440 440
 		    free(thefilename);
441 441
 
... ...
@@ -231,7 +231,7 @@ int scanmanager(const struct optstruct *opt)
231 231
 	    } else {
232 232
 		fmode = (mode_t) fmodeint;
233 233
 
234
-		if(compression && (thefilename[0] != '/')) {
234
+		if(compression && (strlen(thefilename) < 2 || (thefilename[0] != '/' && thefilename[0] != '\\' && thefilename[1] != ':'))) {
235 235
 		    /* we need to complete the path */
236 236
 		    if(!getcwd(cwd, sizeof(cwd))) {
237 237
 			mprintf("@Can't get absolute pathname of current working directory.\n");
... ...
@@ -263,7 +263,7 @@ int scanmanager(const struct optstruct *opt)
263 263
 			ret = 52;
264 264
 		}
265 265
 
266
-		if(compression && thefilename[0] != '/') {
266
+		if(compression && (strlen(thefilename) < 2 || (thefilename[0] != '/' && thefilename[0] != '\\' && thefilename[1] != ':'))) {
267 267
 		    free(fullpath);
268 268
 		    fullpath = NULL;
269 269
 		}
... ...
@@ -291,7 +291,7 @@ int match_regex(const char *filename, const char *pattern)
291 291
 #ifdef HAVE_REGEX_H
292 292
 	regex_t reg;
293 293
 	int match, flags;
294
-#ifndef C_CYGWIN
294
+#if !defined(C_CYGWIN) && !defined(C_OS2)
295 295
 	flags = 0;
296 296
 #else
297 297
 	flags = REG_ICASE; /* case insensitive on Windows */
... ...
@@ -500,9 +500,10 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass
500 500
 	exit(63); /* critical */
501 501
     }
502 502
 
503
+#ifndef C_OS2
503 504
     if(user)
504 505
 	chown(gendir, user->pw_uid, user->pw_gid);
505
-
506
+#endif
506 507
 
507 508
     /* unpack file  - as unprivileged user */
508 509
     if(cli_strbcasestr(filename, ".zip")) {
... ...
@@ -722,10 +723,12 @@ int scandenied(const char *filename, struct cl_node *root, const struct passwd *
722 722
 
723 723
     fixperms(gendir);
724 724
 
725
+#ifndef C_OS2
725 726
     if(user) {
726 727
 	chown(gendir, user->pw_uid, user->pw_gid);
727 728
 	chown(tmpfile, user->pw_uid, user->pw_gid);
728 729
     }
730
+#endif
729 731
 
730 732
     if((ret = treewalk(gendir, root, user, opt, limits, options)) == 1) {
731 733
 	logg("(Real infected archive: %s)\n", filename);
... ...
@@ -1045,7 +1048,9 @@ void move_infected(const char *filename, const struct optstruct *opt)
1045 1045
 	}
1046 1046
 
1047 1047
 	chmod(movefilename, fstat.st_mode);
1048
+#ifndef C_OS2
1048 1049
 	chown(movefilename, fstat.st_uid, fstat.st_gid);
1050
+#endif
1049 1051
 
1050 1052
 	ubuf.actime = fstat.st_atime;
1051 1053
 	ubuf.modtime = fstat.st_mtime;
... ...
@@ -11764,6 +11764,32 @@ _ACEOF
11764 11764
     use_netinfo="yes"
11765 11765
     disable_gethostbyname_r="yes"
11766 11766
     ;;
11767
+os2*)
11768
+    FRESHCLAM_LIBS="$FRESHCLAM_LIBS -lsyslog"
11769
+    CLAMD_LIBS="$CLAMD_LIBS -lsyslog"
11770
+    CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lsyslog"
11771
+    if test "$have_pthreads" = "yes"; then
11772
+	LIBCLAMAV_LIBS="$LIBCLAMAV_LIBS -lpthread"
11773
+	CLAMD_LIBS="$CLAMD_LIBS -lpthread"
11774
+	CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lpthread"
11775
+	TH_SAFE="-thread-safe"
11776
+
11777
+cat >>confdefs.h <<\_ACEOF
11778
+#define CL_THREAD_SAFE 1
11779
+_ACEOF
11780
+
11781
+
11782
+cat >>confdefs.h <<\_ACEOF
11783
+#define _REENTRANT 1
11784
+_ACEOF
11785
+
11786
+    fi
11787
+
11788
+cat >>confdefs.h <<\_ACEOF
11789
+#define C_OS2 1
11790
+_ACEOF
11791
+
11792
+    ;;
11767 11793
 sco*)
11768 11794
                     ;;
11769 11795
 hpux*)
... ...
@@ -432,6 +432,20 @@ darwin*)
432 432
     use_netinfo="yes"
433 433
     disable_gethostbyname_r="yes"
434 434
     ;;
435
+os2*)
436
+    FRESHCLAM_LIBS="$FRESHCLAM_LIBS -lsyslog"
437
+    CLAMD_LIBS="$CLAMD_LIBS -lsyslog"
438
+    CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lsyslog"
439
+    if test "$have_pthreads" = "yes"; then
440
+	LIBCLAMAV_LIBS="$LIBCLAMAV_LIBS -lpthread"
441
+	CLAMD_LIBS="$CLAMD_LIBS -lpthread"
442
+	CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lpthread"
443
+	TH_SAFE="-thread-safe"
444
+	AC_DEFINE(CL_THREAD_SAFE,1,[thread safe])
445
+	AC_DEFINE(_REENTRANT,1,[thread safe])
446
+    fi
447
+    AC_DEFINE(C_OS2,1,[os is OS/2])
448
+    ;;
435 449
 sco*)
436 450
     dnl njh@bandsman.sco.uk: SCO Unix port
437 451
     dnl FRESHCLAM_LIBS="-lsocket"
... ...
@@ -571,7 +571,7 @@ int get_database(const char *dbfile, int socketfd, const char *file, const char
571 571
         }
572 572
     }
573 573
 
574
-#ifdef C_CYGWIN
574
+#if defined(C_CYGWIN) || defined(C_OS2)
575 575
     if((fd = open(file, O_WRONLY|O_CREAT|O_EXCL|O_BINARY, 0644)) == -1) {
576 576
 #else
577 577
     if((fd = open(file, O_WRONLY|O_CREAT|O_EXCL, 0644)) == -1) {
... ...
@@ -151,6 +151,7 @@ struct cl_stat {
151 151
     char *dir;
152 152
     int no;
153 153
     struct stat *stattab;
154
+    char **statdname;
154 155
 };
155 156
 
156 157
 struct cl_cvd {
... ...
@@ -598,7 +598,7 @@ static int handler_writefile(int fd, ole2_header_t *hdr, property_t *prop, const
598 598
 #ifdef  C_DARWIN
599 599
                         *newname &= '\177';
600 600
 #endif
601
-#if     defined(MSDOS) || defined(C_CYGWIN) || defined(WIN32)
601
+#if     defined(MSDOS) || defined(C_CYGWIN) || defined(WIN32) || defined(C_OS2)
602 602
                         if(strchr("/*?<>|\"+=,;: ", *newname))
603 603
 #else
604 604
                         if(*newname == '/')
... ...
@@ -826,6 +826,7 @@ int cl_statinidir(const char *dirname, struct cl_stat *dbstat)
826 826
     if(dbstat) {
827 827
 	dbstat->no = 0;
828 828
 	dbstat->stattab = NULL;
829
+	dbstat->statdname = NULL;
829 830
 	dbstat->dir = strdup(dirname);
830 831
     } else {
831 832
         cli_errmsg("cl_statdbdir(): Null argument passed.\n");
... ...
@@ -860,8 +861,16 @@ int cl_statinidir(const char *dirname, struct cl_stat *dbstat)
860 860
 
861 861
 		dbstat->no++;
862 862
 		dbstat->stattab = (struct stat *) realloc(dbstat->stattab, dbstat->no * sizeof(struct stat));
863
+#if defined(CL_INTERIX) || defined(CL_OS2)
864
+		dbstat->statdname = (char **) realloc(dbstat->statdname, dbstat->no * sizeof(char *));
865
+#endif
866
+
863 867
                 fname = cli_calloc(strlen(dirname) + strlen(dent->d_name) + 2, sizeof(char));
864 868
 		sprintf(fname, "%s/%s", dirname, dent->d_name);
869
+#if defined(CL_INTERIX) || defined(CL_OS2)
870
+		dbstat->statdname[dbstat->no - 1] = (char *) calloc(strlen(dent->d_name) + 1, sizeof(char));
871
+		strcpy(dbstat->statdname[dbstat->no - 1], dent->d_name);
872
+#endif
865 873
 		stat(fname, &dbstat->stattab[dbstat->no - 1]);
866 874
 		free(fname);
867 875
 	    }
... ...
@@ -925,7 +934,11 @@ int cl_statchkdir(const struct cl_stat *dbstat)
925 925
 
926 926
 		found = 0;
927 927
 		for(i = 0; i < dbstat->no; i++)
928
+#if defined(CL_INTERIX) || defined(CL_OS2)
929
+		    if(!strcmp(dbstat->statdname[i], dent->d_name)) {
930
+#else
928 931
 		    if(dbstat->stattab[i].st_ino == sb.st_ino) {
932
+#endif
929 933
 			found = 1;
930 934
 			if(dbstat->stattab[i].st_mtime != sb.st_mtime) {
931 935
 			    closedir(dd);
... ...
@@ -949,6 +962,18 @@ int cl_statfree(struct cl_stat *dbstat)
949 949
 {
950 950
 
951 951
     if(dbstat) {
952
+
953
+#if defined(CL_INTERIX) || defined(CL_OS2)
954
+	    int i;
955
+
956
+	for(i = 0;i < dbstat->no; i++) {
957
+	    free(dbstat->statdname[i]);
958
+	    dbstat->statdname[i] = NULL;
959
+	}
960
+	free(dbstat->statdname);
961
+	dbstat->statdname = NULL;
962
+#endif
963
+
952 964
 	free(dbstat->stattab);
953 965
 	dbstat->stattab = NULL;
954 966
 	dbstat->no = 0;
... ...
@@ -16,6 +16,10 @@
16 16
  * you need to add an include path to the dir containing (!!) the ./zzip/ dir
17 17
  */
18 18
 
19
+#if HAVE_CONFIG_H
20
+#include "clamav-config.h"
21
+#endif
22
+
19 23
 #ifndef _ZZIP_ZZIP_H /* zziplib.h */
20 24
 #define _ZZIP_ZZIP_H
21 25
 
... ...
@@ -25,6 +29,10 @@
25 25
 #include <stddef.h> /* size_t and friends */
26 26
 /* msvc6 has neither ssize_t (we assume "int") nor off_t (assume "long") */
27 27
 
28
+#ifdef CL_OS2
29
+#include <types.h>
30
+#endif
31
+
28 32
 #ifdef __cplusplus
29 33
 extern "C" {
30 34
 #endif
... ...
@@ -1,4 +1,4 @@
1
-# Makefile.in generated by automake 1.8.4 from Makefile.am.
1
+# Makefile.in generated by automake 1.8.5 from Makefile.am.
2 2
 # @configure_input@
3 3
 
4 4
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
... ...
@@ -472,7 +472,7 @@ TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
472 472
 	  $(AWK) '    { files[$$0] = 1; } \
473 473
 	       END { for (i in files) print i; }'`; \
474 474
 	if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
475
-	  test -z "$$unique" && unique=$$empty_fix; \
475
+	  test -n "$$unique" || unique=$$empty_fix; \
476 476
 	  $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
477 477
 	    $$tags $$unique; \
478 478
 	fi