mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-17 14:58:34 +00:00
a little update to the sofia-sip library
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4939 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
1 parent
fabed21ea8
commit
853936abd3
270 files changed
+37121
-11402
No files matched your search
@@ -11,6 +11,7 @@ TAGFILES += ../docs/bnf.doxytags=../bnf
|
||||
TAGFILES += ../docs/url.doxytags=../url
|
||||
TAGFILES += ../docs/msg.doxytags=../msg
|
||||
TAGFILES += ../docs/sip.doxytags=../sip
|
||||
TAGFILES += ../docs/http.doxytags=../http
|
||||
TAGFILES += ../docs/sresolv.doxytags=../sresolv
|
||||
TAGFILES += ../docs/tport.doxytags=../tport
|
||||
TAGFILES += ../docs/nta.doxytags=../nta
|
||||
@@ -18,3 +19,6 @@ TAGFILES += ../docs/nta.doxytags=../nta
|
||||
GENERATE_TAGFILE = ../docs/iptsec.doxytags
|
||||
|
||||
ALIASES +=
|
||||
|
||||
PREDEFINED += SOFIA_EXTEND_AUTH_CLIENT=1
|
||||
|
||||
@@ -35,29 +35,18 @@ nobase_include_sofia_HEADERS = \
|
||||
sofia-sip/auth_common.h \
|
||||
sofia-sip/auth_client.h sofia-sip/auth_digest.h \
|
||||
sofia-sip/auth_module.h sofia-sip/auth_plugin.h \
|
||||
sofia-sip/auth_client_plugin.h \
|
||||
$(NTLM_HEADER)
|
||||
sofia-sip/auth_client_plugin.h
|
||||
|
||||
libiptsec_la_SOURCES = iptsec_debug.h \
|
||||
auth_client.c auth_common.c auth_digest.c \
|
||||
auth_module.c auth_tag.c auth_tag_ref.c \
|
||||
auth_plugin.c auth_plugin_delayed.c \
|
||||
auth_module_http.c auth_module_sip.c \
|
||||
$(NTLM_SOURCE) \
|
||||
auth_module_sip.c \
|
||||
iptsec_debug.c
|
||||
|
||||
NTLM_HEADER = sofia-sip/auth_ntlm.h
|
||||
if HAVE_NTLM
|
||||
NTLM_SOURCE = auth_ntlm.c auth_client_ntlm.c auth_plugin_ntlm.c
|
||||
endif
|
||||
|
||||
EXTRA_libiptsec_la_SOURCES = \
|
||||
auth_ntlm.c auth_client_ntlm.c auth_plugin_ntlm.c
|
||||
|
||||
COVERAGE_INPUT = $(libiptsec_la_SOURCES) $(include_sofia_HEADERS)
|
||||
|
||||
LDADD = libiptsec.la \
|
||||
../http/libhttp.la \
|
||||
../nta/libnta.la \
|
||||
../sip/libsip.la \
|
||||
../msg/libmsg.la \
|
||||
@@ -68,13 +57,31 @@ LDADD = libiptsec.la \
|
||||
|
||||
test_auth_digest_LDFLAGS = -static
|
||||
|
||||
if HAVE_NTLM
|
||||
nobase_include_sofia_HEADERS += $(NTLM_HEADER)
|
||||
libiptsec_la_SOURCES += $(NTLM_SOURCE)
|
||||
endif
|
||||
|
||||
if HAVE_NTH
|
||||
libiptsec_la_SOURCES += $(HTTP_SOURCE)
|
||||
LDADD += ../http/libhttp.la
|
||||
endif
|
||||
|
||||
HTTP_SOURCE = auth_module_http.c
|
||||
|
||||
NTLM_HEADER = sofia-sip/auth_ntlm.h
|
||||
NTLM_SOURCE = auth_ntlm.c auth_client_ntlm.c auth_plugin_ntlm.c
|
||||
|
||||
EXTRA_libiptsec_la_SOURCES = \
|
||||
$(NTLM_HEADER) $(NTLM_SOURCE) $(HTTP_SOURCE)
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# Install and distribution rules
|
||||
|
||||
EXTRA_DIST = Doxyfile iptsec.docs testpasswd \
|
||||
auth_module_sip.c auth_module_http.c $(BUILT_SOURCES)
|
||||
EXTRA_DIST = Doxyfile iptsec.docs testpasswd $(BUILT_SOURCES)
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# Sofia specific rules
|
||||
|
||||
include ../sofia.am
|
||||
include $(top_srcdir)/rules/sofia.am
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define SOFIA_EXTEND_AUTH_CLIENT 1
|
||||
|
||||
#include <sofia-sip/su.h>
|
||||
#include <sofia-sip/su_md5.h>
|
||||
|
||||
@@ -77,9 +79,7 @@ static int ca_credentials(auth_client_t *ca,
|
||||
char const *user,
|
||||
char const *pass);
|
||||
|
||||
static int ca_clear_credentials(auth_client_t *ca,
|
||||
char const *scheme,
|
||||
char const *realm);
|
||||
static int ca_clear_credentials(auth_client_t *ca);
|
||||
|
||||
|
||||
/** Initialize authenticators.
|
||||
@@ -178,29 +178,31 @@ int ca_challenge(auth_client_t *ca,
|
||||
return -1;
|
||||
|
||||
if (!ca->ca_credential_class)
|
||||
stale = 1, ca->ca_credential_class = credential_class;
|
||||
stale = 2, ca->ca_credential_class = credential_class;
|
||||
|
||||
return stale ? 2 : 1;
|
||||
return stale > 1 ? 2 : 1;
|
||||
}
|
||||
|
||||
/** Store authentication info to authenticators.
|
||||
*
|
||||
* The function auc_info() feeds the authentication data from the
|
||||
* authentication info @a info to the list of authenticators @a auc_list.
|
||||
* The function auc_info() feeds the authentication data from the @b
|
||||
* Authentication-Info header @a info to the list of authenticators @a
|
||||
* auc_list.
|
||||
*
|
||||
* @param[in,out] auc_list list of authenticators to be updated
|
||||
* @param[in] info info to be processed
|
||||
* @param[in] crcl corresponding credential class
|
||||
* @param[in] info info header to be processed
|
||||
* @param[in] credential_class corresponding credential class
|
||||
*
|
||||
* The authentication info can be in either Authentication-Info or in
|
||||
* Proxy-Authentication-Info headers.
|
||||
* If the header is Authentication-Info, the @a crcl should be
|
||||
* #sip_authorization_class or #http_authorization_class.
|
||||
* Likewise, If the header is Proxy-Authentication-Info, the @a crcl should
|
||||
* be #sip_proxy_authorization_class or #http_proxy_authorization_class.
|
||||
* The authentication info can be in either @AuthenticationInfo or in
|
||||
* @ProxyAuthenticationInfo headers. If the header is @AuthenticationInfo,
|
||||
* the @a credential_class should be #sip_authorization_class or
|
||||
* #http_authorization_class. Likewise, If the header is
|
||||
* @ProxyAuthenticationInfo, the @a credential_class should be
|
||||
* #sip_proxy_authorization_class or #http_proxy_authorization_class.
|
||||
|
||||
* The authentication into usually contains next nonce or mutual
|
||||
* authentication information. We handle only nextnonce parameter.
|
||||
* The authentication into header usually contains next nonce or mutual
|
||||
* authentication information. Currently, only the nextnonce parameter is
|
||||
* processed.
|
||||
*
|
||||
* @bug
|
||||
* The result can be quite unexpected if there are more than one
|
||||
@@ -210,9 +212,11 @@ int ca_challenge(auth_client_t *ca,
|
||||
* @retval number of challenges to updated
|
||||
* @retval 0 when there was no challenge to update
|
||||
* @retval -1 upon an error
|
||||
*
|
||||
* @NEW_1_12_5
|
||||
*/
|
||||
int auc_info(auth_client_t **auc_list,
|
||||
msg_auth_info_t const *ai,
|
||||
msg_auth_info_t const *info,
|
||||
msg_hclass_t *credential_class)
|
||||
{
|
||||
auth_client_t *ca;
|
||||
@@ -222,7 +226,7 @@ int auc_info(auth_client_t **auc_list,
|
||||
|
||||
/* Update matching authenticator */
|
||||
for (ca = *auc_list; ca; ca = ca->ca_next) {
|
||||
int updated = ca_info(ca, ai, credential_class);
|
||||
int updated = ca_info(ca, info, credential_class);
|
||||
if (updated < 0)
|
||||
return -1;
|
||||
if (updated >= 1)
|
||||
@@ -241,12 +245,12 @@ int auc_info(auth_client_t **auc_list,
|
||||
*/
|
||||
static
|
||||
int ca_info(auth_client_t *ca,
|
||||
msg_auth_info_t const *ai,
|
||||
msg_auth_info_t const *info,
|
||||
msg_hclass_t *credential_class)
|
||||
{
|
||||
assert(ca); assert(ai);
|
||||
assert(ca); assert(info);
|
||||
|
||||
if (!ca || !ai)
|
||||
if (!ca || !info)
|
||||
return -1;
|
||||
|
||||
if (!ca->ca_credential_class)
|
||||
@@ -261,7 +265,7 @@ int ca_info(auth_client_t *ca,
|
||||
|| !ca->ca_auc->auc_info)
|
||||
return 0;
|
||||
|
||||
return ca->ca_auc->auc_info(ca, ai);
|
||||
return ca->ca_auc->auc_info(ca, info);
|
||||
}
|
||||
|
||||
|
||||
@@ -336,8 +340,8 @@ int auc_credentials(auth_client_t **auc_list, su_home_t *home,
|
||||
* @param[in] user username
|
||||
* @param[in] pass password
|
||||
*
|
||||
* @retval number of matching clients
|
||||
* @retval 0 when no matching client was found
|
||||
* @retval number of updated clients
|
||||
* @retval 0 when no client was updated
|
||||
* @retval -1 upon an error
|
||||
*/
|
||||
int auc_all_credentials(auth_client_t **auc_list,
|
||||
@@ -371,6 +375,9 @@ int ca_credentials(auth_client_t *ca,
|
||||
char const *user,
|
||||
char const *pass)
|
||||
{
|
||||
char *new_user, *new_pass;
|
||||
char *old_user, *old_pass;
|
||||
|
||||
assert(ca);
|
||||
|
||||
if (!ca || !ca->ca_scheme || !ca->ca_realm)
|
||||
@@ -380,12 +387,24 @@ int ca_credentials(auth_client_t *ca,
|
||||
(realm != NULL && strcmp(realm, ca->ca_realm)))
|
||||
return -1;
|
||||
|
||||
ca->ca_user = su_strdup(ca->ca_home, user);
|
||||
ca->ca_pass = su_strdup(ca->ca_home, pass);
|
||||
old_user = ca->ca_user, old_pass = ca->ca_pass;
|
||||
|
||||
if (!ca->ca_user || !ca->ca_pass)
|
||||
if (str0cmp(user, old_user) == 0 && str0cmp(pass, old_pass) == 0)
|
||||
return 0;
|
||||
|
||||
new_user = su_strdup(ca->ca_home, user);
|
||||
new_pass = su_strdup(ca->ca_home, pass);
|
||||
|
||||
if (!new_user || !new_pass)
|
||||
return -1;
|
||||
|
||||
ca->ca_user = new_user, ca->ca_pass = new_pass;
|
||||
if (AUTH_CLIENT_IS_EXTENDED(ca))
|
||||
ca->ca_clear = 0;
|
||||
|
||||
su_free(ca->ca_home, old_user);
|
||||
su_free(ca->ca_home, old_pass);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -412,12 +431,15 @@ int auc_copy_credentials(auth_client_t **dst,
|
||||
char *u, *p;
|
||||
if (!ca->ca_user || !ca->ca_pass)
|
||||
continue;
|
||||
if (AUTH_CLIENT_IS_EXTENDED(ca) && ca->ca_clear)
|
||||
continue;
|
||||
if (!ca->ca_scheme[0] || strcmp(ca->ca_scheme, d->ca_scheme))
|
||||
continue;
|
||||
if (!ca->ca_realm[0] || strcmp(ca->ca_realm, d->ca_realm))
|
||||
continue;
|
||||
|
||||
if (d->ca_user && strcmp(d->ca_user, ca->ca_user) == 0 &&
|
||||
if (!(AUTH_CLIENT_IS_EXTENDED(d) && d->ca_clear) &&
|
||||
d->ca_user && strcmp(d->ca_user, ca->ca_user) == 0 &&
|
||||
d->ca_pass && strcmp(d->ca_pass, ca->ca_pass) == 0) {
|
||||
retval++;
|
||||
break;
|
||||
@@ -431,6 +453,9 @@ int auc_copy_credentials(auth_client_t **dst,
|
||||
if (d->ca_user) su_free(d->ca_home, (void *)d->ca_user);
|
||||
if (d->ca_pass) su_free(d->ca_home, (void *)d->ca_pass);
|
||||
d->ca_user = u, d->ca_pass = p;
|
||||
if (AUTH_CLIENT_IS_EXTENDED(d))
|
||||
d->ca_clear = 0;
|
||||
|
||||
retval++;
|
||||
break;
|
||||
}
|
||||
@@ -453,13 +478,24 @@ int auc_copy_credentials(auth_client_t **dst,
|
||||
* @retval -1 upon an error
|
||||
*/
|
||||
int auc_clear_credentials(auth_client_t **auc_list,
|
||||
char const *scheme,
|
||||
char const *realm)
|
||||
char const *scheme,
|
||||
char const *realm)
|
||||
{
|
||||
int retval = 0;
|
||||
int match;
|
||||
|
||||
for (; *auc_list; auc_list = &(*auc_list)->ca_next) {
|
||||
int match = ca_clear_credentials(*auc_list, scheme, realm);
|
||||
auth_client_t *ca = *auc_list;
|
||||
|
||||
if (!AUTH_CLIENT_IS_EXTENDED(ca))
|
||||
continue;
|
||||
|
||||
if ((scheme != NULL && strcasecmp(scheme, ca->ca_scheme)) ||
|
||||
(realm != NULL && strcmp(realm, ca->ca_realm)))
|
||||
continue;
|
||||
|
||||
match = ca->ca_auc->auc_clear(*auc_list);
|
||||
|
||||
if (match < 0) {
|
||||
retval = -1;
|
||||
break;
|
||||
@@ -472,21 +508,14 @@ int auc_clear_credentials(auth_client_t **auc_list,
|
||||
}
|
||||
|
||||
static
|
||||
int ca_clear_credentials(auth_client_t *ca,
|
||||
char const *scheme,
|
||||
char const *realm)
|
||||
int ca_clear_credentials(auth_client_t *ca)
|
||||
{
|
||||
assert(ca);
|
||||
assert(ca); assert(ca->ca_home->suh_size >= (int)(sizeof *ca));
|
||||
|
||||
if (!ca || !ca->ca_scheme || !ca->ca_realm)
|
||||
if (!ca)
|
||||
return -1;
|
||||
|
||||
if ((scheme != NULL && strcasecmp(scheme, ca->ca_scheme)) ||
|
||||
(realm != NULL && strcmp(realm, ca->ca_realm)))
|
||||
return -1;
|
||||
|
||||
su_free(ca->ca_home, (void *)ca->ca_user), ca->ca_user = NULL;
|
||||
su_free(ca->ca_home, (void *)ca->ca_pass), ca->ca_pass = NULL;
|
||||
ca->ca_clear = 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -495,6 +524,8 @@ int ca_clear_credentials(auth_client_t *ca,
|
||||
*
|
||||
* @retval 1 when authorization can proceed
|
||||
* @retval 0 when there is not enough credentials
|
||||
*
|
||||
* @NEW_1_12_5
|
||||
*/
|
||||
int auc_has_authorization(auth_client_t **auc_list)
|
||||
{
|
||||
@@ -507,6 +538,8 @@ int auc_has_authorization(auth_client_t **auc_list)
|
||||
for (ca = *auc_list; ca; ca = ca->ca_next) {
|
||||
if (!ca->ca_user || !ca->ca_pass || !ca->ca_credential_class)
|
||||
return 0;
|
||||
if (AUTH_CLIENT_IS_EXTENDED(ca) && ca->ca_clear)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
@@ -564,8 +597,11 @@ int auc_authorization(auth_client_t **auc_list, msg_t *msg, msg_pub_t *pub,
|
||||
if (!ca->ca_auc)
|
||||
continue;
|
||||
|
||||
if (ca->ca_auc->auc_authorize(ca, home, method, url, body, &h) < 0
|
||||
|| msg_header_insert(msg, pub, h) < 0)
|
||||
if (ca->ca_auc->auc_authorize(ca, home, method, url, body, &h) < 0)
|
||||
return -1;
|
||||
if (h == NULL)
|
||||
continue;
|
||||
if (msg_header_insert(msg, pub, h) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -633,14 +669,15 @@ static int auc_basic_authorization(auth_client_t *ca,
|
||||
msg_payload_t const *body,
|
||||
msg_header_t **);
|
||||
|
||||
const auth_client_plugin_t ca_basic_plugin =
|
||||
static const auth_client_plugin_t ca_basic_plugin =
|
||||
{
|
||||
/* auc_plugin_size: */ sizeof ca_basic_plugin,
|
||||
/* auc_size: */ sizeof (auth_client_t),
|
||||
/* auc_name: */ "Basic",
|
||||
/* auc_challenge: */ NULL,
|
||||
/* auc_authorize: */ auc_basic_authorization,
|
||||
/* auc_info: */ NULL
|
||||
/* auc_info: */ NULL,
|
||||
/* auc_clear: */ ca_clear_credentials
|
||||
};
|
||||
|
||||
/**Create a basic authorization header.
|
||||
@@ -677,6 +714,9 @@ int auc_basic_authorization(auth_client_t *ca,
|
||||
if (user == NULL || pass == NULL)
|
||||
return -1;
|
||||
|
||||
if (AUTH_CLIENT_IS_EXTENDED(ca) && ca->ca_clear)
|
||||
return 0;
|
||||
|
||||
ulen = strlen(user), plen = strlen(pass), uplen = ulen + 1 + plen;
|
||||
b64len = BASE64_SIZE(uplen);
|
||||
basiclen = strlen("Basic ") + b64len;
|
||||
@@ -731,7 +771,7 @@ static int auc_digest_authorization(auth_client_t *ca,
|
||||
msg_payload_t const *body,
|
||||
msg_header_t **);
|
||||
static int auc_digest_info(auth_client_t *ca,
|
||||
msg_auth_info_t const *ai);
|
||||
msg_auth_info_t const *info);
|
||||
|
||||
static const auth_client_plugin_t ca_digest_plugin =
|
||||
{
|
||||
@@ -740,10 +780,15 @@ static const auth_client_plugin_t ca_digest_plugin =
|
||||
/* auc_name: */ "Digest",
|
||||
/* auc_challenge: */ auc_digest_challenge,
|
||||
/* auc_authorize: */ auc_digest_authorization,
|
||||
/* auc_info: */ auc_digest_info
|
||||
/* auc_info: */ auc_digest_info,
|
||||
/* auc_clear: */ ca_clear_credentials
|
||||
};
|
||||
|
||||
/** Store a digest authorization challenge.
|
||||
*
|
||||
* @retval 2 if credentials need to be (re)sent
|
||||
* @retval 1 if challenge was updated
|
||||
* @retval -1 upon an error
|
||||
*/
|
||||
static int auc_digest_challenge(auth_client_t *ca, msg_auth_t const *ch)
|
||||
{
|
||||
@@ -761,27 +806,18 @@ static int auc_digest_challenge(auth_client_t *ca, msg_auth_t const *ch)
|
||||
if (ac->ac_qop && !ac->ac_auth && !ac->ac_auth_int)
|
||||
goto error;
|
||||
|
||||
stale = ac->ac_stale || str0cmp(ac->ac_nonce, cda->cda_ac->ac_nonce);
|
||||
stale = ac->ac_stale || cda->cda_ac->ac_nonce == NULL;
|
||||
|
||||
if (ac->ac_qop && (cda->cda_cnonce == NULL || ac->ac_stale)) {
|
||||
su_guid_t guid[1];
|
||||
char *cnonce;
|
||||
char *e;
|
||||
|
||||
size_t b64len = BASE64_MINSIZE(sizeof(guid)) + 1;
|
||||
if (cda->cda_cnonce != NULL)
|
||||
/* Free the old one if we are updating after stale=true */
|
||||
su_free(home, (void *)cda->cda_cnonce);
|
||||
su_guid_generate(guid);
|
||||
cda->cda_cnonce = cnonce = su_alloc(home, BASE64_SIZE(sizeof(guid)) + 1);
|
||||
base64_e(cnonce, BASE64_SIZE(sizeof(guid)) + 1, guid, sizeof(guid));
|
||||
/* somewhere else in the code the '=' chars are stripped in the header
|
||||
we need to strip it now before the digest is created or we're in trouble
|
||||
cos they won't match.....
|
||||
*/
|
||||
e = cnonce + strlen(cnonce) - 1;
|
||||
while(*e == '=') {
|
||||
*e-- = '\0';
|
||||
}
|
||||
cda->cda_cnonce = cnonce = su_alloc(home, b64len);
|
||||
base64_e(cnonce, b64len, guid, sizeof(guid));
|
||||
cda->cda_ncount = 0;
|
||||
}
|
||||
|
||||
@@ -797,14 +833,14 @@ static int auc_digest_challenge(auth_client_t *ca, msg_auth_t const *ch)
|
||||
}
|
||||
|
||||
static int auc_digest_info(auth_client_t *ca,
|
||||
msg_auth_info_t const *ai)
|
||||
msg_auth_info_t const *info)
|
||||
{
|
||||
auth_digest_client_t *cda = (auth_digest_client_t *)ca;
|
||||
su_home_t *home = ca->ca_home;
|
||||
char const *nextnonce = NULL;
|
||||
issize_t n;
|
||||
|
||||
n = auth_get_params(home, ai->ai_params,
|
||||
n = auth_get_params(home, info->ai_params,
|
||||
"nextnonce=", &nextnonce,
|
||||
NULL);
|
||||
|
||||
@@ -825,9 +861,9 @@ static int auc_digest_info(auth_client_t *ca,
|
||||
* sip_authorization_class or sip_proxy_authorization_class, as well as
|
||||
* http_authorization_class or http_proxy_authorization_class.
|
||||
*
|
||||
* @return
|
||||
* Returns a pointer to newly created authorization header, or NULL upon an
|
||||
* error.
|
||||
* @retval 1 when authorization headers has been created
|
||||
* @retval 0 when there is no credentials
|
||||
* @retval -1 upon an error
|
||||
*/
|
||||
static
|
||||
int auc_digest_authorization(auth_client_t *ca,
|
||||
@@ -853,6 +889,9 @@ int auc_digest_authorization(auth_client_t *ca,
|
||||
auth_response_t ar[1] = {{ 0 }};
|
||||
char ncount[17];
|
||||
|
||||
if (!user || !pass || (AUTH_CLIENT_IS_EXTENDED(ca) && ca->ca_clear))
|
||||
return 0;
|
||||
|
||||
ar->ar_size = sizeof(ar);
|
||||
ar->ar_username = user;
|
||||
ar->ar_realm = ac->ac_realm;
|
||||
|
||||
@@ -76,6 +76,7 @@ static char const __func__[] = "auth_mod";
|
||||
|
||||
char const auth_internal_server_error[] = "Internal server error";
|
||||
|
||||
static void auth_call_scheme_destructor(void *);
|
||||
static void auth_md5_hmac_key(auth_mod_t *am);
|
||||
|
||||
HTABLE_PROTOS_WITH(auth_htable, aht, auth_passwd_t, usize_t, unsigned);
|
||||
@@ -94,7 +95,7 @@ auth_mod_t *auth_mod_alloc(auth_scheme_t *scheme,
|
||||
|
||||
if ((am = su_home_new(scheme->asch_size))) {
|
||||
am->am_scheme = scheme;
|
||||
am->am_refcount = 1;
|
||||
su_home_destructor(am->am_home, auth_call_scheme_destructor);
|
||||
}
|
||||
|
||||
return am;
|
||||
@@ -246,10 +247,14 @@ int auth_init_default(auth_mod_t *am,
|
||||
/** Destroy (a reference to) an authentication module. */
|
||||
void auth_mod_destroy(auth_mod_t *am)
|
||||
{
|
||||
if (am && am->am_refcount != 0 && --am->am_refcount == 0) {
|
||||
am->am_scheme->asch_destroy(am);
|
||||
su_home_zap(am->am_home);
|
||||
}
|
||||
su_home_unref(am->am_home);
|
||||
}
|
||||
|
||||
/** Call scheme-specific destructor function. */
|
||||
static void auth_call_scheme_destructor(void *arg)
|
||||
{
|
||||
auth_mod_t *am = arg;
|
||||
am->am_scheme->asch_destroy(am);
|
||||
}
|
||||
|
||||
/** Do-nothing destroy function.
|
||||
@@ -264,18 +269,13 @@ void auth_destroy_default(auth_mod_t *am)
|
||||
/** Create a new reference to authentication module. */
|
||||
auth_mod_t *auth_mod_ref(auth_mod_t *am)
|
||||
{
|
||||
if (!am || am->am_refcount == 0)
|
||||
return NULL;
|
||||
|
||||
am->am_refcount++;
|
||||
|
||||
return am;
|
||||
return (auth_mod_t *)su_home_ref(am->am_home);
|
||||
}
|
||||
|
||||
/** Destroy a reference to an authentication module. */
|
||||
void auth_mod_unref(auth_mod_t *am)
|
||||
{
|
||||
auth_mod_destroy(am);
|
||||
su_home_unref(am->am_home);
|
||||
}
|
||||
|
||||
/** Get authenticatin module name. @NEW_1_12_4. */
|
||||
@@ -608,7 +608,7 @@ struct nonce {
|
||||
uint8_t digest[6];
|
||||
};
|
||||
|
||||
#define AUTH_DIGEST_NONCE_LEN (BASE64_SIZE(sizeof (struct nonce)) + 1)
|
||||
#define AUTH_DIGEST_NONCE_LEN (BASE64_MINSIZE(sizeof (struct nonce)) + 1)
|
||||
|
||||
/** Authenticate a request with @b Digest authentication scheme.
|
||||
*
|
||||
@@ -950,7 +950,8 @@ int auth_readdb_if_needed(auth_mod_t *am)
|
||||
#include <sys/file.h>
|
||||
#endif
|
||||
|
||||
#define auth_apw_local auth_readdb_internal
|
||||
/* This is just a magic value */
|
||||
#define auth_apw_local ((void *)(intptr_t)auth_readdb_internal)
|
||||
|
||||
/** Read authentication database */
|
||||
static
|
||||
|
||||
@@ -126,7 +126,7 @@ static int delayed_auth_init(auth_mod_t *am,
|
||||
|
||||
struct auth_splugin_t
|
||||
{
|
||||
void const *asp_tag;
|
||||
void const *asp_cookie;
|
||||
auth_splugin_t *asp_next;
|
||||
auth_splugin_t **asp_prev;
|
||||
auth_mod_t *asp_am;
|
||||
@@ -136,6 +136,8 @@ struct auth_splugin_t
|
||||
int asp_canceled;
|
||||
};
|
||||
|
||||
/* This is unique identifier */
|
||||
#define delayed_asp_cookie ((void const *)(intptr_t)delayed_auth_cancel)
|
||||
|
||||
static void delayed_auth_method_recv(su_root_magic_t *rm,
|
||||
su_msg_r msg,
|
||||
@@ -162,7 +164,7 @@ static void delayed_auth_method(auth_mod_t *am,
|
||||
|
||||
asp = su_msg_data(mamc); assert(asp);
|
||||
|
||||
asp->asp_tag = delayed_auth_cancel;
|
||||
asp->asp_cookie = delayed_asp_cookie;
|
||||
asp->asp_am = am;
|
||||
asp->asp_as = as;
|
||||
asp->asp_header = auth;
|
||||
@@ -216,7 +218,7 @@ static void delayed_auth_cancel(auth_mod_t *am, auth_status_t *as)
|
||||
|
||||
(void)ap; /* xyzzy */
|
||||
|
||||
if (as->as_plugin && as->as_plugin->asp_tag == delayed_auth_cancel)
|
||||
if (as->as_plugin && as->as_plugin->asp_cookie == delayed_asp_cookie)
|
||||
as->as_plugin->asp_canceled = 1;
|
||||
|
||||
as->as_status = 500, as->as_phrase = "Authentication canceled";
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
/**@file sofia-sip/auth_client_plugin.h
|
||||
* @brief Client-side plugin interface for authentication
|
||||
*
|
||||
* @note For extensions in 1.12.6 or later,
|
||||
* you have to #define SOFIA_EXTEND_AUTH_CLIENT to 1.
|
||||
*
|
||||
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
|
||||
*
|
||||
* @date Created: Fri May 19 16:18:21 EEST 2006
|
||||
@@ -58,6 +61,10 @@ struct auth_client_s {
|
||||
char *ca_pass;
|
||||
|
||||
msg_hclass_t *ca_credential_class;
|
||||
|
||||
#if SOFIA_EXTEND_AUTH_CLIENT
|
||||
int ca_clear;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct auth_client_plugin
|
||||
@@ -81,8 +88,19 @@ struct auth_client_plugin
|
||||
|
||||
/** Store nextnonce from Authentication-Info or Proxy-Authentication-Info. */
|
||||
int (*auc_info)(auth_client_t *ca, msg_auth_info_t const *ai);
|
||||
|
||||
#if SOFIA_EXTEND_AUTH_CLIENT
|
||||
/** Clear credentials (user/pass). @NEW_1_12_6 */
|
||||
int (*auc_clear)(auth_client_t *ca);
|
||||
#endif
|
||||
};
|
||||
|
||||
/** Check if authentication client has been extended. @NEW_1_12_6 */
|
||||
#define AUTH_CLIENT_IS_EXTENDED(ca) \
|
||||
((ca)->ca_auc->auc_plugin_size > \
|
||||
(int)offsetof(auth_client_plugin_t, auc_clear) \
|
||||
&& (ca)->ca_auc->auc_clear != NULL)
|
||||
|
||||
SOFIA_END_DECLS
|
||||
|
||||
#endif /* !defined AUTH_CLIENT_PLUGIN_H */
|
||||
@@ -105,7 +105,7 @@ struct auth_scheme
|
||||
typedef struct
|
||||
{
|
||||
unsigned apw_index; /**< Key to hash table */
|
||||
void const *apw_type; /**< Magic pointer */
|
||||
void const *apw_type; /**< Magic identifier */
|
||||
|
||||
char const *apw_user; /**< Username */
|
||||
char const *apw_realm; /**< Realm */
|
||||
@@ -124,7 +124,7 @@ struct stat;
|
||||
struct auth_mod_t
|
||||
{
|
||||
su_home_t am_home[1];
|
||||
unsigned am_refcount; /**< Number of references to this module */
|
||||
unsigned _am_refcount; /**< Not used */
|
||||
|
||||
/* User database / cache */
|
||||
char const *am_db; /**< User database file name */
|
||||
|
||||
@@ -769,8 +769,6 @@ int test_digest_client()
|
||||
{
|
||||
char const *nonce1, *nextnonce, *nonce2;
|
||||
|
||||
reinit_as(as); auth_mod_destroy(am); aucs = NULL;
|
||||
|
||||
TEST_1(am = auth_mod_create(NULL,
|
||||
AUTHTAG_METHOD("Digest"),
|
||||
AUTHTAG_REALM("ims3.so.noklab.net"),
|
||||
@@ -1164,9 +1162,10 @@ int test_module_io()
|
||||
extern su_log_t iptsec_log[];
|
||||
|
||||
static
|
||||
void usage(void)
|
||||
void usage(int exitcode)
|
||||
{
|
||||
fprintf(stderr, "usage: %s [-v] [-l n]\n", name);
|
||||
fprintf(stderr, "usage: %s [-v] [-a] [-l n]\n", name);
|
||||
exit(exitcode);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@@ -1179,8 +1178,10 @@ int main(int argc, char *argv[])
|
||||
su_init();
|
||||
|
||||
for (i = 1; argv[i]; i++) {
|
||||
if (argv[i] && strcmp(argv[i], "-v") == 0)
|
||||
if (strcmp(argv[i], "-v") == 0)
|
||||
tstflags |= tst_verbatim;
|
||||
else if (strcmp(argv[i], "-a") == 0)
|
||||
tstflags |= tst_abort;
|
||||
else if (strncmp(argv[i], "-l", 2) == 0) {
|
||||
int level = 3;
|
||||
char *rest = NULL;
|
||||
@@ -1193,11 +1194,11 @@ int main(int argc, char *argv[])
|
||||
level = 3, rest = "";
|
||||
|
||||
if (rest == NULL || *rest)
|
||||
usage();
|
||||
usage(1);
|
||||
|
||||
su_log_set_level(iptsec_log, level);
|
||||
} else {
|
||||
usage();
|
||||
usage(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user