/* Recursively dump the object tree */ static void print_config_tree(confdb_handle_t handle, hdb_handle_t parent_object_handle, int depth) { hdb_handle_t object_handle; char object_name[1024]; size_t object_name_len; char key_name[1024]; size_t key_name_len; char key_value[1024]; size_t key_value_len; int res; int i; /* Show the keys */ res = confdb_key_iter_start(handle, parent_object_handle); if (res != CS_OK) { printf( "error resetting key iterator for object "HDB_X_FORMAT": %d\n", parent_object_handle, res); return; } while ( (res = confdb_key_iter(handle, parent_object_handle, key_name, &key_name_len, key_value, &key_value_len)) == CS_OK) { key_name[key_name_len] = '\0'; key_value[key_value_len] = '\0'; for (i=0; i<depth; i++) printf(" "); printf(" KEY %s=%s\n", key_name, key_value); } /* Show sub-objects */ res = confdb_object_iter_start(handle, parent_object_handle); if (res != CS_OK) { printf( "error resetting object iterator for object "HDB_X_FORMAT": %d\n", parent_object_handle, res); return; } while ( (res = confdb_object_iter(handle, parent_object_handle, &object_handle, object_name, &object_name_len)) == CS_OK) { hdb_handle_t parent; res = confdb_object_parent_get(handle, object_handle, &parent); if (res != CS_OK) { printf( "error getting parent for object "HDB_X_FORMAT": %d\n", object_handle, res); return; } for (i=0; i<depth; i++) printf(" "); object_name[object_name_len] = '\0'; printf("OBJECT: %s ("HDB_X_FORMAT", parent: "HDB_X_FORMAT")\n", object_name, object_handle, parent); /* Down we go ... */ print_config_tree(handle, object_handle, depth+1); } }
/* Recursively dump the object tree */ static void print_config_tree(confdb_handle_t handle, hdb_handle_t parent_object_handle, const char *dn, char *fulldn) { hdb_handle_t object_handle; char object_name[1024]; size_t object_name_len; char key_name[1024]; char *key_value=NULL; confdb_value_types_t type; size_t key_value_len; char cumulative_dn[4096]; int res; int keycount=0; printf("\ndn: %s\n", fulldn); /* Show the keys */ res = confdb_key_iter_start(handle, parent_object_handle); if (res != CS_OK) { printf( "error resetting key iterator for object "HDB_X_FORMAT": %d\n", parent_object_handle, res); return; } while ( (res = confdb_key_iter_typed2(handle, parent_object_handle, key_name, (void**)&key_value, &key_value_len, &type)) == CS_OK) { key_value[key_value_len] = '\0'; printf("%s: %s\n", ldap_attr_name(key_name), key_value); keycount++; free(key_value); key_value=NULL; } if (strncmp(fulldn, "cn=", 3) == 0) { printf("cn: %s\n", dn); } /* Determine objectclass... */ if (keycount == 0) { printf("objectclass: nsContainer\n"); } else { printf("objectclass: %s\n", ldap_attr_name(dn)); } /* Show sub-objects */ res = confdb_object_iter_start(handle, parent_object_handle); if (res != CS_OK) { printf( "error resetting object iterator for object "HDB_X_FORMAT": %d\n", parent_object_handle, res); return; } while ( (res = confdb_object_iter(handle, parent_object_handle, &object_handle, object_name, &object_name_len)) == CS_OK) { hdb_handle_t parent; res = confdb_object_parent_get(handle, object_handle, &parent); if (res != CS_OK) { printf( "error getting parent for object "HDB_X_FORMAT": %d\n", object_handle, res); return; } object_name[object_name_len] = '\0'; /* Check for "name", and create dummy parent object */ res = confdb_key_get_typed2(handle, object_handle, "name", (void **)&key_value, &key_value_len, &type); if (res == CS_OK) { sprintf(cumulative_dn, "cn=%s,%s", object_name, fulldn); printf("\n"); printf("dn: %s\n", cumulative_dn); printf("cn: %s\n", object_name); printf("objectclass: %s\n", "nsContainer"); snprintf(cumulative_dn, sizeof(cumulative_dn) - 1, "name=%s,cn=%s,%s", key_value, object_name, fulldn); free(key_value); key_value = NULL; } else { sprintf(cumulative_dn, "cn=%s,%s", object_name, fulldn); } /* Down we go ... */ print_config_tree(handle, object_handle, object_name, cumulative_dn); } }