Commit 7415e083 authored by Alvaro Herrera's avatar Alvaro Herrera

Refactor some bits in aclchk.c in order to reduce code duplication.

parent 164442fe
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.5 2005/11/22 18:17:08 momjian Exp $ * $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.6 2005/12/01 02:03:00 alvherre Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1122,6 +1122,7 @@ shdepDropOwned(List *roleids, DropBehavior behavior) ...@@ -1122,6 +1122,7 @@ shdepDropOwned(List *roleids, DropBehavior behavior)
{ {
ObjectAddress obj; ObjectAddress obj;
GrantObjectType objtype; GrantObjectType objtype;
InternalGrant istmt;
/* Shouldn't happen */ /* Shouldn't happen */
case SHARED_DEPENDENCY_PIN: case SHARED_DEPENDENCY_PIN:
...@@ -1132,22 +1133,22 @@ shdepDropOwned(List *roleids, DropBehavior behavior) ...@@ -1132,22 +1133,22 @@ shdepDropOwned(List *roleids, DropBehavior behavior)
switch (sdepForm->classid) switch (sdepForm->classid)
{ {
case RelationRelationId: case RelationRelationId:
objtype = ACL_OBJECT_RELATION; istmt.objtype = ACL_OBJECT_RELATION;
break; break;
case DatabaseRelationId: case DatabaseRelationId:
objtype = ACL_OBJECT_DATABASE; istmt.objtype = ACL_OBJECT_DATABASE;
break; break;
case ProcedureRelationId: case ProcedureRelationId:
objtype = ACL_OBJECT_FUNCTION; istmt.objtype = ACL_OBJECT_FUNCTION;
break; break;
case LanguageRelationId: case LanguageRelationId:
objtype = ACL_OBJECT_LANGUAGE; istmt.objtype = ACL_OBJECT_LANGUAGE;
break; break;
case NamespaceRelationId: case NamespaceRelationId:
objtype = ACL_OBJECT_NAMESPACE; istmt.objtype = ACL_OBJECT_NAMESPACE;
break; break;
case TableSpaceRelationId: case TableSpaceRelationId:
objtype = ACL_OBJECT_TABLESPACE; istmt.objtype = ACL_OBJECT_TABLESPACE;
break; break;
default: default:
elog(ERROR, "unexpected object type %d", elog(ERROR, "unexpected object type %d",
...@@ -1156,11 +1157,15 @@ shdepDropOwned(List *roleids, DropBehavior behavior) ...@@ -1156,11 +1157,15 @@ shdepDropOwned(List *roleids, DropBehavior behavior)
objtype = (GrantObjectType) 0; objtype = (GrantObjectType) 0;
break; break;
} }
istmt.is_grant = false;
ExecGrantStmt_oids(false, objtype, istmt.objects = list_make1_oid(sdepForm->objid);
list_make1_oid(sdepForm->objid), true, istmt.all_privs = true;
ACL_NO_RIGHTS, list_make1_oid(roleid), istmt.privileges = ACL_NO_RIGHTS;
false, DROP_CASCADE); istmt.grantees = list_make1_oid(roleid);
istmt.grant_option = false;
istmt.behavior = DROP_CASCADE;
ExecGrantStmt_oids(&istmt);
break; break;
case SHARED_DEPENDENCY_OWNER: case SHARED_DEPENDENCY_OWNER:
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/utils/acl.h,v 1.90 2005/11/22 18:17:31 momjian Exp $ * $PostgreSQL: pgsql/src/include/utils/acl.h,v 1.91 2005/12/01 02:03:01 alvherre Exp $
* *
* NOTES * NOTES
* An ACL array is simply an array of AclItems, representing the union * An ACL array is simply an array of AclItems, representing the union
...@@ -181,6 +181,26 @@ typedef enum AclObjectKind ...@@ -181,6 +181,26 @@ typedef enum AclObjectKind
MAX_ACL_KIND /* MUST BE LAST */ MAX_ACL_KIND /* MUST BE LAST */
} AclObjectKind; } AclObjectKind;
/*
* The information about one Grant/Revoke statement, in internal format: object
* and grantees names have been turned into Oids, the privilege list is an
* AclMode bitmask. If 'privileges' is ACL_NO_RIGHTS (the 0 value) and
* all_privs is true, it will be internally turned into the right kind of
* ACL_ALL_RIGHTS_*, depending on the object type (NB - this will modify the
* InternalGrant struct!)
*/
typedef struct
{
bool is_grant;
GrantObjectType objtype;
List *objects;
bool all_privs;
AclMode privileges;
List *grantees;
bool grant_option;
DropBehavior behavior;
} InternalGrant;
/* /*
* routines used internally * routines used internally
*/ */
...@@ -221,9 +241,7 @@ extern Datum hash_aclitem(PG_FUNCTION_ARGS); ...@@ -221,9 +241,7 @@ extern Datum hash_aclitem(PG_FUNCTION_ARGS);
* prototypes for functions in aclchk.c * prototypes for functions in aclchk.c
*/ */
extern void ExecuteGrantStmt(GrantStmt *stmt); extern void ExecuteGrantStmt(GrantStmt *stmt);
extern void ExecGrantStmt_oids(bool is_grant, GrantObjectType objtype, extern void ExecGrantStmt_oids(InternalGrant *istmt);
List *objects, bool all_privs, AclMode privileges,
List *grantees, bool grant_option, DropBehavior behavior);
extern AclMode pg_class_aclmask(Oid table_oid, Oid roleid, extern AclMode pg_class_aclmask(Oid table_oid, Oid roleid,
AclMode mask, AclMaskHow how); AclMode mask, AclMaskHow how);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment