예제 #1
0
파일: bsigs.c 프로젝트: pkdevbox/burp
int run_bsigs(int argc, char *argv[])
{
	int ret=1;
	fzp *fzp=NULL;
	struct iobuf rbuf;
	struct blk blk;
	memset(&rbuf, 0, sizeof(struct iobuf));

	if(argc!=2)
		return usage();
	path=argv[1];

	if(!(fzp=fzp_gzopen(path, "rb")))
		goto end;
	while(1)
	{
		iobuf_free_content(&rbuf);
		switch(iobuf_fill_from_fzp(&rbuf, fzp))
		{
			case 1: ret=0; // Finished OK.
			case -1: goto end; // Error.
		}

		if(parse_cmd(&rbuf, &blk)) goto end;
	}

end:
	iobuf_free_content(&rbuf);
	fzp_close(&fzp);
	return ret;
}
예제 #2
0
파일: backup_phase2.c 프로젝트: jkniiv/burp
static int do_backup_phase2_client(struct asfd *asfd,
	struct conf *conf, int resume)
{
	int ret=-1;
	// For efficiency, open Windows files for the VSS data, and do not
	// close them until another time around the loop, when the actual
	// data is read.
	BFILE bfd;
	// Windows VSS headers tell us how much file
	// data to expect.
	size_t datalen=0;
#ifdef HAVE_WIN32
	binit(&bfd, 0, conf);
#endif

	struct sbuf *sb=NULL;
	struct iobuf *rbuf=asfd->rbuf;

	if(!(sb=sbuf_alloc(conf))) goto end;

	if(!resume)
	{
		// Only do this bit if the server did not tell us to resume.
		if(asfd->write_str(asfd, CMD_GEN, "backupphase2")
		  || asfd->read_expect(asfd, CMD_GEN, "ok"))
			goto end;
	}
	else if(conf->send_client_cntr)
	{
		// On resume, the server might update the client with cntr.
		if(cntr_recv(asfd, conf)) goto end;
	}

	while(1)
	{
		iobuf_free_content(rbuf);
		if(asfd->read(asfd)) goto end;
		else if(!rbuf->buf) continue;

		if(rbuf->cmd==CMD_GEN && !strcmp(rbuf->buf, "backupphase2end"))
		{
			if(asfd->write_str(asfd, CMD_GEN, "okbackupphase2end"))
				goto end;
			ret=0;
			break;
		}

		if(parse_rbuf(asfd, sb, &bfd, &datalen, conf))
			goto end;
	}

end:
#ifdef HAVE_WIN32
	// It is possible for a bfd to still be open.
	close_file_for_sendl(&bfd, NULL, asfd);
#endif
	iobuf_free_content(rbuf);
	sbuf_free(sb);
	return ret;
}
예제 #3
0
// Return 0 for OK, -1 for error, 1 for finished reading the file.
static int get_next_dindex(uint64_t **dnew, struct sbuf *sb, struct fzp *fzp)
{
	static struct blk blk;
	static struct iobuf rbuf;

	memset(&rbuf, 0, sizeof(rbuf));

	switch(iobuf_fill_from_fzp(&rbuf, fzp))
	{
		case -1: goto error;
		case 1: return 1; // Reached the end.
	}
	if(rbuf.cmd==CMD_SAVE_PATH)
	{
		if(blk_set_from_iobuf_savepath(&blk, &rbuf))
			goto error;
		*dnew=(uint64_t *)malloc_w(sizeof(uint64_t), __func__);
		**dnew=blk.savepath;
		iobuf_free_content(&rbuf);
		return 0;
	}
	else
		iobuf_log_unexpected(&sb->path, __func__);

error:
	iobuf_free_content(&rbuf);
	return -1;
}
예제 #4
0
파일: sbufl.c 프로젝트: Kalimeiro/burp
static int read_stat(struct asfd *asfd, struct iobuf *rbuf, FILE *fp,
	gzFile zp, struct sbuf *sb, struct cntr *cntr)
{
	while(1)
	{
		iobuf_free_content(rbuf);
		if(fp || zp)
		{
			int asr;
			if((asr=read_fp(fp, zp, rbuf)))
			{
				//logp("read_fp returned: %d\n", asr);
				return asr;
			}
			if(rbuf->buf[rbuf->len]=='\n')
				rbuf->buf[rbuf->len]='\0';
		}
		else
		{
			if(asfd->read(asfd))
			{
				break;
			}
			if(rbuf->cmd==CMD_WARNING)
			{
				logp("WARNING: %s\n", rbuf->buf);
				cntr_add(cntr, rbuf->cmd, 0);
				continue;
			}
		}
		if(rbuf->cmd==CMD_DATAPTH)
		{
			iobuf_copy(&(sb->burp1->datapth), rbuf);
			rbuf->buf=NULL;
		}
		else if(rbuf->cmd==CMD_ATTRIBS)
		{
			iobuf_copy(&sb->attr, rbuf);
			rbuf->buf=NULL;
			attribs_decode(sb);

			return 0;
		}
		else if((rbuf->cmd==CMD_GEN && !strcmp(rbuf->buf, "backupend"))
		  || (rbuf->cmd==CMD_GEN && !strcmp(rbuf->buf, "restoreend"))
		  || (rbuf->cmd==CMD_GEN && !strcmp(rbuf->buf, "phase1end"))
		  || (rbuf->cmd==CMD_GEN && !strcmp(rbuf->buf, "backupphase2"))
		  || (rbuf->cmd==CMD_GEN && !strcmp(rbuf->buf, "estimateend")))
		{
			iobuf_free_content(rbuf);
			return 1;
		}
		else
			return unexpected(rbuf, __func__);
	}
	iobuf_free_content(rbuf);
	return -1;
}
예제 #5
0
파일: restore.c 프로젝트: pkdevbox/burp
// FIX THIS: it only works with protocol1.
int restore_interrupt(struct asfd *asfd,
	struct sbuf *sb, const char *msg, struct cntr *cntr,
	enum protocol protocol)
{
	int ret=0;
	struct iobuf *rbuf=asfd->rbuf;

	if(protocol!=PROTO_1) return 0;
	if(!cntr) return 0;

	cntr_add(cntr, CMD_WARNING, 1);
	logp("WARNING: %s\n", msg);
	if(asfd->write_str(asfd, CMD_WARNING, msg)) goto end;

	// If it is file data, get the server
	// to interrupt the flow and move on.
	if(sb->path.cmd!=CMD_FILE
	  && sb->path.cmd!=CMD_ENC_FILE
	  && sb->path.cmd!=CMD_EFS_FILE
	  && sb->path.cmd!=CMD_VSS
	  && sb->path.cmd!=CMD_ENC_VSS
	  && sb->path.cmd!=CMD_VSS_T
	  && sb->path.cmd!=CMD_ENC_VSS_T)
		return 0;
	if(sb->protocol1 && !(sb->protocol1->datapth.buf))
		return 0;
	if(sb->protocol2 && !(sb->path.buf))
		return 0;

	if(asfd->write_str(asfd, CMD_INTERRUPT, sb->protocol1->datapth.buf))
		goto end;

	// Read to the end file marker.
	while(1)
	{
		iobuf_free_content(rbuf);
		if(asfd->read(asfd))
			goto end;
		if(!ret && rbuf->len)
		{
			if(rbuf->cmd==CMD_APPEND)
				continue;
			else if(rbuf->cmd==CMD_END_FILE)
				break;
			else
			{
				iobuf_log_unexpected(rbuf, __func__);
				goto end;
			}
		}
	}

	ret=0;
end:
	iobuf_free_content(rbuf);
	return ret;
}
예제 #6
0
파일: main.c 프로젝트: jkniiv/burp
static enum cliret maybe_check_timer(struct asfd *asfd,
	enum action action, const char *phase1str,
	struct conf *conf, int *resume)
{
	int complen=0;
	struct iobuf *rbuf=asfd->rbuf;

        if(asfd->write_str(asfd, CMD_GEN, phase1str)) goto error;

        if(asfd->read(asfd)) goto error;

        if(rbuf->cmd!=CMD_GEN)
        {
		iobuf_free_content(rbuf);
		iobuf_log_unexpected(rbuf, __func__);
		goto error;
        }
        if(!strcmp(rbuf->buf, "timer conditions not met"))
        {
		iobuf_free_content(rbuf);
                logp("Timer conditions on the server were not met\n");
		goto timer_not_met;
        }
        else if(!strcmp(rbuf->buf, "timer conditions met"))
        {
		iobuf_free_content(rbuf);
                logp("Timer conditions on the server were met\n");
		if(action==ACTION_TIMER_CHECK) goto end;
        }

	if(!strncmp_w(rbuf->buf, "ok"))
		complen=3;
	else if(!strncmp_w(rbuf->buf, "resume"))
	{
		complen=7;
		*resume=1;
		logp("server wants to resume previous backup.\n");
	}
	else
	{
		iobuf_log_unexpected(rbuf, __func__);
		iobuf_free_content(rbuf);
		goto error;
	}
        // The server now tells us the compression level in the OK response.
        if(strlen(rbuf->buf)>3) conf->compression=atoi(rbuf->buf+complen);
        logp("Compression level: %d\n", conf->compression);

