コード例 #1
0
ファイル: test_cstat.c プロジェクト: rubenk/burp
static void do_test_cstat_set_backup_list(enum protocol protocol)
{
	struct cstat *cstat;
	cstat=setup_cstat(CNAME, protocol);
	ck_assert_str_eq(CLIENTCONFDIR "/" CNAME, cstat->conffile);

	cstat->permitted=1;

	fail_unless(recursive_delete(BASE)==0);
	build_storage_dirs((struct sdirs *)cstat->sdirs,
		sd123, ARR_LEN(sd123));
	fail_unless(!cstat_set_backup_list(cstat));
	fail_unless(cstat->bu!=NULL);

	fail_unless(recursive_delete(BASE)==0);
	build_storage_dirs((struct sdirs *)cstat->sdirs,
		sd13, ARR_LEN(sd13));
	fail_unless(!cstat_set_backup_list(cstat));
	fail_unless(cstat->bu!=NULL);

	fail_unless(recursive_delete(BASE)==0);
	build_storage_dirs((struct sdirs *)cstat->sdirs,
		sd12345, ARR_LEN(sd12345));
	fail_unless(!cstat_set_backup_list(cstat));
	fail_unless(cstat->bu!=NULL);

	cstat->permitted=0;
	fail_unless(!cstat_set_backup_list(cstat));
	fail_unless(cstat->bu==NULL);

	tear_down(&cstat);
}
コード例 #2
0
ファイル: test_json_output.c プロジェクト: ZungBang/burp
END_TEST

START_TEST(cleanup)
{
    // Not a test. Just wanted to cleanup before and after this suite.
    fail_unless(!recursive_delete(BASE));
    fail_unless(!recursive_delete(SDIRS));
    fail_unless(!recursive_delete(CONF_BASE));
}
コード例 #3
0
ファイル: test_find.c プロジェクト: vanElden/burp
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));
}
コード例 #4
0
ファイル: rubble.c プロジェクト: Sherlock221B/burp
int check_for_rubble_burp2(struct asfd *asfd, struct sdirs *sdirs,
	const char *incexc, int *resume, struct conf *cconf)
{
	// FIX THIS - currently just deletes the interrupted backup.
	ssize_t len=0;
	char *real=NULL;
	char lnk[32]="";
	if((len=readlink(sdirs->working, lnk, sizeof(lnk)-1))<0)
		return 0;
	else if(!len)
	{
		unlink(sdirs->working);
		return 0;
	}
	lnk[len]='\0';
	if(!(real=prepend_s(sdirs->client, lnk)))
	{
		log_and_send_oom(asfd, __func__);
		return -1;
	}
	if(recursive_delete(real, "", 1))
	{
		char msg[256]="";
		snprintf(msg, sizeof(msg),
			"Could not remove interrupted directory: %s", real);
		log_and_send(asfd, msg);
		return -1;
	}
	unlink(sdirs->working);
	return 0;
}
コード例 #5
0
ファイル: test_find.c プロジェクト: vanElden/burp
static FF_PKT *setup(struct conf ***confs)
{
	FF_PKT *ff;
	fail_unless(!recursive_delete(BASE));

	// Create the root directory, so that we can figure out the absolute
	// path to it, then delete it so that the root directory can be
	// included when setting up the expected file system.
	fail_unless(!mkdir(BASE, 0777));
	fail_unless(realpath(BASE, fullpath)!=NULL);
	fail_unless(!recursive_delete(BASE));

	fail_unless((ff=find_files_init(send_file_callback))!=NULL);
	*confs=setup_conf();
	return ff;
}
コード例 #6
0
ファイル: test_manio.c プロジェクト: ZungBang/burp
END_TEST

