示例#1
0
END_TEST

static void setup_proto2_some_things(struct asfd *asfd, struct slist *slist)
{
	struct sbuf *s;
	struct stat statp_dir;
	struct stat statp_file;
	int r=0; int w=0;
	fail_unless(!lstat(BASE, &statp_dir));
	fail_unless(!lstat(BASE "/burp.conf", &statp_file));
	asfd_assert_write(asfd, &w, 0, CMD_GEN, "restore :");
	asfd_mock_read(asfd, &r, 0, CMD_GEN, "ok");
	asfd_mock_read(asfd, &r, 0, CMD_GEN, "restore_stream");
	asfd_assert_write(asfd, &w, 0, CMD_GEN, "restore_stream_ok");
	for(s=slist->head; s; s=s->next)
	{
		s->winattr=0;
		s->compression=0;
		if(s->path.cmd==CMD_DIRECTORY)
		{
			memcpy(&s->statp, &statp_dir, sizeof(statp_dir));
			attribs_encode(s);
		}
		if(sbuf_is_link(s))
		{
			char path[256];
			if(s->path.cmd==CMD_HARD_LINK)
				snprintf(path, sizeof(path), "%s", s->link.buf);
			else
			{
				char *cp;
				snprintf(path, sizeof(path), "%s", s->path.buf);
				fail_unless((cp=strrchr(path, '/'))!=NULL);
				cp++;
				snprintf(cp, strlen(s->link.buf)+1, "%s",
					s->link.buf);
			}
			build_file(path, NULL);
			
			memcpy(&s->statp, &statp_file, sizeof(statp_file));
			attribs_encode(s);
			asfd_mock_read_iobuf(asfd, &r, 0, &s->attr);
			asfd_mock_read_iobuf(asfd, &r, 0, &s->path);
			asfd_mock_read_iobuf(asfd, &r, 0, &s->link);
		}
		else if(sbuf_is_filedata(s))
		{
			memcpy(&s->statp, &statp_file, sizeof(statp_file));
			attribs_encode(s);
			asfd_mock_read_iobuf(asfd, &r, 0, &s->attr);
			asfd_mock_read_iobuf(asfd, &r,
				0, &s->path);
			asfd_mock_read(asfd, &r, 0, CMD_DATA, "data");
		}
	}
	asfd_mock_read(asfd, &r, 0, CMD_GEN, "restoreend");
	asfd_assert_write(asfd, &w, 0, CMD_GEN, "restoreend ok");
}
示例#2
0
static void setup_reads_from_slist_blks(struct asfd *asfd,
	int *ar, struct slist *slist, int number_of_blks, uint64_t interrupt)
{
	struct sbuf *s;
	struct blk blk;
	struct iobuf iobuf;
	uint64_t file_no=1;
	if(!slist) return;
	for(s=slist->head; s; s=s->next)
	{
		if(sbuf_is_filedata(s)
		  && !sbuf_is_encrypted(s)) // Not working for proto2 yet.
		{
			int b;
			if(interrupt==file_no++)
				continue;
			blk_to_iobuf_sig(&blk, &iobuf);
			for(b=0; b<number_of_blks; b++)
			{
				iobuf_from_str(&iobuf, CMD_DATA,
					(char *)"some data");
				asfd_mock_read_iobuf(asfd, ar, 0, &iobuf);
			}
		}
	}
}
示例#3
0
static void setup_chfd_reads_from_slist_blks_not_got(struct asfd *chfd,
	int *cr, struct slist *slist, int number_of_blks, uint64_t interrupt)
{
	int blk_index=1;
	uint64_t file_no=1;
	struct blk blk;
	struct iobuf iobuf;
	struct sbuf *s;
	if(!slist) return;
	for(s=slist->head; s; s=s->next)
	{
		if(sbuf_is_filedata(s)
		  && !sbuf_is_encrypted(s)) // Not working for proto2 yet.
		{
			int b;
			if(interrupt==file_no++)
				continue;
			for(b=0; b<number_of_blks; b++)
			{
				blk.index=blk_index++;
				blk_to_iobuf_wrap_up(&blk, &iobuf);
				asfd_mock_read_iobuf(chfd, cr, 0, &iobuf);
			}
		}
	}
}
示例#4
0
static void setup_reads_from_slist(struct asfd *asfd,
	int *ar, struct slist *slist, int number_of_blks, uint64_t interrupt)
{
	int file_no=1;
	struct sbuf *s;
	struct blk blk;
	struct iobuf iobuf;
	if(!slist) return;
	for(s=slist->head; s; s=s->next)
	{
		if(sbuf_is_filedata(s)
		  && !sbuf_is_encrypted(s)) // Not working for proto2 yet.
		{
			int b;
			s->protocol2->index=file_no++;
			if(interrupt==s->protocol2->index)
			{
				char buf[32]="";
				asfd_mock_read(asfd,
					ar, 0, CMD_WARNING, "path vanished\n");
				base64_from_uint64(interrupt, buf);
				asfd_mock_read(asfd, ar, 0, CMD_INTERRUPT,
					buf);
				continue;
			}
			iobuf_free_content(&s->attr);
			attribs_encode(s);
			asfd_mock_read(asfd,
				ar, 0, CMD_ATTRIBS_SIGS, s->attr.buf);
			blk.fingerprint=file_no;
			memset(&blk.md5sum, file_no, MD5_DIGEST_LENGTH);
			blk_to_iobuf_sig(&blk, &iobuf);
			for(b=0; b<number_of_blks; b++)
				asfd_mock_read_iobuf(asfd, ar, 0, &iobuf);
		}
	}
}
示例#5
0
static void setup_proto1_some_things(struct asfd *asfd, struct slist *slist)
{
	struct sbuf *s;
	struct stat statp_dir;
	struct stat statp_file;
	int r=0; int w=0;
	fail_unless(!lstat(BASE, &statp_dir));
	fail_unless(!lstat(BASE "/burp.conf", &statp_file));
	asfd_assert_write(asfd, &w, 0, CMD_GEN, "restore :");
	asfd_mock_read(asfd, &r, 0, CMD_GEN, "ok");
	for(s=slist->head; s; s=s->next)
	{
		s->winattr=0;
		s->compression=0;
		if(s->path.cmd==CMD_DIRECTORY)
		{
			memcpy(&s->statp, &statp_dir, sizeof(statp_dir));
			attribs_encode(s);
		}
		if(sbuf_is_link(s))
		{
			char path[256];
			if(s->path.cmd==CMD_HARD_LINK)
				snprintf(path, sizeof(path), "%s", s->link.buf);
			else
			{
				char *cp;
				snprintf(path, sizeof(path), "%s", s->path.buf);
				fail_unless((cp=strrchr(path, '/'))!=NULL);
				cp++;
				snprintf(cp, strlen(s->link.buf)+1, "%s",
					s->link.buf);
			}
			build_file(path, NULL);
			
			memcpy(&s->statp, &statp_file, sizeof(statp_file));
			attribs_encode(s);
			asfd_mock_read_iobuf(asfd, &r, 0, &s->attr);
			asfd_mock_read_iobuf(asfd, &r, 0, &s->path);
			asfd_mock_read_iobuf(asfd, &r, 0, &s->link);
		}
		else if(sbuf_is_filedata(s))
		{
			struct iobuf rbuf;
			// The string "data" gzipped.
			unsigned char gzipped_data[27] = {
				0x1f, 0x8b, 0x08, 0x08, 0xb4, 0x1e, 0x7f, 0x56,
				0x00, 0x03, 0x79, 0x00, 0x4b, 0x49, 0x2c, 0x49,
				0xe4, 0x02, 0x00, 0x82, 0xc5, 0xc1, 0xe6, 0x05,
				0x00, 0x00, 0x00
			};
			memcpy(&s->statp, &statp_file, sizeof(statp_file));
			attribs_encode(s);
			asfd_mock_read(asfd, &r,
				0, CMD_DATAPTH, s->path.buf);
			asfd_mock_read_iobuf(asfd, &r, 0, &s->attr);
			asfd_mock_read_iobuf(asfd, &r,
				0, &s->path);
			// Protocol1 always sends it gzipped.
			iobuf_set(&rbuf, CMD_APPEND,
				(char *)gzipped_data, sizeof(gzipped_data));
			asfd_mock_read_iobuf(asfd, &r, 0, &rbuf);
			asfd_mock_read(asfd, &r,
				0, CMD_END_FILE, "0:19201273128");
		}
	}
	asfd_mock_read(asfd, &r, 0, CMD_GEN, "restoreend");
	asfd_assert_write(asfd, &w, 0, CMD_GEN, "restoreend ok");
}