mirror of
https://github.com/postgres/postgres.git
synced 2025-06-23 14:01:44 +03:00
Fix some problems with restoring databases owned by non-superusers,
as per bug #1249; and remove the last vestiges of using \connect to change authorization.
This commit is contained in:
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.96 2004/08/30 19:44:14 tgl Exp $
|
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.97 2004/09/10 20:05:18 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -56,7 +56,7 @@ static void fixPriorBlobRefs(ArchiveHandle *AH, TocEntry *blobte,
|
|||||||
static void _doSetFixedOutputState(ArchiveHandle *AH);
|
static void _doSetFixedOutputState(ArchiveHandle *AH);
|
||||||
static void _doSetSessionAuth(ArchiveHandle *AH, const char *user);
|
static void _doSetSessionAuth(ArchiveHandle *AH, const char *user);
|
||||||
static void _doSetWithOids(ArchiveHandle *AH, const bool withOids);
|
static void _doSetWithOids(ArchiveHandle *AH, const bool withOids);
|
||||||
static void _reconnectToDB(ArchiveHandle *AH, const char *dbname, const char *user);
|
static void _reconnectToDB(ArchiveHandle *AH, const char *dbname);
|
||||||
static void _becomeUser(ArchiveHandle *AH, const char *user);
|
static void _becomeUser(ArchiveHandle *AH, const char *user);
|
||||||
static void _becomeOwner(ArchiveHandle *AH, TocEntry *te);
|
static void _becomeOwner(ArchiveHandle *AH, TocEntry *te);
|
||||||
static void _selectOutputSchema(ArchiveHandle *AH, const char *schemaName);
|
static void _selectOutputSchema(ArchiveHandle *AH, const char *schemaName);
|
||||||
@ -277,8 +277,8 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
|
|||||||
/* If we created a DB, connect to it... */
|
/* If we created a DB, connect to it... */
|
||||||
if (strcmp(te->desc, "DATABASE") == 0)
|
if (strcmp(te->desc, "DATABASE") == 0)
|
||||||
{
|
{
|
||||||
ahlog(AH, 1, "connecting to new database \"%s\" as user \"%s\"\n", te->tag, te->owner);
|
ahlog(AH, 1, "connecting to new database \"%s\"\n", te->tag);
|
||||||
_reconnectToDB(AH, te->tag, te->owner);
|
_reconnectToDB(AH, te->tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2151,26 +2151,25 @@ _doSetWithOids(ArchiveHandle *AH, const bool withOids)
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Issue the commands to connect to the specified database
|
* Issue the commands to connect to the specified database.
|
||||||
* as the specified user.
|
|
||||||
*
|
*
|
||||||
* If we're currently restoring right into a database, this will
|
* If we're currently restoring right into a database, this will
|
||||||
* actually establish a connection. Otherwise it puts a \connect into
|
* actually establish a connection. Otherwise it puts a \connect into
|
||||||
* the script output.
|
* the script output.
|
||||||
|
*
|
||||||
|
* NULL dbname implies reconnecting to the current DB (pretty useless).
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
_reconnectToDB(ArchiveHandle *AH, const char *dbname, const char *user)
|
_reconnectToDB(ArchiveHandle *AH, const char *dbname)
|
||||||
{
|
{
|
||||||
if (RestoringToDB(AH))
|
if (RestoringToDB(AH))
|
||||||
ReconnectToServer(AH, dbname, user);
|
ReconnectToServer(AH, dbname, NULL);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PQExpBuffer qry = createPQExpBuffer();
|
PQExpBuffer qry = createPQExpBuffer();
|
||||||
|
|
||||||
appendPQExpBuffer(qry, "\\connect %s",
|
appendPQExpBuffer(qry, "\\connect %s\n\n",
|
||||||
dbname ? fmtId(dbname) : "-");
|
dbname ? fmtId(dbname) : "-");
|
||||||
appendPQExpBuffer(qry, " %s\n\n",
|
|
||||||
fmtId(user));
|
|
||||||
|
|
||||||
ahprintf(AH, qry->data);
|
ahprintf(AH, qry->data);
|
||||||
|
|
||||||
@ -2179,12 +2178,12 @@ _reconnectToDB(ArchiveHandle *AH, const char *dbname, const char *user)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* NOTE: currUser keeps track of what the imaginary session user in
|
* NOTE: currUser keeps track of what the imaginary session user in
|
||||||
* our script is
|
* our script is. It's now effectively reset to the original userID.
|
||||||
*/
|
*/
|
||||||
if (AH->currUser)
|
if (AH->currUser)
|
||||||
free(AH->currUser);
|
free(AH->currUser);
|
||||||
|
|
||||||
AH->currUser = strdup(user);
|
AH->currUser = strdup("");
|
||||||
|
|
||||||
/* don't assume we still know the output schema */
|
/* don't assume we still know the output schema */
|
||||||
if (AH->currSchema)
|
if (AH->currSchema)
|
||||||
@ -2448,6 +2447,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
|
|||||||
strlen(te->owner) > 0 && strlen(te->dropStmt) > 0 &&
|
strlen(te->owner) > 0 && strlen(te->dropStmt) > 0 &&
|
||||||
(strcmp(te->desc, "AGGREGATE") == 0 ||
|
(strcmp(te->desc, "AGGREGATE") == 0 ||
|
||||||
strcmp(te->desc, "CONVERSION") == 0 ||
|
strcmp(te->desc, "CONVERSION") == 0 ||
|
||||||
|
strcmp(te->desc, "DATABASE") == 0 ||
|
||||||
strcmp(te->desc, "DOMAIN") == 0 ||
|
strcmp(te->desc, "DOMAIN") == 0 ||
|
||||||
strcmp(te->desc, "FUNCTION") == 0 ||
|
strcmp(te->desc, "FUNCTION") == 0 ||
|
||||||
strcmp(te->desc, "OPERATOR") == 0 ||
|
strcmp(te->desc, "OPERATOR") == 0 ||
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
* Implements the basic DB functions used by the archiver.
|
* Implements the basic DB functions used by the archiver.
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.57 2004/08/29 05:06:53 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.58 2004/09/10 20:05:18 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -88,8 +88,8 @@ _check_database_version(ArchiveHandle *AH, bool ignoreVersion)
|
|||||||
* Reconnect to the server. If dbname is not NULL, use that database,
|
* Reconnect to the server. If dbname is not NULL, use that database,
|
||||||
* else the one associated with the archive handle. If username is
|
* else the one associated with the archive handle. If username is
|
||||||
* not NULL, use that user name, else the one from the handle. If
|
* not NULL, use that user name, else the one from the handle. If
|
||||||
* both the database and the user and match the existing connection
|
* both the database and the user match the existing connection already,
|
||||||
* already, nothing will be done.
|
* nothing will be done.
|
||||||
*
|
*
|
||||||
* Returns 1 in any case.
|
* Returns 1 in any case.
|
||||||
*/
|
*/
|
||||||
@ -111,8 +111,8 @@ ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *username)
|
|||||||
newusername = username;
|
newusername = username;
|
||||||
|
|
||||||
/* Let's see if the request is already satisfied */
|
/* Let's see if the request is already satisfied */
|
||||||
if (strcmp(newusername, PQuser(AH->connection)) == 0
|
if (strcmp(newdbname, PQdb(AH->connection)) == 0 &&
|
||||||
&& strcmp(newdbname, PQdb(AH->connection)) == 0)
|
strcmp(newusername, PQuser(AH->connection)) == 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
newConn = _connectDB(AH, newdbname, newusername);
|
newConn = _connectDB(AH, newdbname, newusername);
|
||||||
|
Reference in New Issue
Block a user