Avoid using SQLITE_OPEN_URI

Centos6 uses a very old version of SQLite without support for URI filenames.
PAM authenticator must use a file-based database.

Commit cherry-picked to 2.4.0 from 2.3.
This commit is contained in:
Esa Korhonen
2019-06-26 16:21:21 +03:00
parent 7c2d5fd6a4
commit 166d26ff13
4 changed files with 57 additions and 19 deletions

View File

@ -91,18 +91,33 @@ PamClientSession* PamClientSession::create(const PamInstance& inst)
{
// This handle is only used from one thread, can define no_mutex.
sqlite3* dbhandle = NULL;
int db_flags = SQLITE_OPEN_READONLY | SQLITE_OPEN_SHAREDCACHE | SQLITE_OPEN_NOMUTEX
| SQLITE_OPEN_URI;
if (sqlite3_open_v2(inst.m_dbname.c_str(), &dbhandle, db_flags, NULL) == SQLITE_OK)
bool error = false;
int db_flags = SQLITE_OPEN_READONLY | SQLITE_OPEN_SHAREDCACHE | SQLITE_OPEN_NOMUTEX;
const char* filename = inst.m_dbname.c_str();
if (sqlite3_open_v2(filename, &dbhandle, db_flags, NULL) == SQLITE_OK)
{
sqlite3_busy_timeout(dbhandle, 1000);
}
else
{
MXS_ERROR("Failed to open SQLite3 handle.");
if (dbhandle)
{
MXS_ERROR(SQLITE_OPEN_FAIL, filename, sqlite3_errmsg(dbhandle));
}
else
{
MXS_ERROR(SQLITE_OPEN_OOM, filename);
}
error = true;
}
PamClientSession* rval = NULL;
if (!dbhandle || (rval = new(std::nothrow) PamClientSession(dbhandle, inst)) == NULL)
if (!error && ((rval = new (std::nothrow) PamClientSession(dbhandle, inst)) == NULL))
{
error = true;
}
if (error)
{
sqlite3_close_v2(dbhandle);
}