PostgreSQL Source Code  git master
objectaccess.c
Go to the documentation of this file.
1 /* -------------------------------------------------------------------------
2  *
3  * objectaccess.c
4  * functions for object_access_hook on various events
5  *
6  * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * -------------------------------------------------------------------------
10  */
11 #include "postgres.h"
12 
13 #include "catalog/objectaccess.h"
14 #include "catalog/pg_class.h"
15 #include "catalog/pg_namespace.h"
16 #include "catalog/pg_proc.h"
17 
18 /*
19  * Hook on object accesses. This is intended as infrastructure for security
20  * and logging plugins.
21  */
23 
24 /*
25  * RunObjectPostCreateHook
26  *
27  * It is entrypoint of OAT_POST_CREATE event
28  */
29 void
30 RunObjectPostCreateHook(Oid classId, Oid objectId, int subId,
31  bool is_internal)
32 {
34 
35  /* caller should check, but just in case... */
36  Assert(object_access_hook != NULL);
37 
38  memset(&pc_arg, 0, sizeof(ObjectAccessPostCreate));
39  pc_arg.is_internal = is_internal;
40 
41  (*object_access_hook) (OAT_POST_CREATE,
42  classId, objectId, subId,
43  (void *) &pc_arg);
44 }
45 
46 /*
47  * RunObjectDropHook
48  *
49  * It is entrypoint of OAT_DROP event
50  */
51 void
52 RunObjectDropHook(Oid classId, Oid objectId, int subId,
53  int dropflags)
54 {
55  ObjectAccessDrop drop_arg;
56 
57  /* caller should check, but just in case... */
58  Assert(object_access_hook != NULL);
59 
60  memset(&drop_arg, 0, sizeof(ObjectAccessDrop));
61  drop_arg.dropflags = dropflags;
62 
63  (*object_access_hook) (OAT_DROP,
64  classId, objectId, subId,
65  (void *) &drop_arg);
66 }
67 
68 /*
69  * RunObjectTruncateHook
70  *
71  * It is the entrypoint of OAT_TRUNCATE event
72  */
73 void
75 {
76  /* caller should check, but just in case... */
77  Assert(object_access_hook != NULL);
78 
79  (*object_access_hook) (OAT_TRUNCATE,
80  RelationRelationId, objectId, 0,
81  NULL);
82 }
83 
84 /*
85  * RunObjectPostAlterHook
86  *
87  * It is entrypoint of OAT_POST_ALTER event
88  */
89 void
90 RunObjectPostAlterHook(Oid classId, Oid objectId, int subId,
91  Oid auxiliaryId, bool is_internal)
92 {
93  ObjectAccessPostAlter pa_arg;
94 
95  /* caller should check, but just in case... */
96  Assert(object_access_hook != NULL);
97 
98  memset(&pa_arg, 0, sizeof(ObjectAccessPostAlter));
99  pa_arg.auxiliary_id = auxiliaryId;
100  pa_arg.is_internal = is_internal;
101 
102  (*object_access_hook) (OAT_POST_ALTER,
103  classId, objectId, subId,
104  (void *) &pa_arg);
105 }
106 
107 /*
108  * RunNamespaceSearchHook
109  *
110  * It is entrypoint of OAT_NAMESPACE_SEARCH event
111  */
112 bool
113 RunNamespaceSearchHook(Oid objectId, bool ereport_on_violation)
114 {
116 
117  /* caller should check, but just in case... */
118  Assert(object_access_hook != NULL);
119 
120  memset(&ns_arg, 0, sizeof(ObjectAccessNamespaceSearch));
121  ns_arg.ereport_on_violation = ereport_on_violation;
122  ns_arg.result = true;
123 
124  (*object_access_hook) (OAT_NAMESPACE_SEARCH,
125  NamespaceRelationId, objectId, 0,
126  (void *) &ns_arg);
127 
128  return ns_arg.result;
129 }
130 
131 /*
132  * RunFunctionExecuteHook
133  *
134  * It is entrypoint of OAT_FUNCTION_EXECUTE event
135  */
136 void
138 {
139  /* caller should check, but just in case... */
140  Assert(object_access_hook != NULL);
141 
142  (*object_access_hook) (OAT_FUNCTION_EXECUTE,
143  ProcedureRelationId, objectId, 0,
144  NULL);
145 }
void RunObjectPostAlterHook(Oid classId, Oid objectId, int subId, Oid auxiliaryId, bool is_internal)
Definition: objectaccess.c:90
void RunObjectTruncateHook(Oid objectId)
Definition: objectaccess.c:74
void RunObjectPostCreateHook(Oid classId, Oid objectId, int subId, bool is_internal)
Definition: objectaccess.c:30
unsigned int Oid
Definition: postgres_ext.h:31
void RunFunctionExecuteHook(Oid objectId)
Definition: objectaccess.c:137
void RunObjectDropHook(Oid classId, Oid objectId, int subId, int dropflags)
Definition: objectaccess.c:52
object_access_hook_type object_access_hook
Definition: objectaccess.c:22
#define Assert(condition)
Definition: c.h:738
void(* object_access_hook_type)(ObjectAccessType access, Oid classId, Oid objectId, int subId, void *arg)
Definition: objectaccess.h:125
bool RunNamespaceSearchHook(Oid objectId, bool ereport_on_violation)
Definition: objectaccess.c:113