[sr-dev] git:oej/permissionsrpc: permissions: Add rpc testUri funcion
Olle E. Johansson
oej at edvina.net
Sun Dec 23 08:47:13 CET 2012
Module: sip-router
Branch: oej/permissionsrpc
Commit: 806a3375debbd2f04578c71d38c39dcc66df32e3
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=806a3375debbd2f04578c71d38c39dcc66df32e3
Author: Olle E. Johansson <oej at edvina.net>
Committer: Olle E. Johansson <oej at edvina.net>
Date: Sun Dec 23 08:32:00 2012 +0100
permissions: Add rpc testUri funcion
...the problem is that it doesn't work. rpc->scan doesn't properly
set the length of the string...
---
modules_k/permissions/mi.c | 56 ++++++++++++++++++++++++++++++++++-
modules_k/permissions/mi.h | 1 +
modules_k/permissions/permissions.c | 8 ++++-
3 files changed, 63 insertions(+), 2 deletions(-)
diff --git a/modules_k/permissions/mi.c b/modules_k/permissions/mi.c
index eed980b..c86388e 100644
--- a/modules_k/permissions/mi.c
+++ b/modules_k/permissions/mi.c
@@ -198,7 +198,7 @@ void rpc_subnet_dump(rpc_t* rpc, void* c) {
#define MAX_FILE_LEN 128
-/*
+/*! \brief
* MI function to make allow_uri query.
*/
struct mi_root* mi_allow_uri(struct mi_root *cmd, void *param)
@@ -249,3 +249,57 @@ struct mi_root* mi_allow_uri(struct mi_root *cmd, void *param)
return init_mi_tree(403, MI_SSTR("Forbidden"));
}
}
+
+/*! \brief
+ * RPC function to make allow_uri query.
+ */
+void rpc_test_uri(rpc_t* rpc, void* c)
+{
+ str *basenamep, *urip, *contactp;
+ char basename[MAX_FILE_LEN + 1];
+ char uri[MAX_URI_SIZE + 1], contact[MAX_URI_SIZE + 1];
+ unsigned int allow_suffix_len;
+ int i;
+
+ if (rpc->scan(c, ".S", &basenamep) != 1) {
+ rpc->fault(c, 500, "Not enough parameters (basename, URI and contact)");
+ return;
+ }
+ //LM_DBG("Basename %s length %d \n", basenamep, basenamep->len);
+ if (rpc->scan(c, ".S", &urip) != 1) {
+ rpc->fault(c, 500, "Not enough parameters (basename, URI and contact)");
+ return;
+ }
+ //LM_DBG("URI %s length %d \n", urip, urip->len);
+ if (rpc->scan(c, ".S", &contactp) != 1) {
+ rpc->fault(c, 500, "Not enough parameters (basename, URI and contact)");
+ return;
+ }
+ //LM_DBG("Contact %s length %d size %d\n", contactp, contactp->len, sizeof(contactp->s) - 1);
+
+ /* For some reason, rtp->scan doesn't set the length properly */
+ if (contactp->len > MAX_URI_SIZE) {
+ rpc->fault(c, 500, "Contact is too long");
+ return;
+ }
+ allow_suffix_len = strlen(allow_suffix);
+ if (basenamep->len + allow_suffix_len + 1 > MAX_FILE_LEN) {
+ rpc->fault(c, 500, "Basename is too long");
+ return;
+ }
+
+ memcpy(basename, basenamep->s, basenamep->len);
+ memcpy(basename + basenamep->len, allow_suffix, allow_suffix_len);
+ basename[basenamep->len + allow_suffix_len] = 0;
+ memcpy(uri, urip->s, urip->len);
+ memcpy(contact, contactp->s, contactp->len);
+ contact[contactp->len] = 0;
+ uri[urip->len] = 0;
+
+ if (allow_test(basename, uri, contact) == 1) {
+ rpc->printf(c, "Allowed");
+ return;
+ }
+ rpc->printf(c, "Denied");
+ return;
+}
diff --git a/modules_k/permissions/mi.h b/modules_k/permissions/mi.h
index c490b0a..09f3897 100644
--- a/modules_k/permissions/mi.h
+++ b/modules_k/permissions/mi.h
@@ -55,5 +55,6 @@ struct mi_root* mi_subnet_dump(struct mi_root *cmd_tree, void *param);
void rpc_subnet_dump(rpc_t* rpc, void* c);
struct mi_root* mi_allow_uri(struct mi_root *cmd, void *param);
+void rpc_test_uri(rpc_t* rpc, void* c);
#endif
diff --git a/modules_k/permissions/permissions.c b/modules_k/permissions/permissions.c
index 37d7b17..2b7a279 100644
--- a/modules_k/permissions/permissions.c
+++ b/modules_k/permissions/permissions.c
@@ -455,7 +455,7 @@ static int load_fixup(void** param, int param_no)
if (table[rules_num].rules) {
LM_DBG("file (%s) parsed\n", pathname);
} else {
- LM_INFO("file (%s) not found => empty rule set\n", pathname);
+ LM_INFO("file (%s) not parsed properly => empty rule set\n", pathname);
}
*param = (void*)(long)rules_num;
if (param_no == 2) rules_num++;
@@ -1009,12 +1009,18 @@ static const char* rpc_subnet_dump_doc[2] = {
0
};
+static const char* rpc_test_uri_doc[2] = {
+ "Tests if (URI, Contact) pair is allowed according to allow/deny files",
+ 0
+};
+
rpc_export_t permissions_rpc[] = {
{"permissions.trustedReload", rpc_trusted_reload, rpc_trusted_reload_doc, 0},
{"permissions.addressReload", rpc_address_reload, rpc_address_reload_doc, 0},
{"permissions.trustedDump", rpc_trusted_dump, rpc_trusted_dump_doc, 0},
{"permissions.addressDump", rpc_address_dump, rpc_address_dump_doc, 0},
{"permissions.subnetDump", rpc_subnet_dump, rpc_subnet_dump_doc, 0},
+ {"permissions.testUri", rpc_test_uri, rpc_test_uri_doc, 0},
{0, 0, 0, 0}
};
More information about the sr-dev
mailing list