aboutsummaryrefslogtreecommitdiff
path: root/src/backend/catalog
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/catalog')
-rw-r--r--src/backend/catalog/Makefile3
-rw-r--r--src/backend/catalog/dependency.c10
-rw-r--r--src/backend/catalog/heap.c10
-rw-r--r--src/backend/catalog/index.c11
-rw-r--r--src/backend/catalog/objectaccess.c63
-rw-r--r--src/backend/catalog/pg_collation.c3
-rw-r--r--src/backend/catalog/pg_constraint.c3
-rw-r--r--src/backend/catalog/pg_conversion.c3
-rw-r--r--src/backend/catalog/pg_namespace.c3
-rw-r--r--src/backend/catalog/pg_operator.c6
-rw-r--r--src/backend/catalog/pg_proc.c3
-rw-r--r--src/backend/catalog/pg_type.c6
12 files changed, 79 insertions, 45 deletions
diff --git a/src/backend/catalog/Makefile b/src/backend/catalog/Makefile
index df6da1f0d33..c4d3f3c1dcc 100644
--- a/src/backend/catalog/Makefile
+++ b/src/backend/catalog/Makefile
@@ -11,7 +11,8 @@ top_builddir = ../../..
include $(top_builddir)/src/Makefile.global
OBJS = catalog.o dependency.o heap.o index.o indexing.o namespace.o aclchk.o \
- objectaddress.o pg_aggregate.o pg_collation.o pg_constraint.o pg_conversion.o \
+ objectaccess.o objectaddress.o pg_aggregate.o pg_collation.o \
+ pg_constraint.o pg_conversion.o \
pg_depend.o pg_enum.o pg_inherits.o pg_largeobject.o pg_namespace.o \
pg_operator.o pg_proc.o pg_range.o pg_db_role_setting.o pg_shdepend.o \
pg_type.o storage.o toasting.o
diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c
index 32f05bbabb0..7b8e0246339 100644
--- a/src/backend/catalog/dependency.c
+++ b/src/backend/catalog/dependency.c
@@ -997,14 +997,8 @@ deleteOneObject(const ObjectAddress *object, Relation *depRel, int flags)
HeapTuple tup;
/* DROP hook of the objects being removed */
- if (object_access_hook)
- {
- ObjectAccessDrop drop_arg;
-
- drop_arg.dropflags = flags;
- InvokeObjectAccessHook(OAT_DROP, object->classId, object->objectId,
- object->objectSubId, &drop_arg);
- }
+ InvokeObjectDropHookArg(object->classId, object->objectId,
+ object->objectSubId, flags);
/*
* Close depRel if we are doing a drop concurrently. The object deletion
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 0ecfc78ed04..04a927dd0c6 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -1293,15 +1293,7 @@ heap_create_with_catalog(const char *relname,
}
/* Post creation hook for new relation */
- if (object_access_hook)
- {
- ObjectAccessPostCreate post_create_args;
-
- memset(&post_create_args, 0, sizeof(ObjectAccessPostCreate));
- post_create_args.is_internal = is_internal;
- (*object_access_hook)(OAT_POST_CREATE, RelationRelationId,
- relid, 0, &post_create_args);
- }
+ InvokeObjectPostCreateHookArg(RelationRelationId, relid, 0, is_internal);
/*
* Store any supplied constraints and defaults.
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 9b339292e49..33a18030b79 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -1028,15 +1028,8 @@ index_create(Relation heapRelation,
}
/* Post creation hook for new index */
- if (object_access_hook)
- {
- ObjectAccessPostCreate post_create_args;
-
- memset(&post_create_args, 0, sizeof(ObjectAccessPostCreate));
- post_create_args.is_internal = is_internal;
- (*object_access_hook)(OAT_POST_CREATE, RelationRelationId,
- indexRelationId, 0, &post_create_args);
- }
+ InvokeObjectPostCreateHookArg(RelationRelationId,
+ indexRelationId, 0, is_internal);
/*
* Advance the command counter so that we can see the newly-entered
diff --git a/src/backend/catalog/objectaccess.c b/src/backend/catalog/objectaccess.c
new file mode 100644
index 00000000000..09f9db5aaf8
--- /dev/null
+++ b/src/backend/catalog/objectaccess.c
@@ -0,0 +1,63 @@
+/* -------------------------------------------------------------------------
+ *
+ * objectaccess.c
+ * functions for object_access_hook on various events
+ *
+ * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * -------------------------------------------------------------------------
+ */
+#include "postgres.h"
+
+#include "catalog/objectaccess.h"
+
+/*
+ * Hook on object accesses. This is intended as infrastructure for security
+ * and logging plugins.
+ */
+object_access_hook_type object_access_hook = NULL;
+
+/*
+ * RunObjectPostCreateHook
+ *
+ * It is entrypoint of OAT_POST_CREATE event
+ */
+void
+RunObjectPostCreateHook(Oid classId, Oid objectId, int subId,
+ bool is_internal)
+{
+ ObjectAccessPostCreate pc_arg;
+
+ /* caller should check, but just in case... */
+ Assert(object_access_hook != NULL);
+
+ memset(&pc_arg, 0, sizeof(ObjectAccessPostCreate));
+ pc_arg.is_internal = is_internal;
+
+ (*object_access_hook)(OAT_POST_CREATE,
+ classId, objectId, subId,
+ (void *) &pc_arg);
+}
+
+/*
+ * RunObjectDropHook
+ *
+ * It is entrypoint of OAT_DROP event
+ */
+void
+RunObjectDropHook(Oid classId, Oid objectId, int subId,
+ int dropflags)
+{
+ ObjectAccessDrop drop_arg;
+
+ /* caller should check, but just in case... */
+ Assert(object_access_hook != NULL);
+
+ memset(&drop_arg, 0, sizeof(ObjectAccessDrop));
+ drop_arg.dropflags = dropflags;
+
+ (*object_access_hook)(OAT_DROP,
+ classId, objectId, subId,
+ (void *) &drop_arg);
+}
diff --git a/src/backend/catalog/pg_collation.c b/src/backend/catalog/pg_collation.c
index 46d6e27d2de..dd0050267f1 100644
--- a/src/backend/catalog/pg_collation.c
+++ b/src/backend/catalog/pg_collation.c
@@ -136,8 +136,7 @@ CollationCreate(const char *collname, Oid collnamespace,
recordDependencyOnCurrentExtension(&myself, false);
/* Post creation hook for new collation */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- CollationRelationId, oid, 0, NULL);
+ InvokeObjectPostCreateHook(CollationRelationId, oid, 0);
heap_freetuple(tup);
heap_close(rel, RowExclusiveLock);
diff --git a/src/backend/catalog/pg_constraint.c b/src/backend/catalog/pg_constraint.c
index 7179fa93922..547c7ee00c6 100644
--- a/src/backend/catalog/pg_constraint.c
+++ b/src/backend/catalog/pg_constraint.c
@@ -367,8 +367,7 @@ CreateConstraintEntry(const char *constraintName,
}
/* Post creation hook for new constraint */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- ConstraintRelationId, conOid, 0, NULL);
+ InvokeObjectPostCreateHook(ConstraintRelationId, conOid, 0);
return conOid;
}
diff --git a/src/backend/catalog/pg_conversion.c b/src/backend/catalog/pg_conversion.c
index 75eafd447d7..45d8e628085 100644
--- a/src/backend/catalog/pg_conversion.c
+++ b/src/backend/catalog/pg_conversion.c
@@ -136,8 +136,7 @@ ConversionCreate(const char *conname, Oid connamespace,
recordDependencyOnCurrentExtension(&myself, false);
/* Post creation hook for new conversion */
- InvokeObjectAccessHook(OAT_POST_CREATE, ConversionRelationId,
- HeapTupleGetOid(tup), 0, NULL);
+ InvokeObjectPostCreateHook(ConversionRelationId, HeapTupleGetOid(tup), 0);
heap_freetuple(tup);
heap_close(rel, RowExclusiveLock);
diff --git a/src/backend/catalog/pg_namespace.c b/src/backend/catalog/pg_namespace.c
index 2948c64d455..8be0558511e 100644
--- a/src/backend/catalog/pg_namespace.c
+++ b/src/backend/catalog/pg_namespace.c
@@ -96,8 +96,7 @@ NamespaceCreate(const char *nspName, Oid ownerId, bool isTemp)
recordDependencyOnCurrentExtension(&myself, false);
/* Post creation hook for new schema */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- NamespaceRelationId, nspoid, 0, NULL);
+ InvokeObjectPostCreateHook(NamespaceRelationId, nspoid, 0);
return nspoid;
}
diff --git a/src/backend/catalog/pg_operator.c b/src/backend/catalog/pg_operator.c
index 7a9148850e7..f8d6bb0e34b 100644
--- a/src/backend/catalog/pg_operator.c
+++ b/src/backend/catalog/pg_operator.c
@@ -275,8 +275,7 @@ OperatorShellMake(const char *operatorName,
heap_freetuple(tup);
/* Post creation hook for new shell operator */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- OperatorRelationId, operatorObjectId, 0, NULL);
+ InvokeObjectPostCreateHook(OperatorRelationId, operatorObjectId, 0);
/*
* Make sure the tuple is visible for subsequent lookups/updates.
@@ -544,8 +543,7 @@ OperatorCreate(const char *operatorName,
makeOperatorDependencies(tup);
/* Post creation hook for new operator */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- OperatorRelationId, operatorObjectId, 0, NULL);
+ InvokeObjectPostCreateHook(OperatorRelationId, operatorObjectId, 0);
heap_close(pg_operator_desc, RowExclusiveLock);
diff --git a/src/backend/catalog/pg_proc.c b/src/backend/catalog/pg_proc.c
index 3570240bf66..0b70adc4795 100644
--- a/src/backend/catalog/pg_proc.c
+++ b/src/backend/catalog/pg_proc.c
@@ -661,8 +661,7 @@ ProcedureCreate(const char *procedureName,
heap_freetuple(tup);
/* Post creation hook for new function */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- ProcedureRelationId, retval, 0, NULL);
+ InvokeObjectPostCreateHook(ProcedureRelationId, retval, 0);
heap_close(rel, RowExclusiveLock);
diff --git a/src/backend/catalog/pg_type.c b/src/backend/catalog/pg_type.c
index 591714f175b..b044400d993 100644
--- a/src/backend/catalog/pg_type.c
+++ b/src/backend/catalog/pg_type.c
@@ -163,8 +163,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
false);
/* Post creation hook for new shell type */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- TypeRelationId, typoid, 0, NULL);
+ InvokeObjectPostCreateHook(TypeRelationId, typoid, 0);
/*
* clean up and return the type-oid
@@ -476,8 +475,7 @@ TypeCreate(Oid newTypeOid,
rebuildDeps);
/* Post creation hook for new type */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- TypeRelationId, typeObjectId, 0, NULL);
+ InvokeObjectPostCreateHook(TypeRelationId, typeObjectId, 0);
/*
* finish up