	iobuf_free_content(rbuf);
end:
	return CLIENT_OK;
error:
	return CLIENT_ERROR;
timer_not_met:
	return CLIENT_SERVER_TIMER_NOT_MET;
}
예제 #7
0
파일: restore.c 프로젝트: EmisFR/burp
int restore_interrupt(struct asfd *asfd,
	struct sbuf *sb, const char *msg, struct cntr *cntr,
	enum protocol protocol)
{
	int ret=0;
	char *path=NULL;
	struct iobuf *rbuf=asfd->rbuf;

	if(cntr)
	{
		cntr_add(cntr, CMD_WARNING, 1);
		logp("WARNING: %s\n", msg);
		if(asfd->write_str(asfd, CMD_WARNING, msg)) goto end;
	}

	// If it is file data, get the server
	// to interrupt the flow and move on.
	if(!iobuf_is_filedata(&sb->path)
	  && !iobuf_is_vssdata(&sb->path))
		return 0;

	if(protocol==PROTO_1)
		path=sb->protocol1->datapth.buf;
	else if(protocol==PROTO_2)
		path=sb->path.buf;

	if(!path) return 0;

	if(asfd->write_str(asfd, CMD_INTERRUPT, path))
		goto end;

	// Read to the end file marker.
	while(1)
	{
		iobuf_free_content(rbuf);
		if(asfd->read(asfd))
			goto end;
		if(!rbuf->len) continue;

		switch(rbuf->cmd)
		{
			case CMD_APPEND:
			case CMD_DATA:
				continue;
			case CMD_END_FILE:
				ret=0;
				goto end;
			default:
				iobuf_log_unexpected(rbuf, __func__);
				goto end;
		}
	}
end:
	iobuf_free_content(rbuf);
	return ret;
}
예제 #8
0
파일: champ_server.c 프로젝트: grke/burp
static int deal_with_client_rbuf(struct asfd *asfd, const char *directory,
	struct scores *scores)
{
	if(asfd->rbuf->cmd==CMD_GEN)
	{
		if(!strncmp_w(asfd->rbuf->buf, "cname:"))
		{
			struct iobuf wbuf;
			free_w(&asfd->desc);
			if(!(asfd->desc=strdup_w(asfd->rbuf->buf
				+strlen("cname:"), __func__)))
					goto error;
			logp("%s: fd %d\n", asfd->desc, asfd->fd);
			iobuf_set(&wbuf, CMD_GEN,
				(char *)"cname ok", strlen("cname ok"));

			if(asfd->write(asfd, &wbuf))
				goto error;
		}
		else if(!strncmp_w(asfd->rbuf->buf, "sigs_end"))
		{
			//printf("Was told no more sigs\n");
			if(deduplicate(asfd, directory, scores)<0)
				goto error;
		}
		else
		{
			iobuf_log_unexpected(asfd->rbuf, __func__);
			goto error;
		}
	}
	else if(asfd->rbuf->cmd==CMD_SIG)
	{
		if(champ_server_deal_with_rbuf_sig(asfd, directory, scores))
			goto error;
	}
	else if(asfd->rbuf->cmd==CMD_MANIFEST)
	{
		// Client has completed a manifest file. Want to start using
		// it as a dedup candidate now.
		if(candidate_add_fresh(asfd->rbuf->buf, directory, scores))
			goto error;
	}
	else
	{
		iobuf_log_unexpected(asfd->rbuf, __func__);
		goto error;
	}
	iobuf_free_content(asfd->rbuf);
	return 0;
error:
	iobuf_free_content(asfd->rbuf);
	return -1;
}
예제 #9
0
파일: sbuf.c 프로젝트: pablodav/burp
void sbuf_free_content(struct sbuf *sb)
{
	iobuf_free_content(&sb->path);
	iobuf_free_content(&sb->attr);
	iobuf_free_content(&sb->link);
	iobuf_free_content(&sb->endfile);
	memset(&(sb->statp), 0, sizeof(sb->statp));
	sb->compression=-1;
	sb->winattr=0;
	sb->flags=0;
	sbuf_protocol1_free_content(sb->protocol1);
	sbuf_protocol2_free_content();
}
예제 #10
0
파일: sbuf.c 프로젝트: pablodav/burp
static int sbuf_fill(struct sbuf *sb, struct asfd *asfd, struct fzp *fzp,
	struct blk *blk, struct cntr *cntr)
{
	static struct iobuf *rbuf;
	static struct iobuf localrbuf;
	int ret=-1;

