* Look up all inherited roles (transitive closure) from the pre-built role * inheritance table using recursive traversal. * * Handles diamond inheritance (e.g., role A inherits B and C, both B and C * inherit D) by using a hash set that serves for both deduplication and * collecting results. */
| 1234 | * collecting results. |
| 1235 | */ |
| 1236 | static List * |
| 1237 | LookupAllInheritedRoles(const char *internalRoleName, HTAB *roleInheritanceTable) |
| 1238 | { |
| 1239 | HASHCTL resultCtl; |
| 1240 | MemSet(&resultCtl, 0, sizeof(resultCtl)); |
| 1241 | resultCtl.keysize = NAMEDATALEN; |
| 1242 | resultCtl.entrysize = NAMEDATALEN; |
| 1243 | HTAB *resultSet = hash_create("InheritedRolesSet", 32, &resultCtl, |
| 1244 | HASH_ELEM | HASH_STRINGS); |
| 1245 | |
| 1246 | CollectInheritedRolesRecursive(internalRoleName, roleInheritanceTable, resultSet); |
| 1247 | |
| 1248 | /* Convert hash set to list */ |
| 1249 | List *result = NIL; |
| 1250 | HASH_SEQ_STATUS status; |
| 1251 | char *entry; |
| 1252 | hash_seq_init(&status, resultSet); |
| 1253 | while ((entry = hash_seq_search(&status)) != NULL) |
| 1254 | { |
| 1255 | result = lappend(result, pstrdup(entry)); |
| 1256 | } |
| 1257 | |
| 1258 | hash_destroy(resultSet); |
| 1259 | return result; |
| 1260 | } |
| 1261 | |
| 1262 | |
| 1263 | /* |
no test coverage detected