Browse code

handle "-" on non af_unix handle "-" without fdpass handle STREAM on af_unix

git-svn-id: file:///var/lib/svn/clamav-devel/branches/clamd-proto@4640 77e5149b-7576-45b1-b177-96237e5ba77b

aCaB authored on 2009/01/23 23:10:14
Showing 1 changed files
... ...
@@ -50,7 +50,9 @@
50 50
 
51 51
 #include "client.h"
52 52
 
53
-#define SOCKET_INET	AF_INET
53
+#ifndef INADDR_LOOPBACK
54
+#define INADDR_LOOPBACK 0x7f000001
55
+#endif
54 56
 
55 57
 int notremoved = 0, notmoved = 0;
56 58
 int printinfected = 0;
... ...
@@ -195,11 +197,13 @@ static int dsresult(int sockd, int scantype, const char *filename)
195 195
     case STREAM:
196 196
 	{
197 197
 	    int wsockd;
198
-
199
-	    if(!(fd = open(filename, O_RDONLY))) {
200
-		logg("!Open failed on %s.\n", filename);
198
+	    
199
+	    if(filename) {
200
+		if(!(fd = open(filename, O_RDONLY))) {
201
+		    logg("!Open failed on %s.\n", filename);
201 202
 		return -1;
202
-	    }
203
+		}
204
+	    } else fd = 0;
203 205
 	    if(sendln(sockd, "zSTREAM", 8)) return -1;
204 206
 	    if(!(len = recvln(&rcv, &bol, &eol)) || len < 7 || memcmp(bol, "PORT ", 5) || !(len = atoi(bol + 5))) return -1;
205 207
 	    strmsock.sin_port = htons(len);
... ...
@@ -246,9 +250,7 @@ static int dsresult(int sockd, int scantype, const char *filename)
246 246
 		    logg("!Open failed on %s.\n", filename);
247 247
 		    return -1;
248 248
 		}
249
-	    } else {
250
-		fd = 0;
251
-	    }
249
+	    } else fd = 0;
252 250
 	    if(sendln(sockd, "zFILDES", 8)) return -1;
253 251
 
254 252
 	    iov[0].iov_base = dummy;
... ...
@@ -343,6 +345,8 @@ static int isremote(const struct optstruct *opts) {
343 343
 	nixsock.sun_path[sizeof(nixsock.sun_path)-1]='\0';
344 344
 	mainsa = (struct sockaddr *)&nixsock;
345 345
 	mainsasz = sizeof(nixsock);
346
+	strmsock.sin_family = AF_INET;
347
+	strmsock.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
346 348
 	optfree(clamdopts);
347 349
 	return 0;
348 350
     }
... ...
@@ -510,7 +514,7 @@ int client(const struct optstruct *opts, int *infected)
510 510
 {
511 511
 	const char *clamd_conf = optget(opts, "config-file")->strarg;
512 512
 	struct optstruct *clamdopts;
513
-	int scantype, session = 0, errors = 0, scandash = 0;
513
+	int remote, scantype, session = 0, errors = 0, scandash = 0;
514 514
 
515 515
     if((clamdopts = optparse(clamd_conf, 0, NULL, 1, OPT_CLAMD, 0, NULL)) == NULL) {
516 516
 	logg("!Can't parse clamd configuration file %s\n", clamd_conf);
... ...
@@ -518,15 +522,18 @@ int client(const struct optstruct *opts, int *infected)
518 518
     }
519 519
 
520 520
     scandash = (opts->filename && opts->filename[0] && !strcmp(opts->filename[0], "-") && !opts->filename[1]);
521
-    if(isremote(opts)) {
522
-	scantype = STREAM;
523
-	session = optget(opts, "multiscan")->enabled;
521
+    remote = isremote(opts);
524 522
 #ifdef HAVE_FD_PASSING
525
-    } else if(optget(clamdopts, "LocalSocket")->enabled && (optget(opts, "fdpass")->enabled || scandash)) {
523
+    if(!remote && optget(clamdopts, "LocalSocket")->enabled && (optget(opts, "fdpass")->enabled || scandash)) {
526 524
 	scantype = FILDES;
527 525
 	session = optget(opts, "multiscan")->enabled;
528 526
 	scandash <<= 1;
527
+    } else 
529 528
 #endif
529
+    if(remote || scandash) {
530
+	scantype = STREAM;
531
+	session = optget(opts, "multiscan")->enabled;
532
+	scandash <<=1;
530 533
     } else if(optget(opts, "multiscan")->enabled) scantype = MULTI;
531 534
     else scantype = CONT;
532 535
 
... ...
@@ -539,9 +546,9 @@ int client(const struct optstruct *opts, int *infected)
539 539
 
540 540
     *infected = 0;
541 541
 
542
-    if(scandash == 2) {
542
+    if(scandash) {
543 543
 	int sockd, ret;
544
-	if((sockd = dconnect()) >= 0 && (ret = dsresult(sockd, FILDES, NULL)) >= 0)
544
+	if((sockd = dconnect()) >= 0 && (ret = dsresult(sockd, scantype, NULL)) >= 0)
545 545
 	    *infected += ret;
546 546
 	else
547 547
 	    errors++;
... ...
@@ -550,7 +557,7 @@ int client(const struct optstruct *opts, int *infected)
550 550
 	unsigned int i;
551 551
 	for (i = 0; opts->filename[i]; i++) {
552 552
 	    if(!strcmp(opts->filename[i], "-")) {
553
-		logg("!Standard input scan requires FD passing support and \"-\" must be the only file argument\n");
553
+		logg("!Scanning from standard input requires \"-\" to be the only file argument\n");
554 554
 		continue;
555 555
 	    }
556 556
 	    client_scan(opts->filename[i], scantype, infected, &errors);