1 /* -------------------------------------------------------------------------
4 * functions for object_access_hook on various events
6 * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * -------------------------------------------------------------------------
13 #include "catalog/objectaccess.h"
14 #include "catalog/pg_namespace.h"
15 #include "catalog/pg_proc.h"
18 * Hook on object accesses. This is intended as infrastructure for security
19 * and logging plugins.
21 object_access_hook_type object_access_hook = NULL;
24 * RunObjectPostCreateHook
26 * It is entrypoint of OAT_POST_CREATE event
29 RunObjectPostCreateHook(Oid classId, Oid objectId, int subId,
32 ObjectAccessPostCreate pc_arg;
34 /* caller should check, but just in case... */
35 Assert(object_access_hook != NULL);
37 memset(&pc_arg, 0, sizeof(ObjectAccessPostCreate));
38 pc_arg.is_internal = is_internal;
40 (*object_access_hook) (OAT_POST_CREATE,
41 classId, objectId, subId,
48 * It is entrypoint of OAT_DROP event
51 RunObjectDropHook(Oid classId, Oid objectId, int subId,
54 ObjectAccessDrop drop_arg;
56 /* caller should check, but just in case... */
57 Assert(object_access_hook != NULL);
59 memset(&drop_arg, 0, sizeof(ObjectAccessDrop));
60 drop_arg.dropflags = dropflags;
62 (*object_access_hook) (OAT_DROP,
63 classId, objectId, subId,
68 * RunObjectPostAlterHook
70 * It is entrypoint of OAT_POST_ALTER event
73 RunObjectPostAlterHook(Oid classId, Oid objectId, int subId,
74 Oid auxiliaryId, bool is_internal)
76 ObjectAccessPostAlter pa_arg;
78 /* caller should check, but just in case... */
79 Assert(object_access_hook != NULL);
81 memset(&pa_arg, 0, sizeof(ObjectAccessPostAlter));
82 pa_arg.auxiliary_id = auxiliaryId;
83 pa_arg.is_internal = is_internal;
85 (*object_access_hook) (OAT_POST_ALTER,
86 classId, objectId, subId,
91 * RunNamespaceSearchHook
93 * It is entrypoint of OAT_NAMESPACE_SEARCH event
96 RunNamespaceSearchHook(Oid objectId, bool ereport_on_violation)
98 ObjectAccessNamespaceSearch ns_arg;
100 /* caller should check, but just in case... */
101 Assert(object_access_hook != NULL);
103 memset(&ns_arg, 0, sizeof(ObjectAccessNamespaceSearch));
104 ns_arg.ereport_on_violation = ereport_on_violation;
105 ns_arg.result = true;
107 (*object_access_hook) (OAT_NAMESPACE_SEARCH,
108 NamespaceRelationId, objectId, 0,
111 return ns_arg.result;
115 * RunFunctionExecuteHook
117 * It is entrypoint of OAT_FUNCTION_EXECUTE event
120 RunFunctionExecuteHook(Oid objectId)
122 /* caller should check, but just in case... */
123 Assert(object_access_hook != NULL);
125 (*object_access_hook) (OAT_FUNCTION_EXECUTE,
126 ProcedureRelationId, objectId, 0,