static krb5_error_code krb5_kt_ret_principal(krb5_context context, krb5_storage *sp, krb5_principal *princ) { int i; int ret; krb5_principal p; int16_t len; ALLOC(p, 1); if(p == NULL) { krb5_set_error_string (context, "malloc: out of memory"); return ENOMEM; } ret = krb5_ret_int16(sp, &len); if(ret) { krb5_set_error_string(context, "Failed decoding length of keytab principal"); goto out; } if(krb5_storage_is_flags(sp, KRB5_STORAGE_PRINCIPAL_WRONG_NUM_COMPONENTS)) len--; if (len < 0) { krb5_set_error_string(context, "Keytab principal contains invalid length"); ret = KRB5_KT_END; goto out; } ret = krb5_kt_ret_string(context, sp, &p->realm); if(ret) goto out; p->name.name_string.val = calloc(len, sizeof(*p->name.name_string.val)); if(p->name.name_string.val == NULL) { krb5_set_error_string (context, "malloc: out of memory"); ret = ENOMEM; goto out; } p->name.name_string.len = len; for(i = 0; i < p->name.name_string.len; i++){ ret = krb5_kt_ret_string(context, sp, p->name.name_string.val + i); if(ret) goto out; } if (krb5_storage_is_flags(sp, KRB5_STORAGE_PRINCIPAL_NO_NAME_TYPE)) p->name.name_type = KRB5_NT_UNKNOWN; else { int32_t tmp32; ret = krb5_ret_int32(sp, &tmp32); p->name.name_type = tmp32; if (ret) goto out; } *princ = p; return 0; out: krb5_free_principal(context, p); return ret; }
static krb5_error_code krb5_kt_ret_principal(krb5_context context, struct fkt_data *fkt, krb5_storage *sp, krb5_principal *princ) { size_t i; int ret; krb5_principal p; int16_t len; ALLOC(p, 1); if(p == NULL) return krb5_enomem(context); ret = krb5_ret_int16(sp, &len); if(ret) { krb5_set_error_message(context, ret, N_("Failed decoding length of " "keytab principal in keytab file %s", ""), fkt->filename); goto out; } if(krb5_storage_is_flags(sp, KRB5_STORAGE_PRINCIPAL_WRONG_NUM_COMPONENTS)) len--; if (len < 0) { ret = KRB5_KT_END; krb5_set_error_message(context, ret, N_("Keytab principal contains " "invalid length in keytab %s", ""), fkt->filename); goto out; } ret = krb5_kt_ret_string(context, sp, &p->realm); if(ret) { krb5_set_error_message(context, ret, N_("Can't read realm from keytab: %s", ""), fkt->filename); goto out; } p->name.name_string.val = calloc(len, sizeof(*p->name.name_string.val)); if(p->name.name_string.val == NULL) { ret = krb5_enomem(context); goto out; } p->name.name_string.len = len; for(i = 0; i < p->name.name_string.len; i++){ ret = krb5_kt_ret_string(context, sp, p->name.name_string.val + i); if(ret) { krb5_set_error_message(context, ret, N_("Can't read principal from " "keytab: %s", ""), fkt->filename); goto out; } } if (krb5_storage_is_flags(sp, KRB5_STORAGE_PRINCIPAL_NO_NAME_TYPE)) p->name.name_type = KRB5_NT_UNKNOWN; else { int32_t tmp32; ret = krb5_ret_int32(sp, &tmp32); p->name.name_type = tmp32; if (ret) { krb5_set_error_message(context, ret, N_("Can't read name-type from " "keytab: %s", ""), fkt->filename); goto out; } } *princ = p; return 0; out: krb5_free_principal(context, p); return ret; }