6
6
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
7
7
* Portions Copyright (c) 1994, Regents of the University of California
8
8
*
9
- * $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.156 2005/07/07 20:39:58 tgl Exp $
9
+ * $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.157 2005/07/25 22:12:31 tgl Exp $
10
10
*
11
11
*-------------------------------------------------------------------------
12
12
*/
@@ -227,7 +227,8 @@ CreateRole(CreateRoleStmt *stmt)
227
227
errmsg ("permission denied to create role" )));
228
228
}
229
229
230
- if (strcmp (stmt -> role , "public" ) == 0 )
230
+ if (strcmp (stmt -> role , "public" ) == 0 ||
231
+ strcmp (stmt -> role , "none" ) == 0 )
231
232
ereport (ERROR ,
232
233
(errcode (ERRCODE_RESERVED_NAME ),
233
234
errmsg ("role name \"%s\" is reserved" ,
@@ -760,11 +761,15 @@ DropRole(DropRoleStmt *stmt)
760
761
if (roleid == GetUserId ())
761
762
ereport (ERROR ,
762
763
(errcode (ERRCODE_OBJECT_IN_USE ),
763
- errmsg ("current role cannot be dropped" )));
764
+ errmsg ("current user cannot be dropped" )));
765
+ if (roleid == GetOuterUserId ())
766
+ ereport (ERROR ,
767
+ (errcode (ERRCODE_OBJECT_IN_USE ),
768
+ errmsg ("current user cannot be dropped" )));
764
769
if (roleid == GetSessionUserId ())
765
770
ereport (ERROR ,
766
771
(errcode (ERRCODE_OBJECT_IN_USE ),
767
- errmsg ("session role cannot be dropped" )));
772
+ errmsg ("session user cannot be dropped" )));
768
773
769
774
/*
770
775
* For safety's sake, we allow createrole holders to drop ordinary
@@ -893,15 +898,20 @@ RenameRole(const char *oldname, const char *newname)
893
898
* XXX Client applications probably store the session user somewhere,
894
899
* so renaming it could cause confusion. On the other hand, there may
895
900
* not be an actual problem besides a little confusion, so think about
896
- * this and decide.
901
+ * this and decide. Same for SET ROLE ... we don't restrict renaming
902
+ * the current effective userid, though.
897
903
*/
898
904
899
905
roleid = HeapTupleGetOid (oldtuple );
900
906
901
907
if (roleid == GetSessionUserId ())
902
908
ereport (ERROR ,
903
909
(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
904
- errmsg ("session role may not be renamed" )));
910
+ errmsg ("session user may not be renamed" )));
911
+ if (roleid == GetOuterUserId ())
912
+ ereport (ERROR ,
913
+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
914
+ errmsg ("current user may not be renamed" )));
905
915
906
916
/* make sure the new name doesn't exist */
907
917
if (SearchSysCacheExists (AUTHNAME ,
@@ -911,6 +921,13 @@ RenameRole(const char *oldname, const char *newname)
911
921
(errcode (ERRCODE_DUPLICATE_OBJECT ),
912
922
errmsg ("role \"%s\" already exists" , newname )));
913
923
924
+ if (strcmp (newname , "public" ) == 0 ||
925
+ strcmp (newname , "none" ) == 0 )
926
+ ereport (ERROR ,
927
+ (errcode (ERRCODE_RESERVED_NAME ),
928
+ errmsg ("role name \"%s\" is reserved" ,
929
+ newname )));
930
+
914
931
/*
915
932
* createrole is enough privilege unless you want to mess with a superuser
916
933
*/
0 commit comments