Skip to content

Commit

Permalink
postgres provider: improve owner check (fixes #9844)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jan 24, 2015
1 parent 4afdf55 commit f8f2713
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/providers/postgres/qgspostgresconn.cpp
Expand Up @@ -894,12 +894,15 @@ bool QgsPostgresConn::openCursor( QString cursorName, QString sql )
{
if ( mOpenCursors++ == 0 && !mTransaction )
{
QgsDebugMsg( "Starting read-only transaction" );
PQexecNR( "BEGIN READ ONLY" );
QgsDebugMsg( QString( "Starting read-only transaction: %1" ).arg( mPostgresqlVersion ) );
if ( mPostgresqlVersion >= 80000 )
PQexecNR( "BEGIN READ ONLY" );
else
PQexecNR( "BEGIN" );
}
QgsDebugMsgLevel( QString( "Binary cursor %1 for %2" ).arg( cursorName ).arg( sql ), 3 );
return PQexecNR( QString( "DECLARE %1 BINARY CURSOR %2 FOR %3" ).
arg( cursorName ).arg( !mTransaction ? QString() : QString( "WITH HOLD" ) ).arg( sql ) );
arg( cursorName ).arg( !mTransaction ? "" : QString( "WITH HOLD" ) ).arg( sql ) );
}

bool QgsPostgresConn::closeCursor( QString cursorName )
Expand Down
5 changes: 3 additions & 2 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -976,10 +976,11 @@ bool QgsPostgresProvider::hasSufficientPermsAndCapabilities()

sql = QString( "SELECT 1 FROM pg_class,pg_namespace WHERE "
"pg_class.relnamespace=pg_namespace.oid AND "
"pg_get_userbyid(relowner)=current_user AND "
"%3 AND "
"relname=%1 AND nspname=%2" )
.arg( quotedValue( mTableName ) )
.arg( quotedValue( mSchemaName ) );
.arg( quotedValue( mSchemaName ) )
.arg( connectionRO()->pgVersion() < 80100 ? "pg_get_userbyid(relowner)=current_user" : "pg_has_role(relowner,'MEMBER')" );
testAccess = connectionRO()->PQexec( sql );
if ( testAccess.PQresultStatus() == PGRES_TUPLES_OK && testAccess.PQntuples() == 1 )
{
Expand Down

0 comments on commit f8f2713

Please sign in to comment.