Browse code

fix gcc -W* warnings

git-svn: trunk@2914

Tomasz Kojm authored on 2007/03/07 01:31:49
Showing 9 changed files
... ...
@@ -1,3 +1,7 @@
1
+Tue Mar  6 15:36:47 CET 2007 (tk)
2
+---------------------------------
3
+  * clamd: fix gcc -W* warnings
4
+
1 5
 Tue Mar  6 01:01:32 CET 2007 (tk)
2 6
 ---------------------------------
3 7
   * libclamav: fix some gcc -W* warnings
... ...
@@ -84,7 +84,8 @@ static void help(void)
84 84
 
85 85
 int main(int argc, char **argv)
86 86
 {
87
-	struct cfgstruct *copt, *cpt;
87
+	struct cfgstruct *copt;
88
+	const struct cfgstruct *cpt;
88 89
         struct passwd *user;
89 90
 	time_t currtime;
90 91
 	struct cl_engine *engine = NULL;
... ...
@@ -98,7 +98,7 @@ void virusaction(const char *filename, const char *virname, const struct cfgstru
98 98
 void virusaction(const char *filename, const char *virname, const struct cfgstruct *copt)
99 99
 {
100 100
 	pid_t pid;
101
-	struct cfgstruct *cpt;
101
+	const struct cfgstruct *cpt;
102 102
 
103 103
     if(!(cpt = cfgopt(copt, "VirusEvent"))->enabled)
104 104
 	return;
... ...
@@ -409,15 +409,16 @@ int scanfd(const int fd, unsigned long int *scanned, const struct cl_engine *eng
409 409
 
410 410
 int scanstream(int odesc, unsigned long int *scanned, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options, const struct cfgstruct *copt)
411 411
 {
412
-	int ret, portscan = 1000, sockfd, port = 0, acceptd;
413
-	int tmpd, bread, retval, timeout, btread, min_port, max_port;
414
-	long int size = 0, maxsize = 0;
412
+	int ret, sockfd, acceptd;
413
+	int tmpd, bread, retval, timeout, btread;
414
+	unsigned int port = 0, portscan = 1000, min_port, max_port;
415
+	unsigned long int size = 0, maxsize = 0;
415 416
 	short bound = 0, rnd_port_first = 1;
416 417
 	const char *virname;
417 418
 	char buff[FILEBUFF];
418 419
 	struct sockaddr_in server;
419 420
 	struct hostent he;
420
-	struct cfgstruct *cpt;
421
+	const struct cfgstruct *cpt;
421 422
 	char *tmpname;
422 423
 
423 424
 
... ...
@@ -477,7 +478,7 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_engine *en
477 477
 	return -1;
478 478
     } else {
479 479
 	listen(sockfd, 1);
480
-	if(mdprintf(odesc, "PORT %d\n", port) <= 0) {
480
+	if(mdprintf(odesc, "PORT %u\n", port) <= 0) {
481 481
 	    logg("!ScanStream: error transmitting port.\n");
482 482
 	    close(sockfd);
483 483
 	    return -1;
... ...
@@ -487,12 +488,12 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_engine *en
487 487
     switch(retval = poll_fd(sockfd, timeout, 0)) {
488 488
 	case 0: /* timeout */
489 489
 	    mdprintf(odesc, "Accept timeout. ERROR\n");
490
-	    logg("!ScanStream %d: accept timeout.\n", port);
490
+	    logg("!ScanStream %u: accept timeout.\n", port);
491 491
 	    close(sockfd);
492 492
 	    return -1;
493 493
 	case -1:
494 494
 	    mdprintf(odesc, "Accept poll. ERROR\n");
495
-	    logg("!ScanStream %d: accept poll failed.\n", port);
495
+	    logg("!ScanStream %u: accept poll failed.\n", port);
496 496
 	    close(sockfd);
497 497
 	    return -1;
498 498
     }
... ...
@@ -500,18 +501,18 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_engine *en
500 500
     if((acceptd = accept(sockfd, NULL, NULL)) == -1) {
501 501
 	close(sockfd);
502 502
 	mdprintf(odesc, "accept() ERROR\n");
503
-	logg("!ScanStream %d: accept() failed.\n", port);
503
+	logg("!ScanStream %u: accept() failed.\n", port);
504 504
 	return -1;
505 505
     }
506 506
 
507
-    logg("*Accepted connection on port %d, fd %d\n", port, acceptd);
507
+    logg("*Accepted connection on port %u, fd %d\n", port, acceptd);
508 508
 
509 509
     if ((tmpname = cli_gentempdesc(NULL, &tmpd)) == NULL) {
510 510
 	shutdown(sockfd, 2);
511 511
 	close(sockfd);
512 512
 	close(acceptd);
513 513
 	mdprintf(odesc, "tempfile() failed. ERROR\n");
514
-	logg("!ScanStream %d: Can't create temporary file.\n", port);
514
+	logg("!ScanStream %u: Can't create temporary file.\n", port);
515 515
 	return -1;
516 516
     }
517 517
 
... ...
@@ -530,7 +531,7 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_engine *en
530 530
 	    closesocket(sockfd);
531 531
 	    closesocket(acceptd);
532 532
 	    mdprintf(odesc, "Temporary file -> write ERROR\n");
533
-	    logg("!ScanStream %d: Can't write to temporary file.\n", port);
533
+	    logg("!ScanStream %u: Can't write to temporary file.\n", port);
534 534
 	    close(tmpd);
535 535
 	    if(!cfgopt(copt, "LeaveTemporaryFiles")->enabled)
536 536
 		unlink(tmpname);
... ...
@@ -542,7 +543,7 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_engine *en
542 542
 	    btread = (maxsize - size); /* only read up to max */
543 543
 
544 544
 	    if(btread <= 0) {
545
-		logg("^ScanStream %d: Size limit reached (max: %d)\n", port, maxsize);
545
+		logg("^ScanStream %u: Size limit reached (max: %lu)\n", port, maxsize);
546 546
 	    	break; /* Scan what we have */
547 547
 	    }
548 548
 	}
... ...
@@ -551,11 +552,11 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_engine *en
551 551
     switch(retval) {
552 552
 	case 0: /* timeout */
553 553
 	    mdprintf(odesc, "read timeout ERROR\n");
554
-	    logg("!ScanStream %d: read timeout.\n", port);
554
+	    logg("!ScanStream %u: read timeout.\n", port);
555 555
 	    break;
556 556
 	case -1:
557 557
 	    mdprintf(odesc, "read poll ERROR\n");
558
-	    logg("!ScanStream %d: read poll failed.\n", port);
558
+	    logg("!ScanStream %u: read poll failed.\n", port);
559 559
 	    break;
560 560
     }
561 561
 
... ...
@@ -575,17 +576,17 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_engine *en
575 575
 
576 576
     if(ret == CL_VIRUS) {
577 577
 	mdprintf(odesc, "stream: %s FOUND\n", virname);
578
-	logg("stream %d: %s FOUND\n", port, virname);
578
+	logg("stream %u: %s FOUND\n", port, virname);
579 579
 	virusaction("stream", virname, copt);
580 580
     } else if(ret != CL_CLEAN) {
581 581
     	if(retval == 1) {
582 582
 	    mdprintf(odesc, "stream: %s ERROR\n", cl_strerror(ret));
583
-	    logg("stream %d: %s ERROR\n", port, cl_strerror(ret));
583
+	    logg("stream %u: %s ERROR\n", port, cl_strerror(ret));
584 584
 	}
585 585
     } else {
586 586
 	mdprintf(odesc, "stream: OK\n");
587 587
         if(logok)
588
-	    logg("stream %d: OK\n", port); 
588
+	    logg("stream %u: OK\n", port); 
589 589
     }
590 590
 
591 591
     return ret;
... ...
@@ -249,7 +249,7 @@ static struct cl_engine *reload_db(struct cl_engine *engine, unsigned int dbopti
249 249
 	*ret = 1;
250 250
 	return NULL;
251 251
     }
252
-    logg("Database correctly reloaded (%d signatures)\n", sigs);
252
+    logg("Database correctly reloaded (%u signatures)\n", sigs);
253 253
 
254 254
     return engine;
255 255
 }
... ...
@@ -268,7 +268,7 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_engine *engine, unsigne
268 268
 	sigset_t sigset;
269 269
 #endif
270 270
 	client_conn_t *client_conn;
271
-	struct cfgstruct *cpt;
271
+	const struct cfgstruct *cpt;
272 272
 #ifdef HAVE_STRERROR_R
273 273
 	char buff[BUFFSIZE + 1];
274 274
 #endif
... ...
@@ -299,13 +299,13 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_engine *engine, unsigne
299 299
 	if((fd = fopen(cpt->strarg, "w")) == NULL) {
300 300
 	    logg("!Can't save PID in file %s\n", cpt->strarg);
301 301
 	} else {
302
-	    fprintf(fd, "%d", (int) mainpid);
302
+	    fprintf(fd, "%u", (unsigned int) mainpid);
303 303
 	    fclose(fd);
304 304
 	}
305 305
 	umask(old_umask);
306 306
     }
307 307
 
308
-    logg("*Listening daemon: PID: %d\n", getpid());
308
+    logg("*Listening daemon: PID: %u\n", (unsigned int) mainpid);
309 309
     max_threads = cfgopt(copt, "MaxThreads")->numarg;
310 310
 
311 311
     if(cfgopt(copt, "ScanArchive")->enabled) {
... ...
@@ -314,25 +314,25 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_engine *engine, unsigne
314 314
 	memset(&limits, 0, sizeof(struct cl_limits));
315 315
 
316 316
 	if((limits.maxfilesize = cfgopt(copt, "ArchiveMaxFileSize")->numarg)) {
317
-	    logg("Archive: Archived file size limit set to %d bytes.\n", limits.maxfilesize);
317
+	    logg("Archive: Archived file size limit set to %lu bytes.\n", limits.maxfilesize);
318 318
 	} else {
319 319
 	    logg("^Archive: File size limit protection disabled.\n");
320 320
 	}
321 321
 
322 322
 	if((limits.maxreclevel = cfgopt(copt, "ArchiveMaxRecursion")->numarg)) {
323
-	    logg("Archive: Recursion level limit set to %d.\n", limits.maxreclevel);
323
+	    logg("Archive: Recursion level limit set to %u.\n", limits.maxreclevel);
324 324
 	} else {
325 325
 	    logg("^Archive: Recursion level limit protection disabled.\n");
326 326
 	}
327 327
 
328 328
 	if((limits.maxfiles = cfgopt(copt, "ArchiveMaxFiles")->numarg)) {
329
-	    logg("Archive: Files limit set to %d.\n", limits.maxfiles);
329
+	    logg("Archive: Files limit set to %u.\n", limits.maxfiles);
330 330
 	} else {
331 331
 	    logg("^Archive: Files limit protection disabled.\n");
332 332
 	}
333 333
 
334 334
 	if((limits.maxratio = cfgopt(copt, "ArchiveMaxCompressionRatio")->numarg)) {
335
-	    logg("Archive: Compression ratio limit set to %d.\n", limits.maxratio);
335
+	    logg("Archive: Compression ratio limit set to %u.\n", limits.maxratio);
336 336
 	} else {
337 337
 	    logg("^Archive: Compression ratio limit disabled.\n");
338 338
 	}
... ...
@@ -463,7 +463,7 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_engine *engine, unsigne
463 463
     if(!selfchk) {
464 464
 	logg("Self checking disabled.\n");
465 465
     } else {
466
-	logg("Self checking every %d seconds.\n", selfchk);
466
+	logg("Self checking every %u seconds.\n", selfchk);
467 467
     }
468 468
 
469 469
     if(cfgopt(copt, "ClamukoScanOnAccess")->enabled)
... ...
@@ -56,7 +56,7 @@ int tcpserver(const struct cfgstruct *copt)
56 56
 {
57 57
 	struct sockaddr_in server;
58 58
 	int sockfd, backlog;
59
-	struct cfgstruct *taddr;
59
+	const struct cfgstruct *taddr;
60 60
 	struct hostent he;
61 61
 	char *estr, buf[1024];
62 62
 	int true = 1;
... ...
@@ -417,7 +417,19 @@ void freecfg(struct cfgstruct *copt)
417 417
     return;
418 418
 }
419 419
 
420
-struct cfgstruct *cfgopt(struct cfgstruct *copt, const char *optname)
420
+const struct cfgstruct *cfgopt(const struct cfgstruct *copt, const char *optname)
421
+{
422
+    while(copt) {
423
+	if(copt->optname && !strcmp(copt->optname, optname))
424
+	    return copt;
425
+
426
+	copt = copt->next;
427
+    }
428
+
429
+    return NULL;
430
+}
431
+
432
+static struct cfgstruct *cfgopt_i(struct cfgstruct *copt, const char *optname)
421 433
 {
422 434
     while(copt) {
423 435
 	if(copt->optname && !strcmp(copt->optname, optname))
... ...
@@ -456,7 +468,7 @@ static int regcfg(struct cfgstruct **copt, const char *optname, char *strarg, in
456 456
     if(numarg != -1 && numarg != 0)
457 457
 	newnode->enabled = 1;
458 458
 
459
-    if((pt = cfgopt(*copt, optname))) {
459
+    if((pt = cfgopt_i(*copt, optname))) {
460 460
 	if(pt->multiple) {
461 461
 
462 462
 	    if(pt->enabled) {
... ...
@@ -54,7 +54,7 @@ struct cfgstruct {
54 54
 extern struct cfgoption cfg_options[];
55 55
 
56 56
 struct cfgstruct *getcfg(const char *cfgfile, int verbose);
57
-struct cfgstruct *cfgopt(struct cfgstruct *copt, const char *optname);
57
+const struct cfgstruct *cfgopt(const struct cfgstruct *copt, const char *optname);
58 58
 void freecfg(struct cfgstruct *copt);
59 59
 
60 60
 #endif
... ...
@@ -58,7 +58,8 @@
58 58
 char *freshdbdir(void)
59 59
 {
60 60
 	struct cl_cvd *d1, *d2;
61
-	struct cfgstruct *copt = NULL, *cpt;
61
+	struct cfgstruct *copt;
62
+	const struct cfgstruct *cpt;
62 63
 	struct stat foo;
63 64
 	const char *dbdir;
64 65
 	char *retdir;