Browse code

Attempt to fix bug 332

git-svn: trunk@2827

Nigel Horne authored on 2007/02/22 06:05:55
Showing 1 changed files
... ...
@@ -2,7 +2,7 @@
2 2
  * clamav-milter.c
3 3
  *	.../clamav-milter/clamav-milter.c
4 4
  *
5
- *  Copyright (C) 2003- Nigel Horne <njh@bandsman.co.uk>
5
+ *  Copyright (C) 2003-2007 Nigel Horne <njh@bandsman.co.uk>
6 6
  *
7 7
  *  This program is free software; you can redistribute it and/or modify
8 8
  *  it under the terms of the GNU General Public License as published by
... ...
@@ -23,10 +23,17 @@
23 23
  * See http://www.elandsys.com/resources/sendmail/libmilter/overview.html
24 24
  *
25 25
  * For installation instructions see the file INSTALL that came with this file
26
+ *
27
+ * NOTE: first character of strings to logg():
28
+ *	! Error
29
+ *	^ Warning
30
+ *	* Verbose
31
+ *	# Info, but not logged in foreground
32
+ *	Default Info
26 33
  */
27 34
 static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.312 2007/02/12 22:24:21 njh Exp $";
28 35
 
29
-#define	CM_VERSION	"devel-120207"
36
+#define	CM_VERSION	"devel-210207"
30 37
 
31 38
 #if HAVE_CONFIG_H
32 39
 #include "clamav-config.h"
... ...
@@ -51,7 +58,6 @@ static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.312 2007/02/12 22:24:21 nj
51 51
 #ifdef	HAVE_SYS_STAT_H
52 52
 #include <sys/stat.h>
53 53
 #endif
54
-#include <syslog.h>
55 54
 #if	HAVE_STDLIB_H
56 55
 #include <stdlib.h>
57 56
 #endif
... ...
@@ -123,8 +129,11 @@ static	char	const	rcsid[] = "$Id: clamav-milter.c,v 1.312 2007/02/12 22:24:21 nj
123 123
 #include <tcpd.h>
124 124
 #endif
125 125
 
126
+#ifdef	USE_SYSLOG
127
+#include <syslog.h>
126 128
 int	allow_severity = LOG_DEBUG;
127 129
 int	deny_severity = LOG_NOTICE;
130
+#endif
128 131
 
129 132
 #endif
130 133
 
... ...
@@ -435,17 +444,7 @@ static	int	detect_forged_local_address;	/*
435 435
 				 * claiming to be from us that must be false
436 436
 				 * Requires that -o, -l or -f are NOT given
437 437
 				 */
438
-static	short	use_syslog = 0;
439
-				/*
440
-				 * NOTE: first character of strings to logg():
441
-				 *	! Error
442
-				 *	^ Warning
443
-				 *	* Verbose
444
-				 *	# Info, but not logged in foreground
445
-				 *	Default Info
446
-				 */
447 438
 static	const	char	*pidFile;
448
-static	int	logVerbose = 0;
449 439
 static	struct	cfgstruct	*copt;
450 440
 static	const	char	*localSocket;	/* milter->clamd comms */
451 441
 static	in_port_t	tcpSocket;	/* milter->clamd comms */
... ...
@@ -545,7 +544,7 @@ static void
545 545
 help(void)
