PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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-2017, 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_namespace.h"
15 #include "catalog/pg_proc.h"
16 
17 /*
18  * Hook on object accesses. This is intended as infrastructure for security
19  * and logging plugins.
20  */
22 
23 /*
24  * RunObjectPostCreateHook
25  *
26  * It is entrypoint of OAT_POST_CREATE event
27  */
28 void
29 RunObjectPostCreateHook(Oid classId, Oid objectId, int subId,
30  bool is_internal)
31 {
33 
34  /* caller should check, but just in case... */
36 
37  memset(&pc_arg, 0, sizeof(ObjectAccessPostCreate));
38  pc_arg.is_internal = is_internal;
39 
40  (*object_access_hook) (OAT_POST_CREATE,
41  classId, objectId, subId,
42  (void *) &pc_arg);
43 }
44 
45 /*
46  * RunObjectDropHook
47  *
48  * It is entrypoint of OAT_DROP event
49  */
50 void
51 RunObjectDropHook(Oid classId, Oid objectId, int subId,
52  int dropflags)
53 {
54  ObjectAccessDrop drop_arg;
55 
56  /* caller should check, but just in case... */
58 
59  memset(&drop_arg, 0, sizeof(ObjectAccessDrop));
60  drop_arg.dropflags = dropflags;
61 
62  (*object_access_hook) (OAT_DROP,
63  classId, objectId, subId,
64  (void *) &drop_arg);
65 }
66 
67 /*
68  * RunObjectPostAlterHook
69  *
70  * It is entrypoint of OAT_POST_ALTER event
71  */
72 void
73 RunObjectPostAlterHook(Oid classId, Oid objectId, int subId,
74  Oid auxiliaryId, bool is_internal)
75 {
76  ObjectAccessPostAlter pa_arg;
77 
78  /* caller should check, but just in case... */
80 
81  memset(&pa_arg, 0, sizeof(ObjectAccessPostAlter));
82  pa_arg.auxiliary_id = auxiliaryId;
83  pa_arg.is_internal = is_internal;
84 
85  (*object_access_hook) (OAT_POST_ALTER,
86  classId, objectId, subId,
87  (void *) &pa_arg);
88 }
89 
90 /*
91  * RunNamespaceSearchHook
92  *
93  * It is entrypoint of OAT_NAMESPACE_SEARCH event
94  */
95 bool
96 RunNamespaceSearchHook(Oid objectId, bool ereport_on_violation)
97 {
99 
100  /* caller should check, but just in case... */
102 
103  memset(&ns_arg, 0, sizeof(ObjectAccessNamespaceSearch));
104  ns_arg.ereport_on_violation = ereport_on_violation;
105  ns_arg.result = true;
106 
107  (*object_access_hook) (OAT_NAMESPACE_SEARCH,
108  NamespaceRelationId, objectId, 0,
109  (void *) &ns_arg);
110 
111  return ns_arg.result;
112 }
113 
114 /*
115  * RunFunctionExecuteHook
116  *
117  * It is entrypoint of OAT_FUNCTION_EXECUTE event
118  */
119 void
121 {
122  /* caller should check, but just in case... */
124 
125  (*object_access_hook) (OAT_FUNCTION_EXECUTE,
126  ProcedureRelationId, objectId, 0,
127  NULL);
128 }
#define NamespaceRelationId
Definition: pg_namespace.h:34
void RunObjectPostAlterHook(Oid classId, Oid objectId, int subId, Oid auxiliaryId, bool is_internal)
Definition: objectaccess.c:73
#define ProcedureRelationId
Definition: pg_proc.h:33
void RunObjectPostCreateHook(Oid classId, Oid objectId, int subId, bool is_internal)
Definition: objectaccess.c:29
unsigned int Oid
Definition: postgres_ext.h:31
void RunFunctionExecuteHook(Oid objectId)
Definition: objectaccess.c:120
void RunObjectDropHook(Oid classId, Oid objectId, int subId, int dropflags)
Definition: objectaccess.c:51
#define NULL
Definition: c.h:226
object_access_hook_type object_access_hook
Definition: objectaccess.c:21
#define Assert(condition)
Definition: c.h:670
bool RunNamespaceSearchHook(Oid objectId, bool ereport_on_violation)
Definition: objectaccess.c:96
void(* object_access_hook_type)(ObjectAccessType access, Oid classId, Oid objectId, int subId, void *arg)
Definition: objectaccess.h:120