dirmgr: followups to !587, mostly using iterators
As discussed in review comments.
@nickm, setting you as reviewer. In particular, you already caught one misunderstanding I had in the existing code, so please check! I think the new code is clearer but I found the old code complex to read so may have misunderstood it.
Also please do let me know if you like (a) the resulting code (b) that I went and did this at all.