Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions doc/manpage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
<arg choice="opt"><option>--bridge_symmetric</option></arg>

<arg choice="opt"><option>--no_resolve</option></arg>
<arg choice="opt"><option>--record_fname_encode</option></arg>
</cmdsynopsis>

<cmdsynopsis>
Expand Down Expand Up @@ -819,6 +820,22 @@
names.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--record_fname_encode</option></term>

<listitem>
<para>When the recording file name is built from the Call-ID and
from-tag (the <command>R</command> command and the
<option>-a</option> option), percent-encode the <quote>/</quote>
and <quote>%</quote> characters as <quote>%2F</quote> and
<quote>%25</quote> instead of refusing to record calls whose
Call-ID or from-tag contains <quote>/</quote>, which is a legal
character in SIP. The original value can be recovered by decoding
the <quote>%XX</quote> sequences. File names given explicitly with
the <command>C</command> command are not affected.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

Expand Down
24 changes: 23 additions & 1 deletion rtpproxy.8
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
rtpproxy \- RTP (Real\-time Transport Protocol) Proxy Server
.SH "SYNOPSIS"
.HP \w'\fBrtpproxy\fR\ 'u
\fBrtpproxy\fR [\fB\-?\fR] [\fB\-2\fR] [\fB\-f\fR] [\fB\-v\fR] [\fB\-V\fR] [\fB\-R\fR] [\fB\-l\fR\ \fIaddr1\fR\fI[/addr2]\fR...] [\fB\-l\fR\ \fI[label@]\fR\fIaddress\fR\fI[=advertized_address]\fR...] [\fB\-6\fR\ \fIaddr1\fR\fI[/addr2]\fR...] [\fB\-6\fR\ \fI[label@]\fR\fIaddress\fR\fI[=advertized_address]\fR...] [\fB\-s\fR\ \fIctrl_socket\fR] [\fB\-t\fR\ \fItos\fR] [\fB\-p\fR\ \fIpidfile\fR] [\fB\-T\fR\ \fImax_ttl\fR] [\fB\-\-maxpps\fR\ \fIpps\fR\fI[,rtcp_pps]\fR] [\fB\-\-maxpsize\fR\ \fIsize\fR\fI[,rtcp_size]\fR] [\fB\-r\fR\ \fIrdir\fR\ [\fB\-S\fR\ \fIsdir\fR]] [\fB\-L\fR\ \fInofile_limit\fR] [\fB\-A\fR\ \fIadvaddr1\fR\fI[/advaddr2]\fR] [\fB\-m\fR\ \fImin_port\fR] [\fB\-M\fR\ \fImax_port\fR] [\fB\-u\fR\ \fIuname\fR\fI[:gname]\fR] [\fB\-w\fR\ \fIsock_mode\fR] [\fB\-F\fR] [\fB\-i\fR] [\fB\-n\fR\ \fItimeout_socket\fR] [\fB\-P\fR] [\fB\-a\fR] [\fB\-d\fR\ \fIlog_level\fR\fI[:log_facility]\fR] [\fB\-W\fR\ \fIsetup_ttl\fR] [\fB\-\-force_asymmetric\fR] [\fB\-b\fR] [\fB\-c\fR\ \fIfifo|rr\fR] [\fB\-\-nice\fR\ \fIlevel\fR] [\fB\-D\fR] [\fB\-\-no_redirect\fR] [\fB\-\-config\fR\ \fIconfig_file\fR] [\fB\-\-dso\fR\ \fImodule\fR...] [\fB\-\-bridge_symmetric\fR] [\fB\-\-no_resolve\fR]
\fBrtpproxy\fR [\fB\-?\fR] [\fB\-2\fR] [\fB\-f\fR] [\fB\-v\fR] [\fB\-V\fR] [\fB\-R\fR] [\fB\-l\fR\ \fIaddr1\fR\fI[/addr2]\fR...] [\fB\-l\fR\ \fI[label@]\fR\fIaddress\fR\fI[=advertized_address]\fR...] [\fB\-6\fR\ \fIaddr1\fR\fI[/addr2]\fR...] [\fB\-6\fR\ \fI[label@]\fR\fIaddress\fR\fI[=advertized_address]\fR...] [\fB\-s\fR\ \fIctrl_socket\fR] [\fB\-t\fR\ \fItos\fR] [\fB\-p\fR\ \fIpidfile\fR] [\fB\-T\fR\ \fImax_ttl\fR] [\fB\-\-maxpps\fR\ \fIpps\fR\fI[,rtcp_pps]\fR] [\fB\-\-maxpsize\fR\ \fIsize\fR\fI[,rtcp_size]\fR] [\fB\-r\fR\ \fIrdir\fR\ [\fB\-S\fR\ \fIsdir\fR]] [\fB\-L\fR\ \fInofile_limit\fR] [\fB\-A\fR\ \fIadvaddr1\fR\fI[/advaddr2]\fR] [\fB\-m\fR\ \fImin_port\fR] [\fB\-M\fR\ \fImax_port\fR] [\fB\-u\fR\ \fIuname\fR\fI[:gname]\fR] [\fB\-w\fR\ \fIsock_mode\fR] [\fB\-F\fR] [\fB\-i\fR] [\fB\-n\fR\ \fItimeout_socket\fR] [\fB\-P\fR] [\fB\-a\fR] [\fB\-d\fR\ \fIlog_level\fR\fI[:log_facility]\fR] [\fB\-W\fR\ \fIsetup_ttl\fR] [\fB\-\-force_asymmetric\fR] [\fB\-b\fR] [\fB\-c\fR\ \fIfifo|rr\fR] [\fB\-\-nice\fR\ \fIlevel\fR] [\fB\-D\fR] [\fB\-\-no_redirect\fR] [\fB\-\-config\fR\ \fIconfig_file\fR] [\fB\-\-dso\fR\ \fImodule\fR...] [\fB\-\-bridge_symmetric\fR] [\fB\-\-no_resolve\fR] [\fB\-\-record_fname_encode\fR]
.HP \w'\fBrtpproxy\fR\ 'u
\fBrtpproxy\fR \fB\-C\fR
.SH "DESCRIPTION"
Expand Down Expand Up @@ -502,6 +502,28 @@ In the bridging mode, do not treat all sessions as asymmetric, which is the defa
.RS 4
Only accept numeric IP addresses, in the command line arguments and in the control commands, instead of resolving host names\&.
.RE
.PP
\fB\-\-record_fname_encode\fR
.RS 4
When the recording file name is built from the Call\-ID and from\-tag (the
\fBR\fR
command and the
\fB\-a\fR
option), percent\-encode the
"/"
and
"%"
characters as
"%2F"
and
"%25"
instead of refusing to record calls whose Call\-ID or from\-tag contains
"/", which is a legal character in SIP\&. The original value can be recovered by decoding the
"%XX"
sequences\&. File names given explicitly with the
\fBC\fR
command are not affected\&.
.RE
.SH "PRINCIPLES OF OPERATION"
.PP
When the SIP controller receives an INVITE request, it extracts the Call\-ID and from_tag from INVITE\&. The call controller communicates it with the rtpproxy via Unix domain socket or a UDP socket\&. rtpproxy looks for an existing session with the given Call\-ID and from_tag\&.
Expand Down
7 changes: 7 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ usage(void)
"[-n timeout_socket]\n\t [-d log_level[:log_facility]] [-p pid_file]\n"
"\t [-c fifo|rr] [-A addr1[/addr2] [-W setup_ttl]\n"
"\t [--maxpps pps[,rtcp_pps]] [--maxpsize size[,rtcp_size]]\n"
"\t [--record_fname_encode]\n"
"\trtpproxy -V\n");
}

