Beispiel #1
0
switch_status_t do_config() 
{
	char *conf = "xml_radius.conf";
	switch_xml_t xml, cfg, tmp, server, param;
	int serv, timeout, deadtime, retries, dict, seq;

	/* TODO:
	   1. Fix read/write lock on configs
	      a. read new configs
	      b. Create replacement xml and vas objects
		  c. Get the write lock.
		  d. Replace xml and vas objects
		  e. unlock and return.
	   2. Don't manually check for proper configs. Use the function in the client library
	   3. Add api that would reload configs
	 */

	if (!(xml = switch_xml_open_cfg(conf, &cfg, NULL))) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", conf);
		goto err;
	}

	serv = timeout = deadtime = retries = dict = seq = 0;
	if ((tmp = switch_xml_dup(switch_xml_child(cfg, "auth_invite"))) != NULL ) {
		if ( (server = switch_xml_child(tmp, "connection")) != NULL) {
				for (param = switch_xml_child(server, "param"); param; param = param->next) {
					char *var = (char *) switch_xml_attr_soft(param, "name");
					if ( strncmp(var, "authserver", 10) == 0 ) {
						serv = 1;
					} else if ( strncmp(var, "radius_timeout", 14) == 0 ) {
						timeout = 1;
					} else if ( strncmp(var, "radius_deadtime", 15) == 0 ) {
						deadtime = 1;
					} else if ( strncmp(var, "radius_retries", 14) == 0 ) {
						retries = 1;
					} else if ( strncmp(var, "dictionary", 10) == 0 ) {
						dict = 1;
					} else if ( strncmp(var, "seqfile", 7) == 0 ) {
						seq = 1;
					}
				}
				
				if ( serv && timeout && deadtime && retries && dict && seq ) {
					globals.auth_invite_configs = tmp;
				} else {
					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing a require section for radius connections\n");
					goto err;
				}
		} else {
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find 'connection' section for auth_invite\n");
			goto err;
		}		
	} else {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Could not find 'auth_invite' section in config file.\n");		
	}
	
	serv = timeout = deadtime = retries = dict = seq = 0;
	if ((tmp = switch_xml_dup(switch_xml_child(cfg, "auth_reg"))) != NULL ) {
		if ( (server = switch_xml_child(tmp, "connection")) != NULL) {
				for (param = switch_xml_child(server, "param"); param; param = param->next) {
					char *var = (char *) switch_xml_attr_soft(param, "name");
					if ( strncmp(var, "authserver", 10) == 0 ) {
						serv = 1;
					} else if ( strncmp(var, "radius_timeout", 14) == 0 ) {
						timeout = 1;
					} else if ( strncmp(var, "radius_deadtime", 15) == 0 ) {
						deadtime = 1;
					} else if ( strncmp(var, "radius_retries", 14) == 0 ) {
						retries = 1;
					} else if ( strncmp(var, "dictionary", 10) == 0 ) {
						dict = 1;
					} else if ( strncmp(var, "seqfile", 7) == 0 ) {
						seq = 1;
					}
				}
				
				if ( serv && timeout && deadtime && retries && dict && seq ) {
					globals.auth_reg_configs = tmp;
				} else {
					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing a require section for radius connections\n");
					goto err;
				}
		} else {
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find 'connection' section for auth_invite\n");
			goto err;
		}		
	} else {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Could not find 'auth_invite' section in config file.\n");		
	}

	if ((tmp = switch_xml_child(cfg, "global")) != NULL ) {
		for (param = switch_xml_child(tmp, "param"); param; param = param->next) {
			char *name = (char *) switch_xml_attr_soft(param, "name");
			char *value = (char *) switch_xml_attr_soft(param, "value");
			if ( strncmp(name, "time_format", 11) == 0 && value != NULL ) {
				GLOBAL_TIME_FORMAT = atoi(value);
				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Time format changed to %d\n", GLOBAL_TIME_FORMAT);
			}
			if ( strncmp(name, "time_zone", 9) == 0 && value != NULL ) {
				GLOBAL_TIME_ZONE = value;
				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Time zone changed to %s\n", GLOBAL_TIME_ZONE);
			}
			if ( strncmp(name, "debug", 5) == 0 && value != NULL ) {
				GLOBAL_DEBUG = atoi(value);
				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Debug changed to %d\n", GLOBAL_DEBUG);
			}
		}
	}

	serv = timeout = deadtime = retries = dict = seq = 0;
	if ((tmp = switch_xml_dup(switch_xml_child(cfg, "auth_app"))) != NULL ) {
		if ( (server = switch_xml_child(tmp, "connection")) != NULL) {
				for (param = switch_xml_child(server, "param"); param; param = param->next) {
					char *var = (char *) switch_xml_attr_soft(param, "name");
					if ( strncmp(var, "authserver", 10) == 0 ) {
						serv = 1;
					} else if ( strncmp(var, "radius_timeout", 14) == 0 ) {
						timeout = 1;
					} else if ( strncmp(var, "radius_deadtime", 15) == 0 ) {
						deadtime = 1;
					} else if ( strncmp(var, "radius_retries", 14) == 0 ) {
						retries = 1;
					} else if ( strncmp(var, "dictionary", 10) == 0 ) {
						dict = 1;
					} else if ( strncmp(var, "seqfile", 7) == 0 ) {
						seq = 1;
					}
				}
				
				if ( serv && timeout && deadtime && retries && dict && seq ) {
					globals.auth_app_configs = tmp;
				} else {
					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing a require section for radius connections\n");
					goto err;
				}
		} else {
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find 'connection' section for auth_app\n");
			goto err;
		}		
	} else {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Could not find 'auth_app' section in config file.\n");		
	}
	
	serv = timeout = deadtime = retries = dict = seq = 0;
	if (( tmp = switch_xml_dup(switch_xml_child(cfg, "acct_start"))) != NULL ) {
		if ( (server = switch_xml_child(tmp, "connection")) != NULL) {
				for (param = switch_xml_child(server, "param"); param; param = param->next) {
					char *var = (char *) switch_xml_attr_soft(param, "name");
					if ( strncmp(var, "acctserver", 10) == 0 ) {
						serv = 1;
					} else if ( strncmp(var, "radius_timeout", 14) == 0 ) {
						timeout = 1;
					} else if ( strncmp(var, "radius_deadtime", 15) == 0 ) {
						deadtime = 1;
					} else if ( strncmp(var, "radius_retries", 14) == 0 ) {
						retries = 1;
					} else if ( strncmp(var, "dictionary", 10) == 0 ) {
						dict = 1;
					} else if ( strncmp(var, "seqfile", 7) == 0 ) {
						seq = 1;
					}
				}
				
				if ( serv && timeout && deadtime && retries && dict && seq ) {
					globals.acct_start_configs = tmp;
				} else {
					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing a require section for radius connections\n");
					goto err;
				}
		} else {
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find 'connection' section for acct_start\n");
			goto err;
		}		
	} else {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Could not find 'acct_start' section in config file.\n");		
	}
	
	serv = timeout = deadtime = retries = dict = seq = 0;
	if (( tmp = switch_xml_dup(switch_xml_child(cfg, "acct_end"))) != NULL ) {
		if ( (server = switch_xml_child(tmp, "connection")) != NULL) {
				for (param = switch_xml_child(server, "param"); param; param = param->next) {
					char *var = (char *) switch_xml_attr_soft(param, "name");
					if ( strncmp(var, "acctserver", 10) == 0 ) {
						serv = 1;
					} else if ( strncmp(var, "radius_timeout", 14) == 0 ) {
						timeout = 1;
					} else if ( strncmp(var, "radius_deadtime", 15) == 0 ) {
						deadtime = 1;
					} else if ( strncmp(var, "radius_retries", 14) == 0 ) {
						retries = 1;
					} else if ( strncmp(var, "dictionary", 10) == 0 ) {
						dict = 1;
					} else if ( strncmp(var, "seqfile", 7) == 0 ) {
						seq = 1;
					}
				}
				
				if ( serv && timeout && deadtime && retries && dict && seq ) {
					globals.acct_end_configs = tmp;
				} else {
					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing a require section for radius connections\n");
					goto err;
				}
		} else {
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find 'connection' section for acct_end\n");
			goto err;
		}		
	} else {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Could not find 'acct_end' section in config file.\n");		
	}
	
	if ( xml ) {
		switch_xml_free(xml);
		xml = NULL;
	}

	return SWITCH_STATUS_SUCCESS;
	
 err:
	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mod_xml_radius: Configuration error\n");
	if ( xml ) {
		switch_xml_free(xml);
		xml = NULL;
	}
	
	return SWITCH_STATUS_GENERR;
}
Beispiel #2
0
switch_status_t do_config() 
{
	char *conf = "xml_radius.conf";
	switch_xml_t xml, cfg, tmp, server, param;
	int serv, timeout, deadtime, retries, dict, seq;
	/* TODO:
	   1. read new auth_invite_configs
	   2. Create replacement xml and vas objects
	   3. Get the write lock. 
	   4. Replace xml and vas objects
	   5. unlock and return.
	 */

	if (!(xml = switch_xml_open_cfg(conf, &cfg, NULL))) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", conf);
		goto err;
	}

	serv = timeout = deadtime = retries = dict = seq = 0;
	if ((tmp = switch_xml_dup(switch_xml_child(cfg, "auth_invite"))) != NULL ) {
		if ( (server = switch_xml_child(xml, "connection")) != NULL) {
				for (param = switch_xml_child(server, "param"); param; param = param->next) {
					char *var = (char *) switch_xml_attr_soft(param, "name");
					if ( strncmp(var, "authserver", 10) == 0 ) {
						serv = 1;
					} else if ( strncmp(var, "radius_timeout", 14) == 0 ) {
						timeout = 1;
					} else if ( strncmp(var, "radius_deadtime", 15) == 0 ) {
						deadtime = 1;
					} else if ( strncmp(var, "radius_retries", 14) == 0 ) {
						retries = 1;
					} else if ( strncmp(var, "dictionary", 10) == 0 ) {
						dict = 1;
					} else if ( strncmp(var, "seqfile", 7) == 0 ) {
						seq = 1;
					}
				}
				
				if ( serv && timeout && deadtime && retries && dict && seq ) {
					globals.auth_invite_configs = tmp;
				} else {
					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing a require section for radius connections\n");
					goto err;
				}
		} else {
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find 'connection' section for auth_invite\n");
			goto err;
		}		
	} else {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Could not find 'auth_invite' section in config file.\n");		
	}
	
	if ((globals.auth_app_configs = switch_xml_dup(switch_xml_child(cfg, "auth_app"))) == NULL ) {
		if ( (server = switch_xml_child(xml, "connection")) != NULL) {
				for (param = switch_xml_child(server, "param"); param; param = param->next) {
					char *var = (char *) switch_xml_attr_soft(param, "name");
					if ( strncmp(var, "authserver", 10) == 0 ) {
						serv = 1;
					} else if ( strncmp(var, "radius_timeout", 14) == 0 ) {
						timeout = 1;
					} else if ( strncmp(var, "radius_deadtime", 15) == 0 ) {
						deadtime = 1;
					} else if ( strncmp(var, "radius_retries", 14) == 0 ) {
						retries = 1;
					} else if ( strncmp(var, "dictionary", 10) == 0 ) {
						dict = 1;
					} else if ( strncmp(var, "seqfile", 7) == 0 ) {
						seq = 1;
					}
				}
				
				if ( serv && timeout && deadtime && retries && dict && seq ) {
					globals.auth_invite_configs = tmp;
				} else {
					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing a require section for radius connections\n");
					goto err;
				}
		} else {
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find 'connection' section for auth_app\n");
			goto err;
		}		
	} else {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Could not find 'auth_app' section in config file.\n");		
	}
	
	if ((globals.acct_start_configs = switch_xml_dup(switch_xml_child(cfg, "acct_start"))) == NULL ) {
		if ( (server = switch_xml_child(xml, "connection")) != NULL) {
				for (param = switch_xml_child(server, "param"); param; param = param->next) {
					char *var = (char *) switch_xml_attr_soft(param, "name");
					if ( strncmp(var, "acctserver", 10) == 0 ) {
						serv = 1;
					} else if ( strncmp(var, "radius_timeout", 14) == 0 ) {
						timeout = 1;
					} else if ( strncmp(var, "radius_deadtime", 15) == 0 ) {
						deadtime = 1;
					} else if ( strncmp(var, "radius_retries", 14) == 0 ) {
						retries = 1;
					} else if ( strncmp(var, "dictionary", 10) == 0 ) {
						dict = 1;
					} else if ( strncmp(var, "seqfile", 7) == 0 ) {
						seq = 1;
					}
				}
				
				if ( serv && timeout && deadtime && retries && dict && seq ) {
					globals.auth_invite_configs = tmp;
				} else {
					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing a require section for radius connections\n");
					goto err;
				}
		} else {
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find 'connection' section for acct_start\n");
			goto err;
		}		
	} else {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Could not find 'acct_start' section in config file.\n");		
	}
	
	if ((globals.acct_end_configs = switch_xml_dup(switch_xml_child(cfg, "acct_end"))) == NULL ) {
		if ( (server = switch_xml_child(xml, "connection")) != NULL) {
				for (param = switch_xml_child(server, "param"); param; param = param->next) {
					char *var = (char *) switch_xml_attr_soft(param, "name");
					if ( strncmp(var, "acctserver", 10) == 0 ) {
						serv = 1;
					} else if ( strncmp(var, "radius_timeout", 14) == 0 ) {
						timeout = 1;
					} else if ( strncmp(var, "radius_deadtime", 15) == 0 ) {
						deadtime = 1;
					} else if ( strncmp(var, "radius_retries", 14) == 0 ) {
						retries = 1;
					} else if ( strncmp(var, "dictionary", 10) == 0 ) {
						dict = 1;
					} else if ( strncmp(var, "seqfile", 7) == 0 ) {
						seq = 1;
					}
				}
				
				if ( serv && timeout && deadtime && retries && dict && seq ) {
					globals.auth_invite_configs = tmp;
				} else {
					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing a require section for radius connections\n");
					goto err;
				}
		} else {
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find 'connection' section for acct_end\n");
			goto err;
		}		
	} else {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Could not find 'acct_end' section in config file.\n");		
	}
	
	if ( xml ) {
		switch_xml_free(xml);
	}

	return SWITCH_STATUS_SUCCESS;
	
 err:
	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mod_xml_radius: Configuration error\n");
	if ( xml ) {
		switch_xml_free(xml);
	}
	
	return SWITCH_STATUS_GENERR;
}