--- /dev/null
+--- ../../../../libs/freeradius-client-1.1.6/lib/config.c 2012-08-18 22:13:13.000000000 -0700
++++ ./config.c 2012-08-18 22:14:08.000000000 -0700
+@@ -301,6 +301,8 @@
+ int i;
+ SERVER *authservers;
+ SERVER *acctservers;
++ OPTION *acct;
++ OPTION *auth;
+
+ rh->config_options = malloc(sizeof(config_options_default));
+ if (rh->config_options == NULL)
+@@ -311,8 +313,8 @@
+ }
+ memcpy(rh->config_options, &config_options_default, sizeof(config_options_default));
+
+- authservers = rc_conf_srv(rh, "authserver");
+- acctservers = rc_conf_srv(rh, "acctserver");
++ acct = find_option(rh, "acctserver", OT_ANY);
++ auth = find_option(rh, "authserver", OT_ANY);
+ authservers = malloc(sizeof(SERVER));
+ acctservers = malloc(sizeof(SERVER));
+
+@@ -334,6 +336,8 @@
+ acctservers->name[i] = NULL;
+ acctservers->secret[i] = NULL;
+ }
++ acct->val = acctservers;
++ auth->val = authservers;
+ return rh;
+ }
+
+@@ -894,11 +898,15 @@
+ continue;
+ if (rh->config_options[i].type == OT_SRV) {
+ serv = (SERVER *)rh->config_options[i].val;
+- for (j = 0; j < serv->max; j++)
++ for (j = 0; j < serv->max; j++) {
+ free(serv->name[j]);
+- free(serv);
+- } else {
++ free(serv->secret[j]);
++ }
+ free(rh->config_options[i].val);
++ rh->config_options[i].val = NULL;
++
++ } else {
++ free(rh->config_options[i].val);
+ }
+ }
+ free(rh->config_options);
switch_status_t mod_xml_radius_new_handle(rc_handle **new_handle, switch_xml_t xml) {
switch_xml_t server, param;
- *new_handle = rc_new();
-
- if ( *new_handle == NULL ) {
+ if ( (*new_handle = rc_new()) == NULL ) {
goto err;
}
- *new_handle = rc_config_init(*new_handle);
-
- if ( *new_handle == NULL ) {
+ if ( rc_config_init(*new_handle) == NULL ) {
goto err;
}
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.
+ 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))) {
if ( xml ) {
switch_xml_free(xml);
+ xml = NULL;
}
return SWITCH_STATUS_SUCCESS;
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;
switch_status_t mod_xml_radius_add_params(switch_core_session_t *session, switch_event_t *params, rc_handle *handle, VALUE_PAIR **send, switch_xml_t fields)
{
switch_xml_t param;
+ void *av_value = NULL;
if ( (param = switch_xml_child(fields, "param")) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to locate a param under the fields section\n");
DICT_ATTR *attribute = NULL;
DICT_VENDOR *vendor = NULL;
int attr_num = 0, vend_num = 0;
- void *av_value = NULL;
char *var = (char *) switch_xml_attr(param, "name");
char *vend = (char *) switch_xml_attr(param, "vendor");
}
if (rc_avpair_add(handle, send, attr_num, av_value, -1, vend_num) == NULL) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mod_xml_radius: failed to add option with val '%s' to handle\n", (char *) av_value);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "mod_xml_radius: failed to add option with val '%s' to handle\n", (char *) av_value);
goto err;
}
} else if ( attribute->type == 1 ) {
int number = atoi(switch_channel_get_variable(channel, variable));
if (rc_avpair_add(handle, send, attr_num, &number, -1, vend_num) == NULL) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mod_xml_radius: failed to add option with value '%d' to handle\n", number);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "mod_xml_radius: failed to add option with value '%d' to handle\n", number);
goto err;
}
}
}
if ( av_value != NULL ) {
free(av_value);
+ av_value = NULL;
}
}
-
+
return SWITCH_STATUS_SUCCESS;
err:
+ if ( av_value != NULL ) {
+ free(av_value);
+ av_value = NULL;
+ }
return SWITCH_STATUS_GENERR;
}
rc_avpair_free(recv);
recv = NULL;
}
- rc_destroy(new_handle);
+ if ( send ) {
+ rc_avpair_free(send);
+ send = NULL;
+ }
+ if ( new_handle ) {
+ rc_destroy(new_handle);
+ new_handle = NULL;
+ }
return SWITCH_STATUS_SUCCESS;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "XML: %s \n", switch_xml_toxml(xml, 1));
}
- rc_avpair_free(recv);
- rc_destroy(new_handle);
+ if ( recv ) {
+ rc_avpair_free(recv);
+ recv = NULL;
+ }
+ if ( send ) {
+ rc_avpair_free(send);
+ send = NULL;
+ }
+ if ( new_handle ) {
+ rc_destroy(new_handle);
+ new_handle = NULL;
+ }
return xml;
err:
if ( recv ) {
rc_avpair_free(recv);
recv = NULL;
}
+ if ( send ) {
+ rc_avpair_free(send);
+ send = NULL;
+ }
if ( new_handle ) {
rc_destroy(new_handle);
new_handle = NULL;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "XML: %s \n", switch_xml_toxml(xml, 1));
}
- rc_avpair_free(recv);
- rc_destroy(new_handle);
+ if ( recv ) {
+ rc_avpair_free(recv);
+ recv = NULL;
+ }
+ if ( send ) {
+ rc_avpair_free(send);
+ send = NULL;
+ }
+ if ( new_handle ) {
+ rc_destroy(new_handle);
+ new_handle = NULL;
+ }
+
return xml;
err:
if ( recv ) {
rc_avpair_free(recv);
recv = NULL;
}
+ if ( send ) {
+ rc_avpair_free(send);
+ send = NULL;
+ }
if ( new_handle ) {
rc_destroy(new_handle);
new_handle = NULL;
}
end:
+ if ( send ) {
+ rc_avpair_free(send);
+ send = NULL;
+ }
if ( new_handle ) {
rc_destroy(new_handle);
+ new_handle = NULL;
}
return SWITCH_STATUS_SUCCESS;
}
end:
+ if ( send ) {
+ rc_avpair_free(send);
+ send = NULL;
+ }
if ( new_handle) {
rc_destroy(new_handle);
+ new_handle = NULL;
}
return SWITCH_STATUS_SUCCESS;
SWITCH_STANDARD_APP(radius_auth_handle)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
-
int result = 0;
VALUE_PAIR *send = NULL, *recv = NULL, *service_vp = NULL;
char msg[512 * 10 + 1] = {0};
uint32_t service = PW_AUTHENTICATE_ONLY;
rc_handle *new_handle = NULL;
switch_xml_t fields;
- char name[512], value[512];
+ char name[512], value[512], *temp = NULL;
if (GLOBAL_DEBUG ) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mod_xml_radius: starting app authentication\n");
if ( GLOBAL_DEBUG ){
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mod_xml_radius: result(RC=%d) %s \n", result, msg);
}
-
- switch_channel_set_variable(channel, "radius_auth_result", switch_mprintf("%d",result));
+ temp = switch_mprintf("%d",result);
+ switch_channel_set_variable(channel, "radius_auth_result", temp);
+ free(temp);
+ temp = NULL;
if ( result != 0 ) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mod_xml_radius: Failed to authenticate\n");
service_vp = service_vp->next;
}
- rc_avpair_free(recv);
- rc_destroy(new_handle);
+ if ( recv ) {
+ rc_avpair_free(recv);
+ recv = NULL;
+ }
+ if ( send ) {
+ rc_avpair_free(send);
+ send = NULL;
+ }
+ if ( new_handle ) {
+ rc_destroy(new_handle);
+ new_handle = NULL;
+ }
+
return;
err:
if ( recv ) {
rc_avpair_free(recv);
recv = NULL;
}
+ if ( send ) {
+ rc_avpair_free(send);
+ send = NULL;
+ }
if ( new_handle ) {
rc_destroy(new_handle);
new_handle = NULL;
}
-
return;
}
if ( globals.auth_invite_configs ) {
switch_xml_free(globals.auth_invite_configs);
}
+ if ( globals.auth_reg_configs ) {
+ switch_xml_free(globals.auth_reg_configs);
+ }
+ if ( globals.auth_app_configs ) {
+ switch_xml_free(globals.auth_app_configs);
+ }
+ if ( globals.acct_start_configs ) {
+ switch_xml_free(globals.acct_start_configs);
+ }
+ if ( globals.acct_end_configs ) {
+ switch_xml_free(globals.acct_end_configs);
+ }
return SWITCH_STATUS_SUCCESS;
}