Browse code

minor fixes

git-svn: trunk@475

Tomasz Kojm authored on 2004/04/06 06:42:11
Showing 9 changed files
... ...
@@ -1,3 +1,14 @@
1
+Mon Apr  5 23:49:23 CEST 2004 (tk)
2
+----------------------------------
3
+  * contrib: new init script for SuSE (by Martin Fuxa <yeti*email.cz>)
4
+  * configure: fix linking problem under NetBSD (reported by Nigel);
5
+	       enable support for threads (pth is required and
6
+	       LDFLAGS="-L/usr/pkg/lib" and CPPFLAGS="-I/usr/pkg/include"
7
+	       must be exported). Thanks to Jorgen Norgaard <jnp*anneli.dk>.
8
+  * clamscan: fix --bell behaviour ("one beep" problem reported by Tomasz
9
+	      Papszun)
10
+  * libclamav: small cosmetics
11
+
1 12
 Mon Apr  5 15:39:12 BST 2004 (njh)
2 13
 ----------------------------------
3 14
   * contrib:	Windows client (finally!) open sourced
... ...
@@ -1,4 +1,4 @@
1
-# aclocal.m4t generated automatically by aclocal 1.6.1 -*- Autoconf -*-
1
+# aclocal.m4 generated automatically by aclocal 1.6.1 -*- Autoconf -*-
2 2
 
3 3
 # Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
4 4
 # Free Software Foundation, Inc.
... ...
@@ -81,7 +81,7 @@ dnl there is now a CREATE_PREFIX_TARGET_H in this file as a shorthand for
81 81
 dnl PREFIX_CONFIG_H from a target.h file, however w/o the target.h ever created
82 82
 dnl (the prefix is a bit different, since we add an extra -target- and -host-)
83 83
 dnl 
84
-dnl @version: $Id: aclocal.m4,v 1.30 2004/03/29 00:00:57 kojm Exp $
84
+dnl @version: $Id: aclocal.m4,v 1.31 2004/04/05 21:42:10 kojm Exp $
85 85
 dnl @author Guido Draheim <guidod@gmx.de>                 STATUS: used often
86 86
 
