Esempio n. 1
0
int cli_scannulsft(cli_ctx *ctx, off_t offset) {
        int ret;
	struct nsis_st nsist;

    cli_dbgmsg("in scannulsft()\n");

    memset(&nsist, 0, sizeof(struct nsis_st));

    nsist.off = offset;
    if (!(nsist.dir = cli_gentemp(ctx->engine->tmpdir)))
        return CL_ETMPDIR;
    if(mkdir(nsist.dir, 0700)) {
	cli_dbgmsg("NSIS: Can't create temporary directory %s\n", nsist.dir);
	free(nsist.dir);
	return CL_ETMPDIR;
    }
    
    nsist.map = *ctx->fmap;
    if(ctx->engine->keeptmp) cli_dbgmsg("NSIS: Extracting files to %s\n", nsist.dir);

    do {
        ret = cli_nsis_unpack(&nsist, ctx);
        if (ret == CL_SUCCESS && nsist.opened == 0) {
            /* Don't scan a non-existent file */
            continue;
        }
	if (ret == CL_SUCCESS) {
	  cli_dbgmsg("NSIS: Successully extracted file #%u\n", nsist.fno);
	  if (lseek(nsist.ofd, 0, SEEK_SET) == -1) {
          cli_dbgmsg("NSIS: call to lseek() failed\n");
          free(nsist.dir);
        return CL_ESEEK;
      }
	  if(nsist.fno == 1)
	    ret=cli_scandesc(nsist.ofd, ctx, 0, 0, NULL, AC_SCAN_VIR, NULL);
	  else
	    ret=cli_magic_scandesc(nsist.ofd, ctx);
	  close(nsist.ofd);
	  if(!ctx->engine->keeptmp)
	    if(cli_unlink(nsist.ofn)) ret = CL_EUNLINK;
	} else if(ret == CL_EMAXSIZE) {
	    ret = nsist.solid ? CL_BREAK : CL_SUCCESS;
	}
    } while(ret == CL_SUCCESS);

    if(ret == CL_BREAK || ret == CL_EMAXFILES)
	ret = CL_CLEAN;

    nsis_shutdown(&nsist);

    if(!ctx->engine->keeptmp)
        cli_rmdirs(nsist.dir);

    free(nsist.dir);

    return ret;
}
int cli_scannulsft(int desc, cli_ctx *ctx, off_t offset) {
        int ret;
	struct nsis_st nsist;

    cli_dbgmsg("in scannulsft()\n");
    if(ctx->limits && ctx->limits->maxreclevel && ctx->arec >= ctx->limits->maxreclevel) {
        cli_dbgmsg("Archive recursion limit exceeded (arec == %u).\n", ctx->arec+1);
	return CL_EMAXREC;
    }

    memset(&nsist, 0, sizeof(struct nsis_st));

    nsist.ifd = desc;
    nsist.off = offset;
    if (!(nsist.dir = cli_gentemp(NULL)))
        return CL_ETMPDIR;
    if(mkdir(nsist.dir, 0700)) {
	cli_dbgmsg("NSIS: Can't create temporary directory %s\n", nsist.dir);
	free(nsist.dir);
	return CL_ETMPDIR;
    }

    if(cli_leavetemps_flag) cli_dbgmsg("NSIS: Extracting files to %s\n", nsist.dir);

    ctx->arec++;

    do {
        ret = cli_nsis_unpack(&nsist, ctx);
	if(ret != CL_SUCCESS) {
	    if(ret == CL_EMAXSIZE) {
	        if(BLOCKMAX) {
		    *ctx->virname = "NSIS.ExceededFileSize";
		    ret=CL_VIRUS;
		} else {
		    ret = nsist.solid ? CL_BREAK : CL_SUCCESS;
		}
	    }
	} else {
	    cli_dbgmsg("NSIS: Successully extracted file #%u\n", nsist.fno);
	    lseek(nsist.ofd, 0, SEEK_SET);
	    if(nsist.fno == 1)
	        ret=cli_scandesc(nsist.ofd, ctx, 0, 0, 0, NULL);
	    else
	        ret=cli_magic_scandesc(nsist.ofd, ctx);
	    close(nsist.ofd);
	    if(!cli_leavetemps_flag)
	        unlink(nsist.ofn);
	}
    } while(ret == CL_SUCCESS);

    if(ret == CL_BREAK)
	ret = CL_CLEAN;

    cli_nsis_free(&nsist);

    if(!cli_leavetemps_flag)
        cli_rmdirs(nsist.dir);

    free(nsist.dir);

    ctx->arec--;    
    return ret;
}