Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite47cbb3

Browse files
committed
Add has_tablespace_privilege().
Christopher Kings-Lynne
1 parent1a0f3e4 commite47cbb3

File tree

5 files changed

+254
-6
lines changed

5 files changed

+254
-6
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.213 2004/07/02 22:49:45 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.214 2004/07/12 20:23:47 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -6980,6 +6980,21 @@ SELECT set_config('log_statement_stats', 'off', false);
69806980
<entry><type>boolean</type></entry>
69816981
<entry>does current user have privilege for schema</entry>
69826982
</row>
6983+
<row>
6984+
<entry><literal><function>has_tablespace_privilege</function>(<parameter>user</parameter>,
6985+
<parameter>tablespace</parameter>,
6986+
<parameter>privilege</parameter>)</literal>
6987+
</entry>
6988+
<entry><type>boolean</type></entry>
6989+
<entry>does user have privilege for tablespace</entry>
6990+
</row>
6991+
<row>
6992+
<entry><literal><function>has_tablespace_privilege</function>(<parameter>tablespace</parameter>,
6993+
<parameter>privilege</parameter>)</literal>
6994+
</entry>
6995+
<entry><type>boolean</type></entry>
6996+
<entry>does current user have privilege for tablespace</entry>
6997+
</row>
69836998
</tbody>
69846999
</tgroup>
69857000
</table>
@@ -6999,6 +7014,9 @@ SELECT set_config('log_statement_stats', 'off', false);
69997014
<indexterm zone="functions-misc">
70007015
<primary>has_schema_privilege</primary>
70017016
</indexterm>
7017+
<indexterm zone="functions-misc">
7018+
<primary>has_tablespace_privilege</primary>
7019+
</indexterm>
70027020

70037021
<para>
70047022
<function>has_table_privilege</function> checks whether a user
@@ -7064,6 +7082,14 @@ SELECT has_function_privilege('joeuser', 'myfunc(int, text)', 'execute');
70647082
<literal>USAGE</literal>.
70657083
</para>
70667084

7085+
<para>
7086+
<function>has_tablespace_privilege</function> checks whether a user
7087+
can access a tablespace in a particular way. The possibilities for its
7088+
arguments are analogous to <function>has_table_privilege</function>.
7089+
The desired access privilege type must evaluate to
7090+
<literal>CREATE</literal>.
7091+
</para>
7092+
70677093
<para>
70687094
To evaluate whether a user holds a grant option on the privilege,
70697095
append <literal> WITH GRANT OPTION</literal> to the privilege key

‎src/backend/utils/adt/acl.c

Lines changed: 205 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.106 2004/06/18 06:13:49 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.107 2004/07/12 20:23:50 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -21,6 +21,7 @@
2121
#include"catalog/pg_shadow.h"
2222
#include"catalog/pg_type.h"
2323
#include"commands/dbcommands.h"
24+
#include"commands/tablespace.h"
2425
#include"miscadmin.h"
2526
#include"utils/acl.h"
2627
#include"utils/builtins.h"
@@ -54,6 +55,8 @@ static Oidconvert_language_name(text *languagename);
5455
staticAclModeconvert_language_priv_string(text*priv_type_text);
5556
staticOidconvert_schema_name(text*schemaname);
5657
staticAclModeconvert_schema_priv_string(text*priv_type_text);
58+
staticOidconvert_tablespace_name(text*tablespacename);
59+
staticAclModeconvert_tablespace_priv_string(text*priv_type_text);
5760

5861

