MCPcopy Create free account
hub / github.com/documentdb/documentdb / ParseDropUserSpec

Function ParseDropUserSpec

pg_documentdb/src/commands/users.c:601–669  ·  view source on GitHub ↗

* ParseDropUserSpec parses the wire * protocol message dropUser() which drops a user */

Source from the content-addressed store, hash-verified

599 * protocol message dropUser() which drops a user
600 */
601static char *
602ParseDropUserSpec(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),

Callers 1

Calls 5

PgbsonInitIteratorFunction · 0.85
EnsureTopLevelFieldTypeFunction · 0.85
IsCommonSpecIgnoredFieldFunction · 0.85

Tested by

no test coverage detected