Header And Logo

PostgreSQL
| The world's most advanced open source database.

objectaccess.c

Go to the documentation of this file.
00001 /* -------------------------------------------------------------------------
00002  *
00003  * objectaccess.c
00004  *      functions for object_access_hook on various events
00005  *
00006  * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
00007  * Portions Copyright (c) 1994, Regents of the University of California
00008  *
00009  * -------------------------------------------------------------------------
00010  */
00011 #include "postgres.h"
00012 
00013 #include "catalog/objectaccess.h"
00014 #include "catalog/pg_namespace.h"
00015 #include "catalog/pg_proc.h"
00016 
00017 /*
00018  * Hook on object accesses.  This is intended as infrastructure for security
00019  * and logging plugins.
00020  */
00021 object_access_hook_type object_access_hook = NULL;
00022 
00023 /*
00024  * RunObjectPostCreateHook
00025  *
00026  * It is entrypoint of OAT_POST_CREATE event
00027  */
00028 void
00029 RunObjectPostCreateHook(Oid classId, Oid objectId, int subId,
00030                         bool is_internal)
00031 {
00032     ObjectAccessPostCreate  pc_arg;
00033 
00034     /* caller should check, but just in case... */
00035     Assert(object_access_hook != NULL);
00036 
00037     memset(&pc_arg, 0, sizeof(ObjectAccessPostCreate));
00038     pc_arg.is_internal = is_internal;
00039 
00040     (*object_access_hook)(OAT_POST_CREATE,
00041                           classId, objectId, subId,
00042                           (void *) &pc_arg);
00043 }
00044 
00045 /*
00046  * RunObjectDropHook
00047  *
00048  * It is entrypoint of OAT_DROP event
00049  */
00050 void
00051 RunObjectDropHook(Oid classId, Oid objectId, int subId,
00052                   int dropflags)
00053 {
00054     ObjectAccessDrop    drop_arg;
00055 
00056     /* caller should check, but just in case... */
00057     Assert(object_access_hook != NULL);
00058 
00059     memset(&drop_arg, 0, sizeof(ObjectAccessDrop));
00060     drop_arg.dropflags = dropflags;
00061 
00062     (*object_access_hook)(OAT_DROP,
00063                           classId, objectId, subId,
00064                           (void *) &drop_arg);
00065 }
00066 
00067 /*
00068  * RunObjectPostAlterHook
00069  *
00070  * It is entrypoint of OAT_POST_ALTER event
00071  */
00072 void
00073 RunObjectPostAlterHook(Oid classId, Oid objectId, int subId,
00074                        Oid auxiliaryId, bool is_internal)
00075 {
00076     ObjectAccessPostAlter   pa_arg;
00077 
00078     /* caller should check, but just in case... */
00079     Assert(object_access_hook != NULL);
00080 
00081     memset(&pa_arg, 0, sizeof(ObjectAccessPostAlter));
00082     pa_arg.auxiliary_id = auxiliaryId;
00083     pa_arg.is_internal = is_internal;
00084 
00085     (*object_access_hook)(OAT_POST_ALTER,
00086                           classId, objectId, subId,
00087                           (void *) &pa_arg);
00088 }
00089 
00090 /*
00091  * RunNamespaceSearchHook
00092  *
00093  * It is entrypoint of OAT_NAMESPACE_SEARCH event
00094  */
00095 bool
00096 RunNamespaceSearchHook(Oid objectId, bool ereport_on_violation)
00097 {
00098     ObjectAccessNamespaceSearch ns_arg;
00099 
00100     /* caller should check, but just in case... */
00101     Assert(object_access_hook != NULL);
00102 
00103     memset(&ns_arg, 0, sizeof(ObjectAccessNamespaceSearch));
00104     ns_arg.ereport_on_violation = ereport_on_violation;
00105     ns_arg.result = true;
00106 
00107     (*object_access_hook)(OAT_NAMESPACE_SEARCH,
00108                           NamespaceRelationId, objectId, 0,
00109                           (void *) &ns_arg);
00110 
00111     return ns_arg.result;
00112 }
00113 
00114 /*
00115  * RunFunctionExecuteHook
00116  *
00117  * It is entrypoint of OAT_FUNCTION_EXECUTE event
00118  */
00119 void
00120 RunFunctionExecuteHook(Oid objectId)
00121 {
00122     /* caller should check, but just in case... */
00123     Assert(object_access_hook != NULL);
00124 
00125     (*object_access_hook)(OAT_FUNCTION_EXECUTE,
00126                           ProcedureRelationId, objectId, 0,
00127                           NULL);
00128 }