5962
/*
@@ -2207,3 +2210,204 @@ convert_schema_priv_string(text *priv_type_text)
22072210
errmsg("unrecognized privilege type: \"%s\"",priv_type)));
22082211
returnACL_NO_RIGHTS;/* keep compiler quiet */
22092212
}
2213+
2214+
/*
2215+
* has_tablespace_privilege variants
2216+
*These are all named "has_tablespace_privilege" at the SQL level.
2217+
*They take various combinations of tablespace name, tablespace OID,
2218+
*user name, user sysid, or implicit user = current_user.
2219+
*
2220+
*The result is a boolean value: true if user has the indicated
2221+
*privilege, false if not.
2222+
*/
2223+
2224+
/*
2225+
* has_tablespace_privilege_name_name
2226+
*Check user privileges on a tablespace given
2227+
*name username, text tablespacename, and text priv name.
2228+
*/
2229+
Datum
2230+
has_tablespace_privilege_name_name(PG_FUNCTION_ARGS)
2231+
{
2232+
Nameusername=PG_GETARG_NAME(0);
2233+
text*tablespacename=PG_GETARG_TEXT_P(1);
2234+
text*priv_type_text=PG_GETARG_TEXT_P(2);
2235+
int32usesysid;
2236+
Oidtablespaceoid;
2237+
AclModemode;
2238+
AclResultaclresult;
2239+
2240+
usesysid=get_usesysid(NameStr(*username));
2241+
tablespaceoid=convert_tablespace_name(tablespacename);
2242+
mode=convert_tablespace_priv_string(priv_type_text);
2243+
2244+
aclresult=pg_tablespace_aclcheck(tablespaceoid,usesysid,mode);
2245+
2246+
PG_RETURN_BOOL(aclresult==ACLCHECK_OK);
2247+
}
2248+
2249+
/*
2250+
* has_tablespace_privilege_name
2251+
*Check user privileges on a tablespace given
2252+
*text tablespacename and text priv name.
2253+
*current_user is assumed
2254+
*/
2255+
Datum
2256+
has_tablespace_privilege_name(PG_FUNCTION_ARGS)
2257+
{
2258+
text*tablespacename=PG_GETARG_TEXT_P(0);
2259+
text*priv_type_text=PG_GETARG_TEXT_P(1);
2260+
AclIdusesysid;
2261+
Oidtablespaceoid;
2262+
AclModemode;
2263+
AclResultaclresult;
2264+
2265+
usesysid=GetUserId();
2266+
tablespaceoid=convert_tablespace_name(tablespacename);
2267+
mode=convert_tablespace_priv_string(priv_type_text);
2268+
2269+
aclresult=pg_tablespace_aclcheck(tablespaceoid,usesysid,mode);
2270+
2271+
PG_RETURN_BOOL(aclresult==ACLCHECK_OK);
2272+
}
2273+
2274+
/*
2275+
* has_tablespace_privilege_name_id
2276+
*Check user privileges on a tablespace given
2277+
*name usename, tablespace oid, and text priv name.
2278+
*/
2279+
Datum
2280+
has_tablespace_privilege_name_id(PG_FUNCTION_ARGS)
2281+
{
2282+
Nameusername=PG_GETARG_NAME(0);
2283+
Oidtablespaceoid=PG_GETARG_OID(1);
2284+
text*priv_type_text=PG_GETARG_TEXT_P(2);
2285+
int32usesysid;
2286+
AclModemode;
2287+
AclResultaclresult;
2288+
2289+
usesysid=get_usesysid(NameStr(*username));
2290+
mode=convert_tablespace_priv_string(priv_type_text);
2291+
2292+
aclresult=pg_tablespace_aclcheck(tablespaceoid,usesysid,mode);
2293+
2294+
PG_RETURN_BOOL(aclresult==ACLCHECK_OK);
2295+
}
2296+
2297+
/*
2298+
* has_tablespace_privilege_id
2299+
*Check user privileges on a tablespace given
2300+
*tablespace oid, and text priv name.
2301+
*current_user is assumed
2302+
*/
2303+
Datum
2304+
has_tablespace_privilege_id(PG_FUNCTION_ARGS)
2305+
{
2306+
Oidtablespaceoid=PG_GETARG_OID(0);
2307+
text*priv_type_text=PG_GETARG_TEXT_P(1);
2308+
AclIdusesysid;
2309+
AclModemode;
2310+
AclResultaclresult;
2311+
2312+
usesysid=GetUserId();
2313+
mode=convert_tablespace_priv_string(priv_type_text);
2314+
2315+
aclresult=pg_tablespace_aclcheck(tablespaceoid,usesysid,mode);
2316+
2317+
PG_RETURN_BOOL(aclresult==ACLCHECK_OK);
2318+
}
2319+
2320+
/*
2321+
* has_tablespace_privilege_id_name
2322+
*Check user privileges on a tablespace given
2323+
*usesysid, text tablespacename, and text priv name.
2324+
*/
2325+
Datum
2326+
has_tablespace_privilege_id_name(PG_FUNCTION_ARGS)
2327+
{
2328+
int32usesysid=PG_GETARG_INT32(0);
2329+
text*tablespacename=PG_GETARG_TEXT_P(1);
2330+
text*priv_type_text=PG_GETARG_TEXT_P(2);
2331+
Oidtablespaceoid;
2332+
AclModemode;
2333+
AclResultaclresult;
2334+
2335+
tablespaceoid=convert_tablespace_name(tablespacename);
2336+
mode=convert_tablespace_priv_string(priv_type_text);
2337+
2338+
aclresult=pg_tablespace_aclcheck(tablespaceoid,usesysid,mode);
2339+
2340+
PG_RETURN_BOOL(aclresult==ACLCHECK_OK);
2341+
}
2342+
2343+
/*
2344+
* has_tablespace_privilege_id_id
2345+
*Check user privileges on a tablespace given
2346+
*usesysid, tablespace oid, and text priv name.
2347+
*/
2348+
Datum
2349+
has_tablespace_privilege_id_id(PG_FUNCTION_ARGS)
2350+
{
2351+
int32usesysid=PG_GETARG_INT32(0);
2352+
Oidtablespaceoid=PG_GETARG_OID(1);
2353+
text*priv_type_text=PG_GETARG_TEXT_P(2);
2354+
AclModemode;
2355+
AclResultaclresult;
2356+
2357+
mode=convert_tablespace_priv_string(priv_type_text);
2358+
2359+
aclresult=pg_tablespace_aclcheck(tablespaceoid,usesysid,mode);
2360+
2361+
PG_RETURN_BOOL(aclresult==ACLCHECK_OK);
2362+
}
2363+
2364+
/*
2365+
*Support routines for has_tablespace_privilege family.
2366+
*/
2367+
2368+
/*
2369+
* Given a tablespace name expressed as a string, look it up and return Oid
2370+
*/
2371+
staticOid
2372+
convert_tablespace_name(text*tablespacename)
2373+
{
2374+
char*spcname;
2375+
Oidoid;
2376+
2377+
spcname=DatumGetCString(DirectFunctionCall1(textout,
2378+
PointerGetDatum(tablespacename)));
2379+
oid=get_tablespace_oid(spcname);
2380+
2381+
if (!OidIsValid(oid))
2382+
ereport(ERROR,
2383+
(errcode(ERRCODE_UNDEFINED_OBJECT),
2384+
errmsg("tablespace \"%s\" does not exist",spcname)));
2385+
2386+
returnoid;
2387+
}
2388+
2389+
/*
2390+
* convert_tablespace_priv_string
2391+
*Convert text string to AclMode value.
2392+
*/
2393+
staticAclMode
2394+
convert_tablespace_priv_string(text*priv_type_text)
2395+
{
2396+
char*priv_type;
2397+
2398+
priv_type=DatumGetCString(DirectFunctionCall1(textout,
2399+
PointerGetDatum(priv_type_text)));
2400+
2401+
/*
2402+
* Return mode from priv_type string
2403+
*/
2404+
if (pg_strcasecmp(priv_type,"CREATE")==0)
2405+
returnACL_CREATE;
2406+
if (pg_strcasecmp(priv_type,"CREATE WITH GRANT OPTION")==0)
2407+
returnACL_GRANT_OPTION_FOR(ACL_CREATE);
2408+
2409+
ereport(ERROR,
2410+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2411+
errmsg("unrecognized privilege type: \"%s\"",priv_type)));
2412+
returnACL_NO_RIGHTS;/* keep compiler quiet */
2413+
}

