Ejemplo n.º 1
0
/*
 * Initialize data structures
 */
int init_trusted(void)
{
	if (db_mode == ENABLE_CACHE) {

		hash_table_1 = new_hash_table();
		if (!hash_table_1) return -1;

		hash_table_2  = new_hash_table();
		if (!hash_table_2) goto error;

		hash_table = (struct trusted_list ***)shm_malloc(sizeof(struct trusted_list **));
		if (!hash_table) goto error;

		*hash_table = hash_table_1;

		if (reload_trusted_table() == -1) {
			LOG(L_CRIT, "init_trusted(): Reload of trusted table failed\n");
			goto error;
		}
	}
	return 0;

 error:
	clean_trusted();
	return -1;
}
Ejemplo n.º 2
0
Archivo: mi.c Proyecto: gbour/kamailio
/*
 * MI function to reload trusted table
 */
struct mi_root* mi_trusted_reload(struct mi_root *cmd_tree, void *param)
{
	if (hash_table==NULL) {
		return init_mi_tree( 200, MI_SSTR(MI_OK));
	}

	if (reload_trusted_table () == 1) {
		return init_mi_tree( 200, MI_SSTR(MI_OK));
	} else {
		return init_mi_tree( 400, MI_SSTR("Trusted table reload failed"));
	}
}
Ejemplo n.º 3
0
/*
 * Fifo function to reload trusted table
 */
static int trusted_reload(str* msg)
{
	if (reload_trusted_table () == 1) {
		unixsock_reply_asciiz("200 OK\n");
		unixsock_reply_send();
		return 0;
	} else {
		unixsock_reply_asciiz("400 Trusted table reload failed\n");
		unixsock_reply_send();
		return -1;
	}
}
Ejemplo n.º 4
0
Archivo: mi.c Proyecto: gbour/kamailio
/*! \brief
 * RPC function to reload trusted table
 */
void rpc_trusted_reload(rpc_t* rpc, void* c) {
	if (hash_table==NULL) {
		rpc->fault(c, 500, "Reload failed. No hash table");
		return;
	}
	if (reload_trusted_table () != 1) {
		rpc->fault(c, 500, "Reload failed.");
		return;
	}

	rpc->printf(c, "Reload OK");
	return;
}
Ejemplo n.º 5
0
int reload_trusted_table_cmd(void)
{
	if (!db_handle) {
		db_handle = perm_dbf.init(&db_url);
		if (!db_handle) {
			LM_ERR("unable to connect database\n");
			return -1;
		}
	}
	if (reload_trusted_table () != 1) {
		perm_dbf.close(db_handle);
		db_handle = 0;
		return -1;
	}

	perm_dbf.close(db_handle);
	db_handle = 0;

	return 1;
}
Ejemplo n.º 6
0
/*
 * Fifo function to reload trusted table
 */
void trusted_reload(rpc_t* rpc, void* ctx)
{
	if (db_mode != ENABLE_CACHE) {
		rpc->fault(ctx, 400, "Database cache is not enabled");
		return;
	}

	/* connect to the DB */
	db_handle = perm_dbf.init(db_url);
	if (!db_handle) {
		LOG(L_ERR, "ERROR: Unable to connect to database\n");
		rpc->fault(ctx, 400, "Trusted Table Reload Failed");
		return;
	}

	/* reload cache */
	if (reload_trusted_table() < 0) {
		rpc->fault(ctx, 400, "Trusted Table Reload Failed");
	}

	/* close DB connection */
	perm_dbf.close(db_handle);
	db_handle = 0;
}
Ejemplo n.º 7
0
/*
 * Initialize data structures
 */
int init_trusted(void)
{
	/* Check if hash table needs to be loaded from trusted table */
	if (!db_url.s) {
		LM_INFO("db_url parameter of permissions module not set, "
			"disabling allow_trusted\n");
		return 0;
	} else {
		if (db_bind_mod(&db_url, &perm_dbf) < 0) {
			LM_ERR("load a database support module\n");
			return -1;
		}

		if (!DB_CAPABILITY(perm_dbf, DB_CAP_QUERY)) {
			LM_ERR("database module does not implement 'query' function\n");
			return -1;
		}
	}

	hash_table_1 = hash_table_2 = 0;
	hash_table = 0;

	if (db_mode == ENABLE_CACHE) {
		db_handle = perm_dbf.init(&db_url);
		if (!db_handle) {
			LM_ERR("unable to connect database\n");
			return -1;
		}

		if(db_check_table_version(&perm_dbf, db_handle, &trusted_table, TABLE_VERSION) < 0) {
			LM_ERR("error during table version check.\n");
			perm_dbf.close(db_handle);
			return -1;
		}

		hash_table_1 = new_hash_table();
		if (!hash_table_1) return -1;
		
		hash_table_2  = new_hash_table();
		if (!hash_table_2) goto error;
		
		hash_table = (struct trusted_list ***)shm_malloc
			(sizeof(struct trusted_list **));
		if (!hash_table) goto error;

		*hash_table = hash_table_1;

		if (reload_trusted_table() == -1) {
			LM_CRIT("reload of trusted table failed\n");
			goto error;
		}

		perm_dbf.close(db_handle);
		db_handle = 0;
	}
	return 0;

error:
	if (hash_table_1) {
		free_hash_table(hash_table_1);
		hash_table_1 = 0;
	}
	if (hash_table_2) {
		free_hash_table(hash_table_2);
		hash_table_2 = 0;
	}
	if (hash_table) {
		shm_free(hash_table);
		hash_table = 0;
	}
	perm_dbf.close(db_handle);
	db_handle = 0;
	return -1;
}