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

Commit87d0036

Browse files
committed
Make PUBLIC an unreserved word (in fact, not a keyword at all),
per previous discussion.
1 parentb312080 commit87d0036

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

‎src/backend/commands/user.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.95 2002/04/04 04:25:45 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.96 2002/04/18 21:16:16 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -153,7 +153,7 @@ write_group_file(Relation urel, Relation grel)
153153
datum=heap_getattr(tuple,Anum_pg_group_groname,dsc,&isnull);
154154
if (isnull)
155155
continue;/* ignore NULL groupnames */
156-
groname=(char*)DatumGetName(datum);
156+
groname=NameStr(*DatumGetName(datum));
157157

158158
grolist_datum=heap_getattr(tuple,Anum_pg_group_grolist,dsc,&isnull);
159159
/* Ignore NULL group lists */
@@ -293,7 +293,7 @@ write_user_file(Relation urel)
293293
datum=heap_getattr(tuple,Anum_pg_shadow_usename,dsc,&isnull);
294294
if (isnull)
295295
continue;/* ignore NULL usernames */
296-
usename=(char*)DatumGetName(datum);
296+
usename=NameStr(*DatumGetName(datum));
297297

298298
datum=heap_getattr(tuple,Anum_pg_shadow_passwd,dsc,&isnull);
299299

@@ -498,6 +498,10 @@ CreateUser(CreateUserStmt *stmt)
498498
if (!superuser())
499499
elog(ERROR,"CREATE USER: permission denied");
500500

