Skip to content

Commit 0164b09

Browse files
committedOct 12, 2015
[auth] Fix #13550; add auth support to Server; read master password file
1 parent 5f82f1b commit 0164b09

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
 

‎src/server/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ TARGET_LINK_LIBRARIES(qgis_server
115115
${FCGI_LIBRARY}
116116
${POSTGRES_LIBRARY}
117117
${GDAL_LIBRARY}
118+
${QCA_LIBRARY}
118119
)
119120

120121
IF (WITH_BINDINGS)
@@ -169,7 +170,9 @@ INCLUDE_DIRECTORIES(
169170
${CMAKE_CURRENT_BINARY_DIR}
170171
${QT_INCLUDE_DIR}
171172
${QGIS_INCLUDE_DIR}
173+
${QCA_INCLUDE_DIR}
172174
../core
175+
../core/auth
173176
../core/dxf
174177
../core/geometry
175178
../core/raster
@@ -192,6 +195,7 @@ TARGET_LINK_LIBRARIES(qgis_mapserv.fcgi
192195
${FCGI_LIBRARY}
193196
${POSTGRES_LIBRARY}
194197
${GDAL_LIBRARY}
198+
${QCA_LIBRARY}
195199
)
196200

197201
########################################################

‎src/server/qgsserver.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "qgsconfig.h"
2323
#include "qgsserver.h"
2424

25+
#include "qgsauthmanager.h"
2526
#include "qgscapabilitiescache.h"
2627
#include "qgsfontutils.h"
2728
#include "qgsgetrequesthandler.h"
@@ -40,11 +41,13 @@
4041
#include "qgseditorwidgetregistry.h"
4142

4243
#include <QDomDocument>
44+
#include <QFile>
4345
#include <QNetworkDiskCache>
4446
#include <QImage>
4547
#include <QSettings>
4648
#include <QDateTime>
4749
#include <QScopedPointer>
50+
#include <QTextStream>
4851
// TODO: remove, it's only needed by a single debug message
4952
#include <fcgi_stdio.h>
5053
#include <stdlib.h>
@@ -350,10 +353,54 @@ bool QgsServer::init( int & argc, char ** argv )
350353
QgsDebugMsg( "Plugin PATH: " + QgsApplication::pluginPath() );
351354
QgsDebugMsg( "PkgData PATH: " + QgsApplication::pkgDataPath() );
352355
QgsDebugMsg( "User DB PATH: " + QgsApplication::qgisUserDbFilePath() );
356+
QgsDebugMsg( "Auth DB PATH: " + QgsApplication::qgisAuthDbFilePath() );
353357
QgsDebugMsg( "SVG PATHS: " + QgsApplication::svgPaths().join( ":" ) );
354358

355359
QgsApplication::createDB(); //init qgis.db (e.g. necessary for user crs)
356360

361+
// Instantiate authentication system
362+
// creates or uses qgis-auth.db in ~/.qgis2/ or directory defined by QGIS_AUTH_DB_DIR_PATH env variable
363+
QgsAuthManager::instance()->init( QgsApplication::pluginPath() );
364+
// set the master password from first line of file defined by QGIS_AUTH_PASSWORD_FILE env variable
365+
const char* passenv = "QGIS_AUTH_PASSWORD_FILE";
366+
if ( getenv( passenv ) )
367+
{
368+
QString passpath( getenv( passenv ) );
369+
// clear the env variable, so it can not be accessed from plugins, etc.
370+
#ifdef Q_OS_WIN
371+
putenv( passenv );
372+
#else
373+
unsetenv( passenv );
374+
#endif
375+
QString masterpass;
376+
QFile passfile( passpath );
377+
if ( passfile.exists() && passfile.open( QIODevice::ReadOnly | QIODevice::Text ) )
378+
{
379+
QTextStream passin( &passfile );
380+
while ( !passin.atEnd() )
381+
{
382+
masterpass = passin.readLine();
383+
break;
384+
}
385+
passfile.close();
386+
}
387+
if ( !masterpass.isEmpty() )
388+
{
389+
if ( QgsAuthManager::instance()->setMasterPassword( masterpass, true ) )
390+
{
391+
QgsDebugMsg( "Authentication master password set" );
392+
}
393+
else
394+
{
395+
QgsDebugMsg( "Setting authentication master password FAILED using file: " + passpath );
396+
}
397+
}
398+
else
399+
{
400+
QgsDebugMsg( "QGIS_AUTH_PASSWORD_FILE set, but FAILED to read file: " + passpath );
401+
}
402+
}
403+
357404
QString defaultConfigFilePath;
358405
QFileInfo projectFileInfo = defaultProjectFile(); //try to find a .qgs file in the server directory
359406
if ( projectFileInfo.exists() )

0 commit comments

Comments
 (0)
Please sign in to comment.