From 91fd188a92e55d5463b6e7ece3a9910fc3c5d7f5 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sun, 21 Mar 2021 13:33:01 +0100 Subject: Fixed incoming (remote-to-local) registration procedure --- src/sip/main.c | 7 ++++++- src/sip/sip.c | 32 +++++++++++++++++++++++--------- src/sip/sip.h | 3 ++- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/sip/main.c b/src/sip/main.c index 8b470be..17ae8a9 100644 --- a/src/sip/main.c +++ b/src/sip/main.c @@ -329,11 +329,16 @@ int main(int argc, char *argv[]) goto error; } - if (!remote_peer) { + if (!remote_peer && !local_register) { PDEBUG(DSIP, DEBUG_ERROR, "You must specify remote SIP peer!\n"); goto error; } + if (!auth_user && local_auth) { + PDEBUG(DSIP, DEBUG_ERROR, "You must specify authentication parameters!\n"); + goto error; + } + if (!cc_argc || !!strncasecmp(cc_argv[0], "help", 4)) { sip_ep = sip_endpoint_create(user_agent, send_no_ringing_after_progress, receive_no_ringing_after_progress, name, local_user, local_peer, remote_user, remote_peer, asserted_id, local_register, remote_register, register_user, register_peer, local_auth, remote_auth, auth_user, auth_password, auth_realm, public_ip, stun_server, register_interval, options_interval, stun_interval, expires); if (!sip_ep) { diff --git a/src/sip/sip.c b/src/sip/sip.c index bda9261..2ced743 100644 --- a/src/sip/sip.c +++ b/src/sip/sip.c @@ -456,7 +456,7 @@ static void setup_req(call_t *call, osmo_cc_msg_t *msg) const char *sdp = sdp; int rc; - if (!call->sip_ep->remote_peer[0]) { + if (!call->sip_ep->remote_peer || !call->sip_ep->remote_peer[0]) { PDEBUG(DSIP, DEBUG_NOTICE, "No remote peer set or no peer has registered to us.\n"); release_and_destroy(call, OSMO_CC_ISDN_CAUSE_DEST_OOO, 0, 0, 0, ""); return; @@ -862,16 +862,29 @@ static void ep_i_register(sip_endpoint_t *sip_ep, int status, nua_t *nua, nua_ha nua_save_event(nua, saved); nua_event_data_t const *data = nua_event_data(saved); sip_authorization_t const *authorization; - char contact[255] = ""; + char contact_user[256] = "", contact_peer[256] = ""; const char *auth_text = NULL; char auth_str[256] = ""; + if (!sip->sip_contact || !sip->sip_contact->m_url || !sip->sip_contact->m_url->url_host) { + PDEBUG(DSIP, DEBUG_NOTICE, "Not found, because we don't have a contact line"); + PDEBUG(DSIP, DEBUG_INFO, "Sending REGISTER response: %d %s (registration)\n", SIP_404_NOT_FOUND); + nua_respond(nh, SIP_403_FORBIDDEN, NUTAG_WITH_THIS_MSG(data->e_msg), TAG_END()); + nua_destroy_event(saved); + PDEBUG(DSIP, DEBUG_DEBUG, "destroying nua_handle %p (register)\n", nh); + nua_handle_destroy(nh); + sip_ep->register_handle = NULL; + return; + } + + if (sip->sip_contact->m_url->url_user) + strcpy(contact_user, sip->sip_contact->m_url->url_user); if (sip->sip_contact->m_url->url_host) { // FIXME: unstable/might not work with IPv6 - strcpy(contact, sip->sip_contact->m_url->url_host); + strcpy(contact_peer, sip->sip_contact->m_url->url_host); if (sip->sip_contact->m_url->url_port && sip->sip_contact->m_url->url_port[0]) { - strcat(contact, ":"); - strcat(contact, sip->sip_contact->m_url->url_port); + strcat(contact_peer, ":"); + strcat(contact_peer, sip->sip_contact->m_url->url_port); } } @@ -886,7 +899,7 @@ static void ep_i_register(sip_endpoint_t *sip_ep, int status, nua_t *nua, nua_ha return; } - PDEBUG(DSIP, DEBUG_DEBUG, " -> contact %s\n", contact); + PDEBUG(DSIP, DEBUG_DEBUG, " -> contact %s@%s\n", contact_user, contact_peer); if (sip_ep->authenticate_local && sip_ep->auth_realm[0]) { authorization = sip->sip_authorization; @@ -903,10 +916,11 @@ static void ep_i_register(sip_endpoint_t *sip_ep, int status, nua_t *nua, nua_ha PDEBUG(DSIP, DEBUG_DEBUG, " -> Authentication: %d %s\n", status, auth_text); if (status == 200) { - strncpy(sip_ep->remote_contact, contact, sizeof(sip_ep->remote_contact) - 1); - sip_ep->remote_peer = sip_ep->remote_contact; + strncpy(sip_ep->remote_contact_user, contact_user, sizeof(sip_ep->remote_contact_user) - 1); + strncpy(sip_ep->remote_contact_peer, contact_peer, sizeof(sip_ep->remote_contact_peer) - 1); + sip_ep->remote_user = sip_ep->remote_contact_user; + sip_ep->remote_peer = sip_ep->remote_contact_peer; sip_ep->register_nonce[0] = '\0'; - PDEBUG(DSIP, DEBUG_DEBUG, "remote contact '%s'\n", sip_ep->remote_peer); } PDEBUG(DSIP, DEBUG_INFO, "Sending REGISTER response: %d %s (registration)\n", status, auth_text); diff --git a/src/sip/sip.h b/src/sip/sip.h index 823b91e..04635bd 100644 --- a/src/sip/sip.h +++ b/src/sip/sip.h @@ -78,7 +78,8 @@ typedef struct sip_endpoint { int shutdown_complete; /* register process */ - char remote_contact[256]; + char remote_contact_user[256]; + char remote_contact_peer[256]; char register_nonce[64]; char invite_nonce[64]; enum reg_state register_state; -- cgit v1.2.3