mirror of https://github.com/citusdata/citus.git
Wip
parent
ff03b35f94
commit
ad435ddba1
|
@ -149,6 +149,8 @@ CreateCimv(CimvCreate *cimvCreate)
|
||||||
elog(ERROR, "SPI_connect failed");
|
elog(ERROR, "SPI_connect failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PushCitusSecurityContext();
|
||||||
|
|
||||||
CreateMatTable(cimvCreate, false);
|
CreateMatTable(cimvCreate, false);
|
||||||
|
|
||||||
if (cimvCreate->createOptions->schedule != NULL)
|
if (cimvCreate->createOptions->schedule != NULL)
|
||||||
|
@ -163,6 +165,8 @@ CreateCimv(CimvCreate *cimvCreate)
|
||||||
CreateDataChangeTriggers(cimvCreate);
|
CreateDataChangeTriggers(cimvCreate);
|
||||||
InsertIntoPgCimv(cimvCreate->formCimv);
|
InsertIntoPgCimv(cimvCreate->formCimv);
|
||||||
|
|
||||||
|
PopCitusSecurityContext();
|
||||||
|
|
||||||
if (SPI_finish() != SPI_OK_FINISH)
|
if (SPI_finish() != SPI_OK_FINISH)
|
||||||
{
|
{
|
||||||
elog(ERROR, "SPI_finish failed");
|
elog(ERROR, "SPI_finish failed");
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "distributed/listutils.h"
|
#include "distributed/listutils.h"
|
||||||
#include "distributed/metadata_cache.h"
|
#include "distributed/metadata_cache.h"
|
||||||
#include "distributed/pg_cimv.h"
|
#include "distributed/pg_cimv.h"
|
||||||
|
#include "distributed/security_utils.h"
|
||||||
#include "executor/spi.h"
|
#include "executor/spi.h"
|
||||||
#include "nodes/parsenodes.h"
|
#include "nodes/parsenodes.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
|
@ -122,6 +123,9 @@ ProcessDropViewStmt(DropStmt *stmt)
|
||||||
static void
|
static void
|
||||||
DropCimv(Form_pg_cimv formCimv, DropBehavior behavior)
|
DropCimv(Form_pg_cimv formCimv, DropBehavior behavior)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
PushCitusSecurityContext();
|
||||||
|
|
||||||
ObjectAddress matTableAddress;
|
ObjectAddress matTableAddress;
|
||||||
matTableAddress.classId = RelationRelationId;
|
matTableAddress.classId = RelationRelationId;
|
||||||
matTableAddress.objectId = formCimv->mattable;
|
matTableAddress.objectId = formCimv->mattable;
|
||||||
|
@ -191,6 +195,7 @@ DropCimv(Form_pg_cimv formCimv, DropBehavior behavior)
|
||||||
|
|
||||||
DeletePgCimvRow(userViewAddress.objectId);
|
DeletePgCimvRow(userViewAddress.objectId);
|
||||||
|
|
||||||
|
PopCitusSecurityContext();
|
||||||
/* Close SPI context. */
|
/* Close SPI context. */
|
||||||
if (SPI_finish() != SPI_OK_FINISH)
|
if (SPI_finish() != SPI_OK_FINISH)
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "catalog/pg_class.h"
|
#include "catalog/pg_class.h"
|
||||||
#include "distributed/listutils.h"
|
#include "distributed/listutils.h"
|
||||||
#include "distributed/metadata_cache.h"
|
#include "distributed/metadata_cache.h"
|
||||||
|
#include "distributed/security_utils.h"
|
||||||
#include "distributed/pg_cimv.h"
|
#include "distributed/pg_cimv.h"
|
||||||
#include "executor/spi.h"
|
#include "executor/spi.h"
|
||||||
#include "nodes/parsenodes.h"
|
#include "nodes/parsenodes.h"
|
||||||
|
@ -109,10 +110,12 @@ RefreshCimv(Form_pg_cimv formCimv, bool skipData, bool isCreate)
|
||||||
matTableName,
|
matTableName,
|
||||||
refreshViewSchemaName,
|
refreshViewSchemaName,
|
||||||
refreshViewName);
|
refreshViewName);
|
||||||
|
PushCitusSecurityContext();
|
||||||
if (SPI_execute(querybuf.data, false, 0) != SPI_OK_INSERT)
|
if (SPI_execute(querybuf.data, false, 0) != SPI_OK_INSERT)
|
||||||
{
|
{
|
||||||
elog(ERROR, "SPI_exec failed: %s", querybuf.data);
|
elog(ERROR, "SPI_exec failed: %s", querybuf.data);
|
||||||
}
|
}
|
||||||
|
PopCitusSecurityContext();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -133,6 +136,7 @@ RefreshCimv(Form_pg_cimv formCimv, bool skipData, bool isCreate)
|
||||||
matTableName,
|
matTableName,
|
||||||
refreshViewSchemaName,
|
refreshViewSchemaName,
|
||||||
refreshViewName);
|
refreshViewName);
|
||||||
|
PushCitusSecurityContext();
|
||||||
SpiExecuteSnapshot(&querybuf, snapshot, SPI_OK_INSERT);
|
SpiExecuteSnapshot(&querybuf, snapshot, SPI_OK_INSERT);
|
||||||
resetStringInfo(&querybuf);
|
resetStringInfo(&querybuf);
|
||||||
|
|
||||||
|
@ -146,6 +150,7 @@ RefreshCimv(Form_pg_cimv formCimv, bool skipData, bool isCreate)
|
||||||
SpiExecuteSnapshot(&querybuf, snapshot, SPI_OK_DELETE);
|
SpiExecuteSnapshot(&querybuf, snapshot, SPI_OK_DELETE);
|
||||||
resetStringInfo(&querybuf);
|
resetStringInfo(&querybuf);
|
||||||
}
|
}
|
||||||
|
PopCitusSecurityContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -461,27 +461,25 @@ multi_ProcessUtility(PlannedStmt *pstmt,
|
||||||
bool continueProcessing = true;
|
bool continueProcessing = true;
|
||||||
if (IsA(parsetree, CreateTableAsStmt))
|
if (IsA(parsetree, CreateTableAsStmt))
|
||||||
{
|
{
|
||||||
PushCitusSecurityContext();
|
|
||||||
continueProcessing = !ProcessCreateMaterializedViewStmt((const
|
continueProcessing = !ProcessCreateMaterializedViewStmt((const
|
||||||
CreateTableAsStmt *)
|
CreateTableAsStmt *)
|
||||||
parsetree, queryString,
|
parsetree, queryString,
|
||||||
pstmt);
|
pstmt);
|
||||||
PopCitusSecurityContext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsA(parsetree, RefreshMatViewStmt))
|
if (IsA(parsetree, RefreshMatViewStmt))
|
||||||
{
|
{
|
||||||
PushCitusSecurityContext();
|
// PushCitusSecurityContext();
|
||||||
continueProcessing = !ProcessRefreshMaterializedViewStmt(
|
continueProcessing = !ProcessRefreshMaterializedViewStmt(
|
||||||
(RefreshMatViewStmt *) parsetree);
|
(RefreshMatViewStmt *) parsetree);
|
||||||
PopCitusSecurityContext();
|
// PopCitusSecurityContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsA(parsetree, DropStmt))
|
if (IsA(parsetree, DropStmt))
|
||||||
{
|
{
|
||||||
DropStmt *dropStatement = (DropStmt *) parsetree;
|
DropStmt *dropStatement = (DropStmt *) parsetree;
|
||||||
|
|
||||||
PushCitusSecurityContext();
|
// PushCitusSecurityContext();
|
||||||
if (dropStatement->removeType == OBJECT_MATVIEW)
|
if (dropStatement->removeType == OBJECT_MATVIEW)
|
||||||
{
|
{
|
||||||
ProcessDropMaterializedViewStmt(dropStatement);
|
ProcessDropMaterializedViewStmt(dropStatement);
|
||||||
|
@ -490,7 +488,7 @@ multi_ProcessUtility(PlannedStmt *pstmt,
|
||||||
{
|
{
|
||||||
ProcessDropViewStmt(dropStatement);
|
ProcessDropViewStmt(dropStatement);
|
||||||
}
|
}
|
||||||
PopCitusSecurityContext();
|
// PopCitusSecurityContext();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
|
||||||
|
#include "postgres.h"
|
||||||
|
#include "distributed/security_utils.h"
|
||||||
|
#include "distributed/metadata_cache.h"
|
||||||
|
|
||||||
|
static Oid savedUserId = InvalidOid;
|
||||||
|
static int savedSecurityContext = 0;
|
||||||
|
|
||||||
|
void PushCitusSecurityContext(void) {
|
||||||
|
GetUserIdAndSecContext(&savedUserId, &savedSecurityContext);
|
||||||
|
SetUserIdAndSecContext(CitusExtensionOwner(), SECURITY_LOCAL_USERID_CHANGE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void PopCitusSecurityContext(void) {
|
||||||
|
SetUserIdAndSecContext(savedUserId, savedSecurityContext);
|
||||||
|
}
|
|
@ -14,13 +14,7 @@
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
#include "miscadmin.h"
|
#include "miscadmin.h"
|
||||||
|
|
||||||
#define PushCitusSecurityContext() \
|
extern void PushCitusSecurityContext(void);
|
||||||
Oid savedUserId_DONTUSE = InvalidOid; \
|
extern void PopCitusSecurityContext(void);
|
||||||
int savedSecurityContext_DONTUSE = 0; \
|
|
||||||
GetUserIdAndSecContext(&savedUserId_DONTUSE, &savedSecurityContext_DONTUSE); \
|
|
||||||
SetUserIdAndSecContext(CitusExtensionOwner(), SECURITY_LOCAL_USERID_CHANGE);
|
|
||||||
|
|
||||||
#define PopCitusSecurityContext() \
|
|
||||||
SetUserIdAndSecContext(savedUserId_DONTUSE, savedSecurityContext_DONTUSE);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue