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

Function ParseUpdateUserSpec

pg_documentdb/src/commands/users.c:777–856  ·  view source on GitHub ↗

* ParseUpdateUserSpec parses the wire * protocol message updateUser() which drops a user */

Source from the content-addressed store, hash-verified

775 * protocol message updateUser() which drops a user
776 */
777static void
778ParseUpdateUserSpec(pgbson *updateSpec, UpdateUserSpec *spec)
779{
780 bson_iter_t updateIter;
781 PgbsonInitIterator(updateSpec, &updateIter);
782
783 bool userFound = false;
784 bool dbFound = false;
785 while (bson_iter_next(&updateIter))
786 {
787 const char *key = bson_iter_key(&updateIter);
788 if (strcmp(key, "updateUser") == 0)
789 {
790 EnsureTopLevelFieldType(key, &updateIter, BSON_TYPE_UTF8);
791 uint32_t strLength = 0;
792 spec->updateUser = bson_iter_utf8(&updateIter, &strLength);
793 if (strLength == 0)
794 {
795 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE),
796 errmsg(
797 "'updateUser' is a required field.")));
798 }
799
800 if (ContainsReservedPgRoleNamePrefix(spec->updateUser) ||
801 IsReservedInternalRoleName(spec->updateUser))
802 {
803 ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT),
804 errmsg("The specified user does not exist.")));
805 }
806
807 userFound = true;
808 }
809 else if (strcmp(key, "pwd") == 0)
810 {
811 EnsureTopLevelFieldType(key, &updateIter, BSON_TYPE_UTF8);
812 uint32_t strLength = 0;
813 spec->pwd = bson_iter_utf8(&updateIter, &strLength);
814 }
815 else if (strcmp(key, "$db") == 0 && EnableUsersAdminDBCheck)
816 {
817 EnsureTopLevelFieldType(key, &updateIter, BSON_TYPE_UTF8);
818 uint32_t strLength = 0;
819 const char *db_name = bson_iter_utf8(&updateIter, &strLength);
820
821 dbFound = true;
822 if (strcmp(db_name, "admin") != 0)
823 {
824 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE),
825 errmsg(
826 "UpdateUser must be called from 'admin' database.")));
827 }
828 }
829 else if (IsCommonSpecIgnoredField(key))
830 {
831 continue;
832 }
833 else if (strcmp(key, "roles") == 0)
834 {

Callers 1

Calls 5

PgbsonInitIteratorFunction · 0.85
EnsureTopLevelFieldTypeFunction · 0.85
IsCommonSpecIgnoredFieldFunction · 0.85

Tested by

no test coverage detected