Пример #1
0
static void setup_asfds_happy_path_one_blk_per_file_no_dedup_interrupt(
	struct asfd *asfd, struct asfd *chfd, struct slist *slist)
{
	int ar=0, aw=0, cr=0, cw=0;

	setup_writes_from_slist(asfd, &aw, slist);
	asfd_assert_write(asfd, &aw, 0, CMD_GEN, "requests_end");
	asfd_mock_read_no_op(asfd, &ar, 30);
	setup_reads_from_slist(asfd, &ar, slist, 1, 2 /* interrupt */);
	asfd_mock_read(asfd, &ar, 0, CMD_GEN, "sigs_end");

	setup_writes_from_slist_blk_requests(asfd,
		&aw, slist, 1, 2 /* interrupt */);
	asfd_assert_write(asfd, &aw, 0, CMD_GEN, "blk_requests_end");
	asfd_mock_read_no_op(asfd, &ar, 60);
	setup_reads_from_slist_blks(asfd, &ar, slist, 1, 2 /* interrupt */);
	asfd_mock_read(asfd, &ar, 0, CMD_GEN, "backup_end");

	setup_chfd_writes_from_slist(chfd, &cw, slist, 1, 2 /* interrupt */);
	asfd_mock_read_no_op(chfd, &cr, 60);
	setup_chfd_reads_from_slist_blks_not_got(chfd,
		&cr, slist, 1, 2 /* interrupt */);
	asfd_mock_read_no_op(chfd, &cr, 60);
	asfd_assert_write(chfd, &cw, 0, CMD_GEN, "sigs_end");
}
Пример #2
0
static void setup_proto1_no_files(struct asfd *asfd, struct slist *slist)
{
	int r=0; int w=0;
	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, "restoreend");
	asfd_assert_write(asfd, &w, 0, CMD_GEN, "restoreend ok");
}
Пример #3
0
static void setup_read_fail_2(struct asfd *asfd)
{
	int r=0; int w=0;
	asfd_assert_write(asfd, &w,  0, CMD_GEN, "hello:" VERSION);
	asfd_mock_read(asfd, &r,  0, CMD_GEN, "whoareyou");
	asfd_assert_write(asfd, &w,  0, CMD_GEN, "testclient");
	asfd_mock_read(asfd, &r, -1, CMD_GEN, "okpassword");
}
Пример #4
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");
}
Пример #5
0
static void setup_stdout_header(struct asfd *so_asfd)
{
	int w=0;
	asfd_assert_write(so_asfd, &w, 0, CMD_GEN, "\n burp status");
	asfd_assert_write(so_asfd, &w, 0, CMD_GEN, "                                                ");
	asfd_assert_write(so_asfd, &w, 0, CMD_GEN, "1977-10-02 00:10:20");
	asfd_assert_write(so_asfd, &w, 0, CMD_GEN, "\n\n");
	asfd_assert_write(so_asfd, &w, 0, CMD_GEN, "\n");
}
Пример #6
0
static void setup_asfds_proto1_stuff(struct asfd *asfd, struct slist *slist)
{
	int r=0; int w=0;
	struct sbuf *s;
	for(s=slist->head; s; s=s->next)
	{
		if(sbuf_is_link(s))
		{
			asfd_assert_write_iobuf(asfd, &w, 0, &s->attr);
			asfd_assert_write_iobuf(asfd, &w, 0, &s->path);
			asfd_assert_write_iobuf(asfd, &w, 0, &s->link);
		}
		else if(sbuf_is_filedata(s))
		{
			struct iobuf wbuf;
			// The string "data" gzipped.
			unsigned char gzipped_data1[10] = {
				0x1f, 0x8b, 0x08, 0, 0,
				0, 0, 0, 0x02, 0x03
			};
			unsigned char gzipped_data2[14] = {
				0x4b, 0x49, 0x2c, 0x49, 0x04, 0x00, 0x63,
				0xf3, 0xf3, 0xad, 0x04, 0x00, 0x00, 0x00
			};
			asfd_assert_write_iobuf(asfd, &w,
				0, &s->protocol1->datapth);
			asfd_assert_write_iobuf(asfd, &w, 0, &s->attr);
			asfd_assert_write_iobuf(asfd, &w, 0, &s->path);
			if(sbuf_is_encrypted(s))
			{
				// Encrypted files get sent as is.
				asfd_assert_write(asfd, &w, 0, CMD_APPEND,
					"data");
				asfd_assert_write(asfd, &w, 0, CMD_END_FILE,
					"4:8d777f385d3dfec8815d20f7496026dc");
				continue;
			}
			// Protocol1 always sends it gzipped.
			iobuf_set(&wbuf, CMD_APPEND,
				(char *)gzipped_data1, sizeof(gzipped_data1));
			asfd_assert_write_iobuf(asfd, &w, 0, &wbuf);
			iobuf_set(&wbuf, CMD_APPEND,
				(char *)gzipped_data2, sizeof(gzipped_data2));
			asfd_assert_write_iobuf(asfd, &w, 0, &wbuf);
			asfd_assert_write(asfd, &w, 0, CMD_END_FILE,
				"4:8d777f385d3dfec8815d20f7496026dc");
		}
		else
		{
			asfd_assert_write_iobuf(asfd, &w, 0, &s->attr);
			asfd_assert_write_iobuf(asfd, &w, 0, &s->path);
		}
	}
	asfd_assert_write(asfd, &w, 0, CMD_GEN, "restoreend");
	asfd_mock_read_no_op(asfd, &r, 100);
	asfd_mock_read(asfd, &r, 0, CMD_GEN, "restoreend_ok");
}
Пример #7
0
static void setup_proto1_no_datapth(struct asfd *asfd, struct slist *slist)
{
	int r=0; int w=0;
	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_ATTRIBS, "attribs");
	asfd_mock_read(asfd, &r, 0, CMD_FILE, BASE "/afile");
	asfd_assert_write(asfd, &w, 0, CMD_ERROR, "datapth not supplied for f:utest_restore/afile in restore_switch_protocol1\n");
}
Пример #8
0
static void setup_proto1_no_attribs(struct asfd *asfd, struct slist *slist)
{
	int r=0; int w=0;
	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_DATAPTH, "datapth");
	asfd_mock_read(asfd, &r, 0, CMD_FILE, BASE "/afile");
	asfd_assert_write(asfd, &w, 0, CMD_ERROR, "read cmd with no attribs");
}
Пример #9
0
static void setup_asfd_1_2_3(struct asfd *asfd)
{
	int w=0;
	asfd_assert_write(asfd, &w, 0,
		CMD_TIMESTAMP, "0000001 1970-01-01 00:00:00");
	asfd_assert_write(asfd, &w, 0,
		CMD_TIMESTAMP, "0000002 1970-01-02 00:00:00");
	asfd_assert_write(asfd, &w, 0,
		CMD_TIMESTAMP, "0000003 1970-01-03 00:00:00");
}
Пример #10
0
static void setup_all_ok_server_version_empty(struct asfd *asfd)
{
	int r=0; int w=0;
	asfd_assert_write(asfd, &w, 0, CMD_GEN, "hello:" VERSION);
	asfd_mock_read(asfd, &r, 0, CMD_GEN, "whoareyou:");
	asfd_assert_write(asfd, &w, 0, CMD_GEN, "testclient");
	asfd_mock_read(asfd, &r, 0, CMD_GEN, "okpassword");
	asfd_assert_write(asfd, &w, 0, CMD_GEN, "password");
	asfd_mock_read(asfd, &r, 0, CMD_GEN, "ok");
}
Пример #11
0
static void setup_asfds_write_error_chfd(struct asfd *asfd, struct asfd *chfd,
	struct slist *slist)
{
	int ar=0, aw=0, cw=0;
	asfd_assert_write(asfd, &aw, 0, CMD_GEN, "requests_end");
	asfd_mock_read(asfd, &ar, 0, CMD_GEN, "sigs_end");
	asfd_assert_write(asfd, &aw, 0, CMD_GEN, "blk_requests_end");

