Example #1
0
static int full_match(struct file *o, struct file *n,
	struct fzp **ofp, struct fzp **nfp)
{
	size_t ogot;
	size_t ngot;
	unsigned int i=0;
	static char obuf[FULL_CHUNK];
	static char nbuf[FULL_CHUNK];

	if(*ofp) fzp_seek(*ofp, 0, SEEK_SET);
	else if(!(*ofp=fzp_open(o->path, "rb")))
	{
		// Blank this entry so that it can be ignored from
		// now on.
		free_w(&o->path);
		return 0;
	}

	if(*nfp) fzp_seek(*nfp, 0, SEEK_SET);
	else if(!(*nfp=fzp_open(n->path, "rb"))) return 0;

	while(1)
	{
		ogot=fzp_read(*ofp, obuf, FULL_CHUNK);
		ngot=fzp_read(*nfp, nbuf, FULL_CHUNK);
		if(ogot!=ngot) return 0;
		for(i=0; i<ogot; i++)
			if(obuf[i]!=nbuf[i]) return 0;
		if(ogot<FULL_CHUNK) break;
	}

	return 1;
}
Example #2
0
int manio_seek(struct manio *manio, man_off_t *offset)
{
	fzp_close(&manio->fzp);
	man_off_t_memcpy(&manio->offset, offset);
	if(!(manio->fzp=fzp_gzopen(manio->offset.fpath, manio->mode)))
		return -1;
	return fzp_seek(manio->fzp, manio->offset.offset, SEEK_SET);
}
Example #3
0
int manio_seek(struct manio *manio, man_off_t *offset)
{
	fzp_close(&manio->fzp);
	if(!(manio->fzp=fzp_gzopen(offset->fpath, manio->mode))
	  || fzp_seek(manio->fzp, offset->offset, SEEK_SET))
		return -1;
	man_off_t_free_content(manio->offset);
	if(!(manio->offset->fpath=strdup_w(offset->fpath, __func__)))
		return -1;
	manio->offset->offset=offset->offset;
	manio->offset->fcount=offset->fcount;
	return 0;
}
Example #4
0
static int get_part_cksum(struct file *f, struct fzp **fzp)
{
	MD5_CTX md5;
	int got=0;
	static char buf[PART_CHUNK];
	unsigned char checksum[MD5_DIGEST_LENGTH+1];

	if(*fzp) fzp_seek(*fzp, 0, SEEK_SET);
	else if(!(*fzp=fzp_open(f->path, "rb")))
	{
		f->part_cksum=0;
		return 0;
	}

	if(!MD5_Init(&md5))
	{
		logp("MD5_Init() failed\n");
		return -1;
	}

	got=fzp_read(*fzp, buf, PART_CHUNK);

	if(!MD5_Update(&md5, buf, got))
	{
		logp("MD5_Update() failed\n");
		return -1;
	}

	if(!MD5_Final(checksum, &md5))
	{
		logp("MD5_Final() failed\n");
		return -1;
	}

	memcpy(&(f->part_cksum), checksum, sizeof(unsigned));

	// Try for a bit of efficiency - no need to calculate the full checksum
	// again if we already read the whole file.
	if(got<PART_CHUNK) f->full_cksum=f->part_cksum;

	return 0;
}
Example #5
0
static int get_full_cksum(struct file *f, struct fzp **fzp)
{
	size_t s=0;
	MD5_CTX md5;
	static char buf[FULL_CHUNK];
	unsigned char checksum[MD5_DIGEST_LENGTH+1];

	if(*fzp) fzp_seek(*fzp, 0, SEEK_SET);
	else if(!(*fzp=fzp_open(f->path, "rb")))
	{
		f->full_cksum=0;
		return 0;
	}

	if(!MD5_Init(&md5))
	{
		logp("MD5_Init() failed\n");
		return -1;
	}

	while((s=fzp_read(*fzp, buf, FULL_CHUNK))>0)
	{
		if(!MD5_Update(&md5, buf, s))
		{
			logp("MD5_Update() failed\n");
			return -1;
		}
		if(s<FULL_CHUNK) break;
	}

	if(!MD5_Final(checksum, &md5))
	{
		logp("MD5_Final() failed\n");
		return -1;
	}

	memcpy(&(f->full_cksum), checksum, sizeof(unsigned));

	return 0;
}
Example #6
0
END_TEST

START_TEST(test_protocol1_verify_file_gzip_read_failure)
{
	struct asfd *asfd;
	struct cntr *cntr;
	struct sbuf *sb;
	const char *path="somepath";
	const char *datapth="/datapth";
	const char *endfile="0:0";
	const char *best=BASE "/existent";
	const char *plain_text="some plain text";
	size_t s;
	struct fzp *fzp;
	s=strlen(plain_text);

	clean();
	cntr=setup_cntr();
	sb=setup_sbuf(path, datapth, endfile, 1/*compression*/);

	// Make a corrupt gzipped file.
	build_path_w(best);
	fail_unless((fzp=fzp_gzopen(best, "wb"))!=NULL);
	fail_unless(fzp_write(fzp, plain_text, s)==s);
	fail_unless(!fzp_close(&fzp));
	fail_unless((fzp=fzp_open(best, "r+b"))!=NULL);
	fail_unless(!fzp_seek(fzp, 10, SEEK_SET));
	fail_unless(fzp_write(fzp, "aa", 2)==2);
	fail_unless(!fzp_close(&fzp));

	asfd=asfd_mock_setup(&areads, &awrites);
	setup_error_while_reading(asfd, best);

	// Returns 0 so that the parent process continues.
	fail_unless(!verify_file(asfd, sb, 0 /*patches*/, best, cntr));
	fail_unless(cntr->ent[CMD_WARNING]->count==1);
	tear_down(&sb, &cntr, NULL, &asfd);
}