From 48663e4239f819b42e7035d9f4023c161eb71d05 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Thu, 23 Apr 2015 16:34:35 +0200 Subject: [PATCH] permissions: fixed reload trusted rpc command - reported by Emmanuel Schmidbauer, GH#138 --- modules/permissions/mi.c | 6 +----- modules/permissions/trusted.c | 21 +++++++++++++++++++++ modules/permissions/trusted.h | 2 ++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/modules/permissions/mi.c b/modules/permissions/mi.c index 9f66683f1bd..35f2cca5f09 100644 --- a/modules/permissions/mi.c +++ b/modules/permissions/mi.c @@ -54,11 +54,7 @@ struct mi_root* mi_trusted_reload(struct mi_root *cmd_tree, void *param) * RPC function to reload trusted table */ void rpc_trusted_reload(rpc_t* rpc, void* c) { - if (hash_table==NULL) { - rpc->fault(c, 500, "Reload failed. No hash table"); - return; - } - if (reload_trusted_table () != 1) { + if (reload_trusted_table_cmd () != 1) { rpc->fault(c, 500, "Reload failed."); return; } diff --git a/modules/permissions/trusted.c b/modules/permissions/trusted.c index 920f30752ff..db20e8f9813 100644 --- a/modules/permissions/trusted.c +++ b/modules/permissions/trusted.c @@ -555,3 +555,24 @@ int allow_trusted_2(struct sip_msg* _msg, char* _src_ip_sp, char* _proto_sp) return -1; } + +int reload_trusted_table_cmd(void) +{ + if (!db_handle) { + db_handle = perm_dbf.init(&db_url); + if (!db_handle) { + LM_ERR("unable to connect database\n"); + return -1; + } + } + if (reload_trusted_table () != 1) { + perm_dbf.close(db_handle); + db_handle = 0; + return -1; + } + + perm_dbf.close(db_handle); + db_handle = 0; + + return 1; +} diff --git a/modules/permissions/trusted.h b/modules/permissions/trusted.h index cbb3655e90c..f487f6a5e4b 100644 --- a/modules/permissions/trusted.h +++ b/modules/permissions/trusted.h @@ -84,4 +84,6 @@ 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); +int reload_trusted_table_cmd(void); + #endif /* TRUSTED_H */