Do not crash ldap backend on keyless principals

Operations like "kadmin -q 'addprinc -nokey foo'" or
"kadmin -q 'purgekeys -all foo'" result in principal entries with
no keys present, so krb5_encode_krbsecretkey() would just return
NULL, which then got unconditionally dereferenced in
krb5_add_ber_mem_ldap_mod().

Rename the file-local helper to just encode_krbsecretkey() and
tweak its style slightly, and also return a krb5_error_code
so that krb5_ldap_put_principal() can handle encoding failures.
Make encode_krbsecretkey() create an empty berval entry, which
will delete any existing krbprincipalkey attribute when presented
with LDAP_MOD_REPLACE | LDAP_MOD_BVALUES.

While here, correct the test for an allocation failure, and slightly
restructure the cleanup handler to be shorter and more appropriate
for the usage.

The -purgekeys all feature appears to have never worked with the
LDAP backend since its introduction in release 1.12.

ticket: 8041 (new)
tags: pullup
target_version: 1.13.1
subject: kadmind with ldap backend crashes when putting keyless entries
Regression tests for keyless principals

Confirm that kadmind does not crash when creating/modifying a principal
to have no keys, and confirm that no keys are present after a
purgekeys -all.
Remove some dead code

The secretkey variable is initialized to NULL and compared against
NULL, but never actually set to anything after initialization.

Remove the variable and all code that would have executed if it
was non-NULL.
Add helper for freeing arrays of berval pointers

This eliminates a potential leak of the bv_val members from
krb5_encode_krbsecretkey().