81#include "utils/fmgroids.h"
130 int num_col_privileges);
134 int num_col_privileges);
138 bool all_privs,
AclMode privileges,
139 Oid objectId,
Oid grantorId,
184 Oid grantorId,
Oid ownerId)
209 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
210 errmsg(
"grant options can only be granted to roles")));
225 newer_acl =
aclupdate(new_acl, &aclitem, modechg, ownerId, behavior);
284 elog(
ERROR,
"grantable rights not supported for event triggers");
294 elog(
ERROR,
"unrecognized object type: %d", objtype);
306 if (
pg_aclmask(objtype, objectId, att_number, grantorId,
327 if (this_privileges == 0)
331 (
errcode(ERRCODE_WARNING_PRIVILEGE_NOT_GRANTED),
332 errmsg(
"no privileges were granted for column \"%s\" of relation \"%s\"",
336 (
errcode(ERRCODE_WARNING_PRIVILEGE_NOT_GRANTED),
337 errmsg(
"no privileges were granted for \"%s\"",
340 else if (!all_privs && this_privileges != privileges)
344 (
errcode(ERRCODE_WARNING_PRIVILEGE_NOT_GRANTED),
345 errmsg(
"not all privileges were granted for column \"%s\" of relation \"%s\"",
349 (
errcode(ERRCODE_WARNING_PRIVILEGE_NOT_GRANTED),
350 errmsg(
"not all privileges were granted for \"%s\"",
356 if (this_privileges == 0)
360 (
errcode(ERRCODE_WARNING_PRIVILEGE_NOT_REVOKED),
361 errmsg(
"no privileges could be revoked for column \"%s\" of relation \"%s\"",
365 (
errcode(ERRCODE_WARNING_PRIVILEGE_NOT_REVOKED),
366 errmsg(
"no privileges could be revoked for \"%s\"",
369 else if (!all_privs && this_privileges != privileges)
373 (
errcode(ERRCODE_WARNING_PRIVILEGE_NOT_REVOKED),
374 errmsg(
"not all privileges could be revoked for column \"%s\" of relation \"%s\"",
378 (
errcode(ERRCODE_WARNING_PRIVILEGE_NOT_REVOKED),
379 errmsg(
"not all privileges could be revoked for \"%s\"",
384 return this_privileges;
395 const char *errormsg;
410 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
411 errmsg(
"grantor must be current user")));
421 switch (
stmt->targtype)
432 elog(
ERROR,
"unrecognized GrantStmt.targtype: %d",
433 (
int)
stmt->targtype);
448 foreach(cell,
stmt->grantees)
469 switch (
stmt->objtype)
479 errormsg =
gettext_noop(
"invalid privilege type %s for relation");
483 errormsg =
gettext_noop(
"invalid privilege type %s for sequence");
487 errormsg =
gettext_noop(
"invalid privilege type %s for database");
491 errormsg =
gettext_noop(
"invalid privilege type %s for domain");
495 errormsg =
gettext_noop(
"invalid privilege type %s for function");
499 errormsg =
gettext_noop(
"invalid privilege type %s for language");
503 errormsg =
gettext_noop(
"invalid privilege type %s for large object");
507 errormsg =
gettext_noop(
"invalid privilege type %s for schema");
511 errormsg =
gettext_noop(
"invalid privilege type %s for procedure");
515 errormsg =
gettext_noop(
"invalid privilege type %s for routine");
519 errormsg =
gettext_noop(
"invalid privilege type %s for tablespace");
523 errormsg =
gettext_noop(
"invalid privilege type %s for type");
527 errormsg =
gettext_noop(
"invalid privilege type %s for foreign-data wrapper");
531 errormsg =
gettext_noop(
"invalid privilege type %s for foreign server");
535 errormsg =
gettext_noop(
"invalid privilege type %s for parameter");
538 elog(
ERROR,
"unrecognized GrantStmt.objtype: %d",
539 (
int)
stmt->objtype);
560 foreach(cell,
stmt->privileges)
573 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
574 errmsg(
"column privileges are only valid for relations")));
580 elog(
ERROR,
"AccessPriv node must specify privilege or columns");
583 if (priv & ~((
AclMode) all_privileges))
585 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
643 elog(
ERROR,
"unrecognized GrantStmt.objtype: %d",
692 foreach(cell, objnames)
709 foreach(cell, objnames)
728 foreach(cell, objnames)
746 foreach(cell, objnames)
794 foreach(cell, nspnames)
832 Anum_pg_proc_pronamespace,
839 Anum_pg_proc_prokind,
844 Anum_pg_proc_prokind,
864 elog(
ERROR,
"unrecognized GrantStmt.objtype: %d",
887 Anum_pg_class_relnamespace,
891 Anum_pg_class_relkind,
926 const char *errormsg;
929 foreach(cell,
stmt->options)
933 if (strcmp(defel->
defname,
"schemas") == 0)
939 else if (strcmp(defel->
defname,
"roles") == 0)
950 nspnames = (
List *) dnspnames->
arg;
952 rolespecs = (
List *) drolespecs->
arg;
970 foreach(cell,
action->grantees)
995 errormsg =
gettext_noop(
"invalid privilege type %s for relation");
999 errormsg =
gettext_noop(
"invalid privilege type %s for sequence");
1003 errormsg =
gettext_noop(
"invalid privilege type %s for function");
1007 errormsg =
gettext_noop(
"invalid privilege type %s for procedure");
1011 errormsg =
gettext_noop(
"invalid privilege type %s for routine");
1015 errormsg =
gettext_noop(
"invalid privilege type %s for type");
1019 errormsg =
gettext_noop(
"invalid privilege type %s for schema");
1023 errormsg =
gettext_noop(
"invalid privilege type %s for large object");
1026 elog(
ERROR,
"unrecognized GrantStmt.objtype: %d",
1048 foreach(cell,
action->privileges)
1055 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
1056 errmsg(
"default privileges cannot be set for columns")));
1059 elog(
ERROR,
"AccessPriv node must specify privilege");
1062 if (priv & ~((
AclMode) all_privileges))
1064 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
1071 if (rolespecs ==
NIL)
1083 foreach(rolecell, rolespecs)
1091 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1092 errmsg(
"permission denied to change default privileges")));
1107 if (nspnames ==
NIL)
1119 foreach(nspcell, nspnames)
1183 objtype = DEFACLOBJ_RELATION;
1189 objtype = DEFACLOBJ_SEQUENCE;
1195 objtype = DEFACLOBJ_FUNCTION;
1201 objtype = DEFACLOBJ_TYPE;
1209 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
1210 errmsg(
"cannot use IN SCHEMA clause when using GRANT/REVOKE ON SCHEMAS")));
1211 objtype = DEFACLOBJ_NAMESPACE;
1219 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
1220 errmsg(
"cannot use IN SCHEMA clause when using GRANT/REVOKE ON LARGE OBJECTS")));
1221 objtype = DEFACLOBJ_LARGEOBJECT;
1227 elog(
ERROR,
"unrecognized object type: %d",
1245 Anum_pg_default_acl_defaclacl,
1259 if (old_acl != NULL)
1266 noldmembers =
aclmembers(old_acl, &oldmembers);
1309 myself.
classId = DefaultAclRelationId;
1319 bool nulls[Natts_pg_default_acl] = {0};
1320 bool replaces[Natts_pg_default_acl] = {0};
1327 Anum_pg_default_acl_oid);
1343 replaces[Anum_pg_default_acl_defaclacl - 1] =
true;
1346 values, nulls, replaces);
1363 myself.
classId = DefaultAclRelationId;
1367 referenced.
classId = NamespaceRelationId;
1378 nnewmembers =
aclmembers(new_acl, &newmembers);
1383 noldmembers, oldmembers,
1384 nnewmembers, newmembers);
1422 if (classid == DefaultAclRelationId)
1435 Anum_pg_default_acl_oid,
1445 elog(
ERROR,
"could not find tuple for default ACL %u", objid);
1449 iacls.
roleid = pg_default_acl_tuple->defaclrole;
1450 iacls.
nspid = pg_default_acl_tuple->defaclnamespace;
1452 switch (pg_default_acl_tuple->defaclobjtype)
1454 case DEFACLOBJ_RELATION:
1457 case DEFACLOBJ_SEQUENCE:
1460 case DEFACLOBJ_FUNCTION:
1463 case DEFACLOBJ_TYPE:
1466 case DEFACLOBJ_NAMESPACE:
1469 case DEFACLOBJ_LARGEOBJECT:
1474 elog(
ERROR,
"unexpected default ACL type: %d",
1475 (
int) pg_default_acl_tuple->defaclobjtype);
1498 case RelationRelationId:
1502 case DatabaseRelationId:
1505 case TypeRelationId:
1508 case ProcedureRelationId:
1511 case LanguageRelationId:
1514 case LargeObjectRelationId:
1517 case NamespaceRelationId:
1520 case TableSpaceRelationId:
1523 case ForeignServerRelationId:
1526 case ForeignDataWrapperRelationId:
1529 case ParameterAclRelationId:
1533 elog(
ERROR,
"unexpected object class %u", classid);
1561 int num_col_privileges)
1565 foreach(cell, colnames)
1573 (
errcode(ERRCODE_UNDEFINED_COLUMN),
1574 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
1577 if (attnum <= 0 || attnum >= num_col_privileges)
1578 elog(
ERROR,
"column number out of range");
1579 col_privileges[
attnum] |= this_privileges;
1594 int num_col_privileges)
1600 curr_att <= classForm->relnatts;
1610 if (classForm->relkind == RELKIND_VIEW && curr_att < 0)
1617 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
1618 curr_att, table_oid);
1653 bool nulls[Natts_pg_attribute] = {0};
1654 bool replaces[Natts_pg_attribute] = {0};
1664 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
1672 aclDatum =
SysCacheGetAttr(ATTNUM, attr_tuple, Anum_pg_attribute_attacl,
1685 noldmembers =
aclmembers(old_acl, &oldmembers);
1694 merged_acl =
aclconcat(old_rel_acl, old_acl);
1698 merged_acl, ownerId,
1699 &grantorId, &avail_goptions);
1717 NameStr(pg_attribute_tuple->attname));
1725 col_privileges, grantorId,
1732 nnewmembers =
aclmembers(new_acl, &newmembers);
1750 nulls[Anum_pg_attribute_attacl - 1] =
true;
1751 need_update = !isNull;
1753 replaces[Anum_pg_attribute_attacl - 1] =
true;
1758 values, nulls, replaces);
1764 ACL_NUM(new_acl) > 0 ? new_acl : NULL);
1769 noldmembers, oldmembers,
1770 nnewmembers, newmembers);
1799 int num_col_privileges;
1800 bool have_col_privileges;
1811 elog(
ERROR,
"cache lookup failed for relation %u", relOid);
1815 if (pg_class_tuple->relkind == RELKIND_INDEX ||
1816 pg_class_tuple->relkind == RELKIND_PARTITIONED_INDEX)
1818 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1819 errmsg(
"\"%s\" is an index",
1820 NameStr(pg_class_tuple->relname))));
1823 if (pg_class_tuple->relkind == RELKIND_COMPOSITE_TYPE)
1825 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1826 errmsg(
"\"%s\" is a composite type",
1827 NameStr(pg_class_tuple->relname))));
1831 pg_class_tuple->relkind != RELKIND_SEQUENCE)
1833 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1834 errmsg(
"\"%s\" is not a sequence",
1835 NameStr(pg_class_tuple->relname))));
1840 if (pg_class_tuple->relkind == RELKIND_SEQUENCE)
1856 if (pg_class_tuple->relkind == RELKIND_SEQUENCE)
1871 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
1872 errmsg(
"sequence \"%s\" only supports USAGE, SELECT, and UPDATE privileges",
1873 NameStr(pg_class_tuple->relname))));
1888 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
1889 errmsg(
"invalid privilege type %s for table",
1902 have_col_privileges =
false;
1917 num_col_privileges);
1918 have_col_privileges =
true;
1925 ownerId = pg_class_tuple->relowner;
1930 switch (pg_class_tuple->relkind)
1932 case RELKIND_SEQUENCE:
1947 noldmembers =
aclmembers(old_acl, &oldmembers);
1951 old_rel_acl =
aclcopy(old_acl);
1963 bool nulls[Natts_pg_class] = {0};
1964 bool replaces[Natts_pg_class] = {0};
1972 &grantorId, &avail_goptions);
1974 switch (pg_class_tuple->relkind)
1976 case RELKIND_SEQUENCE:
1991 relOid, grantorId, objtype,
1992 NameStr(pg_class_tuple->relname),
2011 nnewmembers =
aclmembers(new_acl, &newmembers);
2014 replaces[Anum_pg_class_relacl - 1] =
true;
2018 values, nulls, replaces);
2029 noldmembers, oldmembers,
2030 nnewmembers, newmembers);
2042 foreach(cell_colprivs, istmt->
col_privs)
2053 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
2054 errmsg(
"invalid privilege type %s for column",
2057 if (pg_class_tuple->relkind == RELKIND_SEQUENCE &&
2066 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
2067 errmsg(
"sequence \"%s\" only supports SELECT column privileges",
2068 NameStr(pg_class_tuple->relname))));
2076 num_col_privileges);
2077 have_col_privileges =
true;
2080 if (have_col_privileges)
2084 for (
i = 0;
i < num_col_privileges;
i++)
2090 NameStr(pg_class_tuple->relname),
2100 pfree(col_privileges);
2157 object_check(istmt, tuple);
2181 noldmembers =
aclmembers(old_acl, &oldmembers);
2187 &grantorId, &avail_goptions);
2209 grantorId, ownerId);
2215 nnewmembers =
aclmembers(new_acl, &newmembers);
2234 noldmembers, oldmembers,
2235 nnewmembers, newmembers);
2255 if (!pg_language_tuple->lanpltrusted)
2257 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2258 errmsg(
"language \"%s\" is not trusted",
2259 NameStr(pg_language_tuple->lanname)),
2260 errdetail(
"GRANT and REVOKE are not allowed on untrusted languages, "
2261 "because only superusers can use untrusted languages.")));
2273 relation =
table_open(LargeObjectMetadataRelationId,
2290 Datum values[Natts_pg_largeobject_metadata] = {0};
2291 bool nulls[Natts_pg_largeobject_metadata] = {0};
2292 bool replaces[Natts_pg_largeobject_metadata] = {0};
2303 Anum_pg_largeobject_metadata_oid,
2308 LargeObjectMetadataOidIndexId,
true,
2313 elog(
ERROR,
"could not find tuple for large object %u", loid);
2321 ownerId = form_lo_meta->lomowner;
2323 Anum_pg_largeobject_metadata_lomacl,
2336 noldmembers =
aclmembers(old_acl, &oldmembers);
2342 &grantorId, &avail_goptions);
2348 snprintf(loname,
sizeof(loname),
"large object %u", loid);
2361 grantorId, ownerId);
2367 nnewmembers =
aclmembers(new_acl, &newmembers);
2370 replaces[Anum_pg_largeobject_metadata_lomacl - 1] =
true;
2371 values[Anum_pg_largeobject_metadata_lomacl - 1]
2375 values, nulls, replaces);
2384 form_lo_meta->oid, 0,
2386 noldmembers, oldmembers,
2387 nnewmembers, newmembers);
2408 if (IsTrueArrayType(pg_type_tuple))
2410 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
2411 errmsg(
"cannot set privileges of array types"),
2412 errhint(
"Set the privileges of the element type instead.")));
2413 if (pg_type_tuple->typtype == TYPTYPE_MULTIRANGE)
2415 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
2416 errmsg(
"cannot set privileges of multirange types"),
2417 errhint(
"Set the privileges of the range type instead.")));
2435 const char *parname;
2452 elog(
ERROR,
"cache lookup failed for parameter ACL %u",
2457 Anum_pg_parameter_acl_parname);
2461 ownerId = BOOTSTRAP_SUPERUSERID;
2468 Anum_pg_parameter_acl_paracl,
2482 noldmembers =
aclmembers(old_acl, &oldmembers);
2488 &grantorId, &avail_goptions);
2497 parameterId, grantorId,
2508 grantorId, ownerId);
2514 nnewmembers =
aclmembers(new_acl, &newmembers);
2530 bool nulls[Natts_pg_parameter_acl] = {0};
2531 bool replaces[Natts_pg_parameter_acl] = {0};
2533 replaces[Anum_pg_parameter_acl_paracl - 1] =
true;
2537 values, nulls, replaces);
2549 noldmembers, oldmembers,
2550 nnewmembers, newmembers);
2566 if (strcmp(privname,
"insert") == 0)
2568 if (strcmp(privname,
"select") == 0)
2570 if (strcmp(privname,
"update") == 0)
2572 if (strcmp(privname,
"delete") == 0)
2574 if (strcmp(privname,
"truncate") == 0)
2576 if (strcmp(privname,
"references") == 0)
2578 if (strcmp(privname,
"trigger") == 0)
2580 if (strcmp(privname,
"execute") == 0)
2582 if (strcmp(privname,
"usage") == 0)
2584 if (strcmp(privname,
"create") == 0)
2586 if (strcmp(privname,
"temporary") == 0)
2588 if (strcmp(privname,
"temp") == 0)
2590 if (strcmp(privname,
"connect") == 0)
2592 if (strcmp(privname,
"set") == 0)
2594 if (strcmp(privname,
"alter system") == 0)
2596 if (strcmp(privname,
"maintain") == 0)
2599 (
errcode(ERRCODE_SYNTAX_ERROR),
2600 errmsg(
"unrecognized privilege type \"%s\"", privname)));
2620 return "REFERENCES";
2636 return "ALTER SYSTEM";
2640 elog(
ERROR,
"unrecognized privilege: %d", (
int) privilege);
2653 const char *objectname)
2662 const char *msg =
"???";
2667 msg =
gettext_noop(
"permission denied for aggregate %s");
2670 msg =
gettext_noop(
"permission denied for collation %s");
2676 msg =
gettext_noop(
"permission denied for conversion %s");
2679 msg =
gettext_noop(
"permission denied for database %s");
2685 msg =
gettext_noop(
"permission denied for event trigger %s");
2688 msg =
gettext_noop(
"permission denied for extension %s");
2691 msg =
gettext_noop(
"permission denied for foreign-data wrapper %s");
2694 msg =
gettext_noop(
"permission denied for foreign server %s");
2697 msg =
gettext_noop(
"permission denied for foreign table %s");
2700 msg =
gettext_noop(
"permission denied for function %s");
2706 msg =
gettext_noop(
"permission denied for language %s");
2709 msg =
gettext_noop(
"permission denied for large object %s");
2712 msg =
gettext_noop(
"permission denied for materialized view %s");
2715 msg =
gettext_noop(
"permission denied for operator class %s");
2718 msg =
gettext_noop(
"permission denied for operator %s");
2721 msg =
gettext_noop(
"permission denied for operator family %s");
2724 msg =
gettext_noop(
"permission denied for parameter %s");
2730 msg =
gettext_noop(
"permission denied for procedure %s");
2733 msg =
gettext_noop(
"permission denied for publication %s");
2736 msg =
gettext_noop(
"permission denied for routine %s");
2742 msg =
gettext_noop(
"permission denied for sequence %s");
2745 msg =
gettext_noop(
"permission denied for statistics object %s");
2748 msg =
gettext_noop(
"permission denied for subscription %s");
2754 msg =
gettext_noop(
"permission denied for tablespace %s");
2757 msg =
gettext_noop(
"permission denied for text search configuration %s");
2760 msg =
gettext_noop(
"permission denied for text search dictionary %s");
2787 elog(
ERROR,
"unsupported object type: %d", objtype);
2791 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2792 errmsg(msg, objectname)));
2797 const char *msg =
"???";
2817 msg =
gettext_noop(
"must be owner of event trigger %s");
2823 msg =
gettext_noop(
"must be owner of foreign-data wrapper %s");
2826 msg =
gettext_noop(
"must be owner of foreign server %s");
2829 msg =
gettext_noop(
"must be owner of foreign table %s");
2841 msg =
gettext_noop(
"must be owner of large object %s");
2844 msg =
gettext_noop(
"must be owner of materialized view %s");
2847 msg =
gettext_noop(
"must be owner of operator class %s");
2853 msg =
gettext_noop(
"must be owner of operator family %s");
2868 msg =
gettext_noop(
"must be owner of subscription %s");
2883 msg =
gettext_noop(
"must be owner of statistics object %s");
2889 msg =
gettext_noop(
"must be owner of text search configuration %s");
2892 msg =
gettext_noop(
"must be owner of text search dictionary %s");
2925 elog(
ERROR,
"unsupported object type: %d", objtype);
2929 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2930 errmsg(msg, objectname)));
2934 elog(
ERROR,
"unrecognized AclResult: %d", (
int) aclerr);
2942 const char *objectname,
const char *colname)
2951 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2952 errmsg(
"permission denied for column \"%s\" of relation \"%s\"",
2953 colname, objectname)));
2960 elog(
ERROR,
"unrecognized AclResult: %d", (
int) aclerr);
2996 return object_aclmask(DatabaseRelationId, object_oid, roleid, mask, how);
2998 return object_aclmask(ProcedureRelationId, object_oid, roleid, mask, how);
3000 return object_aclmask(LanguageRelationId, object_oid, roleid, mask, how);
3007 return object_aclmask(NamespaceRelationId, object_oid, roleid, mask, how);
3009 elog(
ERROR,
"grantable rights not supported for statistics objects");
3013 return object_aclmask(TableSpaceRelationId, object_oid, roleid, mask, how);
3015 return object_aclmask(ForeignDataWrapperRelationId, object_oid, roleid, mask, how);
3017 return object_aclmask(ForeignServerRelationId, object_oid, roleid, mask, how);
3019 elog(
ERROR,
"grantable rights not supported for event triggers");
3023 return object_aclmask(TypeRelationId, object_oid, roleid, mask, how);
3025 elog(
ERROR,
"unrecognized object type: %d",
3070 case NamespaceRelationId:
3073 case TypeRelationId:
3079 Assert(classid != RelationRelationId);
3080 Assert(classid != LargeObjectMetadataRelationId);
3096 if (is_missing != NULL)
3103 elog(
ERROR,
"cache lookup failed for %s %u",
3117 aclDatum = (
Datum) 0;
3125 result =
aclmask(acl, roleid, ownerId, mask, how);
3177 if (is_missing != NULL)
3185 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3186 errmsg(
"attribute %d of relation with OID %u does not exist",
3193 if (attributeForm->attisdropped)
3195 if (is_missing != NULL)
3204 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3205 errmsg(
"attribute %d of relation with OID %u does not exist",
3209 aclDatum =
SysCacheGetAttr(ATTNUM, attTuple, Anum_pg_attribute_attacl,
3234 if (is_missing != NULL)
3243 errmsg(
"relation with OID %u does not exist",
3248 ownerId = classForm->relowner;
3255 result =
aclmask(acl, roleid, ownerId, mask, how);
3297 if (is_missing != NULL)
3306 errmsg(
"relation with OID %u does not exist",
3322 classForm->relkind != RELKIND_VIEW &&
3338 ownerId = classForm->relowner;
3345 switch (classForm->relkind)
3347 case RELKIND_SEQUENCE:
3354 aclDatum = (
Datum) 0;
3362 result =
aclmask(acl, roleid, ownerId, mask, how);
3440 Anum_pg_parameter_acl_paracl,
3446 aclDatum = (
Datum) 0;
3454 result =
aclmask(acl, roleid, BOOTSTRAP_SUPERUSERID, mask, how);
3490 (
errcode(ERRCODE_UNDEFINED_OBJECT),
3491 errmsg(
"parameter ACL with OID %u does not exist",
3495 Anum_pg_parameter_acl_paracl,
3501 aclDatum = (
Datum) 0;
3509 result =
aclmask(acl, roleid, BOOTSTRAP_SUPERUSERID, mask, how);
3554 pg_lo_meta =
table_open(LargeObjectMetadataRelationId,
3558 Anum_pg_largeobject_metadata_oid,
3563 LargeObjectMetadataOidIndexId,
true,
3564 snapshot, 1, entry);
3569 (
errcode(ERRCODE_UNDEFINED_OBJECT),
3570 errmsg(
"large object %u does not exist", lobj_oid)));
3574 aclDatum =
heap_getattr(tuple, Anum_pg_largeobject_metadata_lomacl,
3581 aclDatum = (
Datum) 0;
3589 result =
aclmask(acl, roleid, ownerId, mask, how);
3655 if (is_missing != NULL)
3663 (
errcode(ERRCODE_UNDEFINED_SCHEMA),
3664 errmsg(
"schema with OID %u does not exist", nsp_oid)));
3669 aclDatum =
SysCacheGetAttr(NAMESPACEOID, tuple, Anum_pg_namespace_nspacl,
3675 aclDatum = (
Datum) 0;
3683 result =
aclmask(acl, roleid, ownerId, mask, how);
3729 if (is_missing != NULL)
3737 (
errcode(ERRCODE_UNDEFINED_OBJECT),
3738 errmsg(
"type with OID %u does not exist",
3747 if (IsTrueArrayType(typeForm))
3749 Oid elttype_oid = typeForm->typelem;
3756 if (is_missing != NULL)
3764 (
errcode(ERRCODE_UNDEFINED_OBJECT),
3765 errmsg(
"type with OID %u does not exist",
3776 if (typeForm->typtype == TYPTYPE_MULTIRANGE)
3785 if (is_missing != NULL)
3793 (
errcode(ERRCODE_UNDEFINED_OBJECT),
3794 errmsg(
"type with OID %u does not exist",
3803 ownerId = typeForm->typowner;
3806 Anum_pg_type_typacl, &isNull);
3811 aclDatum = (
Datum) 0;
3819 result =
aclmask(acl, roleid, ownerId, mask, how);
3936 if (is_missing != NULL)
3945 errmsg(
"relation with OID %u does not exist",
3950 ownerId = classForm->relowner;
3951 nattrs = classForm->relnatts;
3961 for (curr_att = 1; curr_att <= nattrs; curr_att++)
3988 aclDatum =
SysCacheGetAttr(ATTNUM, attTuple, Anum_pg_attribute_attacl,
4098 if (classid == LargeObjectRelationId)
4099 classid = LargeObjectMetadataRelationId;
4109 elog(
ERROR,
"cache lookup failed for %s %u",
4139 elog(
ERROR,
"could not find tuple for %s %u",
4169 bool result =
false;
4188 bool result =
false;
4226 Anum_pg_default_acl_defaclacl,
4264 defaclobjtype = DEFACLOBJ_RELATION;
4268 defaclobjtype = DEFACLOBJ_SEQUENCE;
4272 defaclobjtype = DEFACLOBJ_FUNCTION;
4276 defaclobjtype = DEFACLOBJ_TYPE;
4280 defaclobjtype = DEFACLOBJ_NAMESPACE;
4284 defaclobjtype = DEFACLOBJ_LARGEOBJECT;
4296 if (glob_acl == NULL && schema_acl == NULL)
4303 if (glob_acl == NULL)
4307 result =
aclmerge(glob_acl, schema_acl, ownerId);
4361 if (classoid == RelationRelationId)
4370 elog(
ERROR,
"cache lookup failed for relation %u", objoid);
4378 if (pg_class_tuple->relkind == RELKIND_INDEX ||
4379 pg_class_tuple->relkind == RELKIND_PARTITIONED_INDEX ||
4380 pg_class_tuple->relkind == RELKIND_COMPOSITE_TYPE)
4390 if (pg_class_tuple->relkind != RELKIND_SEQUENCE)
4393 AttrNumber nattrs = pg_class_tuple->relnatts;
4395 for (curr_att = 1; curr_att <= nattrs; curr_att++)
4415 Anum_pg_attribute_attacl,
4442 else if (classoid == LargeObjectRelationId)
4461 Anum_pg_largeobject_metadata_oid,
4466 LargeObjectMetadataOidIndexId,
true,
4471 elog(
ERROR,
"could not find tuple for large object %u", objoid);
4474 Anum_pg_largeobject_metadata_lomacl,
4495 elog(
ERROR,
"cache lookup failed for %s %u",
4523 if (classoid == RelationRelationId)
4530 elog(
ERROR,
"cache lookup failed for relation %u", objoid);
4538 if (pg_class_tuple->relkind == RELKIND_INDEX ||
4539 pg_class_tuple->relkind == RELKIND_PARTITIONED_INDEX ||
4540 pg_class_tuple->relkind == RELKIND_COMPOSITE_TYPE)
4550 if (pg_class_tuple->relkind != RELKIND_SEQUENCE)
4553 AttrNumber nattrs = pg_class_tuple->relnatts;
4555 for (curr_att = 1; curr_att <= nattrs; curr_att++)
4642 nnewmembers =
aclmembers(new_acl, &newmembers);
4648 Anum_pg_init_privs_objoid,
4652 Anum_pg_init_privs_classoid,
4656 Anum_pg_init_privs_objsubid,
4670 bool nulls[Natts_pg_init_privs] = {0};
4671 bool replace[Natts_pg_init_privs] = {0};
4677 oldAclDatum =
heap_getattr(oldtuple, Anum_pg_init_privs_initprivs,
4681 noldmembers =
aclmembers(old_acl, &oldmembers);
4684 noldmembers, oldmembers,
4685 nnewmembers, newmembers);
4688 if (new_acl &&
ACL_NUM(new_acl) != 0)
4691 replace[Anum_pg_init_privs_initprivs - 1] =
true;
4707 bool nulls[Natts_pg_init_privs] = {0};
4715 if (new_acl &&
ACL_NUM(new_acl) != 0)
4723 values[Anum_pg_init_privs_privtype - 1] =
4737 noldmembers, oldmembers,
4738 nnewmembers, newmembers);
4777 Anum_pg_init_privs_objoid,
4781 Anum_pg_init_privs_classoid,
4785 Anum_pg_init_privs_objsubid,
4807 oldAclDatum =
heap_getattr(oldtuple, Anum_pg_init_privs_initprivs,
4816 new_acl =
aclnewowner(old_acl, oldroleid, newroleid);
4822 if (new_acl == NULL ||
ACL_NUM(new_acl) == 0)
4829 bool nulls[Natts_pg_init_privs] = {0};
4830 bool replaces[Natts_pg_init_privs] = {0};
4834 replaces[Anum_pg_init_privs_initprivs - 1] =
true;
4837 values, nulls, replaces);
4844 noldmembers =
aclmembers(old_acl, &oldmembers);
4845 nnewmembers =
aclmembers(new_acl, &newmembers);
4848 noldmembers, oldmembers,
4849 nnewmembers, newmembers);
4888 Anum_pg_init_privs_objoid,
4892 Anum_pg_init_privs_classoid,
4896 Anum_pg_init_privs_objsubid,
4918 oldAclDatum =
heap_getattr(oldtuple, Anum_pg_init_privs_initprivs,
4928 noldmembers =
aclmembers(old_acl, &oldmembers);
4934 elog(
ERROR,
"cache lookup failed for %s %u",
4945 if (old_acl != NULL)
4958 if (new_acl == NULL ||
ACL_NUM(new_acl) == 0)
4965 bool nulls[Natts_pg_init_privs] = {0};
4966 bool replaces[Natts_pg_init_privs] = {0};
4970 replaces[Anum_pg_init_privs_initprivs - 1] =
true;
4973 values, nulls, replaces);
4980 nnewmembers =
aclmembers(new_acl, &newmembers);
4983 noldmembers, oldmembers,
4984 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, const ItemPointerData *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, ScanKeyData *key)
static void table_endscan(TableScanDesc scan)
text * cstring_to_text(const char *s)
void CommandCounterIncrement(void)