546 546
 {
547 547
 	printf("\n\tclamav-milter version %s\n", CM_VERSION);
548
-	puts("\tCopyright (C) 2006 Nigel Horne <njh@clamav.net>\n");
548
+	puts("\tCopyright (C) 2007 Nigel Horne <njh@clamav.net>\n");
549 549
 
550 550
 	puts(_("\t--advisory\t\t-A\tFlag viruses rather than deleting them."));
551 551
 	puts(_("\t--blacklist=time\t-k\tTime (in seconds) to blacklist an IP."));
... ...
@@ -608,6 +607,7 @@ main(int argc, char **argv)
608 608
 #ifndef	CL_DEBUG
609 609
 	int consolefd;
610 610
 #endif
611
+
611 612
 	/*
612 613
 	 * The SMFI_VERSION checks are for Sendmail 8.14, which I don't have
613 614
 	 * yet, so I can't verify them
... ...
@@ -1267,14 +1267,15 @@ main(int argc, char **argv)
1267 1267
 			logg_verbose = 1;
1268 1268
 #ifdef	CL_DEBUG
1269 1269
 			if(debug_level >= 15) {
1270
-				logVerbose = 1;
1271 1270
 #if	((SENDMAIL_VERSION_A > 8) || ((SENDMAIL_VERSION_A == 8) && (SENDMAIL_VERSION_B >= 13)))
1272 1271
 				smfi_setdbg(6);
1273 1272
 #endif
1274 1273
 			}
1275 1274
 #endif
1276 1275
 		}
1277
-		logg_syslog = use_syslog = 1;
1276
+#if defined(USE_SYSLOG) && !defined(C_AIX)
1277
+		logg_syslog = 1;
1278
+#endif
1278 1279
 
1279 1280
 		if(((cpt = cfgopt(copt, "LogFacility")) != NULL) && cpt->enabled)
1280 1281
 			if((fac = logg_facility(cpt->strarg)) == -1) {
... ...
@@ -1287,7 +1288,9 @@ main(int argc, char **argv)
1287 1287
 		if(qflag)
1288 1288
 			fprintf(stderr, _("%s: (-q && !LogSyslog): warning - all interception message methods are off\n"),
1289 1289
 				argv[0]);
1290
-		logg_syslog = use_syslog = 0;
1290
+#if defined(USE_SYSLOG) && !defined(C_AIX)
1291
+		logg_syslog = 0;
1292
+#endif
1291 1293
 	}
1292 1294
 	/*
1293 1295
 	 * Get the outgoing socket details - the way to talk to clamd, unless
... ...
@@ -1394,8 +1397,7 @@ main(int argc, char **argv)
1394 1394
 		}
1395 1395
 		if(send(sessions[0].sock, "SESSION\n", 7, 0) < 7) {
1396 1396
 			perror("send");
1397
-			if(use_syslog)
1398
-				syslog(LOG_ERR, _("Can't create a clamd session"));
1397
+			logg(_("!Can't create a clamd session"));
1399 1398
 			return EX_UNAVAILABLE;
1400 1399
 		}
1401 1400
 		sessions[0].status = CMDSOCKET_FREE;
... ...
@@ -1532,13 +1534,12 @@ main(int argc, char **argv)
1532 1532
 		}
1533 1533
 #else
1534 1534
 		if(activeServers == 0) {
1535
-			cli_errmsg(_("Can't find any clamd servers\n"));
1536 1535
 			cli_errmsg(_("Check your entry for TCPSocket in %s\n"),
1537 1536
 				cfgfile);
1538
-			if(use_syslog) {
1539
-				syslog(LOG_ERR, _("Can't find any clamd server"));
1540
-				closelog();
1541
-			}
1537
+			logg(_("!Can't find any clamd server"));
1538
+#ifdef USE_SYSLOG
1539
+			closelog();
1540
+#endif
1542 1541
 			return EX_CONFIG;
1543 1542
 		}
1544 1543
 #endif
... ...
@@ -1798,10 +1799,8 @@ main(int argc, char **argv)
1798 1798
 		const mode_t old_umask = umask(0006);
1799 1799
 
1800 1800
 		if(pidfile[0] != '/') {
1801
-			if(use_syslog)
1802
-				syslog(LOG_ERR, _("pidfile: '%s' must be a full pathname"),
1803
-					pidfile);
1804
-			cli_errmsg(_("pidfile '%s' must be a full pathname\n"), pidfile);
1801
+			logg(_("!pidfile: '%s' must be a full pathname"),
1802
+				pidfile);
1805 1803
 
1806 1804
 			return EX_CONFIG;
1807 1805
 		}
... ...
@@ -1814,10 +1813,7 @@ main(int argc, char **argv)
1814 1814
 		free(p);
1815 1815
 
1816 1816
 		if((fd = fopen(pidfile, "w")) == NULL) {
1817
-			if(use_syslog)
1818
-				syslog(LOG_ERR, _("Can't save PID in file %s"),
1819
-					pidfile);
1820
-			cli_errmsg(_("Can't save PID in file %s\n"), pidfile);
1817
+			logg(_("!Can't save PID in file %s"), pidfile);
1821 1818
 			return EX_CONFIG;
1822 1819
 		}
1823 1820
 #ifdef	C_LINUX
... ...
@@ -1878,13 +1874,8 @@ main(int argc, char **argv)
1878 1878
 #ifdef	SESSION
1879 1879
 	pthread_mutex_lock(&version_mutex);
1880 1880
 #endif
1881
-	if(use_syslog) {
1882
-		syslog(LOG_INFO, _("Starting %s"), clamav_version);
1883
-#ifdef	CL_DEBUG
1884
-		if(debug_level > 0)
1885
-			syslog(LOG_DEBUG, _("Debugging is on"));
1886
-#endif
1887
-	}
1881
+	logg(_("Starting %s"), clamav_version);
1882
+	logg(_("*Debugging is on"));
1888 1883
 
1889 1884
 	if(blacklist_time) {
1890 1885
 		mx();
... ...
@@ -2398,13 +2389,11 @@ clamfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
2398 2398
 		return cl_error;
2399 2399
 
2400 2400
 	if(ctx == NULL) {
2401
-		if(use_syslog)
2402
-			syslog(LOG_ERR, _("clamfi_connect: ctx is null"));
2401
+		logg(_("!clamfi_connect: ctx is null"));
2403 2402
 		return cl_error;
2404 2403
 	}
2405 2404
 	if(hostname == NULL) {
2406
-		if(use_syslog)
2407
-			syslog(LOG_ERR, _("clamfi_connect: hostname is null"));
2405
+		logg(_("!clamfi_connect: hostname is null"));
2408 2406
 		return cl_error;
2409 2407
 	}
2410 2408
 	if(smfi_getpriv(ctx) != NULL) {
... ...
@@ -2430,23 +2419,17 @@ clamfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
2430 2430
 #endif
2431 2431
 
2432 2432
 		if(remoteIP == NULL) {
2433
-			if(use_syslog)
2434
-				syslog(LOG_ERR, _("clamfi_connect: remoteIP is null"));
2433
+			logg(_("clamfi_connect: remoteIP is null"));
2435 2434
 			return cl_error;
2436 2435
 		}
2437 2436
 	}
2438 2437
 
2439 2438
 #ifdef	CL_DEBUG
2440 2439
 	if(debug_level >= 4) {
2441
-		if(hostname[0] == '[') {
2442
-			if(use_syslog)
2443
-				syslog(LOG_NOTICE, _("clamfi_connect: connection from %s"), remoteIP);
2444
-			cli_dbgmsg(_("clamfi_connect: connection from %s\n"), remoteIP);
2445
-		} else {
2446
-			if(use_syslog)
2447
-				syslog(LOG_NOTICE, _("clamfi_connect: connection from %s [%s]"), hostname, remoteIP);
2448
-			cli_dbgmsg(_("clamfi_connect: connection from %s [%s]\n"), hostname, remoteIP);
2449
-		}
2440
+		if(hostname[0] == '[')
2441
+			logg(_("clamfi_connect: connection from %s"), remoteIP);
2442
+		else
2443
+			logg(_("clamfi_connect: connection from %s [%s]"), hostname, remoteIP);
2450 2444
 	}
2451 2445
 #endif
2452 2446
 
... ...
@@ -2464,8 +2447,7 @@ clamfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
2464 2464
 		 * Using TCP/IP for the sendmail->clamav-milter connection
2465 2465
 		 */
2466 2466
 		if((hostmail = smfi_getsymval(ctx, "{if_name}")) == NULL) {
2467
-			if(use_syslog)
2468
-				syslog(LOG_ERR, _("Can't get sendmail hostname"));
2467
+			logg(_("Can't get sendmail hostname"));
2469 2468
 			return cl_error;
2470 2469
 		}
2471 2470
 		/*
... ...
@@ -2473,8 +2455,7 @@ clamfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
2473 2473
 		 * by Yar Tikhiy <yar@comp.chem.msu.su>
2474 2474
 		 */
2475 2475
 		if(r_gethostbyname(hostmail, &hostent, buf, sizeof(buf)) != 0) {
2476
-			if(use_syslog)
2477
-				syslog(LOG_WARNING, _("Access Denied: Host Unknown (%s)"), hostmail);
2476
+			logg(_("^Access Denied: Host Unknown (%s)"), hostmail);
2478 2477
 			if(hostmail[0] == '[')
2479 2478
 				/*
2480 2479
 				 * A case could be made that it's not clamAV's
... ...
@@ -2493,8 +2474,7 @@ clamfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
2493 2493
 		   (inet_ntop(AF_INET, (struct in_addr *)hostent.h_addr, ip, sizeof(ip)) == NULL)) {
2494 2494
 			perror(hostent.h_name);
2495 2495
 			/*strcpy(ip, (char *)inet_ntoa(*(struct in_addr *)hostent.h_addr));*/
2496
-			if(use_syslog)
2497
-				syslog(LOG_WARNING, _("Access Denied: Can't get IP address for (%s)"), hostent.h_name);
2496
+			logg(_("^Access Denied: Can't get IP address for (%s)"), hostent.h_name);
2498 2497
 			return cl_error;
2499 2498
 		}
2500 2499
 #else
... ...
@@ -2510,8 +2490,7 @@ clamfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
2510 2510
 		pthread_mutex_lock(&wrap_mutex);
2511 2511
 		if(!hosts_ctl(progname, hostent.h_name, ip, STRING_UNKNOWN)) {
2512 2512
 			pthread_mutex_unlock(&wrap_mutex);
2513
-			if(use_syslog)
2514
-				syslog(LOG_WARNING, _("Access Denied for %s[%s]"), hostent.h_name, ip);
2513
+			logg(_("^Access Denied for %s[%s]"), hostent.h_name, ip);
2515 2514
 			return SMFIS_TEMPFAIL;
2516 2515
 		}
2517 2516
 		pthread_mutex_unlock(&wrap_mutex);
... ...
@@ -2527,11 +2506,7 @@ clamfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
2527 2527
 
2528 2528
 	if(!oflag)
2529 2529
 		if(strcmp(remoteIP, "127.0.0.1") == 0) {
2530
-#ifdef	CL_DEBUG
2531
-			if(use_syslog)
2532
-				syslog(LOG_DEBUG, _("clamfi_connect: not scanning outgoing messages"));
2533
-			cli_dbgmsg(_("clamfi_connect: not scanning outgoing messages\n"));
2534
-#endif
2530
+			logg(_("*clamfi_connect: not scanning outgoing messages"));
2535 2531
 			return SMFIS_ACCEPT;
2536 2532
 		}
2537 2533
 
... ...
@@ -2836,12 +2811,7 @@ clamfi_eoh(SMFICTX *ctx)
2836 2836
 	struct privdata *privdata = (struct privdata *)smfi_getpriv(ctx);
2837 2837
 	char **to;
2838 2838
 
2839
-	if(logVerbose)
2840
-		syslog(LOG_DEBUG, _("clamfi_eoh"));
2841
-#ifdef	CL_DEBUG
2842
-	if(debug_level >= 4)
2843
-		cli_dbgmsg(_("clamfi_eoh\n"));
2844
-#endif
2839
+	logg(_("*clamfi_eoh\n"));
2845 2840
 
2846 2841
 	/*
2847 2842
 	 * The DATA instruction from SMTP (RFC2821) must have been sent
... ...
@@ -2932,11 +2902,7 @@ clamfi_body(SMFICTX *ctx, u_char *bodyp, size_t len)
2932 2932
 	struct privdata *privdata = (struct privdata *)smfi_getpriv(ctx);
2933 2933
 	int nbytes;
2934 2934
 
2935
-	if(logVerbose)
2936
-		syslog(LOG_DEBUG, _("clamfi_envbody: %u bytes"), len);
2937
-#ifdef	CL_DEBUG
2938
-	cli_dbgmsg(_("clamfi_envbody: %u bytes\n"), len);
2939
-#endif
2935
+	logg(_("*clamfi_envbody: %u bytes"), len);
2940 2936
 
2941 2937
 	if(len == 0)	/* unlikely */
2942 2938
 		return SMFIS_CONTINUE;
... ...
@@ -2988,13 +2954,12 @@ clamfi_body(SMFICTX *ctx, u_char *bodyp, size_t len)
2988 2988
 
2989 2989
 	if(streamMaxLength > 0L) {
2990 2990
 		if(privdata->numBytes > streamMaxLength) {
2991
-			if(use_syslog) {
2992
-				const char *sendmailId = smfi_getsymval(ctx, "i");
2993
-				if(sendmailId == NULL)
2994
-					sendmailId = "Unknown";
2995
-				syslog(LOG_NOTICE, _("%s: Message more than StreamMaxLength (%ld) bytes - not scanned"),
2996
-					sendmailId, streamMaxLength);
2997
-			}
2991
+			const char *sendmailId = smfi_getsymval(ctx, "i");
2992
+
2993
+			if(sendmailId == NULL)
2994
+				sendmailId = "Unknown";
2995
+			logg(_("%s: Message more than StreamMaxLength (%ld) bytes - not scanned"),
2996
+				sendmailId, streamMaxLength);
2998 2997
 			if(!nflag)
2999 2998
 				smfi_addheader(ctx, "X-Virus-Status", _("Not Scanned - StreamMaxLength exceeded"));
3000 2999
 
... ...
@@ -3033,10 +2998,7 @@ clamfi_eom(SMFICTX *ctx)
3033 3033
 	struct session *session;
3034 3034
 #endif
3035 3035
 
3036
-	if(logVerbose)
3037
-		syslog(LOG_DEBUG, "clamfi_eom");
3038
-
3039
-	cli_dbgmsg("clamfi_eom\n");
3036
+	logg("*clamfi_eom\n");
3040 3037
 
3041 3038
 	if(!nflag) {
3042 3039
 		/*
... ...
@@ -3048,8 +3010,7 @@ clamfi_eom(SMFICTX *ctx)
3048 3048
 
3049 3049
 		for(i = privdata->statusCount; i > 0; --i)
3050 3050
 			if(smfi_chgheader(ctx, "X-Virus-Status", i, NULL) == MI_FAILURE)
3051
-				if(use_syslog)
3052
-					syslog(LOG_WARNING, _("Failed to delete X-Virus-Status header %d"), i);
3051
+				logg(_("^Failed to delete X-Virus-Status header %d"), i);
3053 3052
 	}
3054 3053
 
3055 3054
 #ifdef	CL_DEBUG
... ...
@@ -3118,8 +3079,7 @@ clamfi_eom(SMFICTX *ctx)
3118 3118
 		if(send(session->sock, cmdbuf, nbytes, 0) < nbytes) {
3119 3119
 			perror("send");
3120 3120
 			clamfi_cleanup(ctx);
3121
-			if(use_syslog)
3122
-				syslog(LOG_ERR, _("failed to send SCAN %s command to clamd"), privdata->filename);
3121
+			logg(_("failed to send SCAN %s command to clamd"), privdata->filename);
3123 3122
 			return cl_error;
3124 3123
 		}
3125 3124
 #else
... ...
@@ -3140,8 +3100,7 @@ clamfi_eom(SMFICTX *ctx)
3140 3140
 		if(send(privdata->cmdSocket, cmdbuf, nbytes, 0) < nbytes) {
3141 3141
 			perror("send");
3142 3142
 			clamfi_cleanup(ctx);
3143
-			if(use_syslog)
3144
-				syslog(LOG_ERR, _("failed to send SCAN command to clamd"));
3143
+			logg(_("failed to send SCAN command to clamd"));
3145 3144
 			return cl_error;
3146 3145
 		}
3147 3146
 
... ...
@@ -3170,9 +3129,7 @@ clamfi_eom(SMFICTX *ctx)
3170 3170
 			if((ptr = strchr(mess, '\n')) != NULL)
3171 3171
 				*ptr = '\0';
3172 3172
 
3173
-			if(logVerbose)
3174
-				syslog(LOG_DEBUG, _("clamfi_eom: read %s"), mess);
3175
-			cli_dbgmsg(_("clamfi_eom: read %s\n"), mess);
3173
+			logg(_("*clamfi_eom: read %s\n"), mess);
3176 3174
 		} else {
3177 3175
 #ifdef	MAXHOSTNAMELEN
3178 3176
 			char hostname[MAXHOSTNAMELEN + 1];
... ...
@@ -3189,10 +3146,9 @@ clamfi_eom(SMFICTX *ctx)
3189 3189
 			 * helps by forcing a retry
3190 3190
 			 */
3191 3191
 			clamfi_cleanup(ctx);
3192
-			syslog(LOG_NOTICE, _("clamfi_eom: read nothing from clamd on %s"), hostname);
3193
-#ifdef	CL_DEBUG
3194
-			cli_dbgmsg(_("clamfi_eom: read nothing from clamd on %s\n"), hostname);
3195
-#endif
3192
+
3193
+			logg(LOG_NOTICE, _("clamfi_eom: read nothing from clamd on %s"), hostname);
3194
+
3196 3195
 #ifdef	SESSION
3197 3196
 			pthread_mutex_lock(&sstatus_mutex);
3198 3197
 			session->status = CMDSOCKET_DOWN;
... ...
@@ -3297,9 +3253,8 @@ clamfi_eom(SMFICTX *ctx)
3297 3297
 			/*
3298 3298
 			 * Clamd has stopped on StreamMaxLength before us
3299 3299
 			 */
3300
-			if(use_syslog)
3301
-				syslog(LOG_NOTICE, _("%s: Message more than StreamMaxLength (%ld) bytes - not scanned"),
3302
-					sendmailId, streamMaxLength);
3300
+			logg(_("%s: Message more than StreamMaxLength (%ld) bytes - not scanned"),
3301
+				sendmailId, streamMaxLength);
3303 3302
 			if(!nflag)
3304 3303
 				smfi_addheader(ctx, "X-Virus-Status", _("Not Scanned - StreamMaxLength exceeded"));
3305 3304
 			clamfi_cleanup(ctx);	/* not needed, but just to be safe */
... ...
@@ -3308,9 +3263,7 @@ clamfi_eom(SMFICTX *ctx)
3308 3308
 		if(!nflag)
3309 3309
 			smfi_addheader(ctx, "X-Virus-Status", _("Not Scanned"));
3310 3310
 
3311
-		cli_warnmsg("%s: %s\n", sendmailId, mess);
3312
-		if(use_syslog)
3313
-			syslog(LOG_ERR, "%s: %s\n", sendmailId, mess);
3311
+		logg("!%s: %s\n", sendmailId, mess);
3314 3312
 		rc = cl_error;
3315 3313
 	} else if((ptr = strstr(mess, "FOUND")) != NULL) {
3316 3314
 		/*
... ...
@@ -3318,8 +3271,9 @@ clamfi_eom(SMFICTX *ctx)
3318 3318
 		 *	word "FOUND" is in the email, e.g. the
3319 3319
 		 *	quarantine directory is /tmp/VIRUSES-FOUND
3320 3320
 		 */
3321
+		int i;
3322
+		char **to, *virusname, *err;
3321 3323
 		char reject[1024];
3322
-		char **to, *virusname;
3323 3324
 
3324 3325
 		/*
3325 3326
 		 * Remove the "FOUND" word, and the space before it
... ...
@@ -3342,59 +3296,53 @@ clamfi_eom(SMFICTX *ctx)
3342 3342
 		if(quarantine_dir)
3343 3343
 			qfile(privdata, sendmailId, virusname);
3344 3344
 
3345
-		if(use_syslog) {
3346
-			/*
3347
-			 * Setup err as a list of recipients
3348
-			 */
3349
-			char *err = (char *)cli_malloc(1024);
3350
-			int i;
3345
+		/*
3346
+		 * Setup err as a list of recipients
3347
+		 */
3348
+		err = (char *)cli_malloc(1024);
3351 3349
 
3352
-			if(err == NULL) {
3353
-				clamfi_cleanup(ctx);
3354
-				return cl_error;
3355
-			}
3350
+		if(err == NULL) {
3351
+			clamfi_cleanup(ctx);
3352
+			return cl_error;
3353
+		}
3356 3354
 
3357
-			/*
3358
-			 * Use snprintf rather than printf since we don't know
3359
-			 * the length of privdata->from and may get a buffer
3360
-			 * overrun
3361
-			 */
3362
-			snprintf(err, 1023, _("Intercepted virus from %s to"),
3363
-				privdata->from);
3355
+		/*
3356
+		 * Use snprintf rather than printf since we don't know
3357
+		 * the length of privdata->from and may get a buffer
3358
+		 * overrun
3359
+		 */
3360
+		snprintf(err, 1023, _("Intercepted virus from %s to"),
3361
+			privdata->from);
3364 3362
 
3365
-			ptr = strchr(err, '\0');
3363
+		ptr = strchr(err, '\0');
3366 3364
 
3367
-			i = 1024;
3365
+		i = 1024;
3368 3366
 
3369
-			for(to = privdata->to; *to; to++) {
3370
-				/*
3371
-				 * Re-alloc if we are about run out of buffer
3372
-				 * space
3373
-				 *
3374
-				 * TODO: Only append *to if it's a valid, local
3375
-				 *	email address
3376
-				 */
3377
-				if(&ptr[strlen(*to) + 2] >= &err[i]) {
3378
-					i += 1024;
3379
-					err = cli_realloc(err, i);
3380
-					if(err == NULL) {
3381
-						clamfi_cleanup(ctx);
3382
-						return cl_error;
3383
-					}
3384
-					ptr = strchr(err, '\0');
3367
+		for(to = privdata->to; *to; to++) {
3368
+			/*
3369
+			 * Re-alloc if we are about run out of buffer
3370
+			 * space
3371
+			 *
3372
+			 * TODO: Only append *to if it's a valid, local
3373
+			 *	email address
3374
+			 */
3375
+			if(&ptr[strlen(*to) + 2] >= &err[i]) {
3376
+				i += 1024;
3377
+				err = cli_realloc(err, i);
3378
+				if(err == NULL) {
3379
+					clamfi_cleanup(ctx);
3380
+					return cl_error;
3385 3381
 				}
3386
-				ptr = cli_strrcpy(ptr, " ");
3387
-				ptr = cli_strrcpy(ptr, *to);
3382
+				ptr = strchr(err, '\0');
3388 3383
 			}
3389
-			(void)strcpy(ptr, "\n");
3390
-
3391
-			/* Include the sendmail queue ID in the log */
3392
-			syslog(LOG_NOTICE, "%s: %s %s", sendmailId, mess, err);
3393
-#ifdef	CL_DEBUG
3394
-			cli_dbgmsg("%s", err);
3395
-#endif
3396
-			free(err);
3384
+			ptr = cli_strrcpy(ptr, " ");
3385
+			ptr = cli_strrcpy(ptr, *to);
3397 3386
 		}
3387
+		(void)strcpy(ptr, "\n");
3388
+
3389
+		/* Include the sendmail queue ID in the log */
3390
+		logg("%s: %s %s", sendmailId, mess, err);
3391
+		free(err);
3398 3392
 
3399 3393
 		if(!qflag) {
3400 3394
 			char cmd[128];
... ...
@@ -3470,8 +3418,7 @@ clamfi_eom(SMFICTX *ctx)
3470 3470
 
3471 3471
 					if(fin == NULL) {
3472 3472
 						perror(templateHeaders);
3473
-						if(use_syslog)
3474
-							syslog(LOG_ERR, _("Can't open e-mail template header file %s"),
3473
+						logg(_("!Can't open e-mail template header file %s"),
3475 3474
 								templateHeaders);
3476 3475
 					} else {
3477 3476
 						int c;
... ...
@@ -3546,10 +3493,9 @@ clamfi_eom(SMFICTX *ctx)
3546 3546
 
3547 3547
 				cli_dbgmsg("Waiting for %s to finish\n", cmd);
3548 3548
 				if(pclose(sendmail) != 0)
3549
-					if(use_syslog)
3550
-						syslog(LOG_ERR, _("%s: Failed to notify clamAV interception - see dead.letter"), sendmailId);
3551
-			} else if(use_syslog)
3552
-				syslog(LOG_WARNING, _("Can't execute '%s' to send virus notice"), cmd);
3549
+					logg(_("%s: Failed to notify clamAV interception - see dead.letter"), sendmailId);
3550
+			} else
3551
+				logg(_("^Can't execute '%s' to send virus notice"), cmd);
3553 3552
 		}
3554 3553
 
3555 3554
 		if(report && (quarantine == NULL) && (!advisory) &&
... ...
@@ -3643,20 +3589,17 @@ clamfi_eom(SMFICTX *ctx)
3643 3643
 	} else if((strstr(mess, "OK") == NULL) && (strstr(mess, "Empty file") == NULL)) {
3644 3644
 		if(!nflag)
3645 3645
 			smfi_addheader(ctx, "X-Virus-Status", _("Unknown"));
3646
-		if(use_syslog)
3647
-			syslog(LOG_ERR, _("%s: incorrect message \"%s\" from clamd"),
3648
-				sendmailId,
3649
-				mess);
3646
+		logg(_("!%s: incorrect message \"%s\" from clamd"),
3647
+				sendmailId, mess);
3650 3648
 		rc = cl_error;
3651 3649
 	} else {
3652 3650
 		if(!nflag)
3653 3651
 			smfi_addheader(ctx, "X-Virus-Status", _("Clean"));
3654 3652
 
3655
-		if(use_syslog && logClean)
3656
-			/* Include the sendmail queue ID in the log */
3657
-			syslog(LOG_NOTICE, _("%s: clean message from %s"),
3658
-				sendmailId,
3659
-				(privdata->from) ? privdata->from : _("an unknown sender"));
3653
+		/* Include the sendmail queue ID in the log */
3654
+		logg(_("%s: clean message from %s"),
3655
+			sendmailId,
3656
+			(privdata->from) ? privdata->from : _("an unknown sender"));
3660 3657
 
3661 3658
 		if(privdata->body) {
3662 3659
 			/*
... ...
@@ -3688,17 +3631,12 @@ clamfi_eom(SMFICTX *ctx)
3688 3688
 static sfsistat
3689 3689
 clamfi_abort(SMFICTX *ctx)
3690 3690
 {
3691
-#ifdef	CL_DEBUG
3692
-	if(logVerbose)
3693
-		syslog(LOG_DEBUG, "clamfi_abort");
3694
-#endif
3695
-
3696
-	cli_dbgmsg("clamfi_abort\n");
3691
+	logg("*clamfi_abort\n");
3697 3692
 
3698 3693
 	clamfi_cleanup(ctx);
3699 3694
 	decrement_connections();
3700 3695
 
3701
-	cli_dbgmsg("clamfi_abort returns\n");
3696
+	logg("*clamfi_abort returns\n");
3702 3697
 
3703 3698
 	return cl_error;
3704 3699
 }
... ...
@@ -3749,10 +3687,8 @@ clamfi_free(struct privdata *privdata, int keep)
3749 3749
 			 */
3750 3750
 			if((unlink(privdata->filename) < 0) && (errno != ENOENT)) {
3751 3751
 				perror(privdata->filename);
3752
-				if(use_syslog)
3753
-					syslog(LOG_ERR,
3754
-						_("Can't remove clean file %s"),
3755
-						privdata->filename);
3752
+				logg(_("!Can't remove clean file %s"),
3753
+					privdata->filename);
3756 3754
 			}
3757 3755
 			free(privdata->filename);
3758 3756
 		}
... ...
@@ -3919,35 +3855,34 @@ clamfi_send(struct privdata *privdata, size_t len, const char *format, ...)
3919 3919
 
3920 3920
 		if(nbytes == -1) {
3921 3921
 			if(privdata->filename) {
3922
-				perror(privdata->filename);
3923
-				if(use_syslog) {
3924 3922
 #ifdef HAVE_STRERROR_R
3925
-					char buf[32];
3926
-					strerror_r(errno, buf, sizeof(buf));
3927
-					syslog(LOG_ERR,
3928
-						_("write failure (%u bytes) to %s: %s"),
3929
-						len, privdata->filename, buf);
3923
+				char buf[32];
3924
+
3925
+				perror(privdata->filename);
3926
+				strerror_r(errno, buf, sizeof(buf));
3927
+				logg(_("!write failure (%u bytes) to %s: %s"),
3928
+					len, privdata->filename, buf);
3930 3929
 #else
3931
-					syslog(LOG_ERR, _("write failure (%u bytes) to %s: %s"),
3932
-						len, privdata->filename,
3933
-						strerror(errno));
3930
+				perror(privdata->filename);
3931
+				logg(_("!write failure (%u bytes) to %s: %s"),
3932
+					len, privdata->filename,
3933
+					strerror(errno));
3934 3934
 #endif
3935
-				}
3936 3935
 			} else {
3937 3936
 				if(errno == EINTR)
3938 3937
 					continue;
3939 3938
 				perror("send");
3940
-				if(use_syslog) {
3941 3939
 #ifdef HAVE_STRERROR_R
3940
+				{
3942 3941
 					char buf[32];
3943 3942
 					strerror_r(errno, buf, sizeof(buf));
3944 3943
 					logg(_("!write failure (%u bytes) to clamd: %s\n"),
3945 3944
 						len, buf);
3945
+				}
3946 3946
 #else
3947
-					logg(_("!write failure (%u bytes) to clamd: %s\n"),
3948
-						len, strerror(errno));
3947
+				logg(_("!write failure (%u bytes) to clamd: %s\n"),
3948
+					len, strerror(errno));
3949 3949
 #endif
3950
-				}
3951 3950
 				checkClamd();
3952 3951
 			}
3953 3952
 
... ...
@@ -4022,8 +3957,7 @@ clamd_recv(int sock, char *buf, size_t len)
4022 4022
 				perror("select");
4023 4023
 				return -1;
4024 4024
 			case 0:
4025
-				if(use_syslog)
4026
-					syslog(LOG_ERR, _("No data received from clamd in %d seconds\n"), readTimeout);
4025
+				logg(_("!No data received from clamd in %d seconds\n"), readTimeout);
4027 4026
 				return 0;
4028 4027
 		}
4029 4028
 		break;
... ...
@@ -4051,8 +3985,7 @@ updateSigFile(void)
4051 4051
 
4052 4052
 	if(stat(sigFilename, &statb) < 0) {
4053 4053
 		perror(sigFilename);
4054
-		if(use_syslog)
4055
-			syslog(LOG_ERR, _("Can't stat %s"), sigFilename);
4054
+		logg(_("Can't stat %s"), sigFilename);
4056 4055
 		return 0;
4057 4056
 	}
4058 4057
 
... ...
@@ -4062,8 +3995,7 @@ updateSigFile(void)
4062 4062
 	fd = open(sigFilename, O_RDONLY);
4063 4063
 	if(fd < 0) {
4064 4064
 		perror(sigFilename);
4065
-		if(use_syslog)
4066
-			syslog(LOG_ERR, _("Can't open %s"), sigFilename);
4065
+		logg(_("Can't open %s"), sigFilename);
4067 4066
 		return 0;
4068 4067
 	}
4069 4068
 
... ...
@@ -4161,12 +4093,7 @@ connect2clamd(struct privdata *privdata)
4161 4161
 	assert(privdata->from != NULL);
4162 4162
 	assert(privdata->to != NULL);
4163 4163
 
4164
-#ifdef	CL_DEBUG
4165
-	if((debug_level > 0) && use_syslog)
4166
-		syslog(LOG_DEBUG, "connect2clamd");
4167
-	if(debug_level >= 4)
4168
-		cli_dbgmsg("connect2clamd\n");
4169
-#endif
4164
+	logg("*connect2clamd\n");
4170 4165
 
4171 4166
 	if(quarantine_dir || tmpdir) {	/* store message in a temporary file */
4172 4167
 		int ntries = 5;
... ...
@@ -4187,8 +4114,7 @@ connect2clamd(struct privdata *privdata)
4187 4187
 		if((mkdir(dir, 0700) < 0) && (errno != EEXIST)) {
4188 4188
 #endif
4189 4189
 			perror(dir);
4190
-			if(use_syslog)
4191
-				syslog(LOG_ERR, _("mkdir %s failed"), dir);
4190
+			logg(_("mkdir %s failed"), dir);
4192 4191
 			return 0;
4193 4192
 		}
4194 4193
 		privdata->filename = (char *)cli_malloc(strlen(dir) + 12);
... ...
@@ -4202,8 +4128,7 @@ connect2clamd(struct privdata *privdata)
4202 4202
 			privdata->dataSocket = mkstemp(privdata->filename);
4203 4203
 #else
4204 4204
 			if(mktemp(privdata->filename) == NULL) {
4205
-				if(use_syslog)
4206
-					syslog(LOG_ERR, _("mktemp %s failed"), privdata->filename);
4205
+				logg(_("mktemp %s failed"), privdata->filename);
4207 4206
 				return 0;
4208 4207
 			}
4209 4208
 			privdata->dataSocket = open(privdata->filename, O_CREAT|O_EXCL|O_WRONLY|O_TRUNC, 0600);
... ...
@@ -4212,8 +4137,8 @@ connect2clamd(struct privdata *privdata)
4212 4212
 
4213 4213
 		if(privdata->dataSocket < 0) {
4214 4214
 			perror(privdata->filename);
4215
-			if(use_syslog)
4216
-				syslog(LOG_ERR, _("Temporary quarantine file %s creation failed"), privdata->filename);
4215
+			logg(_("Temporary quarantine file %s creation failed"),
4216
+				privdata->filename);
4217 4217
 			free(privdata->filename);
4218 4218
 			privdata->filename = NULL;
4219 4219
 			return 0;
... ...
@@ -4315,19 +4240,15 @@ connect2clamd(struct privdata *privdata)
4315 4315
 			pthread_mutex_lock(&sstatus_mutex);
4316 4316
 			session->status = CMDSOCKET_DOWN;
4317 4317
 			pthread_mutex_unlock(&sstatus_mutex);
4318
-			cli_warnmsg("Failed sending stream to server %d (fd %d) errno %d\n",
4319
-				freeServer, session->sock, errno);
4320
-			if(use_syslog)
4321
-				syslog(LOG_ERR, _("failed to send STREAM command clamd server %d"),
4322
-					freeServer);
4318
+			logg(_("!failed to send STREAM command clamd server %d"),
4319
+				freeServer);
4323 4320
 
4324 4321
 			return 0;
4325 4322
 		}
4326 4323
 #else
4327 4324
 		if(send(privdata->cmdSocket, "STREAM\n", 7, 0) < 7) {
4328 4325
 			perror("send");
4329
-			if(use_syslog)
4330
-				syslog(LOG_ERR, _("failed to send STREAM command clamd"));
4326
+			logg(_("!failed to send STREAM command clamd"));
4331 4327
 			return 0;
4332 4328
 		}
4333 4329
 		shutdown(privdata->cmdSocket, SHUT_WR);
... ...
@@ -4338,8 +4259,7 @@ connect2clamd(struct privdata *privdata)
4338 4338
 		 */
4339 4339
 		if((privdata->dataSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
4340 4340
 			perror("socket");
4341
-			if(use_syslog)
4342
-				syslog(LOG_ERR, _("failed to create TCPSocket to talk to clamd"));
4341
+			logg(_("!failed to create TCPSocket to talk to clamd"));
4343 4342
 			return 0;
4344 4343
 		}
4345 4344
 
... ...
@@ -4350,12 +4270,10 @@ connect2clamd(struct privdata *privdata)
4350 4350
 		if(nbytes <= 0) {
4351 4351
 			if(nbytes < 0) {
4352 4352
 				perror("recv");
4353
-				if(use_syslog)
4354
-					syslog(LOG_ERR, _("recv failed from clamd getting PORT"));
4355
-				cli_warnmsg("Failed get PORT from server %d (fd %d) errno %d\n",
4356
-					freeServer, session->sock, errno);
4357
-			} else if(use_syslog)
4358
-				syslog(LOG_ERR, _("EOF from clamd getting PORT"));
4353
+				logg(_("!recv failed from clamd getting PORT"));
4354
+			} else
4355
+				logg(_("!EOF from clamd getting PORT"));
4356
+
4359 4357
 			pthread_mutex_lock(&sstatus_mutex);
4360 4358
 			session->status = CMDSOCKET_DOWN;
4361 4359
 			pthread_mutex_unlock(&sstatus_mutex);
... ...
@@ -4366,10 +4284,10 @@ connect2clamd(struct privdata *privdata)
4366 4366
 		if(nbytes <= 0) {
4367 4367
 			if(nbytes < 0) {
4368 4368
 				perror("recv");
4369
-				if(use_syslog)
4370
-					syslog(LOG_ERR, _("recv failed from clamd getting PORT"));
4371
-			} else if(use_syslog)
4372
-				syslog(LOG_ERR, _("EOF from clamd getting PORT"));
4369
+				logg(_("!recv failed from clamd getting PORT"));
4370
+			} else
4371
+				logg(_("!EOF from clamd getting PORT"));
4372
+
4373 4373
 			return 0;
4374 4374
 		}
4375 4375
 #endif
... ...
@@ -4379,12 +4297,8 @@ connect2clamd(struct privdata *privdata)
4379 4379
 			cli_dbgmsg("Received: %s", buf);
4380 4380
 #endif
4381 4381
 		if(sscanf(buf, "PORT %hu\n", &p) != 1) {
4382
-			if(use_syslog)
4383
-				syslog(LOG_ERR, _("Expected port information from clamd, got '%s'"),
4384
-					buf);
4385
-			else
4386
-				cli_warnmsg(_("Expected port information from clamd, got '%s'\n"),
4387
-					buf);
4382
+			logg(_("!Expected port information from clamd, got '%s'"),
4383
+				buf);
4388 4384
 #ifdef	SESSION
4389 4385
 			session->status = CMDSOCKET_DOWN;
4390 4386
 			pthread_mutex_unlock(&sstatus_mutex);
... ...
@@ -4417,16 +4331,13 @@ connect2clamd(struct privdata *privdata)
4417 4417
 			cli_dbgmsg("Failed to connect to port %d given by clamd",
4418 4418
 				p);
4419 4419
 			/* 0.4 - use better error message */
4420
-			if(use_syslog) {
4421 4420
 #ifdef HAVE_STRERROR_R
4422
-				strerror_r(errno, buf, sizeof(buf));
4423
-				syslog(LOG_ERR,
4424
-					_("Failed to connect to port %d given by clamd: %s"),
4421
+			strerror_r(errno, buf, sizeof(buf));
4422
+			logg(_("!Failed to connect to port %d given by clamd: %s"),
4425 4423
 					p, buf);
4426 4424
 #else
4427
-				syslog(LOG_ERR, _("Failed to connect to port %d given by clamd: %s"), p, strerror(errno));
4425
+			logg(_("!Failed to connect to port %d given by clamd: %s"), p, strerror(errno));
4428 4426
 #endif
4429
-			}
4430 4427
 #ifdef	SESSION
4431 4428
 			pthread_mutex_lock(&sstatus_mutex);
4432 4429
 			session->status = CMDSOCKET_DOWN;
... ...
@@ -4509,8 +4420,7 @@ checkClamd(void)
4509 4509
 	fd = open(pidFile, O_RDONLY);
4510 4510
 	if(fd < 0) {
4511 4511
 		perror(pidFile);
4512
-		if(use_syslog)
4513
-			syslog(LOG_ERR, _("Can't open %s"), pidFile);
4512
+		logg(_("!Can't open %s"), pidFile);
4514 4513
 		return;
4515 4514
 	}
4516 4515
 	nbytes = read(fd, buf, sizeof(buf) - 1);
... ...
@@ -4521,10 +4431,8 @@ checkClamd(void)
4521 4521
 	close(fd);
4522 4522
 	pid = atoi(buf);
4523 4523
 	if((kill(pid, 0) < 0) && (errno == ESRCH)) {
4524
-		if(use_syslog)
4525
-			syslog(LOG_ERR, _("Clamd (pid %d) seems to have died"),
4526
-				pid);
4527 4524
 		perror("clamd");
4525
+		logg(_("!Clamd (pid %d) seems to have died"), pid);
4528 4526
 	}
4529 4527
 }
4530 4528
 
... ...
@@ -4547,33 +4455,27 @@ sendtemplate(SMFICTX *ctx, const char *filename, FILE *sendmail, const char *vir
4547 4547
 
4548 4548
 	if(fin == NULL) {
4549 4549
 		perror(filename);
4550
-		if(use_syslog)
4551
-			syslog(LOG_ERR, _("Can't open e-mail template file %s"),
4552
-				filename);
4550
+		logg(_("!Can't open e-mail template file %s"), filename);
4553 4551
 		return -1;
4554 4552
 	}
4555 4553
 
4556 4554
 	if(fstat(fileno(fin), &statb) < 0) {
4557 4555
 		/* File disappeared in race condition? */
4558 4556
 		perror(filename);
4559
-		if(use_syslog)
4560
-			syslog(LOG_ERR, _("Can't stat e-mail template file %s"),
4561
-				filename);
4557
+		logg(_("!Can't stat e-mail template file %s"), filename);
4562 4558
 		fclose(fin);
4563 4559
 		return -1;
4564 4560
 	}
4565 4561
 	buf = cli_malloc(statb.st_size + 1);
4566 4562
 	if(buf == NULL) {
4567 4563
 		fclose(fin);
4568
-		if(use_syslog)
4569
-			syslog(LOG_ERR, _("Out of memory"));
4564
+		logg(_("!Out of memory"));
4570 4565
 		return -1;
4571 4566
 	}
4572 4567
 	if(fread(buf, sizeof(char), statb.st_size, fin) != (size_t)statb.st_size) {
4573 4568
 		perror(filename);
4574
-		if(use_syslog)
4575
-			syslog(LOG_ERR, _("Error reading e-mail template file %s"),
4576
-				filename);
4569
+		logg(_("!Error reading e-mail template file %s"),
4570
+			filename);
4577 4571
 		fclose(fin);
4578 4572
 		free(buf);
4579 4573
 		return -1;
... ...
@@ -4600,8 +4502,7 @@ sendtemplate(SMFICTX *ctx, const char *filename, FILE *sendmail, const char *vir
4600 4600
 						--ptr;
4601 4601
 						continue;
4602 4602
 					default:
4603
-						syslog(LOG_ERR,
4604
-							_("%s: Unknown clamAV variable \"%c\"\n"),
4603
+						logg(_("!%s: Unknown clamAV variable \"%c\"\n"),
4605 4604
 							filename, *ptr);
4606 4605
 						break;
4607 4606
 				}
... ...
@@ -4611,9 +4512,8 @@ sendtemplate(SMFICTX *ctx, const char *filename, FILE *sendmail, const char *vir
4611 4611
 				char *end = strchr(++ptr, '$');
4612 4612
 
4613 4613
 				if(end == NULL) {
4614
-					syslog(LOG_ERR,
4615
-						_("%s: Unterminated sendmail variable \"%s\"\n"),
4616
-							filename, ptr);
4614
+					logg(_("!%s: Unterminated sendmail variable \"%s\"\n"),
4615
+						filename, ptr);
4617 4616
 					continue;
4618 4617
 				}
4619 4618
 				*end = '\0';
... ...
@@ -4621,9 +4521,7 @@ sendtemplate(SMFICTX *ctx, const char *filename, FILE *sendmail, const char *vir
4621 4621
 				val = smfi_getsymval(ctx, ptr);
4622 4622
 				if(val == NULL) {
4623 4623
 					fputs(ptr, sendmail);
4624
-					if(use_syslog)
4625
-						syslog(LOG_ERR,
4626
-							_("%s: Unknown sendmail variable \"%s\"\n"),
4624
+						logg(_("!%s: Unknown sendmail variable \"%s\"\n"),
4627 4625
 							filename, ptr);
4628 4626
 				} else
4629 4627
 					fputs(val, sendmail);
... ...
@@ -5055,8 +4953,7 @@ watchdog(void *a)
5055 5055
 							if(clamav_versions[i] == NULL)
5056 5056
 								clamav_versions[i] = strdup(buf);
5057 5057
 							else if(strcmp(buf, clamav_versions[i]) != 0) {
5058
-								if(use_syslog)
5059
-									syslog(LOG_INFO, "New version received for server %d: '%s'\n", i, buf);
5058
+								logg("New version received for server %d: '%s'\n", i, buf);
5060 5059
 								free(clamav_versions[i]);
5061 5060
 								clamav_versions[i] = strdup(buf);
5062 5061
 							}
... ...
@@ -5228,8 +5125,7 @@ quit(void)
5228 5228
 #ifdef	SESSION
5229 5229
 	pthread_mutex_lock(&version_mutex);
5230 5230
 #endif
5231
-	if(use_syslog)
5232
-		syslog(LOG_INFO, _("Stopping %s"), clamav_version);
5231
+	logg(_("Stopping %s"), clamav_version);
5233 5232
 #ifdef	SESSION
5234 5233
 	pthread_mutex_unlock(&version_mutex);
5235 5234
 #endif
... ...
@@ -5283,8 +5179,7 @@ quit(void)
5283 5283
 		if(unlink(pidfile) < 0)
5284 5284
 			perror(pidfile);
5285 5285
 
5286
-	if(use_syslog)
5287
-		closelog();
5286
+	logg_close();
5288 5287
 }
5289 5288
 
5290 5289
 static void
... ...
@@ -5423,16 +5318,14 @@ loadDatabase(void)
5423 5423
 	root = newroot;
5424 5424
 	pthread_mutex_unlock(&root_mutex);
5425 5425
 
5426
-	if(use_syslog) {
5427 5426
 #ifdef	SESSION
5428
-		pthread_mutex_lock(&version_mutex);
5427
+	pthread_mutex_lock(&version_mutex);
5429 5428
 #endif
5430
-		syslog(LOG_INFO, _("Loaded %s"), clamav_version);
5429
+	logg( _("Loaded %s"), clamav_version);
5431 5430
 #ifdef	SESSION
5432
-		pthread_mutex_unlock(&version_mutex);
5431
+	pthread_mutex_unlock(&version_mutex);
5433 5432
 #endif
5434
-		syslog(LOG_INFO, _("ClamAV: Protecting against %u viruses"), signatures);
5435
-	}
5433
+	logg(_("ClamAV: Protecting against %u viruses"), signatures);
5436 5434
 	if(oldroot) {
5437 5435
 		cl_free(oldroot);
5438 5436
 		logg("#Database correctly reloaded (%u viruses)", signatures);
... ...
@@ -5469,14 +5362,9 @@ print_trace(void)
5469 5469
 	strings = backtrace_symbols(array, size);
5470 5470
 
5471 5471
 	cli_dbgmsg("Backtrace of pid %d:\n", pid);
5472
-	if(use_syslog)
5473
-		syslog(LOG_ERR, "Backtrace of pid %d:", pid);
5474 5472
 
5475
-	for(i = 0; i < size; i++) {
5476
-		if(use_syslog)
5477
-			syslog(LOG_ERR, "bt[%u]: %s", i, strings[i]);
5478
-		cli_dbgmsg("%s\n", strings[i]);
5479
-	}
5473
+	for(i = 0; i < size; i++)
5474
+		logg("bt[%u]: %s", i, strings[i]);
5480 5475
 
5481 5476
 	/* TODO: dump the current email */
5482 5477
 
... ...
@@ -5585,17 +5473,14 @@ isWhitelisted(const char *emailaddress, int to)
5585 5585
 
5586 5586
 		if(fin == NULL) {
5587 5587
 			perror(whitelistFile);
5588
-			if(use_syslog)
5589
-				syslog(LOG_ERR, _("Can't open whitelist file %s"),
5590
-					whitelistFile);
5588
+			logg(_("!Can't open whitelist file %s"), whitelistFile);
5591 5589
 			return 0;
5592 5590
 		}
5593 5591
 		to_whitelist = tableCreate();
5594 5592
 		from_whitelist = tableCreate();
5595 5593
 
5596 5594
 		if((to_whitelist == NULL) || (from_whitelist == NULL)) {
5597
-			if(use_syslog)
5598
-				syslog(LOG_ERR, _("Can't create whitelist table"));
5595
+			logg(_("!Can't create whitelist table"));
5599 5596
 			if(to_whitelist) {
5600 5597
 				tableDestroy(to_whitelist);
5601 5598
 				to_whitelist = NULL;
... ...
@@ -5683,8 +5568,7 @@ isBlacklisted(const char *ip_address)
5683 5683
 		pthread_mutex_unlock(&blacklist_mutex);
5684 5684
 
5685 5685
 		if(blacklist == NULL)
5686
-			if(use_syslog)
5687
-				syslog(LOG_ERR, _("Can't create blacklist table"));
5686
+			logg(_("!Can't create blacklist table"));
5688 5687
 		return 0;
5689 5688
 	}
5690 5689
 	t = tableFind(blacklist, ip_address);
... ...
@@ -5919,8 +5803,8 @@ black_hole(const struct privdata *privdata)
5919 5919
 				}
5920 5920
 			}
5921 5921
 			pclose(sendmail);
5922
-		} else if(use_syslog) {
5923
-			syslog(LOG_WARNING, _("Can't execute '%s' to expand '%s'"),
5922
+		} else {
5923
+			logg(_("^Can't execute '%s' to expand '%s'"),
5924 5924
 				cmd, *to);
5925 5925
 			must_scan = 1;
5926 5926
 		}
... ...
@@ -5929,13 +5813,11 @@ black_hole(const struct privdata *privdata)
5929 5929
 	}
5930 5930
 	if(!must_scan) {
5931 5931
 		/* All recipients map to /dev/null */
5932
-		if(use_syslog) {
5933
-			to = privdata->to;
5934
-			if(*to)
5935
-				syslog(LOG_NOTICE, "discarded, since all recipients (e.g. \"%s\") are /dev/null", *to);
5936
-			else
5937
-				syslog(LOG_NOTICE, "discarded, since all recipients are /dev/null");
5938
-		}
5932
+		to = privdata->to;
5933
+		if(*to)
5934
+			logg("discarded, since all recipients (e.g. \"%s\") are /dev/null", *to);
5935
+		else
5936
+			logg("discarded, since all recipients are /dev/null");
5939 5937
 		return SMFIS_DISCARD;
5940 5938
 	}
5941 5939
 	return SMFIS_CONTINUE;