END_TEST static void do_md5sum_test(const char *endfile, int warnings, void setup_callback(struct asfd *asfd, struct sbuf *sb)) { struct asfd *asfd; struct cntr *cntr; struct sbuf *sb; const char *path="somepath"; const char *datapth="/datapth"; const char *best=BASE "/existent"; clean(); cntr=setup_cntr(); sb=setup_sbuf(path, datapth, endfile, 0/*compression*/); build_file(best, "blah"); asfd=asfd_mock_setup(&areads, &awrites); setup_callback(asfd, sb); // Returns 0 so that the parent process continues. fail_unless(!verify_file(asfd, sb, 0 /*patches*/, best, cntr)); fail_unless(cntr->ent[CMD_WARNING]->count==warnings); tear_down(&sb, &cntr, NULL, &asfd); }
void interpret_file(struct byte_array *path, struct byte_array *args) { struct byte_array *program; if (NULL != args) { struct byte_array *source = read_file(path, 0, 0); if (NULL == source) return; byte_array_append(args, source); program = build_string(args, path); } else { program = build_file(path); } #ifdef DEBUG //display_program(program); #endif execute(program); byte_array_del(program); }
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"); }
static void create_file(const char *backup, const char *file, int compressed_logs) { char path[256]=""; if(compressed_logs) snprintf(path, sizeof(path), "%s/%s.gz", backup, file); else snprintf(path, sizeof(path), "%s/%s", backup, file); build_file(path, NULL); }
static int process_file(Elf *elf, char *cur_file, Cmd_Info *cmd_info) { int error = SUCCESS; int x; GElf_Ehdr ehdr; size_t shnum; /* * Initialize */ if (gelf_getehdr(elf, &ehdr) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } if (elf_getshnum(elf, &shnum) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } initialize(shnum, cmd_info); if (ehdr.e_phnum != 0) { if (build_segment_table(elf, &ehdr) == FAILURE) return (FAILURE); } if ((x = traverse_file(elf, &ehdr, cur_file, cmd_info)) == FAILURE) { error_message(WRN_MANIPULATED_ERROR, PLAIN_ERROR, (char *)0, prog, cur_file); error = FAILURE; } else if (x != DONT_BUILD && x != FAILURE) { post_process(cmd_info); if (build_file(elf, &ehdr, cmd_info) == FAILURE) { error_message(WRN_MANIPULATED_ERROR, PLAIN_ERROR, (char *)0, prog, cur_file); error = FAILURE; } } free(off_table); free(sec_table); free(nobits_table); if (x == DONT_BUILD) return (DONT_BUILD); else return (error); }
static void run_find(const char *buf, FF_PKT *ff, struct conf **confs) { struct strlist *l; const char *conffile=CONFBASE "/burp.conf"; fail_unless(!recursive_delete(CONFBASE)); build_file(conffile, buf); fail_unless(!conf_load_global_only(conffile, confs)); for(l=get_strlist(confs[OPT_STARTDIR]); l; l=l->next) if(l->flag) fail_unless(!find_files_begin(NULL, ff, confs, l->path)); fail_unless(!recursive_delete(CONFBASE)); }
static void setup_datadir_tmp(struct slist *slist, struct fdirs *fdirs, struct conf **confs) { char *path; struct sbuf *s; for(s=slist->head; s; s=s->next) { if(!sbuf_is_filedata(s)) continue; path=datadirtmp_path(fdirs, s); build_file(path, /*content*/path); } }
static void test_cstat_set_run_status_server_crashed(enum protocol protocol) { struct cstat *cstat; struct sdirs *sdirs; cstat=set_run_status_setup(protocol, 1 /*permitted*/); fail_unless(recursive_delete(BASE)==0); build_storage_dirs((struct sdirs *)cstat->sdirs, sd1w, ARR_LEN(sd1w)); sdirs=(struct sdirs *)cstat->sdirs; build_file(sdirs->lock->path, NULL); cstat_set_run_status(cstat); fail_unless(cstat->run_status==RUN_STATUS_SERVER_CRASHED); tear_down(&cstat); }
std::vector<std::string> build(std::string line, std::string prefix) { std::string::size_type inclpos = line.find(include); std::string::size_type virtpos = line.find(virt); if (inclpos == std::string::npos && virtpos == std::string::npos) { return std::vector<std::string>(1, prefix + line + '\n'); } if (inclpos != std::string::npos) { std::string newpre = prefix + line.substr(0, inclpos); std::string newfile = line.substr(inclpos + sizeof(include) - 1); return build_file(newfile, newpre); } if (virtpos == std::string::npos) { throw std::runtime_error("Should not be reached"); } std::string newpre = prefix + line.substr(0, virtpos); std::string funcname = line.substr(virtpos + sizeof(virt) - 1); std::string newfile = virtclass + "." + funcname; return build_file(newfile, newpre); }
static void test_xattr(struct xattrdata x) { size_t rlen=0; char metasymbol=META_XATTR; char *retrieved=NULL; const char *path=NULL; const char *myfile=BASE "/myfile"; char expected[256]; fail_unless(recursive_delete(BASE)==0); build_file(myfile, NULL); if(x.do_dir) path=BASE; else path=myfile; #if defined(HAVE_FREEBSD_OS) || \ defined(HAVE_NETBSD_OS) metasymbol=META_XATTR_BSD; #endif #if defined(HAVE_LINUX_OS) || \ defined(HAVE_DARWIN_OS) metasymbol=META_XATTR; #endif snprintf(expected, sizeof(expected), "%s", x.expected_read); expected[0]=metasymbol; fail_unless(has_xattr(path)==0); fail_unless(!set_xattr( NULL, // asfd path, x.write, strlen(x.write), metasymbol, NULL // cntr )); fail_unless(!get_xattr( NULL, // asfd path, &retrieved, &rlen, NULL // cntr )); fail_unless(rlen==strlen(expected)); assert_xattr(expected, retrieved, rlen); free_w(&retrieved); tear_down(); }
END_TEST static struct cstat *test_cstat_remove_setup(struct conf ***globalcs, const char *cnames[]) { struct cstat *clist=NULL; clean(); fail_unless((*globalcs=confs_alloc())!=NULL); fail_unless(!confs_init(*globalcs)); build_file(GLOBAL_CONF, MIN_SERVER_CONF); fail_unless(!conf_load_global_only(GLOBAL_CONF, *globalcs)); build_clientconfdir_files(cnames); fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR)); assert_cstat_list(clist, cnames); return clist; }
static void gb_project_tree_builder_build_node (IdeTreeBuilder *builder, IdeTreeNode *node) { GbProjectTreeBuilder *self = (GbProjectTreeBuilder *)builder; GObject *item; g_return_if_fail (GB_IS_PROJECT_TREE_BUILDER (self)); item = ide_tree_node_get_item (node); if (IDE_IS_CONTEXT (item)) build_context (self, node); else if (GB_IS_PROJECT_FILE (item)) build_file (self, node); }
static void do_build_storage_dirs(struct sdirs *sdirs, struct sd *s, int len, int compressed_logs) { int i=0; time_t t=0; char backup[128]=""; char timestamp_path[128]=""; fail_unless(!build_path_w(sdirs->client)); fail_unless(!mkdir(sdirs->client, 0777)); for(i=0; i<len; i++) { snprintf(backup, sizeof(backup), "%s/%s", sdirs->client, s[i].timestamp); snprintf(timestamp_path, sizeof(timestamp_path), "%s/timestamp", backup); fail_unless(!mkdir(backup, 0777)); fail_unless(!timestamp_write(timestamp_path, s[i].timestamp)); if(s[i].flags & BU_CURRENT) fail_unless(!symlink(s[i].timestamp, sdirs->current)); if(s[i].flags & BU_WORKING) fail_unless(!symlink(s[i].timestamp, sdirs->working)); if(s[i].flags & BU_FINISHING) fail_unless(!symlink(s[i].timestamp, sdirs->finishing)); if(s[i].flags & BU_MANIFEST) create_file(backup, "manifest", compressed_logs); if(s[i].flags & BU_LOG_BACKUP) create_file(backup, "log", compressed_logs); if(s[i].flags & BU_LOG_RESTORE) create_file(backup, "restorelog", compressed_logs); if(s[i].flags & BU_LOG_VERIFY) create_file(backup, "verifylog", compressed_logs); if(sdirs->protocol==PROTO_1) { if(s[i].flags & BU_HARDLINKED) create_file(backup, "hardlinked", 0); } // This one is never compressed. if(sdirs->global_sparse) build_file(sdirs->global_sparse, NULL); t+=60*60*24; // Add one day. } }
int main(int argc, char** argv) { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " input\n"; return 1; } std::string inputfile(argv[1]); virtclass = inputfile.substr(0, inputfile.find('.')); try { std::vector<std::string> output(build_file(argv[1])); std::copy(output.begin(), output.end(), std::ostream_iterator<std::string>(std::cout, "\n")); } catch (std::exception& e) { std::cerr << e.what() << '\n'; return 1; } }
END_TEST START_TEST(test_cstat_add_out_of_order) { struct cstat *clist=NULL; struct conf **globalcs; const char *cnames31204[] = {"cli3", "cli1", "cli2", "cli0", "cli4", NULL}; const char *cnames01234[] = {"cli0", "cli1", "cli2", "cli3", "cli4", NULL}; clean(); fail_unless((globalcs=confs_alloc())!=NULL); fail_unless(!confs_init(globalcs)); build_file(GLOBAL_CONF, MIN_SERVER_CONF); fail_unless(!conf_load_global_only(GLOBAL_CONF, globalcs)); build_clientconfdir_files(cnames31204); fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR)); assert_cstat_list(clist, cnames01234); test_cstat_remove_teardown(&globalcs, &clist); }
static void run_test(int expected_ret, int slist_entries, enum protocol protocol, void setup_callback(struct asfd *asfd, struct slist *slist)) { int result; struct slist *slist=NULL; const char *conffile=BASE "/burp.conf"; struct asfd *asfd; struct conf **confs; const char *buf; if(protocol==PROTO_1) buf=MIN_CLIENT_CONF "protocol=1\n"; else buf=MIN_CLIENT_CONF "protocol=2\n"; base64_init(); asfd=asfd_mock_setup(&reads, &writes); confs=setup_conf(); fail_unless(recursive_delete(BASE)==0); build_file(conffile, buf); fail_unless(!conf_load_global_only(conffile, confs)); if(slist_entries) slist=build_slist_phase1(BASE, protocol, slist_entries); setup_callback(asfd, slist); result=do_restore_client(asfd, confs, ACTION_RESTORE, 0 /* vss_restore */); fail_unless(result==expected_ret); slist_free(&slist); tear_down(&asfd, &confs); }
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"); }
void build_clientconfdir_file(const char *file, const char *content) { const char *path=get_clientconfdir_path(file); build_file(path, content); }
static void run_test(int expected_ret, enum protocol protocol, int manio_entries, int blocks_per_file, void setup_asfds_callback(struct asfd *asfd, struct slist *slist)) { struct async *as; struct asfd *asfd; struct sdirs *sdirs; struct conf **confs; struct slist *slist=NULL; char *dir_for_notify=NULL; prng_init(0); base64_init(); hexmap_init(); setup(protocol, &as, &sdirs, &confs); set_string(confs[OPT_BACKUP], "1"); set_protocol(confs, protocol); asfd=asfd_mock_setup(&reads, &writes); as->asfd_add(as, asfd); as->read_write=async_rw_simple; as->read_quick=async_rw_simple; asfd->as=as; build_storage_dirs(sdirs, sd1, ARR_LEN(sd1)); if(manio_entries) { struct sbuf *s; if(protocol==PROTO_2) slist=build_manifest_with_data_files(sdirs->cmanifest, sdirs->data, manio_entries, blocks_per_file); else { slist=build_manifest(sdirs->cmanifest, protocol, manio_entries, 0 /*phase*/); for(s=slist->head; s; s=s->next) { char path[256]; if(!sbuf_is_filedata(s)) continue; snprintf(path, sizeof(path), "%s/%s%s", sdirs->currentdata, TREE_DIR, s->path.buf); build_file(path, "data"); } } } setup_asfds_callback(asfd, slist); fail_unless(do_restore_server( asfd, sdirs, ACTION_RESTORE, 0, // srestore &dir_for_notify, confs )==expected_ret); if(!expected_ret) { // FIX THIS: Should check for the presence and correctness of // changed and unchanged manios. } slist_free(&slist); free_w(&dir_for_notify); tear_down(&as, &asfd, &sdirs, &confs); }