static void test_manifest_tell_seek(enum protocol protocol, int phase)
{
	struct slist *slist;
	struct manio *manio;
	struct sbuf *sb=NULL;
	man_off_t *offset=NULL;
	int entries=1000;
	prng_init(0);
	base64_init();
	hexmap_init();
	recursive_delete(path);

	slist=build_manifest(path, protocol, entries, phase);
	fail_unless(slist!=NULL);

	sb=slist->head;
	fail_unless((manio=do_manio_open(path, "rb", protocol, phase))!=NULL);
	read_manifest(&sb, manio, 0, entries/2, protocol, phase);
	fail_unless((offset=manio_tell(manio))!=NULL);
	fail_unless(sb!=NULL);
	fail_unless(!manio_close(&manio));

	fail_unless((manio=do_manio_open(path, "rb", protocol, phase))!=NULL);
	fail_unless(!manio_seek(manio, offset));
	read_manifest(&sb, manio, entries/2, entries, protocol, phase);
	fail_unless(sb==NULL);
	fail_unless(!manio_close(&manio));
	fail_unless(!manio);

	slist_free(&slist);
	man_off_t_free(&offset);
	tear_down();
}
コード例 #7
0
ファイル: worker-launcher.c プロジェクト: rajkrrsingh/storm
static int remove_files_from_dir(const char *path) {
  DIR *dir;
  struct dirent *entry;
  dir = opendir(path);
  if (dir) {
    int exit_code = 0;
    while ((entry = readdir(dir)) != NULL) {
      if(strcmp(entry->d_name, ".") == 0
         || strcmp(entry->d_name, "..") == 0) {
          continue;
      }
      char *newpath;
      int bytesPrinted = asprintf(&newpath, "%s/%s", path, entry->d_name);
      if (bytesPrinted == -1) {
        //asprintf failed, stop the process
        exit(EXIT_FAILURE);
      }
      if(newpath) {
        // Recur on anything in the directory.
        int new_exit = recursive_delete(newpath, 0);
        if(!exit_code) {
          exit_code = new_exit;
        }
      }
      free(newpath);
    }
    closedir(dir);
    return exit_code;
  }
  return -1;
}
コード例 #8
0
ファイル: deleteme.c プロジェクト: pkdevbox/burp
int deleteme_maybe_delete(struct conf **cconfs, struct sdirs *sdirs)
{
	// If manual_delete is on, they will have to delete the files
	// manually, via a cron job or something.
	if(get_string(cconfs[OPT_MANUAL_DELETE])) return 0;
	return recursive_delete(sdirs->deleteme);
}
コード例 #9
0
ファイル: test_json_output.c プロジェクト: ZungBang/burp
static void tear_down(struct asfd **asfd)
{
    asfd_free(asfd);
    fail_unless(!fzp_close(&output));
    fail_unless(!recursive_delete(CLIENTCONFDIR));
    alloc_check();
}
コード例 #10
0
ファイル: test_list.c プロジェクト: EmisFR/burp
static void tear_down(struct asfd **asfd, struct sdirs **sdirs)
{
	asfd_free(asfd);
	asfd_mock_teardown(&reads, &writes);
	sdirs_free(sdirs);
	fail_unless(recursive_delete(BASE)==0);
	alloc_check();
}
コード例 #11
0
ファイル: test_backup_phase4.c プロジェクト: ZungBang/burp
static void setup(
	struct sdirs **sdirs, struct fdirs **fdirs, struct conf ***confs)
{
	if(sdirs) *sdirs=setup_sdirs();
	if(fdirs) *fdirs=setup_fdirs(*sdirs);
	if(confs) *confs=setup_conf();
	fail_unless(!recursive_delete(BASE));
}
コード例 #12
0
ファイル: test_backup_phase2.c プロジェクト: grealish/burp
static void setup(struct async **as,
	struct sdirs **sdirs, struct conf ***confs)
{
	if(as) *as=setup_async();
	if(sdirs) *sdirs=setup_sdirs();
	if(confs) *confs=setup_conf();
	fail_unless(!recursive_delete(BASE));
}
コード例 #13
0
ファイル: test_dpth.c プロジェクト: adrianimboden/burp
static struct dpth *setup(void)
{
	struct dpth *dpth;
	hexmap_init();
	fail_unless(recursive_delete(lockpath, "", 1)==0);
	fail_unless((dpth=dpth_alloc())!=NULL);
	assert_components(dpth, 0, 0, 0, 0);
	return dpth;
}
コード例 #14
0
ファイル: delete.c プロジェクト: Sherlock221B/burp
static int recursive_delete_w(struct sdirs *sdirs, struct bu *bu)
{
	if(recursive_delete(sdirs->deleteme, NULL, 1))
	{
		logp("Error when trying to delete %s\n", bu->path);
		return -1;
	}
	return 0;
}
コード例 #15
0
ファイル: test_find.c プロジェクト: vanElden/burp
static void tear_down(FF_PKT **ff, struct conf ***confs)
{
	fail_unless(e==NULL);
	find_files_free(ff);
	confs_free(confs);
	strlists_free(&expected);
	fail_unless(recursive_delete(BASE)==0);
	alloc_check();
}
コード例 #16
0
ファイル: deleteme.c プロジェクト: Shloub/burp
int deleteme_maybe_delete(struct conf **cconfs, const char *basedir)
{
	char *deleteme;
	// If manual_delete is on, they will have to delete the files
	// manually, via a cron job or something.
	if(get_string(cconfs[OPT_MANUAL_DELETE])) return 0;
	if(!(deleteme=deleteme_get_path(basedir, cconfs))) return -1;
	return recursive_delete(deleteme, NULL, 1 /* delete all */);
}
コード例 #17
0
ファイル: test_backup_phase4.c プロジェクト: ZungBang/burp
static void tear_down(
	struct sdirs **sdirs, struct fdirs **fdirs, struct conf ***confs)
{
	sdirs_free(sdirs);
	fdirs_free(fdirs);
	confs_free(confs);
	fail_unless(!recursive_delete(BASE));
	alloc_check();
}
コード例 #18
0
ファイル: test_restore.c プロジェクト: ZungBang/burp
static void tear_down(struct asfd **asfd, struct conf ***confs)
{
	asfd_free(asfd);
	confs_free(confs);
	asfd_mock_teardown(&reads, &writes);
//printf("%d %d\n", alloc_count, free_count);
	alloc_check();
	fail_unless(recursive_delete(BASE)==0);
}
コード例 #19
0
static void recursive_delete(LinkList* list, GTreeNode* node)
{
    if( (list != NULL) && (node != NULL) )
    {
        GTreeNode* parent = node->parent;
        int index = -1;
        int i = 0;
        
        for(i=0; i<LinkList_Length(list); i++)
        {
            TLNode* trNode = (TLNode*)LinkList_Get(list, i);
             
            if( trNode->node == node )
            {
                LinkList_Delete(list, i);
                
                free(trNode);
                
                index = i;
                
                break;
            }
        }
          
        if( index >= 0 )
        {  
            if( parent != NULL )
            {
                 for(i=0; i<LinkList_Length(parent->child); i++)
                 {
                     TLNode* trNode = (TLNode*)LinkList_Get(parent->child, i);
                     
                     if( trNode->node == node )
                     {
                         LinkList_Delete(parent->child, i);
                         
                         free(trNode);
                         
                         break;
                     }
                 }               
            }
            
            while( LinkList_Length(node->child) > 0 )
            {
                TLNode* trNode = (TLNode*)LinkList_Get(node->child, 0);
                
                recursive_delete(list, trNode->node);
            }
            
            LinkList_Destroy(node->child);
        
            free(node);
        }
    }
}
コード例 #20
0
ファイル: test_backup_phase2.c プロジェクト: grealish/burp
static void tear_down(struct async **as,
	struct sdirs **sdirs, struct conf ***confs)
{
	async_free(as);
	sdirs_free(sdirs);
	confs_free(confs);
	fail_unless(!recursive_delete(BASE));
//printf("%d %d\n", alloc_count, free_count);
	alloc_check();
}
コード例 #21
0
ファイル: server.c プロジェクト: rti7743/samba
/*
  cleanup temporary files. This is the new alternative to
  TDB_CLEAR_IF_FIRST. Unfortunately TDB_CLEAR_IF_FIRST is not
  efficient on unix systems due to the lack of scaling of the byte
  range locking system. So instead of putting the burden on tdb to
  cleanup tmp files, this function deletes them. 
*/
static void cleanup_tmp_files(struct loadparm_context *lp_ctx)
{
	char *path;
	TALLOC_CTX *mem_ctx = talloc_new(NULL);

	path = smbd_tmp_path(mem_ctx, lp_ctx, NULL);

	recursive_delete(path);
	talloc_free(mem_ctx);
}
コード例 #22
0
ファイル: art.c プロジェクト: biokoda/actordb_qdrv
/**
 * Deletes a value from the ART tree
 * @arg t The tree
 * @arg key The key
 * @arg key_len The length of the key
 * @return NULL if the item was not found, otherwise
 * the value pointer is returned.
 */
