mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-10-29 14:44:17 +00:00
add domain-based acl auth thingy
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9056 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
1 parent
74c511f421
commit
4722de507b
8 files changed
+150
-87
No files matched your search
@@ -365,54 +365,7 @@ SWITCH_STANDARD_APP(three_way_function)
|
||||
#define SET_USER_SYNTAX "<user>@<domain>"
|
||||
SWITCH_STANDARD_APP(set_user_function)
|
||||
{
|
||||
switch_xml_t x_domain, xml = NULL, x_user, x_param, x_params;
|
||||
char *user, *mailbox, *domain;
|
||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||
|
||||
if (switch_strlen_zero(data)) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
user = switch_core_session_strdup(session, data);
|
||||
|
||||
if (!(domain = strchr(user, '@'))) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
*domain++ = '\0';
|
||||
|
||||
if (switch_xml_locate_user("id", user, domain, NULL, &xml, &x_domain, &x_user, NULL) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", user, domain);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if ((mailbox = (char *) switch_xml_attr(x_user, "mailbox"))) {
|
||||
switch_channel_set_variable(channel, "mailbox", mailbox);
|
||||
}
|
||||
|
||||
if ((x_params = switch_xml_child(x_user, "variables"))) {
|
||||
for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
|
||||
const char *var = switch_xml_attr(x_param, "name");
|
||||
const char *val = switch_xml_attr(x_param, "value");
|
||||
|
||||
if (var && val) {
|
||||
switch_channel_set_variable(channel, var, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch_channel_set_variable(channel, "user_name", user);
|
||||
switch_channel_set_variable(channel, "domain_name", domain);
|
||||
|
||||
goto done;
|
||||
|
||||
error:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No user@domain specified.\n");
|
||||
|
||||
done:
|
||||
if (xml) {
|
||||
switch_xml_free(xml);
|
||||
}
|
||||
switch_ivr_set_user(session, data);
|
||||
}
|
||||
|
||||
SWITCH_STANDARD_APP(ring_ready_function)
|
||||
|
||||
@@ -2965,6 +2965,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
|
||||
su_addrinfo_t *my_addrinfo = msg_addrinfo(nua_current_request(nua));
|
||||
int network_port = 0;
|
||||
char *is_nat = NULL;
|
||||
char *acl_token = NULL;
|
||||
|
||||
if (sess_count >= sess_max || !(profile->pflags & PFLAG_RUNNING)) {
|
||||
nua_respond(nh, 503, "Maximum Calls In Progress", SIPTAG_RETRY_AFTER_STR("300"), TAG_END());
|
||||
@@ -3018,23 +3019,27 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (profile->acl_count) {
|
||||
uint32_t x = 0;
|
||||
int ok = 1;
|
||||
char *last_acl = NULL;
|
||||
const char *token;
|
||||
|
||||
for (x = 0; x < profile->acl_count; x++) {
|
||||
last_acl = profile->acl[x];
|
||||
if (!(ok = switch_check_network_list_ip(network_ip, last_acl))) {
|
||||
if (!(ok = switch_check_network_list_ip_token(network_ip, last_acl, &token))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
if (token) {
|
||||
acl_token = strdup(token);
|
||||
}
|
||||
if ((profile->pflags & PFLAG_AUTH_CALLS)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "IP %s Approved by acl %s. Access Granted.\n",
|
||||
network_ip, switch_str_nil(last_acl));
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "IP %s Approved by acl %s[%s]. Access Granted.\n",
|
||||
network_ip, switch_str_nil(last_acl), switch_str_nil(acl_token));
|
||||
is_auth = 1;
|
||||
}
|
||||
} else {
|
||||
@@ -3090,6 +3095,19 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
|
||||
|
||||
channel = tech_pvt->channel = switch_core_session_get_channel(session);
|
||||
|
||||
if (acl_token) {
|
||||
switch_channel_set_variable(channel, "acl_token", acl_token);
|
||||
if (strchr(acl_token, '@')) {
|
||||
if (switch_ivr_set_user(session, acl_token) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Authenticating user %s\n", acl_token);
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Error Authenticating user %s\n", acl_token);
|
||||
}
|
||||
}
|
||||
free(acl_token);
|
||||
acl_token = NULL;
|
||||
}
|
||||
|
||||
if (sip->sip_contact && sip->sip_contact->m_url) {
|
||||
char tmp[35] = "";
|
||||
sofia_transport_t transport = sofia_glue_url2transport(sip->sip_contact->m_url);
|
||||
|
||||
Reference in new issue
Block a user