87 87
 AC_DEFUN([AC_CREATE_TARGET_H],
... ...
@@ -4041,7 +4041,7 @@ dnl      AC_COMPILE_CHECK_SIZEOF(ptrdiff_t, $headers)
4041 4041
 dnl      AC_COMPILE_CHECK_SIZEOF(off_t, $headers)
4042 4042
 dnl
4043 4043
 dnl @author Kaveh Ghazi <ghazi@caip.rutgers.edu>
4044
-dnl @version $Id: aclocal.m4,v 1.30 2004/03/29 00:00:57 kojm Exp $
4044
+dnl @version $Id: aclocal.m4,v 1.31 2004/04/05 21:42:10 kojm Exp $
4045 4045
 dnl
4046 4046
 AC_DEFUN([AC_COMPILE_CHECK_SIZEOF],
4047 4047
 [changequote(<<, >>)dnl
... ...
@@ -651,7 +651,7 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass
651 651
 	    mprintf("%s: Infected Archive FOUND\n", filename);
652 652
 
653 653
 	    if(bell)
654
-		printf("\007");
654
+		fprintf(stderr, "\007");
655 655
 
656 656
 	    if(optl(opt, "remove")) {
657 657
 		if(unlink(filename)) {
... ...
@@ -780,7 +780,7 @@ int checkfile(const char *filename, const struct cl_node *root, const struct cl_
780 780
 	claminfo.ifiles++;
781 781
 
782 782
 	if(bell)
783
-	    printf("\007");
783
+	    fprintf(stderr, "\007");
784 784
 
785 785
     } else if(ret == CL_CLEAN) {
786 786
 	if(!printinfected)
... ...
@@ -806,7 +806,7 @@ int checkstdin(const struct cl_node *root, const struct cl_limits *limits)
806 806
 	claminfo.ifiles++;
807 807
 
808 808
 	if(bell)
809
-	    printf("\007");
809
+	    fprintf(stderr, "\007");
810 810
 
811 811
     } else if(ret == CL_CLEAN) {
812 812
 	if(!printinfected)
... ...
@@ -9573,6 +9573,7 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
9573 9573
   echo "$as_me:$LINENO: result: -lwrap" >&5
9574 9574
 echo "${ECHO_T}-lwrap" >&6
9575 9575
                 have_wrappers=yes
9576
+		LIBS="$save_LIBS"
9576 9577
                 CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lwrap"
9577 9578
 else
9578 9579
   echo "$as_me: failed program was:" >&5
... ...
@@ -9819,11 +9820,13 @@ openbsd3.3*)
9819 9819
 	CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -pthread"
9820 9820
 	fi
9821 9821
 	TH_SAFE="-thread-safe"
9822
-	cat >>confdefs.h <<\_ACEOF
9822
+
9823
+cat >>confdefs.h <<\_ACEOF
9823 9824
 #define CL_THREAD_SAFE 1
9824 9825
 _ACEOF
9825 9826
 
9826
-	cat >>confdefs.h <<\_ACEOF
9827
+
9828
+cat >>confdefs.h <<\_ACEOF
9827 9829
 #define _REENTRANT 1
9828 9830
 _ACEOF
9829 9831
 
... ...
@@ -9863,9 +9866,21 @@ _ACEOF
9863 9863
 
9864 9864
     ;;
9865 9865
 netbsd*)
9866
-    echo "$as_me:$LINENO: result: NetBSD detected. Disabling thread support." >&5
9867
-echo "${ECHO_T}NetBSD detected. Disabling thread support." >&6
9868
-    have_pthreads="no"
9866
+     if test "$have_pthreads" = "yes"; then
9867
+ 	LIBCLAMAV_LIBS="$LIBCLAMAV_LIBS -lpthread"
9868
+ 	CLAMD_LIBS="-lpthread"
9869
+ 	CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lpthread"
9870
+
9871
+cat >>confdefs.h <<\_ACEOF
9872
+#define CL_THREAD_SAFE 1
9873
+_ACEOF
9874
+
9875
+
9876
+cat >>confdefs.h <<\_ACEOF
9877
+#define _REENTRANT 1
9878
+_ACEOF
9879
+
9880
+     fi
9869 9881
 
9870 9882
 cat >>confdefs.h <<\_ACEOF
9871 9883
 #define C_BSD 1
... ...
@@ -245,6 +245,7 @@ struct request_info *req;
245 245
 hosts_access(req)
246 246
                 ],[AC_MSG_RESULT([-lwrap])
247 247
                 have_wrappers=yes
248
+		LIBS="$save_LIBS"
248 249
                 CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lwrap"],[
249 250
                 dnl try with -lnsl
250 251
                 LIBS="$LIBS -lnsl"
... ...
@@ -350,8 +351,8 @@ openbsd3.3*)
350 350
 	CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -pthread"
351 351
 	fi
352 352
 	TH_SAFE="-thread-safe"
353
-	AC_DEFINE(CL_THREAD_SAFE)
354
-	AC_DEFINE(_REENTRANT)
353
+	AC_DEFINE(CL_THREAD_SAFE,1,[thread safe])
354
+	AC_DEFINE(_REENTRANT,1,[thread safe])
355 355
     fi
356 356
     AC_DEFINE(C_BSD,1,[os is bsd flavor])
357 357
     ;;
... ...
@@ -372,8 +373,13 @@ openbsd*)
372 372
     AC_DEFINE(C_BSD,1,[os is bsd flavor])
373 373
     ;;
374 374
 netbsd*)
375
-    AC_MSG_RESULT(NetBSD detected. Disabling thread support.)
376
-    have_pthreads="no"
375
+     if test "$have_pthreads" = "yes"; then
376
+ 	LIBCLAMAV_LIBS="$LIBCLAMAV_LIBS -lpthread"
377
+ 	CLAMD_LIBS="-lpthread"
378
+ 	CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lpthread"
379
+	AC_DEFINE(CL_THREAD_SAFE,1,[thread safe])
380
+	AC_DEFINE(_REENTRANT,1,[thread safe])
381
+     fi
377 382
     AC_DEFINE(C_BSD,1,[os is bsd flavor])
378 383
     ;;
379 384
 bsd*)
... ...
@@ -1,8 +1,6 @@
1 1
 #! /bin/sh
2
-
3
-# -- ntw2007:/etc/init.d/clamd, 17.06.2003 shw --
4
-
5
-
2
+# v1.1 03-2004, martin fuxa, yeti@email.cz
3
+#
6 4
 ### BEGIN INIT INFO
7 5
 # Provides:       clamd
8 6
 # Required-Start: 
... ...
@@ -12,85 +10,57 @@
12 12
 # Description:    Control clamav daemon.
13 13
 ### END INIT INFO
14 14
 
15
+# Variables
16
+PID="/var/run/clamd.pid"
17
+SBIN="/usr/local/sbin/clamd"
18
+CONF="/etc/clamav.conf"
19
+WHAT="Clam AntiVirus"
15 20
 
