Exemple #1
0
char *get_endfile_str(uint64_t bytes, uint8_t *checksum)
{
	static char endmsg[128]="";
	snprintf(endmsg, sizeof(endmsg), "%" PRIu64 ":%s",
			(uint64_t)bytes,
			checksum?bytes_to_md5str(checksum):"");
	return endmsg;
}
Exemple #2
0
static char *sig_to_msg(struct blk *blk, int save_path)
{
	static char msg[128];
	snprintf(msg, sizeof(msg),
		"%016"PRIX64 "%s%s",
		blk->fingerprint,
		bytes_to_md5str(blk->md5sum),
		save_path?bytes_to_savepathstr_with_sig(blk->savepath):"");
	return msg;
}
Exemple #3
0
static int parse_cmd(struct iobuf *rbuf, struct blk *blk)
{
	int ret=-1;

	printf("%c%04X", rbuf->cmd, (unsigned int)rbuf->len);
	switch(rbuf->cmd)
	{
		case CMD_SIG:
			if(blk_set_from_iobuf_sig_and_savepath(blk, rbuf))
				goto end;
			printf("%016" PRIX64 "%s%s\n",
				blk->fingerprint,
				bytes_to_md5str(blk->md5sum),
				uint64_to_savepathstr_with_sig(blk->savepath));
			break;
		case CMD_FINGERPRINT:
			if(blk_set_from_iobuf_fingerprint(blk, rbuf))
				goto end;
			printf("%016" PRIX64 "\n", blk->fingerprint);
			break;
		case CMD_SAVE_PATH:
			if(blk_set_from_iobuf_savepath(blk, rbuf))
				goto end;
			printf("%s\n", uint64_to_savepathstr(blk->savepath));
			break;
		case CMD_DATA:
			logp("\n%s looks like a data file\n", path);
			goto end;
/*
	FIX THIS - give a flag to tell it to decode attributes.
		case CMD_ATTRIBS:
			memcpy(&sb->attr, rbuf, sizeof(struct iobuf));
			attribs_decode(sb);
			printf("compression: %d\n", sb->compression);
			break;
*/
		default:
			printf("%s\n", rbuf->buf);
			break;
	}
	ret=0;
end:
	return ret;
}
Exemple #4
0
int protocol2_extra_restore_stream_bits(struct asfd *asfd, struct blk *blk,
	struct slist *slist, enum action act,
	struct sbuf *need_data, int last_ent_was_dir, struct cntr *cntr)
{
	int ret=-1;
	if(need_data->path.buf)
	{
		ret=send_data(asfd, blk, act, need_data, cntr);
	}
	else if(last_ent_was_dir)
	{
		// Careful, blk is not allocating blk->data and the data there
		// can get changed if we try to keep it for later. So, need to
		// allocate new space and copy the bytes.
		struct blk *nblk;
		struct sbuf *xb;
		if(!(nblk=blk_alloc_with_data(blk->length)))
			goto end;
		nblk->length=blk->length;
		memcpy(nblk->data, blk->data, blk->length);
		xb=slist->head;
		if(!xb->protocol2->bstart)
			xb->protocol2->bstart=xb->protocol2->bend=nblk;
		else
		{
			xb->protocol2->bend->next=nblk;
			xb->protocol2->bend=nblk;
		}
		ret=0;
	}
	else
	{
		logw(asfd, cntr,
			"Unexpected signature in manifest: %016" PRIX64 "%s%s\n",
			blk->fingerprint,
			bytes_to_md5str(blk->md5sum),
			uint64_to_savepathstr_with_sig(blk->savepath));
	}
end:
	blk->data=NULL;
	return ret;
}
Exemple #5
0
static int append_for_champ_chooser(struct asfd *chfd,
	struct blist *blist, int sigs_end)
{
	static int finished_sending=0;
	static struct iobuf *wbuf=NULL;
	if(!wbuf)
	{
		if(!(wbuf=iobuf_alloc())
		  || !(wbuf->buf=(char *)malloc_w(128, __func__)))
			return -1;
		wbuf->cmd=CMD_SIG;
	}
	while(blist->blk_for_champ_chooser)
	{
		// FIX THIS: This should not need to be done quite like this.
		// Make weak/strong into uint64 and uint8_t array, then
		// send them unconverted.
		wbuf->len=snprintf(wbuf->buf, 128,
#ifdef HAVE_WIN32
			"%016I64X%s",
#else
			"%016lX%s",
#endif
			blist->blk_for_champ_chooser->fingerprint,
			bytes_to_md5str(blist->blk_for_champ_chooser->md5sum));

		if(chfd->append_all_to_write_buffer(chfd, wbuf))
			return 0; // Try again later.
		blist->blk_for_champ_chooser=blist->blk_for_champ_chooser->next;
	}
	if(sigs_end && !finished_sending && !blist->blk_for_champ_chooser)
	{
		wbuf->cmd=CMD_GEN;
		wbuf->len=snprintf(wbuf->buf, 128, "%s", "sigs_end");
		if(chfd->append_all_to_write_buffer(chfd, wbuf))
			return 0; // Try again later.
		finished_sending++;
	}
	return 0;
}
Exemple #6
0
static int parse_cmd(struct iobuf *rbuf, struct blk *blk)
{
	int ret=-1;

	printf("%c%04lX", rbuf->cmd, rbuf->len);
	switch(rbuf->cmd)
	{
		case CMD_SIG:
			if(blk_set_from_iobuf_sig_and_savepath(blk, rbuf))
				goto end;
			printf("%016"PRIX64"%s%s\n",
				blk->fingerprint,
				bytes_to_md5str(blk->md5sum),
				uint64_to_savepathstr_with_sig(blk->savepath));
			break;
		case CMD_FINGERPRINT:
			if(blk_set_from_iobuf_fingerprint(blk, rbuf))
				goto end;
			printf("%016"PRIX64"\n", blk->fingerprint);
			break;
		case CMD_SAVE_PATH:
			if(blk_set_from_iobuf_savepath(blk, rbuf))
				goto end;
			printf("%s\n", uint64_to_savepathstr(blk->savepath));
			break;
		case CMD_DATA:
			logp("\n%s looks like a data file\n", path);
			goto end;
		default:
			printf("%s\n", rbuf->buf);
			break;
	}
	ret=0;
end:
	return ret;;
}
Exemple #7
0
static int verify_file(struct asfd *asfd, struct sbuf *sb,
	int patches, const char *best,
	uint64_t *bytes, struct cntr *cntr)
{
	MD5_CTX md5;
	size_t b=0;
	const char *cp=NULL;
	const char *newsum=NULL;
	uint8_t in[ZCHUNK];
	uint8_t checksum[MD5_DIGEST_LENGTH];
	uint64_t cbytes=0;
	struct fzp *fzp=NULL;

	if(!(cp=strrchr(sb->endfile.buf, ':')))
	{
		logw(asfd, cntr,
			"%s has no md5sum!\n", sb->protocol1->datapth.buf);
		return 0;
	}
	cp++;
	if(!MD5_Init(&md5))
	{
		logp("MD5_Init() failed\n");
		return -1;
	}
	if(patches
	  || sb->path.cmd==CMD_ENC_FILE
	  || sb->path.cmd==CMD_ENC_METADATA
	  || sb->path.cmd==CMD_EFS_FILE
	  || sb->path.cmd==CMD_ENC_VSS
	  || (!patches && !dpth_protocol1_is_compressed(sb->compression, best)))
		fzp=fzp_open(best, "rb");
	else
		fzp=fzp_gzopen(best, "rb");

	if(!fzp)
	{
		logw(asfd, cntr, "could not open %s\n", best);
		return 0;
	}
	while((b=fzp_read(fzp, in, ZCHUNK))>0)
	{
		cbytes+=b;
		if(!MD5_Update(&md5, in, b))
		{
			logp("MD5_Update() failed\n");
			fzp_close(&fzp);
			return -1;
		}
	}
	if(!fzp_eof(fzp))
	{
		logw(asfd, cntr, "error while reading %s\n", best);
		fzp_close(&fzp);
		return 0;
	}
	fzp_close(&fzp);
	if(!MD5_Final(checksum, &md5))
	{
		logp("MD5_Final() failed\n");
		return -1;
	}
	newsum=bytes_to_md5str(checksum);

	if(strcmp(newsum, cp))
	{
		logp("%s %s\n", newsum, cp);
		logw(asfd, cntr, "md5sum for '%s (%s)' did not match!\n",
			sb->path.buf, sb->protocol1->datapth.buf);
		logp("md5sum for '%s (%s)' did not match!\n",
			sb->path.buf, sb->protocol1->datapth.buf);
		return 0;
	}
	*bytes+=cbytes;

	// Just send the file name to the client, so that it can show cntr.
	if(asfd->write(asfd, &sb->path)) return -1;
	return 0;
}