Commit 2722eb3f authored by Mickaël Turnel's avatar Mickaël Turnel

Fix indentations

parent a0d5561b
......@@ -28,30 +28,30 @@ using namespace std;
void FileAuthDb::parsePasswd(string* pass, string user, string domain, passwd_algo_t* password){
// parse password and calcul passmd5, passsha256 if there is clrtxt pass.
int i;
for(i=0;i<3;i++){
if(pass[i].substr(0,7)=="clrtxt:"){
password->pass = pass[i].substr(7);
}
}
if(password->pass !=""){
string input;
input = user+":"+domain+":"+password->pass;
password->passmd5=syncMd5(input.c_str(), 16);
password->passsha256=syncSha256(input.c_str(), 32);
return;
}
for(i=0;i<3;i++){
if(pass[i].substr(0,4)=="md5:"){
password->passmd5 = pass[i].substr(4);
}
if(pass[i].substr(0,7)=="sha256:"){
password->passsha256 = pass[i].substr(7);
}
}
// parse password and calcul passmd5, passsha256 if there is clrtxt pass.
int i;
for(i=0;i<3;i++){
if(pass[i].substr(0,7)=="clrtxt:"){
password->pass = pass[i].substr(7);
}
}
if(password->pass !=""){
string input;
input = user+":"+domain+":"+password->pass;
password->passmd5=syncMd5(input.c_str(), 16);
password->passsha256=syncSha256(input.c_str(), 32);
return;
}
for(i=0;i<3;i++){
if(pass[i].substr(0,4)=="md5:"){
password->passmd5 = pass[i].substr(4);
}
if(pass[i].substr(0,7)=="sha256:"){
password->passsha256 = pass[i].substr(7);
}
}
}
FileAuthDb::FileAuthDb() {
......@@ -60,7 +60,7 @@ FileAuthDb::FileAuthDb() {
mLastSync = 0;
mFileString = ma->get<ConfigString>("datasource")->read();
sync();
sync();
}
void FileAuthDb::getUserWithPhoneFromBackend(const std::string &phone, const std::string &domain, AuthDbListener *listener) {
......@@ -86,7 +86,7 @@ void FileAuthDb::getPasswordFromBackend(const std::string &id, const std::string
string key(createPasswordKey(id, authid));
passwd_algo_t passwd;
passwd_algo_t passwd;
if (getCachedPassword(key, domain, passwd) == VALID_PASS_FOUND) {
res = AuthDbResult::PASSWORD_FOUND;
}
......@@ -95,113 +95,113 @@ void FileAuthDb::getPasswordFromBackend(const std::string &id, const std::string
}
void FileAuthDb::sync() {
LOGD("Syncing password file");
GenericStruct *cr = GenericManager::get()->getRoot();
GenericStruct *ma = cr->get<GenericStruct>("module::Authentication");
list<string> domains = ma->get<ConfigStringList>("auth-domains")->read();
mLastSync = getCurrentTime();
ifstream file;
stringstream ss;
ss.exceptions(ifstream::failbit | ifstream::badbit);
string line;
string user;
string domain;
passwd_algo_t password;
string userid;
string phone;
string pass[3];
string version;
string passwd_tag;
int i;
LOGD("Opening file %s", mFileString.c_str());
file.open(mFileString);
if (file.is_open()) {
while (file.good() && getline(file, line)) {
if (line.empty()) continue;
ss.clear();
ss.str(line);
version.clear();
getline(ss, version, ' ');
if(version.substr(0,8)=="version:")
version = version.substr(8);
else
LOGA("userdb.conf must start by version:X to be used.");
break;
}
if(version=="1"){
while (file.good() && getline(file, line)) {
if (line.empty()) continue;
ss.clear();
ss.str(line);
user.clear();
domain.clear();
pass[0].clear();
pass[1].clear();
pass[2].clear();
password.pass.clear();
password.passmd5.clear();
password.passsha256.clear();
userid.clear();
phone.clear();
try {
getline(ss, user, '@');
getline(ss, domain, ' ');
for(i=0;i<3 && (!ss.eof());i++){
passwd_tag.clear();
getline(ss, passwd_tag, ' ');
if(passwd_tag!=";")
pass[i]=strdup(passwd_tag.c_str());
else break;
}
if(passwd_tag!=";"){
if(ss.eof())
LOGA("In userdb.conf, the section of password must end with ';'");
else {
passwd_tag.clear();
getline(ss, passwd_tag, ' ');
if((!ss.eof())&&(passwd_tag!=";"))
LOGA("In userdb.conf, the section of password must end with ';'");
}
}
if (!ss.eof()) {
getline(ss, userid, ' ');
if (!ss.eof()) {
getline(ss, phone);
} else {
phone = "";
}
} else {
userid = user;
phone = "";
}
cacheUserWithPhone(phone, domain, user);
parsePasswd(pass,user,domain,&password);
if (find(domains.begin(), domains.end(), domain) != domains.end()) {
string key(createPasswordKey(user, userid));
cachePassword(key, domain, password, mCacheExpire);
} else if (find(domains.begin(), domains.end(), "*") != domains.end()) {
string key(createPasswordKey(user, userid));
cachePassword(key, domain, password, mCacheExpire);
} else {
LOGW("Not handled domain: %s", domain.c_str());
}
} catch (const stringstream::failure &e) {
LOGW("Incorrect line format: %s (error: %s)", line.c_str(), e.what());
}
}
} else {
LOGE("Version %s is not supported",version.c_str());
}
} else {
LOGE("Can't open file %s", mFileString.c_str());
}
LOGD("Syncing done");
LOGD("Syncing password file");
GenericStruct *cr = GenericManager::get()->getRoot();
GenericStruct *ma = cr->get<GenericStruct>("module::Authentication");
list<string> domains = ma->get<ConfigStringList>("auth-domains")->read();
mLastSync = getCurrentTime();
ifstream file;
stringstream ss;
ss.exceptions(ifstream::failbit | ifstream::badbit);
string line;
string user;
string domain;
passwd_algo_t password;
string userid;
string phone;
string pass[3];
string version;
string passwd_tag;
int i;
LOGD("Opening file %s", mFileString.c_str());
file.open(mFileString);
if (file.is_open()) {
while (file.good() && getline(file, line)) {
if (line.empty()) continue;
ss.clear();
ss.str(line);
version.clear();
getline(ss, version, ' ');
if(version.substr(0,8)=="version:")
version = version.substr(8);
else
LOGA("userdb.conf must start by version:X to be used.");
break;
}
if(version=="1"){
while (file.good() && getline(file, line)) {
if (line.empty()) continue;
ss.clear();
ss.str(line);
user.clear();
domain.clear();
pass[0].clear();
pass[1].clear();
pass[2].clear();
password.pass.clear();
password.passmd5.clear();
password.passsha256.clear();
userid.clear();
phone.clear();
try {
getline(ss, user, '@');
getline(ss, domain, ' ');
for(i=0;i<3 && (!ss.eof());i++){
passwd_tag.clear();
getline(ss, passwd_tag, ' ');
if(passwd_tag!=";")
pass[i]=strdup(passwd_tag.c_str());
else break;
}
if(passwd_tag!=";"){
if(ss.eof())
LOGA("In userdb.conf, the section of password must end with ';'");
else {
passwd_tag.clear();
getline(ss, passwd_tag, ' ');
if((!ss.eof())&&(passwd_tag!=";"))
LOGA("In userdb.conf, the section of password must end with ';'");
}
}
if (!ss.eof()) {
getline(ss, userid, ' ');
if (!ss.eof()) {
getline(ss, phone);
} else {
phone = "";
}
} else {
userid = user;
phone = "";
}
cacheUserWithPhone(phone, domain, user);
parsePasswd(pass,user,domain,&password);
if (find(domains.begin(), domains.end(), domain) != domains.end()) {
string key(createPasswordKey(user, userid));
cachePassword(key, domain, password, mCacheExpire);
} else if (find(domains.begin(), domains.end(), "*") != domains.end()) {
string key(createPasswordKey(user, userid));
cachePassword(key, domain, password, mCacheExpire);
} else {
LOGW("Not handled domain: %s", domain.c_str());
}
} catch (const stringstream::failure &e) {
LOGW("Incorrect line format: %s (error: %s)", line.c_str(), e.what());
}
}
} else {
LOGE("Version %s is not supported",version.c_str());
}
} else {
LOGE("Can't open file %s", mFileString.c_str());
}
LOGD("Syncing done");
}
......@@ -137,10 +137,10 @@ struct AuthDbTimingsAnalyzer {
void display(const char *name) {
LOGI("%lu [%lu micro] timings (%lu errors) %lu [%lu micro] slow - %lu [%lu millis] slowest", count,
(long)average, errorCount, slowCount, (long)slowAverage, slowestCount, ((long)slowestAverage) / 1000);
(long)average, errorCount, slowCount, (long)slowAverage, slowestCount, ((long)slowestAverage) / 1000);
double lDiv = ((double)maxLineWidth) / LineWidth;
LOGI("Displaying %s, %u steps [%lu - %lu] - max %lu - div %f", name, steps, 0l, maxDuration, maxLineWidth,
lDiv);
lDiv);
if (lDiv == 0.f) {
LOGI("Skipping display with no maxcount");
return;
......@@ -199,9 +199,9 @@ static vector<string> parseAndUpdateRequestConfig(string &request) {
}
/**
* See documentation on ODBC on Microsoft pages:
* http://msdn.microsoft.com/en-us/library/ms716319%28v=VS.85%29.aspx
*/
* See documentation on ODBC on Microsoft pages:
* http://msdn.microsoft.com/en-us/library/ms716319%28v=VS.85%29.aspx
*/
OdbcAuthDb::OdbcAuthDb() : mAsynchronousRetrieving(true), env(NULL), execDirect(false) {
GenericStruct *cr = GenericManager::get()->getRoot();
GenericStruct *ma = cr->get<GenericStruct>("module::Authentication");
......@@ -256,9 +256,9 @@ OdbcAuthDb::OdbcAuthDb() : mAsynchronousRetrieving(true), env(NULL), execDirect(
LOGF("odbc error");
}
/*SM: this follow code is really a crap because it blocks flexisip entirely at startup if the database is not
*responding.
* However it is required because mysql client lib segfaults like a shit when used from a thread for the first.
**/
*responding.
* However it is required because mysql client lib segfaults like a shit when used from a thread for the first.
**/
#if 1
// Make sure the driver library is loaded.
AuthDbTimings timings;
......@@ -277,18 +277,18 @@ void OdbcAuthDb::declareConfig(GenericStruct *mc) {
"Named parameters are :id (the user found in the from header), :domain (the authorization "
"realm) and :authid (the authorization username). "
"The use of the :id parameter is mandatory.",
"select password from accounts where id = :id and domain = :domain and authid=:authid"},
"select password from accounts where id = :id and domain = :domain and authid=:authid"},
{Boolean, "odbc-pooling", "Use pooling in ODBC (improves performances). This is not guaranteed to succeed, "
"because if you are using unixODBC, it consults the /etc/odbcinst.ini"
"file in section [ODBC] to check for Pooling=yes/no option. You should make sure "
"that this flag is set before expecting this option to work.",
"true"},
"because if you are using unixODBC, it consults the /etc/odbcinst.ini"
"file in section [ODBC] to check for Pooling=yes/no option. You should make sure "
"that this flag is set before expecting this option to work.",
"true"},
{Integer, "odbc-display-timings-interval", "Display timing statistics after this count of seconds", "0"},
{Integer, "odbc-display-timings-after-count",
"Display timing statistics once the number of samples reach this number.", "0"},
"Display timing statistics once the number of samples reach this number.", "0"},
config_item_end};
......@@ -386,13 +386,13 @@ bool OdbcAuthDb::getConnection(const string &id, ConnectionCtx &ctx, AuthDbTimin
// - establish an underlying connecion;
// Attach underlying to wrapper.
retcode = SQLDriverConnect(ctx.dbc, NULL, (SQLCHAR *)connectionString.c_str(), SQL_NTS, NULL, 0, NULL,
SQL_DRIVER_COMPLETE);
SQL_DRIVER_COMPLETE);
if (!SQL_SUCCEEDED(retcode)) {
dbcError(ctx, "SQLDriverConnect");
return false;
}
LOGD("SQLDriverConnect %s : %lu ms", id.c_str(),
(unsigned long)duration_cast<milliseconds>(steady_clock::now() - tp2).count());
(unsigned long)duration_cast<milliseconds>(steady_clock::now() - tp2).count());
// Set connection to be read only
SQLSetConnectAttr(ctx.dbc, SQL_ATTR_ACCESS_MODE, (SQLPOINTER)SQL_MODE_READ_ONLY, 0);
......@@ -429,7 +429,7 @@ bool OdbcAuthDb::getConnection(const string &id, ConnectionCtx &ctx, AuthDbTimin
}
LOGD("SQLBindParameter %u -> %s", (unsigned int)i, parameters[i].c_str());
retcode = SQLBindParameter(ctx.stmt, i + 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, (SQLULEN)fieldLength, 0,
fieldBuffer, 0, NULL);
fieldBuffer, 0, NULL);
if (!SQL_SUCCEEDED(retcode)) {
logSqlError("SQLBindParameter", ctx.stmt, SQL_HANDLE_STMT);
LOGF("couldn't bind parameter");
......@@ -478,7 +478,7 @@ static unsigned long threadCount=0;
static mutex threadCountMutex;
*/
void OdbcAuthDb::doAsyncRetrievePassword(string id, string domain, string auth,
AuthDbListener *listener) {
AuthDbListener *listener) {
/* unsigned long localThreadCountCopy=0;
threadCountMutex.lock();
++threadCount;
......
......@@ -37,59 +37,59 @@ void SociAuthDB::declareConfig(GenericStruct *mc) {
ConfigItemDescriptor items[] = {
{String, "soci-password-request",
"Soci SQL request to execute to obtain the password.\n"
"Named parameters are:\n -':id' : the user found in the from header,\n -':domain' : the authorization realm, "
"and\n -':authid' : the authorization username.\n"
"The use of the :id parameter is mandatory.",
"select password from accounts where login = :id and domain = :domain"},
"Soci SQL request to execute to obtain the password.\n"
"Named parameters are:\n -':id' : the user found in the from header,\n -':domain' : the authorization realm, "
"and\n -':authid' : the authorization username.\n"
"The use of the :id parameter is mandatory.",
"select password from accounts where login = :id and domain = :domain"},
{String, "soci-password-algo-request",
"Soci SQL request to execute to obtain the password.\n"
"Named parameters are:\n -':id' : the user found in the from header,\n -':domain' : the authorization realm, "
"and\n -':authid' : the authorization username.\n"
"The use of the :id parameter is mandatory."
"select password,password_md5,password_sha256 from accounts_algo where id = (select id from accounts where login = :id and domain = :domain)",
""},
""},
{String, "soci-user-with-phone-request",
"Soci SQL request to execute to obtain the username associated with a phone alias.\n"
"Named parameters are:\n -':phone' : the phone number to search for.\n"
"The use of the :phone parameter is mandatory.\n"
"Example : select login from accounts where phone = :phone ",
""},
"Soci SQL request to execute to obtain the username associated with a phone alias.\n"
"Named parameters are:\n -':phone' : the phone number to search for.\n"
"The use of the :phone parameter is mandatory.\n"
"Example : select login from accounts where phone = :phone ",
""},
{String, "soci-users-with-phones-request",
"Soci SQL request to execute to obtain the usernames associated with phones aliases.\n"
"Named parameters are:\n -':phones' : the phones to search for.\n"
"The use of the :phones parameter is mandatory.\n"
"If you use phone number linked accounts you'll need to select login, domain, phone in your request for flexisip to work."
"Example : select login, domain, phone from accounts where phone in (:phones)",
""},
"Soci SQL request to execute to obtain the usernames associated with phones aliases.\n"
"Named parameters are:\n -':phones' : the phones to search for.\n"
"The use of the :phones parameter is mandatory.\n"
"If you use phone number linked accounts you'll need to select login, domain, phone in your request for flexisip to work."
"Example : select login, domain, phone from accounts where phone in (:phones)",
""},
{Integer, "soci-poolsize",
"Size of the pool of connections that Soci will use. We open a thread for each DB query, and this pool will "
"allow each thread to get a connection.\n"
"The threads are blocked until a connection is released back to the pool, so increasing the pool size will "
"allow more connections to occur simultaneously.\n"
"On the other hand, you should not keep too many open connections to your DB at the same time.",
"100"},
"Size of the pool of connections that Soci will use. We open a thread for each DB query, and this pool will "
"allow each thread to get a connection.\n"
"The threads are blocked until a connection is released back to the pool, so increasing the pool size will "
"allow more connections to occur simultaneously.\n"
"On the other hand, you should not keep too many open connections to your DB at the same time.",
"100"},
{String, "soci-backend", "Choose the type of backend that Soci will use for the connection.\n"
"Depending on your Soci package and the modules you installed, this could be 'mysql', "
"'oracle', 'postgresql' or something else.",
"mysql"},
"Depending on your Soci package and the modules you installed, this could be 'mysql', "
"'oracle', 'postgresql' or something else.",
"mysql"},
{String, "soci-connection-string", "The configuration parameters of the Soci backend.\n"
"The basic format is \"key=value key2=value2\". For a mysql backend, this "
"is a valid config: \"db=mydb user=user password='pass' host=myhost.com\".\n"
"Please refer to the Soci documentation of your backend, for intance: "
"http://soci.sourceforge.net/doc/3.2/backends/mysql.html",
"db=mydb user=myuser password='mypass' host=myhost.com"},
"The basic format is \"key=value key2=value2\". For a mysql backend, this "
"is a valid config: \"db=mydb user=user password='pass' host=myhost.com\".\n"
"Please refer to the Soci documentation of your backend, for intance: "
"http://soci.sourceforge.net/doc/3.2/backends/mysql.html",
"db=mydb user=myuser password='mypass' host=myhost.com"},
{Integer, "soci-max-queue-size",
"Amount of queries that will be allowed to be queued before bailing password "
"requests.\n This value should be chosen accordingly with 'soci-poolsize', so "
"that you have a coherent behavior.\n This limit is here mainly as a safeguard "
"against out-of-control growth of the queue in the event of a flood or big "
"delays in the database backend.",
"1000"},
"Amount of queries that will be allowed to be queued before bailing password "
"requests.\n This value should be chosen accordingly with 'soci-poolsize', so "
"that you have a coherent behavior.\n This limit is here mainly as a safeguard "
"against out-of-control growth of the queue in the event of a flood or big "
"delays in the database backend.",
"1000"},
config_item_end};
mc->addChildrenValues(items);
......@@ -147,7 +147,7 @@ void SociAuthDB::reconnectSession(soci::session &session) {
#define DURATION_MS(start, stop) (unsigned long) duration_cast<milliseconds>((stop) - (start)).count()
void SociAuthDB::getPasswordWithPool(const std::string &id, const std::string &domain,
const std::string &authid, AuthDbListener *listener, AuthDbListener *listener_ref) {
const std::string &authid, AuthDbListener *listener, AuthDbListener *listener_ref) {
steady_clock::time_point start;
steady_clock::time_point stop;
passwd_algo_t passwd;
......@@ -195,11 +195,11 @@ void SociAuthDB::getPasswordWithPool(const std::string &id, const std::string &d
if ((e.err_num_ == 2014 || e.err_num_ == 2006) && errorCount == 1){
/* 2014 is the infamous "Commands out of sync; you can't run this command now" mysql error,
* which is retryable.
* At this time we don't know if it is a soci or mysql bug, or bug with the sql request being executed.
*
* 2006 is "MySQL server has gone away" which is also retryable.
*/
* which is retryable.
* At this time we don't know if it is a soci or mysql bug, or bug with the sql request being executed.
*
* 2006 is "MySQL server has gone away" which is also retryable.
*/
SLOGE << "[SOCI] retrying mysql error " << e.err_num_;
retry = true;
}
......@@ -362,7 +362,7 @@ void SociAuthDB::getPasswordFromBackend(const std::string &id, const std::string
if (success == FALSE) {
// Enqueue() can fail when the queue is full, so we have to act on that
SLOGE << "[SOCI] Auth queue is full, cannot fullfil password request for " << id << " / " << domain << " / "
<< authid;
<< authid;
if (listener) listener->onResult(AUTH_ERROR, "");
}
}
......
......@@ -31,7 +31,7 @@ void AuthDbListener::onResults(list<std::string> &phones, set<std::string> &user
}
class FixedAuthDb : public AuthDbBackend {
public:
public:
FixedAuthDb() {
}
......@@ -96,22 +96,22 @@ string AuthDbBackend::createPasswordKey(const string &user, const string &auth_u
}
AuthDbBackend::CacheResult AuthDbBackend::getCachedPassword(const string &key, const string &domain, passwd_algo_t &pass) {
time_t now = getCurrentTime();
auto &passwords = mCachedPasswords[domain];
unique_lock<mutex> lck(mCachedPasswordMutex);
auto it = passwords.find(key);
if (it != passwords.end()) {
pass.pass.assign(it->second.pass.pass);
pass.passmd5.assign(it->second.pass.passmd5);
pass.passsha256.assign(it->second.pass.passsha256);
if (now < it->second.expire_date) {
return VALID_PASS_FOUND;
} else {
passwords.erase(it);
return EXPIRED_PASS_FOUND;
}
}
return NO_PASS_FOUND;
time_t now = getCurrentTime();
auto &passwords = mCachedPasswords[domain];
unique_lock<mutex> lck(mCachedPasswordMutex);
auto it = passwords.find(key);
if (it != passwords.end()) {
pass.pass.assign(it->second.pass.pass);
pass.passmd5.assign(it->second.pass.passmd5);
pass.passsha256.assign(it->second.pass.passsha256);
if (now < it->second.expire_date) {
return VALID_PASS_FOUND;
} else {
passwords.erase(it);
return EXPIRED_PASS_FOUND;
}
}
return NO_PASS_FOUND;
}
void AuthDbBackend::clearCache() {
......@@ -119,19 +119,19 @@ void AuthDbBackend::clearCache() {
}
bool AuthDbBackend::cachePassword(const string &key, const string &domain, const passwd_algo_t &pass, int expires) {
time_t now = getCurrentTime();
map<string, CachedPassword> &passwords = mCachedPasswords[domain];
unique_lock<mutex> lck(mCachedPasswordMutex);
map<string, CachedPassword>::iterator it = passwords.find(key);
if (expires == -1)
expires = mCacheExpire;
if (it != passwords.end()) {
it->second.pass = pass;
it->second.expire_date = now + expires;
} else {
passwords.insert(make_pair(key, CachedPassword(pass, now + expires)));
}
return true;
time_t now = getCurrentTime();
map<string, CachedPassword> &passwords = mCachedPasswords[domain];
unique_lock<mutex> lck(mCachedPasswordMutex);
map<string, CachedPassword>::iterator it = passwords.find(key);
if (expires == -1)
expires = mCacheExpire;
if (it != passwords.end()) {
it->second.pass = pass;
it->second.expire_date = now + expires;
} else {
passwords.insert(make_pair(key, CachedPassword(pass, now + expires)));
}
return true;
}
bool AuthDbBackend::cacheUserWithPhone(const std::string &phone, const std::string &domain, const std::string &user) {
......@@ -149,78 +149,78 @@ bool AuthDbBackend::cacheUserWithPhone(const std::string &phone, const std::stri
}
void AuthDbBackend::getPassword(const std::string &user, const std::string &host, const std::string &auth_username,
AuthDbListener *listener) {
// Check for usable cached password
string key(createPasswordKey(user, auth_username));
passwd_algo_t pass;
switch (getCachedPassword(key, host, pass)) {
case VALID_PASS_FOUND:
if (listener) listener->onResult(AuthDbResult::PASSWORD_FOUND, pass);
return;
case EXPIRED_PASS_FOUND:
// Might check here if connection is failing
// If it is the case use fallback password and
// return AuthDbResult::PASSWORD_FOUND;
break;
case NO_PASS_FOUND:
break;
}
// if we reach here, password wasn't cached: we have to grab the password from the actual backend
getPasswordFromBackend(user, host, auth_username, listener, NULL);
AuthDbListener *listener) {
// Check for usable cached password
string key(createPasswordKey(user, auth_username));
passwd_algo_t pass;
switch (getCachedPassword(key, host, pass)) {
case VALID_PASS_FOUND:
if (listener) listener->onResult(AuthDbResult::PASSWORD_FOUND, pass);
return;
case EXPIRED_PASS_FOUND:
// Might check here if connection is failing
// If it is the case use fallback password and
// return AuthDbResult::PASSWORD_FOUND;
break;
case NO_PASS_FOUND:
break;
}
// if we reach here, password wasn't cached: we have to grab the password from the actual backend
getPasswordFromBackend(user, host, auth_username, listener, NULL);
}
void AuthDbBackend::getPasswordForAlgo(const std::string &user, const std::string &host, const std::string &auth_username,
AuthDbListener *listener, AuthDbListener *listener_ref) {
// Check for usable cached password
string key(createPasswordKey(user, auth_username));
passwd_algo_t pass;
switch (getCachedPassword(key, host, pass)) {
case VALID_PASS_FOUND:
if (listener) listener->onResult(AuthDbResult::PASSWORD_FOUND, pass);
// Check for usable cached password
string key(createPasswordKey(user, auth_username));
passwd_algo_t pass;
switch (getCachedPassword(key, host, pass)) {
case VALID_PASS_FOUND:
if (listener) listener->onResult(AuthDbResult::PASSWORD_FOUND, pass);
if(listener_ref) listener_ref->finish_verify_algos(pass);
return;
case EXPIRED_PASS_FOUND:
// Might check here if connection is failing
// If it is the case use fallback password and
// return AuthDbResult::PASSWORD_FOUND;
break;
case NO_PASS_FOUND:
break;
}
// if we reach here, password wasn't cached: we have to grab the password from the actual backend
getPasswordFromBackend(user, host, auth_username, listener, listener_ref);
return;
case EXPIRED_PASS_FOUND:
// Might check here if connection is failing
// If it is the case use fallback password and
// return AuthDbResult::PASSWORD_FOUND;
break;
case NO_PASS_FOUND:
break;
}
// if we reach here, password wasn't cached: we have to grab the password from the actual backend
getPasswordFromBackend(user, host, auth_username, listener, listener_ref);
}
void AuthDbBackend::createCachedAccount(const std::string &user, const std::string &host, const std::string &auth_username, const passwd_algo_t &password,
int expires, const std::string & phone_alias) {
if (!user.empty() && !host.empty()) {
string key = createPasswordKey(user, auth_username);
cachePassword(key, host, password, expires);
cacheUserWithPhone(phone_alias, host, user);
}
int expires, const std::string & phone_alias) {
if (!user.empty() && !host.empty()) {
string key = createPasswordKey(user, auth_username);
cachePassword(key, host, password, expires);
cacheUserWithPhone(phone_alias, host, user);
}
}
string AuthDbBackend::syncSha256(const char* input,size_t size){
uint8_t a1buf[size];
size_t di;
char out[size*2+1];
bctbx_sha256((const unsigned char*)input, strlen(input),size, a1buf);
for (di = 0; di < size; ++di)
sprintf(out + di * 2, "%02x", a1buf[di]);
out[size*2]='\0';
return out;
uint8_t a1buf[size];
size_t di;
char out[size*2+1];
bctbx_sha256((const unsigned char*)input, strlen(input),size, a1buf);
for (di = 0; di < size; ++di)
sprintf(out + di * 2, "%02x", a1buf[di]);
out[size*2]='\0';