Any callback of kadm5_iter_principals() that wants to call other kadm5 functions (such as kadm5_get_principal()) needs to do so on a different kadm5 handle than the one used for kadm5_iter_principals().