Browse code

cleanup

git-svn: trunk@2014

Tomasz Kojm authored on 2006/06/09 03:56:22
Showing 1 changed files
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 2003 - 2005 Tomasz Kojm <tkojm@clamav.net>
2
+ *  Copyright (C) 2003 - 2006 Tomasz Kojm <tkojm@clamav.net>
3 3
  *
4 4
  *  untgz() is based on public domain minitar utility by Charles G. Waldman
5 5
  *
... ...
@@ -244,22 +244,22 @@ struct cl_cvd *cl_cvdparse(const char *head)
244 244
 
245 245
 struct cl_cvd *cl_cvdhead(const char *file)
246 246
 {
247
-	FILE *fd;
247
+	FILE *fs;
248 248
 	char head[513];
249 249
 	int i;
250 250
 
251
-    if((fd = fopen(file, "rb")) == NULL) {
251
+    if((fs = fopen(file, "rb")) == NULL) {
252 252
 	cli_dbgmsg("Can't open CVD file %s\n", file);
253 253
 	return NULL;
254 254
     }
255 255
 
256
-    if((i = fread(head, 1, 512, fd)) != 512) {
256
+    if((i = fread(head, 1, 512, fs)) != 512) {
257 257
 	cli_dbgmsg("Short read (%d) while reading CVD head from %s\n", i, file);
258
-	fclose(fd);
258
+	fclose(fs);
259 259
 	return NULL;
260 260
     }
261 261
 
262
-    fclose(fd);
262
+    fclose(fs);
263 263
 
264 264
     head[512] = 0;
265 265
     for(i = 511; i > 0 && (head[i] == ' ' || head[i] == 10); head[i] = 0, i--);
... ...
@@ -276,14 +276,14 @@ void cl_cvdfree(struct cl_cvd *cvd)
276 276
     free(cvd);
277 277
 }
278 278
 
279
-static int cli_cvdverify(FILE *fd, struct cl_cvd *cvdpt)
279
+static int cli_cvdverify(FILE *fs, struct cl_cvd *cvdpt)
280 280
 {
281 281
 	struct cl_cvd *cvd;
282 282
 	char *md5, head[513];
283 283
 	int i;
284 284
 
285
-    fseek(fd, 0, SEEK_SET);
286
-    if(fread(head, 1, 512, fd) != 512) {
285
+    fseek(fs, 0, SEEK_SET);
286
+    if(fread(head, 1, 512, fs) != 512) {
287 287
 	cli_dbgmsg("Can't read CVD head from stream\n");
288 288
 	return CL_ECVD;
289 289
     }
... ...
@@ -297,7 +297,7 @@ static int cli_cvdverify(FILE *fd, struct cl_cvd *cvdpt)
297 297
     if(cvdpt)
298 298
 	memcpy(cvdpt, cvd, sizeof(struct cl_cvd));
299 299
 
300
-    md5 = cli_md5stream(fd, NULL);
300
+    md5 = cli_md5stream(fs, NULL);
301 301
     cli_dbgmsg("MD5(.tar.gz) = %s\n", md5);
302 302
 
303 303
     if(strncmp(md5, cvd->md5, 32)) {
... ...
@@ -323,26 +323,25 @@ static int cli_cvdverify(FILE *fd, struct cl_cvd *cvdpt)
323 323
 
324 324
 int cl_cvdverify(const char *file)
325 325
 {
326
-	FILE *fd;
326
+	FILE *fs;
327 327
 	int ret;
328 328
 
329
-    if((fd = fopen(file, "rb")) == NULL) {
329
+    if((fs = fopen(file, "rb")) == NULL) {
330 330
 	cli_errmsg("Can't open CVD file %s\n", file);
331 331
 	return CL_EOPEN;
332 332
     }
333 333
 
334
-    ret = cli_cvdverify(fd, NULL);
335
-    fclose(fd);
334
+    ret = cli_cvdverify(fs, NULL);
335
+    fclose(fs);
336 336
 
337 337
     return ret;
338 338
 }
339 339
 
340
-int cli_cvdload(FILE *fd, struct cl_engine **engine, unsigned int *signo, short warn, unsigned int options)
340
+int cli_cvdload(FILE *fs, struct cl_engine **engine, unsigned int *signo, short warn, unsigned int options)
341 341
 {
342
-        char *dir, *tmp, *buffer;
342
+        char *dir;
343 343
 	struct cl_cvd cvd;
344
-	int bytes, ret;
345
-	FILE *tmpd;
344
+	int ret;
346 345
 	time_t stime;
347 346
 
348 347
 
... ...
@@ -350,7 +349,7 @@ int cli_cvdload(FILE *fd, struct cl_engine **engine, unsigned int *signo, short
350 350
 
351 351
     /* verify */
352 352
 
353
-    if((ret = cli_cvdverify(fd, &cvd)))
353
+    if((ret = cli_cvdverify(fs, &cvd)))
354 354
 	return ret;
355 355
 
356 356
     if(cvd.stime && warn) {
... ...
@@ -370,66 +369,19 @@ int cli_cvdload(FILE *fd, struct cl_engine **engine, unsigned int *signo, short
370 370
 	cli_warnmsg("********************************************************\n");
371 371
     }
372 372
 
373
-    fseek(fd, 512, SEEK_SET);
373
+    fseek(fs, 512, SEEK_SET);
374 374
 
375 375
     dir = cli_gentemp(NULL);
376 376
     if(mkdir(dir, 0700)) {
377 377
 	cli_errmsg("cli_cvdload():  Can't create temporary directory %s\n", dir);
378
+	free(dir);
378 379
 	return CL_ETMPDIR;
379 380
     }
380 381
 
381
-    /* 
382
-    if(cli_untgz(fileno(fd), dir)) {
382
+    if(cli_untgz(dup(fileno(fs)), dir)) {
383 383
 	cli_errmsg("cli_cvdload(): Can't unpack CVD file.\n");
384 384
 	return CL_ECVDEXTR;
385 385
     }
386
-    */
387
-
388
-    /* FIXME: it seems there is some problem with current position indicator
389
-     * after gzdopen() call in cli_untgz(). Temporarily we need this wrapper:
390
-     */
391
-
392
-	    /* start */
393
-
394
-	    tmp = cli_gentemp(NULL);
395
-	    if((tmpd = fopen(tmp, "wb+")) == NULL) {
396
-		cli_errmsg("Can't create temporary file %s\n", tmp);
397
-		free(dir);
398
-		free(tmp);
399
-		return CL_ETMPFILE;
400
-	    }
401
-
402
-	    if(!(buffer = (char *) cli_malloc(FILEBUFF))) {
403
-		free(dir);
404
-		free(tmp);
405
-		fclose(tmpd);
406
-		return CL_EMEM;
407
-	    }
408
-
409
-	    while((bytes = fread(buffer, 1, FILEBUFF, fd)) > 0)
410
-		fwrite(buffer, 1, bytes, tmpd);
411
-
412
-	    free(buffer);
413
-
414
-	    fflush(tmpd);
415
-	    fseek(tmpd, 0L, SEEK_SET);
416
-
417
-	    if(cli_untgz(fileno(tmpd), dir)) {
418
-		perror("cli_untgz");
419
-		cli_errmsg("cli_cvdload(): Can't unpack CVD file.\n");
420
-		cli_rmdirs(dir);
421
-		free(dir);
422
-		fclose(tmpd);
423
-		unlink(tmp);
424
-		free(tmp);
425
-		return CL_ECVDEXTR;
426
-	    }
427
-
428
-	    fclose(tmpd);
429
-	    unlink(tmp);
430
-	    free(tmp);
431
-
432
-	    /* end */
433 386
 
434 387
     /* load extracted directory */
435 388
     cl_load(dir, engine, signo, options);