#include "catalog/index.h"
#include "catalog/indexing.h"
#include "catalog/namespace.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_attrdef.h"
#include "catalog/pg_constraint.h"
#include "catalog/pg_inherits.h"
}
}
+ /* Post creation hook for new relation */
+ InvokeObjectAccessHook(OAT_POST_CREATE, RelationRelationId, relid, 0);
+
/*
* Store any supplied constraints and defaults.
*
#include "access/heapam.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_constraint.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_type.h"
DEPENDENCY_NORMAL);
}
+ /* Post creation hook for new constraint */
+ InvokeObjectAccessHook(OAT_POST_CREATE, ConstraintRelationId, conOid, 0);
+
return conOid;
}
#include "access/sysattr.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_conversion.h"
#include "catalog/pg_conversion_fn.h"
#include "catalog/pg_namespace.h"
recordDependencyOnOwner(ConversionRelationId, HeapTupleGetOid(tup),
conowner);
+ /* Post creation hook for new conversion */
+ InvokeObjectAccessHook(OAT_POST_CREATE,
+ ConversionRelationId, HeapTupleGetOid(tup), 0);
+
heap_freetuple(tup);
heap_close(rel, RowExclusiveLock);
#include "access/heapam.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_namespace.h"
#include "utils/builtins.h"
#include "utils/rel.h"
/* Record dependency on owner */
recordDependencyOnOwner(NamespaceRelationId, nspoid, ownerId);
+ /* Post creation hook for new schema */
+ InvokeObjectAccessHook(OAT_POST_CREATE, NamespaceRelationId, nspoid, 0);
+
return nspoid;
}
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/namespace.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_proc.h"
heap_freetuple(tup);
+ /* Post creation hook for new shell operator */
+ InvokeObjectAccessHook(OAT_POST_CREATE,
+ OperatorRelationId, operatorObjectId, 0);
+
/*
* Make sure the tuple is visible for subsequent lookups/updates.
*/
/* Add dependencies for the entry */
makeOperatorDependencies(tup);
+ /* Post creation hook for new operator */
+ InvokeObjectAccessHook(OAT_POST_CREATE,
+ OperatorRelationId, operatorObjectId, 0);
+
heap_close(pg_operator_desc, RowExclusiveLock);
/*
#include "access/xact.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_language.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_proc.h"
heap_freetuple(tup);
+ /* Post creation hook for new function */
+ InvokeObjectAccessHook(OAT_POST_CREATE, ProcedureRelationId, retval, 0);
+
heap_close(rel, RowExclusiveLock);
/* Verify function body */
#include "access/xact.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
NULL,
false);
+ /* Post creation hook for new shell type */
+ InvokeObjectAccessHook(OAT_POST_CREATE, TypeRelationId, typoid, 0);
+
/*
* clean up and return the type-oid
*/
NULL),
rebuildDeps);
+ /* Post creation hook for new type */
+ InvokeObjectAccessHook(OAT_POST_CREATE, TypeRelationId, typeObjectId, 0);
+
/*
* finish up
*/
#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_database.h"
#include "catalog/pg_db_role_setting.h"
/* Create pg_shdepend entries for objects within database */
copyTemplateDependencies(src_dboid, dboid);
+ /* Post creation hook for new database */
+ InvokeObjectAccessHook(OAT_POST_CREATE, DatabaseRelationId, dboid, 0);
+
/*
* Force a checkpoint before starting the copy. This will force dirty
* buffers out to disk, to ensure source database is up-to-date on disk
#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_foreign_data_wrapper.h"
#include "catalog/pg_foreign_server.h"
#include "catalog/pg_proc.h"
recordDependencyOnOwner(ForeignDataWrapperRelationId, fdwId, ownerId);
+ /* Post creation hook for new foreign data wrapper */
+ InvokeObjectAccessHook(OAT_POST_CREATE,
+ ForeignDataWrapperRelationId, fdwId, 0);
+
heap_close(rel, NoLock);
}
recordDependencyOnOwner(ForeignServerRelationId, srvId, ownerId);
+ /* Post creation hook for new foreign server */
+ InvokeObjectAccessHook(OAT_POST_CREATE, ForeignServerRelationId, srvId, 0);
+
heap_close(rel, NoLock);
}
/* Record the mapped user dependency */
recordDependencyOnOwner(UserMappingRelationId, umId, useId);
+ /* Post creation hook for new user mapping */
+ InvokeObjectAccessHook(OAT_POST_CREATE, UserMappingRelationId, umId, 0);
+
heap_close(rel, NoLock);
}
#include "access/sysattr.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_aggregate.h"
#include "catalog/pg_cast.h"
#include "catalog/pg_language.h"
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
}
+ /* Post creation hook for new cast */
+ InvokeObjectAccessHook(OAT_POST_CREATE,
+ CastRelationId, myself.objectId, 0);
+
heap_freetuple(tuple);
heap_close(relation, RowExclusiveLock);
#include "access/sysattr.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_amop.h"
#include "catalog/pg_amproc.h"
#include "catalog/pg_namespace.h"
/* dependency on owner */
recordDependencyOnOwner(OperatorFamilyRelationId, opfamilyoid, GetUserId());
+ /* Post creation hook for new operator family */
+ InvokeObjectAccessHook(OAT_POST_CREATE,
+ OperatorFamilyRelationId, opfamilyoid, 0);
+
heap_close(rel, RowExclusiveLock);
return opfamilyoid;
/* dependency on owner */
recordDependencyOnOwner(OperatorClassRelationId, opclassoid, GetUserId());
+ /* Post creation hook for new operator class */
+ InvokeObjectAccessHook(OAT_POST_CREATE,
+ OperatorClassRelationId, opclassoid, 0);
+
heap_close(rel, RowExclusiveLock);
}
#include "access/heapam.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_language.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_pltemplate.h"
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
}
+ /* Post creation hook for new procedural language */
+ InvokeObjectAccessHook(OAT_POST_CREATE,
+ LanguageRelationId, myself.objectId, 0);
+
heap_close(rel, RowExclusiveLock);
}
#include "catalog/index.h"
#include "catalog/indexing.h"
#include "catalog/namespace.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_constraint.h"
#include "catalog/pg_depend.h"
#include "catalog/pg_inherits.h"
heap_freetuple(reltup);
+ /* Post creation hook for new attribute */
+ InvokeObjectAccessHook(OAT_POST_CREATE,
+ RelationRelationId, myrelid, newattnum);
+
heap_close(pgclass, RowExclusiveLock);
/* Make the attribute's catalog entry visible */
#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_tablespace.h"
#include "commands/comment.h"
#include "commands/defrem.h"
/* Record dependency on owner */
recordDependencyOnOwner(TableSpaceRelationId, tablespaceoid, ownerId);
+ /* Post creation hook for new tablespace */
+ InvokeObjectAccessHook(OAT_POST_CREATE,
+ TableSpaceRelationId, tablespaceoid, 0);
+
create_tablespace_directories(location, tablespaceoid);
/* Record the filesystem change in XLOG */
#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_constraint.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_trigger.h"
recordDependencyOnExpr(&myself, whenClause, whenRtable,
DEPENDENCY_NORMAL);
+ /* Post creation hook for new trigger */
+ InvokeObjectAccessHook(OAT_POST_CREATE,
+ TriggerRelationId, trigoid, 0);
+
/* Keep lock on target rel until end of xact */
heap_close(rel, NoLock);
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/namespace.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_ts_config.h"
makeParserDependencies(tup);
+ /* Post creation hook for new text search parser */
+ InvokeObjectAccessHook(OAT_POST_CREATE, TSParserRelationId, prsOid, 0);
+
heap_freetuple(tup);
heap_close(prsRel, RowExclusiveLock);
makeDictionaryDependencies(tup);
+ /* Post creation hook for new text search dictionary */
+ InvokeObjectAccessHook(OAT_POST_CREATE,
+ TSDictionaryRelationId, dictOid, 0);
+
heap_freetuple(tup);
heap_close(dictRel, RowExclusiveLock);
makeTSTemplateDependencies(tup);
+ /* Post creation hook for new text search template */
+ InvokeObjectAccessHook(OAT_POST_CREATE, TSTemplateRelationId, dictOid, 0);
+
heap_freetuple(tup);
heap_close(tmplRel, RowExclusiveLock);
makeConfigurationDependencies(tup, false, mapRel);
+ /* Post creation hook for new text search configuration */
+ InvokeObjectAccessHook(OAT_POST_CREATE, TSConfigRelationId, cfgOid, 0);
+
heap_freetuple(tup);
if (mapRel)
#include "access/xact.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_auth_members.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_database.h"
rolemembers, roleNamesToIds(rolemembers),
GetUserId(), false);
+ /* Post creation hook for new role */
+ InvokeObjectAccessHook(OAT_POST_CREATE, AuthIdRelationId, roleid, 0);
+
/*
* Close pg_authid, but keep lock till commit.
*/
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/namespace.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_rewrite.h"
#include "catalog/storage.h"
#include "miscadmin.h"
DEPENDENCY_NORMAL);
}
+ /* Post creation hook for new rule */
+ InvokeObjectAccessHook(OAT_POST_CREATE,
+ RewriteRelationId, rewriteObjectId, 0);
+
heap_close(pg_rewrite_desc, RowExclusiveLock);
return rewriteObjectId;
#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_largeobject.h"
#include "catalog/pg_largeobject_metadata.h"
#include "commands/comment.h"
recordDependencyOnOwner(LargeObjectRelationId,
lobjId_new, GetUserId());
+ /* Post creation hook for new large object */
+ InvokeObjectAccessHook(OAT_POST_CREATE,
+ 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.
+ */
+PGDLLIMPORT object_access_hook_type object_access_hook = NULL;
--- /dev/null
+/*
+ * objectaccess.h
+ *
+ * Object access hooks.
+ *
+ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ */
+
+#ifndef OBJECTACCESS_H
+#define OBJECTACCESS_H
+
+/*
+ * Object access hooks are intended to be called just before or just after
+ * performing certain actions on a SQL object. This is intended as
+ * infrastructure for security or logging pluggins.
+ *
+ * OAT_POST_CREATE should be invoked just after the the object is created.
+ * Typically, this is done after inserting the primary catalog records and
+ * associated dependencies.
+ *
+ * Other types may be added in the future.
+ */
+typedef enum ObjectAccessType
+{
+ OAT_POST_CREATE,
+} ObjectAccessType;
+
+/*
+ * Hook, and a macro to invoke it.
+ */
+
+typedef void (*object_access_hook_type)(ObjectAccessType access,
+ Oid classId,
+ Oid objectId,
+ int subId);
+
+extern PGDLLIMPORT object_access_hook_type object_access_hook;
+
+#define InvokeObjectAccessHook(access,classId,objectId,subId) \
+ do { \
+ if (object_access_hook) \
+ (*object_access_hook)((access),(classId),(objectId),(subId)); \
+ } while(0)
+
+#endif /* OBJECTACCESS_H */