Commit 5ac1a5ee authored by François Grisez's avatar François Grisez

Fix unreleased AuthDbBackend singleton

parent 5b0f4b73
Pipeline #1263 passed with stage
in 25 minutes and 15 seconds
......@@ -21,7 +21,7 @@
using namespace std;
AuthDbBackend *AuthDbBackend::sUnique = NULL;
unique_ptr<AuthDbBackend> AuthDbBackend::sUnique;
AuthDbListener::~AuthDbListener(){
}
......@@ -45,27 +45,27 @@ public:
static void declareConfig(GenericStruct *mc){};
};
AuthDbBackend *AuthDbBackend::get() {
if (sUnique == NULL) {
AuthDbBackend &AuthDbBackend::get() {
if (sUnique == nullptr) {
GenericStruct *cr = GenericManager::get()->getRoot();
GenericStruct *ma = cr->get<GenericStruct>("module::Authentication");
const string &impl = ma->get<ConfigString>("db-implementation")->read();
if (impl == "fixed") {
sUnique = new FixedAuthDb();
sUnique.reset(new FixedAuthDb());
} else if (impl == "file") {
sUnique = new FileAuthDb();
sUnique.reset(new FileAuthDb());
#if ENABLE_ODBC
} else if (impl == "odbc") {
sUnique = new OdbcAuthDb();
sUnique.reset(new OdbcAuthDb());
#endif
#if ENABLE_SOCI
} else if (impl == "soci") {
sUnique = new SociAuthDB();
sUnique.reset(new SociAuthDB());
#endif
}
}
return sUnique;
return *sUnique;
}
AuthDbBackend::AuthDbBackend() {
......
......@@ -63,7 +63,7 @@ public:
};
class AuthDbBackend {
static AuthDbBackend *sUnique;
static std::unique_ptr<AuthDbBackend> sUnique;
struct CachedPassword {
std::vector<passwd_algo_t> pass;
......@@ -105,7 +105,7 @@ public:
virtual void getPasswordFromBackend(const std::string &id, const std::string &domain,
const std::string &authid, AuthDbListener *listener, AuthDbListener *listener_ref) = 0;
static AuthDbBackend *get();
static AuthDbBackend &get();
/* called by module_auth so that backends can declare their configuration to the ConfigurationManager */
static void declareConfig(GenericStruct *mc);
static std::string syncSha256(const char* input,size_t size);
......
......@@ -609,7 +609,7 @@ public:
sip_unknown_t *h2 = ModuleToolbox::getCustomHeaderByName(sip, "X-Phone-Alias");
const char* phone_alias = h2 ? h2->un_value : NULL;
phone_alias = phone_alias ? phone_alias : "";
AuthDbBackend::get()->createAccount(url->url_user, url->url_host, url->url_user, url->url_password,
AuthDbBackend::get().createAccount(url->url_user, url->url_host, url->url_user, url->url_password,
sip->sip_expires->ex_delta, phone_alias);
LOGD("Account created for %s@%s with password %s and expires %lu%s%s", url->url_user, url->url_host,
url->url_password, sip->sip_expires->ex_delta, phone_alias ? " with phone alias " : "", phone_alias);
......@@ -1254,7 +1254,7 @@ void Authentication::flexisip_auth_check_digest(auth_mod_t *am, auth_status_t *a
}
}
AuthDbBackend::get()->getPassword(as->as_user_uri->url_user, as->as_user_uri->url_host, ar->ar_username, listener);
AuthDbBackend::get().getPassword(as->as_user_uri->url_user, as->as_user_uri->url_host, ar->ar_username, listener);
}
/** Authenticate a request with @b Digest authentication scheme.
......@@ -1313,7 +1313,7 @@ void Authentication::flexisip_auth_method_digest(auth_mod_t *am, auth_status_t *
if (listener->mImmediateRetrievePass) {
SLOGD << "Searching for " << as->as_user_uri->url_user
<< " password to have it when the authenticated request comes";
AuthDbBackend::get()->getPassword(as->as_user_uri->url_user, as->as_user_uri->url_host, as->as_user_uri->url_user, NULL);
AuthDbBackend::get().getPassword(as->as_user_uri->url_user, as->as_user_uri->url_host, as->as_user_uri->url_user, NULL);
//AuthDbBackend::get()->getPasswordForAlgo(as->as_user_uri->url_user, as->as_user_uri->url_host, as->as_user_uri->url_user, NULL, listener);
}
listener->finish();
......
......@@ -156,9 +156,8 @@ private:
void onRecordFound(Record *r) {
if (r == NULL) {
LOGD("Record doesn't exist. Fork");
AuthDbBackend *mAuthDb = AuthDbBackend::get();
url_t *url = gw->getFrom()->a_url;
mAuthDb->getPassword(url->url_user, url->url_host, url->url_user, new OnAuthListener(gw));
AuthDbBackend::get().getPassword(url->url_user, url->url_host, url->url_user, new OnAuthListener(gw));
} else {
LOGD("Record already exists. Not forked");
}
......
......@@ -113,7 +113,7 @@ string Monitor::findLocalAddress(const list<string> &nodes) {
}
void Monitor::createAccounts() {
AuthDbBackend *authDb = AuthDbBackend::get();
AuthDbBackend &authDb = AuthDbBackend::get();
GenericStruct *cluster = GenericManager::get()->getRoot()->get<GenericStruct>("cluster");
GenericStruct *monitorConf = GenericManager::get()->getRoot()->get<GenericStruct>("monitor");
string salt = monitorConf->get<ConfigString>("password-salt")->read();
......@@ -128,10 +128,10 @@ void Monitor::createAccounts() {
string password = generatePassword(localIP, salt);
string username = generateUsername(CALLER_PREFIX, localIP);
authDb->createAccount(username, domain, username, password, PASSWORD_CACHE_EXPIRE);
authDb.createAccount(username, domain, username, password, PASSWORD_CACHE_EXPIRE);
username = generateUsername(CALLEE_PREFIX, localIP);
authDb->createAccount(username, domain, username, password, PASSWORD_CACHE_EXPIRE);
authDb.createAccount(username, domain, username, password, PASSWORD_CACHE_EXPIRE);
}
bool Monitor::isLocalhost(const string &host) {
......
......@@ -108,7 +108,7 @@ void PresenceLongterm::onListenerEvent(const shared_ptr<PresentityPresenceInform
//no presence information know yet, so ask again to the db.
const belle_sip_uri_t* uri = info->getEntity();
SLOGD << "No presence info element known yet for " << belle_sip_uri_get_user(uri) << ", checking if this user is already registered";
AuthDbBackend::get()->getUserWithPhone(belle_sip_uri_get_user(info->getEntity())
AuthDbBackend::get().getUserWithPhone(belle_sip_uri_get_user(info->getEntity())
, belle_sip_uri_get_host(info->getEntity())
, new PresenceAuthListener(mMainLoop, info));
}
......@@ -122,5 +122,5 @@ void PresenceLongterm::onListenerEvents(list<shared_ptr<PresentityPresenceInform
}
dInfo.insert(pair<string, shared_ptr<PresentityPresenceInformation>>(belle_sip_uri_get_user(info->getEntity()), info));
}
AuthDbBackend::get()->getUsersWithPhone(creds, new PresenceAuthListener(mMainLoop, dInfo));
AuthDbBackend::get().getUsersWithPhone(creds, new PresenceAuthListener(mMainLoop, dInfo));
}
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