* ParseDropRoleSpec parses the dropRole command parameters */
| 736 | * ParseDropRoleSpec parses the dropRole command parameters |
| 737 | */ |
| 738 | static void |
| 739 | ParseDropRoleSpec(pgbson *dropRoleBson, DropRoleSpec *dropRoleSpec) |
| 740 | { |
| 741 | bson_iter_t dropRoleIter; |
| 742 | PgbsonInitIterator(dropRoleBson, &dropRoleIter); |
| 743 | bool dbFound = false; |
| 744 | while (bson_iter_next(&dropRoleIter)) |
| 745 | { |
| 746 | const char *key = bson_iter_key(&dropRoleIter); |
| 747 | |
| 748 | if (strcmp(key, "dropRole") == 0) |
| 749 | { |
| 750 | EnsureTopLevelFieldType(key, &dropRoleIter, BSON_TYPE_UTF8); |
| 751 | uint32_t strLength = 0; |
| 752 | const char *roleNameValue = bson_iter_utf8(&dropRoleIter, &strLength); |
| 753 | |
| 754 | if (strLength == 0) |
| 755 | { |
| 756 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 757 | errmsg("'dropRole' cannot be empty."))); |
| 758 | } |
| 759 | |
| 760 | if (ContainsReservedPgRoleNamePrefix(roleNameValue) || |
| 761 | IsReservedInternalRoleName(roleNameValue)) |
| 762 | { |
| 763 | ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT), |
| 764 | errmsg( |
| 765 | "The specified role '%s' does not exist.", |
| 766 | roleNameValue))); |
| 767 | } |
| 768 | |
| 769 | if (IS_NATIVE_BUILTIN_ROLE(roleNameValue)) |
| 770 | { |
| 771 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 772 | errmsg( |
| 773 | "Cannot drop built-in role '%s'.", |
| 774 | roleNameValue))); |
| 775 | } |
| 776 | |
| 777 | dropRoleSpec->roleName = pstrdup(roleNameValue); |
| 778 | } |
| 779 | else if (strcmp(key, "$db") == 0 && EnableRolesAdminDBCheck) |
| 780 | { |
| 781 | EnsureTopLevelFieldType(key, &dropRoleIter, BSON_TYPE_UTF8); |
| 782 | uint32_t strLength = 0; |
| 783 | const char *dbName = bson_iter_utf8(&dropRoleIter, &strLength); |
| 784 | |
| 785 | dbFound = true; |
| 786 | if (strcmp(dbName, "admin") != 0) |
| 787 | { |
| 788 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 789 | errmsg( |
| 790 | "DropRole must be called from 'admin' database."))); |
| 791 | } |
| 792 | } |
| 793 | else if (IsCommonSpecIgnoredField(key)) |
| 794 | { |
| 795 | continue; |
no test coverage detected