	asfd_assert_write(chfd, &cw, -1, CMD_GEN, "sigs_end");
}
Пример #12
0
static void setup_all_ok_version_warning_read_error(struct asfd *asfd)
{
	int r=0; int w=0;
	asfd_assert_write(asfd, &w,  0, CMD_GEN, "hello:" VERSION);
	asfd_mock_read(asfd, &r,  0, CMD_GEN, "whoareyou:" VERSION);
	asfd_assert_write(asfd, &w,  0, CMD_GEN, "testclient");
	asfd_mock_read(asfd, &r,  0, CMD_GEN, "okpassword");
	asfd_assert_write(asfd, &w,  0, CMD_GEN, "password");
	asfd_mock_read(asfd, &r,  0, CMD_WARNING, "This is a version warning");
	asfd_mock_read(asfd, &r, -1, CMD_GEN, "ok");
}
Пример #13
0
END_TEST

static void setup_asfds_empty(struct asfd *asfd, struct asfd *chfd,
	struct slist *slist)
{
	int ar=0, aw=0, cw=0;
	asfd_assert_write(asfd, &aw, 0, CMD_GEN, "requests_end");
	asfd_mock_read(asfd, &ar, 0, CMD_GEN, "sigs_end");
	asfd_assert_write(asfd, &aw, 0, CMD_GEN, "blk_requests_end");
	asfd_mock_read(asfd, &ar, 0, CMD_GEN, "backup_end");

	asfd_assert_write(chfd, &cw, 0, CMD_GEN, "sigs_end");
}
Пример #14
0
static void setup_asfds_no_sigs_from_client(struct asfd *asfd,
	struct asfd *chfd, struct slist *slist)
{
	int ar=0, aw=0, cw=0;

	setup_writes_from_slist(asfd, &aw, slist);
	asfd_assert_write(asfd, &aw, 0, CMD_GEN, "requests_end");
	asfd_mock_read_no_op(asfd, &ar, 60);
	asfd_mock_read(asfd, &ar, 0, CMD_GEN, "sigs_end");
	asfd_assert_write(asfd, &aw, 0, CMD_GEN, "blk_requests_end");
	asfd_mock_read(asfd, &ar, 0, CMD_GEN, "backup_end");

	asfd_assert_write(chfd, &cw, 0, CMD_GEN, "sigs_end");
}
Пример #15
0
static void setup_bad_read(struct asfd *asfd, struct slist *slist)
{
	int r=0; int w=0;
	asfd_assert_write(asfd, &w, 0, CMD_GEN, "restore :");
	asfd_mock_read(asfd, &r, 0, CMD_GEN, "ok");
	asfd_mock_read(asfd, &r, -1, CMD_GEN, "blah");
}
Пример #16
0
static void setup_error_while_reading(struct asfd *asfd, const char *path)
{
	int w=0;
	char msg[256]="";
	snprintf(msg, sizeof(msg), "error while reading %s\n", path);
	asfd_assert_write(asfd, &w, 0, CMD_WARNING, msg);
}
Пример #17
0
static void setup_sfd_to_output(struct asfd *sfd,
	struct asfd *in, struct asfd *out)
{
	int a=0;
	int r=0;
	int w=0;

	asfd_mock_read_no_op(in, &r, 3);

	asfd_mock_read(sfd, &a, 0, CMD_GEN, "blah");
	asfd_mock_read(sfd, &a, 0, CMD_GEN, "halb");
	asfd_assert_write(out, &w, 0, CMD_GEN, "blah");
	asfd_assert_write(out, &w, 0, CMD_GEN, "halb");

	asfd_mock_read(sfd, &a, -1, CMD_GEN, "blah2");
}
Пример #18
0
static void setup_could_not_open_message(struct asfd *asfd, const char *path)
{
	int w=0;
	char msg[256]="";
	snprintf(msg, sizeof(msg), "could not open %s\n", path);
	asfd_assert_write(asfd, &w, 0, CMD_WARNING, msg);
}
Пример #19
0
static void setup_read_error(struct asfd *csin, struct asfd *csout,
	struct asfd *so_asfd)
{
	int r=0; int w=0;
	asfd_assert_write(csin, &w, 0, CMD_GEN, "c:\n");
	asfd_mock_read(csin, &r, -1, CMD_GEN, "");
}
Пример #20
0
static void setup_bad_json(struct asfd *csin, struct asfd *csout,
	struct asfd *so_asfd)
{
	int r=0; int w=0;
	asfd_assert_write(csin, &w, 0, CMD_GEN, "c:\n");
	asfd_mock_read(csin, &r, 0, CMD_GEN, "{ adfdff }\n");
}
Пример #21
0
static void setup_input_to_sfd(struct asfd *sfd,
	struct asfd *in, struct asfd *out)
{
	int r=0;
	int ar=0;
	int aw=0;

	asfd_mock_read_no_op(sfd, &ar, 3);

	asfd_mock_read(in, &r, 0, CMD_GEN, "blah");
	asfd_mock_read(in, &r, 0, CMD_GEN, "halb");
	asfd_assert_write(sfd, &aw, 0, CMD_GEN, "blah");
	asfd_assert_write(sfd, &aw, 0, CMD_GEN, "halb");

