Commit 9d615b7e authored by François Grisez's avatar François Grisez

Fix several issues

* crashes
* authentication issues
parent 26160f6f
...@@ -121,8 +121,9 @@ try: ...@@ -121,8 +121,9 @@ try:
caller.register() caller.register()
callee.register() callee.register()
except CoreManager.RegistrationFailError as e: except CoreManager.RegistrationFailError as e:
identity = e.core.default_proxy.identity proxy_config = e.manager.core.default_proxy_config
proxy = e.core.default_proxy.server_addr identity = proxy_config.identity
proxy = proxy_config.server_addr
logging.fatal("One UA could not register. identity={0}, proxy={1}".format(identity, proxy)) logging.fatal("One UA could not register. identity={0}, proxy={1}".format(identity, proxy))
exit(1) exit(1)
......
...@@ -71,10 +71,7 @@ AuthDb::~AuthDb() { ...@@ -71,10 +71,7 @@ AuthDb::~AuthDb() {
string AuthDb::createPasswordKey(const string &user, const string &host, const string &auth_username) { string AuthDb::createPasswordKey(const string &user, const string &host, const string &auth_username) {
ostringstream key; ostringstream key;
key<<user; key<<user<<"#"<<auth_username;
if (!auth_username.empty()){
key<<user<<"#"<<auth_username;
}
return key.str(); return key.str();
} }
...@@ -101,9 +98,9 @@ void AuthDb::clearCache(){ ...@@ -101,9 +98,9 @@ void AuthDb::clearCache(){
bool AuthDb::cachePassword(const string &key, const string &domain, const string &pass, int expires){ bool AuthDb::cachePassword(const string &key, const string &domain, const string &pass, int expires){
time_t now = getCurrentTime(); time_t now = getCurrentTime();
auto & passwords=mCachedPasswords[domain]; map<string, CachedPassword> &passwords=mCachedPasswords[domain];
unique_lock<mutex> lck(mCachedPasswordMutex); unique_lock<mutex> lck(mCachedPasswordMutex);
auto it=passwords.find(key); map<string, CachedPassword>::iterator it=passwords.find(key);
if (expires==-1) expires=mCacheExpire; if (expires==-1) expires=mCacheExpire;
if (it != passwords.end()) { if (it != passwords.end()) {
(*it).second.pass=pass; (*it).second.pass=pass;
...@@ -116,7 +113,7 @@ bool AuthDb::cachePassword(const string &key, const string &domain, const string ...@@ -116,7 +113,7 @@ bool AuthDb::cachePassword(const string &key, const string &domain, const string
void AuthDb::createCachedAccount(const url_t *from, const char *auth_username, const char *password, int expires){ void AuthDb::createCachedAccount(const url_t *from, const char *auth_username, const char *password, int expires){
if (from->url_host && from->url_user){ if (from->url_host && from->url_user){
string key=createPasswordKey(from->url_user,from->url_host,auth_username ? auth_username : ""); string key=createPasswordKey(from->url_user, from->url_host, auth_username ? auth_username : "");
cachePassword(key,from->url_host,password,expires); cachePassword(key,from->url_host,password,expires);
} }
} }
......
...@@ -645,7 +645,7 @@ int main(int argc, char *argv[]){ ...@@ -645,7 +645,7 @@ int main(int argc, char *argv[]){
a->loadConfig (cfg); a->loadConfig (cfg);
// Create temporary test accounts for the Flexisip monitor if necessary // Create cached test accounts for the Flexisip monitor if necessary
if(monitorEnabled) { if(monitorEnabled) {
try { try {
Monitor::createAccounts(); Monitor::createAccounts();
......
/* /*
Flexisip, a flexible SIP proxy server with media capabilities. Flexisip, a flexible SIP proxy server with media capabilities.
Copyright (C) 2014 Belledonne Communications SARL. Copyright (C) 2014 Belledonne Communications SARL.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version. License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
...@@ -37,9 +37,9 @@ Monitor::Init::Init() { ...@@ -37,9 +37,9 @@ Monitor::Init::Init() {
{ String , "logfile" , "Path to the log file", "/etc/flexisip/flexisip_monitor.log"}, { String , "logfile" , "Path to the log file", "/etc/flexisip/flexisip_monitor.log"},
{ Integer , "switch-port" , "Port to open/close folowing the test succeed or not", "12345"}, { Integer , "switch-port" , "Port to open/close folowing the test succeed or not", "12345"},
{ String , "password-salt" , "Salt used to generate the passwords of each test account", "" }, { String , "password-salt" , "Salt used to generate the passwords of each test account", "" },
config_item_end config_item_end
}; };
GenericStruct *s = new GenericStruct("monitor", "Flexisip monitor parameters", 0); GenericStruct *s = new GenericStruct("monitor", "Flexisip monitor parameters", 0);
GenericManager::get()->getRoot()->addChild(s); GenericManager::get()->getRoot()->addChild(s);
s->addChildrenValues(items); s->addChildrenValues(items);
...@@ -50,7 +50,7 @@ void Monitor::exec(int socket) { ...@@ -50,7 +50,7 @@ void Monitor::exec(int socket) {
su_root_t *root = NULL; su_root_t *root = NULL;
shared_ptr<Agent> a = make_shared<Agent>(root); shared_ptr<Agent> a = make_shared<Agent>(root);
GenericManager::get()->loadStrict(); GenericManager::get()->loadStrict();
GenericStruct *monitorParams = GenericManager::get()->getRoot()->get<GenericStruct>("monitor"); GenericStruct *monitorParams = GenericManager::get()->getRoot()->get<GenericStruct>("monitor");
GenericStruct *cluster = GenericManager::get()->getRoot()->get<GenericStruct>("cluster"); GenericStruct *cluster = GenericManager::get()->getRoot()->get<GenericStruct>("cluster");
string interval = monitorParams->get<ConfigValue>("test-interval")->get(); string interval = monitorParams->get<ConfigValue>("test-interval")->get();
...@@ -58,7 +58,7 @@ void Monitor::exec(int socket) { ...@@ -58,7 +58,7 @@ void Monitor::exec(int socket) {
string port = monitorParams->get<ConfigValue>("switch-port")->get(); string port = monitorParams->get<ConfigValue>("switch-port")->get();
string salt = monitorParams->get<ConfigString>("password-salt")->read(); string salt = monitorParams->get<ConfigString>("password-salt")->read();
list<string> nodes = cluster->get<ConfigStringList>("nodes")->read(); list<string> nodes = cluster->get<ConfigStringList>("nodes")->read();
string domain; string domain;
try { try {
domain = findDomain(); domain = findDomain();
...@@ -66,18 +66,18 @@ void Monitor::exec(int socket) { ...@@ -66,18 +66,18 @@ void Monitor::exec(int socket) {
LOGF("Monitor: cannot find domain. %s", e.str().c_str()); LOGF("Monitor: cannot find domain. %s", e.str().c_str());
exit(-1); exit(-1);
} }
if(salt.empty()) { if(salt.empty()) {
LOGF("Monitor: no salt set"); LOGF("Monitor: no salt set");
exit(-1); exit(-1);
} }
if(nodes.empty()) { if(nodes.empty()) {
LOGF("Monitor: no nodes declared in the cluster section"); LOGF("Monitor: no nodes declared in the cluster section");
exit(-1); exit(-1);
} }
char **args = new char *[10 + nodes.size()]; char **args = new char *[10 + nodes.size() + 1];
args[0] = strdup(PYTHON_INTERPRETOR.c_str()); args[0] = strdup(PYTHON_INTERPRETOR.c_str());
args[1] = strdup(SCRIPT_PATH.c_str()); args[1] = strdup(SCRIPT_PATH.c_str());
args[2] = strdup("--interval"); args[2] = strdup("--interval");
...@@ -88,7 +88,7 @@ void Monitor::exec(int socket) { ...@@ -88,7 +88,7 @@ void Monitor::exec(int socket) {
args[7] = strdup(port.c_str()); args[7] = strdup(port.c_str());
args[8] = strdup(domain.c_str()); args[8] = strdup(domain.c_str());
args[9] = strdup(salt.c_str()); args[9] = strdup(salt.c_str());
int i=10; int i = 10;
for(string node : nodes) { for(string node : nodes) {
args[i] = strdup(node.c_str()); args[i] = strdup(node.c_str());
i++; i++;
...@@ -115,27 +115,30 @@ string Monitor::findLocalAddress(const list<string> &nodes) { ...@@ -115,27 +115,30 @@ string Monitor::findLocalAddress(const list<string> &nodes) {
} }
void Monitor::createAccounts() { void Monitor::createAccounts() {
url_t url; url_t url = {0};
AuthDb *authDb = AuthDb::get(); AuthDb *authDb = AuthDb::get();
GenericStruct *cluster = GenericManager::get()->getRoot()->get<GenericStruct>("cluster"); GenericStruct *cluster = GenericManager::get()->getRoot()->get<GenericStruct>("cluster");
GenericStruct *monitorConf = GenericManager::get()->getRoot()->get<GenericStruct>("monitor"); GenericStruct *monitorConf = GenericManager::get()->getRoot()->get<GenericStruct>("monitor");
string salt = monitorConf->get<ConfigString>("password-salt")->read(); string salt = monitorConf->get<ConfigString>("password-salt")->read();
list<string> nodes = cluster->get<ConfigStringList>("nodes")->read(); list<string> nodes = cluster->get<ConfigStringList>("nodes")->read();
url.url_host = findDomain().c_str(); string domaine = findDomain();
url.url_host = domaine.c_str();
string localIP = findLocalAddress(nodes); string localIP = findLocalAddress(nodes);
if(localIP == "") { if(localIP == "") {
SLOGA << "Could not find local IP address"; SLOGA << "Could not find local IP address";
exit(-1); exit(-1);
} }
const char *password = generatePassword(localIP, salt).c_str(); string password = generatePassword(localIP, salt).c_str();
url.url_user = generateUsername(CALLER_PREFIX, localIP).c_str(); string username = generateUsername(CALLER_PREFIX, localIP);
authDb->createAccount(&url, "", password, INT_MAX); url.url_user = username.c_str();
authDb->createAccount(&url, url.url_user, password.c_str(), INT_MAX/2);
url.url_user = generateUsername(CALLEE_PREFIX, localIP).c_str();
authDb->createAccount(&url, "", password, INT_MAX); username = generateUsername(CALLEE_PREFIX, localIP).c_str();
url.url_user = username.c_str();
authDb->createAccount(&url, url.url_user, password.c_str(), INT_MAX/2);
} }
bool Monitor::isLocalhost(const string &host) { bool Monitor::isLocalhost(const string &host) {
...@@ -150,7 +153,7 @@ bool Monitor::notLocalhost(const string &host) { ...@@ -150,7 +153,7 @@ bool Monitor::notLocalhost(const string &host) {
} }
string Monitor::md5sum(const string &s) { string Monitor::md5sum(const string &s) {
char digest[2*SU_MD5_DIGEST_SIZE+1]; char digest[2 * SU_MD5_DIGEST_SIZE + 1];
su_md5_t ctx; su_md5_t ctx;
su_md5_init(&ctx); su_md5_init(&ctx);
su_md5_strupdate(&ctx, s.c_str()); su_md5_strupdate(&ctx, s.c_str());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment