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

Function CollectInheritedRolesRecursive

pg_documentdb/src/commands/roles.c:1184–1225  ·  view source on GitHub ↗

* Recursively collect all inherited roles into the result hash set. * The hash set serves for both deduplication and collecting results. */

Source from the content-addressed store, hash-verified

1182 * The hash set serves for both deduplication and collecting results.
1183 */
1184static void
1185CollectInheritedRolesRecursive(const char *internalRoleName, HTAB *roleInheritanceTable,
1186 HTAB *resultSet)
1187{
1188 bool found = false;
1189 RoleParentEntry *entry = (RoleParentEntry *) hash_search(
1190 roleInheritanceTable, internalRoleName, HASH_FIND, &found);
1191
1192 /*
1193 * Role may not be found if it's a system role (oid < FirstNormalObjectId)
1194 * that was referenced as a parent but not included in our inheritance table query.
1195 * This is expected behavior - silently skip such roles.
1196 */
1197 if (!found)
1198 {
1199 ereport(WARNING, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR),
1200 errmsg(
1201 "Role '%s' not found.",
1202 internalRoleName)));
1203 }
1204
1205 if (entry->parentRoles == NIL)
1206 {
1207 return;
1208 }
1209
1210 ListCell *cell;
1211 foreach(cell, entry->parentRoles)
1212 {
1213 char *parentName = (char *) lfirst(cell);
1214
1215 /* Insert into resultSet; skip if already present */
1216 bool alreadyExists = false;
1217 hash_search(resultSet, parentName, HASH_ENTER, &alreadyExists);
1218 if (alreadyExists)
1219 {
1220 continue;
1221 }
1222
1223 CollectInheritedRolesRecursive(parentName, roleInheritanceTable, resultSet);
1224 }
1225}
1226
1227
1228/*

Callers 1

LookupAllInheritedRolesFunction · 0.85

Calls 1

foreachFunction · 0.50

Tested by

no test coverage detected