Module: sip-router
Branch: master
Commit: 462a7b4c00e5ea544472e3f1f89a844c0158adb5
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=462a7b4c00e5ea544472e3f1f89a844c0158adb5

Author: Peter Dunkley <[email protected]>
Committer: Peter Dunkley <[email protected]>
Date:   Fri Jun  1 11:37:21 2012 +0100

modules_k/permissions: allow_trusted() doesn't work for HTTP requests

- This is because HTTP requests don't have From: headers.
- Fixed by only checking From-URIs for SIP requests.

---

 modules_k/permissions/hash.c    |   19 +++++++++++--------
 modules_k/permissions/trusted.c |   18 ++++++++++--------
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/modules_k/permissions/hash.c b/modules_k/permissions/hash.c
index 467259b..72ebc41 100644
--- a/modules_k/permissions/hash.c
+++ b/modules_k/permissions/hash.c
@@ -218,21 +218,24 @@ int match_hash_table(struct trusted_list** table, struct 
sip_msg* msg,
        src_ip.s = src_ip_c_str;
        src_ip.len = strlen(src_ip.s);
 
-       if (parse_from_header(msg) < 0) return -1;
-       uri = get_from(msg)->uri;
-       if (uri.len > MAX_URI_SIZE) {
-               LM_ERR("from URI too large\n");
-               return -1;
+       if (IS_SIP(msg))
+       {
+               if (parse_from_header(msg) < 0) return -1;
+               uri = get_from(msg)->uri;
+               if (uri.len > MAX_URI_SIZE) {
+                       LM_ERR("from URI too large\n");
+                       return -1;
+               }
+               memcpy(uri_string, uri.s, uri.len);
+               uri_string[uri.len] = (char)0;
        }
-       memcpy(uri_string, uri.s, uri.len);
-       uri_string[uri.len] = (char)0;
 
        for (np = table[perm_hash(src_ip)]; np != NULL; np = np->next) {
            if ((np->src_ip.len == src_ip.len) && 
                (strncmp(np->src_ip.s, src_ip.s, src_ip.len) == 0) &&
                ((np->proto == PROTO_NONE) || (proto == PROTO_NONE) ||
                 (np->proto == proto))) {
-               if (np->pattern) {
+               if (np->pattern && IS_SIP(msg)) {
                    if (regcomp(&preg, np->pattern, REG_NOSUB)) {
                        LM_ERR("invalid regular expression\n");
                        continue;
diff --git a/modules_k/permissions/trusted.c b/modules_k/permissions/trusted.c
index 4e7953c..96c03e7 100644
--- a/modules_k/permissions/trusted.c
+++ b/modules_k/permissions/trusted.c
@@ -344,14 +344,16 @@ static int match_res(struct sip_msg* msg, int proto, 
db1_res_t* _r)
        int_str tag_avp, avp_val;
        int count = 0;
 
-       if (parse_from_header(msg) < 0) return -1;
-       uri = get_from(msg)->uri;
-       if (uri.len > MAX_URI_SIZE) {
-               LM_ERR("message has From URI too large\n");
-               return -1;
+       if (IS_SIP(msg)) {
+               if (parse_from_header(msg) < 0) return -1;
+               uri = get_from(msg)->uri;
+               if (uri.len > MAX_URI_SIZE) {
+                       LM_ERR("message has From URI too large\n");
+                       return -1;
+               }
+               memcpy(uri_string, uri.s, uri.len);
+               uri_string[uri.len] = (char)0;
        }
-       memcpy(uri_string, uri.s, uri.len);
-       uri_string[uri.len] = (char)0;
        get_tag_avp(&tag_avp, &tag_avp_type);
 
        row = RES_ROWS(_r);
@@ -366,7 +368,7 @@ static int match_res(struct sip_msg* msg, int proto, 
db1_res_t* _r)
                    (VAL_NULL(val + 2) ||
                      ((VAL_TYPE(val + 2) == DB1_STRING) && !VAL_NULL(val + 
2))))
                {
-                       if (!VAL_NULL(val + 1)) {
+                       if (!VAL_NULL(val + 1) && IS_SIP(msg)) {
                                if (regcomp(&preg, (char *)VAL_STRING(val + 1), 
REG_NOSUB)) {
                                        LM_ERR("invalid regular expression\n");
                                        continue;


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to