diff --git a/daemon/src/dbus/configurationmanager.cpp b/daemon/src/dbus/configurationmanager.cpp index f067e5ec9317fbad9a6dad1d920fb49517522f6d..2a739e9d8ab79d2d7572fe06bc906de04c7a2589 100644 --- a/daemon/src/dbus/configurationmanager.cpp +++ b/daemon/src/dbus/configurationmanager.cpp @@ -56,12 +56,12 @@ std::map<std::string, std::string> ConfigurationManager::getIp2IpDetails() SIPAccount *sipaccount = Manager::instance().getIP2IPAccount(); if (!sipaccount) { - ERROR("ConfigurationManager: could not find account"); + ERROR("ConfigurationManager: could not find IP2IP account"); return ip2ipAccountDetails; } else return sipaccount->getIp2IpDetails(); - std::map<std::string, std::string> tlsSettings = getTlsSettings(); + std::map<std::string, std::string> tlsSettings(getTlsSettings()); std::copy(tlsSettings.begin(), tlsSettings.end(), std::inserter(ip2ipAccountDetails, ip2ipAccountDetails.end())); @@ -442,23 +442,19 @@ void ConfigurationManager::setShortcuts( std::vector<std::map<std::string, std::string> > ConfigurationManager::getCredentials( const std::string& accountID) { - Account *account = Manager::instance().getAccount(accountID); + SIPAccount *account = dynamic_cast<SIPAccount*>(Manager::instance().getAccount(accountID)); std::vector<std::map<std::string, std::string> > credentialInformation; - if (!account or account->getType() != "SIP") + if (!account) return credentialInformation; - - SIPAccount *sipaccount = static_cast<SIPAccount *>(account); - return sipaccount->getCredentials(); + else + return account->getCredentials(); } void ConfigurationManager::setCredentials(const std::string& accountID, const std::vector<std::map<std::string, std::string> >& details) { - Account *account = Manager::instance().getAccount(accountID); - - if (account and account->getType() == "SIP") { - SIPAccount *sipaccount = static_cast<SIPAccount*>(account); - sipaccount->setCredentials(details); - } + SIPAccount *account = dynamic_cast<SIPAccount*>(Manager::instance().getAccount(accountID)); + if (account) + account->setCredentials(details); } diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp index 66cfcfc64d01b12240a4a029ce25c4a6d913511a..545c5bc02d7cb12e79ab6a6f81b8bb1ccf8bb6ce 100644 --- a/daemon/src/sip/sipaccount.cpp +++ b/daemon/src/sip/sipaccount.cpp @@ -42,9 +42,8 @@ #include "manager.h" #include <pwd.h> #include <sstream> -#include <cassert> -const char * const SIPAccount::IP2IP_PROFILE = "IP2IP"; +const char * const SIPAccount::IP2IP_PROFILE = "IP2IP"; const char * const SIPAccount::OVERRTP_STR = "overrtp"; const char * const SIPAccount::SIPINFO_STR = "sipinfo"; @@ -872,6 +871,7 @@ std::string computeMd5HashFromCredential(const std::string& username, MD5_APPEND(&pms, realm.data(), realm.length()); MD5_APPEND(&pms, ":", 1); MD5_APPEND(&pms, password.data(), password.length()); +#undef MD5_APPEND unsigned char digest[16]; pj_md5_final(&pms, digest); @@ -887,14 +887,18 @@ std::string computeMd5HashFromCredential(const std::string& username, void SIPAccount::setCredentials(const std::vector<std::map<std::string, std::string> >& creds) { + // we can not authenticate without credentials + if (creds.empty()) { + ERROR("SIPAccount: Cannot authenticate with empty credentials list"); + return; + } + using std::vector; using std::string; using std::map; bool md5HashingEnabled = Manager::instance().preferences.getMd5Hash(); - assert(not creds.empty()); // we can not authenticate without credentials - credentials_ = creds; /* md5 hashing */ @@ -951,7 +955,8 @@ void SIPAccount::setCredentials(const std::vector<std::map<std::string, std::str } } -const std::vector<std::map<std::string, std::string> > &SIPAccount::getCredentials() +const std::vector<std::map<std::string, std::string> > & +SIPAccount::getCredentials() const { return credentials_; } @@ -983,8 +988,7 @@ std::map<std::string, std::string> SIPAccount::getIp2IpDetails() const portstr << localPort_; ip2ipAccountDetails[CONFIG_LOCAL_PORT] = portstr.str(); - std::map<std::string, std::string> tlsSettings; - tlsSettings = getTlsSettings(); + std::map<std::string, std::string> tlsSettings(getTlsSettings()); std::copy(tlsSettings.begin(), tlsSettings.end(), std::inserter( ip2ipAccountDetails, ip2ipAccountDetails.end())); @@ -993,8 +997,8 @@ std::map<std::string, std::string> SIPAccount::getIp2IpDetails() const std::map<std::string, std::string> SIPAccount::getTlsSettings() const { - std::map<std::string, std::string> tlsSettings; assert(isIP2IP()); + std::map<std::string, std::string> tlsSettings; std::stringstream portstr; portstr << tlsListenerPort_; diff --git a/daemon/src/sip/sipaccount.h b/daemon/src/sip/sipaccount.h index 2e406363ae8119b08202fbc00709c226348f56f0..960b47f74fa0de0b544d370a316c055a04561521 100644 --- a/daemon/src/sip/sipaccount.h +++ b/daemon/src/sip/sipaccount.h @@ -205,7 +205,9 @@ class SIPAccount : public Account { } void setCredentials(const std::vector<std::map<std::string, std::string> >& details); - const std::vector<std::map<std::string, std::string> > &getCredentials(); + + const std::vector<std::map<std::string, std::string> > & + getCredentials() const; /** * A client sendings a REGISTER request MAY suggest an expiration