	asfd_mock_read(in, &r, -1, CMD_GEN, "blah2");
}
Пример #22
0
static void setup_asfds_read_error(struct asfd *asfd, struct asfd *chfd,
	struct slist *slist)
{
	int ar=0, aw=0;
	asfd_assert_write(asfd, &aw,  0, CMD_GEN, "requests_end");
	asfd_mock_read(asfd, &ar, -1, CMD_DATA, "some data");
}
Пример #23
0
static void setup_asfds_empty_and_messages(struct asfd *asfd, struct asfd *chfd,
	struct slist *slist)
{
	int ar=0, aw=0, cw=0;
	asfd_mock_read(asfd, &ar, 0, CMD_MESSAGE, "a message");
	asfd_assert_write(asfd, &aw, 0, CMD_GEN, "requests_end");
	asfd_mock_read(asfd, &ar, 0, CMD_MESSAGE, "a message");
	asfd_mock_read(asfd, &ar, 0, CMD_GEN, "sigs_end");
	asfd_mock_read(asfd, &ar, 0, CMD_WARNING, "a warning");
	asfd_mock_read(asfd, &ar, 0, CMD_WARNING, "another warning");
	asfd_assert_write(asfd, &aw, 0, CMD_GEN, "blk_requests_end");
	asfd_mock_read(asfd, &ar, 0, CMD_MESSAGE, "a message");
	asfd_mock_read(asfd, &ar, 0, CMD_GEN, "backup_end");

	asfd_assert_write(chfd, &cw, 0, CMD_GEN, "sigs_end");
}
Пример #24
0
static void setup_md5sum_no_match(struct asfd *asfd, struct sbuf *sb)
{
	int w=0;
	char msg[256]="";
	snprintf(msg, sizeof(msg), "md5sum for '%s (%s)' did not match!\n",
		sb->path.buf, sb->protocol1->datapth.buf);
	asfd_assert_write(asfd, &w, 0, CMD_WARNING, msg);
}
Пример #25
0
static void setup_simplest_json(struct asfd *csin, struct asfd *csout,
	struct asfd *so_asfd)
{
	int r=0; int w=0;
	asfd_assert_write(csin, &w, 0, CMD_GEN, "c:\n");
	asfd_mock_read(csin, &r, 0, CMD_GEN, "{}");
	asfd_mock_read(csin, &r, -1, CMD_GEN, "blah");
}
Пример #26
0
static void setup_asfds_chfd_bad_cmd(struct asfd *asfd, struct asfd *chfd,
	struct slist *slist)
{
	int ar=0, aw=0, cr=0;
	asfd_assert_write(asfd, &aw,  0, CMD_GEN, "requests_end");
	asfd_mock_read_no_op(asfd, &ar, 1);
	asfd_mock_read(chfd, &cr,  0, CMD_MESSAGE, "some message");
}
Пример #27
0
static void setup_asfds_read_error_chfd(struct asfd *asfd, struct asfd *chfd,
	struct slist *slist)
{
	int ar=0, aw=0, cr=0;
	asfd_assert_write(asfd, &aw,  0, CMD_GEN, "requests_end");
	asfd_mock_read_no_op(asfd, &ar, 1);
	asfd_mock_read(chfd, &cr, -1, CMD_SIG, "some sig");
}
Пример #28
0
static void setup_multiline_json(struct asfd *asfd)
{
	int r=0; int w=0;
	asfd_assert_write(asfd, &w, 0, CMD_GEN, "c:\n");
	asfd_mock_read(asfd, &r, 0, CMD_GEN, "\n{\n");
	asfd_mock_read(asfd, &r, 0, CMD_GEN, "\n\n\n");
	asfd_mock_read(asfd, &r, 0, CMD_GEN, "\n}\n");
}
Пример #29
0
static void setup_not_found_message(struct asfd *asfd, struct sbuf *sb)
{
	int w=0;
	char msg[256]="";
	snprintf(msg, sizeof(msg), "restore could not find %s (%s)\n",
		sb->path.buf, sb->protocol1->datapth.buf);
	asfd_assert_write(asfd, &w, 0, CMD_WARNING, msg);
}
Пример #30
0
static void setup_no_md5sum(struct asfd *asfd, struct sbuf *sb)
{
	int w=0;
	char msg[256]="";
	snprintf(msg, sizeof(msg), "%s has no md5sum!\n",
		sb->protocol1->datapth.buf);
	asfd_assert_write(asfd, &w, 0, CMD_WARNING, msg);
}