Skip to content

Commit

Permalink
save QGIS_AUTH_PASSWORD_FILE before FCGI_Accept() destroys it
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Nov 27, 2024
1 parent ff6e755 commit 6302af3
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/core/auth/qgsauthmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ bool QgsAuthManager::ensureInitialized() const
return mLazyInitResult;
}

static char *sPassFileEnv = nullptr;

bool QgsAuthManager::initPrivate( const QString &pluginPath )
{
if ( mAuthInit )
Expand Down Expand Up @@ -314,17 +316,11 @@ bool QgsAuthManager::initPrivate( const QString &pluginPath )
initSslCaches();
#endif
// set the master password from first line of file defined by QGIS_AUTH_PASSWORD_FILE env variable
const char *passenv = "QGIS_AUTH_PASSWORD_FILE";
if ( getenv( passenv ) && masterPasswordHashInDatabase() )
if ( sPassFileEnv && masterPasswordHashInDatabase() )
{
QString passpath( getenv( passenv ) );
// clear the env variable, so it can not be accessed from plugins, etc.
// (note: stored QgsApplication::systemEnvVars() skips this env variable as well)
#ifdef Q_OS_WIN
putenv( passenv );
#else
unsetenv( passenv );
#endif
QString passpath( sPassFileEnv );
free( sPassFileEnv );
sPassFileEnv = nullptr;

QString masterpass;
QFile passfile( passpath );
Expand Down Expand Up @@ -368,6 +364,20 @@ void QgsAuthManager::setup( const QString &pluginPath, const QString &authDataba
{
mPluginPath = pluginPath;
mAuthDatabaseConnectionUri = authDatabasePath;

const char *p = getenv( "QGIS_AUTH_PASSWORD_FILE" );
if ( p )
{
sPassFileEnv = qstrdup( p );

// clear the env variable, so it can not be accessed from plugins, etc.
// (note: stored QgsApplication::systemEnvVars() skips this env variable as well)
#ifdef Q_OS_WIN
putenv( "QGIS_AUTH_PASSWORD_FILE" );
#else
unsetenv( "QGIS_AUTH_PASSWORD_FILE" );
#endif
}
}

bool QgsAuthManager::isDisabled() const
Expand Down

0 comments on commit 6302af3

Please sign in to comment.