summaryrefslogtreecommitdiff
path: root/res/res_pjsip_outbound_registration.c
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2014-12-18 15:34:16 +0000
committerMark Michelson <mmichelson@digium.com>2014-12-18 15:34:16 +0000
commit14d2f8f20fc71b3aed7191c69b9fda378b696840 (patch)
treea4cb91d8e23a78f2bd426f1f75fde0d129f739f6 /res/res_pjsip_outbound_registration.c
parentc1582929f9c27330ac58420e2329421a4713b70c (diff)
Prevent potential infinite outbound authentication loops in registration.
Prior to this patch, Asterisk would always respond to 401 responses to registration attempts by trying to provide a registration with authentication credentials. Even if subsequent attempts were rejected with 401 responses, Asterisk would continue this behavior. If authentication credentials were incorrect, this could continue forever. With this patch, we keep track of whether we have attempted authentication on an outbound registration attempt. If we already have, we don not try again until the next attempt. This prevents the infinite loop scenario. Review: https://reviewboard.asterisk.org/r/4273 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@429761 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_pjsip_outbound_registration.c')
-rw-r--r--res/res_pjsip_outbound_registration.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/res/res_pjsip_outbound_registration.c b/res/res_pjsip_outbound_registration.c
index 552d61e28..6de264647 100644
--- a/res/res_pjsip_outbound_registration.c
+++ b/res/res_pjsip_outbound_registration.c
@@ -256,6 +256,8 @@ struct sip_outbound_registration_client_state {
struct ast_sip_auth_vector outbound_auths;
/*! \brief Registration should be destroyed after completion of transaction */
unsigned int destroy:1;
+ /*! \brief Non-zero if we have attempted sending a REGISTER with authentication */
+ unsigned int auth_attempted:1;
};
/*! \brief Outbound registration state information (persists for lifetime that registration should exist) */
@@ -563,12 +565,15 @@ static int handle_registration_response(void *data)
ast_copy_pj_str(server_uri, &info.server_uri, sizeof(server_uri));
ast_copy_pj_str(client_uri, &info.client_uri, sizeof(client_uri));
- if (response->code == 401 || response->code == 407) {
+ if (!response->client_state->auth_attempted &&
+ (response->code == 401 || response->code == 407)) {
pjsip_tx_data *tdata;
if (!ast_sip_create_request_with_auth(&response->client_state->outbound_auths,
response->rdata, response->tsx, &tdata)) {
ao2_ref(response->client_state, +1);
+ response->client_state->auth_attempted = 1;
if (pjsip_regc_send(response->client_state->client, tdata) != PJ_SUCCESS) {
+ response->client_state->auth_attempted = 0;
ao2_cleanup(response->client_state);
}
return 0;
@@ -576,6 +581,8 @@ static int handle_registration_response(void *data)
/* Otherwise, fall through so the failure is processed appropriately */
}
+ response->client_state->auth_attempted = 0;
+
if (PJSIP_IS_STATUS_IN_CLASS(response->code, 200)) {
/* Check if this is in regards to registering or unregistering */
if (response->expiration) {