diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c index 0404307d3caa6affcf1e11feb125ed40d938184b..f206e806f430cb6394e5b0f5b2e8a4e487dae7b9 100644 --- a/src/backend/utils/adt/acl.c +++ b/src/backend/utils/adt/acl.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.101 2003/11/29 19:51:57 pgsql Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.102 2004/04/26 15:06:48 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -874,6 +874,43 @@ makeaclitem(PG_FUNCTION_ARGS) PG_RETURN_ACLITEM_P(aclitem); } +/* give access to internal data within aclitem + */ +Datum +aclitem_grantee(PG_FUNCTION_ARGS) +{ + AclItem * a = PG_GETARG_ACLITEM_P(0); + PG_RETURN_INT32(a->ai_grantee); +} + +Datum +aclitem_grantor(PG_FUNCTION_ARGS) +{ + AclItem * a = PG_GETARG_ACLITEM_P(0); + PG_RETURN_INT32(a->ai_grantor); +} + +Datum +aclitem_idtype(PG_FUNCTION_ARGS) +{ + AclItem * a = PG_GETARG_ACLITEM_P(0); + PG_RETURN_INT32(ACLITEM_GET_IDTYPE(*a)); +} + +Datum +aclitem_privs(PG_FUNCTION_ARGS) +{ + AclItem * a = PG_GETARG_ACLITEM_P(0); + PG_RETURN_INT32(ACLITEM_GET_PRIVS(*a)); +} + +Datum +aclitem_goptions(PG_FUNCTION_ARGS) +{ + AclItem * a = PG_GETARG_ACLITEM_P(0); + PG_RETURN_INT32(ACLITEM_GET_GOPTIONS(*a)); +} + static AclMode convert_priv_string(text *priv_type_text) { diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 50eea65169b2dfd121c6961c2186a67c3e65250f..9e1122982aec4db76e775103dcfa6ef286b283cd 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.224 2004/04/23 20:32:19 neilc Exp $ + * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.225 2004/04/26 15:06:49 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 200404220 +#define CATALOG_VERSION_NO 200404260 #endif diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index f4998eee572e9b67fbb24f6ed2fc2dd0f17da400..fa59adcfc81fb7df57d37c02cd9264e711a0f628 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.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/catalog/pg_proc.h,v 1.325 2004/04/23 20:32:19 neilc Exp $ + * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.326 2004/04/26 15:06:49 momjian Exp $ * * NOTES * The script catalog/genbki.sh reads this file and generates .bki @@ -3534,6 +3534,18 @@ DESCR("non-persistent series generator"); DATA(insert OID = 1069 ( generate_series PGNSP PGUID 12 f f t t v 2 20 "20 20" _null_ generate_series_int8 - _null_ )); DESCR("non-persistent series generator"); +/* aclitem utils */ +DATA(insert OID = 2510 ( aclitem_grantor PGNSP PGUID 12 f f t f i 1 23 "1033" _null_ aclitem_grantor - _null_ )); +DESCR("extract user id grantor from aclitem"); +DATA(insert OID = 2511 ( aclitem_grantee PGNSP PGUID 12 f f t f i 1 23 "1033" _null_ aclitem_grantee - _null_ )); +DESCR("extract grantee (user or group id) from aclitem"); +DATA(insert OID = 2512 ( aclitem_idtype PGNSP PGUID 12 f f t f i 1 23 "1033" _null_ aclitem_idtype - _null_ )); +DESCR("extract id type of grantee (0 public, 1 user, 2 group) from aclitem"); +DATA(insert OID = 2513 ( aclitem_privs PGNSP PGUID 12 f f t f i 1 23 "1033" _null_ aclitem_privs - _null_ )); +DESCR("extract privileges from aclitem"); +DATA(insert OID = 2514 ( aclitem_goptions PGNSP PGUID 12 f f t f i 1 23 "1033" _null_ aclitem_goptions - _null_ )); +DESCR("extract grant options from aclitem"); + /* * Symbolic values for provolatile column: these indicate whether the result diff --git a/src/include/utils/acl.h b/src/include/utils/acl.h index efe7af30b202934de8078c68db648b91ff71ae90..6cd1d7fb7ef20c8340a3e845da9f7bdfbb0f5c7a 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.66 2004/01/14 23:01:55 tgl Exp $ + * $PostgreSQL: pgsql/src/include/utils/acl.h,v 1.67 2004/04/26 15:06:49 momjian Exp $ * * NOTES * An ACL array is simply an array of AclItems, representing the union @@ -220,6 +220,11 @@ extern Datum aclcontains(PG_FUNCTION_ARGS); extern Datum makeaclitem(PG_FUNCTION_ARGS); extern Datum aclitem_eq(PG_FUNCTION_ARGS); extern Datum hash_aclitem(PG_FUNCTION_ARGS); +extern Datum aclitem_grantee(PG_FUNCTION_ARGS); +extern Datum aclitem_grantor(PG_FUNCTION_ARGS); +extern Datum aclitem_idtype(PG_FUNCTION_ARGS); +extern Datum aclitem_privs(PG_FUNCTION_ARGS); +extern Datum aclitem_goptions(PG_FUNCTION_ARGS); /* * prototypes for functions in aclchk.c diff --git a/src/test/regress/expected/privileges.out b/src/test/regress/expected/privileges.out index f5a6c039d5438b09c9cc27b88380e82786ee22e2..fe1b8483a65fa4efdf1b2e56996ad2f145ccd9b3 100644 --- a/src/test/regress/expected/privileges.out +++ b/src/test/regress/expected/privileges.out @@ -581,6 +581,20 @@ SELECT has_table_privilege('regressuser1', 'atest4', 'SELECT WITH GRANT OPTION') t (1 row) +-- aclitem utils small test +SELECT u1.usename AS u1, u2.usename AS u2, + aclitem_idtype(c.relacl[0]) AS idtype, + aclitem_privs(c.relacl[0]) AS privs, + aclitem_goptions(c.relacl[0]) AS goptions +FROM pg_class AS c, pg_user AS u1, pg_user AS u2 +WHERE u1.usesysid = aclitem_grantor(c.relacl[0]) + AND u2.usesysid = aclitem_grantee(c.relacl[0]) + AND c.relname LIKE 'atest4'; + u1 | u2 | idtype | privs | goptions +--------------+--------------+--------+-------+---------- + regressuser1 | regressuser1 | 1 | 127 | 127 +(1 row) + -- clean up \c regression DROP FUNCTION testfunc2(int); diff --git a/src/test/regress/sql/privileges.sql b/src/test/regress/sql/privileges.sql index d3e9b54303584afcb892e2f4e094f00a75181942..dd33295277a5d75845b47c06dc1370941394a4cf 100644 --- a/src/test/regress/sql/privileges.sql +++ b/src/test/regress/sql/privileges.sql @@ -316,6 +316,15 @@ SELECT has_table_privilege('regressuser3', 'atest4', 'SELECT'); -- false SELECT has_table_privilege('regressuser1', 'atest4', 'SELECT WITH GRANT OPTION'); -- true +-- aclitem utils small test +SELECT u1.usename AS u1, u2.usename AS u2, + aclitem_idtype(c.relacl[0]) AS idtype, + aclitem_privs(c.relacl[0]) AS privs, + aclitem_goptions(c.relacl[0]) AS goptions +FROM pg_class AS c, pg_user AS u1, pg_user AS u2 +WHERE u1.usesysid = aclitem_grantor(c.relacl[0]) + AND u2.usesysid = aclitem_grantee(c.relacl[0]) + AND c.relname LIKE 'atest4'; -- clean up