lp1 = prev->next;
}
lp1->entry = lp->entry;
- } else if (lp1->entry->vno < lp->entry->vno)
- /* Check if lp->entry is newer kvno; if so, update */
- lp1->entry = lp->entry;
+ } else {
+ /* This heuristic should be roughly the same as in the
+ keytab-reading code in libkrb5. */
+ int offset = 0;
+ if (lp1->entry->vno > 240 || lp->entry->vno > 240) {
+ offset = 128;
+ }
+#define M(X) (((X) + offset) % 256)
+ if (M(lp1->entry->vno) < M(lp->entry->vno))
+ /* Check if lp->entry is newer kvno; if so, update */
+ lp1->entry = lp->entry;
+ }
}
umask(0077); /*Changing umask for all of ktutil is OK
* We don't ever write out anything that should use
+2002-03-06 Ken Raeburn <raeburn@mit.edu>
+
+ * ktf_g_ent.c (krb5_ktfile_get_entry): For non-zero kvno, match
+ only low 8 bits. For zero kvno, if any kvno in the keytab is over
+ 240, assume we're dealing with numbers 128 through (127+256)
+ instead. This allows for wrapping at 256 while retaining a small
+ set of consecutively numbered prior keys in the keytab.
+
2001-11-19 Tom Yu <tlyu@mit.edu>
* ktf_g_ent.c (krb5_ktfile_get_entry): Coerce enctype for now to
krb5_error_code kerror = 0;
int found_wrong_kvno = 0;
krb5_boolean similar;
+ int kvno_offset = 0;
/* Open the keyfile for reading */
if ((kerror = krb5_ktfileint_openr(context, id)))
/* if this is the first match, or if the new vno is
bigger, free the current and keep the new. Otherwise,
free the new. */
-
+ /* A 1.2.x keytab contains only the low 8 bits of the key
+ version number. Since it can be much bigger, and thus
+ the 8-bit value can wrap, we need some heuristics to
+ figure out the "highest" numbered key if some numbers
+ close to 255 and some near 0 are used.
+
+ The heuristic here:
+
+ If we have any keys with versions over 240, then assume
+ that all version numbers 0-127 refer to 256+N instead.
+ Not perfect, but maybe good enough? */
+
+#define M(VNO) (((VNO) - kvno_offset + 256) % 256)
+
+ if (new_entry.vno > 240)
+ kvno_offset = 128;
if (! cur_entry.principal ||
- (new_entry.vno > cur_entry.vno)) {
+ M(new_entry.vno) > M(cur_entry.vno)) {
krb5_kt_free_entry(context, &cur_entry);
cur_entry = new_entry;
} else {
be one?), keep the new, and break out. Otherwise, remember
that we were here so we can return the right error, and
free the new */
+ /* Yuck. The krb5-1.2.x keytab format only stores one byte
+ for the kvno, so we're toast if the kvno requested is
+ higher than that. Short-term workaround: only compare
+ the low 8 bits. */
- if (new_entry.vno == kvno) {
+ if (new_entry.vno == (kvno & 0xff)) {
krb5_kt_free_entry(context, &cur_entry);
cur_entry = new_entry;
break;