Browse code

--on-outdated-execute update

git-svn: trunk@1681

Tomasz Kojm authored on 2005/08/03 23:21:55
Showing 6 changed files
... ...
@@ -1,3 +1,10 @@
1
+Wed Aug  3 16:16:59 CEST 2005 (tk)
2
+----------------------------------
3
+  * freshclam: --on-outdated-execute: do not trigger on f-level warning (which
4
+	       in most cases means software was linked against improper
5
+	       version of libclamav); add support for %v (new version string)
6
+	       in command string
7
+
1 8
 Wed Aug  3 09:56:33 BST 2005 (trog)
2 9
 -----------------------------------
3 10
   * libclamav/chmunpack.c: Fix possible memory leak (TK)
... ...
@@ -61,7 +61,7 @@ Execute COMMAND if error occurred. Remember, that virus database freshness is th
61 61
 Execute COMMAND after successful update.
62 62
 .TP 
63 63
 \fB\-\-on\-outdated\-execute=COMMAND\fR
64
-Execute COMMAND when freshclam reports outdated version.
64
+Execute COMMAND when freshclam reports outdated version. In the command string %v will be replaced by the new version number.
65 65
 .SH "EXAMPLES"
66 66
 .LP 
67 67
 .TP 
... ...
@@ -108,7 +108,7 @@ Execute this command after the database has been successfully updated.
108 108
 Default: disabled
109 109
 .TP 
110 110
 \fBOnOutdatedExecute STRING\fR
111
-Execute this command when freshclam reports outdated version.
111
+Execute this command when freshclam reports outdated version. In the command string %v will be replaced by the new version number.
112 112
 .br 
113 113
 Default: disabled
114 114
 .TP
... ...
@@ -94,6 +94,7 @@ DatabaseMirror database.clamav.net
94 94
 #OnErrorExecute command
95 95
 
96 96
 # Run command when freshclam reports outdated version.
97
+# In the command string %v will be replaced by the new version number.
97 98
 # Default: disabled
98 99
 #OnOutdatedExecute command
99 100
 
... ...
@@ -56,10 +56,9 @@ int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, c
56 56
 {
57 57
 	time_t currtime;
58 58
 	int ret, updated = 0, outdated = 0, signo = 0, ttl = -1;
59
-	char ipaddr[16], *dnsreply = NULL, *pt;
60
-	struct cfgstruct *cpt;
61
-	char *localip = NULL;
59
+	char ipaddr[16], *dnsreply = NULL, *pt, *localip = NULL, *newver = NULL;
62 60
 	const char *arg = NULL;
61
+	struct cfgstruct *cpt;
63 62
 #ifdef HAVE_RESOLV_H
64 63
 	const char *dnsdbinfo;
65 64
 #endif
... ...
@@ -109,19 +108,18 @@ int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, c
109 109
 		    free(pt);
110 110
 		}
111 111
 
112
-		if((pt = cli_strtok(dnsreply, 0, ":"))) {
112
+		if((newver = cli_strtok(dnsreply, 0, ":"))) {
113 113
 
114
-		    logg("*Software version from DNS: %s\n", pt);
114
+		    logg("*Software version from DNS: %s\n", newver);
115 115
 
116 116
 		    if(vwarning && !strstr(cl_retver(), "devel") && !strstr(cl_retver(), "rc")) {
117
-			if(strcmp(cl_retver(), pt)) {
117
+			if(strcmp(cl_retver(), newver)) {
118 118
 			    logg("^Your ClamAV installation is OUTDATED!\n");
119 119
 			    logg("^Local version: %s Recommended version: %s\n", cl_retver(), pt);
120 120
 			    logg("DON'T PANIC! Read http://www.clamav.net/faq.html\n");
121 121
 			    outdated = 1;
122 122
 			}
123 123
 		    }
124
-		    free(pt);
125 124
 		}
126 125
 
127 126
 	    } else {
... ...
@@ -146,20 +144,26 @@ int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, c
146 146
 
147 147
     memset(ipaddr, 0, sizeof(ipaddr));
148 148
 
149
-    if((ret = downloaddb(DB1NAME, "main.cvd", hostname, ipaddr, &signo, copt, dnsreply, localip, &outdated)) > 50) {
149
+    if((ret = downloaddb(DB1NAME, "main.cvd", hostname, ipaddr, &signo, copt, dnsreply, localip, outdated)) > 50) {
150 150
 	if(dnsreply)
151 151
 	    free(dnsreply);
152 152
 
153
+	if(newver)
154
+	    free(newver);
155
+
153 156
 	return ret;
154 157
 
155 158
     } else if(ret == 0)
156 159
 	updated = 1;
157 160
 
158 161
     /* if ipaddr[0] != 0 it will use it to connect to the web host */
159
-    if((ret = downloaddb(DB2NAME, "daily.cvd", hostname, ipaddr, &signo, copt, dnsreply, localip, &outdated)) > 50) {
162
+    if((ret = downloaddb(DB2NAME, "daily.cvd", hostname, ipaddr, &signo, copt, dnsreply, localip, outdated)) > 50) {
160 163
 	if(dnsreply)
161 164
 	    free(dnsreply);
162 165
 
166
+	if(newver)
167
+	    free(newver);
168
+
163 169
 	return ret;
164 170
 
165 171
     } else if(ret == 0)
... ...
@@ -207,17 +211,35 @@ int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, c
207 207
 	    arg = cpt->strarg;
208 208
 
209 209
 	if(arg) {
210
+		char *cmd = strdup(arg);
211
+
212
+	    if((pt = strstr(cmd, "%v")) && newver && isdigit(*newver)) {
213
+		    char *buffer = (char *) mcalloc(strlen(cmd) + strlen(newver) + 10, sizeof(char));
214
+		*pt = 0; pt += 2;
215
+		strcpy(buffer, cmd);
216
+		strcat(buffer, newver);
217
+		strcat(buffer, pt);
218
+		free(cmd);
219
+		cmd = strdup(buffer);
220
+		free(buffer);
221
+	    }
222
+
210 223
 	    if(optc(opt, 'd'))
211
-		execute("OnOutdatedExecute", arg);
224
+		execute("OnOutdatedExecute", cmd);
212 225
 	    else
213
-		system(arg);
226
+		system(cmd);
227
+
228
+	    free(cmd);
214 229
 	}
215 230
     }
216 231
 
232
+    if(newver)
233
+	free(newver);
234
+
217 235
     return updated ? 0 : 1;
218 236
 }
219 237
 
220
-int downloaddb(const char *localname, const char *remotename, const char *hostname, char *ip, int *signo, const struct cfgstruct *copt, const char *dnsreply, char *localip, int *outdated)
238
+int downloaddb(const char *localname, const char *remotename, const char *hostname, char *ip, int *signo, const struct cfgstruct *copt, const char *dnsreply, char *localip, int outdated)
221 239
 {
222 240
 	struct cl_cvd *current, *remote;
223 241
 	struct cfgstruct *cpt;
... ...
@@ -325,12 +347,11 @@ int downloaddb(const char *localname, const char *remotename, const char *hostna
325 325
     if(!nodb && (current->version >= dbver)) {
326 326
 	logg("%s is up to date (version: %d, sigs: %d, f-level: %d, builder: %s)\n", localname, current->version, current->sigs, current->fl, current->builder);
327 327
 
328
-	if(!*outdated && flevel < current->fl) {
328
+	if(!outdated && flevel < current->fl) {
329 329
 	    /* display warning even for already installed database */
330
-	    logg("^Your ClamAV installation is OUTDATED!\n");
331 330
 	    logg("^Current functionality level = %d, recommended = %d\n", flevel, current->fl);
331
+	    logg("Please check if ClamAV tools are linked against proper version of libclamav\n");
332 332
 	    logg("DON'T PANIC! Read http://www.clamav.net/faq.html\n");
333
-	    *outdated = 1;
334 333
 	}
335 334
 
336 335
 	*signo += current->sigs;
... ...
@@ -24,7 +24,7 @@
24 24
 
25 25
 int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, const char *hostname);
26 26
 
27
-int downloaddb(const char *localname, const char *remotename, const char *hostname, char *ip, int *signo, const struct cfgstruct *copt, const char *dnsreply, char *localip, int *outdated);
27
+int downloaddb(const char *localname, const char *remotename, const char *hostname, char *ip, int *signo, const struct cfgstruct *copt, const char *dnsreply, char *localip, int outdated);
28 28
 
29 29
 int wwwconnect(const char *server, const char *proxy, int pport, char *remoteip, char *localip);
30 30