void* art_delete(art_tree *t, const unsigned char *key, int key_len) {
    art_leaf *l = recursive_delete(t->root, &t->root, key, key_len, 0);
    if (l) {
        t->size--;
        void *old = l->value;
        free(l);
        return old;
    }
    return NULL;
}
コード例 #23
0
ファイル: delete.c プロジェクト: ZungBang/burp
static int recursive_delete_w(struct sdirs *sdirs, struct bu *bu,
	const char *manual_delete)
{
	if(manual_delete) return 0;
	if(recursive_delete(sdirs->deleteme))
	{
		logp("Error when trying to delete %s\n", bu->path);
		return -1;
	}
	return 0;
}
コード例 #24
0
ファイル: test_cstat.c プロジェクト: rubenk/burp
static void test_cstat_set_run_status_client_crashed(enum protocol protocol)
{
	struct cstat *cstat;
	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));
	cstat_set_run_status(cstat);
	fail_unless(cstat->run_status==RUN_STATUS_CLIENT_CRASHED);
	tear_down(&cstat);
}
コード例 #25
0
GTreeData* GTree_Delete(GTree* tree, int pos)
{
    TLNode* trNode = (TLNode*)LinkList_Get(tree, pos);
    GTreeData* ret = NULL;
    
    if( trNode != NULL )
    {
        ret = trNode->node->data;
        
        recursive_delete(tree, trNode->node);
    }
    
    return ret;
}
コード例 #26
0
ファイル: rubble.c プロジェクト: ZungBang/burp
static int working_delete(struct async *as, struct sdirs *sdirs)
{
	// Try to remove it and start again.
	logp("deleting old working directory\n");
	if(recursive_delete(sdirs->rworking))
	{
		log_and_send(as->asfd,
			"Old working directory is in the way.\n");
		return -1;
	}
	// Get rid of the symlink.
	unlink(sdirs->working);
	return 0;
}
コード例 #27
0
ファイル: test_cstat.c プロジェクト: rubenk/burp
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);
}
コード例 #28
0
ファイル: test_xattr.c プロジェクト: EmisFR/burp
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();
}
コード例 #29
0
ファイル: test_json_output.c プロジェクト: ZungBang/burp
static void do_test_json_send_clients_with_backup(const char *path,
        struct sd *sd, int s, const char *specific_client)
{
    struct asfd *asfd;
    struct cstat *c=NULL;
    struct cstat *clist=NULL;
    const char *cnames[] = {"cli1", "cli2", "cli3", NULL};
    fail_unless(recursive_delete(CLIENTCONFDIR)==0);
    build_clientconfdir_files(cnames, NULL);
    fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR));
    assert_cstat_list(clist, cnames);
    for(c=clist; c; c=c->next)
    {
        c->permitted=1;
        c->protocol=PROTO_1;
        fail_unless((c->sdirs=setup_sdirs(c->protocol, c->name))!=NULL);
        build_storage_dirs((struct sdirs *)c->sdirs, sd, s);
        fail_unless(!cstat_set_backup_list(c));
        fail_unless(c->bu!=NULL);
        // Hack the cntr timestamps so that they are always the same.
        c->cntr->ent[(uint8_t)CMD_TIMESTAMP]->count=200;
        c->cntr->ent[(uint8_t)CMD_TIMESTAMP_END]->count=400;

    }
    asfd=asfd_setup(path);

    c=NULL;
    if(specific_client)
        fail_unless((c=cstat_get_by_name(clist, specific_client))!=NULL);

    fail_unless(!json_send(asfd, clist, c, NULL, NULL, NULL, 0/*cache*/));
    cstat_list_free_sdirs(clist);
    cstat_list_free(&clist);
    fail_unless(!recursive_delete(SDIRS));
    tear_down(&asfd);
}
コード例 #30
0
ファイル: bstree.c プロジェクト: RongJunFei/data
static BSTreeNode* recursive_delete(BSTreeNode** pRoot, BSKey* key, BSTree_Compare* compare)
{
    BSTreeNode* ret = NULL;
    
    if( (pRoot != NULL) && (*pRoot != NULL) )
    {
        int r = compare(key, (*pRoot)->key);
        
        if( r == 0 )
        {
            ret = delete_node(pRoot);
        }
        else if( r < 0 )
        {
            ret = recursive_delete(&((*pRoot)->left), key, compare);
        }
        else if( r > 0 )
        {
            ret = recursive_delete(&((*pRoot)->right), key, compare);
        }
    }
    
    return ret;
}