Exemplo n.º 1
0
/*
 * Module initialization function
 */
static int mod_init(void)
{
	str prot_url;

	LM_DBG("initializing\n");

    memset(attrs, 0, sizeof(attrs));
    memset(vals, 0, sizeof(vals));
    attrs[A_USER_NAME].name 			= "User-Name";
    attrs[A_SIP_URI_USER].name 			= "SIP-URI-User";
    attrs[A_SIP_FROM_TAG].name 			= "SIP-From-Tag";
    attrs[A_SIP_CALL_ID].name 			= "SIP-Call-Id";
    attrs[A_SIP_REQUEST_HASH].name		= "SIP-Request-Hash";
    attrs[A_SIP_AVP].name	 			= "SIP-AVP";
    attrs[A_SERVICE_TYPE].name 			= "Service-Type";
    vals[V_SIP_VERIFY_DESTINATION].name = "Sip-Verify-Destination";
    vals[V_SIP_VERIFY_SOURCE].name		= "Sip-Verify-Source";

	prot_url.s = aaa_proto_url;
	prot_url.len = strlen(aaa_proto_url);

	if(aaa_prot_bind(&prot_url, &proto)) {
		LM_ERR("aaa protocol bind failure\n");
		return -1;
	}

	if (!(conn = proto.init_prot(&prot_url))) {
		LM_ERR("aaa protocol initialization failure\n");
		return -2;
	}

    INIT_AV(proto, conn, attrs, A_MAX, vals, V_MAX, "peering", -3, -4);

    if (verify_destination_service_type != -1)
		vals[V_SIP_VERIFY_DESTINATION].value = verify_destination_service_type;

    if (verify_source_service_type != -1)
		vals[V_SIP_VERIFY_SOURCE].value = verify_source_service_type;

    return 0;
}
Exemplo n.º 2
0
static int mod_init(void)
{
	LM_DBG("group module - initializing\n");

	/* check for a database module */
	if (db_url.s) {

		db_url.len = strlen(db_url.s);
		table.len = strlen(table.s);
		user_column.len = strlen(user_column.s);
		domain_column.len = strlen(domain_column.s);
		group_column.len = strlen(group_column.s);

		re_table.len = (re_table.s && re_table.s[0])?strlen(re_table.s):0;
		re_exp_column.len = strlen(re_exp_column.s);
		re_gid_column.len = strlen(re_gid_column.s);

		if (group_db_bind(&db_url)) {
			LM_ERR("unable to bind database module\n");
			return -1;
		}

		if (group_db_init(&db_url) < 0 ){
			LM_ERR("unable to open database connection\n");
			return -1;
		}

		/* check version for group table */
		if (db_check_table_version(&group_dbf, group_dbh, &table, TABLE_VERSION) < 0) {
			LM_ERR("error during group table version check.\n");
			return -1;
		}

		if (re_table.len) {
			/* check version for group re_group table */
			if (db_check_table_version(&group_dbf, group_dbh, &re_table, RE_TABLE_VERSION) < 0) {
				LM_ERR("error during re_group table version check.\n");
				return -1;
			}
			if (load_re( &re_table )!=0 ) {
				LM_ERR("failed to load <%s> table\n", re_table.s);
				return -1;
			}
		}

		group_db_close();

		LM_DBG("group database loaded\n");
	}

	/* check for an aaa module */
	if (aaa_proto_url.s) {

		aaa_proto_url.len = strlen(aaa_proto_url.s);

		memset(attrs, 0, sizeof(attrs));
		memset(vals, 0, sizeof(vals));
		attrs[A_SERVICE_TYPE].name		= "Service-Type";
		attrs[A_USER_NAME].name			= "User-Name";
		attrs[A_SIP_GROUP].name			= "Sip-Group";
		attrs[A_ACCT_SESSION_ID].name	= "Acct-Session-Id";
		vals[V_GROUP_CHECK].name		= "Group-Check";

		if (aaa_prot_bind(&aaa_proto_url, &proto)) {
			LM_ERR("unable to bind aaa protocol module\n");
			return -1;
		}

		if (!(conn = proto.init_prot(&aaa_proto_url))) {
			LM_ERR("unable to initialize aaa protocol module\n");
			return -1;
		}

		INIT_AV(proto, conn, attrs, A_MAX, vals, V_MAX, "group", -3, -4);

		LM_DBG("aaa protocol module loaded\n");
	}

	return 0;
}
Exemplo n.º 3
0
static int mod_init(void)
{
	str proto_url;
	int checkver=-1;
	db_func_t db_funcs;
	db_con_t *db_conn = NULL;

	LM_DBG("initializing\n");

	init_db_url( db_url , 1 /*can be null*/);
	if (db_url.s) {
		if (db_url.len == 0) {
			if (use_uri_table != 0) {
				LM_ERR("configuration error - no database URL, "
					"but use_uri_table is set!\n");
				return -1;
			}
			return 0;
		}

		if (db_table.s == NULL) {
			/* no table set -> use defaults */
			if (use_uri_table != 0){
				db_table.s = URI_TABLE;
			}
			else {
				db_table.s = SUBSCRIBER_TABLE;
			}
		}

		db_table.len = strlen(db_table.s);
		uridb_user_col.len = strlen(uridb_user_col.s);
		uridb_domain_col.len = strlen(uridb_domain_col.s);
		uridb_uriuser_col.len = strlen(uridb_uriuser_col.s);

		if ( db_bind_mod(&db_url, &db_funcs) != 0 ) {
			LM_ERR("No database module found\n");
			return -1;
		}

		db_conn = db_funcs.init(&db_url);
		if( db_conn == NULL ) {
			LM_ERR("Could not connect to database\n");
			return -1;
		}

		checkver = db_check_table_version( &db_funcs, db_conn, &db_table,
			use_uri_table?URI_TABLE_VERSION:SUBSCRIBER_TABLE_VERSION );

		/** If checkver == -1, table validation failed */
		if( checkver == -1 ) {
			LM_ERR("Invalid table version.\n");
			db_funcs.close(db_conn);
			return -1;
		}

		db_funcs.close(db_conn);

		/* done with checkings - init the working connection */
		if (uridb_db_bind(&db_url)!=0) {
			LM_ERR("Failed to bind to a DB module\n");
			return -1;
		}
	}


	if (aaa_proto_url) {
		memset(attrs, 0, sizeof(attrs));
		memset(vals, 0, sizeof(vals));
		attrs[A_SERVICE_TYPE].name		= "Service-Type";
		attrs[A_USER_NAME].name			= "User-Name";

		if (use_sip_uri_host)
			attrs[A_SIP_URI_HOST].name	= "SIP-URI-Host";

		attrs[A_SIP_AVP].name			= "SIP-AVP";
		attrs[A_ACCT_SESSION_ID].name	= "Acct-Session-Id";
		vals[V_CALL_CHECK].name			= "Call-Check";

		proto_url.s = aaa_proto_url;
		proto_url.len = strlen(aaa_proto_url);

		if(aaa_prot_bind(&proto_url, &proto)) {
			LM_ERR("aaa protocol bind failure\n");
			return -1;
		}

		conn = proto.init_prot(&proto_url);
		if (!conn) {
			LM_ERR("aaa protocol initialization failure\n");
			return -2;
		}

		INIT_AV(proto, conn, attrs, A_MAX, vals, V_MAX, "uri", -3, -4);

		if (service_type != -1)
			vals[V_CALL_CHECK].value = service_type;
	}

	return 0;
}
Exemplo n.º 4
0
/*
 * Module initialization function
 */
