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
178 errmsg(
"role name \"%s\" contains a newline or carriage return character",
stmt->role)));
181 switch (
stmt->stmt_type)
207 (
errmsg(
"SYSID can no longer be specified")));
221 else if (
strcmp(
defel->defname,
"createrole") == 0)
239 else if (
strcmp(
defel->defname,
"isreplication") == 0)
245 else if (
strcmp(
defel->defname,
"connectionlimit") == 0)
257 else if (
strcmp(
defel->defname,
"rolemembers") == 0)
263 else if (
strcmp(
defel->defname,
"adminmembers") == 0)
269 else if (
strcmp(
defel->defname,
"validUntil") == 0)
282 elog(
ERROR,
"option \"%s\" not recognized",
325 errmsg(
"permission denied to create role"),
326 errdetail(
"Only roles with the %s attribute may create roles.",
331 errmsg(
"permission denied to create role"),
332 errdetail(
"Only roles with the %s attribute may create roles with the %s attribute.",
333 "SUPERUSER",
"SUPERUSER")));
337 errmsg(
"permission denied to create role"),
338 errdetail(
"Only roles with the %s attribute may create roles with the %s attribute.",
339 "CREATEDB",
"CREATEDB")));
343 errmsg(
"permission denied to create role"),
344 errdetail(
"Only roles with the %s attribute may create roles with the %s attribute.",
345 "REPLICATION",
"REPLICATION")));
349 errmsg(
"permission denied to create role"),
350 errdetail(
"Only roles with the %s attribute may create roles with the %s attribute.",
351 "BYPASSRLS",
"BYPASSRLS")));
361 errmsg(
"role name \"%s\" is reserved",
363 errdetail(
"Role names starting with \"pg_\" are reserved.")));
369#ifdef ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS
371 elog(
WARNING,
"roles created by regression test cases should have names starting with \"regress_\"");
384 errmsg(
"role \"%s\" already exists",
406 (*check_password_hook) (
stmt->role,
428 const char *logdetail =
NULL;
446 (
errmsg(
"empty string is not a valid password, clearing password")));
475 errmsg(
"pg_authid OID value not set when in binary upgrade mode")));
659 _(
"Cannot alter reserved roles."));
684 else if (
strcmp(
defel->defname,
"createrole") == 0)
702 else if (
strcmp(
defel->defname,
"isreplication") == 0)
708 else if (
strcmp(
defel->defname,
"connectionlimit") == 0)
714 else if (
strcmp(
defel->defname,
"rolemembers") == 0 &&
721 else if (
strcmp(
defel->defname,
"validUntil") == 0)
734 elog(
ERROR,
"option \"%s\" not recognized",
766 errmsg(
"permission denied to alter role"),
767 errdetail(
"Only roles with the %s attribute may alter roles with the %s attribute.",
768 "SUPERUSER",
"SUPERUSER")));
772 errmsg(
"permission denied to alter role"),
773 errdetail(
"Only roles with the %s attribute may change the %s attribute.",
774 "SUPERUSER",
"SUPERUSER")));
788 errmsg(
"permission denied to alter role"),
789 errdetail(
"Only roles with the %s attribute and the %s option on role \"%s\" may alter this role.",
790 "CREATEROLE",
"ADMIN", rolename)));
796 errmsg(
"permission denied to alter role"),
797 errdetail(
"To change another role's password, the current user must have the %s attribute and the %s option on the role.",
798 "CREATEROLE",
"ADMIN")));
810 errmsg(
"permission denied to alter role"),
811 errdetail(
"Only roles with the %s attribute may change the %s attribute.",
812 "CREATEDB",
"CREATEDB")));
816 errmsg(
"permission denied to alter role"),
817 errdetail(
"Only roles with the %s attribute may change the %s attribute.",
818 "REPLICATION",
"REPLICATION")));
822 errmsg(
"permission denied to alter role"),
823 errdetail(
"Only roles with the %s attribute may change the %s attribute.",
824 "BYPASSRLS",
"BYPASSRLS")));
831 errmsg(
"permission denied to alter role"),
832 errdetail(
"Only roles with the %s option on role \"%s\" may add or drop members.",
833 "ADMIN", rolename)));
856 (*check_password_hook) (rolename,
876 errmsg(
"permission denied to alter role"),
877 errdetail(
"The bootstrap superuser must have the %s attribute.",
924 const char *logdetail =
NULL;
931 (
errmsg(
"empty string is not a valid password, clearing password")));
984 if (
stmt->action == +1)
988 else if (
stmt->action == -1)
1017 _(
"Cannot alter reserved roles."));
1039 errmsg(
"permission denied to alter role"),
1040 errdetail(
"Only roles with the %s attribute may alter roles with the %s attribute.",
1041 "SUPERUSER",
"SUPERUSER")));
1050 errmsg(
"permission denied to alter role"),
1051 errdetail(
"Only roles with the %s attribute and the %s option on role \"%s\" may alter this role.",
1076 if (!
stmt->role && !
stmt->database)
1082 errmsg(
"permission denied to alter setting"),
1083 errdetail(
"Only roles with the %s attribute may alter settings globally.",
1107 errmsg(
"permission denied to drop role"),
1108 errdetail(
"Only roles with the %s attribute and the %s option on the target roles may drop roles.",
1109 "CREATEROLE",
"ADMIN")));
1118 foreach(item,
stmt->roles)
1132 errmsg(
"cannot use special role specifier in DROP ROLE")));
1138 if (!
stmt->missing_ok)
1142 errmsg(
"role \"%s\" does not exist", role)));
1147 (
errmsg(
"role \"%s\" does not exist, skipping",
1160 errmsg(
"current user cannot be dropped")));
1164 errmsg(
"current user cannot be dropped")));
1168 errmsg(
"session user cannot be dropped")));
1178 errmsg(
"permission denied to drop role"),
1179 errdetail(
"Only roles with the %s attribute may drop roles with the %s attribute.",
1180 "SUPERUSER",
"SUPERUSER")));
1184 errmsg(
"permission denied to drop role"),
1185 errdetail(
"Only roles with the %s attribute and the %s option on role \"%s\" may drop this role.",
1292 elog(
ERROR,
"could not find tuple for role %u", roleid);
1303 &detail, &detail_log))
1306 errmsg(
"role \"%s\" cannot be dropped because some objects depend on it",
1361 errmsg(
"role name \"%s\" contains a newline or carriage return character", newname)));
1386 errmsg(
"session user cannot be renamed")));
1390 errmsg(
"current user cannot be renamed")));
1399 errmsg(
"role name \"%s\" is reserved",
1401 errdetail(
"Role names starting with \"pg_\" are reserved.")));
1406 errmsg(
"role name \"%s\" is reserved",
1408 errdetail(
"Role names starting with \"pg_\" are reserved.")));
1414#ifdef ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS
1415 if (
strncmp(newname,
"regress_", 8) != 0)
1416 elog(
WARNING,
"roles created by regression test cases should have names starting with \"regress_\"");
1423 errmsg(
"role \"%s\" already exists", newname)));
1434 errmsg(
"permission denied to rename role"),
1435 errdetail(
"Only roles with the %s attribute may rename roles with the %s attribute.",
1436 "SUPERUSER",
"SUPERUSER")));
1444 errmsg(
"permission denied to rename role"),
1445 errdetail(
"Only roles with the %s attribute and the %s option on role \"%s\" may rename this role.",
1467 (
errmsg(
"MD5 password cleared because of role rename")));
1504 foreach(item,
stmt->opt)
1536 errmsg(
"unrecognized value for role option \"%s\": \"%s\"",
1559 foreach(item,
stmt->granted_roles)
1569 errmsg(
"column names cannot be included in GRANT/REVOKE ROLE")));
1573 roleid,
stmt->is_grant);
1581 grantor, &popt,
stmt->behavior);
1609 errmsg(
"permission denied to drop objects"),
1610 errdetail(
"Only roles with privileges of role \"%s\" may drop objects owned by it.",
1638 errmsg(
"permission denied to reassign objects"),
1639 errdetail(
"Only roles with privileges of role \"%s\" may reassign objects owned by it.",
1649 errmsg(
"permission denied to reassign objects"),
1650 errdetail(
"Only roles with privileges of role \"%s\" may reassign objects to it.",
1747 errmsg(
"role \"%s\" cannot be a member of any role",
1760 errmsg(
"role \"%s\" is a member of role \"%s\"",
1800 errmsg(
"%s option cannot be granted back to your own grantor",
1826 errmsg(
"%s option cannot be granted back to your own grantor",
1903 (
errmsg(
"role \"%s\" has already been granted membership in role \"%s\" by role \"%s\"",
2038 (
errmsg(
"role \"%s\" has not been granted membership in role \"%s\" by role \"%s\"",
2102 elog(
ERROR,
"unknown role revoke action");
2139 errmsg(
"role \"%s\" cannot have explicit members",
2150 errmsg(
"permission denied to grant role \"%s\"",
2152 errdetail(
"Only roles with the %s attribute may grant roles with the %s attribute.",
2153 "SUPERUSER",
"SUPERUSER")));
2157 errmsg(
"permission denied to revoke role \"%s\"",
2159 errdetail(
"Only roles with the %s attribute may revoke roles with the %s attribute.",
2160 "SUPERUSER",
"SUPERUSER")));
2173 errmsg(
"permission denied to grant role \"%s\"",
2175 errdetail(
"Only roles with the %s option on role \"%s\" may grant this role.",
2180 errmsg(
"permission denied to revoke role \"%s\"",
2182 errdetail(
"Only roles with the %s option on role \"%s\" may revoke this role.",
2262 errmsg(
"permission denied to grant privileges as role \"%s\"",
2264 errdetail(
"Only roles with privileges of role \"%s\" may grant privileges as this role.",
2271 errmsg(
"permission denied to grant privileges as role \"%s\"",
2273 errdetail(
"The grantor must have the %s option on role \"%s\".",
2281 errmsg(
"permission denied to revoke privileges granted by role \"%s\"",
2283 errdetail(
"Only roles with privileges of role \"%s\" may revoke privileges granted by this role.",
2506 errmsg(
"dependent privileges exist"),
2507 errhint(
"Use CASCADE to revoke them too.")));
2521 popt->
admin =
false;
2585 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 errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
int int errdetail_internal(const char *fmt,...) pg_attribute_printf(1
int errhint(const char *fmt,...) pg_attribute_printf(1
int errdetail(const char *fmt,...) pg_attribute_printf(1
int int int errdetail_log(const char *fmt,...) pg_attribute_printf(1
#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)
END_CATALOG_STRUCT typedef FormData_pg_auth_members * Form_pg_auth_members
END_CATALOG_STRUCT typedef FormData_pg_authid * Form_pg_authid
static 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 SearchSysCache3(SysCacheIdentifier cacheId, Datum key1, Datum key2, Datum key3)
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Datum SysCacheGetAttr(SysCacheIdentifier 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)