mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Replace pg_shadow and pg_group by new role-capable catalogs pg_authid
and pg_auth_members. There are still many loose ends to finish in this patch (no documentation, no regression tests, no pg_dump support for instance). But I'm going to commit it now anyway so that Alvaro can make some progress on shared dependencies. The catalog changes should be pretty much done.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/aggregatecmds.c,v 1.26 2005/04/14 20:03:23 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/aggregatecmds.c,v 1.27 2005/06/28 05:08:53 tgl Exp $
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The "DefineFoo" routines take the parse tree and pick out the
|
||||
@@ -295,7 +295,7 @@ RenameAggregate(List *name, TypeName *basetype, const char *newname)
|
||||
* Change aggregate owner
|
||||
*/
|
||||
void
|
||||
AlterAggregateOwner(List *name, TypeName *basetype, AclId newOwnerSysId)
|
||||
AlterAggregateOwner(List *name, TypeName *basetype, Oid newOwnerId)
|
||||
{
|
||||
Oid basetypeOid;
|
||||
Oid procOid;
|
||||
@@ -329,7 +329,7 @@ AlterAggregateOwner(List *name, TypeName *basetype, AclId newOwnerSysId)
|
||||
* If the new owner is the same as the existing owner, consider the
|
||||
* command to have succeeded. This is for dump restoration purposes.
|
||||
*/
|
||||
if (procForm->proowner != newOwnerSysId)
|
||||
if (procForm->proowner != newOwnerId)
|
||||
{
|
||||
/* Otherwise, must be superuser to change object ownership */
|
||||
if (!superuser())
|
||||
@@ -341,7 +341,7 @@ AlterAggregateOwner(List *name, TypeName *basetype, AclId newOwnerSysId)
|
||||
* Modify the owner --- okay to scribble on tup because it's a
|
||||
* copy
|
||||
*/
|
||||
procForm->proowner = newOwnerSysId;
|
||||
procForm->proowner = newOwnerId;
|
||||
|
||||
simple_heap_update(rel, &tup->t_self, tup);
|
||||
CatalogUpdateIndexes(rel, tup);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/alter.c,v 1.12 2004/12/31 21:59:41 pgsql Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/alter.c,v 1.13 2005/06/28 05:08:53 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -64,10 +64,6 @@ ExecRenameStmt(RenameStmt *stmt)
|
||||
RenameFunction(stmt->object, stmt->objarg, stmt->newname);
|
||||
break;
|
||||
|
||||
case OBJECT_GROUP:
|
||||
RenameGroup(stmt->subname, stmt->newname);
|
||||
break;
|
||||
|
||||
case OBJECT_LANGUAGE:
|
||||
RenameLanguage(stmt->subname, stmt->newname);
|
||||
break;
|
||||
@@ -76,6 +72,10 @@ ExecRenameStmt(RenameStmt *stmt)
|
||||
RenameOpClass(stmt->object, stmt->subname, stmt->newname);
|
||||
break;
|
||||
|
||||
case OBJECT_ROLE:
|
||||
RenameRole(stmt->subname, stmt->newname);
|
||||
break;
|
||||
|
||||
case OBJECT_SCHEMA:
|
||||
RenameSchema(stmt->subname, stmt->newname);
|
||||
break;
|
||||
@@ -84,10 +84,6 @@ ExecRenameStmt(RenameStmt *stmt)
|
||||
RenameTableSpace(stmt->subname, stmt->newname);
|
||||
break;
|
||||
|
||||
case OBJECT_USER:
|
||||
RenameUser(stmt->subname, stmt->newname);
|
||||
break;
|
||||
|
||||
case OBJECT_TABLE:
|
||||
case OBJECT_INDEX:
|
||||
case OBJECT_COLUMN:
|
||||
@@ -153,7 +149,7 @@ ExecRenameStmt(RenameStmt *stmt)
|
||||
void
|
||||
ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
|
||||
{
|
||||
AclId newowner = get_usesysid(stmt->newowner);
|
||||
Oid newowner = get_roleid_checked(stmt->newowner);
|
||||
|
||||
switch (stmt->objectType)
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/conversioncmds.c,v 1.18 2005/05/03 19:17:59 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/conversioncmds.c,v 1.19 2005/06/28 05:08:53 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -175,7 +175,7 @@ RenameConversion(List *name, const char *newname)
|
||||
* Change conversion owner
|
||||
*/
|
||||
void
|
||||
AlterConversionOwner(List *name, AclId newOwnerSysId)
|
||||
AlterConversionOwner(List *name, Oid newOwnerId)
|
||||
{
|
||||
Oid conversionOid;
|
||||
HeapTuple tup;
|
||||
@@ -203,7 +203,7 @@ AlterConversionOwner(List *name, AclId newOwnerSysId)
|
||||
* If the new owner is the same as the existing owner, consider the
|
||||
* command to have succeeded. This is for dump restoration purposes.
|
||||
*/
|
||||
if (convForm->conowner != newOwnerSysId)
|
||||
if (convForm->conowner != newOwnerId)
|
||||
{
|
||||
/* Otherwise, must be superuser to change object ownership */
|
||||
if (!superuser())
|
||||
@@ -215,7 +215,7 @@ AlterConversionOwner(List *name, AclId newOwnerSysId)
|
||||
* Modify the owner --- okay to scribble on tup because it's a
|
||||
* copy
|
||||
*/
|
||||
convForm->conowner = newOwnerSysId;
|
||||
convForm->conowner = newOwnerId;
|
||||
|
||||
simple_heap_update(rel, &tup->t_self, tup);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.245 2005/06/02 01:21:22 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.246 2005/06/28 05:08:53 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -25,7 +25,6 @@
|
||||
#include "catalog/index.h"
|
||||
#include "catalog/namespace.h"
|
||||
#include "catalog/pg_index.h"
|
||||
#include "catalog/pg_shadow.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "commands/copy.h"
|
||||
#include "commands/trigger.h"
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.161 2005/06/25 22:47:29 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.162 2005/06/28 05:08:53 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -28,10 +28,10 @@
|
||||
#include "access/genam.h"
|
||||
#include "access/heapam.h"
|
||||
#include "catalog/catalog.h"
|
||||
#include "catalog/pg_database.h"
|
||||
#include "catalog/pg_shadow.h"
|
||||
#include "catalog/pg_tablespace.h"
|
||||
#include "catalog/indexing.h"
|
||||
#include "catalog/pg_authid.h"
|
||||
#include "catalog/pg_database.h"
|
||||
#include "catalog/pg_tablespace.h"
|
||||
#include "commands/comment.h"
|
||||
#include "commands/dbcommands.h"
|
||||
#include "commands/tablespace.h"
|
||||
@@ -52,7 +52,7 @@
|
||||
|
||||
|
||||
/* non-export function prototypes */
|
||||
static bool get_db_info(const char *name, Oid *dbIdP, int4 *ownerIdP,
|
||||
static bool get_db_info(const char *name, Oid *dbIdP, Oid *ownerIdP,
|
||||
int *encodingP, bool *dbIsTemplateP, bool *dbAllowConnP,
|
||||
Oid *dbLastSysOidP,
|
||||
TransactionId *dbVacuumXidP, TransactionId *dbFrozenXidP,
|
||||
@@ -70,7 +70,7 @@ createdb(const CreatedbStmt *stmt)
|
||||
HeapScanDesc scan;
|
||||
Relation rel;
|
||||
Oid src_dboid;
|
||||
AclId src_owner;
|
||||
Oid src_owner;
|
||||
int src_encoding;
|
||||
bool src_istemplate;
|
||||
bool src_allowconn;
|
||||
@@ -85,7 +85,7 @@ createdb(const CreatedbStmt *stmt)
|
||||
Datum new_record[Natts_pg_database];
|
||||
char new_record_nulls[Natts_pg_database];
|
||||
Oid dboid;
|
||||
AclId datdba;
|
||||
Oid datdba;
|
||||
ListCell *option;
|
||||
DefElem *dtablespacename = NULL;
|
||||
DefElem *downer = NULL;
|
||||
@@ -186,13 +186,13 @@ createdb(const CreatedbStmt *stmt)
|
||||
nodeTag(dencoding->arg));
|
||||
}
|
||||
|
||||
/* obtain sysid of proposed owner */
|
||||
/* obtain OID of proposed owner */
|
||||
if (dbowner)
|
||||
datdba = get_usesysid(dbowner); /* will ereport if no such user */
|
||||
datdba = get_roleid_checked(dbowner);
|
||||
else
|
||||
datdba = GetUserId();
|
||||
|
||||
if (datdba == GetUserId())
|
||||
if (is_member_of_role(GetUserId(), datdba))
|
||||
{
|
||||
/* creating database for self: can be superuser or createdb */
|
||||
if (!superuser() && !have_createdb_privilege())
|
||||
@@ -243,7 +243,7 @@ createdb(const CreatedbStmt *stmt)
|
||||
*/
|
||||
if (!src_istemplate)
|
||||
{
|
||||
if (!superuser() && GetUserId() != src_owner)
|
||||
if (!pg_database_ownercheck(src_dboid, GetUserId()))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
||||
errmsg("permission denied to copy database \"%s\"",
|
||||
@@ -483,7 +483,7 @@ createdb(const CreatedbStmt *stmt)
|
||||
|
||||
new_record[Anum_pg_database_datname - 1] =
|
||||
DirectFunctionCall1(namein, CStringGetDatum(dbname));
|
||||
new_record[Anum_pg_database_datdba - 1] = Int32GetDatum(datdba);
|
||||
new_record[Anum_pg_database_datdba - 1] = ObjectIdGetDatum(datdba);
|
||||
new_record[Anum_pg_database_encoding - 1] = Int32GetDatum(encoding);
|
||||
new_record[Anum_pg_database_datistemplate - 1] = BoolGetDatum(false);
|
||||
new_record[Anum_pg_database_datallowconn - 1] = BoolGetDatum(true);
|
||||
@@ -557,9 +557,8 @@ createdb(const CreatedbStmt *stmt)
|
||||
void
|
||||
dropdb(const char *dbname)
|
||||
{
|
||||
int4 db_owner;
|
||||
bool db_istemplate;
|
||||
Oid db_id;
|
||||
bool db_istemplate;
|
||||
Relation pgdbrel;
|
||||
SysScanDesc pgdbscan;
|
||||
ScanKeyData key;
|
||||
@@ -588,13 +587,13 @@ dropdb(const char *dbname)
|
||||
*/
|
||||
pgdbrel = heap_open(DatabaseRelationId, ExclusiveLock);
|
||||
|
||||
if (!get_db_info(dbname, &db_id, &db_owner, NULL,
|
||||
if (!get_db_info(dbname, &db_id, NULL, NULL,
|
||||
&db_istemplate, NULL, NULL, NULL, NULL, NULL))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_DATABASE),
|
||||
errmsg("database \"%s\" does not exist", dbname)));
|
||||
|
||||
if (GetUserId() != db_owner && !superuser())
|
||||
if (!pg_database_ownercheck(db_id, GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_DATABASE,
|
||||
dbname);
|
||||
|
||||
@@ -818,8 +817,7 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
|
||||
(errcode(ERRCODE_UNDEFINED_DATABASE),
|
||||
errmsg("database \"%s\" does not exist", stmt->dbname)));
|
||||
|
||||
if (!(superuser()
|
||||
|| ((Form_pg_database) GETSTRUCT(tuple))->datdba == GetUserId()))
|
||||
if (!pg_database_ownercheck(HeapTupleGetOid(tuple), GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_DATABASE,
|
||||
stmt->dbname);
|
||||
|
||||
@@ -878,7 +876,7 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
|
||||
* ALTER DATABASE name OWNER TO newowner
|
||||
*/
|
||||
void
|
||||
AlterDatabaseOwner(const char *dbname, AclId newOwnerSysId)
|
||||
AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
|
||||
{
|
||||
HeapTuple tuple;
|
||||
Relation rel;
|
||||
@@ -910,7 +908,7 @@ AlterDatabaseOwner(const char *dbname, AclId newOwnerSysId)
|
||||
* command to have succeeded. This is to be consistent with other
|
||||
* objects.
|
||||
*/
|
||||
if (datForm->datdba != newOwnerSysId)
|
||||
if (datForm->datdba != newOwnerId)
|
||||
{
|
||||
Datum repl_val[Natts_pg_database];
|
||||
char repl_null[Natts_pg_database];
|
||||
@@ -930,7 +928,7 @@ AlterDatabaseOwner(const char *dbname, AclId newOwnerSysId)
|
||||
memset(repl_repl, ' ', sizeof(repl_repl));
|
||||
|
||||
repl_repl[Anum_pg_database_datdba - 1] = 'r';
|
||||
repl_val[Anum_pg_database_datdba - 1] = Int32GetDatum(newOwnerSysId);
|
||||
repl_val[Anum_pg_database_datdba - 1] = ObjectIdGetDatum(newOwnerId);
|
||||
|
||||
/*
|
||||
* Determine the modified ACL for the new owner. This is only
|
||||
@@ -943,7 +941,7 @@ AlterDatabaseOwner(const char *dbname, AclId newOwnerSysId)
|
||||
if (!isNull)
|
||||
{
|
||||
newAcl = aclnewowner(DatumGetAclP(aclDatum),
|
||||
datForm->datdba, newOwnerSysId);
|
||||
datForm->datdba, newOwnerId);
|
||||
repl_repl[Anum_pg_database_datacl - 1] = 'r';
|
||||
repl_val[Anum_pg_database_datacl - 1] = PointerGetDatum(newAcl);
|
||||
}
|
||||
@@ -972,7 +970,7 @@ AlterDatabaseOwner(const char *dbname, AclId newOwnerSysId)
|
||||
*/
|
||||
|
||||
static bool
|
||||
get_db_info(const char *name, Oid *dbIdP, int4 *ownerIdP,
|
||||
get_db_info(const char *name, Oid *dbIdP, Oid *ownerIdP,
|
||||
int *encodingP, bool *dbIsTemplateP, bool *dbAllowConnP,
|
||||
Oid *dbLastSysOidP,
|
||||
TransactionId *dbVacuumXidP, TransactionId *dbFrozenXidP,
|
||||
@@ -1007,7 +1005,7 @@ get_db_info(const char *name, Oid *dbIdP, int4 *ownerIdP,
|
||||
/* oid of the database */
|
||||
if (dbIdP)
|
||||
*dbIdP = HeapTupleGetOid(tuple);
|
||||
/* sysid of the owner */
|
||||
/* oid of the owner */
|
||||
if (ownerIdP)
|
||||
*ownerIdP = dbform->datdba;
|
||||
/* character encoding */
|
||||
@@ -1046,12 +1044,12 @@ have_createdb_privilege(void)
|
||||
bool result = false;
|
||||
HeapTuple utup;
|
||||
|
||||
utup = SearchSysCache(SHADOWSYSID,
|
||||
Int32GetDatum(GetUserId()),
|
||||
utup = SearchSysCache(AUTHOID,
|
||||
ObjectIdGetDatum(GetUserId()),
|
||||
0, 0, 0);
|
||||
if (HeapTupleIsValid(utup))
|
||||
{
|
||||
result = ((Form_pg_shadow) GETSTRUCT(utup))->usecreatedb;
|
||||
result = ((Form_pg_authid) GETSTRUCT(utup))->rolcreatedb;
|
||||
ReleaseSysCache(utup);
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.61 2005/04/14 20:03:23 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.62 2005/06/28 05:08:53 tgl Exp $
|
||||
*
|
||||
* DESCRIPTION
|
||||
* These routines take the parse tree and pick out the
|
||||
@@ -853,7 +853,7 @@ RenameFunction(List *name, List *argtypes, const char *newname)
|
||||
* Change function owner
|
||||
*/
|
||||
void
|
||||
AlterFunctionOwner(List *name, List *argtypes, AclId newOwnerSysId)
|
||||
AlterFunctionOwner(List *name, List *argtypes, Oid newOwnerId)
|
||||
{
|
||||
Oid procOid;
|
||||
HeapTuple tup;
|
||||
@@ -882,7 +882,7 @@ AlterFunctionOwner(List *name, List *argtypes, AclId newOwnerSysId)
|
||||
* If the new owner is the same as the existing owner, consider the
|
||||
* command to have succeeded. This is for dump restoration purposes.
|
||||
*/
|
||||
if (procForm->proowner != newOwnerSysId)
|
||||
if (procForm->proowner != newOwnerId)
|
||||
{
|
||||
Datum repl_val[Natts_pg_proc];
|
||||
char repl_null[Natts_pg_proc];
|
||||
@@ -902,7 +902,7 @@ AlterFunctionOwner(List *name, List *argtypes, AclId newOwnerSysId)
|
||||
memset(repl_repl, ' ', sizeof(repl_repl));
|
||||
|
||||
repl_repl[Anum_pg_proc_proowner - 1] = 'r';
|
||||
repl_val[Anum_pg_proc_proowner - 1] = Int32GetDatum(newOwnerSysId);
|
||||
repl_val[Anum_pg_proc_proowner - 1] = ObjectIdGetDatum(newOwnerId);
|
||||
|
||||
/*
|
||||
* Determine the modified ACL for the new owner. This is only
|
||||
@@ -914,7 +914,7 @@ AlterFunctionOwner(List *name, List *argtypes, AclId newOwnerSysId)
|
||||
if (!isNull)
|
||||
{
|
||||
newAcl = aclnewowner(DatumGetAclP(aclDatum),
|
||||
procForm->proowner, newOwnerSysId);
|
||||
procForm->proowner, newOwnerId);
|
||||
repl_repl[Anum_pg_proc_proacl - 1] = 'r';
|
||||
repl_val[Anum_pg_proc_proacl - 1] = PointerGetDatum(newAcl);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.32 2005/04/14 20:03:23 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.33 2005/06/28 05:08:53 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -321,7 +321,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
|
||||
namestrcpy(&opcName, opcname);
|
||||
values[i++] = NameGetDatum(&opcName); /* opcname */
|
||||
values[i++] = ObjectIdGetDatum(namespaceoid); /* opcnamespace */
|
||||
values[i++] = Int32GetDatum(GetUserId()); /* opcowner */
|
||||
values[i++] = ObjectIdGetDatum(GetUserId()); /* opcowner */
|
||||
values[i++] = ObjectIdGetDatum(typeoid); /* opcintype */
|
||||
values[i++] = BoolGetDatum(stmt->isDefault); /* opcdefault */
|
||||
values[i++] = ObjectIdGetDatum(storageoid); /* opckeytype */
|
||||
@@ -880,7 +880,7 @@ RenameOpClass(List *name, const char *access_method, const char *newname)
|
||||
* Change opclass owner
|
||||
*/
|
||||
void
|
||||
AlterOpClassOwner(List *name, const char *access_method, AclId newOwnerSysId)
|
||||
AlterOpClassOwner(List *name, const char *access_method, Oid newOwnerId)
|
||||
{
|
||||
Oid opcOid;
|
||||
Oid amOid;
|
||||
@@ -945,7 +945,7 @@ AlterOpClassOwner(List *name, const char *access_method, AclId newOwnerSysId)
|
||||
* If the new owner is the same as the existing owner, consider the
|
||||
* command to have succeeded. This is for dump restoration purposes.
|
||||
*/
|
||||
if (opcForm->opcowner != newOwnerSysId)
|
||||
if (opcForm->opcowner != newOwnerId)
|
||||
{
|
||||
/* Otherwise, must be superuser to change object ownership */
|
||||
if (!superuser())
|
||||
@@ -957,7 +957,7 @@ AlterOpClassOwner(List *name, const char *access_method, AclId newOwnerSysId)
|
||||
* Modify the owner --- okay to scribble on tup because it's a
|
||||
* copy
|
||||
*/
|
||||
opcForm->opcowner = newOwnerSysId;
|
||||
opcForm->opcowner = newOwnerId;
|
||||
|
||||
simple_heap_update(rel, &tup->t_self, tup);
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/operatorcmds.c,v 1.21 2005/04/14 20:03:24 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/operatorcmds.c,v 1.22 2005/06/28 05:08:54 tgl Exp $
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The "DefineFoo" routines take the parse tree and pick out the
|
||||
@@ -269,7 +269,7 @@ RemoveOperatorById(Oid operOid)
|
||||
*/
|
||||
void
|
||||
AlterOperatorOwner(List *name, TypeName *typeName1, TypeName *typeName2,
|
||||
AclId newOwnerSysId)
|
||||
Oid newOwnerId)
|
||||
{
|
||||
Oid operOid;
|
||||
HeapTuple tup;
|
||||
@@ -293,7 +293,7 @@ AlterOperatorOwner(List *name, TypeName *typeName1, TypeName *typeName2,
|
||||
* If the new owner is the same as the existing owner, consider the
|
||||
* command to have succeeded. This is for dump restoration purposes.
|
||||
*/
|
||||
if (oprForm->oprowner != newOwnerSysId)
|
||||
if (oprForm->oprowner != newOwnerId)
|
||||
{
|
||||
/* Otherwise, must be superuser to change object ownership */
|
||||
if (!superuser())
|
||||
@@ -305,7 +305,7 @@ AlterOperatorOwner(List *name, TypeName *typeName1, TypeName *typeName2,
|
||||
* Modify the owner --- okay to scribble on tup because it's a
|
||||
* copy
|
||||
*/
|
||||
oprForm->oprowner = newOwnerSysId;
|
||||
oprForm->oprowner = newOwnerId;
|
||||
|
||||
simple_heap_update(rel, &tup->t_self, tup);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/schemacmds.c,v 1.30 2005/06/21 00:58:15 neilc Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/schemacmds.c,v 1.31 2005/06/28 05:08:54 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -42,11 +42,11 @@ CreateSchemaCommand(CreateSchemaStmt *stmt)
|
||||
Oid namespaceId;
|
||||
List *parsetree_list;
|
||||
ListCell *parsetree_item;
|
||||
AclId owner_userid;
|
||||
AclId saved_userid;
|
||||
Oid owner_uid;
|
||||
Oid saved_uid;
|
||||
AclResult aclresult;
|
||||
|
||||
saved_userid = GetUserId();
|
||||
saved_uid = GetUserId();
|
||||
|
||||
/*
|
||||
* Figure out user identities.
|
||||
@@ -54,12 +54,11 @@ CreateSchemaCommand(CreateSchemaStmt *stmt)
|
||||
|
||||
if (!authId)
|
||||
{
|
||||
owner_userid = saved_userid;
|
||||
owner_uid = saved_uid;
|
||||
}
|
||||
else if (superuser())
|
||||
{
|
||||
/* The following will error out if user does not exist */
|
||||
owner_userid = get_usesysid(authId);
|
||||
owner_uid = get_roleid_checked(authId);
|
||||
|
||||
/*
|
||||
* Set the current user to the requested authorization so that
|
||||
@@ -67,15 +66,15 @@ CreateSchemaCommand(CreateSchemaStmt *stmt)
|
||||
* (This will revert to session user on error or at the end of
|
||||
* this routine.)
|
||||
*/
|
||||
SetUserId(owner_userid);
|
||||
SetUserId(owner_uid);
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *owner_name;
|
||||
|
||||
/* not superuser */
|
||||
owner_userid = saved_userid;
|
||||
owner_name = GetUserNameFromId(owner_userid);
|
||||
owner_uid = saved_uid;
|
||||
owner_name = GetUserNameFromId(owner_uid);
|
||||
if (strcmp(authId, owner_name) != 0)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
||||
@@ -87,7 +86,7 @@ CreateSchemaCommand(CreateSchemaStmt *stmt)
|
||||
/*
|
||||
* Permissions checks.
|
||||
*/
|
||||
aclresult = pg_database_aclcheck(MyDatabaseId, saved_userid, ACL_CREATE);
|
||||
aclresult = pg_database_aclcheck(MyDatabaseId, saved_uid, ACL_CREATE);
|
||||
if (aclresult != ACLCHECK_OK)
|
||||
aclcheck_error(aclresult, ACL_KIND_DATABASE,
|
||||
get_database_name(MyDatabaseId));
|
||||
@@ -99,7 +98,7 @@ CreateSchemaCommand(CreateSchemaStmt *stmt)
|
||||
errdetail("The prefix \"pg_\" is reserved for system schemas.")));
|
||||
|
||||
/* Create the schema's namespace */
|
||||
namespaceId = NamespaceCreate(schemaName, owner_userid);
|
||||
namespaceId = NamespaceCreate(schemaName, owner_uid);
|
||||
|
||||
/* Advance cmd counter to make the namespace visible */
|
||||
CommandCounterIncrement();
|
||||
@@ -149,7 +148,7 @@ CreateSchemaCommand(CreateSchemaStmt *stmt)
|
||||
PopSpecialNamespace(namespaceId);
|
||||
|
||||
/* Reset current user */
|
||||
SetUserId(saved_userid);
|
||||
SetUserId(saved_uid);
|
||||
}
|
||||
|
||||
|
||||
@@ -279,7 +278,7 @@ RenameSchema(const char *oldname, const char *newname)
|
||||
* Change schema owner
|
||||
*/
|
||||
void
|
||||
AlterSchemaOwner(const char *name, AclId newOwnerSysId)
|
||||
AlterSchemaOwner(const char *name, Oid newOwnerId)
|
||||
{
|
||||
HeapTuple tup;
|
||||
Relation rel;
|
||||
@@ -300,7 +299,7 @@ AlterSchemaOwner(const char *name, AclId newOwnerSysId)
|
||||
* If the new owner is the same as the existing owner, consider the
|
||||
* command to have succeeded. This is for dump restoration purposes.
|
||||
*/
|
||||
if (nspForm->nspowner != newOwnerSysId)
|
||||
if (nspForm->nspowner != newOwnerId)
|
||||
{
|
||||
Datum repl_val[Natts_pg_namespace];
|
||||
char repl_null[Natts_pg_namespace];
|
||||
@@ -320,7 +319,7 @@ AlterSchemaOwner(const char *name, AclId newOwnerSysId)
|
||||
memset(repl_repl, ' ', sizeof(repl_repl));
|
||||
|
||||
repl_repl[Anum_pg_namespace_nspowner - 1] = 'r';
|
||||
repl_val[Anum_pg_namespace_nspowner - 1] = Int32GetDatum(newOwnerSysId);
|
||||
repl_val[Anum_pg_namespace_nspowner - 1] = ObjectIdGetDatum(newOwnerId);
|
||||
|
||||
/*
|
||||
* Determine the modified ACL for the new owner. This is only
|
||||
@@ -332,7 +331,7 @@ AlterSchemaOwner(const char *name, AclId newOwnerSysId)
|
||||
if (!isNull)
|
||||
{
|
||||
newAcl = aclnewowner(DatumGetAclP(aclDatum),
|
||||
nspForm->nspowner, newOwnerSysId);
|
||||
nspForm->nspowner, newOwnerId);
|
||||
repl_repl[Anum_pg_namespace_nspacl - 1] = 'r';
|
||||
repl_val[Anum_pg_namespace_nspacl - 1] = PointerGetDatum(newAcl);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.161 2005/06/06 20:22:57 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.162 2005/06/28 05:08:54 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -231,9 +231,9 @@ static void ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,
|
||||
const char *colName, TypeName *typename);
|
||||
static void ATPostAlterTypeCleanup(List **wqueue, AlteredTableInfo *tab);
|
||||
static void ATPostAlterTypeParse(char *cmd, List **wqueue);
|
||||
static void ATExecChangeOwner(Oid relationOid, int32 newOwnerSysId);
|
||||
static void ATExecChangeOwner(Oid relationOid, Oid newOwnerId);
|
||||
static void change_owner_recurse_to_sequences(Oid relationOid,
|
||||
int32 newOwnerSysId);
|
||||
Oid newOwnerId);
|
||||
static void ATExecClusterOn(Relation rel, const char *indexName);
|
||||
static void ATExecDropCluster(Relation rel);
|
||||
static void ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel,
|
||||
@@ -2133,8 +2133,8 @@ ATExecCmd(AlteredTableInfo *tab, Relation rel, AlterTableCmd *cmd)
|
||||
AlterTableCreateToastTable(RelationGetRelid(rel), false);
|
||||
break;
|
||||
case AT_ChangeOwner: /* ALTER OWNER */
|
||||
/* get_usesysid raises an error if no such user */
|
||||
ATExecChangeOwner(RelationGetRelid(rel), get_usesysid(cmd->name));
|
||||
ATExecChangeOwner(RelationGetRelid(rel),
|
||||
get_roleid_checked(cmd->name));
|
||||
break;
|
||||
case AT_ClusterOn: /* CLUSTER ON */
|
||||
ATExecClusterOn(rel, cmd->name);
|
||||
@@ -5233,7 +5233,7 @@ ATPostAlterTypeParse(char *cmd, List **wqueue)
|
||||
* ALTER TABLE OWNER
|
||||
*/
|
||||
static void
|
||||
ATExecChangeOwner(Oid relationOid, int32 newOwnerSysId)
|
||||
ATExecChangeOwner(Oid relationOid, Oid newOwnerId)
|
||||
{
|
||||
Relation target_rel;
|
||||
Relation class_rel;
|
||||
@@ -5277,7 +5277,7 @@ ATExecChangeOwner(Oid relationOid, int32 newOwnerSysId)
|
||||
* If the new owner is the same as the existing owner, consider the
|
||||
* command to have succeeded. This is for dump restoration purposes.
|
||||
*/
|
||||
if (tuple_class->relowner != newOwnerSysId)
|
||||
if (tuple_class->relowner != newOwnerId)
|
||||
{
|
||||
Datum repl_val[Natts_pg_class];
|
||||
char repl_null[Natts_pg_class];
|
||||
@@ -5297,7 +5297,7 @@ ATExecChangeOwner(Oid relationOid, int32 newOwnerSysId)
|
||||
memset(repl_repl, ' ', sizeof(repl_repl));
|
||||
|
||||
repl_repl[Anum_pg_class_relowner - 1] = 'r';
|
||||
repl_val[Anum_pg_class_relowner - 1] = Int32GetDatum(newOwnerSysId);
|
||||
repl_val[Anum_pg_class_relowner - 1] = ObjectIdGetDatum(newOwnerId);
|
||||
|
||||
/*
|
||||
* Determine the modified ACL for the new owner. This is only
|
||||
@@ -5309,7 +5309,7 @@ ATExecChangeOwner(Oid relationOid, int32 newOwnerSysId)
|
||||
if (!isNull)
|
||||
{
|
||||
newAcl = aclnewowner(DatumGetAclP(aclDatum),
|
||||
tuple_class->relowner, newOwnerSysId);
|
||||
tuple_class->relowner, newOwnerId);
|
||||
repl_repl[Anum_pg_class_relacl - 1] = 'r';
|
||||
repl_val[Anum_pg_class_relacl - 1] = PointerGetDatum(newAcl);
|
||||
}
|
||||
@@ -5337,7 +5337,7 @@ ATExecChangeOwner(Oid relationOid, int32 newOwnerSysId)
|
||||
|
||||
/* For each index, recursively change its ownership */
|
||||
foreach(i, index_oid_list)
|
||||
ATExecChangeOwner(lfirst_oid(i), newOwnerSysId);
|
||||
ATExecChangeOwner(lfirst_oid(i), newOwnerId);
|
||||
|
||||
list_free(index_oid_list);
|
||||
}
|
||||
@@ -5346,10 +5346,10 @@ ATExecChangeOwner(Oid relationOid, int32 newOwnerSysId)
|
||||
{
|
||||
/* If it has a toast table, recurse to change its ownership */
|
||||
if (tuple_class->reltoastrelid != InvalidOid)
|
||||
ATExecChangeOwner(tuple_class->reltoastrelid, newOwnerSysId);
|
||||
ATExecChangeOwner(tuple_class->reltoastrelid, newOwnerId);
|
||||
|
||||
/* If it has dependent sequences, recurse to change them too */
|
||||
change_owner_recurse_to_sequences(relationOid, newOwnerSysId);
|
||||
change_owner_recurse_to_sequences(relationOid, newOwnerId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5366,7 +5366,7 @@ ATExecChangeOwner(Oid relationOid, int32 newOwnerSysId)
|
||||
* ownership.
|
||||
*/
|
||||
static void
|
||||
change_owner_recurse_to_sequences(Oid relationOid, int32 newOwnerSysId)
|
||||
change_owner_recurse_to_sequences(Oid relationOid, Oid newOwnerId)
|
||||
{
|
||||
Relation depRel;
|
||||
SysScanDesc scan;
|
||||
@@ -5416,7 +5416,7 @@ change_owner_recurse_to_sequences(Oid relationOid, int32 newOwnerSysId)
|
||||
}
|
||||
|
||||
/* We don't need to close the sequence while we alter it. */
|
||||
ATExecChangeOwner(depForm->objid, newOwnerSysId);
|
||||
ATExecChangeOwner(depForm->objid, newOwnerId);
|
||||
|
||||
/* Now we can close it. Keep the lock till end of transaction. */
|
||||
relation_close(seqRel, NoLock);
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.22 2005/06/19 21:34:01 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.23 2005/06/28 05:08:54 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -208,7 +208,7 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
|
||||
Oid tablespaceoid;
|
||||
char *location;
|
||||
char *linkloc;
|
||||
AclId ownerid;
|
||||
Oid ownerId;
|
||||
|
||||
/* validate */
|
||||
|
||||
@@ -225,12 +225,9 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
|
||||
|
||||
/* However, the eventual owner of the tablespace need not be */
|
||||
if (stmt->owner)
|
||||
{
|
||||
/* No need to check result, get_usesysid() does that */
|
||||
ownerid = get_usesysid(stmt->owner);
|
||||
}
|
||||
ownerId = get_roleid_checked(stmt->owner);
|
||||
else
|
||||
ownerid = GetUserId();
|
||||
ownerId = GetUserId();
|
||||
|
||||
/* Unix-ify the offered path, and strip any trailing slashes */
|
||||
location = pstrdup(stmt->location);
|
||||
@@ -297,7 +294,7 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
|
||||
values[Anum_pg_tablespace_spcname - 1] =
|
||||
DirectFunctionCall1(namein, CStringGetDatum(stmt->tablespacename));
|
||||
values[Anum_pg_tablespace_spcowner - 1] =
|
||||
Int32GetDatum(ownerid);
|
||||
ObjectIdGetDatum(ownerId);
|
||||
values[Anum_pg_tablespace_spclocation - 1] =
|
||||
DirectFunctionCall1(textin, CStringGetDatum(location));
|
||||
nulls[Anum_pg_tablespace_spcacl - 1] = 'n';
|
||||
@@ -426,9 +423,8 @@ DropTableSpace(DropTableSpaceStmt *stmt)
|
||||
|
||||
tablespaceoid = HeapTupleGetOid(tuple);
|
||||
|
||||
/* Must be superuser or owner */
|
||||
if (GetUserId() != ((Form_pg_tablespace) GETSTRUCT(tuple))->spcowner &&
|
||||
!superuser())
|
||||
/* Must be tablespace owner */
|
||||
if (!pg_tablespace_ownercheck(tablespaceoid, GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TABLESPACE,
|
||||
tablespacename);
|
||||
|
||||
@@ -711,8 +707,8 @@ RenameTableSpace(const char *oldname, const char *newname)
|
||||
|
||||
heap_endscan(scan);
|
||||
|
||||
/* Must be owner or superuser */
|
||||
if (newform->spcowner != GetUserId() && !superuser())
|
||||
/* Must be owner */
|
||||
if (!pg_tablespace_ownercheck(HeapTupleGetOid(newtuple), GetUserId()))
|
||||
aclcheck_error(ACLCHECK_NO_PRIV, ACL_KIND_TABLESPACE, oldname);
|
||||
|
||||
/* Validate new name */
|
||||
@@ -750,7 +746,7 @@ RenameTableSpace(const char *oldname, const char *newname)
|
||||
* Change tablespace owner
|
||||
*/
|
||||
void
|
||||
AlterTableSpaceOwner(const char *name, AclId newOwnerSysId)
|
||||
AlterTableSpaceOwner(const char *name, Oid newOwnerId)
|
||||
{
|
||||
Relation rel;
|
||||
ScanKeyData entry[1];
|
||||
@@ -778,7 +774,7 @@ AlterTableSpaceOwner(const char *name, AclId newOwnerSysId)
|
||||
* If the new owner is the same as the existing owner, consider the
|
||||
* command to have succeeded. This is for dump restoration purposes.
|
||||
*/
|
||||
if (spcForm->spcowner != newOwnerSysId)
|
||||
if (spcForm->spcowner != newOwnerId)
|
||||
{
|
||||
Datum repl_val[Natts_pg_tablespace];
|
||||
char repl_null[Natts_pg_tablespace];
|
||||
@@ -798,7 +794,7 @@ AlterTableSpaceOwner(const char *name, AclId newOwnerSysId)
|
||||
memset(repl_repl, ' ', sizeof(repl_repl));
|
||||
|
||||
repl_repl[Anum_pg_tablespace_spcowner - 1] = 'r';
|
||||
repl_val[Anum_pg_tablespace_spcowner - 1] = Int32GetDatum(newOwnerSysId);
|
||||
repl_val[Anum_pg_tablespace_spcowner - 1] = ObjectIdGetDatum(newOwnerId);
|
||||
|
||||
/*
|
||||
* Determine the modified ACL for the new owner. This is only
|
||||
@@ -811,7 +807,7 @@ AlterTableSpaceOwner(const char *name, AclId newOwnerSysId)
|
||||
if (!isNull)
|
||||
{
|
||||
newAcl = aclnewowner(DatumGetAclP(aclDatum),
|
||||
spcForm->spcowner, newOwnerSysId);
|
||||
spcForm->spcowner, newOwnerId);
|
||||
repl_repl[Anum_pg_tablespace_spcacl - 1] = 'r';
|
||||
repl_val[Anum_pg_tablespace_spcacl - 1] = PointerGetDatum(newAcl);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.72 2005/05/06 17:24:53 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.73 2005/06/28 05:08:54 tgl Exp $
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The "DefineFoo" routines take the parse tree and pick out the
|
||||
@@ -2016,7 +2016,7 @@ GetDomainConstraints(Oid typeOid)
|
||||
* Change the owner of a type.
|
||||
*/
|
||||
void
|
||||
AlterTypeOwner(List *names, AclId newOwnerSysId)
|
||||
AlterTypeOwner(List *names, Oid newOwnerId)
|
||||
{
|
||||
TypeName *typename;
|
||||
Oid typeOid;
|
||||
@@ -2063,7 +2063,7 @@ AlterTypeOwner(List *names, AclId newOwnerSysId)
|
||||
* If the new owner is the same as the existing owner, consider the
|
||||
* command to have succeeded. This is for dump restoration purposes.
|
||||
*/
|
||||
if (typTup->typowner != newOwnerSysId)
|
||||
if (typTup->typowner != newOwnerId)
|
||||
{
|
||||
/* Otherwise, must be superuser to change object ownership */
|
||||
if (!superuser())
|
||||
@@ -2075,7 +2075,7 @@ AlterTypeOwner(List *names, AclId newOwnerSysId)
|
||||
* Modify the owner --- okay to scribble on typTup because it's a
|
||||
* copy
|
||||
*/
|
||||
typTup->typowner = newOwnerSysId;
|
||||
typTup->typowner = newOwnerId;
|
||||
|
||||
simple_heap_update(rel, &tup->t_self, tup);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/variable.c,v 1.108 2005/06/09 21:52:07 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/variable.c,v 1.109 2005/06/28 05:08:55 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <ctype.h>
|
||||
|
||||
#include "access/xact.h"
|
||||
#include "catalog/pg_shadow.h"
|
||||
#include "catalog/pg_authid.h"
|
||||
#include "commands/variable.h"
|
||||
#include "miscadmin.h"
|
||||
#include "parser/scansup.h"
|
||||
@@ -567,46 +567,46 @@ assign_client_encoding(const char *value, bool doit, GucSource source)
|
||||
* SET SESSION AUTHORIZATION
|
||||
*
|
||||
* When resetting session auth after an error, we can't expect to do catalog
|
||||
* lookups. Hence, the stored form of the value must provide a numeric userid
|
||||
* lookups. Hence, the stored form of the value must provide a numeric oid
|
||||
* that can be re-used directly. We store the string in the form of
|
||||
* NAMEDATALEN 'x's, followed by T or F to indicate superuserness, followed
|
||||
* by the numeric userid, followed by a comma, followed by the user name.
|
||||
* This cannot be confused with a plain user name because of the NAMEDATALEN
|
||||
* by the numeric oid, followed by a comma, followed by the role name.
|
||||
* This cannot be confused with a plain role name because of the NAMEDATALEN
|
||||
* limit on names, so we can tell whether we're being passed an initial
|
||||
* username or a saved/restored value.
|
||||
* role name or a saved/restored value.
|
||||
*/
|
||||
extern char *session_authorization_string; /* in guc.c */
|
||||
|
||||
const char *
|
||||
assign_session_authorization(const char *value, bool doit, GucSource source)
|
||||
{
|
||||
AclId usesysid = 0;
|
||||
Oid roleid = InvalidOid;
|
||||
bool is_superuser = false;
|
||||
const char *actual_username = NULL;
|
||||
const char *actual_rolename = NULL;
|
||||
char *result;
|
||||
|
||||
if (strspn(value, "x") == NAMEDATALEN &&
|
||||
(value[NAMEDATALEN] == 'T' || value[NAMEDATALEN] == 'F'))
|
||||
{
|
||||
/* might be a saved userid string */
|
||||
AclId savedsysid;
|
||||
Oid savedoid;
|
||||
char *endptr;
|
||||
|
||||
savedsysid = (AclId) strtoul(value + NAMEDATALEN + 1, &endptr, 10);
|
||||
savedoid = (Oid) strtoul(value + NAMEDATALEN + 1, &endptr, 10);
|
||||
|
||||
if (endptr != value + NAMEDATALEN + 1 && *endptr == ',')
|
||||
{
|
||||
/* syntactically valid, so break out the data */
|
||||
usesysid = savedsysid;
|
||||
roleid = savedoid;
|
||||
is_superuser = (value[NAMEDATALEN] == 'T');
|
||||
actual_username = endptr + 1;
|
||||
actual_rolename = endptr + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (usesysid == 0)
|
||||
if (roleid == InvalidOid)
|
||||
{
|
||||
/* not a saved ID, so look it up */
|
||||
HeapTuple userTup;
|
||||
HeapTuple roleTup;
|
||||
|
||||
if (!IsTransactionState())
|
||||
{
|
||||
@@ -618,38 +618,38 @@ assign_session_authorization(const char *value, bool doit, GucSource source)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
userTup = SearchSysCache(SHADOWNAME,
|
||||
roleTup = SearchSysCache(AUTHNAME,
|
||||
PointerGetDatum(value),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(userTup))
|
||||
if (!HeapTupleIsValid(roleTup))
|
||||
{
|
||||
if (source >= PGC_S_INTERACTIVE)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("user \"%s\" does not exist", value)));
|
||||
errmsg("role \"%s\" does not exist", value)));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
usesysid = ((Form_pg_shadow) GETSTRUCT(userTup))->usesysid;
|
||||
is_superuser = ((Form_pg_shadow) GETSTRUCT(userTup))->usesuper;
|
||||
actual_username = value;
|
||||
roleid = HeapTupleGetOid(roleTup);
|
||||
is_superuser = ((Form_pg_authid) GETSTRUCT(roleTup))->rolsuper;
|
||||
actual_rolename = value;
|
||||
|
||||
ReleaseSysCache(userTup);
|
||||
ReleaseSysCache(roleTup);
|
||||
}
|
||||
|
||||
if (doit)
|
||||
SetSessionAuthorization(usesysid, is_superuser);
|
||||
SetSessionAuthorization(roleid, is_superuser);
|
||||
|
||||
result = (char *) malloc(NAMEDATALEN + 32 + strlen(actual_username));
|
||||
result = (char *) malloc(NAMEDATALEN + 32 + strlen(actual_rolename));
|
||||
if (!result)
|
||||
return NULL;
|
||||
|
||||
memset(result, 'x', NAMEDATALEN);
|
||||
|
||||
sprintf(result + NAMEDATALEN, "%c%lu,%s",
|
||||
sprintf(result + NAMEDATALEN, "%c%u,%s",
|
||||
is_superuser ? 'T' : 'F',
|
||||
(unsigned long) usesysid,
|
||||
actual_username);
|
||||
roleid,
|
||||
actual_rolename);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -662,13 +662,13 @@ show_session_authorization(void)
|
||||
* assign_session_authorization
|
||||
*/
|
||||
const char *value = session_authorization_string;
|
||||
AclId savedsysid;
|
||||
Oid savedoid;
|
||||
char *endptr;
|
||||
|
||||
Assert(strspn(value, "x") == NAMEDATALEN &&
|
||||
(value[NAMEDATALEN] == 'T' || value[NAMEDATALEN] == 'F'));
|
||||
|
||||
savedsysid = (AclId) strtoul(value + NAMEDATALEN + 1, &endptr, 10);
|
||||
savedoid = (Oid) strtoul(value + NAMEDATALEN + 1, &endptr, 10);
|
||||
|
||||
Assert(endptr != value + NAMEDATALEN + 1 && *endptr == ',');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user