From 22eaf35c1d247407b7cf1fffb310a26cd9b9ceb1 Mon Sep 17 00:00:00 2001 From: Stephen Frost Date: Tue, 15 Sep 2015 15:49:31 -0400 Subject: RLS refactoring This refactors rewrite/rowsecurity.c to simplify the handling of the default deny case (reducing the number of places where we check for and add the default deny policy from three to one) by splitting up the retrival of the policies from the application of them. This also allowed us to do away with the policy_id field. A policy_name field was added for WithCheckOption policies and is used in error reporting, when available. Patch by Dean Rasheed, with various mostly cosmetic changes by me. Back-patch to 9.5 where RLS was introduced to avoid unnecessary differences, since we're still in alpha, per discussion with Robert. --- src/backend/commands/policy.c | 41 ----------------------------------------- 1 file changed, 41 deletions(-) (limited to 'src/backend/commands') diff --git a/src/backend/commands/policy.c b/src/backend/commands/policy.c index 45326a3bec4..8851fe7c9ff 100644 --- a/src/backend/commands/policy.c +++ b/src/backend/commands/policy.c @@ -186,9 +186,6 @@ policy_role_list_to_array(List *roles, int *num_roles) /* * Load row security policy from the catalog, and store it in * the relation's relcache entry. - * - * We will always set up some kind of policy here. If no explicit policies - * are found then an implicit default-deny policy is created. */ void RelationBuildRowSecurity(Relation relation) @@ -246,7 +243,6 @@ RelationBuildRowSecurity(Relation relation) char *with_check_value; Expr *with_check_qual; char *policy_name_value; - Oid policy_id; bool isnull; RowSecurityPolicy *policy; @@ -298,14 +294,11 @@ RelationBuildRowSecurity(Relation relation) else with_check_qual = NULL; - policy_id = HeapTupleGetOid(tuple); - /* Now copy everything into the cache context */ MemoryContextSwitchTo(rscxt); policy = palloc0(sizeof(RowSecurityPolicy)); policy->policy_name = pstrdup(policy_name_value); - policy->policy_id = policy_id; policy->polcmd = cmd_value; policy->roles = DatumGetArrayTypePCopy(roles_datum); policy->qual = copyObject(qual_expr); @@ -326,40 +319,6 @@ RelationBuildRowSecurity(Relation relation) systable_endscan(sscan); heap_close(catalog, AccessShareLock); - - /* - * Check if no policies were added - * - * If no policies exist in pg_policy for this relation, then we need - * to create a single default-deny policy. We use InvalidOid for the - * Oid to indicate that this is the default-deny policy (we may decide - * to ignore the default policy if an extension adds policies). - */ - if (rsdesc->policies == NIL) - { - RowSecurityPolicy *policy; - Datum role; - - MemoryContextSwitchTo(rscxt); - - role = ObjectIdGetDatum(ACL_ID_PUBLIC); - - policy = palloc0(sizeof(RowSecurityPolicy)); - policy->policy_name = pstrdup("default-deny policy"); - policy->policy_id = InvalidOid; - policy->polcmd = '*'; - policy->roles = construct_array(&role, 1, OIDOID, sizeof(Oid), true, - 'i'); - policy->qual = (Expr *) makeConst(BOOLOID, -1, InvalidOid, - sizeof(bool), BoolGetDatum(false), - false, true); - policy->with_check_qual = copyObject(policy->qual); - policy->hassublinks = false; - - rsdesc->policies = lcons(policy, rsdesc->policies); - - MemoryContextSwitchTo(oldcxt); - } } PG_CATCH(); { -- cgit v1.2.3