Hi everyone,
I'm using the C SDK and writing a program to prune old directory records.
The core logic of the program could go something like this:-
rc = ldap_search_ext( ld, .. <rest of parameters> ); while (!done) { rc = ldap_result( ld, .. <rest of parameters>, &searchResult) ; //Delete records matching criteria dn = ldap_get_dn( ld, searchResult ); rc = ldap_delete_ext_s( ld, dn, .. <rest of parameters>); }
------- I have two questions and they are probably related:-
Firstly: Can I delete records while iterating through the results of the ldap search? (In higher level languages deleting an item from a collection while navigating through a collection is often bad form. Is that the case here?)
Secondly: Can I use the same session handle to delete the records as is used for the search? In the logic above, the session handle is ld, and ld is used for both the search and for the deletion. (I'm expecting I would need to use a different session handle for the logic above to work. Alternatively one could save all the records to be deleted in an array and then after the search loop, the same session handle can be used for all the deletes).
Thank you Stephen
Stephen wrote:
Hi everyone,
I'm using the C SDK and writing a program to prune old directory records.
The core logic of the program could go something like this:-
rc = ldap_search_ext( ld, ..<rest of parameters> ); while (!done) { rc = ldap_result( ld, ..<rest of parameters>,&searchResult) ; //Delete records matching criteria dn = ldap_get_dn( ld, searchResult ); rc = ldap_delete_ext_s( ld, dn, ..<rest of parameters>); }
I have two questions and they are probably related:-
Firstly: Can I delete records while iterating through the results of the ldap search?
In general, yes. However, the order in which entries are returned is unspecified; if you're iterating through a subtree you may get a parent entry before a child, while you must delete the child before the parent.
(In higher level languages deleting an item from a collection while navigating through a collection is often bad form. Is that the case here?)
RFC4511 doesn't say anything about this. It's probably implementation-dependent, but OpenLDAP has no issue with it.
Secondly: Can I use the same session handle to delete the records as is used for the search? In the logic above, the session handle is ld, and ld is used for both the search and for the deletion. (I'm expecting I would need to use a different session handle for the logic above to work. Alternatively one could save all the records to be deleted in an array and then after the search loop, the same session handle can be used for all the deletes).
The API has no issue with this, but you may need to do the save anyway, due to ordering concerns.
openldap-technical@openldap.org