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
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
}
/* 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.
}
/* 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
--- /dev/null
+/* -------------------------------------------------------------------------
+ *
+ * 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);
+}
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);
}
/* Post creation hook for new constraint */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- ConstraintRelationId, conOid, 0, NULL);
+ InvokeObjectPostCreateHook(ConstraintRelationId, conOid, 0);
return conOid;
}
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);
recordDependencyOnCurrentExtension(&myself, false);
/* Post creation hook for new schema */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- NamespaceRelationId, nspoid, 0, NULL);
+ InvokeObjectPostCreateHook(NamespaceRelationId, nspoid, 0);
return nspoid;
}
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.
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);
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);
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
rebuildDeps);
/* Post creation hook for new type */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- TypeRelationId, typeObjectId, 0, NULL);
+ InvokeObjectPostCreateHook(TypeRelationId, typeObjectId, 0);
/*
* finish up
#include "catalog/pg_aggregate.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
+#include "commands/alter.h"
#include "commands/defrem.h"
#include "miscadmin.h"
#include "parser/parse_func.h"
copyTemplateDependencies(src_dboid, dboid);
/* Post creation hook for new database */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- DatabaseRelationId, dboid, 0, NULL);
+ InvokeObjectPostCreateHook(DatabaseRelationId, dboid, 0);
/*
* Force a checkpoint before starting the copy. This will force dirty
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);
- }
+ InvokeObjectDropHook(DatabaseRelationId, db_id, 0);
/*
* Disallow dropping a DB that is marked istemplate. This is just to
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
/* Post creation hook for new operator family */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- EventTriggerRelationId, trigoid, 0, NULL);
+ InvokeObjectPostCreateHook(EventTriggerRelationId, trigoid, 0);
/* Close pg_event_trigger. */
heap_close(tgrel, RowExclusiveLock);
recordDependencyOn(&myself, &otherext, DEPENDENCY_NORMAL);
}
/* Post creation hook for new extension */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- ExtensionRelationId, extensionOid, 0, NULL);
+ InvokeObjectPostCreateHook(ExtensionRelationId, extensionOid, 0);
return extensionOid;
}
recordDependencyOnCurrentExtension(&myself, false);
/* Post creation hook for new foreign data wrapper */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- ForeignDataWrapperRelationId, fdwId, 0, NULL);
+ InvokeObjectPostCreateHook(ForeignDataWrapperRelationId, fdwId, 0);
heap_close(rel, RowExclusiveLock);
recordDependencyOnCurrentExtension(&myself, false);
/* Post creation hook for new foreign server */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- ForeignServerRelationId, srvId, 0, NULL);
+ InvokeObjectPostCreateHook(ForeignServerRelationId, srvId, 0);
heap_close(rel, RowExclusiveLock);
recordDependencyOnCurrentExtension(&myself, false);
/* Post creation hook for new user mapping */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- UserMappingRelationId, umId, 0, NULL);
+ InvokeObjectPostCreateHook(UserMappingRelationId, umId, 0);
heap_close(rel, RowExclusiveLock);
recordDependencyOnCurrentExtension(&myself, false);
/* Post creation hook for new cast */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- CastRelationId, castid, 0, NULL);
+ InvokeObjectPostCreateHook(CastRelationId, castid, 0);
heap_freetuple(tuple);
recordDependencyOnCurrentExtension(&myself, false);
/* Post creation hook for new operator family */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- OperatorFamilyRelationId, opfamilyoid, 0, NULL);
+ InvokeObjectPostCreateHook(OperatorFamilyRelationId, opfamilyoid, 0);
heap_close(rel, RowExclusiveLock);
recordDependencyOnCurrentExtension(&myself, false);
/* Post creation hook for new operator class */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- OperatorClassRelationId, opclassoid, 0, NULL);
+ InvokeObjectPostCreateHook(OperatorClassRelationId, opclassoid, 0);
heap_close(rel, RowExclusiveLock);
}
/* Post creation hook for new procedural language */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- LanguageRelationId, myself.objectId, 0, NULL);
+ InvokeObjectPostCreateHook(LanguageRelationId, myself.objectId, 0);
heap_close(rel, RowExclusiveLock);
heap_freetuple(reltup);
/* Post creation hook for new attribute */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- RelationRelationId, myrelid, newattnum, NULL);
+ InvokeObjectPostCreateHook(RelationRelationId, myrelid, newattnum);
heap_close(pgclass, RowExclusiveLock);
recordDependencyOnOwner(TableSpaceRelationId, tablespaceoid, ownerId);
/* Post creation hook for new tablespace */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- TableSpaceRelationId, tablespaceoid, 0, NULL);
+ InvokeObjectPostCreateHook(TableSpaceRelationId, tablespaceoid, 0);
create_tablespace_directories(location, tablespaceoid);
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);
- }
+ InvokeObjectDropHook(TableSpaceRelationId, tablespaceoid, 0);
/*
* Remove the pg_tablespace tuple (this will roll back if we fail below)
DEPENDENCY_NORMAL);
/* Post creation hook for new trigger */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- TriggerRelationId, trigoid, 0, NULL);
+ InvokeObjectPostCreateHook(TriggerRelationId, trigoid, 0);
/* Keep lock on target rel until end of xact */
heap_close(rel, NoLock);
makeParserDependencies(tup);
/* Post creation hook for new text search parser */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- TSParserRelationId, prsOid, 0, NULL);
+ InvokeObjectPostCreateHook(TSParserRelationId, prsOid, 0);
heap_freetuple(tup);
makeDictionaryDependencies(tup);
/* Post creation hook for new text search dictionary */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- TSDictionaryRelationId, dictOid, 0, NULL);
+ InvokeObjectPostCreateHook(TSDictionaryRelationId, dictOid, 0);
heap_freetuple(tup);
makeTSTemplateDependencies(tup);
/* Post creation hook for new text search template */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- TSTemplateRelationId, tmplOid, 0, NULL);
+ InvokeObjectPostCreateHook(TSTemplateRelationId, tmplOid, 0);
heap_freetuple(tup);
makeConfigurationDependencies(tup, false, mapRel);
/* Post creation hook for new text search configuration */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- TSConfigRelationId, cfgOid, 0, NULL);
+ InvokeObjectPostCreateHook(TSConfigRelationId, cfgOid, 0);
heap_freetuple(tup);
GetUserId(), false);
/* Post creation hook for new role */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- AuthIdRelationId, roleid, 0, NULL);
+ InvokeObjectPostCreateHook(AuthIdRelationId, roleid, 0);
/*
* Close pg_authid, but keep lock till commit.
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);
- }
+ InvokeObjectDropHook(AuthIdRelationId, roleid, 0);
/*
* Lock the role, so nobody can add dependencies to her while we drop
}
/* Post creation hook for new rule */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- RewriteRelationId, rewriteObjectId, 0, NULL);
+ InvokeObjectPostCreateHook(RewriteRelationId, rewriteObjectId, 0);
heap_close(pg_rewrite_desc, RowExclusiveLock);
lobjId_new, GetUserId());
/* Post creation hook for new large object */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- LargeObjectRelationId, lobjId_new, 0, NULL);
+ InvokeObjectPostCreateHook(LargeObjectRelationId, lobjId_new, 0);
/*
* Advance command counter to make new tuple visible to later operations.
*/
#include "postgres.h"
-#include "catalog/objectaccess.h"
#include "libpq/pqcomm.h"
#include "miscadmin.h"
#include "storage/backendid.h"
bool VacuumCostActive = false;
int GinFuzzySearchLimit = 0;
-
-/*
- * Hook on object accesses. This is intended as infrastructure for security
- * and logging plugins.
- */
-object_access_hook_type object_access_hook = NULL;
{
OAT_POST_CREATE,
OAT_DROP,
+ OAT_POST_ALTER,
} ObjectAccessType;
/*
extern PGDLLIMPORT object_access_hook_type object_access_hook;
-#define InvokeObjectAccessHook(access,classId,objectId,subId,arg) \
+extern void RunObjectPostCreateHook(Oid classId, Oid objectId, int subId,
+ bool is_internal);
+extern void RunObjectDropHook(Oid classId, Oid objectId, int subId,
+ int dropflags);
+
+#define InvokeObjectPostCreateHook(classId,objectId,subId) \
+ InvokeObjectPostCreateHookArg((classId),(objectId),(subId),false)
+#define InvokeObjectPostCreateHookArg(classId,objectId,subId,is_internal) \
+ do { \
+ if (object_access_hook) \
+ RunObjectPostCreateHook((classId),(objectId),(subId), \
+ (is_internal)); \
+ } while(0)
+
+#define InvokeObjectDropHook(classId,objectId,subId) \
+ InvokeObjectDropHookArg((classId),(objectId),(subId),0)
+#define InvokeObjectDropHookArg(classId,objectId,subId,dropflags) \
do { \
if (object_access_hook) \
- (*object_access_hook)((access),(classId), \
- (objectId),(subId),(arg)); \
+ RunObjectDropHook((classId),(objectId),(subId), \
+ (dropflags)); \
} while(0)
#endif /* OBJECTACCESS_H */