save QGIS_AUTH_PASSWORD_FILE before FCGI_Accept() destroys it

This commit is contained in:
Juergen E. Fischer 2024-11-27 00:03:20 +01:00 committed by Jürgen Fischer
parent ff6e7551f2
commit 6302af30a3

View File

@ -200,6 +200,8 @@ bool QgsAuthManager::ensureInitialized() const
return mLazyInitResult; return mLazyInitResult;
} }
static char *sPassFileEnv = nullptr;
bool QgsAuthManager::initPrivate( const QString &pluginPath ) bool QgsAuthManager::initPrivate( const QString &pluginPath )
{ {
if ( mAuthInit ) if ( mAuthInit )
@ -314,17 +316,11 @@ bool QgsAuthManager::initPrivate( const QString &pluginPath )
initSslCaches(); initSslCaches();
#endif #endif
// set the master password from first line of file defined by QGIS_AUTH_PASSWORD_FILE env variable // 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 ( sPassFileEnv && masterPasswordHashInDatabase() )
if ( getenv( passenv ) && masterPasswordHashInDatabase() )
{ {
QString passpath( getenv( passenv ) ); QString passpath( sPassFileEnv );
// clear the env variable, so it can not be accessed from plugins, etc. free( sPassFileEnv );
// (note: stored QgsApplication::systemEnvVars() skips this env variable as well) sPassFileEnv = nullptr;
#ifdef Q_OS_WIN
putenv( passenv );
#else
unsetenv( passenv );
#endif
QString masterpass; QString masterpass;
QFile passfile( passpath ); QFile passfile( passpath );
@ -368,6 +364,20 @@ void QgsAuthManager::setup( const QString &pluginPath, const QString &authDataba
{ {
mPluginPath = pluginPath; mPluginPath = pluginPath;
mAuthDatabaseConnectionUri = authDatabasePath; 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 bool QgsAuthManager::isDisabled() const