Skip to content
Permalink
Browse files

make SSL mode of PostgreSQL connections configuable

git-svn-id: http://svn.osgeo.org/qgis/trunk@10456 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Apr 2, 2009
1 parent e1d9527 commit 1e64ed34c6e6dfb1412926511375cea3881b6492
@@ -12,6 +12,7 @@ class QgsDataSourceURI
%End

public:
enum SSLmode { SSLprefer, SSLdisable, SSLallow, SSLrequire };

//! default constructor
QgsDataSourceURI();
@@ -33,7 +34,8 @@ public:
const QString& aPort,
const QString& aDatabase,
const QString& aUsername,
const QString& aPassword);
const QString& aPassword,
SSLmode sslmode );

//! Set all data source related members at once
void setDataSource(const QString& aSchema,
@@ -240,6 +240,7 @@ void QgsDbSourceSelect::deleteConnection()
settings.remove( key + "/username" );
settings.remove( key + "/password" );
settings.remove( key + "/port" );
settings.remove( key + "/sslmode" );
settings.remove( key + "/save" );
settings.remove( key );
//if(!success){
@@ -373,7 +374,10 @@ void QgsDbSourceSelect::on_btnConnect_clicked()
settings.value( key + "/port" ).toString(),
database,
settings.value( key + "/username" ).toString(),
password );
password,
(QgsDataSourceURI::SSLmode) settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt() );



bool searchPublicOnly = settings.value( key + "/publicOnly" ).toBool();
bool searchGeometryColumnsOnly = settings.value( key + "/geometryColumnsOnly" ).toBool();
@@ -410,7 +414,8 @@ void QgsDbSourceSelect::on_btnConnect_clicked()
settings.value( key + "/port" ).toString(),
database,
settings.value( key + "/username" ).toString(),
password );
password,
(QgsDataSourceURI::SSLmode) settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt() );

m_connectionInfo = uri.connectionInfo();
PQfinish( pd );
@@ -61,6 +61,12 @@ QgsNewConnection::QgsNewConnection( QWidget *parent, const QString& connName, Qt
// Ensure that cb_plublicSchemaOnly is set correctly
on_cb_geometryColumnsOnly_clicked();

cbxSSLmode->insertItem( QgsDataSourceURI::SSLprefer, tr("prefer") );
cbxSSLmode->insertItem( QgsDataSourceURI::SSLrequire, tr("require") );
cbxSSLmode->insertItem( QgsDataSourceURI::SSLallow, tr("allow") );
cbxSSLmode->insertItem( QgsDataSourceURI::SSLdisable, tr("disable") );
cbxSSLmode->setCurrentIndex( settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt() );

if ( settings.value( key + "/save" ).toString() == "true" )
{
txtPassword->setText( settings.value( key + "/password" ).toString() );
@@ -108,7 +114,7 @@ QgsNewConnection::~QgsNewConnection()
void QgsNewConnection::testConnection()
{
QgsDataSourceURI uri;
uri.setConnection( txtHost->text(), txtPort->text(), txtDatabase->text(), txtUsername->text(), txtPassword->text() );
uri.setConnection( txtHost->text(), txtPort->text(), txtDatabase->text(), txtUsername->text(), txtPassword->text(), (QgsDataSourceURI::SSLmode) cbxSSLmode->currentIndex() );

QgsLogger::debug( "PQconnectdb(" + uri.connectionInfo() + ");" );

@@ -142,6 +148,7 @@ void QgsNewConnection::saveConnection()
settings.setValue( baseKey + "/publicOnly", cb_publicSchemaOnly->isChecked() );
settings.setValue( baseKey + "/geometryColumnsOnly", cb_geometryColumnsOnly->isChecked() );
settings.setValue( baseKey + "/save", chkStorePassword->isChecked() ? "true" : "false" );
settings.setValue( baseKey + "/sslmode", cbxSSLmode->currentIndex() );
accept();
}

@@ -23,12 +23,12 @@
#include <QStringList>
#include <QRegExp>

QgsDataSourceURI::QgsDataSourceURI()
QgsDataSourceURI::QgsDataSourceURI() : mSSLmode(SSLprefer)
{
// do nothing
}

QgsDataSourceURI::QgsDataSourceURI( QString uri )
QgsDataSourceURI::QgsDataSourceURI( QString uri ) : mSSLmode(SSLprefer)
{
int i = 0;
while ( i < uri.length() )
@@ -146,7 +146,21 @@ QgsDataSourceURI::QgsDataSourceURI( QString uri )
}
else if ( pname == "sslmode" )
{
QgsDebugMsg( "sslmode ignored" );
if( pval == "disable" )
mSSLmode = SSLdisable;
else if( pval == "allow" )
mSSLmode = SSLallow;
else if( pval == "prefer" )
mSSLmode = SSLprefer;
else if( pval == "require" )
mSSLmode = SSLrequire;
}
else if ( pname == "requiressl" )
{
if( pval == "0" )
mSSLmode = SSLdisable;
else
mSSLmode = SSLprefer;
}
else if ( pname == "krbsrvname" )
{
@@ -293,6 +307,15 @@ QString QgsDataSourceURI::connectionInfo() const
}
}

if ( mSSLmode == SSLdisable )
connectionInfo += " sslmode=disable";
else if ( mSSLmode == SSLallow )
connectionInfo += " sslmode=allow";
else if ( mSSLmode == SSLrequire )
connectionInfo += " sslmode=require";
else if ( mSSLmode == SSLprefer )
connectionInfo += " sslmode=prefer";

return connectionInfo;
}