	if(asfd) rbuf=asfd->rbuf;
	else
	{
		// If not given asfd, use our own iobuf.
		memset(&localrbuf, 0, sizeof(struct iobuf));
		rbuf=&localrbuf;
	}
	while(1)
	{
		iobuf_free_content(rbuf);
		if(fzp)
		{
			if((ret=iobuf_fill_from_fzp(rbuf, fzp)))
				goto end;
		}
		else
		{
			if(asfd->read(asfd))
			{
				logp("error in async_read\n");
				break;
			}
		}
		switch(parse_cmd(sb, asfd, rbuf, blk, cntr))
		{
			case PARSE_RET_NEED_MORE:
				continue;
			case PARSE_RET_COMPLETE:
				return 0;
			case PARSE_RET_FINISHED:
				ret=1;
				goto end;
			case PARSE_RET_ERROR:
			default:
				ret=-1;
				goto end;
		}
	}
end:
	iobuf_free_content(rbuf);
	return ret;
}
예제 #11
0
파일: test_manio.c 프로젝트: ZungBang/burp
static void check_dindex(int i)
{
	int ret;
	struct fzp *fzp;
	const char *p;
	struct iobuf rbuf;
	int lines=0;
	struct blk blk;
	uint64_t last_savepath=0;

	p=get_extra_path(i, "dindex");
	memset(&rbuf, 0, sizeof(rbuf));

	fail_unless((fzp=fzp_gzopen(p, "rb"))!=NULL);
	while(!(ret=iobuf_fill_from_fzp(&rbuf, fzp)))
	{
		lines++;
		switch(rbuf.cmd)
		{
			case CMD_SAVE_PATH:
				blk_set_from_iobuf_savepath(&blk, &rbuf);
				fail_unless(blk.savepath>last_savepath);
				last_savepath=blk.savepath;
				break;
			default:
				fail_unless(0==1);
				break;
		}
		iobuf_free_content(&rbuf);
	}
	fail_unless(ret==1);
	fail_unless(lines>500);
	fail_unless(!fzp_close(&fzp));
}
예제 #12
0
파일: handy.c 프로젝트: adrianimboden/burp
// return -1 for error, 0 for OK, 1 if the client wants to interrupt the
// transfer.
int do_quick_read(struct asfd *asfd, const char *datapth, struct conf **confs)
{
	int r=0;
	struct iobuf *rbuf;
	if(asfd->as->read_quick(asfd->as)) return -1;
	rbuf=asfd->rbuf;

	if(rbuf->buf)
	{
		if(rbuf->cmd==CMD_MESSAGE
		  || rbuf->cmd==CMD_WARNING)
		{
			log_recvd(rbuf, confs, 0);
		}
		else if(rbuf->cmd==CMD_INTERRUPT)
		{
			// Client wants to interrupt - double check that
			// it is still talking about the file that we are
			// sending.
			if(datapth && !strcmp(rbuf->buf, datapth))
				r=1;
		}
		else
		{
			iobuf_log_unexpected(rbuf, __func__);
			r=-1;
		}
		iobuf_free_content(rbuf);
	}
	return r;
}
예제 #13
0
static int do_asfd_assert_write(struct asfd *asfd, struct iobuf *wbuf)
{
	struct ioevent *w;
	struct iobuf *expected;
	struct ioevent_list *writes=(struct ioevent_list *)asfd->data2;
//printf("w %s %d %d\n", asfd->desc, writes->cursor, writes->size);
//printf("%c:%s\n", wbuf->cmd, wbuf->buf);
	fail_unless(writes->cursor<writes->size);
	w=&writes->ioevent[writes->cursor++];
	expected=&w->iobuf;
/*
if(wbuf->cmd==CMD_SIG)
{
	struct blk blk;
                        blk_set_from_iobuf_sig(&blk, wbuf);
                        printf("%016"PRIX64" %s\n",
                                blk.fingerprint,
                                bytes_to_md5str(blk.md5sum));

}
if(wbuf->cmd==CMD_APPEND)
{
	for(int i=0; i<wbuf->len; i++)
		printf("0x%x 0x%x\n", wbuf->buf[i], expected->buf[i]);
}
*/
//printf("%d %d\n", wbuf->len, expected->len);
//printf("w %s - '%c:%s' '%c:%s'\n", asfd->desc, wbuf->cmd, wbuf->buf,
//		expected->cmd, expected->buf);
	fail_unless(wbuf->len==expected->len);
	fail_unless(wbuf->cmd==expected->cmd);
	fail_unless(!memcmp(expected->buf, wbuf->buf, wbuf->len));
	iobuf_free_content(expected);
	return w->ret;
}
예제 #14
0
파일: backup_phase2.c 프로젝트: EmisFR/burp
static int deal_with_read_from_chfd(struct asfd *chfd,
	struct blist *blist, uint64_t *wrap_up, struct dpth *dpth,
	struct cntr *cntr)
{
	int ret=-1;

	// Deal with champ chooser read here.
	//printf("read from cc: %s\n", chfd->rbuf->buf);
	switch(chfd->rbuf->cmd)
	{
		case CMD_SIG:
			// Get these for blks that the champ chooser has found.
			if(deal_with_sig_from_chfd(chfd->rbuf, blist, dpth))
				goto end;
			cntr_add_same(cntr, CMD_DATA);
			break;
		case CMD_WRAP_UP:
			if(deal_with_wrap_up_from_chfd(chfd->rbuf, blist, dpth))
				goto end;
			break;
		default:
			iobuf_log_unexpected(chfd->rbuf, __func__);
			goto end;
	}
	ret=0;
end:
	iobuf_free_content(chfd->rbuf);
	return ret;
}
예제 #15
0
파일: backup_phase2.c 프로젝트: EmisFR/burp
static int set_up_for_sig_info(struct slist *slist, struct iobuf *attr,
	uint64_t index)
{
	struct sbuf *sb;

	for(sb=slist->add_sigs_here; sb; sb=sb->next)
	{
		if(!sb->protocol2->index)
			continue;
		if(index==sb->protocol2->index)
			break;
	}
	if(!sb)
	{
		logp("Could not find %" PRIu64 " in request list\n", index);
		return -1;
	}
	// Replace the attribs with the more recent values.
	iobuf_free_content(&sb->attr);
	iobuf_move(&sb->attr, attr);

	// Mark the end of the previous file.
	slist->add_sigs_here->protocol2->bend=slist->blist->tail;

	slist->add_sigs_here=sb;

	// Incoming sigs now need to get added to 'add_sigs_here'
	return 0;
}
예제 #16
0
파일: run_action.c 프로젝트: EmisFR/burp
static int run_list(struct asfd *asfd,
	struct sdirs *sdirs, struct conf **cconfs)
{
	int ret=-1;
	char *cp=NULL;
	char *backupno=NULL;
	char *browsedir=NULL;
	char *listregex=NULL;
	struct iobuf *rbuf=asfd->rbuf;

	if(!client_can_generic(cconfs, OPT_CLIENT_CAN_LIST))
	{
		logp("Not allowing list of %s\n",
			get_string(cconfs[OPT_CNAME]));
		asfd->write_str(asfd, CMD_GEN, "Client list is not allowed");
		goto end;
	}

	if(!strncmp_w(rbuf->buf, "list "))
	{
		if((cp=strchr(rbuf->buf, ':')))
		{
			*cp='\0';
			if(!(listregex=strdup_w(cp+1, __func__)))
				goto end;
		}
		if(!(backupno=strdup_w(rbuf->buf+strlen("list "), __func__)))
			goto end;
		
	}
	else if(!strncmp_w(rbuf->buf, "listb "))
	{
		if((cp=strchr(rbuf->buf, ':')))
		{
			*cp='\0';
			if(!(browsedir=strdup_w(cp+1, __func__)))
				goto end;
		}
		strip_trailing_slashes(&browsedir);
		if(!(backupno=strdup_w(rbuf->buf+strlen("listb "), __func__)))
			goto end;
	}
	if(asfd->write_str(asfd, CMD_GEN, "ok")) goto end;

	iobuf_free_content(asfd->rbuf);

