40#include "utils/fmgroids.h"
81#define GRANT_ROLE_SPECIFIED_ADMIN 0x0001
82#define GRANT_ROLE_SPECIFIED_INHERIT 0x0002
83#define GRANT_ROLE_SPECIFIED_SET 0x0004
175 switch (
stmt->stmt_type)
201 (
errmsg(
"SYSID can no longer be specified")));
215 else if (
strcmp(
defel->defname,
"createrole") == 0)
233 else if (
strcmp(
defel->defname,
"isreplication") == 0)
239 else if (
strcmp(
defel->defname,
"connectionlimit") == 0)
251 else if (
strcmp(
defel->defname,
"rolemembers") == 0)
257 else if (
strcmp(
defel->defname,
"adminmembers") == 0)
263 else if (
strcmp(
defel->defname,
"validUntil") == 0)
276 elog(
ERROR,
"option \"%s\" not recognized",
319 errmsg(
"permission denied to create role"),
320 errdetail(
"Only roles with the %s attribute may create roles.",
325 errmsg(
"permission denied to create role"),
326 errdetail(
"Only roles with the %s attribute may create roles with the %s attribute.",
327 "SUPERUSER",
"SUPERUSER")));
331 errmsg(
"permission denied to create role"),
332 errdetail(
"Only roles with the %s attribute may create roles with the %s attribute.",
333 "CREATEDB",
"CREATEDB")));
337 errmsg(
"permission denied to create role"),
338 errdetail(
"Only roles with the %s attribute may create roles with the %s attribute.",
339 "REPLICATION",
"REPLICATION")));
343 errmsg(
"permission denied to create role"),
344 errdetail(
"Only roles with the %s attribute may create roles with the %s attribute.",
345 "BYPASSRLS",
"BYPASSRLS")));
355 errmsg(
"role name \"%s\" is reserved",
357 errdetail(
"Role names starting with \"pg_\" are reserved.")));
363#ifdef ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS
365 elog(
WARNING,
"roles created by regression test cases should have names starting with \"regress_\"");
378 errmsg(
"role \"%s\" already exists",
400 (*check_password_hook) (
stmt->role,
422 const char *logdetail =
NULL;
440 (
errmsg(
"empty string is not a valid password, clearing password")));
469 errmsg(
"pg_authid OID value not set when in binary upgrade mode")));
653 _(
"Cannot alter reserved roles."));
678 else if (
strcmp(
defel->defname,
"createrole") == 0)
696 else if (
strcmp(
defel->defname,
"isreplication") == 0)
702 else if (
strcmp(
defel->defname,
"connectionlimit") == 0)
708 else if (
strcmp(
defel->defname,
"rolemembers") == 0 &&
715 else if (
strcmp(
defel->defname,
"validUntil") == 0)
728 elog(
ERROR,
"option \"%s\" not recognized",
760 errmsg(
"permission denied to alter role"),
761 errdetail(
"Only roles with the %s attribute may alter roles with the %s attribute.",
762 "SUPERUSER",
"SUPERUSER")));
766 errmsg(
"permission denied to alter role"),
767 errdetail(
"Only roles with the %s attribute may change the %s attribute.",
768 "SUPERUSER",
"SUPERUSER")));
782 errmsg(
"permission denied to alter role"),
783 errdetail(
"Only roles with the %s attribute and the %s option on role \"%s\" may alter this role.",
784 "CREATEROLE",
"ADMIN", rolename)));
790 errmsg(
"permission denied to alter role"),
791 errdetail(
"To change another role's password, the current user must have the %s attribute and the %s option on the role.",
792 "CREATEROLE",
"ADMIN")));
804 errmsg(
"permission denied to alter role"),
805 errdetail(
"Only roles with the %s attribute may change the %s attribute.",
806 "CREATEDB",
"CREATEDB")));
810 errmsg(
"permission denied to alter role"),
811 errdetail(
"Only roles with the %s attribute may change the %s attribute.",
812 "REPLICATION",
"REPLICATION")));
816 errmsg(
"permission denied to alter role"),
817 errdetail(
"Only roles with the %s attribute may change the %s attribute.",
818 "BYPASSRLS",
"BYPASSRLS")));
825 errmsg(
"permission denied to alter role"),
826 errdetail(
"Only roles with the %s option on role \"%s\" may add or drop members.",
827 "ADMIN", rolename)));
850 (*check_password_hook) (rolename,
870 errmsg(
"permission denied to alter role"),
871 errdetail(
"The bootstrap superuser must have the %s attribute.",
918 const char *logdetail =
NULL;
925 (
errmsg(
"empty string is not a valid password, clearing password")));
978 if (
stmt->action == +1)
982 else if (
stmt->action == -1)
1011 _(
"Cannot alter reserved roles."));
1033 errmsg(
"permission denied to alter role"),
1034 errdetail(
"Only roles with the %s attribute may alter roles with the %s attribute.",
1035 "SUPERUSER",
"SUPERUSER")));
1044 errmsg(
"permission denied to alter role"),
1045 errdetail(
"Only roles with the %s attribute and the %s option on role \"%s\" may alter this role.",
1070 if (!
stmt->role && !
stmt->database)
1076 errmsg(
"permission denied to alter setting"),
1077 errdetail(
"Only roles with the %s attribute may alter settings globally.",
1101 errmsg(
"permission denied to drop role"),
1102 errdetail(
"Only roles with the %s attribute and the %s option on the target roles may drop roles.",
1103 "CREATEROLE",
"ADMIN")));
1112 foreach(item,
stmt->roles)
1126 errmsg(
"cannot use special role specifier in DROP ROLE")));
1132 if (!
stmt->missing_ok)
1136 errmsg(
"role \"%s\" does not exist", role)));
1141 (
errmsg(
"role \"%s\" does not exist, skipping",
1154 errmsg(
"current user cannot be dropped")));
1158 errmsg(
"current user cannot be dropped")));
1162 errmsg(
"session user cannot be dropped")));
1172 errmsg(
"permission denied to drop role"),
1173 errdetail(
"Only roles with the %s attribute may drop roles with the %s attribute.",
1174 "SUPERUSER",
"SUPERUSER")));
1178 errmsg(
"permission denied to drop role"),
1179 errdetail(
"Only roles with the %s attribute and the %s option on role \"%s\" may drop this role.",
1286 elog(
ERROR,
"could not find tuple for role %u", roleid);
1297 &detail, &detail_log))
1300 errmsg(
"role \"%s\" cannot be dropped because some objects depend on it",
1374 errmsg(
"session user cannot be renamed")));
1378 errmsg(
"current user cannot be renamed")));
1387 errmsg(
"role name \"%s\" is reserved",
1389 errdetail(
"Role names starting with \"pg_\" are reserved.")));
1394 errmsg(
"role name \"%s\" is reserved",
1396 errdetail(
"Role names starting with \"pg_\" are reserved.")));
1402#ifdef ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS
1403 if (
strncmp(newname,
"regress_", 8) != 0)
1404 elog(
WARNING,
"roles created by regression test cases should have names starting with \"regress_\"");
1411 errmsg(
"role \"%s\" already exists", newname)));
1422 errmsg(
"permission denied to rename role"),
1423 errdetail(
"Only roles with the %s attribute may rename roles with the %s attribute.",
1424 "SUPERUSER",
"SUPERUSER")));
1432 errmsg(
"permission denied to rename role"),
1433 errdetail(
"Only roles with the %s attribute and the %s option on role \"%s\" may rename this role.",
1455 (
errmsg(
"MD5 password cleared because of role rename")));
1492 foreach(item,
stmt->opt)
1524 errmsg(
"unrecognized value for role option \"%s\": \"%s\"",
1547 foreach(item,
stmt->granted_roles)
1557 errmsg(
"column names cannot be included in GRANT/REVOKE ROLE")));
1561 roleid,
stmt->is_grant);
1569 grantor, &popt,
stmt->behavior);
1597 errmsg(
"permission denied to drop objects"),
1598 errdetail(
"Only roles with privileges of role \"%s\" may drop objects owned by it.",
1626 errmsg(
"permission denied to reassign objects"),
1627 errdetail(
"Only roles with privileges of role \"%s\" may reassign objects owned by it.",
1637 errmsg(
"permission denied to reassign objects"),
1638 errdetail(
"Only roles with privileges of role \"%s\" may reassign objects to it.",
1735 errmsg(
"role \"%s\" cannot be a member of any role",
1748 errmsg(
"role \"%s\" is a member of role \"%s\"",
1788 errmsg(
"%s option cannot be granted back to your own grantor",
1814 errmsg(
"%s option cannot be granted back to your own grantor",
1891 (
errmsg(
"role \"%s\" has already been granted membership in role \"%s\" by role \"%s\"",
2026 (
errmsg(
"role \"%s\" has not been granted membership in role \"%s\" by role \"%s\"",
2090 elog(
ERROR,
"unknown role revoke action");
2127 errmsg(
"role \"%s\" cannot have explicit members",
2138 errmsg(
"permission denied to grant role \"%s\"",
2140 errdetail(
"Only roles with the %s attribute may grant roles with the %s attribute.",
2141 "SUPERUSER",
"SUPERUSER")));
2145 errmsg(
"permission denied to revoke role \"%s\"",
2147 errdetail(
"Only roles with the %s attribute may revoke roles with the %s attribute.",
2148 "SUPERUSER",
"SUPERUSER")));
2161 errmsg(
"permission denied to grant role \"%s\"",
2163 errdetail(
"Only roles with the %s option on role \"%s\" may grant this role.",
2168 errmsg(
"permission denied to revoke role \"%s\"",
2170 errdetail(
"Only roles with the %s option on role \"%s\" may revoke this role.",
2250 errmsg(
"permission denied to grant privileges as role \"%s\"",
2252 errdetail(
"Only roles with privileges of role \"%s\" may grant privileges as this role.",
2259 errmsg(
"permission denied to grant privileges as role \"%s\"",
2261 errdetail(
"The grantor must have the %s option on role \"%s\".",
2269 errmsg(
"permission denied to revoke privileges granted by role \"%s\"",
2271 errdetail(
"Only roles with privileges of role \"%s\" may revoke privileges granted by this role.",
2494 errmsg(
"dependent privileges exist"),
2495 errhint(
"Use CASCADE to revoke them too.")));
2509 popt->
admin =
false;
2573 unsigned options = *(
unsigned *) extra;
bool is_admin_of_role(Oid member, Oid role)
Oid select_best_admin(Oid member, Oid role)
bool is_member_of_role_nosuper(Oid member, Oid role)
bool has_privs_of_role(Oid member, Oid role)
Oid get_role_oid(const char *rolname, bool missing_ok)
char * get_rolespec_name(const RoleSpec *role)
void check_rolespec_name(const RoleSpec *role, const char *detail_msg)
Oid get_rolespec_oid(const RoleSpec *role, bool missing_ok)
HeapTuple get_rolespec_tuple(const RoleSpec *role)
bool has_bypassrls_privilege(Oid roleid)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
bool has_createrole_privilege(Oid roleid)
Datum timestamptz_in(PG_FUNCTION_ARGS)
bool parse_bool(const char *value, bool *result)
#define CStringGetTextDatum(s)
#define TextDatumGetCString(d)
#define Assert(condition)
#define OidIsValid(objectId)
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
bool IsReservedName(const char *name)
int plain_crypt_verify(const char *role, const char *shadow_pass, const char *client_pass, const char **logdetail)
PasswordType get_password_type(const char *shadow_pass)
char * encrypt_password(PasswordType target_type, const char *role, const char *password)
@ PASSWORD_TYPE_SCRAM_SHA_256
bool have_createdb_privilege(void)
Oid get_database_oid(const char *dbname, bool missing_ok)
Oid createdb(ParseState *pstate, const CreatedbStmt *stmt)
char * defGetString(DefElem *def)
void errorConflictingDefElem(DefElem *defel, ParseState *pstate)
int errdetail_internal(const char *fmt,...)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
int errdetail_log(const char *fmt,...)
#define ereport(elevel,...)
#define palloc_object(type)
#define palloc_array(type, count)
#define DirectFunctionCall1(func, arg1)
#define DirectFunctionCall3(func, arg1, arg2, arg3)
void systable_endscan(SysScanDesc sysscan)
HeapTuple systable_getnext(SysScanDesc sysscan)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
void * guc_malloc(int elevel, size_t size)
#define GUC_check_errdetail
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
static void * GETSTRUCT(const HeapTupleData *tuple)
void CatalogTupleUpdate(Relation heapRel, const ItemPointerData *otid, HeapTuple tup)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
void CatalogTupleDelete(Relation heapRel, const ItemPointerData *tid)
List * lappend_oid(List *list, Oid datum)
List * list_append_unique_oid(List *list, Oid datum)
void list_free(List *list)
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
#define AccessExclusiveLock
#define ShareUpdateExclusiveLock
char * pstrdup(const char *in)
void pfree(void *pointer)
Oid GetSessionUserId(void)
bool has_rolreplication(Oid roleid)
char * GetUserNameFromId(Oid roleid, bool noerr)
Datum namein(PG_FUNCTION_ARGS)
#define InvokeObjectPostCreateHook(classId, objectId, subId)
#define InvokeObjectPostAlterHook(classId, objectId, subId)
#define InvokeObjectDropHook(classId, objectId, subId)
#define ObjectAddressSet(addr, class_id, object_id)
int parser_errposition(ParseState *pstate, int location)
FormData_pg_auth_members * Form_pg_auth_members
FormData_pg_authid * Form_pg_authid
int pg_popcount32(uint32 word)
void DropSetting(Oid databaseid, Oid roleid)
void AlterSetting(Oid databaseid, Oid roleid, VariableSetStmt *setstmt)
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define forboth(cell1, list1, cell2, list2)
#define list_make1_oid(x1)
static rewind_source * source
void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId, int32 objectSubId)
void updateAclDependencies(Oid classId, Oid objectId, int32 objsubId, Oid ownerId, int noldmembers, Oid *oldmembers, int nnewmembers, Oid *newmembers)
bool checkSharedDependencies(Oid classId, Oid objectId, char **detail_msg, char **detail_log_msg)
void shdepDropOwned(List *roleids, DropBehavior behavior)
void shdepLockAndCheckObject(Oid classId, Oid objectId)
void shdepReassignOwned(List *roleids, Oid newrole)
int pg_strcasecmp(const char *s1, const char *s2)
static Datum PointerGetDatum(const void *X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
#define RelationGetDescr(relation)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
void DeleteSharedSecurityLabel(Oid objectId, Oid classId)
#define BTEqualStrategyNumber
#define ERRCODE_DUPLICATE_OBJECT
bool superuser_arg(Oid roleid)
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
HeapTuple SearchSysCache3(int cacheId, Datum key1, Datum key2, Datum key3)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
#define ReleaseSysCacheList(x)
#define SearchSysCacheList1(cacheId, key1)
#define SearchSysCacheExists1(cacheId, key1)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
static bool have_createrole_privilege(void)
ObjectAddress RenameRole(const char *oldname, const char *newname)
#define GRANT_ROLE_SPECIFIED_ADMIN
static bool plan_single_revoke(CatCList *memlist, RevokeRoleGrantAction *actions, Oid member, Oid grantor, GrantRoleOptions *popt, DropBehavior behavior)
static GrantRoleOptions createrole_self_grant_options
static void InitGrantRoleOptions(GrantRoleOptions *popt)
static void plan_member_revoke(CatCList *memlist, RevokeRoleGrantAction *actions, Oid member)
static void AddRoleMems(Oid currentUserId, const char *rolename, Oid roleid, List *memberSpecs, List *memberIds, Oid grantorId, GrantRoleOptions *popt)
void ReassignOwnedObjects(ReassignOwnedStmt *stmt)
Oid AlterRole(ParseState *pstate, AlterRoleStmt *stmt)
static bool createrole_self_grant_enabled
#define GRANT_ROLE_SPECIFIED_SET
Oid AlterRoleSet(AlterRoleSetStmt *stmt)
static Oid check_role_grantor(Oid currentUserId, Oid roleid, Oid grantorId, bool is_grant)
bool check_createrole_self_grant(char **newval, void **extra, GucSource source)
void assign_createrole_self_grant(const char *newval, void *extra)
static void check_role_membership_authorization(Oid currentUserId, Oid roleid, bool is_grant)
Oid binary_upgrade_next_pg_authid_oid
#define GRANT_ROLE_SPECIFIED_INHERIT
void DropRole(DropRoleStmt *stmt)
Oid CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
void GrantRole(ParseState *pstate, GrantRoleStmt *stmt)
List * roleSpecsToIds(List *memberNames)
static void plan_recursive_revoke(CatCList *memlist, RevokeRoleGrantAction *actions, int index, bool revoke_admin_option_only, DropBehavior behavior)
char * createrole_self_grant
check_password_hook_type check_password_hook
@ RRG_REMOVE_INHERIT_OPTION
@ RRG_REMOVE_ADMIN_OPTION
static RevokeRoleGrantAction * initialize_revoke_actions(CatCList *memlist)
void DropOwnedObjects(DropOwnedStmt *stmt)
static void DelRoleMems(Oid currentUserId, const char *rolename, Oid roleid, List *memberSpecs, List *memberIds, Oid grantorId, GrantRoleOptions *popt, DropBehavior behavior)
void(* check_password_hook_type)(const char *username, const char *shadow_pass, PasswordType password_type, Datum validuntil_time, bool validuntil_null)
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
void CommandCounterIncrement(void)