static int mod_init(void)
{
	bind_auth_t bind_auth;
	str proto_url;

	aaa_map map;

	LM_INFO("initializing...\n");

	memset(attrs, 0, sizeof(attrs));
	memset(vals, 0, sizeof(vals));
	attrs[A_SERVICE_TYPE].name			= "Service-Type";
	attrs[A_SIP_URI_USER].name			= "Sip-URI-User";
	attrs[A_DIGEST_RESPONSE].name		= "Digest-Response";
	attrs[A_DIGEST_ALGORITHM].name		= "Digest-Algorithm";
	attrs[A_DIGEST_BODY_DIGEST].name	= "Digest-Body-Digest";
	attrs[A_DIGEST_CNONCE].name			= "Digest-CNonce";
	attrs[A_DIGEST_NONCE_COUNT].name	= "Digest-Nonce-Count";
	attrs[A_DIGEST_QOP].name			= "Digest-QOP";
	attrs[A_DIGEST_METHOD].name			= "Digest-Method";
	attrs[A_DIGEST_URI].name			= "Digest-URI";
	attrs[A_DIGEST_NONCE].name			= "Digest-Nonce";
	attrs[A_DIGEST_REALM].name			= "Digest-Realm";
	attrs[A_DIGEST_USER_NAME].name		= "Digest-User-Name";
	attrs[A_USER_NAME].name				= "User-Name";
	attrs[A_CISCO_AVPAIR].name			= "Cisco-AVPair";
	attrs[A_SIP_AVP].name				= "SIP-AVP";
	attrs[A_ACCT_SESSION_ID].name		= "Acct-Session-Id";
	vals[V_SIP_SESSION].name			= "Sip-Session";

	fix_flag_name(&use_ruri_flag_str, use_ruri_flag);
	use_ruri_flag = get_flag_id_by_name(FLAG_TYPE_MSG, use_ruri_flag_str);

	if (!aaa_proto_url) {
		LM_ERR("aaa_url is empty\n");
		return -1;
	}

	proto_url.s = aaa_proto_url;
	proto_url.len = strlen(aaa_proto_url);

	if(aaa_prot_bind(&proto_url, &proto)) {
		LM_ERR("aaa protocol bind failure\n");
		return -1;
	}

	if (!(conn = proto.init_prot(&proto_url))) {
		LM_ERR("aaa init protocol failure\n");
		return -2;
	}

	map.name = "Cisco";
	if (proto.dictionary_find(conn, &map, AAA_DICT_FIND_VEND)) {
		LM_DBG("no `Cisco' vendor in AAA protocol dictionary\n");
		attrs[A_CISCO_AVPAIR].name = NULL;
	}

	bind_auth = (bind_auth_t)find_export("bind_auth", 0, 0);
	if (!bind_auth) {
		LM_ERR("unable to find bind_auth function. Check if you load the auth module.\n");
		return -1;
	}

	if (bind_auth(&auth_api) < 0) {
		LM_ERR("cannot bind to auth module\n");
		return -4;
	}

	INIT_AV(proto, conn, attrs, A_MAX, vals, V_MAX, "auth_aaa", -5, -6);

	if (service_type != -1) {
		vals[V_SIP_SESSION].value = service_type;
	}

	return 0;
}