Example #1
0
/*
 * module initialization function
 */
static int mod_init(void)
{
	if(register_mi_mod(exports.name, mi_cmds)!=0)
	{
		LM_ERR("failed to register MI commands\n");
		return -1;
	}

	if(permissions_init_rpc()!=0)
	{
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}

	allow[0].filename = get_pathname(default_allow_file);
	allow[0].rules = parse_config_file(allow[0].filename);
	if (allow[0].rules) {
		LM_DBG("default allow file (%s) parsed\n", allow[0].filename);
	} else {
		LM_INFO("default allow file (%s) not found => empty rule set\n",
				allow[0].filename);
	}

	deny[0].filename = get_pathname(default_deny_file);
	deny[0].rules = parse_config_file(deny[0].filename);
	if (deny[0].rules) {
		LM_DBG("default deny file (%s) parsed\n", deny[0].filename);
	} else {
		LM_INFO("default deny file (%s) not found => empty rule set\n",
				deny[0].filename);
	}

	if (init_trusted() != 0) {
		LM_ERR("failed to initialize the allow_trusted function\n");
		return -1;
	}

	if (init_tag_avp(&tag_avp_param) < 0) {
		LM_ERR("failed to process peer_tag_avp AVP param\n");
		return -1;
	}

	if (init_addresses() != 0) {
		LM_ERR("failed to initialize the allow_address function\n");
		return -1;
	}

	if ((db_mode != DISABLE_CACHE) && (db_mode != ENABLE_CACHE)) {
		LM_ERR("invalid db_mode value: %d\n", db_mode);
		return -1;
	}

	rules_num = 1;
	return 0;
}
Example #2
0
/*
 * module initialization function
 */
static int mod_init(void)
{
	LOG(L_INFO, "permissions - initializing\n");


	/* do not load the files if not necessary */
	if (strlen(default_allow_file) || strlen(default_deny_file)) {
		if (load_file(default_allow_file, &allow, &allow_rules_num, 1) != 0) goto error;
		if (load_file(default_deny_file, &deny, &deny_rules_num, 1) != 0) goto error;
	}

	if (db_url && (db_mode == ENABLE_CACHE)) {
		/* database backend is enabled, and cache is requested -- load the DB */
		if (perm_init_db()) goto error;

		/* prepare DB commands for trusted table */
		if (init_trusted_db()) {
			LOG(L_ERR, "Error while preparing DB commands for trusted table\n");
			goto error;
		}

		/* init trusted tables */
		if (init_trusted() != 0) {
			LOG(L_ERR, "Error while initializing allow_trusted function\n");
			goto error;
		}

		/* prepare DB commands for ipmatch table */
		if (init_im_db()) {
			LOG(L_ERR, "Error while preparing DB commands for ipmatch table\n");
			goto error;
		}

		/* init ipmatch table */
		if (init_ipmatch() != 0) {
			LOG(L_ERR, "Error while initializing ipmatch table\n");
			goto error;
		}
		
		/* Destory DB connection, we do not need it anymore,
		each child process will create its own connection */
		destroy_trusted_db();
		destroy_im_db();
		perm_destroy_db();
	}

	if (ip_set_list_malloc(ip_set_list_count, ip_set_list_names) < 0) goto error;
	if (ip_set_list_count > 0) {
		ip_set_list_local = pkg_malloc(ip_set_list_count*sizeof(*ip_set_list_local));
		if (!ip_set_list_local) goto error;
		memset(ip_set_list_local, 0, sizeof(*ip_set_list_local)*ip_set_list_count);
	}
	if (ip_set_list_names) 
		pkg_free(ip_set_list_names);  /* we need not longer names in pkg memory */

	return 0;

error:
	/* free file containers */
	delete_files(&allow, allow_rules_num);
	delete_files(&deny, deny_rules_num);

	/* destroy DB cmds */
	destroy_trusted_db();
	destroy_im_db();

	/* destory DB connection */
	perm_destroy_db();

	/* free the cache */
	clean_trusted();
	clean_ipmatch();

	ip_set_list_free();

	return -1;
}
Example #3
0
/*
 * module initialization function
 */
static int mod_init(void)
{
	if(_perm_load_backends==0) {
		LM_ERR("failure - no backend to be loaded\n");
		return -1;
	}

	if(permissions_init_rpc()!=0) {
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}

	if(_perm_load_backends&PERM_LOAD_ALLOWFILE) {
		allow[0].filename = get_pathname(default_allow_file);
		allow[0].rules = parse_config_file(allow[0].filename);
		if (allow[0].rules) {
			LM_DBG("default allow file (%s) parsed\n", allow[0].filename);
		} else {
			LM_INFO("default allow file (%s) not found => empty rule set\n",
					allow[0].filename);
		}
	} else {
		allow[0].filename = NULL;
		allow[0].rules = NULL;
	}

	if(_perm_load_backends&PERM_LOAD_DENYFILE) {
		deny[0].filename = get_pathname(default_deny_file);
		deny[0].rules = parse_config_file(deny[0].filename);
		if (deny[0].rules) {
			LM_DBG("default deny file (%s) parsed\n", deny[0].filename);
		} else {
			LM_INFO("default deny file (%s) not found => empty rule set\n",
					deny[0].filename);
		}
	} else {
		deny[0].filename = NULL;
		deny[0].rules = NULL;
	}

	if (init_tag_avp(&tag_avp_param) < 0) {
		LM_ERR("failed to process peer_tag_avp AVP param\n");
		return -1;
	}

	if(_perm_load_backends&PERM_LOAD_TRUSTEDDB) {
		if (init_trusted() != 0) {
			LM_ERR("failed to initialize the allow_trusted function\n");
			return -1;
		}
	}

	if(_perm_load_backends&PERM_LOAD_ADDRESSDB) {
		if (init_addresses() != 0) {
			LM_ERR("failed to initialize the allow_address function\n");
			return -1;
		}
	}

	if ((db_mode != DISABLE_CACHE) && (db_mode != ENABLE_CACHE)) {
		LM_ERR("invalid db_mode value: %d\n", db_mode);
		return -1;
	}

	rules_num = 1;
	return 0;
}