66 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
77 * Portions Copyright (c) 1994, Regents of the University of California
88 *
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 $
1010 *
1111 *-------------------------------------------------------------------------
1212 */
@@ -227,7 +227,8 @@ CreateRole(CreateRoleStmt *stmt)
227227 errmsg ("permission denied to create role" )));
228228 }
229229
230- if (strcmp (stmt -> role , "public" ) == 0 )
230+ if (strcmp (stmt -> role , "public" ) == 0 ||
231+ strcmp (stmt -> role , "none" ) == 0 )
231232 ereport (ERROR ,
232233 (errcode (ERRCODE_RESERVED_NAME ),
233234 errmsg ("role name \"%s\" is reserved" ,
@@ -760,11 +761,15 @@ DropRole(DropRoleStmt *stmt)
760761 if (roleid == GetUserId ())
761762 ereport (ERROR ,
762763 (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" )));
764769 if (roleid == GetSessionUserId ())
765770 ereport (ERROR ,
766771 (errcode (ERRCODE_OBJECT_IN_USE ),
767- errmsg ("session role cannot be dropped" )));
772+ errmsg ("session user cannot be dropped" )));
768773
769774 /*
770775 * For safety's sake, we allow createrole holders to drop ordinary
@@ -893,15 +898,20 @@ RenameRole(const char *oldname, const char *newname)
893898 * XXX Client applications probably store the session user somewhere,
894899 * so renaming it could cause confusion. On the other hand, there may
895900 * 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.
897903 */
898904
899905 roleid = HeapTupleGetOid (oldtuple );
900906
901907 if (roleid == GetSessionUserId ())
902908 ereport (ERROR ,
903909 (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" )));
905915
906916 /* make sure the new name doesn't exist */
907917 if (SearchSysCacheExists (AUTHNAME ,
@@ -911,6 +921,13 @@ RenameRole(const char *oldname, const char *newname)
911921 (errcode (ERRCODE_DUPLICATE_OBJECT ),
912922 errmsg ("role \"%s\" already exists" , newname )));
913923
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+
914931 /*
915932 * createrole is enough privilege unless you want to mess with a superuser
916933 */
0 commit comments