	if(list_server_init(asfd, sdirs, get_cntr(cconfs),
		get_protocol(cconfs), backupno, listregex, browsedir))
			goto end;
	ret=do_list_server();
end:
	free_w(&backupno);
	free_w(&browsedir);
	free_w(&listregex);
	list_server_free();
	return ret;
}
예제 #17
0
파일: rblk.c 프로젝트: grke/burp
static void rblk_free_content(struct rblk *rblk)
{
	for(int j=0; j<rblk->rlen; j++)
	{
		rblk_mem-=rblk->readbuf[j].len;
		iobuf_free_content(&rblk->readbuf[j]);
	}
	fzp_close(&rblk->fzp);
}
예제 #18
0
파일: restore.c 프로젝트: EmisFR/burp
static int get_meta(
	struct asfd *asfd,
	struct cntr *cntr,
	char **metadata,
	size_t *metalen)
{
	int ret=-1;
	struct iobuf *rbuf=asfd->rbuf;

	while(1)
	{
		iobuf_free_content(rbuf);
		if(asfd->read(asfd))
			goto end;

		switch(rbuf->cmd)
		{
			case CMD_DATA:
				if(!(*metadata=(char *)realloc_w(*metadata,
					(*metalen)+rbuf->len, __func__)))
						goto end;
				memcpy((*metadata)+(*metalen),
					rbuf->buf, rbuf->len);
				*metalen+=rbuf->len;
				break;
			case CMD_END_FILE:
				ret=0;
				goto end;
			case CMD_MESSAGE:
			case CMD_WARNING:
				log_recvd(rbuf, cntr, 0);
				break;
			default:
				iobuf_log_unexpected(rbuf, __func__);
				goto end;
		}
	}

end:
	iobuf_free_content(rbuf);
	return ret;
}
예제 #19
0
파일: msg.c 프로젝트: pkdevbox/burp
static DWORD WINAPI read_efs(PBYTE pbData, PVOID pvCallbackContext, PULONG ulLength)
{
	struct iobuf *rbuf;
	struct winbuf *mybuf=(struct winbuf *)pvCallbackContext;
	rbuf=mybuf->asfd->rbuf;

	while(1)
	{
		if(mybuf->asfd->read(mybuf->asfd))
			return ERROR_FUNCTION_FAILED;
		(*(mybuf->rcvd))+=rbuf->len;

		switch(rbuf->cmd)
		{
			case CMD_APPEND:
				memcpy(pbData, rbuf->buf, rbuf->len);
				*ulLength=(ULONG)rbuf->len;
				(*(mybuf->sent))+=rbuf->len;
				iobuf_free_content(rbuf);
				return ERROR_SUCCESS;
			case CMD_END_FILE:
				*ulLength=0;
				iobuf_free_content(rbuf);
				return ERROR_SUCCESS;
			case CMD_MESSAGE:
				logp("MESSAGE: %s\n", rbuf->buf);
				cntr_add(mybuf->cntr, rbuf->cmd, 0);
				iobuf_free_content(rbuf);
				continue;
			case CMD_WARNING:
				logp("WARNING: %s\n", rbuf->buf);
				cntr_add(mybuf->cntr, rbuf->cmd, 0);
				iobuf_free_content(rbuf);
				continue;
			default:
				iobuf_log_unexpected(rbuf, __func__);
				iobuf_free_content(rbuf);
				break;
		}
	}
	return ERROR_FUNCTION_FAILED;
}
예제 #20
0
파일: rblk.c 프로젝트: EmisFR/burp
void rblk_free(void)
{
	if(!rblks) return;
	for(int i=0; i<RBLK_MAX; i++)
	{
		free_w(&rblks[i].datpath);
		for(int j=0; j<DATA_FILE_SIG_MAX; j++)
			iobuf_free_content(&rblks[i].readbuf[j]);
	}
	free_v((void **)&rblks);
}
예제 #21
0
파일: build_manifest.c 프로젝트: grke/burp
static void set_sbuf_protocol1(struct sbuf *sb)
{
	if(sbuf_is_filedata(sb) || sbuf_is_vssdata(sb))
	{
		char *endfile=gen_endfile_str();
		iobuf_free_content(&sb->endfile);
		sb->endfile.cmd=CMD_END_FILE;
		sb->endfile.len=strlen(endfile);
		fail_unless((sb->endfile.buf
			=strdup_w(endfile, __func__))!=NULL);
	}

	if(sbuf_is_filedata(sb) || sbuf_is_vssdata(sb))
	{
		char *datapth;
		fail_unless((datapth=prepend_s(TREE_DIR, sb->path.buf))!=NULL);
		iobuf_free_content(&sb->protocol1->datapth);
		iobuf_from_str(&sb->protocol1->datapth, CMD_DATAPTH, datapth);
	}
}
예제 #22
0
파일: build_manifest.c 프로젝트: grke/burp
// Deal with a hack where the index is stripped off the beginning of the
// attributes when protocol2 saves to the manifest.
static void hack_protocol2_attr(struct iobuf *attr)
{
	char *cp=NULL;
	char *copy=NULL;
	size_t newlen;
	fail_unless((cp=strchr(attr->buf, ' '))!=NULL);
	fail_unless((copy=strdup_w(cp, __func__))!=NULL);
	newlen=attr->buf-cp+attr->len;
	iobuf_free_content(attr);
	iobuf_set(attr, CMD_ATTRIBS, copy, newlen);
}
예제 #23
0
파일: run_action.c 프로젝트: EmisFR/burp
static int run_restore(struct asfd *asfd,
	struct sdirs *sdirs, struct conf **cconfs, int srestore)
{
	int ret=-1;
	char *dir_for_notify=NULL;
	enum action act=ACTION_RESTORE;
	struct iobuf *rbuf=asfd->rbuf;
	const char *cname=get_string(cconfs[OPT_CNAME]);

