2 * lib/krb5/keytab/file/ktf_get_en.c
4 * Copyright 1990 by the Massachusetts Institute of Technology.
7 * Export of this software from the United States of America may
8 * require a specific license from the United States Government.
9 * It is the responsibility of any person or organization contemplating
10 * export to obtain such a license before exporting.
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of M.I.T. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. M.I.T. makes no representations about the suitability of
20 * this software for any purpose. It is provided "as is" without express
21 * or implied warranty.
24 * This is the get_entry routine for the file based keytab implementation.
25 * It opens the keytab file, and either retrieves the entry or returns
32 krb5_error_code INTERFACE
33 krb5_ktfile_get_entry(context, id, principal, kvno, keytype, entry)
36 krb5_principal principal;
39 krb5_keytab_entry * entry;
41 krb5_keytab_entry cur_entry, new_entry;
42 krb5_error_code kerror = 0;
44 /* Open the keyfile for reading */
45 if (kerror = krb5_ktfileint_openr(context, id))
49 * For efficiency and simplicity, we'll use a while true that
50 * is exited with a break statement.
52 cur_entry.principal = 0;
54 cur_entry.key.contents = 0;
56 if (kerror = krb5_ktfileint_read_entry(context, id, &new_entry))
59 if (krb5_principal_compare(context, principal, new_entry.principal)) {
60 if (kvno == IGNORE_VNO) {
61 if (cur_entry.vno < new_entry.vno) {
62 krb5_kt_free_entry(context, &cur_entry);
63 cur_entry = new_entry;
66 cur_entry = new_entry;
70 krb5_kt_free_entry(context, &new_entry);
73 if (kerror == KRB5_KT_END)
74 kerror = cur_entry.principal ? 0 : KRB5_KT_NOTFOUND;
76 (void) krb5_ktfileint_close(context, id);
77 krb5_kt_free_entry(context, &cur_entry);
80 if ((kerror = krb5_ktfileint_close(context, id)) != 0) {
81 krb5_kt_free_entry(context, &cur_entry);