@@ -317,13 +340,15 @@ void QgsDataSourceURI::setConnection( const QString &host,
const QString &port,
const QString &database,
const QString &username,
const QString &password )
const QString &password,
SSLmode sslmode )
{
mHost = host;
mDatabase = database;
mPort = port;
mUsername = username;
mPassword = password;
mSSLmode = sslmode;
}

void QgsDataSourceURI::setDataSource( const QString &schema,
@@ -29,8 +29,8 @@
*/
class CORE_EXPORT QgsDataSourceURI
{

public:
enum SSLmode { SSLprefer, SSLdisable, SSLallow, SSLrequire };

//! default constructor
QgsDataSourceURI();
@@ -52,19 +52,22 @@ class CORE_EXPORT QgsDataSourceURI
const QString& aPort,
const QString& aDatabase,
const QString& aUsername,
const QString& aPassword );
const QString& aPassword,
SSLmode sslmode );

//! Set all data source related members at once
void setDataSource( const QString& aSchema,
const QString& aTable,
const QString& aGeometryColumn,
const QString& aSql = QString() );


QString username() const;
QString schema() const;
QString table() const;
QString sql() const;
QString geometryColumn() const;
enum SSLmode sslMode() const;

void clearSchema();
void setSql( QString sql );
@@ -93,6 +96,8 @@ class CORE_EXPORT QgsDataSourceURI
QString mUsername;
//! password
QString mPassword;
//! ssl mode
enum SSLmode mSSLmode;
};

#endif //QGSDATASOURCEURI_H
@@ -413,7 +413,8 @@ void QgsSpit::dbConnect()
settings.value( key + "/port" ).toString(),
database,
settings.value( key + "/username" ).toString(),
password );
password,
(QgsDataSourceURI::SSLmode) settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt() );

conn = PQconnectdb( uri.connectionInfo().toUtf8() );
}
@@ -6,13 +6,11 @@
<x>0</x>
<y>0</y>
<width>509</width>
<height>335</height>
<height>402</height>
</rect>
</property>
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>3</vsizetype>
<sizepolicy vsizetype="MinimumExpanding" hsizetype="MinimumExpanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@@ -93,12 +91,12 @@
</item>
<item row="1" column="1" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="chkStorePassword" >
<property name="text" >
@@ -117,20 +115,20 @@
</item>
<item row="0" column="1" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QLabel" name="TextLabel1_2" >
<property name="text" >
@@ -191,16 +189,23 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="TextLabel3_3" >
<property name="text" >
<string>SSL mode</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="txtName" >
<property name="toolTip" >
@@ -231,6 +236,9 @@
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbxSSLmode" />
</item>
</layout>
</item>
</layout>
@@ -240,12 +248,12 @@
</item>
<item row="0" column="1" >
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="btnOk" >
<property name="text" >
@@ -299,7 +307,7 @@
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>87</width>
<height>150</height>

0 comments on commit 1e64ed3

Please sign in to comment.
You can’t perform that action at this time.