‎src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.243 2004/07/02 22:49:48 tgl Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.244 2004/07/12 20:23:51 momjian Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200407022
56+
#defineCATALOG_VERSION_NO200407121
5757

5858
#endif

‎src/include/catalog/pg_proc.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.341 2004/07/02 22:49:48 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.342 2004/07/12 20:23:53 momjian Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -3181,6 +3181,18 @@ DESCR("current user privilege on schema by schema name");
31813181
DATA(insertOID=2273 (has_schema_privilegePGNSPPGUID12fftfs216"26 25"_null_has_schema_privilege_id-_null_ ));
31823182
DESCR("current user privilege on schema by schema oid");
31833183

3184+
DATA(insertOID=2390 (has_tablespace_privilegePGNSPPGUID12fftfs316"19 25 25"_null_has_tablespace_privilege_name_name-_null_ ));
3185+
DESCR("user privilege on tablespace by username, tablespace name");
3186+
DATA(insertOID=2391 (has_tablespace_privilegePGNSPPGUID12fftfs316"19 26 25"_null_has_tablespace_privilege_name_id-_null_ ));
3187+
DESCR("user privilege on tablespace by username, tablespace oid");
3188+
DATA(insertOID=2392 (has_tablespace_privilegePGNSPPGUID12fftfs316"23 25 25"_null_has_tablespace_privilege_id_name-_null_ ));
3189+
DESCR("user privilege on tablespace by usesysid, tablespace name");
3190+
DATA(insertOID=2393 (has_tablespace_privilegePGNSPPGUID12fftfs316"23 26 25"_null_has_tablespace_privilege_id_id-_null_ ));
3191+
DESCR("user privilege on tablespace by usesysid, tablespace oid");
3192+
DATA(insertOID=2394 (has_tablespace_privilegePGNSPPGUID12fftfs216"25 25"_null_has_tablespace_privilege_name-_null_ ));
3193+
DESCR("current user privilege on tablespace by tablespace name");
3194+
DATA(insertOID=2395 (has_tablespace_privilegePGNSPPGUID12fftfs216"26 25"_null_has_tablespace_privilege_id-_null_ ));
3195+
DESCR("current user privilege on tablespace by tablespace oid");
31843196

