Relation query_rel;
Oid save_userid;
int save_sec_context;
- int temp_sec_context;
/*
* Use the query type code to determine whether the query is run against
/* Switch to proper UID to perform check as */
GetUserIdAndSecContext(&save_userid, &save_sec_context);
-
- /*
- * Row-level security should be disabled in the case where a foreign-key
- * relation is queried to check existence of tuples that references the
- * primary-key being modified.
- */
- temp_sec_context = save_sec_context | SECURITY_LOCAL_USERID_CHANGE;
- if (qkey->constr_queryno == RI_PLAN_CHECK_LOOKUPPK
- || qkey->constr_queryno == RI_PLAN_CHECK_LOOKUPPK_FROM_PK
- || qkey->constr_queryno == RI_PLAN_RESTRICT_DEL_CHECKREF
- || qkey->constr_queryno == RI_PLAN_RESTRICT_UPD_CHECKREF)
- temp_sec_context |= SECURITY_ROW_LEVEL_DISABLED;
-
-
SetUserIdAndSecContext(RelationGetForm(query_rel)->relowner,
- temp_sec_context);
+ save_sec_context | SECURITY_LOCAL_USERID_CHANGE);
/* Create the plan */
qplan = SPI_prepare(querystr, nargs, argtypes);
plansource->total_custom_cost = 0;
plansource->num_custom_plans = 0;
plansource->hasRowSecurity = false;
- plansource->rowSecurityDisabled
- = (security_context & SECURITY_ROW_LEVEL_DISABLED) != 0;
plansource->planUserId = InvalidOid;
plansource->row_security_env = false;
}
/*
- * Check if row security is enabled for this query and things have changed
- * such that we need to invalidate this plan and rebuild it. Note that if
- * row security was explicitly disabled (eg: this is a FK check plan) then
- * we don't invalidate due to RLS.
- *
- * Otherwise, if the plan has a possible RLS dependency, force a replan if
- * either the role under which the plan was planned or the row_security
- * setting has been changed.
+ * If the plan has a possible RLS dependency, force a replan if either the
+ * role or the row_security setting has changed.
*/
if (plansource->is_valid
- && !plansource->rowSecurityDisabled
&& plansource->hasRowSecurity
&& (plansource->planUserId != GetUserId()
|| plansource->row_security_env != row_security))
bool relrowsecurity;
Oid user_id = checkAsUser ? checkAsUser : GetUserId();
+ /* Nothing to do for built-in relations */
+ if (relid < FirstNormalObjectId)
+ return RLS_NONE;
+
tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));
if (!HeapTupleIsValid(tuple))
return RLS_NONE;
/* flags to be OR'd to form sec_context */
#define SECURITY_LOCAL_USERID_CHANGE 0x0001
#define SECURITY_RESTRICTED_OPERATION 0x0002
-#define SECURITY_ROW_LEVEL_DISABLED 0x0004
extern char *DatabasePath;
#ifdef PGXC
char *stmt_name; /* If set, this is a copy of prepared stmt name */
#endif
- bool hasRowSecurity; /* planned with row security? */
- int row_security_env; /* row security setting when planned */
- bool rowSecurityDisabled; /* is row security disabled? */
+ bool hasRowSecurity; /* planned with row security? */
+ bool row_security_env; /* row security setting when planned */
} CachedPlanSource;
/*