Return the most recent key (with the greatest kvno) instead of the
authorTheodore Tso <tytso@mit.edu>
Thu, 29 Sep 1994 18:40:00 +0000 (18:40 +0000)
committerTheodore Tso <tytso@mit.edu>
Thu, 29 Sep 1994 18:40:00 +0000 (18:40 +0000)
first key found in the keytab file.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@4375 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/keytab/file/ChangeLog
src/lib/krb5/keytab/file/ktf_get_en.c

index d4e6a7b2aab3cf45c4ce6e1f33bad86291f7ada4..4c345eaa2cb8ba747e77d164e12bfe3fe9678621 100644 (file)
@@ -1,3 +1,9 @@
+Wed Sep 28 21:14:49 1994  Theodore Y. Ts'o  (tytso@dcl)
+
+       * ktf_get_en.c (krb5_ktfile_get_entry): Modified to return the
+               most recent key (with the greatest kvno), instead of the
+               first.
+
 Thu Sep 22 21:51:53 1994  Theodore Y. Ts'o  (tytso@dcl)
     
        * ktf_get_en.c (krb5_ktfile_get_entry):
index 59e20aed0cafc52ecf52cbd414f238896c3f22e5..2660a455ff811abe2846df1a8010c4e46f2241a2 100644 (file)
@@ -42,7 +42,7 @@ OLDDECLARG(krb5_principal, principal)
 OLDDECLARG(krb5_kvno, kvno)
 OLDDECLARG(krb5_keytab_entry *, entry)
 {
-    krb5_keytab_entry cur_entry;
+    krb5_keytab_entry cur_entry, new_entry;
     krb5_error_code kerror = 0;
 
     /* Open the keyfile for reading */
@@ -53,25 +53,37 @@ OLDDECLARG(krb5_keytab_entry *, entry)
      * For efficiency and simplicity, we'll use a while true that 
      * is exited with a break statement.
      */
+    cur_entry.principal = 0;
     while (TRUE) {
-       if (kerror = krb5_ktfileint_read_entry(id, &cur_entry))
+       if (kerror = krb5_ktfileint_read_entry(id, &new_entry))
            break;
 
-       if (((kvno == IGNORE_VNO) || (kvno == cur_entry.vno)) &&
-           krb5_principal_compare(principal, cur_entry.principal)) {
-           /* found a match */
-           break;
+       if (krb5_principal_compare(principal, cur_entry.principal)) {
+               if (kvno == IGNORE_VNO) {
+                       if (cur_entry.vno < new_entry.vno) {
+                               krb5_kt_free_entry(&cur_entry);
+                               cur_entry = new_entry;
+                       }
+               } else {
+                       cur_entry = new_entry;
+                       break;
+               }
+       } else {
+               krb5_kt_free_entry(&new_entry);
        }
-       krb5_kt_free_entry(&cur_entry);
     }
     if (kerror) {
        if (kerror == KRB5_KT_END)
            kerror = KRB5_KT_NOTFOUND;
        (void) krb5_ktfileint_close(id);
+       if (cur_entry.principal)
+               krb5_kt_free_entry(&cur_entry);
        return kerror;
     }
     if ((kerror = krb5_ktfileint_close(id)) != 0) {
        krb5_kt_free_entry(&cur_entry);
+       if (cur_entry.principal)
+               krb5_kt_free_entry(&cur_entry);
        return kerror;
     }
     *entry = cur_entry;