mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Extend object access hook framework to support arguments, and DROP.
This allows loadable modules to get control at drop time, perhaps for the purpose of performing additional security checks or to log the event. The initial purpose of this code is to support sepgsql, but other applications should be possible as well. KaiGai Kohei, reviewed by me.
This commit is contained in:
@@ -515,7 +515,8 @@ createdb(const CreatedbStmt *stmt)
|
||||
copyTemplateDependencies(src_dboid, dboid);
|
||||
|
||||
/* Post creation hook for new database */
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE, DatabaseRelationId, dboid, 0);
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE,
|
||||
DatabaseRelationId, dboid, 0, NULL);
|
||||
|
||||
/*
|
||||
* Force a checkpoint before starting the copy. This will force dirty
|
||||
@@ -777,6 +778,15 @@ dropdb(const char *dbname, bool missing_ok)
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_DATABASE,
|
||||
dbname);
|
||||
|
||||
/* DROP hook for the database being removed */
|
||||
if (object_access_hook)
|
||||
{
|
||||
ObjectAccessDrop drop_arg;
|
||||
memset(&drop_arg, 0, sizeof(ObjectAccessDrop));
|
||||
InvokeObjectAccessHook(OAT_DROP,
|
||||
DatabaseRelationId, db_id, 0, &drop_arg);
|
||||
}
|
||||
|
||||
/*
|
||||
* Disallow dropping a DB that is marked istemplate. This is just to
|
||||
* prevent people from accidentally dropping template0 or template1; they
|
||||
|
||||
@@ -1558,7 +1558,7 @@ InsertExtensionTuple(const char *extName, Oid extOwner,
|
||||
}
|
||||
/* Post creation hook for new extension */
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE,
|
||||
ExtensionRelationId, extensionOid, 0);
|
||||
ExtensionRelationId, extensionOid, 0, NULL);
|
||||
|
||||
return extensionOid;
|
||||
}
|
||||
|
||||
@@ -666,7 +666,7 @@ CreateForeignDataWrapper(CreateFdwStmt *stmt)
|
||||
|
||||
/* Post creation hook for new foreign data wrapper */
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE,
|
||||
ForeignDataWrapperRelationId, fdwId, 0);
|
||||
ForeignDataWrapperRelationId, fdwId, 0, NULL);
|
||||
|
||||
heap_close(rel, RowExclusiveLock);
|
||||
}
|
||||
@@ -962,7 +962,8 @@ CreateForeignServer(CreateForeignServerStmt *stmt)
|
||||
recordDependencyOnCurrentExtension(&myself, false);
|
||||
|
||||
/* Post creation hook for new foreign server */
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE, ForeignServerRelationId, srvId, 0);
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE,
|
||||
ForeignServerRelationId, srvId, 0, NULL);
|
||||
|
||||
heap_close(rel, RowExclusiveLock);
|
||||
}
|
||||
@@ -1202,7 +1203,8 @@ CreateUserMapping(CreateUserMappingStmt *stmt)
|
||||
recordDependencyOnCurrentExtension(&myself, false);
|
||||
|
||||
/* Post creation hook for new user mapping */
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE, UserMappingRelationId, umId, 0);
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE,
|
||||
UserMappingRelationId, umId, 0, NULL);
|
||||
|
||||
heap_close(rel, RowExclusiveLock);
|
||||
}
|
||||
|
||||
@@ -1759,7 +1759,8 @@ CreateCast(CreateCastStmt *stmt)
|
||||
recordDependencyOnCurrentExtension(&myself, false);
|
||||
|
||||
/* Post creation hook for new cast */
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE, CastRelationId, castid, 0);
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE,
|
||||
CastRelationId, castid, 0, NULL);
|
||||
|
||||
heap_freetuple(tuple);
|
||||
|
||||
|
||||
@@ -314,7 +314,7 @@ CreateOpFamily(char *amname, char *opfname, Oid namespaceoid, Oid amoid)
|
||||
|
||||
/* Post creation hook for new operator family */
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE,
|
||||
OperatorFamilyRelationId, opfamilyoid, 0);
|
||||
OperatorFamilyRelationId, opfamilyoid, 0, NULL);
|
||||
|
||||
heap_close(rel, RowExclusiveLock);
|
||||
|
||||
@@ -717,7 +717,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
|
||||
|
||||
/* Post creation hook for new operator class */
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE,
|
||||
OperatorClassRelationId, opclassoid, 0);
|
||||
OperatorClassRelationId, opclassoid, 0, NULL);
|
||||
|
||||
heap_close(rel, RowExclusiveLock);
|
||||
}
|
||||
|
||||
@@ -428,7 +428,7 @@ create_proc_lang(const char *languageName, bool replace,
|
||||
|
||||
/* Post creation hook for new procedural language */
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE,
|
||||
LanguageRelationId, myself.objectId, 0);
|
||||
LanguageRelationId, myself.objectId, 0, NULL);
|
||||
|
||||
heap_close(rel, RowExclusiveLock);
|
||||
}
|
||||
|
||||
@@ -4382,7 +4382,7 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
|
||||
|
||||
/* Post creation hook for new attribute */
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE,
|
||||
RelationRelationId, myrelid, newattnum);
|
||||
RelationRelationId, myrelid, newattnum, NULL);
|
||||
|
||||
heap_close(pgclass, RowExclusiveLock);
|
||||
|
||||
|
||||
@@ -330,7 +330,7 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
|
||||
|
||||
/* Post creation hook for new tablespace */
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE,
|
||||
TableSpaceRelationId, tablespaceoid, 0);
|
||||
TableSpaceRelationId, tablespaceoid, 0, NULL);
|
||||
|
||||
create_tablespace_directories(location, tablespaceoid);
|
||||
|
||||
@@ -434,6 +434,15 @@ DropTableSpace(DropTableSpaceStmt *stmt)
|
||||
aclcheck_error(ACLCHECK_NO_PRIV, ACL_KIND_TABLESPACE,
|
||||
tablespacename);
|
||||
|
||||
/* DROP hook for the tablespace being removed */
|
||||
if (object_access_hook)
|
||||
{
|
||||
ObjectAccessDrop drop_arg;
|
||||
memset(&drop_arg, 0, sizeof(ObjectAccessDrop));
|
||||
InvokeObjectAccessHook(OAT_DROP, TableSpaceRelationId,
|
||||
tablespaceoid, 0, &drop_arg);
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove the pg_tablespace tuple (this will roll back if we fail below)
|
||||
*/
|
||||
|
||||
@@ -756,7 +756,7 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
|
||||
|
||||
/* Post creation hook for new trigger */
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE,
|
||||
TriggerRelationId, trigoid, 0);
|
||||
TriggerRelationId, trigoid, 0, NULL);
|
||||
|
||||
/* Keep lock on target rel until end of xact */
|
||||
heap_close(rel, NoLock);
|
||||
|
||||
@@ -271,7 +271,8 @@ DefineTSParser(List *names, List *parameters)
|
||||
makeParserDependencies(tup);
|
||||
|
||||
/* Post creation hook for new text search parser */
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE, TSParserRelationId, prsOid, 0);
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE,
|
||||
TSParserRelationId, prsOid, 0, NULL);
|
||||
|
||||
heap_freetuple(tup);
|
||||
|
||||
@@ -565,7 +566,7 @@ DefineTSDictionary(List *names, List *parameters)
|
||||
|
||||
/* Post creation hook for new text search dictionary */
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE,
|
||||
TSDictionaryRelationId, dictOid, 0);
|
||||
TSDictionaryRelationId, dictOid, 0, NULL);
|
||||
|
||||
heap_freetuple(tup);
|
||||
|
||||
@@ -1036,7 +1037,8 @@ DefineTSTemplate(List *names, List *parameters)
|
||||
makeTSTemplateDependencies(tup);
|
||||
|
||||
/* Post creation hook for new text search template */
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE, TSTemplateRelationId, dictOid, 0);
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE,
|
||||
TSTemplateRelationId, dictOid, 0, NULL);
|
||||
|
||||
heap_freetuple(tup);
|
||||
|
||||
@@ -1419,7 +1421,8 @@ DefineTSConfiguration(List *names, List *parameters)
|
||||
makeConfigurationDependencies(tup, false, mapRel);
|
||||
|
||||
/* Post creation hook for new text search configuration */
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE, TSConfigRelationId, cfgOid, 0);
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE,
|
||||
TSConfigRelationId, cfgOid, 0, NULL);
|
||||
|
||||
heap_freetuple(tup);
|
||||
|
||||
|
||||
@@ -425,7 +425,8 @@ CreateRole(CreateRoleStmt *stmt)
|
||||
GetUserId(), false);
|
||||
|
||||
/* Post creation hook for new role */
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE, AuthIdRelationId, roleid, 0);
|
||||
InvokeObjectAccessHook(OAT_POST_CREATE,
|
||||
AuthIdRelationId, roleid, 0, NULL);
|
||||
|
||||
/*
|
||||
* Close pg_authid, but keep lock till commit.
|
||||
@@ -932,6 +933,15 @@ DropRole(DropRoleStmt *stmt)
|
||||
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
||||
errmsg("must be superuser to drop superusers")));
|
||||
|
||||
/* DROP hook for the role being removed */
|
||||
if (object_access_hook)
|
||||
{
|
||||
ObjectAccessDrop drop_arg;
|
||||
memset(&drop_arg, 0, sizeof(ObjectAccessDrop));
|
||||
InvokeObjectAccessHook(OAT_DROP,
|
||||
AuthIdRelationId, roleid, 0, &drop_arg);
|
||||
}
|
||||
|
||||
/*
|
||||
* Lock the role, so nobody can add dependencies to her while we drop
|
||||
* her. We keep the lock until the end of transaction.
|
||||
|
||||
Reference in New Issue
Block a user