16
-# -- variables --
17
-_what="Clam AntiVirus"
18
-
19
-# -- see whether we are installed --
20
-_cnf="/etc/clamav.conf"
21
-
22
-_pid="$(awk '/^PidFile/ {print $2}' ${_cnf})"
23
-_port="$(awk '/^TCPSocket/ {print $2}' ${_cnf})"
24
-
25
-if [ -s "${_cnf}" -a -r "${_cnf}" ]
26
-   then
27
-      _srv="$(\which clamd | sed -e 's+/*+/+' | head -1)"
28
-      test -x "${_srv}" || exit 5
29
-
30
-      _clnt="$(\which clamdscan | sed -e 's+/*+/+' | head -1)"
31
-      test -x "${_clnt}" || exit 5
21
+# Source SuSE config
22
+. /etc/rc.status
32 23
 
33
-      _cnf="-c ${_cnf}"
34
-   else
35
-      exit 6
36
-fi
24
+test -x $SBIN || exit 5
25
+test -e $CONF || exit 5
37 26
 
38
-
39
-# -- fetch LSB compliant functions (hope they get our environment) --
40
-. /lib/lsb/init-functions
41
-
42
-
43
-# -- first reset status of this service --
27
+# First reset status of this service
44 28
 rc_reset
45 29
 
46
-
47
-# -- process request --
48
-case "${1}" in
49
-   start)
50
-      echo -n "Starting ${_what} ${_cnf}."
51
-
52
-      "${_srv}" "${_cfg}"
53
-
54
-      rc_status -v
55
-   ;;
56
-   stop)
57
-      echo -n "Shutting down ${_what}: "
58
-
59
-      "${_clnt}" +QUIT
60
-
61
-      rc_status -v
62
-   ;;
63
-   try-restart)
64
-      ${0} status 1>/dev/null && ${0} restart
65
-
66
-      rc_status
67
-   ;;
68
-   restart)
69
-      ${0} stop; sleep 3
70
-
71
-      ${0} start
72
-
73
-      rc_status
74
-   ;;
75
-   status)
76
-      echo -n "Checking ${_what}: "
77
-
78
-      "${_clnt}" +VERSION
79
-
80
-      rc_status -v
81
-
82
-      test -s "${_pid}" && echo "ProcessID claims to be: $(cat ${_pid})."
83
-   ;;
84
-   *)
85
-      (echo; echo "Usage: ${0} {start|stop|status|try-restart|restart}") 2>&1
86
-
87
-      exit 1
88
-   ;;
30
+# Process request
31
+case "$1" in
32
+    start)
33
+        echo -n "Starting ${WHAT} ${CONF} "
34
+        ## Start daemon with startproc(8). If this fails
35
+        ## the echo return value is set appropriate.
36
+        startproc $SBIN $CONF
37
+        # Remember status and be verbose
38
+        rc_status -v
39
+    ;;
40
+    stop)
41
+        echo -n "Shutting down ${WHAT} "
42
+        ## Stop daemon with killproc(8) and if this fails
43
+        ## set echo the echo return value.
44
+        killproc -TERM $SBIN
45
+        # Remember status and be verbose
46
+        rc_status -v
47
+    ;;
48
+    restart)
49
+        ## Stop the service and regardless of whether it was
50
+        ## running or not, start it again.
51
+        $0 stop
52
+        $0 start
53
+        # Remember status and be quiet
54
+        rc_status
55
+    ;;
56
+    status)
57
+        echo -n "Checking for ${WHAT} "
58
+        checkproc $SBIN
59
+        rc_status -v
60
+    ;;
61
+
62
+    *)
63
+        echo "Usage: $0 {start|stop|status|restart}"
64
+        exit 1
65
+    ;;
89 66
 esac
90
-
91
-
92
-# -- inform caller --
93 67
 rc_exit
94
-
95
-
96
-# -- end of clamd --
68
+### END
... ...
@@ -4,7 +4,7 @@
4 4
  *  http://www-sr.informatik.uni-tuebingen.de/~buehler/AC/AC.html
5 5
  *  Thanks to Kurt Huwig for pointing me to this page.
6 6
  *
7
- *  Copyright (C) 2002 Tomasz Kojm <zolw@konarski.edu.pl>
7
+ *  Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net>
8 8
  *
9 9
  *  This program is free software; you can redistribute it and/or modify
10 10
  *  it under the terms of the GNU General Public License as published by
... ...
@@ -193,23 +193,19 @@ void cl_freetrie(struct cl_node *root)
193 193
     free(root);
194 194
 }
195 195
 
