Module: sip-router
Branch: master
Commit: 1984f288bcc74a0287513ce69490a38cfe16971f
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=1984f28…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Fri May 4 16:35:04 2012 +0200
usrloc(k): set ruid for contacts added via MI command
---
modules_k/usrloc/Makefile | 1 +
modules_k/usrloc/ul_mi.c | 10 +++++++++-
modules_k/usrloc/ul_mod.c | 7 +++++++
3 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/modules_k/usrloc/Makefile b/modules_k/usrloc/Makefile
index 1c6c64e..50f9ce0 100644
--- a/modules_k/usrloc/Makefile
+++ b/modules_k/usrloc/Makefile
@@ -16,4 +16,5 @@ SERLIBPATH=../../lib
SER_LIBS+=$(SERLIBPATH)/kmi/kmi
SER_LIBS+=$(SERLIBPATH)/srdb1/srdb1
SER_LIBS+=$(SERLIBPATH)/kcore/kcore
+SER_LIBS+=$(SERLIBPATH)/srutils/srutils
include ../../Makefile.modules
diff --git a/modules_k/usrloc/ul_mi.c b/modules_k/usrloc/ul_mi.c
index 1855706..ca7c71a 100644
--- a/modules_k/usrloc/ul_mi.c
+++ b/modules_k/usrloc/ul_mi.c
@@ -35,6 +35,7 @@
#include <string.h>
#include <stdio.h>
#include "../../lib/kmi/mi.h"
+#include "../../lib/srutils/sruid.h"
#include "../../dprint.h"
#include "../../ut.h"
#include "../../qvalue.h"
@@ -49,12 +50,14 @@
/*! CSEQ nr used */
#define MI_UL_CSEQ 1
/*! call-id used for ul_add and ul_rm_contact */
-static str mi_ul_cid = str_init("dfjrewr12386fd6-343(a)openser.mi").mi");
+static str mi_ul_cid = str_init("dfjrewr12386fd6-343(a)kamailio.mi").mi");
/*! user agent used for ul_add */
static str mi_ul_ua = str_init("SIP Router MI Server");
/*! path used for ul_add and ul_rm_contact */
static str mi_ul_path = str_init("dummypath");
+extern sruid_t _ul_sruid;
+
/************************ helper functions ****************************/
/*!
@@ -540,6 +543,10 @@ struct mi_root* mi_usrloc_add(struct mi_root *cmd, void *param)
if (str2int( &node->value, (unsigned int*)&ci.methods) < 0)
goto bad_syntax;
+ if(sruid_next(&_ul_sruid)<0)
+ goto error;
+ ci.ruid = _ul_sruid.uid;
+
lock_udomain( dom, aor);
n = get_urecord( dom, aor, &r);
@@ -580,6 +587,7 @@ release_error:
release_urecord(r);
lock_error:
unlock_udomain( dom, aor);
+error:
return init_mi_tree( 500, MI_INTERNAL_ERR_S, MI_INTERNAL_ERR_LEN);
}
diff --git a/modules_k/usrloc/ul_mod.c b/modules_k/usrloc/ul_mod.c
index 5a05a3d..ccd94e8 100644
--- a/modules_k/usrloc/ul_mod.c
+++ b/modules_k/usrloc/ul_mod.c
@@ -60,6 +60,7 @@
#include "../../timer_proc.h" /* register_sync_timer */
#include "../../globals.h" /* is_main */
#include "../../ut.h" /* str_init */
+#include "../../lib/srutils/sruid.h"
#include "dlist.h" /* register_udomain */
#include "udomain.h" /* {insert,delete,get,release}_urecord */
#include "urecord.h" /* {insert,delete,get}_ucontact */
@@ -107,6 +108,9 @@ extern int ul_locks_no;
int ul_db_update_as_insert = 0;
int ul_timer_procs = 0;
+/* sruid to get internal uid for mi/rpc commands */
+sruid_t _ul_sruid;
+
/*
* Module parameters and their default values
*/
@@ -241,6 +245,9 @@ static int mod_init(void)
int i;
udomain_t* d;
+ if(sruid_init(&_ul_sruid, '-', "ulcx", SRUID_INC)<0)
+ return -1;
+
#ifdef STATISTICS
/* register statistics */
if (register_module_stats( exports.name, mod_stats)!=0 ) {