#include "catalog/heap.h"
#include "catalog/index.h"
#include "catalog/namespace.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_amop.h"
#include "catalog/pg_amproc.h"
#include "catalog/pg_attrdef.h"
SysScanDesc scan;
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);
+ }
+
/*
* First remove any pg_depend records that link from this object to
* others. (Any records linking to this object should be gone already.)
}
/* Post creation hook for new relation */
- InvokeObjectAccessHook(OAT_POST_CREATE, RelationRelationId, relid, 0);
+ InvokeObjectAccessHook(OAT_POST_CREATE,
+ RelationRelationId, relid, 0, NULL);
/*
* Store any supplied constraints and defaults.
/* Post creation hook for new collation */
InvokeObjectAccessHook(OAT_POST_CREATE,
- CollationRelationId, oid, 0);
+ CollationRelationId, oid, 0, NULL);
heap_freetuple(tup);
heap_close(rel, RowExclusiveLock);
}
/* Post creation hook for new constraint */
- InvokeObjectAccessHook(OAT_POST_CREATE, ConstraintRelationId, conOid, 0);
+ InvokeObjectAccessHook(OAT_POST_CREATE,
+ ConstraintRelationId, conOid, 0, NULL);
return conOid;
}
recordDependencyOnCurrentExtension(&myself, false);
/* Post creation hook for new conversion */
- InvokeObjectAccessHook(OAT_POST_CREATE,
- ConversionRelationId, HeapTupleGetOid(tup), 0);
+ InvokeObjectAccessHook(OAT_POST_CREATE, ConversionRelationId,
+ HeapTupleGetOid(tup), 0, NULL);
heap_freetuple(tup);
heap_close(rel, RowExclusiveLock);
recordDependencyOnCurrentExtension(&myself, false);
/* Post creation hook for new schema */
- InvokeObjectAccessHook(OAT_POST_CREATE, NamespaceRelationId, nspoid, 0);
+ InvokeObjectAccessHook(OAT_POST_CREATE,
+ NamespaceRelationId, nspoid, 0, NULL);
return nspoid;
}
/* Post creation hook for new shell operator */
InvokeObjectAccessHook(OAT_POST_CREATE,
- OperatorRelationId, operatorObjectId, 0);
+ OperatorRelationId, operatorObjectId, 0, NULL);
/*
* Make sure the tuple is visible for subsequent lookups/updates.
/* Post creation hook for new operator */
InvokeObjectAccessHook(OAT_POST_CREATE,
- OperatorRelationId, operatorObjectId, 0);
+ OperatorRelationId, operatorObjectId, 0, NULL);
heap_close(pg_operator_desc, RowExclusiveLock);
heap_freetuple(tup);
/* Post creation hook for new function */
- InvokeObjectAccessHook(OAT_POST_CREATE, ProcedureRelationId, retval, 0);
+ InvokeObjectAccessHook(OAT_POST_CREATE,
+ ProcedureRelationId, retval, 0, NULL);
heap_close(rel, RowExclusiveLock);
false);
/* Post creation hook for new shell type */
- InvokeObjectAccessHook(OAT_POST_CREATE, TypeRelationId, typoid, 0);
+ InvokeObjectAccessHook(OAT_POST_CREATE,
+ TypeRelationId, typoid, 0, NULL);
/*
* clean up and return the type-oid
rebuildDeps);
/* Post creation hook for new type */
- InvokeObjectAccessHook(OAT_POST_CREATE, TypeRelationId, typeObjectId, 0);
+ InvokeObjectAccessHook(OAT_POST_CREATE,
+ TypeRelationId, typeObjectId, 0, NULL);
/*
* finish up
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
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
}
/* Post creation hook for new extension */
InvokeObjectAccessHook(OAT_POST_CREATE,
- ExtensionRelationId, extensionOid, 0);
+ ExtensionRelationId, extensionOid, 0, NULL);
return extensionOid;
}
/* Post creation hook for new foreign data wrapper */
InvokeObjectAccessHook(OAT_POST_CREATE,
- ForeignDataWrapperRelationId, fdwId, 0);
+ ForeignDataWrapperRelationId, fdwId, 0, NULL);
heap_close(rel, RowExclusiveLock);
}
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);
}
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);
}
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);
/* Post creation hook for new operator family */
InvokeObjectAccessHook(OAT_POST_CREATE,
- OperatorFamilyRelationId, opfamilyoid, 0);
+ OperatorFamilyRelationId, opfamilyoid, 0, NULL);
heap_close(rel, RowExclusiveLock);
/* Post creation hook for new operator class */
InvokeObjectAccessHook(OAT_POST_CREATE,
- OperatorClassRelationId, opclassoid, 0);
+ OperatorClassRelationId, opclassoid, 0, NULL);
heap_close(rel, RowExclusiveLock);
}
/* Post creation hook for new procedural language */
InvokeObjectAccessHook(OAT_POST_CREATE,
- LanguageRelationId, myself.objectId, 0);
+ LanguageRelationId, myself.objectId, 0, NULL);
heap_close(rel, RowExclusiveLock);
}
/* Post creation hook for new attribute */
InvokeObjectAccessHook(OAT_POST_CREATE,
- RelationRelationId, myrelid, newattnum);
+ RelationRelationId, myrelid, newattnum, NULL);
heap_close(pgclass, RowExclusiveLock);
/* Post creation hook for new tablespace */
InvokeObjectAccessHook(OAT_POST_CREATE,
- TableSpaceRelationId, tablespaceoid, 0);
+ TableSpaceRelationId, tablespaceoid, 0, NULL);
create_tablespace_directories(location, tablespaceoid);
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)
*/
/* 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);
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);
/* Post creation hook for new text search dictionary */
InvokeObjectAccessHook(OAT_POST_CREATE,
- TSDictionaryRelationId, dictOid, 0);
+ TSDictionaryRelationId, dictOid, 0, NULL);
heap_freetuple(tup);
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);
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);
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.
(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.
/* Post creation hook for new rule */
InvokeObjectAccessHook(OAT_POST_CREATE,
- RewriteRelationId, rewriteObjectId, 0);
+ RewriteRelationId, rewriteObjectId, 0, NULL);
heap_close(pg_rewrite_desc, RowExclusiveLock);
/* Post creation hook for new large object */
InvokeObjectAccessHook(OAT_POST_CREATE,
- LargeObjectRelationId, lobjId_new, 0);
+ LargeObjectRelationId, lobjId_new, 0, NULL);
/*
* Advance command counter to make new tuple visible to later operations.
* Typically, this is done after inserting the primary catalog records and
* associated dependencies.
*
+ * OAT_DROP should be invoked just before deletion of objects; typically
+ * deleteOneObject(). Its arguments are packed within ObjectAccessDrop.
+ *
* Other types may be added in the future.
*/
typedef enum ObjectAccessType
{
OAT_POST_CREATE,
+ OAT_DROP,
} ObjectAccessType;
/*
- * Hook, and a macro to invoke it.
+ * Arguments of OAT_DROP event
*/
+typedef struct
+{
+ /*
+ * Flags to inform extensions the context of this deletion.
+ * Also see PERFORM_DELETION_* in dependency.h
+ */
+ int dropflags;
+} ObjectAccessDrop;
+/*
+ * Hook, and a macro to invoke it.
+ */
typedef void (*object_access_hook_type) (ObjectAccessType access,
Oid classId,
Oid objectId,
- int subId);
+ int subId,
+ void *arg);
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)); \
+#define InvokeObjectAccessHook(access,classId,objectId,subId,arg) \
+ do { \
+ if (object_access_hook) \
+ (*object_access_hook)((access),(classId), \
+ (objectId),(subId),(arg)); \
} while(0)
#endif /* OBJECTACCESS_H */