Module: sip-router Branch: master Commit: 18e67ca2d125f87b85c00eb74b057b9c010a8a26 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=18e67ca2...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Thu Nov 25 22:25:01 2010 +0100
permissions(k): changed params from PVAR to SPVE type
- type of fixup params for allow_trusted() updated from PVAR to SPVE - PVAR can be non-zero terminated string - SPVE accepts also static string or combination of PVs - adapted patch submitted by Alex Hermann for crash related to static protocol value, FS#102
---
modules_k/permissions/permissions.c | 4 +- modules_k/permissions/trusted.c | 77 +++++++++++++++++------------------ 2 files changed, 39 insertions(+), 42 deletions(-)
diff --git a/modules_k/permissions/permissions.c b/modules_k/permissions/permissions.c index 4d41817..5beb016 100644 --- a/modules_k/permissions/permissions.c +++ b/modules_k/permissions/permissions.c @@ -129,8 +129,8 @@ static cmd_export_t cmds[] = { REQUEST_ROUTE | FAILURE_ROUTE}, {"allow_trusted", (cmd_function)allow_trusted_0, 0, 0, 0, REQUEST_ROUTE | FAILURE_ROUTE}, - {"allow_trusted", (cmd_function)allow_trusted_2, 2, fixup_pvar_pvar, - fixup_free_pvar_pvar, REQUEST_ROUTE | FAILURE_ROUTE}, + {"allow_trusted", (cmd_function)allow_trusted_2, 2, fixup_spve_spve, + fixup_free_spve_spve, REQUEST_ROUTE | FAILURE_ROUTE}, {"allow_uri", (cmd_function)allow_uri, 2, double_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE|LOCAL_ROUTE}, {"allow_address", (cmd_function)allow_address, 3, fixup_igp_pvar_pvar, diff --git a/modules_k/permissions/trusted.c b/modules_k/permissions/trusted.c index 77545ad..33cae33 100644 --- a/modules_k/permissions/trusted.c +++ b/modules_k/permissions/trusted.c @@ -35,6 +35,7 @@ #include "../../config.h" #include "../../lib/srdb1/db.h" #include "../../ip_addr.h" +#include "../../mod_fix.h" #include "../../mem/shm_mem.h" #include "../../parser/msg_parser.h" #include "../../parser/parse_from.h" @@ -462,51 +463,47 @@ int allow_trusted_0(struct sip_msg* _msg, char* str1, char* str2) */ int allow_trusted_2(struct sip_msg* _msg, char* _src_ip_sp, char* _proto_sp) { - pv_spec_t *src_ip_sp, *proto_sp; - pv_value_t pv_val; - char *src_ip, *proto; + str src_ip, proto; int proto_int;
- src_ip_sp = (pv_spec_t *)_src_ip_sp; - proto_sp = (pv_spec_t *)_proto_sp; - - if (src_ip_sp && (pv_get_spec_value(_msg, src_ip_sp, &pv_val) == 0)) { - if (pv_val.flags & PV_VAL_STR) { - src_ip = pv_val.rs.s; - } else { - LM_ERR("src_ip pvar value is not string\n"); - return -1; - } - } else { - LM_ERR("src_ip pvar does not exist or has no value\n"); - return -1; + if (_src_ip_sp==NULL + || (fixup_get_svalue(_msg, (gparam_p)_src_ip_sp, &src_ip) != 0)) { + LM_ERR("src_ip param does not exist or has no value\n"); + return -1; }
- if (proto_sp && (pv_get_spec_value(_msg, proto_sp, &pv_val) == 0)) { - if (pv_val.flags & PV_VAL_STR) { - strlower(&(pv_val.rs)); - proto = pv_val.rs.s; - } else { - LM_ERR("proto pvar value is not string\n"); - return -1; - } - } else { - LM_ERR("proto pvar does not exist or has no value\n"); - return -1; + if (_proto_sp==NULL + || (fixup_get_svalue(_msg, (gparam_p)_proto_sp, &proto) != 0)) { + LM_ERR("proto param does not exist or has no value\n"); + return -1; } - - if (strcmp(proto, "udp") == 0) { - proto_int = PROTO_UDP; - } else if (strcmp(proto, "tcp") == 0) { - proto_int = PROTO_TCP; - } else if (strcmp(proto, "tls") == 0) { - proto_int = PROTO_TLS; - } else if (strcmp(proto, "sctp") == 0) { - proto_int = PROTO_SCTP; - } else { - LM_ERR("unknown protocol %s\n", proto); - return -1; + if(proto.len!=3 && proto.len!=4) + goto error; + + switch(proto.s[0]) { + case 'u': case 'U': + if (proto.len==3 && strncasecmp(proto.s, "udp", 3) == 0) { + proto_int = PROTO_UDP; + } else goto error; + break; + case 't': case 'T': + if (proto.len==3 && strncasecmp(proto.s, "tcp", 3) == 0) { + proto_int = PROTO_TCP; + } else if (proto.len==3 && strncasecmp(proto.s, "tls", 3) == 0) { + proto_int = PROTO_TLS; + } else goto error; + break; + case 's': case 'S': + if (proto.len==4 && strncasecmp(proto.s, "sctp", 4) == 0) { + proto_int = PROTO_SCTP; + } else goto error; + break; + default: + goto error; }
- return allow_trusted(_msg, src_ip, proto_int); + return allow_trusted(_msg, src_ip.s, proto_int); +error: + LM_ERR("unknown protocol %.*s\n", proto.len, proto.s); + return -1; }
Daniel-Constantin Mierla writes:
- type of fixup params for allow_trusted() updated from PVAR to SPVE
- PVAR can be non-zero terminated string
- SPVE accepts also static string or combination of PVs
would it be better to allow a real expression as a parameter than a string that embeds variables?
-- juha
On 11/26/10 11:27 AM, Juha Heinanen wrote:
Daniel-Constantin Mierla writes:
- type of fixup params for allow_trusted() updated from PVAR to SPVE
- PVAR can be non-zero terminated string
- SPVE accepts also static string or combination of PVs
would it be better to allow a real expression as a parameter than a string that embeds variables?
patch was done to overcome the issues reported in the bug tracker. The problem was that a pseduo-variable value is str, not always null terminated, which potentially could bring problems. Few other functions need to be updated as well.
The new planned module function interface is allowing also expressions as parameters, when that will be ready, can be practically used.
On another hand, current format is more compact than an expression -- a mater of admin choice of course.
Cheers, Daniel