Ejemplo n.º 1
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;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
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;;
}
Ejemplo n.º 4
0
static int send_data(struct asfd *asfd, struct blk *blk,
	enum action act, struct sbuf *need_data, struct cntr *cntr)
{
	struct iobuf wbuf;

	switch(act)
	{
		case ACTION_RESTORE:
			iobuf_set(&wbuf, CMD_DATA, blk->data, blk->length);
			if(asfd->write(asfd, &wbuf)) return -1;
			return 0;
		case ACTION_VERIFY:
			// Need to check that the block has the correct
			// checksums.
			switch(blk_verify(blk->fingerprint, blk->md5sum,
				blk->data, blk->length))
			{
				case 1:
					iobuf_set(&wbuf, CMD_DATA, (char *)"0", 1);
					if(asfd->write(asfd, &wbuf)) return -1;
					cntr_add(cntr, CMD_DATA, 0);
					break; // All OK.
				case 0:
				{
					logw(asfd, cntr, "Checksum mismatch in block for %c:%s:%s\n", need_data->path.cmd, need_data->path.buf, uint64_to_savepathstr_with_sig(blk->savepath));
					break;
		
				}
				default:
				{
					char msg[256];
					snprintf(msg, sizeof(msg), "Error when attempting to verify block for %c:%s:%s\n", need_data->path.cmd, need_data->path.buf, uint64_to_savepathstr_with_sig(blk->savepath));
					return -1;
				}
			}
			return 0;
		default:
			logp("unknown action in %s: %d\n", __func__, act);
			return -1;
	}
}