	if(parse_restore_str_and_set_confs(rbuf->buf, &act, cconfs))
		goto end;

	iobuf_free_content(rbuf);

	if(act==ACTION_RESTORE)
	{
		int r;
		if((r=client_can_restore(cconfs))<0)
			goto end;
		else if(!r)
		{
			logp("Not allowing restore of %s\n", cname);
			if(!asfd->write_str(asfd, CMD_GEN,
				"Client restore is not allowed")) ret=0;
			goto end;
		}
	}
	if(act==ACTION_VERIFY
	  && !(client_can_generic(cconfs, OPT_CLIENT_CAN_VERIFY)))
	{
		logp("Not allowing verify of %s\n", cname);
		if(!asfd->write_str(asfd, CMD_GEN,
			"Client verify is not allowed")) ret=0;
		goto end;
	}

	if(asfd->write_str(asfd, CMD_GEN, "ok"))
		goto end;
	ret=do_restore_server(asfd, sdirs, act,
		srestore, &dir_for_notify, cconfs);
	if(dir_for_notify)
		maybe_do_notification(asfd, ret,
			sdirs->client, dir_for_notify,
			act==ACTION_RESTORE?"restorelog":"verifylog",
			act==ACTION_RESTORE?"restore":"verify",
			cconfs);
end:
	free_w(&dir_for_notify);
	return ret;
}
예제 #24
0
파일: monitor.c 프로젝트: EmisFR/burp
static int main_loop(struct async *as, struct conf **confs)
{
	struct asfd *asfd;
	struct asfd *sfd; // Server fd.
	struct asfd *sin;
	struct asfd *sout;

	sfd=as->asfd;
	sin=sfd->next;
	sout=sin->next;

	// Send a blank line to kick the server off.
	if(sfd->write_str(sfd, CMD_GEN, "\n"))
		goto error;

	while(1)
	{
		if(as->read_write(as))
		{
			logp("Exiting main loop\n");
			break;
		}

		for(asfd=as->asfd; asfd; asfd=asfd->next)
			while(asfd->rbuf->buf)
		{
			if(asfd==sfd)
			{
				if(copy_input_to_output(sfd, sout))
					goto error;
			}
			else if(asfd==sin)
			{
				if(copy_input_to_output(sin, sfd))
					goto error;
			}
			iobuf_free_content(asfd->rbuf);
			if(asfd->parse_readbuf(asfd))
				goto error;
		}

		//if(sel) logp("sel: %s\n", sel->name);
	}

error:
	// FIX THIS: should probably be freeing a bunch of stuff here.
	return -1;
}
예제 #25
0
파일: test_manio.c 프로젝트: ZungBang/burp
static void check_hooks(int i, int fcount)
{
	int ret;
	struct fzp *fzp;
	const char *p;
	struct iobuf rbuf;
	struct blk blk;
	int lines=0;
	uint64_t last_fingerprint=0;
	char manifest_line[64]="";

	p=get_extra_path(i, "hooks");
	memset(&rbuf, 0, sizeof(rbuf));
	snprintf(manifest_line, sizeof(manifest_line),
		"%s/%08X", RMANIFEST_RELATIVE, i);

	fail_unless((fzp=fzp_gzopen(p, "rb"))!=NULL);
	while(!(ret=iobuf_fill_from_fzp(&rbuf, fzp)))
	{
		lines++;
		switch(rbuf.cmd)
		{
			case CMD_MANIFEST:
				fail_unless(lines==1);
				ck_assert_str_eq(manifest_line, rbuf.buf);
				break;
			case CMD_FINGERPRINT:
				blk_set_from_iobuf_fingerprint(&blk, &rbuf);
				fail_unless(blk.fingerprint>last_fingerprint);
				last_fingerprint=blk.fingerprint;
				break;
			default:
				fail_unless(0==1);
				break;
		}
		iobuf_free_content(&rbuf);
	}
	fail_unless(ret==1);
	if(i<fcount-1)
		fail_unless(lines>200);
	else
		fail_unless(lines>10); // Last file will have fewer entries.
	fail_unless(!fzp_close(&fzp));
}
예제 #26
0
파일: rblk.c 프로젝트: EmisFR/burp
static int load_rblk(struct rblk *rblks, int ind, const char *datpath)
{
	int r;
	int ret=-1;
	int done=0;
	struct fzp *fzp=NULL;
	struct iobuf rbuf;

	iobuf_init(&rbuf);

	free_w(&rblks[ind].datpath);
	if(!(rblks[ind].datpath=strdup_w(datpath, __func__)))
		goto end;

	logp("swap %d to: %s\n", ind, datpath);

	if(!(fzp=fzp_open(datpath, "rb")))
		goto end;
	for(r=0; r<DATA_FILE_SIG_MAX; r++)
	{
		switch(iobuf_fill_from_fzp_data(&rbuf, fzp))
		{
			case 0: if(rbuf.cmd!=CMD_DATA)
				{
					logp("unknown cmd in %s: %c\n",
						__func__, rbuf.cmd);
					goto end;
				}
				iobuf_free_content(&rblks[ind].readbuf[r]);
				iobuf_move(&rblks[ind].readbuf[r], &rbuf);
				continue;
			case 1: done++;
				break;
			default: goto end;
		}
		if(done) break;
	}
	rblks[ind].readbuflen=r;
	ret=0;
end:
	fzp_close(&fzp);
	return ret;
}
예제 #27
0
파일: sbufl.c 프로젝트: Kalimeiro/burp
static int do_sbufl_fill_from_net(struct sbuf *sb, struct asfd *asfd,
	struct cntr *cntr)
{
	int ars;
	static struct iobuf *rbuf=NULL;
	rbuf=asfd->rbuf;
	iobuf_free_content(rbuf);
	if((ars=read_stat(asfd, rbuf, NULL, NULL, sb, cntr))
	  || (ars=asfd->read(asfd))) return ars;
	iobuf_copy(&sb->path, rbuf);
	rbuf->buf=NULL;
	if(sbuf_is_link(sb))
	{
		if((ars=asfd->read(asfd))) return ars;
		iobuf_copy(&sb->link, rbuf);
		rbuf->buf=NULL;
		if(!cmd_is_link(rbuf->cmd))
			return unexpected(rbuf, __func__);
	}
	return 0;
}
예제 #28
0
static int deal_with_read_from_chfd(struct asfd *asfd, struct asfd *chfd,
	struct blist *blist, uint64_t *wrap_up, struct dpth *dpth)
{
	int ret=-1;
	uint64_t file_no;
	char *save_path;

