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

Function BuildUserRoleEntryTable

pg_documentdb/src/commands/users.c:1810–1895  ·  view source on GitHub ↗

* BuildUserRoleEntryTable creates and populates a hash table with user role information * from the provided user data array. */

Source from the content-addressed store, hash-verified

1808 * from the provided user data array.
1809 */
1810static HTAB *
1811BuildUserRoleEntryTable(Datum *userDatums, int userCount)
1812{
1813 HTAB *userRolesTable = CreateUserEntryHashSet();
1814
1815 for (int i = 0; i < userCount; i++)
1816 {
1817 /* Convert Datum to a bson_t object */
1818 pgbson *bson_doc = DatumGetPgBson(userDatums[i]);
1819 bson_iter_t getIter;
1820 PgbsonInitIterator(bson_doc, &getIter);
1821
1822 const char *user = NULL;
1823
1824 /* Initialize iterator */
1825 if (bson_iter_find(&getIter, "child_role"))
1826 {
1827 if (BSON_ITER_HOLDS_UTF8(&getIter))
1828 {
1829 user = bson_iter_utf8(&getIter, NULL);
1830 bool userFound = false;
1831 UserRoleHashEntry searchEntry = {
1832 .user = (char *) user,
1833 };
1834
1835 hash_search(userRolesTable,
1836 &searchEntry,
1837 HASH_FIND,
1838 &userFound);
1839
1840 if (!userFound)
1841 {
1842 UserRoleHashEntry newEntry = {
1843 .user = pstrdup(user),
1844 .roles = NULL,
1845 .isExternal = IsUserExternal(user)
1846 };
1847
1848 bool entryCreated = false;
1849 hash_search(userRolesTable, &newEntry, HASH_ENTER, &entryCreated);
1850 }
1851 }
1852 }
1853 if (bson_iter_find(&getIter, "parent_role"))
1854 {
1855 if (BSON_ITER_HOLDS_UTF8(&getIter))
1856 {
1857 const char *parentRole = bson_iter_utf8(&getIter, NULL);
1858
1859 if (!IS_BUILTIN_ROLE(parentRole))
1860 {
1861 continue;
1862 }
1863
1864 UserRoleHashEntry userSearchEntry = {
1865 .user = (char *) user,
1866 };
1867

Callers 1

Calls 4

CreateUserEntryHashSetFunction · 0.85
PgbsonInitIteratorFunction · 0.85
IsUserExternalFunction · 0.85
CreateStringViewHashSetFunction · 0.85

Tested by

no test coverage detected