196
-int cli_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cl_node *root, int *pcnt)
196
+int cli_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cl_node *root, int *partcnt)
197 197
 {
198 198
 	struct cl_node *current;
199 199
 	struct cli_patt *pt;
200
-	int position, *partcnt, extpartcnt = 0;
200
+	int position;
201 201
         unsigned int i;
202 202
 
203
+
203 204
     current = (struct cl_node *) root;
204 205
 
205
-    if(pcnt) {
206
-	partcnt = pcnt;
207
-	extpartcnt = 1;
208
-    } else {
209
-	if((partcnt = (int *) cli_calloc(root->partsigs + 1, sizeof(int))) == NULL) {
210
-	    cli_dbgmsg("cl_scanbuff(): unable to calloc(%d, %d)\n", root->partsigs + 1, sizeof(int));
211
-	    return CL_EMEM;
212
-	}
206
+    if(!partcnt) {
207
+	cli_dbgmsg("cli_scanbuff(): partcnt == NULL\n");
208
+	return CL_EMEM;
213 209
     }
214 210
 
215 211
     for(i = 0; i < length; i++)  {
... ...
@@ -223,19 +219,15 @@ int cli_scanbuff(const char *buffer, unsigned int length, const char **virname,
223 223
 		if(cli_findpos(buffer, position, length, pt)) {
224 224
 		    if(pt->sigid) { /* it's a partial signature */
225 225
 			if(partcnt[pt->sigid] + 1 == pt->partno) {
226
-			    if(++partcnt[pt->sigid] == pt->parts) { /* last */
226
+			    if(++partcnt[pt->sigid] == pt->parts) { /* the last one */
227 227
 				if(virname)
228 228
 				    *virname = pt->virname;
229
-				if(!extpartcnt)
230
-				    free(partcnt);
231 229
 				return CL_VIRUS;
232 230
 			    }
233 231
 			}
234 232
 		    } else { /* old type signature */
235 233
 			if(virname)
236 234
 			    *virname = pt->virname;
237
-			if(!extpartcnt)
238
-			    free(partcnt);
239 235
 			return CL_VIRUS;
240 236
 		    }
241 237
 		}
... ...
@@ -247,15 +239,23 @@ int cli_scanbuff(const char *buffer, unsigned int length, const char **virname,
247 247
 	}
248 248
     }
249 249
 
250
-    if(!extpartcnt)
251
-	free(partcnt);
252 250
     return CL_CLEAN;
253 251
 }
254 252
 
255 253
 int cl_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cl_node *root)
256 254
 
257 255
 {
258
-    return cli_scanbuff(buffer, length, virname, root, NULL);
256
+	int ret, *partcnt;
257
+
258
+    if((partcnt = (int *) cli_calloc(root->partsigs + 1, sizeof(int))) == NULL) {
259
+	cli_dbgmsg("cli_scanbuff(): unable to cli_calloc(%d, %d)\n", root->partsigs + 1, sizeof(int));
260
+	return CL_EMEM;
261
+    }
262
+
263
+    ret = cli_scanbuff(buffer, length, virname, root, partcnt);
264
+
265
+    free(partcnt);
266
+    return ret;
259 267
 }
260 268
 
261 269
 int cli_findpos(const char *buffer, int offset, int length, const struct cli_patt *pattern)
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 2002 Tomasz Kojm <zolw@konarski.edu.pl>
2
+ *  Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net>
3 3
  *
4 4
  *  This program is free software; you can redistribute it and/or modify
5 5
  *  it under the terms of the GNU General Public License as published by
... ...
@@ -31,6 +31,6 @@ struct nodelist *cli_bfsadd(struct nodelist *bfs, struct cl_node *n);
31 31
 void cli_failtrans(struct cl_node *root);
32 32
 void cli_fasttrie(struct cl_node *n, struct cl_node *root);
33 33
 int cli_findpos(const char *buffer, int offset, int length, const struct cli_patt *pattern);
34
-int cli_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cl_node *root, int *pcnt);
34
+int cli_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cl_node *root, int *partcnt);
35 35
 
36 36
 #endif
... ...
@@ -118,12 +118,12 @@ cl_node *root)
118 118
     /* prepare the buffer */
119 119
     buffsize = root->maxpatlen + SCANBUFF;
120 120
     if(!(buffer = (char *) cli_calloc(buffsize, sizeof(char)))) {
121
-	cli_dbgmsg("cli_scandesc(): unable to malloc(%d)\n", buffsize);
121
+	cli_dbgmsg("cli_scandesc(): unable to cli_malloc(%d)\n", buffsize);
122 122
 	return CL_EMEM;
123 123
     }
124 124
 
125 125
     if((partcnt = (int *) cli_calloc(root->partsigs + 1, sizeof(int))) == NULL) {
126
-	cli_dbgmsg("cl_scandesc(): unable to calloc(%d, %d)\n", root->partsigs + 1, sizeof(int));
126
+	cli_dbgmsg("cli_scandesc(): unable to cli_calloc(%d, %d)\n", root->partsigs + 1, sizeof(int));
127 127
 	free(buffer);
128 128
 	return CL_EMEM;
129 129
     }