	// Deal with champ chooser read here.
	//printf("read from cc: %s\n", chfd->rbuf->buf);
	switch(chfd->rbuf->cmd)
	{
		case CMD_SIG:
			// Get these for blks that the champ chooser has found.
			file_no=decode_file_no_and_save_path(chfd->rbuf,
				&save_path);
		//	printf("got save_path: %d %s\n", file_no, save_path);
			if(mark_up_to_index(blist, file_no, dpth)) goto end;
			mark_got(blist->blk_from_champ_chooser, save_path);
//			printf("after mark_got: %d\n",
//				blist->blk_from_champ_chooser->index);
			break;
		case CMD_WRAP_UP:
			file_no=decode_file_no(chfd->rbuf);
	//		printf("mark up to: %d\n", file_no);
			if(mark_up_to_index(blist, file_no, dpth)) goto end;
			mark_not_got(blist->blk_from_champ_chooser, dpth);

			//printf("after mark_up: %d\n",
			//	blist->blk_from_champ_chooser->index);
			break;
		default:
			iobuf_log_unexpected(chfd->rbuf, __func__);
			goto end;
	}
	ret=0;
end:
	iobuf_free_content(chfd->rbuf);
	return ret;
}
예제 #29
0
파일: status_server.c 프로젝트: EmisFR/burp
int status_server(struct async *as, struct conf **confs)
{
	int ret=-1;
	int gotdata=0;
	struct asfd *asfd;
	struct cstat *clist=NULL;
	struct asfd *cfd=as->asfd; // Client.
	struct conf **cconfs=NULL;

	if(!(cconfs=confs_alloc()))
		goto end;

	while(1)
	{
		// Take the opportunity to get data from the disk if nothing
		// was read from the fds.
		if(gotdata) gotdata=0;
		else if(cstat_load_data_from_disk(&clist, confs, cconfs))
			goto end;
		if(as->read_write(as))
		{
			logp("Exiting main status server loop\n");
			break;
		}
		for(asfd=as->asfd; asfd; asfd=asfd->next)
			while(asfd->rbuf->buf)
		{
			gotdata=1;
			if(parse_data(asfd, clist, cfd, confs)
			  || asfd->parse_readbuf(asfd))
				goto end;
			iobuf_free_content(asfd->rbuf);
		}
	}
	ret=0;
end:
// FIX THIS: should free clist;
	return ret;
}
예제 #30
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);
		}
	}
}