From 1fe21371a358670e0df084aa0bdcc8d8b52df5ab Mon Sep 17 00:00:00 2001
From: Luigi Rizzo <rizzo@icir.org>
Date: Fri, 13 Oct 2006 11:11:19 +0000
Subject: [PATCH] arguments to auth_headers() needed to be swapped here. To
 avoid the same mistake in the future (due to slightly confusing variable
 names), add a comment.

On passing, remove a redundant initialization.



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@45009 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 channels/chan_sip.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index ee285a92d6..f4de10bba5 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -7737,7 +7737,7 @@ static enum check_auth_result check_auth(struct sip_pvt *p, struct sip_request *
 					 const char *secret, const char *md5secret, int sipmethod,
 					 char *uri, enum xmittype reliable, int ignore)
 {
-	const char *response = "407 Proxy Authentication Required";
+	const char *response;
 	char *reqheader, *respheader;
 	const char *authtoken;
 	char a1_hash[256];
@@ -7746,6 +7746,7 @@ static enum check_auth_result check_auth(struct sip_pvt *p, struct sip_request *
 	char *c;
 	int  wrongnonce = FALSE;
 	int  good_response;
+	int code;
 	const char *usednonce = p->randdata;
 
 	/* table of recognised keywords, and their value in the digest */
@@ -7768,12 +7769,18 @@ static enum check_auth_result check_auth(struct sip_pvt *p, struct sip_request *
 		/* On a REGISTER, we have to use 401 and its family of headers
 		 * instead of 407 and its family of headers.
 		 */
+		code = WWW_AUTH;
 		response = "401 Unauthorized";
-		auth_headers(WWW_AUTH, &reqheader, &respheader);
 	} else {
+		code = PROXY_AUTH;
 		response = "407 Proxy Authentication Required";
-		auth_headers(PROXY_AUTH, &reqheader, &respheader);
 	}
+	/*
+	 * Note the apparent swap of arguments below, compared to other
+	 * usages of auth_headers().
+	 */
+	auth_headers(code, &respheader, &reqheader);
+
 	authtoken =  get_header(req, reqheader);	
 	if (ignore && !ast_strlen_zero(p->randdata) && ast_strlen_zero(authtoken)) {
 		/* This is a retransmitted invite/register/etc, don't reconstruct authentication
-- 
GitLab