Exemple #1
0
static int mod_init(void)
{
	int ld_count = 0, i = 0;
	char* section_name;
	char* ldap_version;

	LM_INFO("LDAP_H350 module - initializing\n");

	/*
	* read config file
	*/
	if (strlen(ldap_config.s) == 0)
	{
		LM_ERR("config_file is empty - this module param is mandatory\n");
		return -2;
	}
	if ((config_vals = iniparser_new(ldap_config.s)) == NULL)
	{
		LM_ERR("failed to read config_file [%s]\n", ldap_config.s);
		return -2;
	}
	if ((ld_count = iniparser_getnsec(config_vals)) < 1)
	{
		LM_ERR("no section found in config_file [%s]\n", ldap_config.s);
		return -2;
	}
	/* check if mandatory settings are present */
	for (i = 0; i < ld_count; i++)
	{
		section_name = iniparser_getsecname(config_vals, i);
		if (strlen(section_name) > 255)
		{
			LM_ERR(	"config_file section name [%s]"
				" longer than allowed 255 characters",
				section_name);
			return -2;
		}
		if (!iniparser_find_entry(config_vals,
					get_ini_key_name(section_name, CFG_N_LDAP_HOST)))
		{
			LM_ERR(	"mandatory %s not defined in [%s]\n",
				CFG_N_LDAP_HOST,
				section_name);
			return -2;
		}
	}

	/*
	* print ldap version string
	*/
	if (ldap_get_vendor_version(&ldap_version) != 0)
	{
		LM_ERR("ldap_get_vendor_version failed\n");
		return -2;
	}
	LM_INFO("%s\n", ldap_version);

	return 0;
}
Exemple #2
0
int add_ld_session(char* _name, LDAP* _ldh, dictionary* _d)
{
	struct ld_session* current = ld_sessions;
	struct ld_session* new_lds = NULL;
	char *host_name, *bind_dn, *bind_pwd;
	int client_search_timeout_ms, client_bind_timeout_ms, network_timeout_ms;
	
	new_lds = (struct ld_session*)pkg_malloc(sizeof(struct ld_session));
	if (new_lds == NULL)
	{
		LM_ERR("no memory\n");
		return -1;
	}
	memset( new_lds, 0, sizeof(struct ld_session));

	/* name */
	strncpy(new_lds->name, _name, 255);
	/* handle */
	new_lds->handle = _ldh;
	
	/* host_name */
	host_name = iniparser_getstring(
		_d,
		get_ini_key_name(_name, CFG_N_LDAP_HOST),
		CFG_DEF_HOST_NAME);
	new_lds->host_name = (char*)pkg_malloc(strlen(host_name)+1);
	if (new_lds->host_name == NULL) {
		LM_ERR("no memory\n");
		return -1;
	}
	strcpy(new_lds->host_name, host_name);

	/* version */
	new_lds->version = iniparser_getint(
		_d,
		get_ini_key_name(_name, CFG_N_LDAP_VERSION),
		CFG_DEF_LDAP_VERSION);
	
	/* client_search_timeout */
	client_search_timeout_ms = iniparser_getint(
		_d,
		get_ini_key_name(_name, CFG_N_LDAP_CLIENT_SEARCH_TIMEOUT),
		CFG_DEF_LDAP_CLIENT_SEARCH_TIMEOUT);
	if (client_search_timeout_ms < CFG_LDAP_CLIENT_SEARCH_TIMEOUT_MIN)
	{
		LM_INFO("[%s = %d ms] is below allowed min"
			" [%d ms] - [%s] set to [%d ms]\n",
			CFG_N_LDAP_CLIENT_SEARCH_TIMEOUT,
			client_search_timeout_ms,
			CFG_LDAP_CLIENT_SEARCH_TIMEOUT_MIN,
			CFG_N_LDAP_CLIENT_SEARCH_TIMEOUT,
			CFG_LDAP_CLIENT_SEARCH_TIMEOUT_MIN);
		client_search_timeout_ms = CFG_LDAP_CLIENT_SEARCH_TIMEOUT_MIN;
	}
	new_lds->client_search_timeout.tv_sec = client_search_timeout_ms / 1000;
	new_lds->client_search_timeout.tv_usec =
									(client_search_timeout_ms % 1000) * 1000;

	/* client_bind_timeout */
	client_bind_timeout_ms = iniparser_getint(
		_d,
		get_ini_key_name(_name, CFG_N_LDAP_CLIENT_BIND_TIMEOUT),
		CFG_DEF_LDAP_CLIENT_BIND_TIMEOUT);
	new_lds->client_bind_timeout.tv_sec = client_bind_timeout_ms / 1000;
	new_lds->client_bind_timeout.tv_usec = 
									(client_bind_timeout_ms % 1000) * 1000;
	
	/* network_timeout */
	network_timeout_ms = iniparser_getint(
		_d,
		get_ini_key_name(_name, CFG_N_LDAP_NETWORK_TIMEOUT),
		LDAP_NO_LIMIT);
	new_lds->network_timeout.tv_sec = network_timeout_ms / 1000;
	new_lds->network_timeout.tv_usec = (network_timeout_ms % 1000) * 1000;

	/* bind_dn */
	bind_dn = iniparser_getstring(
		_d,
		get_ini_key_name(_name, CFG_N_LDAP_BIND_DN),
		CFG_DEF_LDAP_BIND_DN);
	new_lds->bind_dn = (char*)pkg_malloc(strlen(bind_dn)+1);
	if (new_lds->bind_dn == NULL) {
		LM_ERR("no memory\n");
		return -1;
	}
	strcpy(new_lds->bind_dn, bind_dn);

	/* bind_pwd */
	bind_pwd = iniparser_getstring(
		_d,
		get_ini_key_name(_name, CFG_N_LDAP_BIND_PWD),
		CFG_DEF_LDAP_BIND_PWD);
	new_lds->bind_pwd = (char*)pkg_malloc(strlen(bind_pwd)+1);
	if (new_lds->bind_pwd == NULL) {
		LM_ERR("no memory\n");
		return -1;
	}
	memset(new_lds->bind_pwd, 0, strlen(bind_pwd)+1);
	strcpy(new_lds->bind_pwd, bind_pwd);

	/* calculate_ha1 */
	new_lds->calculate_ha1 = iniparser_getboolean(
		_d, 
		get_ini_key_name(_name, CFG_N_CALCULATE_HA1), 
		CFG_DEF_CALCULATE_HA1);
	
	
	if (current == NULL)
	{
		ld_sessions = new_lds;
	} else
	{
		while (current->next != NULL) { current = current->next; };
		current->next = new_lds;
	}

	return 0;
}