31853197
DATA(insertOID=2290 (record_inPGNSPPGUID12fftfv22249"2275 26"_null_record_in-_null_ ));
31863198
DESCR("I/O");

‎src/include/utils/builtins.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.245 2004/07/02 18:59:25 joe Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.246 2004/07/12 20:23:59 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -52,6 +52,12 @@ extern Datum has_schema_privilege_id_name(PG_FUNCTION_ARGS);
5252
externDatumhas_schema_privilege_id_id(PG_FUNCTION_ARGS);
5353
externDatumhas_schema_privilege_name(PG_FUNCTION_ARGS);
5454
externDatumhas_schema_privilege_id(PG_FUNCTION_ARGS);
55+
externDatumhas_tablespace_privilege_name_name(PG_FUNCTION_ARGS);
56+
externDatumhas_tablespace_privilege_name_id(PG_FUNCTION_ARGS);
57+
externDatumhas_tablespace_privilege_id_name(PG_FUNCTION_ARGS);
58+
externDatumhas_tablespace_privilege_id_id(PG_FUNCTION_ARGS);
59+
externDatumhas_tablespace_privilege_name(PG_FUNCTION_ARGS);
60+
externDatumhas_tablespace_privilege_id(PG_FUNCTION_ARGS);
5561

5662
/* bool.c */
5763
externDatumboolin(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp