[Date Prev][Date Next] [Chronological] [Thread] [Top]

Deleting records while iterating through ldap_result



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