I am confused about the handling of KRB5_KDB_SALTTYPE_ONLYREALM. You appear to be leaving the type alone and filling in the contents with the realm from the source principal name. But get_salt_from_key will ignore the contents when it sees that salt type, so setting the contents won't have any effect.