39 #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
116 bool revoke_admin_option_only,
138 Datum new_record[Natts_pg_authid] = {0};
139 bool new_record_nulls[Natts_pg_authid] = {0};
145 bool issuper =
false;
147 bool createrole =
false;
149 bool canlogin =
false;
150 bool isreplication =
false;
151 bool bypassrls =
false;
156 char *validUntil = NULL;
157 Datum validUntil_datum;
158 bool validUntil_null;
165 DefElem *disreplication = NULL;
175 switch (
stmt->stmt_type)
192 if (strcmp(defel->
defname,
"password") == 0)
198 else if (strcmp(defel->
defname,
"sysid") == 0)
201 (
errmsg(
"SYSID can no longer be specified")));
203 else if (strcmp(defel->
defname,
"superuser") == 0)
209 else if (strcmp(defel->
defname,
"inherit") == 0)
215 else if (strcmp(defel->
defname,
"createrole") == 0)
221 else if (strcmp(defel->
defname,
"createdb") == 0)
227 else if (strcmp(defel->
defname,
"canlogin") == 0)
233 else if (strcmp(defel->
defname,
"isreplication") == 0)
237 disreplication = defel;
239 else if (strcmp(defel->
defname,
"connectionlimit") == 0)
245 else if (strcmp(defel->
defname,
"addroleto") == 0)
251 else if (strcmp(defel->
defname,
"rolemembers") == 0)
255 drolemembers = defel;
257 else if (strcmp(defel->
defname,
"adminmembers") == 0)
261 dadminmembers = defel;
263 else if (strcmp(defel->
defname,
"validUntil") == 0)
269 else if (strcmp(defel->
defname,
"bypassrls") == 0)
276 elog(
ERROR,
"option \"%s\" not recognized",
280 if (dpassword && dpassword->
arg)
299 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
300 errmsg(
"invalid connection limit: %d", connlimit)));
303 addroleto = (
List *) daddroleto->
arg;
305 rolemembers = (
List *) drolemembers->
arg;
307 adminmembers = (
List *) dadminmembers->
arg;
318 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
319 errmsg(
"permission denied to create role"),
320 errdetail(
"Only roles with the %s attribute may create roles.",
324 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
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")));
330 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
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")));
336 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
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")));
342 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
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")));
354 (
errcode(ERRCODE_RESERVED_NAME),
355 errmsg(
"role name \"%s\" is reserved",
357 errdetail(
"Role names starting with \"pg_\" are reserved.")));
363 #ifdef ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS
364 if (strncmp(
stmt->role,
"regress_", 8) != 0)
365 elog(
WARNING,
"roles created by regression test cases should have names starting with \"regress_\"");
378 errmsg(
"role \"%s\" already exists",
388 validUntil_null =
false;
392 validUntil_datum = (
Datum) 0;
393 validUntil_null =
true;
400 (*check_password_hook) (
stmt->role,
409 new_record[Anum_pg_authid_rolname - 1] =
411 new_record[Anum_pg_authid_rolsuper - 1] =
BoolGetDatum(issuper);
412 new_record[Anum_pg_authid_rolinherit - 1] =
BoolGetDatum(inherit);
413 new_record[Anum_pg_authid_rolcreaterole - 1] =
BoolGetDatum(createrole);
415 new_record[Anum_pg_authid_rolcanlogin - 1] =
BoolGetDatum(canlogin);
416 new_record[Anum_pg_authid_rolreplication - 1] =
BoolGetDatum(isreplication);
417 new_record[Anum_pg_authid_rolconnlimit - 1] =
Int32GetDatum(connlimit);
422 const char *logdetail = NULL;
440 (
errmsg(
"empty string is not a valid password, clearing password")));
441 new_record_nulls[Anum_pg_authid_rolpassword - 1] =
true;
448 new_record[Anum_pg_authid_rolpassword - 1] =
453 new_record_nulls[Anum_pg_authid_rolpassword - 1] =
true;
455 new_record[Anum_pg_authid_rolvaliduntil - 1] = validUntil_datum;
456 new_record_nulls[Anum_pg_authid_rolvaliduntil - 1] = validUntil_null;
458 new_record[Anum_pg_authid_rolbypassrls - 1] =
BoolGetDatum(bypassrls);
468 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
469 errmsg(
"pg_authid OID value not set when in binary upgrade mode")));
493 if (addroleto || adminmembers || rolemembers)
512 foreach(item, addroleto)
517 Oid oldroleid = oldroleform->oid;
518 char *oldrolename =
NameStr(oldroleform->rolname);
555 poptself.
admin =
true;
557 poptself.
set =
false;
560 memberSpecs, memberIds,
561 BOOTSTRAP_SUPERUSERID, &poptself);
580 memberSpecs, memberIds,
622 Datum new_record[Natts_pg_authid] = {0};
623 bool new_record_nulls[Natts_pg_authid] = {0};
624 bool new_record_repl[Natts_pg_authid] = {0};
634 char *validUntil = NULL;
635 Datum validUntil_datum;
636 bool validUntil_null;
643 DefElem *disreplication = NULL;
653 _(
"Cannot alter reserved roles."));
660 if (strcmp(defel->
defname,
"password") == 0)
666 else if (strcmp(defel->
defname,
"superuser") == 0)
672 else if (strcmp(defel->
defname,
"inherit") == 0)
678 else if (strcmp(defel->
defname,
"createrole") == 0)
684 else if (strcmp(defel->
defname,
"createdb") == 0)
690 else if (strcmp(defel->
defname,
"canlogin") == 0)
696 else if (strcmp(defel->
defname,
"isreplication") == 0)
700 disreplication = defel;
702 else if (strcmp(defel->
defname,
"connectionlimit") == 0)
708 else if (strcmp(defel->
defname,
"rolemembers") == 0 &&
713 drolemembers = defel;
715 else if (strcmp(defel->
defname,
"validUntil") == 0)
721 else if (strcmp(defel->
defname,
"bypassrls") == 0)
728 elog(
ERROR,
"option \"%s\" not recognized",
732 if (dpassword && dpassword->
arg)
739 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
740 errmsg(
"invalid connection limit: %d", connlimit)));
754 roleid = authform->oid;
759 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
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")));
765 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
766 errmsg(
"permission denied to alter role"),
767 errdetail(
"Only roles with the %s attribute may change the %s attribute.",
768 "SUPERUSER",
"SUPERUSER")));
778 if (dinherit || dcreaterole || dcreatedb || dcanlogin || dconnlimit ||
779 dvalidUntil || disreplication || dbypassRLS)
781 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
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)));
787 if (dpassword && roleid != currentUserId)
789 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
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")));
803 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
804 errmsg(
"permission denied to alter role"),
805 errdetail(
"Only roles with the %s attribute may change the %s attribute.",
806 "CREATEDB",
"CREATEDB")));
809 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
810 errmsg(
"permission denied to alter role"),
811 errdetail(
"Only roles with the %s attribute may change the %s attribute.",
812 "REPLICATION",
"REPLICATION")));
815 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
816 errmsg(
"permission denied to alter role"),
817 errdetail(
"Only roles with the %s attribute may change the %s attribute.",
818 "BYPASSRLS",
"BYPASSRLS")));
824 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
825 errmsg(
"permission denied to alter role"),
826 errdetail(
"Only roles with the %s option on role \"%s\" may add members.",
827 "ADMIN", rolename)));
836 validUntil_null =
false;
842 Anum_pg_authid_rolvaliduntil,
850 (*check_password_hook) (rolename,
865 bool should_be_super =
boolVal(dissuper->
arg);
867 if (!should_be_super && roleid == BOOTSTRAP_SUPERUSERID)
869 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
870 errmsg(
"permission denied to alter role"),
871 errdetail(
"The bootstrap user must have the %s attribute.",
874 new_record[Anum_pg_authid_rolsuper - 1] =
BoolGetDatum(should_be_super);
875 new_record_repl[Anum_pg_authid_rolsuper - 1] =
true;
881 new_record_repl[Anum_pg_authid_rolinherit - 1] =
true;
887 new_record_repl[Anum_pg_authid_rolcreaterole - 1] =
true;
893 new_record_repl[Anum_pg_authid_rolcreatedb - 1] =
true;
899 new_record_repl[Anum_pg_authid_rolcanlogin - 1] =
true;
905 new_record_repl[Anum_pg_authid_rolreplication - 1] =
true;
910 new_record[Anum_pg_authid_rolconnlimit - 1] =
Int32GetDatum(connlimit);
911 new_record_repl[Anum_pg_authid_rolconnlimit - 1] =
true;
918 const char *logdetail = NULL;
925 (
errmsg(
"empty string is not a valid password, clearing password")));
926 new_record_nulls[Anum_pg_authid_rolpassword - 1] =
true;
933 new_record[Anum_pg_authid_rolpassword - 1] =
936 new_record_repl[Anum_pg_authid_rolpassword - 1] =
true;
940 if (dpassword && dpassword->
arg == NULL)
942 new_record_repl[Anum_pg_authid_rolpassword - 1] =
true;
943 new_record_nulls[Anum_pg_authid_rolpassword - 1] =
true;
947 new_record[Anum_pg_authid_rolvaliduntil - 1] = validUntil_datum;
948 new_record_nulls[Anum_pg_authid_rolvaliduntil - 1] = validUntil_null;
949 new_record_repl[Anum_pg_authid_rolvaliduntil - 1] =
true;
954 new_record_repl[Anum_pg_authid_rolbypassrls - 1] =
true;
958 new_record_nulls, new_record_repl);
978 if (
stmt->action == +1)
982 else if (
stmt->action == -1)
1011 _(
"Cannot alter reserved roles."));
1015 roleid = roleform->oid;
1028 if (roleform->rolsuper)
1032 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
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")));
1043 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
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.",
1046 "CREATEROLE",
"ADMIN",
NameStr(roleform->rolname))));
1053 if (
stmt->database != NULL)
1070 if (!
stmt->role && !
stmt->database)
1075 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1076 errmsg(
"permission denied to alter setting"),
1077 errdetail(
"Only roles with the %s attribute may alter settings globally.",
1094 pg_auth_members_rel;
1100 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
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 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1127 errmsg(
"cannot use special role specifier in DROP ROLE")));
1133 if (!
stmt->missing_ok)
1136 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1137 errmsg(
"role \"%s\" does not exist", role)));
1142 (
errmsg(
"role \"%s\" does not exist, skipping",
1150 roleid = roleform->oid;
1154 (
errcode(ERRCODE_OBJECT_IN_USE),
1155 errmsg(
"current user cannot be dropped")));
1158 (
errcode(ERRCODE_OBJECT_IN_USE),
1159 errmsg(
"current user cannot be dropped")));
1162 (
errcode(ERRCODE_OBJECT_IN_USE),
1163 errmsg(
"session user cannot be dropped")));
1172 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1173 errmsg(
"permission denied to drop role"),
1174 errdetail(
"Only roles with the %s attribute may drop roles with the %s attribute.",
1175 "SUPERUSER",
"SUPERUSER")));
1178 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1179 errmsg(
"permission denied to drop role"),
1180 errdetail(
"Only roles with the %s attribute and the %s option on role \"%s\" may drop this role.",
1181 "CREATEROLE",
"ADMIN",
NameStr(roleform->rolname))));
1213 Anum_pg_auth_members_roleid,
1218 true, NULL, 1, &scankey);
1226 authmem_form->oid, 0);
1233 Anum_pg_auth_members_member,
1238 true, NULL, 1, &scankey);
1246 authmem_form->oid, 0);
1265 role_address->
classId = AuthIdRelationId;
1268 role_addresses =
lappend(role_addresses, role_address);
1274 foreach(item, role_addresses)
1292 elog(
ERROR,
"could not find tuple for role %u", roleid);
1303 &detail, &detail_log))
1305 (
errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
1306 errmsg(
"role \"%s\" cannot be dropped because some objects depend on it",
1349 Datum repl_val[Natts_pg_authid];
1350 bool repl_null[Natts_pg_authid];
1351 bool repl_repl[Natts_pg_authid];
1363 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1364 errmsg(
"role \"%s\" does not exist", oldname)));
1375 roleid = authform->oid;
1379 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1380 errmsg(
"session user cannot be renamed")));
1383 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1384 errmsg(
"current user cannot be renamed")));
1392 (
errcode(ERRCODE_RESERVED_NAME),
1393 errmsg(
"role name \"%s\" is reserved",
1395 errdetail(
"Role names starting with \"pg_\" are reserved.")));
1399 (
errcode(ERRCODE_RESERVED_NAME),
1400 errmsg(
"role name \"%s\" is reserved",
1402 errdetail(
"Role names starting with \"pg_\" are reserved.")));
1408 #ifdef ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS
1409 if (strncmp(newname,
"regress_", 8) != 0)
1410 elog(
WARNING,
"roles created by regression test cases should have names starting with \"regress_\"");
1417 errmsg(
"role \"%s\" already exists", newname)));
1423 if (authform->rolsuper)
1427 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1428 errmsg(
"permission denied to rename role"),
1429 errdetail(
"Only roles with the %s attribute may rename roles with the %s attribute.",
1430 "SUPERUSER",
"SUPERUSER")));
1437 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1438 errmsg(
"permission denied to rename role"),
1439 errdetail(
"Only roles with the %s attribute and the %s option on role \"%s\" may rename this role.",
1440 "CREATEROLE",
"ADMIN",
NameStr(authform->rolname))));
1444 for (
i = 0;
i < Natts_pg_authid;
i++)
1445 repl_repl[
i] =
false;
1447 repl_repl[Anum_pg_authid_rolname - 1] =
true;
1450 repl_null[Anum_pg_authid_rolname - 1] =
false;
1452 datum =
heap_getattr(oldtuple, Anum_pg_authid_rolpassword, dsc, &isnull);
1457 repl_repl[Anum_pg_authid_rolpassword - 1] =
true;
1458 repl_null[Anum_pg_authid_rolpassword - 1] =
true;
1461 (
errmsg(
"MD5 password cleared because of role rename")));
1498 foreach(item,
stmt->opt)
1503 if (strcmp(opt->
defname,
"admin") == 0)
1510 else if (strcmp(opt->
defname,
"inherit") == 0)
1516 else if (strcmp(opt->
defname,
"set") == 0)
1524 errcode(ERRCODE_SYNTAX_ERROR),
1529 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1530 errmsg(
"unrecognized value for role option \"%s\": \"%s\"",
1553 foreach(item,
stmt->granted_roles)
1560 if (rolename == NULL || priv->
cols !=
NIL)
1562 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
1563 errmsg(
"column names cannot be included in GRANT/REVOKE ROLE")));
1567 roleid,
stmt->is_grant);
1570 stmt->grantee_roles, grantee_ids,
1574 stmt->grantee_roles, grantee_ids,
1575 grantor, &popt,
stmt->behavior);
1596 foreach(cell, role_ids)
1602 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1603 errmsg(
"permission denied to drop objects"),
1604 errdetail(
"Only roles with privileges of role \"%s\" may drop objects owned by it.",
1625 foreach(cell, role_ids)
1631 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1632 errmsg(
"permission denied to reassign objects"),
1633 errdetail(
"Only roles with privileges of role \"%s\" may reassign objects owned by it.",
1642 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1643 errmsg(
"permission denied to reassign objects"),
1644 errdetail(
"Only roles with privileges of role \"%s\" may reassign objects to it.",
1664 foreach(l, memberNames)
1689 List *memberSpecs,
List *memberIds,
1714 forboth(specitem, memberSpecs, iditem, memberIds)
1738 if (memberid == ROLE_PG_DATABASE_OWNER)
1740 errmsg(
"role \"%s\" cannot be a member of any role",
1752 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
1753 errmsg(
"role \"%s\" is a member of role \"%s\"",
1771 if (popt->
admin && grantorId != BOOTSTRAP_SUPERUSERID)
1786 foreach(iditem, memberIds)
1790 if (memberid == BOOTSTRAP_SUPERUSERID)
1792 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
1793 errmsg(
"%s option cannot be granted back to your own grantor",
1812 authmem_form->member == grantorId &&
1813 authmem_form->admin_option)
1818 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
1819 errmsg(
"%s option cannot be granted back to your own grantor",
1826 forboth(specitem, memberSpecs, iditem, memberIds)
1832 Datum new_record[Natts_pg_auth_members] = {0};
1833 bool new_record_nulls[Natts_pg_auth_members] = {0};
1834 bool new_record_repl[Natts_pg_auth_members] = {0};
1837 new_record[Anum_pg_auth_members_roleid - 1] =
1839 new_record[Anum_pg_auth_members_member - 1] =
1841 new_record[Anum_pg_auth_members_grantor - 1] =
1859 bool at_least_one_change =
false;
1864 && authmem_form->admin_option != popt->
admin)
1866 new_record[Anum_pg_auth_members_admin_option - 1] =
1868 new_record_repl[Anum_pg_auth_members_admin_option - 1] =
1870 at_least_one_change =
true;
1874 && authmem_form->inherit_option != popt->
inherit)
1876 new_record[Anum_pg_auth_members_inherit_option - 1] =
1878 new_record_repl[Anum_pg_auth_members_inherit_option - 1] =
1880 at_least_one_change =
true;
1884 && authmem_form->set_option != popt->
set)
1886 new_record[Anum_pg_auth_members_set_option - 1] =
1888 new_record_repl[Anum_pg_auth_members_set_option - 1] =
1890 at_least_one_change =
true;
1893 if (!at_least_one_change)
1896 (
errmsg(
"role \"%s\" has already been granted membership in role \"%s\" by role \"%s\"",
1905 new_record_nulls, new_record_repl);
1920 new_record[Anum_pg_auth_members_admin_option - 1] =
1922 new_record[Anum_pg_auth_members_set_option - 1] =
1931 new_record[Anum_pg_auth_members_inherit_option - 1] =
1940 elog(
ERROR,
"cache lookup failed for role %u", memberid);
1942 new_record[Anum_pg_auth_members_inherit_option - 1] =
1949 Anum_pg_auth_members_oid);
1950 new_record[Anum_pg_auth_members_oid - 1] = objectId;
1952 new_record, new_record_nulls);
1956 newmembers[0] = grantorId;
1986 List *memberSpecs,
List *memberIds,
2022 forboth(specitem, memberSpecs, iditem, memberIds)
2031 (
errmsg(
"role \"%s\" has not been granted membership in role \"%s\" by role \"%s\"",
2061 authmem_form->oid, 0);
2068 Datum new_record[Natts_pg_auth_members] = {0};
2069 bool new_record_nulls[Natts_pg_auth_members] = {0};
2070 bool new_record_repl[Natts_pg_auth_members] = {0};
2075 new_record[Anum_pg_auth_members_admin_option - 1] =
2077 new_record_repl[Anum_pg_auth_members_admin_option - 1] =
2082 new_record[Anum_pg_auth_members_inherit_option - 1] =
2084 new_record_repl[Anum_pg_auth_members_inherit_option - 1] =
2089 new_record[Anum_pg_auth_members_set_option - 1] =
2091 new_record_repl[Anum_pg_auth_members_set_option - 1] =
2095 elog(
ERROR,
"unknown role revoke action");
2099 new_record_nulls, new_record_repl);
2129 if (is_grant && roleid == ROLE_PG_DATABASE_OWNER)
2131 errmsg(
"role \"%s\" cannot have explicit members",
2141 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2142 errmsg(
"permission denied to grant role \"%s\"",
2144 errdetail(
"Only roles with the %s attribute may grant roles with the %s attribute.",
2145 "SUPERUSER",
"SUPERUSER")));
2148 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2149 errmsg(
"permission denied to revoke role \"%s\"",
2151 errdetail(
"Only roles with the %s attribute may revoke roles with the %s attribute.",
2152 "SUPERUSER",
"SUPERUSER")));
2164 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2165 errmsg(
"permission denied to grant role \"%s\"",
2167 errdetail(
"Only roles with the %s option on role \"%s\" may grant this role.",
2171 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2172 errmsg(
"permission denied to revoke role \"%s\"",
2174 errdetail(
"Only roles with the %s option on role \"%s\" may revoke this role.",
2221 return BOOTSTRAP_SUPERUSERID;
2253 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2254 errmsg(
"permission denied to grant privileges as role \"%s\"",
2256 errdetail(
"Only roles with privileges of role \"%s\" may grant privileges as this role.",
2259 if (grantorId != BOOTSTRAP_SUPERUSERID &&
2262 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2263 errmsg(
"permission denied to grant privileges as role \"%s\"",
2265 errdetail(
"The grantor must have the %s option on role \"%s\".",
2272 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2273 errmsg(
"permission denied to revoke privileges granted by role \"%s\"",
2275 errdetail(
"Only roles with privileges of role \"%s\" may revoke privileges granted by this role.",
2350 if (authmem_form->member == member &&
2351 authmem_form->grantor == grantor)
2368 bool revoke_admin_option_only;
2374 revoke_admin_option_only =
2377 revoke_admin_option_only, behavior);
2409 if (authmem_form->member == member)
2424 bool would_still_have_admin_option =
false;
2433 revoke_admin_option_only)
2446 if (!revoke_admin_option_only)
2449 if (!authmem_form->admin_option)
2454 if (!authmem_form->admin_option)
2468 if (am_cascade_form->member == authmem_form->member &&
2469 am_cascade_form->admin_option && actions[
i] ==
RRG_NOOP)
2471 would_still_have_admin_option =
true;
2477 if (would_still_have_admin_option)
2492 if (am_cascade_form->grantor == authmem_form->member &&
2497 (
errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
2498 errmsg(
"dependent privileges exist"),
2499 errhint(
"Use CASCADE to revoke them too.")));
2513 popt->
admin =
false;
2542 foreach(l, elemlist)
2544 char *tok = (
char *)
lfirst(l);
2575 unsigned options = *(
unsigned *) extra;
bool is_admin_of_role(Oid member, Oid role)
char * get_rolespec_name(const RoleSpec *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)
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)
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)
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)
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)
static void plan_recursive_revoke(CatCList *memlist, RevokeRoleGrantAction *actions, int index, bool revoke_admin_option_only, DropBehavior behavior)
List * roleSpecsToIds(List *memberNames)
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)
Datum timestamptz_in(PG_FUNCTION_ARGS)
bool parse_bool(const char *value, bool *result)
#define CStringGetTextDatum(s)
#define TextDatumGetCString(d)
#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)
elog(ERROR, "%s: %s", p2, msg)
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 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)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
if(TABLE==NULL||TABLE_index==NULL)
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lappend(List *list, void *datum)
List * lappend_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)
char * GetUserNameFromId(Oid roleid, bool noerr)
Oid GetSessionUserId(void)
bool has_rolreplication(Oid roleid)
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
CatCTup * members[FLEXIBLE_ARRAY_MEMBER]
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)
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)