Пример #1
0
void sec_mod_client_db_deinit(sec_mod_st *sec)
{
struct htable *db = sec->client_db;

	htable_clear(db);
	talloc_free(db);
}
Пример #2
0
/**
 * @fn void virtual_cache_clear(virtual_cache_t vc)
 * @brief Clear the virtual cache entries.
 * @param vc The virtual cache pointer.
 */
void virtual_cache_clear(virtual_cache_t vc) {
  struct virtual_cache_s *v = (struct virtual_cache_s*)vc;
  virtual_cache_item_t item;
  if(!v) return;
  if(v->table && v->table->kcount != 0) {
    int count, i;
    char** keys = NULL;
    count = htable_get_keys(v->table, &keys);
    for(i = 0; i < count; i++) {
      item = htable_lookup(v->table, keys[i]);
      virtual_cache_item_delete(item);
    }
    if(keys) free(keys);
    htable_clear(v->table);
  }
}
Пример #3
0
void ip_lease_deinit(struct ip_lease_db_st* db)
{
struct ip_lease_st * cache;
struct htable_iter iter;

	cache = htable_first(&db->ht, &iter);
	while(cache != NULL) {
		free(cache);
		
		cache = htable_next(&db->ht, &iter);
	}
	
	htable_clear(&db->ht);
	
	return;
}
Пример #4
0
void ip_lease_deinit(struct ip_lease_db_st* db)
{
struct ip_lease_st * cache;
struct htable_iter iter;

	cache = htable_first(&db->ht, &iter);
	while(cache != NULL) {
		/* disable the destructor */
		cache->db = NULL;
		talloc_free(cache);
		
		cache = htable_next(&db->ht, &iter);
	}
	htable_clear(&db->ht);
	
	return;
}
Пример #5
0
void faup_snapshot_item_free(faup_snapshot_item_t *item)
{
  struct htable_iter iter;
  faup_snapshot_value_count_t *vc;
  
  vc = htable_first(&item->values, &iter);
  while (vc) {
    htable_del(&item->values, hash_string(vc->value), vc);
    faup_snapshot_value_count_free(vc);

    vc = htable_next(&item->values, &iter);
  }

  htable_clear(&item->values);
  
  free(item->key);
  free(item);
}
Пример #6
0
int main(int argc, char *argv[])
{
	struct htable ht;
	uint64_t val[NUM_VALS];
	unsigned int i;

	plan_tests((NUM_VALS) * 2);
	for (i = 0; i < NUM_VALS; i++)
		val[i] = i;

	htable_init(&ht, hash, NULL);
	for (i = 0; i < NUM_VALS; i++) {
		ok1(ht.max >= i);
		ok1(ht.max <= i * 2);
		htable_add(&ht, hash(&val[i], NULL), &val[i]);
	}
	htable_clear(&ht);

	return exit_status();
}
Пример #7
0
void test_htable_size() {
    htable *ht = htable_create();

    assert(0 == htable_size(ht)
        && "Count should be 0 upon creation.");

    htable_insert(ht, "one", "1st value");
    htable_insert(ht, "two", "2nd value");
    htable_insert(ht, "three", "3rd value");

    assert(3 == htable_size(ht)
        && "Count should be 3 after three insertions.");

    htable_clear(ht);

    assert(0 == htable_size(ht)
        && "Count should be 0 after clear.");

    htable_destroy(ht);
}
static void check_addr(void *ip, void *addr)
{
	if (!inst_enable)
		return;

	address *new_addr = (address*)malloc(sizeof(*new_addr));
	*new_addr = (address)addr;

	size_t new_addr_hash = addr_hash(new_addr, NULL);

	if (htable_get(&addresses, new_addr_hash, cmp, new_addr)) {
		if (instr_count > max_instr_count) {
			max_instr_count = instr_count;
			instr_count = 0;
		}

		htable_clear(&addresses);
	}

	htable_add(&addresses, new_addr_hash, new_addr);
}
Пример #9
0
void kmscon_hashtable_free(struct kmscon_hashtable *tbl)
{
	struct htable_iter i;
	struct kmscon_hashentry *entry;

	if (!tbl)
		return;

	for (entry = htable_first(&tbl->tbl, &i);
	     entry;
	     entry = htable_next(&tbl->tbl, &i)) {
		htable_delval(&tbl->tbl, &i);
		if (tbl->free_key)
			tbl->free_key(entry->key);
		if (tbl->free_value)
			tbl->free_value(entry->value);
		free(entry);
	}

	htable_clear(&tbl->tbl);
	free(tbl);
}
Пример #10
0
static void plain_group_list(void *pool, void *additional, char ***groupname, unsigned *groupname_size)
{
    FILE *fp;
    char line[512];
    ssize_t ll;
    char *p, *sp;
    unsigned i;
    size_t hval;
    struct htable_iter iter;
    char *tgroup[MAX_GROUPS];
    unsigned tgroup_size;
    struct htable hash;
    struct plain_cfg_st *config = additional;

    htable_init(&hash, rehash, NULL);

    pool = talloc_init("plain");
    fp = fopen(config->passwd, "r");
    if (fp == NULL) {
        syslog(LOG_AUTH,
               "error in plain authentication; cannot open: %s",
               (char*)config->passwd);
        return;
    }

    line[sizeof(line)-1] = 0;
    while ((p=fgets(line, sizeof(line)-1, fp)) != NULL) {
        ll = strlen(p);

        if (ll <= 4)
            continue;

        if (line[ll - 1] == '\n') {
            ll--;
            line[ll] = 0;
        }
        if (line[ll - 1] == '\r') {
            ll--;
            line[ll] = 0;
        }

#ifdef HAVE_STRSEP
        sp = line;
        p = strsep(&sp, ":");

        if (p != NULL) {
            p = strsep(&sp, ":");
#else
        p = strtok_r(line, ":", &sp);

        if (p != NULL) {
            p = strtok_r(NULL, ":", &sp);
#endif
            if (p != NULL) {
                break_group_list(pool, p, tgroup, &tgroup_size);

                for (i=0; i<tgroup_size; i++) {
                    hval = rehash(tgroup[i], NULL);

                    if (htable_get(&hash, hval, str_cmp, tgroup[i]) == NULL) {
                        if (strlen(tgroup[i]) > 1)
                            htable_add(&hash, hval, tgroup[i]);
                    }
                }
            }
        }
    }

    *groupname_size = 0;
    *groupname = talloc_size(pool, sizeof(char*)*MAX_GROUPS);
    if (*groupname == NULL) {
        goto exit;
    }

    p = htable_first(&hash, &iter);
    while (p != NULL && (*groupname_size) < MAX_GROUPS) {
        (*groupname)[(*groupname_size)] = talloc_strdup(*groupname, p);
        p = htable_next(&hash, &iter);
        (*groupname_size)++;
    }

    /* always succeed */
exit:
    htable_clear(&hash);
    safe_memset(line, 0, sizeof(line));
    fclose(fp);
    return;
}

const struct auth_mod_st plain_auth_funcs = {
    .type = AUTH_TYPE_PLAIN | AUTH_TYPE_USERNAME_PASS,
    .allows_retries = 1,
    .global_init = plain_global_init,
    .auth_init = plain_auth_init,
    .auth_deinit = plain_auth_deinit,
    .auth_msg = plain_auth_msg,
    .auth_pass = plain_auth_pass,
    .auth_user = plain_auth_user,
    .auth_group = plain_auth_group,
    .group_list = plain_group_list
};
Пример #11
0
int main(int argc, char *argv[])
{
	unsigned int i;
	uintptr_t perfect_bit;
	struct htable ht;
	uint64_t val[NUM_VALS];
	uint64_t dne;
	void *p;
	struct htable_iter iter;

	plan_tests(29);
	for (i = 0; i < NUM_VALS; i++)
		val[i] = i;
	dne = i;

	htable_init(&ht, hash, NULL);
	ok1(ht.max == 0);
	ok1(ht.bits == 0);

	/* We cannot find an entry which doesn't exist. */
	ok1(!htable_get(&ht, hash(&dne, NULL), objcmp, &dne));

	/* This should increase it once. */
	add_vals(&ht, val, 0, 1);
	ok1(ht.bits == 1);
	ok1(ht.max == 1);
	ok1(ht.common_mask == -1);

	/* Mask should be set. */
	ok1(check_mask(&ht, val, 1));

	/* This should increase it again. */
	add_vals(&ht, val, 1, 1);
	ok1(ht.bits == 2);
	ok1(ht.max == 3);

	/* Mask should be set. */
	ok1(ht.common_mask != 0);
	ok1(ht.common_mask != -1);
	ok1(check_mask(&ht, val, 2));

	/* Now do the rest. */
	add_vals(&ht, val, 2, NUM_VALS - 2);

	/* Find all. */
	find_vals(&ht, val, NUM_VALS);
	ok1(!htable_get(&ht, hash(&dne, NULL), objcmp, &dne));

	/* Walk once, should get them all. */
	i = 0;
	for (p = htable_first(&ht,&iter); p; p = htable_next(&ht, &iter))
		i++;
	ok1(i == NUM_VALS);

	/* Delete all. */
	del_vals(&ht, val, NUM_VALS);
	ok1(!htable_get(&ht, hash(&val[0], NULL), objcmp, &val[0]));

	/* Worst case, a "pointer" which doesn't have any matching bits. */
	htable_add(&ht, 0, (void *)~(uintptr_t)&val[NUM_VALS-1]);
	htable_add(&ht, hash(&val[NUM_VALS-1], NULL), &val[NUM_VALS-1]);
	ok1(ht.common_mask == 0);
	ok1(ht.common_bits == 0);
	/* Get rid of bogus pointer before we trip over it! */
	htable_del(&ht, 0, (void *)~(uintptr_t)&val[NUM_VALS-1]);

	/* Add the rest. */
	add_vals(&ht, val, 0, NUM_VALS-1);

	/* Check we can find them all. */
	find_vals(&ht, val, NUM_VALS);
	ok1(!htable_get(&ht, hash(&dne, NULL), objcmp, &dne));

	/* Corner cases: wipe out the perfect bit using bogus pointer. */
	htable_clear(&ht);
	htable_add(&ht, 0, (void *)((uintptr_t)&val[NUM_VALS-1]));
	ok1(ht.perfect_bit);
	perfect_bit = ht.perfect_bit;
	htable_add(&ht, 0, (void *)((uintptr_t)&val[NUM_VALS-1]
				   | perfect_bit));
	ok1(ht.perfect_bit == 0);
	htable_del(&ht, 0, (void *)((uintptr_t)&val[NUM_VALS-1] | perfect_bit));

	/* Enlarging should restore it... */
	add_vals(&ht, val, 0, NUM_VALS-1);

	ok1(ht.perfect_bit != 0);
	htable_clear(&ht);

	return exit_status();
}
Пример #12
0
/**
 * Reset limits.
 */
static void
ctl_reset(void)
{
	htable_clear(ctl_by_country);
	ctl_all_flags = 0;
}
Пример #13
0
void		htable_clear_destroy(t_htable *htable)
{
	htable_clear(htable);
	htable_destroy(htable);
}
Пример #14
0
void htable_free(htable* t)
{
	htable_clear(t);
	free(t);
}