82#include "utils/fmgroids.h"
131 int num_col_privileges);
135 int num_col_privileges);
139 bool all_privs,
AclMode privileges,
140 Oid objectId,
Oid grantorId,
185 Oid grantorId,
Oid ownerId)
210 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
211 errmsg(
"grant options can only be granted to roles")));
226 newer_acl =
aclupdate(new_acl, &aclitem, modechg, ownerId, behavior);
285 elog(
ERROR,
"grantable rights not supported for event triggers");
295 elog(
ERROR,
"unrecognized object type: %d", objtype);
307 if (
pg_aclmask(objtype, objectId, att_number, grantorId,
328 if (this_privileges == 0)
332 (
errcode(ERRCODE_WARNING_PRIVILEGE_NOT_GRANTED),
333 errmsg(
"no privileges were granted for column \"%s\" of relation \"%s\"",
337 (
errcode(ERRCODE_WARNING_PRIVILEGE_NOT_GRANTED),
338 errmsg(
"no privileges were granted for \"%s\"",
341 else if (!all_privs && this_privileges != privileges)
345 (
errcode(ERRCODE_WARNING_PRIVILEGE_NOT_GRANTED),
346 errmsg(
"not all privileges were granted for column \"%s\" of relation \"%s\"",
350 (
errcode(ERRCODE_WARNING_PRIVILEGE_NOT_GRANTED),
351 errmsg(
"not all privileges were granted for \"%s\"",
357 if (this_privileges == 0)
361 (
errcode(ERRCODE_WARNING_PRIVILEGE_NOT_REVOKED),
362 errmsg(
"no privileges could be revoked for column \"%s\" of relation \"%s\"",
366 (
errcode(ERRCODE_WARNING_PRIVILEGE_NOT_REVOKED),
367 errmsg(
"no privileges could be revoked for \"%s\"",
370 else if (!all_privs && this_privileges != privileges)
374 (
errcode(ERRCODE_WARNING_PRIVILEGE_NOT_REVOKED),
375 errmsg(
"not all privileges could be revoked for column \"%s\" of relation \"%s\"",
379 (
errcode(ERRCODE_WARNING_PRIVILEGE_NOT_REVOKED),
380 errmsg(
"not all privileges could be revoked for \"%s\"",
385 return this_privileges;
396 const char *errormsg;
411 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
412 errmsg(
"grantor must be current user")));
422 switch (
stmt->targtype)
433 elog(
ERROR,
"unrecognized GrantStmt.targtype: %d",
434 (
int)
stmt->targtype);
449 foreach(cell,
stmt->grantees)
470 switch (
stmt->objtype)
480 errormsg =
gettext_noop(
"invalid privilege type %s for relation");
484 errormsg =
gettext_noop(
"invalid privilege type %s for sequence");
488 errormsg =
gettext_noop(
"invalid privilege type %s for database");
492 errormsg =
gettext_noop(
"invalid privilege type %s for domain");
496 errormsg =
gettext_noop(
"invalid privilege type %s for function");
500 errormsg =
gettext_noop(
"invalid privilege type %s for language");
504 errormsg =
gettext_noop(
"invalid privilege type %s for large object");
508 errormsg =
gettext_noop(
"invalid privilege type %s for schema");
512 errormsg =
gettext_noop(
"invalid privilege type %s for procedure");
516 errormsg =
gettext_noop(
"invalid privilege type %s for routine");
520 errormsg =
gettext_noop(
"invalid privilege type %s for tablespace");
524 errormsg =
gettext_noop(
"invalid privilege type %s for type");
528 errormsg =
gettext_noop(
"invalid privilege type %s for foreign-data wrapper");
532 errormsg =
gettext_noop(
"invalid privilege type %s for foreign server");
536 errormsg =
gettext_noop(
"invalid privilege type %s for parameter");
539 elog(
ERROR,
"unrecognized GrantStmt.objtype: %d",
540 (
int)
stmt->objtype);
561 foreach(cell,
stmt->privileges)
574 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
575 errmsg(
"column privileges are only valid for relations")));
581 elog(
ERROR,
"AccessPriv node must specify privilege or columns");
584 if (priv & ~((
AclMode) all_privileges))
586 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
644 elog(
ERROR,
"unrecognized GrantStmt.objtype: %d",
679 foreach(cell, objnames)
696 foreach(cell, objnames)
715 foreach(cell, objnames)
733 foreach(cell, objnames)
781 foreach(cell, nspnames)
819 Anum_pg_proc_pronamespace,
826 Anum_pg_proc_prokind,
831 Anum_pg_proc_prokind,
851 elog(
ERROR,
"unrecognized GrantStmt.objtype: %d",
874 Anum_pg_class_relnamespace,
878 Anum_pg_class_relkind,
913 const char *errormsg;
916 foreach(cell,
stmt->options)
920 if (strcmp(defel->
defname,
"schemas") == 0)
926 else if (strcmp(defel->
defname,
"roles") == 0)
937 nspnames = (
List *) dnspnames->
arg;
939 rolespecs = (
List *) drolespecs->
arg;
957 foreach(cell,
action->grantees)
982 errormsg =
gettext_noop(
"invalid privilege type %s for relation");
986 errormsg =
gettext_noop(
"invalid privilege type %s for sequence");
990 errormsg =
gettext_noop(
"invalid privilege type %s for function");
994 errormsg =
gettext_noop(
"invalid privilege type %s for procedure");
998 errormsg =
gettext_noop(
"invalid privilege type %s for routine");
1002 errormsg =
gettext_noop(
"invalid privilege type %s for type");
1006 errormsg =
gettext_noop(
"invalid privilege type %s for schema");
1010 errormsg =
gettext_noop(
"invalid privilege type %s for large object");
1013 elog(
ERROR,
"unrecognized GrantStmt.objtype: %d",
1035 foreach(cell,
action->privileges)
1042 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
1043 errmsg(
"default privileges cannot be set for columns")));
1046 elog(
ERROR,
"AccessPriv node must specify privilege");
1049 if (priv & ~((
AclMode) all_privileges))
1051 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
1058 if (rolespecs ==
NIL)
1070 foreach(rolecell, rolespecs)
1078 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1079 errmsg(
"permission denied to change default privileges")));
1094 if (nspnames ==
NIL)
1106 foreach(nspcell, nspnames)
1170 objtype = DEFACLOBJ_RELATION;
1176 objtype = DEFACLOBJ_SEQUENCE;
1182 objtype = DEFACLOBJ_FUNCTION;
1188 objtype = DEFACLOBJ_TYPE;
1196 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
1197 errmsg(
"cannot use IN SCHEMA clause when using GRANT/REVOKE ON SCHEMAS")));
1198 objtype = DEFACLOBJ_NAMESPACE;
1206 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
1207 errmsg(
"cannot use IN SCHEMA clause when using GRANT/REVOKE ON LARGE OBJECTS")));
1208 objtype = DEFACLOBJ_LARGEOBJECT;
1214 elog(
ERROR,
"unrecognized object type: %d",
1232 Anum_pg_default_acl_defaclacl,
1246 if (old_acl != NULL)
1253 noldmembers =
aclmembers(old_acl, &oldmembers);
1296 myself.
classId = DefaultAclRelationId;
1306 bool nulls[Natts_pg_default_acl] = {0};
1307 bool replaces[Natts_pg_default_acl] = {0};
1314 Anum_pg_default_acl_oid);
1330 replaces[Anum_pg_default_acl_defaclacl - 1] =
true;
1333 values, nulls, replaces);
1350 myself.
classId = DefaultAclRelationId;
1354 referenced.
classId = NamespaceRelationId;
1365 nnewmembers =
aclmembers(new_acl, &newmembers);
1370 noldmembers, oldmembers,
1371 nnewmembers, newmembers);
1409 if (classid == DefaultAclRelationId)
1422 Anum_pg_default_acl_oid,
1432 elog(
ERROR,
"could not find tuple for default ACL %u", objid);
1436 iacls.
roleid = pg_default_acl_tuple->defaclrole;
1437 iacls.
nspid = pg_default_acl_tuple->defaclnamespace;
1439 switch (pg_default_acl_tuple->defaclobjtype)
1441 case DEFACLOBJ_RELATION:
1444 case DEFACLOBJ_SEQUENCE:
1447 case DEFACLOBJ_FUNCTION:
1450 case DEFACLOBJ_TYPE:
1453 case DEFACLOBJ_NAMESPACE:
1456 case DEFACLOBJ_LARGEOBJECT:
1461 elog(
ERROR,
"unexpected default ACL type: %d",
1462 (
int) pg_default_acl_tuple->defaclobjtype);
1485 case RelationRelationId:
1489 case DatabaseRelationId:
1492 case TypeRelationId:
1495 case ProcedureRelationId:
1498 case LanguageRelationId:
1501 case LargeObjectRelationId:
1504 case NamespaceRelationId:
1507 case TableSpaceRelationId:
1510 case ForeignServerRelationId:
1513 case ForeignDataWrapperRelationId:
1516 case ParameterAclRelationId:
1520 elog(
ERROR,
"unexpected object class %u", classid);
1548 int num_col_privileges)
1552 foreach(cell, colnames)
1560 (
errcode(ERRCODE_UNDEFINED_COLUMN),
1561 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
1564 if (attnum <= 0 || attnum >= num_col_privileges)
1565 elog(
ERROR,
"column number out of range");
1566 col_privileges[
attnum] |= this_privileges;
1581 int num_col_privileges)
1587 curr_att <= classForm->relnatts;
1597 if (classForm->relkind == RELKIND_VIEW && curr_att < 0)
1604 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
1605 curr_att, table_oid);
1640 bool nulls[Natts_pg_attribute] = {0};
1641 bool replaces[Natts_pg_attribute] = {0};
1651 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
1659 aclDatum =
SysCacheGetAttr(ATTNUM, attr_tuple, Anum_pg_attribute_attacl,
1672 noldmembers =
aclmembers(old_acl, &oldmembers);
1681 merged_acl =
aclconcat(old_rel_acl, old_acl);
1685 merged_acl, ownerId,
1686 &grantorId, &avail_goptions);
1704 NameStr(pg_attribute_tuple->attname));
1712 col_privileges, grantorId,
1719 nnewmembers =
aclmembers(new_acl, &newmembers);
1737 nulls[Anum_pg_attribute_attacl - 1] =
true;
1738 need_update = !isNull;
1740 replaces[Anum_pg_attribute_attacl - 1] =
true;
1745 values, nulls, replaces);
1751 ACL_NUM(new_acl) > 0 ? new_acl : NULL);
1756 noldmembers, oldmembers,
1757 nnewmembers, newmembers);
1786 int num_col_privileges;
1787 bool have_col_privileges;
1798 elog(
ERROR,
"cache lookup failed for relation %u", relOid);
1802 if (pg_class_tuple->relkind == RELKIND_INDEX ||
1803 pg_class_tuple->relkind == RELKIND_PARTITIONED_INDEX)
1805 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1806 errmsg(
"\"%s\" is an index",
1807 NameStr(pg_class_tuple->relname))));
1810 if (pg_class_tuple->relkind == RELKIND_COMPOSITE_TYPE)
1812 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1813 errmsg(
"\"%s\" is a composite type",
1814 NameStr(pg_class_tuple->relname))));
1818 pg_class_tuple->relkind != RELKIND_SEQUENCE)
1820 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1821 errmsg(
"\"%s\" is not a sequence",
1822 NameStr(pg_class_tuple->relname))));
1827 if (pg_class_tuple->relkind == RELKIND_SEQUENCE)
1843 if (pg_class_tuple->relkind == RELKIND_SEQUENCE)
1858 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
1859 errmsg(
"sequence \"%s\" only supports USAGE, SELECT, and UPDATE privileges",
1860 NameStr(pg_class_tuple->relname))));
1875 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
1876 errmsg(
"invalid privilege type %s for table",
1889 have_col_privileges =
false;
1904 num_col_privileges);
1905 have_col_privileges =
true;
1912 ownerId = pg_class_tuple->relowner;
1917 switch (pg_class_tuple->relkind)
1919 case RELKIND_SEQUENCE:
1934 noldmembers =
aclmembers(old_acl, &oldmembers);
1938 old_rel_acl =
aclcopy(old_acl);
1950 bool nulls[Natts_pg_class] = {0};
1951 bool replaces[Natts_pg_class] = {0};
1959 &grantorId, &avail_goptions);
1961 switch (pg_class_tuple->relkind)
1963 case RELKIND_SEQUENCE:
1978 relOid, grantorId, objtype,
1979 NameStr(pg_class_tuple->relname),
1998 nnewmembers =
aclmembers(new_acl, &newmembers);
2001 replaces[Anum_pg_class_relacl - 1] =
true;
2005 values, nulls, replaces);
2016 noldmembers, oldmembers,
2017 nnewmembers, newmembers);
2029 foreach(cell_colprivs, istmt->
col_privs)
2040 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
2041 errmsg(
"invalid privilege type %s for column",
2044 if (pg_class_tuple->relkind == RELKIND_SEQUENCE &&
2053 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
2054 errmsg(
"sequence \"%s\" only supports SELECT column privileges",
2055 NameStr(pg_class_tuple->relname))));
2063 num_col_privileges);
2064 have_col_privileges =
true;
2067 if (have_col_privileges)
2071 for (
i = 0;
i < num_col_privileges;
i++)
2077 NameStr(pg_class_tuple->relname),
2087 pfree(col_privileges);
2144 object_check(istmt, tuple);
2168 noldmembers =
aclmembers(old_acl, &oldmembers);
2174 &grantorId, &avail_goptions);
2196 grantorId, ownerId);
2202 nnewmembers =
aclmembers(new_acl, &newmembers);
2221 noldmembers, oldmembers,
2222 nnewmembers, newmembers);
2242 if (!pg_language_tuple->lanpltrusted)
2244 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2245 errmsg(
"language \"%s\" is not trusted",
2246 NameStr(pg_language_tuple->lanname)),
2247 errdetail(
"GRANT and REVOKE are not allowed on untrusted languages, "
2248 "because only superusers can use untrusted languages.")));
2260 relation =
table_open(LargeObjectMetadataRelationId,
2277 Datum values[Natts_pg_largeobject_metadata] = {0};
2278 bool nulls[Natts_pg_largeobject_metadata] = {0};
2279 bool replaces[Natts_pg_largeobject_metadata] = {0};
2290 Anum_pg_largeobject_metadata_oid,
2295 LargeObjectMetadataOidIndexId,
true,
2300 elog(
ERROR,
"could not find tuple for large object %u", loid);
2308 ownerId = form_lo_meta->lomowner;
2310 Anum_pg_largeobject_metadata_lomacl,
2323 noldmembers =
aclmembers(old_acl, &oldmembers);
2329 &grantorId, &avail_goptions);
2335 snprintf(loname,
sizeof(loname),
"large object %u", loid);
2348 grantorId, ownerId);
2354 nnewmembers =
aclmembers(new_acl, &newmembers);
2357 replaces[Anum_pg_largeobject_metadata_lomacl - 1] =
true;
2358 values[Anum_pg_largeobject_metadata_lomacl - 1]
2362 values, nulls, replaces);
2371 form_lo_meta->oid, 0,
2373 noldmembers, oldmembers,
2374 nnewmembers, newmembers);
2395 if (IsTrueArrayType(pg_type_tuple))
2397 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
2398 errmsg(
"cannot set privileges of array types"),
2399 errhint(
"Set the privileges of the element type instead.")));
2400 if (pg_type_tuple->typtype == TYPTYPE_MULTIRANGE)
2402 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
2403 errmsg(
"cannot set privileges of multirange types"),
2404 errhint(
"Set the privileges of the range type instead.")));
2422 const char *parname;
2439 elog(
ERROR,
"cache lookup failed for parameter ACL %u",
2444 Anum_pg_parameter_acl_parname);
2448 ownerId = BOOTSTRAP_SUPERUSERID;
2455 Anum_pg_parameter_acl_paracl,
2469 noldmembers =
aclmembers(old_acl, &oldmembers);
2475 &grantorId, &avail_goptions);
2484 parameterId, grantorId,
2495 grantorId, ownerId);
2501 nnewmembers =
aclmembers(new_acl, &newmembers);
2517 bool nulls[Natts_pg_parameter_acl] = {0};
2518 bool replaces[Natts_pg_parameter_acl] = {0};
2520 replaces[Anum_pg_parameter_acl_paracl - 1] =
true;
2524 values, nulls, replaces);
2536 noldmembers, oldmembers,
2537 nnewmembers, newmembers);
2553 if (strcmp(privname,
"insert") == 0)
2555 if (strcmp(privname,
"select") == 0)
2557 if (strcmp(privname,
"update") == 0)
2559 if (strcmp(privname,
"delete") == 0)
2561 if (strcmp(privname,
"truncate") == 0)
2563 if (strcmp(privname,
"references") == 0)
2565 if (strcmp(privname,
"trigger") == 0)
2567 if (strcmp(privname,
"execute") == 0)
2569 if (strcmp(privname,
"usage") == 0)
2571 if (strcmp(privname,
"create") == 0)
2573 if (strcmp(privname,
"temporary") == 0)
2575 if (strcmp(privname,
"temp") == 0)
2577 if (strcmp(privname,
"connect") == 0)
2579 if (strcmp(privname,
"set") == 0)
2581 if (strcmp(privname,
"alter system") == 0)
2583 if (strcmp(privname,
"maintain") == 0)
2586 (
errcode(ERRCODE_SYNTAX_ERROR),
2587 errmsg(
"unrecognized privilege type \"%s\"", privname)));
2607 return "REFERENCES";
2623 return "ALTER SYSTEM";
2627 elog(
ERROR,
"unrecognized privilege: %d", (
int) privilege);
2640 const char *objectname)
2649 const char *msg =
"???";
2654 msg =
gettext_noop(
"permission denied for aggregate %s");
2657 msg =
gettext_noop(
"permission denied for collation %s");
2663 msg =
gettext_noop(
"permission denied for conversion %s");
2666 msg =
gettext_noop(
"permission denied for database %s");
2672 msg =
gettext_noop(
"permission denied for event trigger %s");
2675 msg =
gettext_noop(
"permission denied for extension %s");
2678 msg =
gettext_noop(
"permission denied for foreign-data wrapper %s");
2681 msg =
gettext_noop(
"permission denied for foreign server %s");
2684 msg =
gettext_noop(
"permission denied for foreign table %s");
2687 msg =
gettext_noop(
"permission denied for function %s");
2693 msg =
gettext_noop(
"permission denied for language %s");
2696 msg =
gettext_noop(
"permission denied for large object %s");
2699 msg =
gettext_noop(
"permission denied for materialized view %s");
2702 msg =
gettext_noop(
"permission denied for operator class %s");
2705 msg =
gettext_noop(
"permission denied for operator %s");
2708 msg =
gettext_noop(
"permission denied for operator family %s");
2711 msg =
gettext_noop(
"permission denied for parameter %s");
2717 msg =
gettext_noop(
"permission denied for procedure %s");
2720 msg =
gettext_noop(
"permission denied for publication %s");
2723 msg =
gettext_noop(
"permission denied for routine %s");
2729 msg =
gettext_noop(
"permission denied for sequence %s");
2732 msg =
gettext_noop(
"permission denied for statistics object %s");
2735 msg =
gettext_noop(
"permission denied for subscription %s");
2741 msg =
gettext_noop(
"permission denied for tablespace %s");
2744 msg =
gettext_noop(
"permission denied for text search configuration %s");
2747 msg =
gettext_noop(
"permission denied for text search dictionary %s");
2774 elog(
ERROR,
"unsupported object type: %d", objtype);
2778 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2779 errmsg(msg, objectname)));
2784 const char *msg =
"???";
2804 msg =
gettext_noop(
"must be owner of event trigger %s");
2810 msg =
gettext_noop(
"must be owner of foreign-data wrapper %s");
2813 msg =
gettext_noop(
"must be owner of foreign server %s");
2816 msg =
gettext_noop(
"must be owner of foreign table %s");
2828 msg =
gettext_noop(
"must be owner of large object %s");
2831 msg =
gettext_noop(
"must be owner of materialized view %s");
2834 msg =
gettext_noop(
"must be owner of operator class %s");
2840 msg =
gettext_noop(
"must be owner of operator family %s");
2855 msg =
gettext_noop(
"must be owner of subscription %s");
2870 msg =
gettext_noop(
"must be owner of statistics object %s");
2876 msg =
gettext_noop(
"must be owner of text search configuration %s");
2879 msg =
gettext_noop(
"must be owner of text search dictionary %s");
2912 elog(
ERROR,
"unsupported object type: %d", objtype);
2916 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2917 errmsg(msg, objectname)));
2921 elog(
ERROR,
"unrecognized AclResult: %d", (
int) aclerr);
2929 const char *objectname,
const char *colname)
2938 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2939 errmsg(
"permission denied for column \"%s\" of relation \"%s\"",
2940 colname, objectname)));
2947 elog(
ERROR,
"unrecognized AclResult: %d", (
int) aclerr);
2983 return object_aclmask(DatabaseRelationId, object_oid, roleid, mask, how);
2985 return object_aclmask(ProcedureRelationId, object_oid, roleid, mask, how);
2987 return object_aclmask(LanguageRelationId, object_oid, roleid, mask, how);
2994 return object_aclmask(NamespaceRelationId, object_oid, roleid, mask, how);
2996 elog(
ERROR,
"grantable rights not supported for statistics objects");
3000 return object_aclmask(TableSpaceRelationId, object_oid, roleid, mask, how);
3002 return object_aclmask(ForeignDataWrapperRelationId, object_oid, roleid, mask, how);
3004 return object_aclmask(ForeignServerRelationId, object_oid, roleid, mask, how);
3006 elog(
ERROR,
"grantable rights not supported for event triggers");
3010 return object_aclmask(TypeRelationId, object_oid, roleid, mask, how);
3012 elog(
ERROR,
"unrecognized object type: %d",
3057 case NamespaceRelationId:
3060 case TypeRelationId:
3066 Assert(classid != RelationRelationId);
3067 Assert(classid != LargeObjectMetadataRelationId);
3083 if (is_missing != NULL)
3090 elog(
ERROR,
"cache lookup failed for %s %u",
3104 aclDatum = (
Datum) 0;
3112 result =
aclmask(acl, roleid, ownerId, mask, how);
3164 if (is_missing != NULL)
3172 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3173 errmsg(
"attribute %d of relation with OID %u does not exist",
3180 if (attributeForm->attisdropped)
3182 if (is_missing != NULL)
3191 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3192 errmsg(
"attribute %d of relation with OID %u does not exist",
3196 aclDatum =
SysCacheGetAttr(ATTNUM, attTuple, Anum_pg_attribute_attacl,
3221 if (is_missing != NULL)
3230 errmsg(
"relation with OID %u does not exist",
3235 ownerId = classForm->relowner;
3242 result =
aclmask(acl, roleid, ownerId, mask, how);
3284 if (is_missing != NULL)
3293 errmsg(
"relation with OID %u does not exist",
3309 classForm->relkind != RELKIND_VIEW &&
3325 ownerId = classForm->relowner;
3332 switch (classForm->relkind)
3334 case RELKIND_SEQUENCE:
3341 aclDatum = (
Datum) 0;
3349 result =
aclmask(acl, roleid, ownerId, mask, how);
3427 Anum_pg_parameter_acl_paracl,
3433 aclDatum = (
Datum) 0;
3441 result =
aclmask(acl, roleid, BOOTSTRAP_SUPERUSERID, mask, how);
3477 (
errcode(ERRCODE_UNDEFINED_OBJECT),
3478 errmsg(
"parameter ACL with OID %u does not exist",
3482 Anum_pg_parameter_acl_paracl,
3488 aclDatum = (
Datum) 0;
3496 result =
aclmask(acl, roleid, BOOTSTRAP_SUPERUSERID, mask, how);
3541 pg_lo_meta =
table_open(LargeObjectMetadataRelationId,
3545 Anum_pg_largeobject_metadata_oid,
3550 LargeObjectMetadataOidIndexId,
true,
3551 snapshot, 1, entry);
3556 (
errcode(ERRCODE_UNDEFINED_OBJECT),
3557 errmsg(
"large object %u does not exist", lobj_oid)));
3561 aclDatum =
heap_getattr(tuple, Anum_pg_largeobject_metadata_lomacl,
3568 aclDatum = (
Datum) 0;
3576 result =
aclmask(acl, roleid, ownerId, mask, how);
3642 if (is_missing != NULL)
3650 (
errcode(ERRCODE_UNDEFINED_SCHEMA),
3651 errmsg(
"schema with OID %u does not exist", nsp_oid)));
3656 aclDatum =
SysCacheGetAttr(NAMESPACEOID, tuple, Anum_pg_namespace_nspacl,
3662 aclDatum = (
Datum) 0;
3670 result =
aclmask(acl, roleid, ownerId, mask, how);
3716 if (is_missing != NULL)
3724 (
errcode(ERRCODE_UNDEFINED_OBJECT),
3725 errmsg(
"type with OID %u does not exist",
3734 if (IsTrueArrayType(typeForm))
3736 Oid elttype_oid = typeForm->typelem;
3743 if (is_missing != NULL)
3751 (
errcode(ERRCODE_UNDEFINED_OBJECT),
3752 errmsg(
"type with OID %u does not exist",
3763 if (typeForm->typtype == TYPTYPE_MULTIRANGE)
3772 if (is_missing != NULL)
3780 (
errcode(ERRCODE_UNDEFINED_OBJECT),
3781 errmsg(
"type with OID %u does not exist",
3790 ownerId = typeForm->typowner;
3793 Anum_pg_type_typacl, &isNull);
3798 aclDatum = (
Datum) 0;
3806 result =
aclmask(acl, roleid, ownerId, mask, how);
3923 if (is_missing != NULL)
3932 errmsg(
"relation with OID %u does not exist",
3937 ownerId = classForm->relowner;
3938 nattrs = classForm->relnatts;
3948 for (curr_att = 1; curr_att <= nattrs; curr_att++)
3975 aclDatum =
SysCacheGetAttr(ATTNUM, attTuple, Anum_pg_attribute_attacl,
4085 if (classid == LargeObjectRelationId)
4086 classid = LargeObjectMetadataRelationId;
4096 elog(
ERROR,
"cache lookup failed for %s %u",
4126 elog(
ERROR,
"could not find tuple for %s %u",
4156 bool result =
false;
4175 bool result =
false;
4213 Anum_pg_default_acl_defaclacl,
4251 defaclobjtype = DEFACLOBJ_RELATION;
4255 defaclobjtype = DEFACLOBJ_SEQUENCE;
4259 defaclobjtype = DEFACLOBJ_FUNCTION;
4263 defaclobjtype = DEFACLOBJ_TYPE;
4267 defaclobjtype = DEFACLOBJ_NAMESPACE;
4271 defaclobjtype = DEFACLOBJ_LARGEOBJECT;
4283 if (glob_acl == NULL && schema_acl == NULL)
4290 if (glob_acl == NULL)
4294 result =
aclmerge(glob_acl, schema_acl, ownerId);
4348 if (classoid == RelationRelationId)
4357 elog(
ERROR,
"cache lookup failed for relation %u", objoid);
4365 if (pg_class_tuple->relkind == RELKIND_INDEX ||
4366 pg_class_tuple->relkind == RELKIND_PARTITIONED_INDEX ||
4367 pg_class_tuple->relkind == RELKIND_COMPOSITE_TYPE)
4377 if (pg_class_tuple->relkind != RELKIND_SEQUENCE)
4380 AttrNumber nattrs = pg_class_tuple->relnatts;
4382 for (curr_att = 1; curr_att <= nattrs; curr_att++)
4402 Anum_pg_attribute_attacl,
4429 else if (classoid == LargeObjectRelationId)
4448 Anum_pg_largeobject_metadata_oid,
4453 LargeObjectMetadataOidIndexId,
true,
4458 elog(
ERROR,
"could not find tuple for large object %u", objoid);
4461 Anum_pg_largeobject_metadata_lomacl,
4482 elog(
ERROR,
"cache lookup failed for %s %u",
4510 if (classoid == RelationRelationId)
4517 elog(
ERROR,
"cache lookup failed for relation %u", objoid);
4525 if (pg_class_tuple->relkind == RELKIND_INDEX ||
4526 pg_class_tuple->relkind == RELKIND_PARTITIONED_INDEX ||
4527 pg_class_tuple->relkind == RELKIND_COMPOSITE_TYPE)
4537 if (pg_class_tuple->relkind != RELKIND_SEQUENCE)
4540 AttrNumber nattrs = pg_class_tuple->relnatts;
4542 for (curr_att = 1; curr_att <= nattrs; curr_att++)
4629 nnewmembers =
aclmembers(new_acl, &newmembers);
4635 Anum_pg_init_privs_objoid,
4639 Anum_pg_init_privs_classoid,
4643 Anum_pg_init_privs_objsubid,
4657 bool nulls[Natts_pg_init_privs] = {0};
4658 bool replace[Natts_pg_init_privs] = {0};
4664 oldAclDatum =
heap_getattr(oldtuple, Anum_pg_init_privs_initprivs,
4668 noldmembers =
aclmembers(old_acl, &oldmembers);
4671 noldmembers, oldmembers,
4672 nnewmembers, newmembers);
4675 if (new_acl &&
ACL_NUM(new_acl) != 0)
4678 replace[Anum_pg_init_privs_initprivs - 1] =
true;
4694 bool nulls[Natts_pg_init_privs] = {0};
4702 if (new_acl &&
ACL_NUM(new_acl) != 0)
4710 values[Anum_pg_init_privs_privtype - 1] =
4724 noldmembers, oldmembers,
4725 nnewmembers, newmembers);
4764 Anum_pg_init_privs_objoid,
4768 Anum_pg_init_privs_classoid,
4772 Anum_pg_init_privs_objsubid,
4794 oldAclDatum =
heap_getattr(oldtuple, Anum_pg_init_privs_initprivs,
4803 new_acl =
aclnewowner(old_acl, oldroleid, newroleid);
4809 if (new_acl == NULL ||
ACL_NUM(new_acl) == 0)
4816 bool nulls[Natts_pg_init_privs] = {0};
4817 bool replaces[Natts_pg_init_privs] = {0};
4821 replaces[Anum_pg_init_privs_initprivs - 1] =
true;
4824 values, nulls, replaces);
4831 noldmembers =
aclmembers(old_acl, &oldmembers);
4832 nnewmembers =
aclmembers(new_acl, &newmembers);
4835 noldmembers, oldmembers,
4836 nnewmembers, newmembers);
4875 Anum_pg_init_privs_objoid,
4879 Anum_pg_init_privs_classoid,
4883 Anum_pg_init_privs_objsubid,
4905 oldAclDatum =
heap_getattr(oldtuple, Anum_pg_init_privs_initprivs,
4915 noldmembers =
aclmembers(old_acl, &oldmembers);
4921 elog(
ERROR,
"cache lookup failed for %s %u",
4932 if (old_acl != NULL)
4945 if (new_acl == NULL ||
ACL_NUM(new_acl) == 0)
4952 bool nulls[Natts_pg_init_privs] = {0};
4953 bool replaces[Natts_pg_init_privs] = {0};
4957 replaces[Anum_pg_init_privs_initprivs - 1] =
true;
4960 values, nulls, replaces);
4967 nnewmembers =
aclmembers(new_acl, &newmembers);
4970 noldmembers, oldmembers,
4971 nnewmembers, newmembers);
Acl * aclconcat(const Acl *left_acl, const Acl *right_acl)
Acl * aclmerge(const Acl *left_acl, const Acl *right_acl, Oid ownerId)
Acl * acldefault(ObjectType objtype, Oid ownerId)
bool aclequal(const Acl *left_acl, const Acl *right_acl)
Acl * aclupdate(const Acl *old_acl, const AclItem *mod_aip, int modechg, Oid ownerId, DropBehavior behavior)
void select_best_grantor(Oid roleId, AclMode privileges, const Acl *acl, Oid ownerId, Oid *grantorId, AclMode *grantOptions)
bool has_privs_of_role(Oid member, Oid role)
Acl * make_empty_acl(void)
int aclmembers(const Acl *acl, Oid **roleids)
Acl * aclnewowner(const Acl *old_acl, Oid oldOwnerId, Oid newOwnerId)
Acl * aclcopy(const Acl *orig_acl)
void aclitemsort(Acl *acl)
AclMode aclmask(const Acl *acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how)
Oid get_rolespec_oid(const RoleSpec *role, bool missing_ok)
#define ACLITEM_ALL_PRIV_BITS
#define ACL_ALL_RIGHTS_FOREIGN_SERVER
#define ACL_ALL_RIGHTS_TABLESPACE
#define ACL_ALL_RIGHTS_PARAMETER_ACL
#define ACL_ALL_RIGHTS_SCHEMA
#define ACL_ALL_RIGHTS_SEQUENCE
#define ACL_ALL_RIGHTS_DATABASE
#define ACL_ALL_RIGHTS_COLUMN
#define ACL_OPTION_TO_PRIVS(privs)
#define ACL_ALL_RIGHTS_FUNCTION
#define ACL_ALL_RIGHTS_LANGUAGE
#define ACL_ALL_RIGHTS_TYPE
#define ACL_ALL_RIGHTS_FDW
#define ACLITEM_SET_PRIVS_GOPTIONS(item, privs, goptions)
#define DatumGetAclPCopy(X)
#define ACL_ALL_RIGHTS_RELATION
#define ACL_ALL_RIGHTS_LARGEOBJECT
#define ACL_GRANT_OPTION_FOR(privs)
static AclMode pg_attribute_aclmask_ext(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mask, AclMaskHow how, bool *is_missing)
AclResult object_aclcheck_ext(Oid classid, Oid objectid, Oid roleid, AclMode mode, bool *is_missing)
void ExecuteGrantStmt(GrantStmt *stmt)
AclResult pg_largeobject_aclcheck_snapshot(Oid lobj_oid, Oid roleid, AclMode mode, Snapshot snapshot)
static void expand_all_col_privileges(Oid table_oid, Form_pg_class classForm, AclMode this_privileges, AclMode *col_privileges, int num_col_privileges)
void RemoveRoleFromInitPriv(Oid roleid, Oid classid, Oid objid, int32 objsubid)
static void recordExtensionInitPriv(Oid objoid, Oid classoid, int objsubid, Acl *new_acl)
static void expand_col_privileges(List *colnames, Oid table_oid, AclMode this_privileges, AclMode *col_privileges, int num_col_privileges)
bool has_bypassrls_privilege(Oid roleid)
AclResult pg_class_aclcheck_ext(Oid table_oid, Oid roleid, AclMode mode, bool *is_missing)
void aclcheck_error_col(AclResult aclerr, ObjectType objtype, const char *objectname, const char *colname)
AclResult pg_attribute_aclcheck_all_ext(Oid table_oid, Oid roleid, AclMode mode, AclMaskHow how, bool *is_missing)
void recordDependencyOnNewAcl(Oid classId, Oid objectId, int32 objsubId, Oid ownerId, Acl *acl)
static void ExecGrant_Attribute(InternalGrant *istmt, Oid relOid, const char *relname, AttrNumber attnum, Oid ownerId, AclMode col_privileges, Relation attRelation, const Acl *old_rel_acl)
static void ExecGrant_Type_check(InternalGrant *istmt, HeapTuple tuple)
void ExecAlterDefaultPrivilegesStmt(ParseState *pstate, AlterDefaultPrivilegesStmt *stmt)
static void ExecGrantStmt_oids(InternalGrant *istmt)
static AclMode pg_largeobject_aclmask_snapshot(Oid lobj_oid, Oid roleid, AclMode mask, AclMaskHow how, Snapshot snapshot)
static AclMode pg_attribute_aclmask(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mask, AclMaskHow how)
static List * objectNamesToOids(ObjectType objtype, List *objnames, bool is_grant)
static AclMode pg_parameter_aclmask(const char *name, Oid roleid, AclMode mask, AclMaskHow how)
AclResult pg_attribute_aclcheck_all(Oid table_oid, Oid roleid, AclMode mode, AclMaskHow how)
static AclMode pg_parameter_acl_aclmask(Oid acl_oid, Oid roleid, AclMode mask, AclMaskHow how)
static void SetDefaultACL(InternalDefaultACL *iacls)
static List * objectsInSchemaToOids(ObjectType objtype, List *nspnames)
AclResult pg_parameter_aclcheck(const char *name, Oid roleid, AclMode mode)
void ReplaceRoleInInitPriv(Oid oldroleid, Oid newroleid, Oid classid, Oid objid, int32 objsubid)
static void ExecGrant_common(InternalGrant *istmt, Oid classid, AclMode default_privs, void(*object_check)(InternalGrant *istmt, HeapTuple tuple))
static Acl * merge_acl_with_grant(Acl *old_acl, bool is_grant, bool grant_option, DropBehavior behavior, List *grantees, AclMode privileges, Oid grantorId, Oid ownerId)
void recordExtObjInitPriv(Oid objoid, Oid classoid)
static List * getRelationsInNamespace(Oid namespaceId, char relkind)
static AclMode pg_class_aclmask_ext(Oid table_oid, Oid roleid, AclMode mask, AclMaskHow how, bool *is_missing)
static AclMode string_to_privilege(const char *privname)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
static AclMode object_aclmask(Oid classid, Oid objectid, Oid roleid, AclMode mask, AclMaskHow how)
static void ExecGrant_Largeobject(InternalGrant *istmt)
AclResult pg_attribute_aclcheck(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mode)
static AclMode restrict_and_check_grant(bool is_grant, AclMode avail_goptions, bool all_privs, AclMode privileges, Oid objectId, Oid grantorId, ObjectType objtype, const char *objname, AttrNumber att_number, const char *colname)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
static void recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid, Acl *new_acl)
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
AclResult pg_attribute_aclcheck_ext(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mode, bool *is_missing)
static AclMode pg_namespace_aclmask_ext(Oid nsp_oid, Oid roleid, AclMode mask, AclMaskHow how, bool *is_missing)
static void SetDefaultACLsInSchemas(InternalDefaultACL *iacls, List *nspnames)
AclMode pg_class_aclmask(Oid table_oid, Oid roleid, AclMode mask, AclMaskHow how)
static void ExecGrant_Parameter(InternalGrant *istmt)
static const char * privilege_to_string(AclMode privilege)
static Acl * get_default_acl_internal(Oid roleId, Oid nsp_oid, char objtype)
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
bool has_createrole_privilege(Oid roleid)
static void ExecGrant_Relation(InternalGrant *istmt)
static AclMode pg_type_aclmask_ext(Oid type_oid, Oid roleid, AclMode mask, AclMaskHow how, bool *is_missing)
bool binary_upgrade_record_init_privs
Acl * get_user_default_acl(ObjectType objtype, Oid ownerId, Oid nsp_oid)
void RemoveRoleFromObjectACL(Oid roleid, Oid classid, Oid objid)
static void ExecGrant_Language_check(InternalGrant *istmt, HeapTuple tuple)
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
static AclMode pg_aclmask(ObjectType objtype, Oid object_oid, AttrNumber attnum, Oid roleid, AclMode mask, AclMaskHow how)
static AclMode object_aclmask_ext(Oid classid, Oid objectid, Oid roleid, AclMode mask, AclMaskHow how, bool *is_missing)
void removeExtObjInitPriv(Oid objoid, Oid classoid)
#define InvalidAttrNumber
static Datum values[MAXATTR]
#define TextDatumGetCString(d)
#define OidIsValid(objectId)
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
bool IsSystemClass(Oid relid, Form_pg_class reltuple)
void errorConflictingDefElem(DefElem *defel, ParseState *pstate)
void performDeletion(const ObjectAddress *object, DropBehavior behavior, int flags)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
bool EventTriggerSupportsObjectType(ObjectType obtype)
void EventTriggerCollectGrant(InternalGrant *istmt)
#define palloc0_array(type, count)
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)
char * convert_GUC_name_for_parameter_acl(const char *name)
Assert(PointerIsAligned(start, uint64))
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
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)
#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, ItemPointer otid, HeapTuple tup)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
if(TABLE==NULL||TABLE_index==NULL)
List * lappend(List *list, void *datum)
List * list_concat(List *list1, const List *list2)
List * lappend_oid(List *list, Oid datum)
void UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
#define InplaceUpdateTupleLock
char * get_rel_name(Oid relid)
AttrNumber get_attnum(Oid relid, const char *attname)
Oid get_element_type(Oid typid)
Oid get_multirange_range(Oid multirangeOid)
TypeName * makeTypeNameFromNameList(List *names)
void pfree(void *pointer)
void * palloc0(Size size)
#define IsBootstrapProcessingMode()
Oid LookupExplicitNamespace(const char *nspname, bool missing_ok)
bool isTempNamespace(Oid namespaceId)
Oid get_namespace_oid(const char *nspname, bool missing_ok)
#define RangeVarGetRelid(relation, lockmode, missing_ok)
#define InvokeObjectPostCreateHook(classId, objectId, subId)
#define InvokeObjectPostAlterHook(classId, objectId, subId)
AttrNumber get_object_attnum_owner(Oid class_id)
AttrNumber get_object_attnum_oid(Oid class_id)
AttrNumber get_object_attnum_name(Oid class_id)
const char * get_object_class_descr(Oid class_id)
AttrNumber get_object_attnum_acl(Oid class_id)
int get_object_catcache_oid(Oid class_id)
Oid get_object_oid_index(Oid class_id)
ObjectType get_object_type(Oid class_id, Oid object_id)
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
@ OBJECT_PUBLICATION_NAMESPACE
@ ACL_TARGET_ALL_IN_SCHEMA
FormData_pg_attribute * Form_pg_attribute
FormData_pg_authid * Form_pg_authid
static PgChecksumMode mode
FormData_pg_class * Form_pg_class
FormData_pg_default_acl * Form_pg_default_acl
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
FormData_pg_language * Form_pg_language
#define list_make1_oid(x1)
FormData_pg_namespace * Form_pg_namespace
Oid ParameterAclLookup(const char *parameter, bool missing_ok)
Oid ParameterAclCreate(const char *parameter)
FormData_pg_proc * Form_pg_proc
void updateAclDependencies(Oid classId, Oid objectId, int32 objsubId, Oid ownerId, int noldmembers, Oid *oldmembers, int nnewmembers, Oid *newmembers)
void updateInitAclDependencies(Oid classId, Oid objectId, int32 objsubId, int noldmembers, Oid *oldmembers, int nnewmembers, Oid *newmembers)
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
FormData_pg_type * Form_pg_type
#define ERRCODE_UNDEFINED_TABLE
static Datum PointerGetDatum(const void *X)
static Name DatumGetName(Datum X)
static Oid DatumGetObjectId(Datum X)
static Datum Int16GetDatum(int16 X)
static Datum ObjectIdGetDatum(Oid X)
static Pointer DatumGetPointer(Datum X)
static Datum Int32GetDatum(int32 X)
static Datum CharGetDatum(char X)
#define RelationGetDescr(relation)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
#define BTEqualStrategyNumber
bool superuser_arg(Oid roleid)
#define FirstLowInvalidHeapAttributeNumber
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCacheLocked1(int cacheId, Datum key1)
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)
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, struct ScanKeyData *key)
static void table_endscan(TableScanDesc scan)
text * cstring_to_text(const char *s)
void CommandCounterIncrement(void)