提交 6c6d2aad authored 作者: Anthony Minessale's avatar Anthony Minessale

add ip auth

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4988 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 500a6c9a
...@@ -317,6 +317,13 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate(const char *section, ...@@ -317,6 +317,13 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate(const char *section,
const char *key_name, const char *key_value, switch_xml_t * root, switch_xml_t * node, const char *key_name, const char *key_value, switch_xml_t * root, switch_xml_t * node,
const char *params); const char *params);
SWITCH_DECLARE(switch_status_t) switch_xml_locate_domain(char *domain_name, char *params, switch_xml_t *root, switch_xml_t *domain);
SWITCH_DECLARE(switch_status_t) switch_xml_locate_user(char *user_name, char *domain_name,
char *ip,
switch_xml_t *root,
switch_xml_t *domain,
switch_xml_t *user);
///\brief open a config in the core registry ///\brief open a config in the core registry
///\param file_path the name of the config section e.g. modules.conf ///\param file_path the name of the config section e.g. modules.conf
///\param node a pointer to point to the node if it is found ///\param node a pointer to point to the node if it is found
......
...@@ -399,7 +399,7 @@ void sofia_presence_event_handler(switch_event_t *event); ...@@ -399,7 +399,7 @@ void sofia_presence_event_handler(switch_event_t *event);
void sofia_presence_mwi_event_handler(switch_event_t *event); void sofia_presence_mwi_event_handler(switch_event_t *event);
void sofia_presence_cancel(void); void sofia_presence_cancel(void);
switch_status_t config_sofia(int reload); switch_status_t config_sofia(int reload);
auth_res_t parse_auth(sofia_profile_t *profile, sip_authorization_t const *authorization, const char *regstr, char *np, size_t nplen); auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t const *authorization, const char *regstr, char *np, size_t nplen, char *ip);
void sofia_reg_handle_sip_r_challenge(int status, void sofia_reg_handle_sip_r_challenge(int status,
char const *phrase, char const *phrase,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, switch_core_session_t *session, sip_t const *sip, tagi_t tags[]); nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, switch_core_session_t *session, sip_t const *sip, tagi_t tags[]);
......
...@@ -78,7 +78,7 @@ void sofia_event_callback(nua_event_t event, ...@@ -78,7 +78,7 @@ void sofia_event_callback(nua_event_t event,
if ((profile->pflags & PFLAG_AUTH_ALL) && tech_pvt && tech_pvt->key && sip) { if ((profile->pflags & PFLAG_AUTH_ALL) && tech_pvt && tech_pvt->key && sip) {
sip_authorization_t const *authorization = NULL; sip_authorization_t const *authorization = NULL;
if (sip->sip_authorization) { if (sip->sip_authorization) {
authorization = sip->sip_authorization; authorization = sip->sip_authorization;
} else if (sip->sip_proxy_authorization) { } else if (sip->sip_proxy_authorization) {
...@@ -86,7 +86,10 @@ void sofia_event_callback(nua_event_t event, ...@@ -86,7 +86,10 @@ void sofia_event_callback(nua_event_t event,
} }
if (authorization) { if (authorization) {
auth_res = parse_auth(profile, authorization, (char *) sip->sip_request->rq_method_name, tech_pvt->key, strlen(tech_pvt->key)); char network_ip[80];
get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_addr);
auth_res = sofia_reg_parse_auth(profile, authorization,
(char *) sip->sip_request->rq_method_name, tech_pvt->key, strlen(tech_pvt->key), network_ip);
} }
if (auth_res != AUTH_OK) { if (auth_res != AUTH_OK) {
......
...@@ -1459,9 +1459,6 @@ int sofia_glue_init_sql(sofia_profile_t *profile) ...@@ -1459,9 +1459,6 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
char auth_sql[] = char auth_sql[] =
"CREATE TABLE sip_authentication (\n" "CREATE TABLE sip_authentication (\n"
" user VARCHAR(255),\n"
" host VARCHAR(255),\n"
" passwd VARCHAR(255),\n"
" nonce VARCHAR(255),\n" " nonce VARCHAR(255),\n"
" expires INTEGER(8)" " expires INTEGER(8)"
");\n"; ");\n";
......
...@@ -1173,6 +1173,46 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate(const char *section, ...@@ -1173,6 +1173,46 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate(const char *section,
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
SWITCH_DECLARE(switch_status_t) switch_xml_locate_domain(char *domain_name, char *params, switch_xml_t *root, switch_xml_t *domain)
{
*domain = NULL;
return switch_xml_locate("directory", "domain", "name", domain_name, root, domain, params);
}
SWITCH_DECLARE(switch_status_t) switch_xml_locate_user(char *user_name, char *domain_name,
char *ip,
switch_xml_t *root,
switch_xml_t *domain,
switch_xml_t *user)
{
char params[1024] = "";
switch_status_t status;
*root = NULL;
*user = NULL;
*domain = NULL;
snprintf(params, sizeof(params), "user=%s&domain=%s&ip=%s", switch_str_nil(user_name), switch_str_nil(domain_name), switch_str_nil(ip));
if ((status = switch_xml_locate_domain(domain_name, params, root, domain)) != SWITCH_STATUS_SUCCESS) {
return status;
}
if (ip) {
if ((*user = switch_xml_find_child(*domain, "user", "ip", ip))) {
return SWITCH_STATUS_SUCCESS;
}
}
if (user_name) {
if (!(*user = switch_xml_find_child(*domain, "user", "id", user_name))) {
return SWITCH_STATUS_FALSE;
}
return SWITCH_STATUS_SUCCESS;
}
return SWITCH_STATUS_FALSE;
}
SWITCH_DECLARE(switch_xml_t) switch_xml_root(void) SWITCH_DECLARE(switch_xml_t) switch_xml_root(void)
{ {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论