2013-03-07 02:52:06 +01:00
|
|
|
/* -------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* objectaccess.c
|
|
|
|
* functions for object_access_hook on various events
|
|
|
|
*
|
|
|
|
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include "catalog/objectaccess.h"
|
2013-04-05 14:51:31 +02:00
|
|
|
#include "catalog/pg_namespace.h"
|
2013-04-12 14:55:56 +02:00
|
|
|
#include "catalog/pg_proc.h"
|
2013-03-07 02:52:06 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Hook on object accesses. This is intended as infrastructure for security
|
|
|
|
* and logging plugins.
|
|
|
|
*/
|
|
|
|
object_access_hook_type object_access_hook = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RunObjectPostCreateHook
|
|
|
|
*
|
|
|
|
* It is entrypoint of OAT_POST_CREATE event
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
RunObjectPostCreateHook(Oid classId, Oid objectId, int subId,
|
|
|
|
bool is_internal)
|
|
|
|
{
|
2013-05-29 22:58:43 +02:00
|
|
|
ObjectAccessPostCreate pc_arg;
|
2013-03-07 02:52:06 +01:00
|
|
|
|
|
|
|
/* caller should check, but just in case... */
|
|
|
|
Assert(object_access_hook != NULL);
|
|
|
|
|
|
|
|
memset(&pc_arg, 0, sizeof(ObjectAccessPostCreate));
|
|
|
|
pc_arg.is_internal = is_internal;
|
|
|
|
|
2013-05-29 22:58:43 +02:00
|
|
|
(*object_access_hook) (OAT_POST_CREATE,
|
|
|
|
classId, objectId, subId,
|
|
|
|
(void *) &pc_arg);
|
2013-03-07 02:52:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RunObjectDropHook
|
|
|
|
*
|
|
|
|
* It is entrypoint of OAT_DROP event
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
RunObjectDropHook(Oid classId, Oid objectId, int subId,
|
|
|
|
int dropflags)
|
|
|
|
{
|
2013-05-29 22:58:43 +02:00
|
|
|
ObjectAccessDrop drop_arg;
|
2013-03-07 02:52:06 +01:00
|
|
|
|
|
|
|
/* caller should check, but just in case... */
|
|
|
|
Assert(object_access_hook != NULL);
|
|
|
|
|
|
|
|
memset(&drop_arg, 0, sizeof(ObjectAccessDrop));
|
|
|
|
drop_arg.dropflags = dropflags;
|
|
|
|
|
2013-05-29 22:58:43 +02:00
|
|
|
(*object_access_hook) (OAT_DROP,
|
|
|
|
classId, objectId, subId,
|
|
|
|
(void *) &drop_arg);
|
2013-03-07 02:52:06 +01:00
|
|
|
}
|
2013-03-18 03:55:14 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* RunObjectPostAlterHook
|
|
|
|
*
|
|
|
|
* It is entrypoint of OAT_POST_ALTER event
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
RunObjectPostAlterHook(Oid classId, Oid objectId, int subId,
|
|
|
|
Oid auxiliaryId, bool is_internal)
|
|
|
|
{
|
2013-05-29 22:58:43 +02:00
|
|
|
ObjectAccessPostAlter pa_arg;
|
2013-03-18 03:55:14 +01:00
|
|
|
|
|
|
|
/* caller should check, but just in case... */
|
|
|
|
Assert(object_access_hook != NULL);
|
|
|
|
|
|
|
|
memset(&pa_arg, 0, sizeof(ObjectAccessPostAlter));
|
|
|
|
pa_arg.auxiliary_id = auxiliaryId;
|
|
|
|
pa_arg.is_internal = is_internal;
|
|
|
|
|
2013-05-29 22:58:43 +02:00
|
|
|
(*object_access_hook) (OAT_POST_ALTER,
|
|
|
|
classId, objectId, subId,
|
|
|
|
(void *) &pa_arg);
|
2013-03-18 03:55:14 +01:00
|
|
|
}
|
2013-04-05 14:51:31 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* RunNamespaceSearchHook
|
|
|
|
*
|
|
|
|
* It is entrypoint of OAT_NAMESPACE_SEARCH event
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
RunNamespaceSearchHook(Oid objectId, bool ereport_on_violation)
|
|
|
|
{
|
2013-05-29 22:58:43 +02:00
|
|
|
ObjectAccessNamespaceSearch ns_arg;
|
2013-04-05 14:51:31 +02:00
|
|
|
|
2013-04-12 14:39:38 +02:00
|
|
|
/* caller should check, but just in case... */
|
2013-04-05 14:51:31 +02:00
|
|
|
Assert(object_access_hook != NULL);
|
|
|
|
|
|
|
|
memset(&ns_arg, 0, sizeof(ObjectAccessNamespaceSearch));
|
|
|
|
ns_arg.ereport_on_violation = ereport_on_violation;
|
|
|
|
ns_arg.result = true;
|
|
|
|
|
2013-05-29 22:58:43 +02:00
|
|
|
(*object_access_hook) (OAT_NAMESPACE_SEARCH,
|
|
|
|
NamespaceRelationId, objectId, 0,
|
|
|
|
(void *) &ns_arg);
|
2013-04-05 14:51:31 +02:00
|
|
|
|
|
|
|
return ns_arg.result;
|
|
|
|
}
|
2013-04-12 14:55:56 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* RunFunctionExecuteHook
|
|
|
|
*
|
|
|
|
* It is entrypoint of OAT_FUNCTION_EXECUTE event
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
RunFunctionExecuteHook(Oid objectId)
|
|
|
|
{
|
|
|
|
/* caller should check, but just in case... */
|
|
|
|
Assert(object_access_hook != NULL);
|
|
|
|
|
2013-05-29 22:58:43 +02:00
|
|
|
(*object_access_hook) (OAT_FUNCTION_EXECUTE,
|
|
|
|
ProcedureRelationId, objectId, 0,
|
|
|
|
NULL);
|
2013-04-12 14:55:56 +02:00
|
|
|
}
|