예제 #1
0
int
cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
{
	struct args		*args = self->args;
	struct key_binding	*bd;
	int			 key;

	if (args_has(args, 'a')) {
		while (!SPLAY_EMPTY(&key_bindings)) {
			bd = SPLAY_ROOT(&key_bindings);
			SPLAY_REMOVE(key_bindings, &key_bindings, bd);
			cmd_list_free(bd->cmdlist);
			xfree(bd);
		}
		return (0);
	}

	key = key_string_lookup_string(args->argv[0]);
	if (key == KEYC_NONE) {
		ctx->error(ctx, "unknown key: %s", args->argv[0]);
		return (-1);
	}

	if (args_has(args, 't'))
		return (cmd_unbind_key_table(self, ctx, key));

	if (!args_has(args, 'n'))
		key |= KEYC_PREFIX;
	key_bindings_remove(key);
	return (0);
}
예제 #2
0
파일: policy.c 프로젝트: radixo/openbsd-src
void
systrace_cleanpolicy(struct policy *policy)
{
    struct filter *filter;
    struct policy_syscall *pflq;
    int i;

    /* Set the default policy to ask */
    for (i = 0; i < INTERCEPT_MAXSYSCALLNR; i++)
        policy->kerneltable[i] = ICPOLICY_ASK;

    while ((filter = TAILQ_FIRST(&policy->prefilters)) != NULL) {
        TAILQ_REMOVE(&policy->prefilters, filter, policy_next);
        filter_free(filter);
    }

    while ((filter = TAILQ_FIRST(&policy->filters)) != NULL) {
        TAILQ_REMOVE(&policy->filters, filter, policy_next);
        filter_free(filter);
    }

    while ((pflq = SPLAY_ROOT(&policy->pflqs)) != NULL) {
        SPLAY_REMOVE(syscalltree, &policy->pflqs, pflq);

        while ((filter = TAILQ_FIRST(&pflq->flq)) != NULL) {
            TAILQ_REMOVE(&pflq->flq, filter, next);
            filter_free(filter);
        }

        free(pflq);
    }
}
예제 #3
0
파일: filter.c 프로젝트: 4sp1r3/Honeyd
void
filter_free(struct filtertree *filters)
{
	struct filter *filter;

	while ((filter = SPLAY_ROOT(filters)) != NULL) {
		SPLAY_REMOVE(filtertree, filters, filter);
		free(filter);
	}
	free(filters);
}
예제 #4
0
파일: tree.c 프로젝트: clongeau/opensmtpd
void
tree_merge(struct tree *dst, struct tree *src)
{
	struct treeentry	*entry;

	while (!SPLAY_EMPTY(src)) {
		entry = SPLAY_ROOT(src);
		SPLAY_REMOVE(tree, src, entry);
		if (SPLAY_INSERT(tree, dst, entry))
			errx(1, "tree_merge: duplicate");
	}
}
예제 #5
0
void
key_bindings_clean(void)
{
	struct key_binding	*bd;

	while (!SPLAY_EMPTY(&dead_key_bindings)) {
		bd = SPLAY_ROOT(&dead_key_bindings);
		SPLAY_REMOVE(key_bindings, &dead_key_bindings, bd);
		cmd_list_free(bd->cmdlist);
		xfree(bd);
	}
}
예제 #6
0
파일: analyze.c 프로젝트: 4sp1r3/Honeyd
void
aux_free(void *arg)
{
	struct aux *aux = arg;
	struct auxtree *tree = &aux->tree;
	struct auxkey *key;

	while ((key = SPLAY_ROOT(tree)) != NULL) {
		SPLAY_REMOVE(auxtree, tree, key);
		free(key);
	}
	free(arg);
}
예제 #7
0
void
options_free(struct options *oo)
{
	struct options_entry	*o;

	while (!SPLAY_EMPTY(&oo->tree)) {
		o = SPLAY_ROOT(&oo->tree);
		SPLAY_REMOVE(options_tree, &oo->tree, o);
		xfree(o->name);
		if (o->type == OPTIONS_STRING)
			xfree(o->value.string);
		xfree(o);
	}
}
예제 #8
0
void
mode_key_free_trees(void)
{
	const struct mode_key_table	*mtab;
	struct mode_key_binding		*mbind;

	for (mtab = mode_key_tables; mtab->name != NULL; mtab++) {
		while (!SPLAY_EMPTY(mtab->tree)) {
			mbind = SPLAY_ROOT(mtab->tree);
			SPLAY_REMOVE(mode_key_tree, mtab->tree, mbind);
			xfree(mbind);
		}
	}
}
예제 #9
0
int
tree_root(struct tree *t, uint64_t *id, void **data)
{
	struct treeentry	*entry;

	entry = SPLAY_ROOT(&t->tree);
	if (entry == NULL)
		return (0);
	if (id)
		*id = entry->id;
	if (data)
		*data = entry->data;
	return (1);
}
예제 #10
0
void
tree_merge(struct tree *dst, struct tree *src)
{
	struct treeentry	*entry;

	while (!SPLAY_EMPTY(&src->tree)) {
		entry = SPLAY_ROOT(&src->tree);
		SPLAY_REMOVE(_tree, &src->tree, entry);
		if (SPLAY_INSERT(_tree, &dst->tree, entry))
			errx(1, "tree_merge: duplicate");
	}
	dst->count += src->count;
	src->count = 0;
}
예제 #11
0
파일: dict.c 프로젝트: edeln/OpenSMTPD
void
dict_merge(struct dict *dst, struct dict *src)
{
	struct dictentry	*entry;

	while (!SPLAY_EMPTY(&src->dict)) {
		entry = SPLAY_ROOT(&src->dict);
		SPLAY_REMOVE(_dict, &src->dict, entry);
		if (SPLAY_INSERT(_dict, &dst->dict, entry))
			errx(1, "dict_merge: duplicate");
	}
	dst->count += src->count;
	src->count = 0;
}
예제 #12
0
파일: dict.c 프로젝트: edeln/OpenSMTPD
int
dict_root(struct dict *d, const char **k, void **data)
{
	struct dictentry	*entry;

	entry = SPLAY_ROOT(&d->dict);
	if (entry == NULL)
		return (0);
	if (k)
		*k = entry->key;
	if (data)
		*data = entry->data;
	return (1);
}
예제 #13
0
int
main(int argc, char **argv)
{
	struct node *tmp, *ins;
	int i, max, min;

	SPLAY_INIT(&root);

	for (i = 0; i < ITER; i++) {
		tmp = malloc(sizeof(struct node));
		if (tmp == NULL) err(1, "malloc");
		do {
			tmp->key = arc4random_uniform(MAX-MIN);
			tmp->key += MIN;
		} while (SPLAY_FIND(tree, &root, tmp) != NULL);
		if (i == 0)
			max = min = tmp->key;
		else {
			if (tmp->key > max)
				max = tmp->key;
			if (tmp->key < min)
				min = tmp->key;
		}
		if (SPLAY_INSERT(tree, &root, tmp) != NULL)
			errx(1, "SPLAY_INSERT failed");
	}

	ins = SPLAY_MIN(tree, &root);
	if (ins->key != min)
		errx(1, "min does not match");
	tmp = ins;
	ins = SPLAY_MAX(tree, &root);
	if (ins->key != max)
		errx(1, "max does not match");

	if (SPLAY_REMOVE(tree, &root, tmp) != tmp)
		errx(1, "SPLAY_REMOVE failed");

	for (i = 0; i < ITER - 1; i++) {
		tmp = SPLAY_ROOT(&root);
		if (tmp == NULL)
			errx(1, "SPLAY_ROOT error");
		if (SPLAY_REMOVE(tree, &root, tmp) != tmp)
			errx(1, "SPLAY_REMOVE error");
		free(tmp);
	}

	exit(0);
}
예제 #14
0
void
purge_config(uint8_t what)
{
	struct listener	*l;
	struct map	*m;
	struct rule	*r;
	struct ssl	*s;
	struct mapel	*me;

	if (what & PURGE_LISTENERS) {
		while ((l = TAILQ_FIRST(env->sc_listeners)) != NULL) {
			TAILQ_REMOVE(env->sc_listeners, l, entry);
			free(l);
		}
		free(env->sc_listeners);
		env->sc_listeners = NULL;
	}
	if (what & PURGE_MAPS) {
		while ((m = TAILQ_FIRST(env->sc_maps)) != NULL) {
			TAILQ_REMOVE(env->sc_maps, m, m_entry);
			while ((me = TAILQ_FIRST(&m->m_contents))) {
				TAILQ_REMOVE(&m->m_contents, me, me_entry);
				free(me);
			}
			free(m);
		}
		free(env->sc_maps);
		env->sc_maps = NULL;
	}
	if (what & PURGE_RULES) {
		while ((r = TAILQ_FIRST(env->sc_rules)) != NULL) {
			TAILQ_REMOVE(env->sc_rules, r, r_entry);
			free(r);
		}
		free(env->sc_rules);
		env->sc_rules = NULL;
	}
	if (what & PURGE_SSL) {
		while ((s = SPLAY_ROOT(env->sc_ssl)) != NULL) {
			SPLAY_REMOVE(ssltree, env->sc_ssl, s);
			free(s->ssl_cert);
			free(s->ssl_key);
			free(s);
		}
		free(env->sc_ssl);
		env->sc_ssl = NULL;
	}
}
예제 #15
0
파일: options.c 프로젝트: Hooman3/minix
void
options_free(struct options *oo)
{
	struct options_entry	*o;

	while (!SPLAY_EMPTY(&oo->tree)) {
		o = SPLAY_ROOT(&oo->tree);
		SPLAY_REMOVE(options_tree, &oo->tree, o);
		xfree(o->name);
		if (o->type == OPTIONS_STRING)
			xfree(o->str);
		else if (o->type == OPTIONS_DATA)
			o->freefn(o->data);
		xfree(o);
	}
}
예제 #16
0
파일: dict.c 프로젝트: edeln/OpenSMTPD
int
dict_poproot(struct dict *d, void **data)
{
	struct dictentry	*entry;

	entry = SPLAY_ROOT(&d->dict);
	if (entry == NULL)
		return (0);
	if (data)
		*data = entry->data;
	SPLAY_REMOVE(_dict, &d->dict, entry);
	free(entry);
	d->count -= 1;

	return (1);
}
예제 #17
0
파일: tree.c 프로젝트: clongeau/opensmtpd
int
tree_poproot(struct tree *t, uint64_t *id, void **data)
{
	struct treeentry	*entry;

	entry = SPLAY_ROOT(t);
	if (entry == NULL)
		return (0);
	if (id)
		*id = entry->id;
	if (data)
		*data = entry->data;
	SPLAY_REMOVE(tree, t, entry);
	free(entry);
	return (1);
}
예제 #18
0
int
tree_poproot(struct tree *t, uint64_t *id, void **data)
{
	struct treeentry	*entry;

	entry = SPLAY_ROOT(&t->tree);
	if (entry == NULL)
		return (0);
	if (id)
		*id = entry->id;
	if (data)
		*data = entry->data;
	SPLAY_REMOVE(_tree, &t->tree, entry);
	free(entry);
	t->count -= 1;

	return (1);
}
예제 #19
0
int
cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
{
	struct cmd_unbind_key_data	*data = self->data;
	struct key_binding		*bd;

	if (data == NULL)
		return (0);
	if (data->flag_all) {
		while (!SPLAY_EMPTY(&key_bindings)) {
			bd = SPLAY_ROOT(&key_bindings);
			SPLAY_REMOVE(key_bindings, &key_bindings, bd);
			cmd_list_free(bd->cmdlist);
			xfree(bd);
		}
	} else {
		if (data->tablename != NULL)
			return (cmd_unbind_key_table(self, ctx));

		key_bindings_remove(data->key);
	}

	return (0);
}