84 static const char *
getid(
const char *s,
char *n,
Node *escontext);
85 static void putid(
char *p,
const char *s);
146 bool in_quotes =
false;
150 while (isspace((
unsigned char) *s))
155 (isalnum((
unsigned char) *s) ||
166 in_quotes = !in_quotes;
176 (
errcode(ERRCODE_NAME_TOO_LONG),
177 errmsg(
"identifier too long"),
178 errdetail(
"Identifier must be less than %d characters.",
184 while (isspace((
unsigned char) *s))
200 for (src = s; *src; src++)
203 if (!isalnum((
unsigned char) *src) && *src !=
'_')
211 for (src = s; *src; src++)
263 if (strcmp(
name,
"group") != 0 && strcmp(
name,
"user") != 0)
265 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
266 errmsg(
"unrecognized key word: \"%s\"",
name),
267 errhint(
"ACL key word must be \"group\" or \"user\".")));
274 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
276 errhint(
"A name must follow the \"group\" or \"user\" key word.")));
281 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
282 errmsg(
"missing \"=\" sign")));
286 for (++s,
read = 0; isalpha((
unsigned char) *s) || *s ==
'*'; s++)
340 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
341 errmsg(
"invalid mode character: must be one of \"%s\"",
355 (
errcode(ERRCODE_UNDEFINED_OBJECT),
365 s =
getid(s + 1, name2, escontext);
368 if (name2[0] ==
'\0')
370 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
371 errmsg(
"a name must follow the \"/\" sign")));
375 (
errcode(ERRCODE_UNDEFINED_OBJECT),
376 errmsg(
"role \"%s\" does not exist", name2)));
382 (
errcode(ERRCODE_INVALID_GRANTOR),
383 errmsg(
"defaulting grantor to user ID %u",
384 BOOTSTRAP_SUPERUSERID)));
483 if (left_acl == NULL ||
ACL_NUM(left_acl) == 0)
485 if (right_acl == NULL ||
ACL_NUM(right_acl) == 0)
492 if (right_acl == NULL ||
ACL_NUM(right_acl) == 0)
497 result_acl =
aclcopy(left_acl);
502 for (
i = 0;
i < num;
i++, aip++)
509 result_acl = tmp_acl;
521 if (acl != NULL &&
ACL_NUM(acl) > 1)
536 if (left_acl == NULL ||
ACL_NUM(left_acl) == 0)
538 if (right_acl == NULL ||
ACL_NUM(right_acl) == 0)
545 if (right_acl == NULL ||
ACL_NUM(right_acl) == 0)
568 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
569 errmsg(
"ACL array contains wrong data type")));
572 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
573 errmsg(
"ACL arrays must be one-dimensional")));
576 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
577 errmsg(
"ACL arrays must not contain null values")));
592 Node *escontext = fcinfo->context;
601 while (isspace((
unsigned char) *s))
605 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
606 errmsg(
"extra garbage at the end of the ACL specification")));
628 out =
palloc(strlen(
"=/") +
689 return a1->ai_grantee ==
a2->ai_grantee &&
690 a1->ai_grantor ==
a2->ai_grantor;
703 if (
a1->ai_grantee >
a2->ai_grantee)
705 if (
a1->ai_grantee <
a2->ai_grantee)
707 if (
a1->ai_grantor >
a2->ai_grantor)
709 if (
a1->ai_grantor <
a2->ai_grantor)
711 if (
a1->ai_privs >
a2->ai_privs)
713 if (
a1->ai_privs <
a2->ai_privs)
728 result =
a1->ai_privs ==
a2->ai_privs &&
729 a1->ai_grantee ==
a2->ai_grantee &&
730 a1->ai_grantor ==
a2->ai_grantor;
845 elog(
ERROR,
"unrecognized object type: %d", (
int) objtype);
942 elog(
ERROR,
"unrecognized object type abbreviation: %c", objtypec);
997 for (dst = 0; dst < num; ++dst)
1004 memcpy(new_acl, old_acl,
ACL_SIZE(old_acl));
1014 memcpy(new_aip, old_aip, num *
sizeof(
AclItem));
1052 memmove(new_aip + dst,
1054 (num - dst - 1) *
sizeof(
AclItem));
1064 if ((old_goptions & ~new_goptions) != 0)
1068 (old_goptions & ~new_goptions),
1095 bool newpresent =
false;
1112 memcpy(new_aip, old_aip, num *
sizeof(
AclItem));
1113 for (dst = 0, dst_aip = new_aip; dst < num; dst++, dst_aip++)
1144 for (targ = 0, targ_aip = new_aip; targ < num; targ++, targ_aip++)
1150 for (src = targ + 1, src_aip = targ_aip + 1; src < num;
1165 new_aip[dst] = *targ_aip;
1213 memcpy(acl, old_acl,
ACL_SIZE(old_acl));
1219 for (
i = 0;
i < num;
i++)
1247 (
errcode(ERRCODE_INVALID_GRANT_OPERATION),
1248 errmsg(
"grant options cannot be granted back to your own grantor")));
1284 if (grantee == ownerId)
1288 still_has =
aclmask(acl, grantee, ownerId,
1298 for (
i = 0;
i < num;
i++)
1300 if (aip[
i].ai_grantor == grantee
1308 (
errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
1309 errmsg(
"dependent privileges exist"),
1310 errhint(
"Use CASCADE to revoke them too.")));
1385 if ((how ==
ACLMASK_ALL) ? (result == mask) : (result != 0))
1395 for (
i = 0;
i < num;
i++)
1403 if ((how ==
ACLMASK_ALL) ? (result == mask) : (result != 0))
1416 for (
i = 0;
i < num;
i++)
1428 if ((how ==
ACLMASK_ALL) ? (result == mask) : (result != 0))
1473 if ((how ==
ACLMASK_ALL) ? (result == mask) : (result != 0))
1483 for (
i = 0;
i < num;
i++)
1490 if ((how ==
ACLMASK_ALL) ? (result == mask) : (result != 0))
1515 if (acl == NULL ||
ACL_NUM(acl) == 0)
1563 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1564 errmsg(
"aclinsert is no longer supported")));
1573 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1574 errmsg(
"aclremove is no longer supported")));
1591 for (
i = 0;
i < num; ++
i)
1610 static const priv_map any_priv_map[] = {
1663 for (chunk = priv_type; chunk; chunk = next_chunk)
1669 next_chunk = strchr(chunk,
',');
1671 *next_chunk++ =
'\0';
1674 while (*chunk && isspace((
unsigned char) *chunk))
1676 chunk_len = strlen(chunk);
1677 while (chunk_len > 0 && isspace((
unsigned char) chunk[chunk_len - 1]))
1679 chunk[chunk_len] =
'\0';
1682 for (this_priv = privileges; this_priv->
name; this_priv++)
1686 result |= this_priv->
value;
1690 if (!this_priv->
name)
1692 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1693 errmsg(
"unrecognized privilege type: \"%s\"", chunk)));
1717 return "REFERENCES";
1733 return "ALTER SYSTEM";
1735 elog(
ERROR,
"unrecognized aclright: %d", aclright);
1816 aidata = &aidat[
idx[0]];
1817 priv_bit = UINT64CONST(1) <<
idx[1];
1823 bool nulls[4] = {0};
2028 static const priv_map table_priv_map[] = {
2044 {
"RULE WITH GRANT OPTION", 0},
2083 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2084 errmsg(
"\"%s\" is not a sequence",
2113 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2114 errmsg(
"\"%s\" is not a sequence",
2141 if (relkind ==
'\0')
2143 else if (relkind != RELKIND_SEQUENCE)
2145 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2146 errmsg(
"\"%s\" is not a sequence",
2173 if (relkind ==
'\0')
2175 else if (relkind != RELKIND_SEQUENCE)
2177 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2178 errmsg(
"\"%s\" is not a sequence",
2205 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2206 errmsg(
"\"%s\" is not a sequence",
2231 if (relkind ==
'\0')
2233 else if (relkind != RELKIND_SEQUENCE)
2235 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2236 errmsg(
"\"%s\" is not a sequence",
2251 static const priv_map sequence_priv_map[] = {
2478 bool is_missing =
false;
2495 else if (is_missing)
2502 else if (is_missing)
2856 if (attributeForm->attisdropped)
2859 attnum = attributeForm->attnum;
2871 if (tablename != NULL)
2875 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2876 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
2877 colname, tablename)));
2894 static const priv_map column_priv_map[] = {
3091 static const priv_map database_priv_map[] = {
3288 static const priv_map foreign_data_wrapper_priv_map[] = {
3475 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
3488 static const priv_map function_priv_map[] = {
3679 static const priv_map language_priv_map[] = {
3870 static const priv_map schema_priv_map[] = {
4063 static const priv_map server_priv_map[] = {
4254 static const priv_map tablespace_priv_map[] = {
4440 (
errcode(ERRCODE_UNDEFINED_OBJECT),
4453 static const priv_map type_priv_map[] = {
4542 static const priv_map parameter_priv_map[] = {
4720 static const priv_map role_priv_map[] = {
4837 Oid admin_of,
Oid *admin_role)
4842 List *new_cached_roles;
4846 if (admin_role != NULL)
4885 foreach(l, roles_list)
4898 Oid otherid = form->roleid;
4904 if (otherid == admin_of && form->admin_option &&
4906 *admin_role = memberid;
4928 ROLE_PG_DATABASE_OWNER);
4935 new_cached_roles =
list_copy(roles_list);
5022 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5023 errmsg(
"must be able to SET ROLE \"%s\"",
5172 const Acl *acl,
Oid ownerId,
5188 *grantorId = ownerId;
5189 *grantOptions = needed_goptions;
5203 *grantorId = roleId;
5207 foreach(l, roles_list)
5214 if (otherprivs == needed_goptions)
5217 *grantorId = otherrole;
5218 *grantOptions = otherprivs;
5230 if (nnewrights > nrights)
5232 *grantorId = otherrole;
5233 *grantOptions = otherprivs;
5234 nrights = nnewrights;
5255 (
errcode(ERRCODE_UNDEFINED_OBJECT),
5267 if (strcmp(
rolname,
"public") == 0)
5303 (
errcode(ERRCODE_UNDEFINED_OBJECT),
5304 errmsg(
"role \"%s\" does not exist",
"public")));
5331 (
errcode(ERRCODE_UNDEFINED_OBJECT),
5350 (
errcode(ERRCODE_UNDEFINED_OBJECT),
5351 errmsg(
"role \"%s\" does not exist",
"public")));
5400 (
errcode(ERRCODE_RESERVED_NAME),
5401 errmsg(
"role name \"%s\" is reserved",
5406 (
errcode(ERRCODE_RESERVED_NAME),
5407 errmsg(
"role name \"%s\" is reserved",
Datum idx(PG_FUNCTION_ARGS)
Datum pg_has_role_id_id(PG_FUNCTION_ARGS)
Datum has_schema_privilege_id(PG_FUNCTION_ARGS)
Datum hash_aclitem(PG_FUNCTION_ARGS)
void initialize_acl(void)
Datum has_sequence_privilege_name(PG_FUNCTION_ARGS)
Datum has_table_privilege_id_id(PG_FUNCTION_ARGS)
Datum has_server_privilege_id(PG_FUNCTION_ARGS)
Acl * aclupdate(const Acl *old_acl, const AclItem *mod_aip, int modechg, Oid ownerId, DropBehavior behavior)
Datum has_tablespace_privilege_id_id(PG_FUNCTION_ARGS)
Datum has_column_privilege_id_id_attnum(PG_FUNCTION_ARGS)
Datum has_server_privilege_name_name(PG_FUNCTION_ARGS)
Datum aclinsert(PG_FUNCTION_ARGS)
static AclMode convert_function_priv_string(text *priv_type_text)
static const char * getid(const char *s, char *n, Node *escontext)
static const char * convert_aclright_to_string(int aclright)
bool is_admin_of_role(Oid member, Oid role)
Datum has_column_privilege_id_name(PG_FUNCTION_ARGS)
static bool aclitem_match(const AclItem *a1, const AclItem *a2)
Datum pg_has_role_name_name(PG_FUNCTION_ARGS)
Datum has_language_privilege_name_name(PG_FUNCTION_ARGS)
Datum has_schema_privilege_name_name(PG_FUNCTION_ARGS)
Datum aclitem_eq(PG_FUNCTION_ARGS)
Datum has_tablespace_privilege_name_id(PG_FUNCTION_ARGS)
Datum makeaclitem(PG_FUNCTION_ARGS)
Datum has_table_privilege_id_name(PG_FUNCTION_ARGS)
Datum has_server_privilege_name_id(PG_FUNCTION_ARGS)
Datum has_column_privilege_name_id_attnum(PG_FUNCTION_ARGS)
Datum has_language_privilege_id_name(PG_FUNCTION_ARGS)
static int column_privilege_check(Oid tableoid, AttrNumber attnum, Oid roleid, AclMode mode)
static Oid convert_type_name(text *typename)
char * get_rolespec_name(const RoleSpec *role)
Oid select_best_admin(Oid member, Oid role)
Datum aclexplode(PG_FUNCTION_ARGS)
static Oid convert_database_name(text *databasename)
Datum aclitemout(PG_FUNCTION_ARGS)
Oid get_role_oid_or_public(const char *rolname)
Datum has_foreign_data_wrapper_privilege_name_id(PG_FUNCTION_ARGS)
Datum has_foreign_data_wrapper_privilege_id_id(PG_FUNCTION_ARGS)
bool aclequal(const Acl *left_acl, const Acl *right_acl)
Datum hash_aclitem_extended(PG_FUNCTION_ARGS)
static void check_acl(const Acl *acl)
Datum has_parameter_privilege_name_name(PG_FUNCTION_ARGS)
Datum has_foreign_data_wrapper_privilege_id(PG_FUNCTION_ARGS)
Datum has_database_privilege_name(PG_FUNCTION_ARGS)
static uint32 cached_db_hash
Datum has_type_privilege_name_name(PG_FUNCTION_ARGS)
Datum has_column_privilege_name_name_name(PG_FUNCTION_ARGS)
Datum pg_has_role_name(PG_FUNCTION_ARGS)
Datum has_sequence_privilege_id(PG_FUNCTION_ARGS)
static AclMode convert_type_priv_string(text *priv_type_text)
Datum has_tablespace_privilege_name(PG_FUNCTION_ARGS)
static AclMode convert_table_priv_string(text *priv_type_text)
static AclMode convert_server_priv_string(text *priv_type_text)
Datum has_table_privilege_name_id(PG_FUNCTION_ARGS)
Datum has_foreign_data_wrapper_privilege_name_name(PG_FUNCTION_ARGS)
Datum has_tablespace_privilege_id_name(PG_FUNCTION_ARGS)
static Acl * recursive_revoke(Acl *acl, Oid grantee, AclMode revoke_privs, Oid ownerId, DropBehavior behavior)
static void RoleMembershipCacheCallback(Datum arg, int cacheid, uint32 hashvalue)
Datum has_database_privilege_name_id(PG_FUNCTION_ARGS)
static Oid convert_schema_name(text *schemaname)
Datum has_column_privilege_name_name(PG_FUNCTION_ARGS)
static void putid(char *p, const char *s)
Datum has_schema_privilege_id_name(PG_FUNCTION_ARGS)
static void check_circularity(const Acl *old_acl, const AclItem *mod_aip, Oid ownerId)
static bool has_param_priv_byname(Oid roleid, const text *parameter, AclMode priv)
bool is_member_of_role(Oid member, Oid role)
Datum has_sequence_privilege_id_name(PG_FUNCTION_ARGS)
Datum has_database_privilege_id_name(PG_FUNCTION_ARGS)
static Oid convert_foreign_data_wrapper_name(text *fdwname)
Datum has_language_privilege_id(PG_FUNCTION_ARGS)
static AclMode convert_database_priv_string(text *priv_type_text)
Datum has_foreign_data_wrapper_privilege_name(PG_FUNCTION_ARGS)
Datum has_column_privilege_name_attnum(PG_FUNCTION_ARGS)
Datum has_column_privilege_id_attnum(PG_FUNCTION_ARGS)
Datum has_type_privilege_name_id(PG_FUNCTION_ARGS)
Datum has_any_column_privilege_name_id(PG_FUNCTION_ARGS)
Datum has_server_privilege_id_name(PG_FUNCTION_ARGS)
Datum has_language_privilege_name_id(PG_FUNCTION_ARGS)
Datum has_foreign_data_wrapper_privilege_id_name(PG_FUNCTION_ARGS)
Datum has_schema_privilege_name_id(PG_FUNCTION_ARGS)
Datum has_function_privilege_name_name(PG_FUNCTION_ARGS)
void select_best_grantor(Oid roleId, AclMode privileges, const Acl *acl, Oid ownerId, Oid *grantorId, AclMode *grantOptions)
Datum has_any_column_privilege_name_name(PG_FUNCTION_ARGS)
bool is_member_of_role_nosuper(Oid member, Oid role)
Datum has_sequence_privilege_name_id(PG_FUNCTION_ARGS)
Datum has_schema_privilege_name(PG_FUNCTION_ARGS)
Datum acldefault_sql(PG_FUNCTION_ARGS)
bool has_privs_of_role(Oid member, Oid role)
static Oid convert_language_name(text *languagename)
Datum has_language_privilege_id_id(PG_FUNCTION_ARGS)
static AclMode convert_any_priv_string(text *priv_type_text, const priv_map *privileges)
Datum has_database_privilege_id_id(PG_FUNCTION_ARGS)
Datum has_function_privilege_name(PG_FUNCTION_ARGS)
int aclmembers(const Acl *acl, Oid **roleids)
Datum has_language_privilege_name(PG_FUNCTION_ARGS)
Acl * aclconcat(const Acl *left_acl, const Acl *right_acl)
Acl * aclcopy(const Acl *orig_acl)
Datum has_server_privilege_name(PG_FUNCTION_ARGS)
bool member_can_set_role(Oid member, Oid role)
Datum aclremove(PG_FUNCTION_ARGS)
Datum has_function_privilege_id(PG_FUNCTION_ARGS)
void aclitemsort(Acl *acl)
Datum has_table_privilege_id(PG_FUNCTION_ARGS)
Datum has_function_privilege_id_id(PG_FUNCTION_ARGS)
AclMode aclmask(const Acl *acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how)
static Oid convert_server_name(text *servername)
Acl * acldefault(ObjectType objtype, Oid ownerId)
static Oid convert_tablespace_name(text *tablespacename)
Acl * make_empty_acl(void)
Datum has_column_privilege_name_name_attnum(PG_FUNCTION_ARGS)
static AclMode convert_parameter_priv_string(text *priv_text)
static Oid convert_table_name(text *tablename)
Datum has_column_privilege_name_id_name(PG_FUNCTION_ARGS)
static int count_one_bits(AclMode mask)
static AclMode convert_tablespace_priv_string(text *priv_type_text)
static AclMode convert_language_priv_string(text *priv_type_text)
Datum aclitemin(PG_FUNCTION_ARGS)
static AclMode convert_sequence_priv_string(text *priv_type_text)
Datum pg_has_role_id(PG_FUNCTION_ARGS)
Datum has_parameter_privilege_id_name(PG_FUNCTION_ARGS)
Acl * aclnewowner(const Acl *old_acl, Oid oldOwnerId, Oid newOwnerId)
static Acl * allocacl(int n)
static AttrNumber convert_column_name(Oid tableoid, text *column)
static AclMode convert_role_priv_string(text *priv_type_text)
Oid get_role_oid(const char *rolname, bool missing_ok)
Datum has_tablespace_privilege_name_name(PG_FUNCTION_ARGS)
Datum has_parameter_privilege_name(PG_FUNCTION_ARGS)
Datum has_any_column_privilege_name(PG_FUNCTION_ARGS)
Datum has_sequence_privilege_name_name(PG_FUNCTION_ARGS)
Datum has_function_privilege_name_id(PG_FUNCTION_ARGS)
Datum has_type_privilege_id_id(PG_FUNCTION_ARGS)
Datum has_server_privilege_id_id(PG_FUNCTION_ARGS)
static AclResult pg_role_aclcheck(Oid role_oid, Oid roleid, AclMode mode)
Datum has_function_privilege_id_name(PG_FUNCTION_ARGS)
Datum has_table_privilege_name(PG_FUNCTION_ARGS)
Datum has_type_privilege_id_name(PG_FUNCTION_ARGS)
Datum has_column_privilege_id_name_attnum(PG_FUNCTION_ARGS)
void check_can_set_role(Oid member, Oid role)
static const char * aclparse(const char *s, AclItem *aip, Node *escontext)
void check_rolespec_name(const RoleSpec *role, const char *detail_msg)
Datum has_type_privilege_name(PG_FUNCTION_ARGS)
static List * cached_roles[]
static AclMode aclmask_direct(const Acl *acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow h