From e3ed50d8dbb2befad3dbebddf4eef41eecdc6a4d Mon Sep 17 00:00:00 2001 From: Thomas Ries Date: Tue, 30 Mar 2004 19:45:01 +0000 Subject: [PATCH] - Again '*' Contact header in unREGISTER - new: tools/extract_sip.pl --- ChangeLog | 2 ++ src/register.c | 31 +++++++++++++++++++++++++------ src/security.c | 11 ----------- tools/extract_sip.pl | 26 ++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 17 deletions(-) create mode 100755 tools/extract_sip.pl diff --git a/ChangeLog b/ChangeLog index c678de3..5472b33 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 0.5.5 ===== + 30-Mar-2004: - Again '*' Contact header in unREGISTER + - new: tools/extract_sip.pl 26-Mar-2004: - SDP rewrite: properly handle 'c=' items in session *and* media part of SDP data. 22-Mar-2004: - deal with wildcard Contact header for unREGISTER diff --git a/src/register.c b/src/register.c index 12f47de..8682690 100644 --- a/src/register.c +++ b/src/register.c @@ -242,19 +242,38 @@ int register_client(osip_message_t *my_msg, int force_lcl_masq) { } url1_to=my_msg->to->url; - url1_contact=((osip_contact_t*)(my_msg->contacts->node->element))->url; - DEBUGC(DBCLASS_REG,"register: %s@%s expires=%i seconds", - (url1_contact->username) ? url1_contact->username : "*NULL*", - (url1_contact->host) ? url1_contact->host : "*NULL*", - expires); /* * REGISTER */ if (expires > 0) { - /* Update registration. There are two possibilities: + /* + * First make sure, we have a prober Contact header: + * - url + * - url -> hostname + * + * Libosip parses an: + * "Contact: *" + * the following way (Note: Display name!! and URL is NULL) + * (gdb) p *((osip_contact_t*)(sip->contacts->node->element)) + * $5 = {displayname = 0x8af8848 "*", url = 0x0, gen_params = 0x8af8838} + */ + url1_contact=((osip_contact_t*)(my_msg->contacts->node->element))->url; + if ((url1_contact == NULL) || (url1_contact->host == NULL)) { + /* Don't have reqiured Contact fields */ + ERROR("tried registration with empty Contact header"); + return STS_FAILURE; + } + + DEBUGC(DBCLASS_REG,"register: %s@%s expires=%i seconds", + (url1_contact->username) ? url1_contact->username : "*NULL*", + (url1_contact->host) ? url1_contact->host : "*NULL*", + expires); + + /* + * Update registration. There are two possibilities: * - already registered, then update the existing record * - not registered, then create a new record */ diff --git a/src/security.c b/src/security.c index 5993974..7dd47b1 100644 --- a/src/security.c +++ b/src/security.c @@ -239,17 +239,6 @@ RFC 3261 SIP: Session Initiation Protocol June 2002 return STS_FAILURE; } - /* - * check for existing Contact: header - * according to RFC3261 not mandatory, but siproxd relies on it - * on REGISTER... - */ - if (MSG_IS_REGISTER(sip) && ((sip->contacts==NULL)|| - (sip->contacts->node==NULL)||(sip->contacts->node->element==NULL)|| - ((osip_contact_t*)(sip->contacts->node->element))->url==NULL)) { - ERROR("security check failed: NULL Contact Header"); - return STS_FAILURE; - } /* TODO: still way to go here ... */ diff --git a/tools/extract_sip.pl b/tools/extract_sip.pl new file mode 100755 index 0000000..094ef8d --- /dev/null +++ b/tools/extract_sip.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl +# +# +# extract a buffer dump from siproxd's debug log and +# write the plain content into a file. This file then +# may be used to feed netcat for a replay.# +# +# $ netcat -u siphost 5060 < buffer.sip +# +# usage: +# reads from STDIN and writes to STDOUT +# +# $ cat bufferdump.log | extract_sip.pl > buffer.sip + +while (<>) { + # strip off CR/LF + chomp; + + # cut out the hex digits and store them into an array + my @hex=split(/ /, substr($_, 2, 47)); + + for (my $i=0; $i<16; $i++) { + # write HEX byte as character + print chr(hex($hex[$i])); + } +}