]> granicus.if.org Git - postgresql/blob - src/backend/catalog/objectaccess.c
Update copyright via script for 2017
[postgresql] / src / backend / catalog / objectaccess.c
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  */
21 object_access_hook_type object_access_hook = NULL;
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 {
32         ObjectAccessPostCreate pc_arg;
33
34         /* caller should check, but just in case... */
35         Assert(object_access_hook != NULL);
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... */
57         Assert(object_access_hook != NULL);
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... */
79         Assert(object_access_hook != NULL);
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 {
98         ObjectAccessNamespaceSearch ns_arg;
99
100         /* caller should check, but just in case... */
101         Assert(object_access_hook != NULL);
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
120 RunFunctionExecuteHook(Oid objectId)
121 {
122         /* caller should check, but just in case... */
123         Assert(object_access_hook != NULL);
124
125         (*object_access_hook) (OAT_FUNCTION_EXECUTE,
126                                                    ProcedureRelationId, objectId, 0,
127                                                    NULL);
128 }