Skip to content

Commit 07d1edb

Browse files
committed
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.
1 parent b149539 commit 07d1edb

23 files changed

+104
-36
lines changed

src/backend/catalog/dependency.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "catalog/heap.h"
2121
#include "catalog/index.h"
2222
#include "catalog/namespace.h"
23+
#include "catalog/objectaccess.h"
2324
#include "catalog/pg_amop.h"
2425
#include "catalog/pg_amproc.h"
2526
#include "catalog/pg_attrdef.h"
@@ -991,6 +992,15 @@ deleteOneObject(const ObjectAddress *object, Relation depRel, int flags)
991992
SysScanDesc scan;
992993
HeapTuple tup;
993994

995+
/* DROP hook of the objects being removed */
996+
if (object_access_hook)
997+
{
998+
ObjectAccessDrop drop_arg;
999+
drop_arg.dropflags = flags;
1000+
InvokeObjectAccessHook(OAT_DROP, object->classId, object->objectId,
1001+
object->objectSubId, &drop_arg);
1002+
}
1003+
9941004
/*
9951005
* First remove any pg_depend records that link from this object to
9961006
* others. (Any records linking to this object should be gone already.)

src/backend/catalog/heap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,8 @@ heap_create_with_catalog(const char *relname,
12861286
}
12871287

12881288
/* Post creation hook for new relation */
1289-
InvokeObjectAccessHook(OAT_POST_CREATE, RelationRelationId, relid, 0);
1289+
InvokeObjectAccessHook(OAT_POST_CREATE,
1290+
RelationRelationId, relid, 0, NULL);
12901291

12911292
/*
12921293
* Store any supplied constraints and defaults.

src/backend/catalog/pg_collation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ CollationCreate(const char *collname, Oid collnamespace,
136136

137137
/* Post creation hook for new collation */
138138
InvokeObjectAccessHook(OAT_POST_CREATE,
139-
CollationRelationId, oid, 0);
139+
CollationRelationId, oid, 0, NULL);
140140

141141
heap_freetuple(tup);
142142
heap_close(rel, RowExclusiveLock);

src/backend/catalog/pg_constraint.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ CreateConstraintEntry(const char *constraintName,
366366
}
367367

368368
/* Post creation hook for new constraint */
369-
InvokeObjectAccessHook(OAT_POST_CREATE, ConstraintRelationId, conOid, 0);
369+
InvokeObjectAccessHook(OAT_POST_CREATE,
370+
ConstraintRelationId, conOid, 0, NULL);
370371

371372
return conOid;
372373
}

src/backend/catalog/pg_conversion.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ ConversionCreate(const char *conname, Oid connamespace,
134134
recordDependencyOnCurrentExtension(&myself, false);
135135

136136
/* Post creation hook for new conversion */
137-
InvokeObjectAccessHook(OAT_POST_CREATE,
138-
ConversionRelationId, HeapTupleGetOid(tup), 0);
137+
InvokeObjectAccessHook(OAT_POST_CREATE, ConversionRelationId,
138+
HeapTupleGetOid(tup), 0, NULL);
139139

140140
heap_freetuple(tup);
141141
heap_close(rel, RowExclusiveLock);

src/backend/catalog/pg_namespace.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ NamespaceCreate(const char *nspName, Oid ownerId, bool isTemp)
9595
recordDependencyOnCurrentExtension(&myself, false);
9696

9797
/* Post creation hook for new schema */
98-
InvokeObjectAccessHook(OAT_POST_CREATE, NamespaceRelationId, nspoid, 0);
98+
InvokeObjectAccessHook(OAT_POST_CREATE,
99+
NamespaceRelationId, nspoid, 0, NULL);
99100

100101
return nspoid;
101102
}

src/backend/catalog/pg_operator.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ OperatorShellMake(const char *operatorName,
275275

276276
/* Post creation hook for new shell operator */
277277
InvokeObjectAccessHook(OAT_POST_CREATE,
278-
OperatorRelationId, operatorObjectId, 0);
278+
OperatorRelationId, operatorObjectId, 0, NULL);
279279

280280
/*
281281
* Make sure the tuple is visible for subsequent lookups/updates.
@@ -544,7 +544,7 @@ OperatorCreate(const char *operatorName,
544544

545545
/* Post creation hook for new operator */
546546
InvokeObjectAccessHook(OAT_POST_CREATE,
547-
OperatorRelationId, operatorObjectId, 0);
547+
OperatorRelationId, operatorObjectId, 0, NULL);
548548

549549
heap_close(pg_operator_desc, RowExclusiveLock);
550550

src/backend/catalog/pg_proc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,8 @@ ProcedureCreate(const char *procedureName,
655655
heap_freetuple(tup);
656656

657657
/* Post creation hook for new function */
658-
InvokeObjectAccessHook(OAT_POST_CREATE, ProcedureRelationId, retval, 0);
658+
InvokeObjectAccessHook(OAT_POST_CREATE,
659+
ProcedureRelationId, retval, 0, NULL);
659660

660661
heap_close(rel, RowExclusiveLock);
661662

src/backend/catalog/pg_type.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
162162
false);
163163

164164
/* Post creation hook for new shell type */
165-
InvokeObjectAccessHook(OAT_POST_CREATE, TypeRelationId, typoid, 0);
165+
InvokeObjectAccessHook(OAT_POST_CREATE,
166+
TypeRelationId, typoid, 0, NULL);
166167

167168
/*
168169
* clean up and return the type-oid
@@ -474,7 +475,8 @@ TypeCreate(Oid newTypeOid,
474475
rebuildDeps);
475476

476477
/* Post creation hook for new type */
477-
InvokeObjectAccessHook(OAT_POST_CREATE, TypeRelationId, typeObjectId, 0);
478+
InvokeObjectAccessHook(OAT_POST_CREATE,
479+
TypeRelationId, typeObjectId, 0, NULL);
478480

479481
/*
480482
* finish up

src/backend/commands/dbcommands.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ createdb(const CreatedbStmt *stmt)
515515
copyTemplateDependencies(src_dboid, dboid);
516516

517517
/* Post creation hook for new database */
518-
InvokeObjectAccessHook(OAT_POST_CREATE, DatabaseRelationId, dboid, 0);
518+
InvokeObjectAccessHook(OAT_POST_CREATE,
519+
DatabaseRelationId, dboid, 0, NULL);
519520

520521
/*
521522
* Force a checkpoint before starting the copy. This will force dirty
@@ -777,6 +778,15 @@ dropdb(const char *dbname, bool missing_ok)
777778
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_DATABASE,
778779
dbname);
779780

781+
/* DROP hook for the database being removed */
782+
if (object_access_hook)
783+
{
784+
ObjectAccessDrop drop_arg;
785+
memset(&drop_arg, 0, sizeof(ObjectAccessDrop));
786+
InvokeObjectAccessHook(OAT_DROP,
787+
DatabaseRelationId, db_id, 0, &drop_arg);
788+
}
789+
780790
/*
781791
* Disallow dropping a DB that is marked istemplate. This is just to
782792
* prevent people from accidentally dropping template0 or template1; they

0 commit comments

Comments
 (0)