501+
if (strcmp(stmt->user,"public")==0)
502+
elog(ERROR,"CREATE USER: user name \"%s\" is reserved",
503+
stmt->user);
504+
501505
/*
502506
* Scan the pg_shadow relation to be certain the user or id doesn't
503507
* already exist. Note we secure exclusive lock, because we also need
@@ -518,7 +522,7 @@ CreateUser(CreateUserStmt *stmt)
518522
datum=heap_getattr(tuple,Anum_pg_shadow_usename,
519523
pg_shadow_dsc,&null);
520524
Assert(!null);
521-
user_exists= (strcmp((char*)DatumGetName(datum),stmt->user)==0);
525+
user_exists= (strcmp(NameStr(*DatumGetName(datum)),stmt->user)==0);
522526

523527
datum=heap_getattr(tuple,Anum_pg_shadow_usesysid,
524528
pg_shadow_dsc,&null);
@@ -1027,7 +1031,7 @@ DropUser(DropUserStmt *stmt)
10271031
datum=heap_getattr(tmp_tuple,Anum_pg_database_datname,
10281032
pg_dsc,&null);
10291033
Assert(!null);
1030-
dbname=(char*)DatumGetName(datum);
1034+
dbname=NameStr(*DatumGetName(datum));
10311035
elog(ERROR,"DROP USER: user \"%s\" owns database \"%s\", cannot be removed%s",
10321036
user,dbname,
10331037
(length(stmt->users)>1) ?" (no users removed)" :"");
@@ -1186,6 +1190,10 @@ CreateGroup(CreateGroupStmt *stmt)
11861190
if (!superuser())
11871191
elog(ERROR,"CREATE GROUP: permission denied");
11881192

1193+
if (strcmp(stmt->name,"public")==0)
1194+
elog(ERROR,"CREATE GROUP: group name \"%s\" is reserved",
1195+
stmt->name);
1196+
11891197
pg_group_rel=heap_openr(GroupRelationName,ExclusiveLock);
11901198
pg_group_dsc=RelationGetDescr(pg_group_rel);
11911199

@@ -1200,7 +1208,7 @@ CreateGroup(CreateGroupStmt *stmt)
12001208
datum=heap_getattr(tuple,Anum_pg_group_groname,
12011209
pg_group_dsc,&null);
12021210
Assert(!null);
1203-
group_exists= (strcmp((char*)DatumGetName(datum),stmt->name)==0);
1211+
group_exists= (strcmp(NameStr(*DatumGetName(datum)),stmt->name)==0);
12041212

12051213
datum=heap_getattr(tuple,Anum_pg_group_grosysid,
12061214
pg_group_dsc,&null);
@@ -1597,7 +1605,7 @@ DropGroup(DropGroupStmt *stmt)
15971605

15981606
datum=heap_getattr(tuple,Anum_pg_group_groname,
15991607
pg_group_dsc,&null);
1600-
if (!null&&strcmp((char*)DatumGetName(datum),stmt->name)==0)
1608+
if (!null&&strcmp(NameStr(*DatumGetName(datum)),stmt->name)==0)
16011609
{
16021610
gro_exists= true;
16031611
simple_heap_delete(pg_group_rel,&tuple->t_self);

‎src/backend/parser/gram.y

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.304 2002/04/1820:01:09 tgl Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.305 2002/04/1821:16:16 tgl Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -330,7 +330,7 @@ static bool set_name_needs_quotes(const char *name);
330330
MATCH,MINUTE_P,MONTH_P,NAMES,
331331
NATIONAL,NATURAL,NCHAR,NEXT,NO,NOT,NULLIF,NULL_P,NUMERIC,
332332
OF,OLD,ON,ONLY,OPTION,OR,ORDER,OUTER_P,OVERLAPS,
333-
PARTIAL,POSITION,PRECISION,PRIMARY,PRIOR,PRIVILEGES,PROCEDURE,PUBLIC,
333+
PARTIAL,POSITION,PRECISION,PRIMARY,PRIOR,PRIVILEGES,PROCEDURE,
334334
READ,REFERENCES,RELATIVE,REVOKE,RIGHT,ROLLBACK,
335335
SCHEMA,SCROLL,SECOND_P,SELECT,SESSION,SESSION_USER,SET,SOME,SUBSTRING,
336336
TABLE,TEMPORARY,THEN,TIME,TIMESTAMP,
@@ -2532,25 +2532,26 @@ grantee_list: grantee{ $$ = makeList1($1); }
25322532
|grantee_list','grantee{$$ = lappend($1,$3); }
25332533
;
25342534

2535-
grantee:PUBLIC
2535+
grantee:ColId
25362536
{
25372537
PrivGrantee *n = makeNode(PrivGrantee);
2538-
n->username =NULL;
2538+
/* This hack lets us avoid reserving PUBLIC as a keyword*/
2539+
if (strcmp($1,"public") ==0)
2540+
n->username =NULL;
2541+
else
2542+
n->username =$1;
25392543
n->groupname =NULL;
25402544
$$ = (Node *)n;
25412545
}
25422546
|GROUPColId
25432547
{
25442548
PrivGrantee *n = makeNode(PrivGrantee);
2549+
/* Treat GROUP PUBLIC as a synonym for PUBLIC*/
2550+
if (strcmp($2,"public") ==0)
2551+
n->groupname =NULL;
2552+
else
2553+
n->groupname =$2;
25452554
n->username =NULL;
2546-
n->groupname =$2;
2547-
$$ = (Node *)n;
2548-
}
2549-
|ColId
2550-
{
2551-
PrivGrantee *n = makeNode(PrivGrantee);
2552-
n->username =$1;
2553-
n->groupname =NULL;
25542555
$$ = (Node *)n;
25552556
}
25562557
;
@@ -6112,7 +6113,7 @@ unreserved_keyword:
61126113
|STATISTICS{$$ ="statistics"; }
61136114
|STDIN{$$ ="stdin"; }
61146115
|STDOUT{$$ ="stdout"; }
6115-
|STORAGE{$$ ="storage"; }
6116+
|STORAGE{$$ ="storage"; }
61166117
|SYSID{$$ ="sysid"; }
61176118
|TEMP{$$ ="temp"; }
61186119
|TEMPLATE{$$ ="template"; }
@@ -6205,7 +6206,6 @@ func_name_keyword:
62056206
|NOTNULL{$$ ="notnull"; }
62066207
|OUTER_P{$$ ="outer"; }
62076208
|OVERLAPS{$$ ="overlaps"; }
6208-
|PUBLIC{$$ ="public"; }
62096209
|RIGHT{$$ ="right"; }
62106210
|VERBOSE{$$ ="verbose"; }
62116211
;

‎src/backend/parser/keywords.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.104 2002/03/19 02:18:19 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.105 2002/04/18 21:16:16 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -211,7 +211,6 @@ static ScanKeyword ScanKeywords[] = {
211211
{"privileges",PRIVILEGES},
212212
{"procedural",PROCEDURAL},
213213
{"procedure",PROCEDURE},
214-
{"public",PUBLIC},
215214
{"read",READ},
216215
{"references",REFERENCES},
217216
{"reindex",REINDEX},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp