* ParseDropUserSpec parses the wire * protocol message dropUser() which drops a user */
| 599 | * protocol message dropUser() which drops a user |
| 600 | */ |
| 601 | static char * |
| 602 | ParseDropUserSpec(pgbson *dropSpec) |
| 603 | { |
| 604 | bson_iter_t dropIter; |
| 605 | PgbsonInitIterator(dropSpec, &dropIter); |
| 606 | |
| 607 | char *dropUser = NULL; |
| 608 | bool dbFound = false; |
| 609 | while (bson_iter_next(&dropIter)) |
| 610 | { |
| 611 | const char *key = bson_iter_key(&dropIter); |
| 612 | if (strcmp(key, "dropUser") == 0) |
| 613 | { |
| 614 | EnsureTopLevelFieldType(key, &dropIter, BSON_TYPE_UTF8); |
| 615 | uint32_t strLength = 0; |
| 616 | dropUser = (char *) bson_iter_utf8(&dropIter, &strLength); |
| 617 | if (strLength == 0) |
| 618 | { |
| 619 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 620 | errmsg( |
| 621 | "The field 'dropUser' is mandatory."))); |
| 622 | } |
| 623 | |
| 624 | if (ContainsReservedPgRoleNamePrefix(dropUser) || |
| 625 | IsReservedInternalRoleName(dropUser)) |
| 626 | { |
| 627 | ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT), |
| 628 | errmsg("The specified user does not exist."))); |
| 629 | } |
| 630 | } |
| 631 | else if (strcmp(key, "$db") == 0 && EnableUsersAdminDBCheck) |
| 632 | { |
| 633 | EnsureTopLevelFieldType(key, &dropIter, BSON_TYPE_UTF8); |
| 634 | uint32_t strLength = 0; |
| 635 | const char *db_name = bson_iter_utf8(&dropIter, &strLength); |
| 636 | |
| 637 | dbFound = true; |
| 638 | if (strcmp(db_name, "admin") != 0) |
| 639 | { |
| 640 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 641 | errmsg( |
| 642 | "DropUser must be called from 'admin' database."))); |
| 643 | } |
| 644 | } |
| 645 | else if (IsCommonSpecIgnoredField(key)) |
| 646 | { |
| 647 | continue; |
| 648 | } |
| 649 | else |
| 650 | { |
| 651 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 652 | errmsg("The specified field '%s' is not supported.", key))); |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | if (!dbFound && EnableUsersAdminDBCheck) |
| 657 | { |
| 658 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
no test coverage detected