--- /home/chan_sip.c 2007-04-24 19:05:06.000000000 +0300 +++ /root/asterisk-1.2.18/channels/chan_sip.c 2007-06-12 20:58:59.000000000 +0300 @@ -10145,6 +10145,20 @@ handle_response_invite(p, resp, rest, req, ignore, seqno); } else if (p->registry && sipmethod == SIP_REGISTER) { res = handle_response_register(p, resp, rest, req, ignore, seqno); + } else if (sipmethod == SIP_BYE || sipmethod == SIP_REFER) { + char *auth, *auth2; + + if (resp == 407) { + auth = "Proxy-Authenticate"; + auth2 = "Proxy-Authorization"; + } else { + auth = "WWW-Authenticate"; + auth2 = "Authorization"; + } + if ((p->authtries == MAX_AUTHTRIES) || do_proxy_auth(p, req, auth, auth2, sipmethod, 0)) { + ast_log(LOG_NOTICE, "Failed to authenticate on %s to '%s'\n", msg, get_header(&p->initreq, "From")); + ast_set_flag(p, SIP_NEEDDESTROY); + } } else { ast_log(LOG_WARNING, "Got authentication request (401) on unknown %s to '%s'\n", sip_methods[sipmethod].text, get_header(req, "To")); ast_set_flag(p, SIP_NEEDDESTROY);