Expand Down Expand Up @@ -266,6 +267,7 @@ ehandler(void)
#define LOPT_NO_REDIR 263
#define LOPT_MAXPPS 264
#define LOPT_MAXPSIZE 265
#define LOPT_RFNAME_ENC 266

const static struct option longopts[] = {
{ "dso", required_argument, NULL, LOPT_DSO },
Expand All @@ -278,6 +280,7 @@ const static struct option longopts[] = {
{ "no_redirect", no_argument, NULL, LOPT_NO_REDIR },
{ "maxpps", required_argument, NULL, LOPT_MAXPPS },
{ "maxpsize", required_argument, NULL, LOPT_MAXPSIZE },
{ "record_fname_encode", no_argument, NULL, LOPT_RFNAME_ENC },
{ NULL, 0, NULL, 0 }
};

Expand Down Expand Up @@ -519,6 +522,10 @@ init_config(struct rtpp_cfg *cfsp, int argc, const char * const *argv)
}
break;

case LOPT_RFNAME_ENC:
cfsp->record_fname_enc = 1;
break;

case 'c':
if (strcmp(optarg, "fifo") == 0) {
cfsp->sched_policy = SCHED_FIFO;
Expand Down
2 changes: 2 additions & 0 deletions src/rtpp_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ struct rtpp_cfg {
const char *sdir;
int record_pcap; /* Record in the PCAP format? */
int record_all; /* Record everything */
int record_fname_enc; /* Percent-encode '/' and '%' in file names
built from Call-ID and from-tag */

int rrtcp; /* Whether or not to relay RTCP? */
struct rtpp_log *glog;
Expand Down
68 changes: 57 additions & 11 deletions src/rtpp_record.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,44 @@ ropen_remote_ctor_pa(const struct rtpp_cfg *cfg, struct rtpp_record_channel *rrc
return (0);
}

/*
* Copy slen bytes of src (a Call-ID or a from-tag, which are not
* NUL-terminated) into dst as a NUL-terminated file name component. With
* encode set, '/' and '%' are percent-encoded as "%2F" and "%25", so the
* result never contains '/' and the original value can be recovered by
* decoding "%XX". Returns the length of the result, or -1 if it does not
* fit into dlen bytes.
*/
static int
rtpp_record_fname_cpy(char *dst, size_t dlen, const char *src, size_t slen,
int encode)
{
size_t i, j;
const char *esc;

if (dlen == 0)
return (-1);
for (i = j = 0; i < slen; i++) {
esc = NULL;
if (encode && src[i] == '/')
esc = "%2F";
else if (encode && src[i] == '%')
esc = "%25";
if (esc != NULL) {
if (dlen - j < 4)
return (-1);
memcpy(dst + j, esc, 3);
j += 3;
} else {
if (dlen - j < 2)
return (-1);
dst[j++] = src[i];
}
}
dst[j] = '\0';
return ((int)j);
}

struct rtpp_record *
rtpp_record_ctor(const struct rtpp_cfg *cfsp, const struct remote_copy_args *rap,
struct rtpp_session *sp, const char *rname, int orig, int record_type)
Expand All @@ -173,6 +211,7 @@ rtpp_record_ctor(const struct rtpp_cfg *cfsp, const struct remote_copy_args *rap
int rval, remote;
size_t len;
pcap_hdr_t pcap_hdr;
char cid[PATH_MAX + 1], tag[PATH_MAX + 1];

remote = (rname != NULL && strncmp("udp:", rname, 4) == 0) ? 1 : 0;

Expand Down Expand Up @@ -211,11 +250,20 @@ rtpp_record_ctor(const struct rtpp_cfg *cfsp, const struct remote_copy_args *rap
goto e2;
}

if (rname == NULL && (memchr(sp->call_id->s, '/', sp->call_id->len) != NULL ||
memchr(sp->from_tag_nmn->s, '/', sp->from_tag_nmn->len) != NULL)) {
RTPP_LOG(sp->log, RTPP_LOG_ERR, "call-id or from-tag contains '/', "
"refusing to use it in the recording file name");
goto e2;
if (rname == NULL) {
if (rtpp_record_fname_cpy(cid, sizeof(cid), sp->call_id->s,
sp->call_id->len, cfsp->record_fname_enc) < 0 ||
rtpp_record_fname_cpy(tag, sizeof(tag), sp->from_tag_nmn->s,
sp->from_tag_nmn->len, cfsp->record_fname_enc) < 0) {
RTPP_LOG(sp->log, RTPP_LOG_ERR, "recording file name is too long");
goto e2;
}
if (strchr(cid, '/') != NULL || strchr(tag, '/') != NULL) {
RTPP_LOG(sp->log, RTPP_LOG_ERR, "call-id or from-tag contains '/', "
"refusing to use it in the recording file name (see "
"--record_fname_encode)");
goto e2;
}
}

if (cfsp->record_pcap != 0) {
Expand All @@ -240,9 +288,8 @@ rtpp_record_ctor(const struct rtpp_cfg *cfsp, const struct remote_copy_args *rap
sdir = cfsp->sdir;
rrc->needspool = 1;
if (rname == NULL) {
len = snprintf(rrc->rpath, sizeof(rrc->rpath), "%s/%.*s=%.*s%s%s",
cfsp->rdir, (int)sp->call_id->len, sp->call_id->s,
(int)sp->from_tag_nmn->len, sp->from_tag_nmn->s, suffix1, suffix2);
len = snprintf(rrc->rpath, sizeof(rrc->rpath), "%s/%s=%s%s%s",
cfsp->rdir, cid, tag, suffix1, suffix2);
} else {
len = snprintf(rrc->rpath, sizeof(rrc->rpath), "%s/%s%s",
cfsp->rdir, rname, suffix2);
Expand All @@ -253,9 +300,8 @@ rtpp_record_ctor(const struct rtpp_cfg *cfsp, const struct remote_copy_args *rap
}
}
if (rname == NULL) {
len = snprintf(rrc->spath, sizeof(rrc->spath), "%s/%.*s=%.*s%s%s",
sdir, (int)sp->call_id->len, sp->call_id->s,
(int)sp->from_tag_nmn->len, sp->from_tag_nmn->s, suffix1, suffix2);
len = snprintf(rrc->spath, sizeof(rrc->spath), "%s/%s=%s%s%s",
sdir, cid, tag, suffix1, suffix2);
} else {
len = snprintf(rrc->spath, sizeof(rrc->spath), "%s/%s%s", sdir, rname,
suffix2);
Expand Down
2 changes: 1 addition & 1 deletion tests/recording/basic
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ run_recording() {
report_rc ${RPTL_RC} "running basic.${stest}.rptl RPTL script"
}

SUB_TESTS="${SUB_TESTS:-"files singlefile singlefile_c stopall files_stophalf singlefile_stophalf remote remote_p badpath"}"
SUB_TESTS="${SUB_TESTS:-"files singlefile singlefile_c stopall files_stophalf singlefile_stophalf remote remote_p badpath badpath_enc"}"

for stest in ${SUB_TESTS}
do
Expand Down
51 changes: 51 additions & 0 deletions tests/recording/basic.badpath_enc.rptl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Same Call-IDs as in basic.badpath, with --record_fname_encode: '/' and
# '%' in the Call-ID or from-tag are written as "%2F" and "%25", so the
# recording (R, Rs) is created inside of the recording directory under the
# encoded name instead of being refused. Names that do not fit into
# PATH_MAX are still refused.

.eval: 0 -> RES_OK
.eval: E50 -> RES_E50
.eval: recording.%%SUBTEST%% -> WORK_BASE
.eval: ../%%WORK_BASE%%.rec. -> CALLID
.eval: ../%%WORK_BASE%%.recs. -> CALLID_S
.eval: %%WORK_BASE%%.pct%41 -> CALLID_P
.eval: %%RECORD_SPL_DIR%%/%%CALLID%%=from_tag_1 -> REC_BASE
.eval: %%RECORD_SPL_DIR%%/%%CALLID_S%%=from_tag_1 -> REC_BASE_S
# Same names, encoded ('?' stands for the '%' of the escape sequences).
.eval: %%RECORD_SPL_DIR%%/..?2F%%WORK_BASE%%.rec.=from_tag_1 -> ENC_BASE
.eval: %%RECORD_SPL_DIR%%/..?2F%%WORK_BASE%%.recs.=from_tag_1 -> ENC_BASE_S
.eval: %%RECORD_SPL_DIR%%/%%WORK_BASE%%.pct?2541=from_tag_1 -> ENC_BASE_P

.exec: mkdir -p %%RECORD_SPL_DIR%%
.exec: rm -f %%REC_BASE%%.* %%REC_BASE_S%%* %%ENC_BASE%%.* %%ENC_BASE_S%%* %%ENC_BASE_P%%.*

# Longer than PATH_MAX on any supported platform, yet short enough for
# the commands carrying it to fit into the RTPP_CMD_BUFLEN.
.exec: printf '%4200s' '' | tr ' ' x -> LONG_NAME
.eval: %%WORK_BASE%%.long.%%LONG_NAME%% -> CALLID_LONG

.eval: -d dbug -T60 -W60 -P -r %%RECORD_SPL_DIR%% --record_fname_encode -> RTPPROXY_ARGS
socket rtpp: stdio: %%RTPPROXY_ARGS%% -> %%WORK_BASE%%.rout

rtpp: U %%CALLID%% 127.0.0.1 12345 from_tag_1 -> validate_port(_)
rtpp: L %%CALLID%% 127.0.0.1 54321 from_tag_1 to_tag_1 -> validate_port(_)
rtpp: R %%CALLID%% to_tag_1 from_tag_1 -> str_compare(RES_OK)

rtpp: U %%CALLID_S%% 127.0.0.1 12345 from_tag_1 -> validate_port(_)
rtpp: L %%CALLID_S%% 127.0.0.1 54321 from_tag_1 to_tag_1 -> validate_port(_)
rtpp: Rs %%CALLID_S%% to_tag_1 from_tag_1 -> str_compare(RES_OK)

rtpp: U %%CALLID_P%% 127.0.0.1 12345 from_tag_1 -> validate_port(_)
rtpp: L %%CALLID_P%% 127.0.0.1 54321 from_tag_1 to_tag_1 -> validate_port(_)
rtpp: R %%CALLID_P%% to_tag_1 from_tag_1 -> str_compare(RES_OK)

rtpp: U %%CALLID_LONG%% 127.0.0.1 12345 from_tag_1 -> validate_port(_)
rtpp: L %%CALLID_LONG%% 127.0.0.1 54321 from_tag_1 to_tag_1 -> validate_port(_)
rtpp: R %%CALLID_LONG%% to_tag_1 from_tag_1 -> str_compare(RES_E50)
rtpp: Rs %%CALLID_LONG%% to_tag_1 from_tag_1 -> str_compare(RES_E50)

.close: rtpp
.exec: for f in %%REC_BASE%%.* %%REC_BASE_S%%*; do test ! -e "$f" || exit 1; done
.exec: ls %%ENC_BASE%%.* %%ENC_BASE_S%%* %%ENC_BASE_P%%.* > /dev/null
.exec: rm -f %%ENC_BASE%%.* %%ENC_BASE_S%%* %%ENC_BASE_P%%.*