diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-01-14 23:01:55 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-01-14 23:01:55 +0000 |
commit | cfd7fb7ed4b66da97f88338d991843fa7e2fe59d (patch) | |
tree | f433f1281eba10a7ab2e563fa39eaf3228df32e8 /src/include | |
parent | 01d320d421b3f82de799e86e8b9adac27c2f9a26 (diff) | |
download | postgresql-cfd7fb7ed4b66da97f88338d991843fa7e2fe59d.tar.gz postgresql-cfd7fb7ed4b66da97f88338d991843fa7e2fe59d.zip |
Fix permission-checking bug reported by Tim Burgess 10-Feb-03 (this time
for sure...). Rather than relying on the query context of a rangetable
entry to identify what permissions it wants checked, store a full AclMode
mask in each RTE, and check exactly those bits. This allows an RTE
specifying, say, INSERT privilege on a view to be copied into a derived
UPDATE query without changing meaning. Per recent discussion thread.
initdb forced due to change of stored rule representation.
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/catalog/catversion.h | 4 | ||||
-rw-r--r-- | src/include/executor/executor.h | 4 | ||||
-rw-r--r-- | src/include/nodes/parsenodes.h | 66 | ||||
-rw-r--r-- | src/include/parser/parse_clause.h | 4 | ||||
-rw-r--r-- | src/include/utils/acl.h | 14 |
5 files changed, 49 insertions, 43 deletions
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 1910e33e3b1..7dd262c1e46 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -37,7 +37,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.215 2004/01/06 23:55:19 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.216 2004/01/14 23:01:55 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 200401061 +#define CATALOG_VERSION_NO 200401141 #endif diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h index 8f1dc7fafaf..050894708c8 100644 --- a/src/include/executor/executor.h +++ b/src/include/executor/executor.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/executor/executor.h,v 1.104 2003/12/18 20:21:37 tgl Exp $ + * $PostgreSQL: pgsql/src/include/executor/executor.h,v 1.105 2004/01/14 23:01:55 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -91,7 +91,7 @@ extern TupleTableSlot *ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, long count); extern void ExecutorEnd(QueryDesc *queryDesc); extern void ExecutorRewind(QueryDesc *queryDesc); -extern void ExecCheckRTPerms(List *rangeTable, CmdType operation); +extern void ExecCheckRTPerms(List *rangeTable); extern void ExecEndPlan(PlanState *planstate, EState *estate); extern void ExecConstraints(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate); diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 8b6446d8605..01ff239a444 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.252 2004/01/10 23:28:45 neilc Exp $ + * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.253 2004/01/14 23:01:55 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -27,6 +27,32 @@ typedef enum QuerySource QSRC_NON_INSTEAD_RULE /* added by non-INSTEAD rule */ } QuerySource; +/* + * Grantable rights are encoded so that we can OR them together in a bitmask. + * The present representation of AclItem limits us to 15 distinct rights, + * even though AclMode is defined as uint32. See utils/acl.h. + * + * Caution: changing these codes breaks stored ACLs, hence forces initdb. + */ +typedef uint32 AclMode; /* a bitmask of privilege bits */ + +#define ACL_INSERT (1<<0) /* for relations */ +#define ACL_SELECT (1<<1) +#define ACL_UPDATE (1<<2) +#define ACL_DELETE (1<<3) +#define ACL_RULE (1<<4) +#define ACL_REFERENCES (1<<5) +#define ACL_TRIGGER (1<<6) +#define ACL_EXECUTE (1<<7) /* for functions */ +#define ACL_USAGE (1<<8) /* for languages and namespaces */ +#define ACL_CREATE (1<<9) /* for namespaces and databases */ +#define ACL_CREATE_TEMP (1<<10) /* for databases */ +#define N_ACL_RIGHTS 11 /* 1 plus the last 1<<x */ +#define ACL_ALL_RIGHTS (-1) /* all-privileges marker in GRANT list */ +#define ACL_NO_RIGHTS 0 +/* Currently, SELECT ... FOR UPDATE requires UPDATE privileges */ +#define ACL_SELECT_FOR_UPDATE ACL_UPDATE + /***************************************************************************** * Query Tree @@ -425,12 +451,13 @@ typedef struct DefElem * column names processed later, and it also shouldn't affect the * expansion of '*'. * - * checkForRead, checkForWrite, and checkAsUser control run-time access - * permissions checks. A rel will be checked for read or write access - * (or both, or neither) per checkForRead and checkForWrite. If - * checkAsUser is not InvalidOid, then do the permissions checks using - * the access rights of that user, not the current effective user ID. - * (This allows rules to act as setuid gateways.) + * requiredPerms and checkAsUser specify run-time access permissions + * checks to be performed at query startup. The user must have *all* + * of the permissions that are OR'd together in requiredPerms (zero + * indicates no permissions checking). If checkAsUser is not zero, + * then do the permissions checks using the access rights of that user, + * not the current effective user ID. (This allows rules to act as + * setuid gateways.) *-------------------- */ typedef enum RTEKind @@ -490,9 +517,8 @@ typedef struct RangeTblEntry Alias *eref; /* expanded reference names */ bool inh; /* inheritance requested? */ bool inFromCl; /* present in FROM clause */ - bool checkForRead; /* check rel for read access */ - bool checkForWrite; /* check rel for write access */ - Oid checkAsUser; /* if not zero, check access as this user */ + AclMode requiredPerms; /* bitmask of required access permissions */ + AclId checkAsUser; /* if not zero, check access as this user */ } RangeTblEntry; /* @@ -809,26 +835,6 @@ typedef enum GrantObjectType ACL_OBJECT_NAMESPACE /* namespace */ } GrantObjectType; -/* - * Grantable rights are encoded so that we can OR them together in a bitmask. - * The present representation of AclItem limits us to 15 distinct rights. - * Caution: changing these codes breaks stored ACLs, hence forces initdb. - */ -#define ACL_INSERT (1<<0) /* for relations */ -#define ACL_SELECT (1<<1) -#define ACL_UPDATE (1<<2) -#define ACL_DELETE (1<<3) -#define ACL_RULE (1<<4) -#define ACL_REFERENCES (1<<5) -#define ACL_TRIGGER (1<<6) -#define ACL_EXECUTE (1<<7) /* for functions */ -#define ACL_USAGE (1<<8) /* for languages and namespaces */ -#define ACL_CREATE (1<<9) /* for namespaces and databases */ -#define ACL_CREATE_TEMP (1<<10) /* for databases */ -#define N_ACL_RIGHTS 11 /* 1 plus the last 1<<x */ -#define ACL_ALL_RIGHTS (-1) /* all-privileges marker in GRANT list */ -#define ACL_NO_RIGHTS 0 - typedef struct GrantStmt { NodeTag type; diff --git a/src/include/parser/parse_clause.h b/src/include/parser/parse_clause.h index a57a80325b5..d91f5e80643 100644 --- a/src/include/parser/parse_clause.h +++ b/src/include/parser/parse_clause.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/parser/parse_clause.h,v 1.38 2003/11/29 22:41:09 pgsql Exp $ + * $PostgreSQL: pgsql/src/include/parser/parse_clause.h,v 1.39 2004/01/14 23:01:55 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -18,7 +18,7 @@ extern void transformFromClause(ParseState *pstate, List *frmList); extern int setTargetTable(ParseState *pstate, RangeVar *relation, - bool inh, bool alsoSource); + bool inh, bool alsoSource, AclMode requiredPerms); extern bool interpretInhOption(InhOption inhOpt); extern Node *transformWhereClause(ParseState *pstate, Node *clause, diff --git a/src/include/utils/acl.h b/src/include/utils/acl.h index be34fcce5ce..efe7af30b20 100644 --- a/src/include/utils/acl.h +++ b/src/include/utils/acl.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/utils/acl.h,v 1.65 2003/11/29 22:41:15 pgsql Exp $ + * $PostgreSQL: pgsql/src/include/utils/acl.h,v 1.66 2004/01/14 23:01:55 tgl Exp $ * * NOTES * An ACL array is simply an array of AclItems, representing the union @@ -28,7 +28,12 @@ #include "utils/array.h" -/* typedef AclId is declared in c.h */ +/* + * typedef AclId is declared in c.h + * + * typedef AclMode is declared in parsenodes.h, also the individual privilege + * bit meanings are defined there + */ #define ACL_ID_WORLD 0 /* placeholder for id in a WORLD acl item */ @@ -40,11 +45,6 @@ #define ACL_IDTYPE_GID 0x02 /* group id - from pg_group */ /* - * AclMode a bitmask of privilege bits - */ -typedef uint32 AclMode; - -/* * AclItem * * The IDTYPE included in ai_privs identifies the type of the grantee ID. |