From 2b5d25acb0fd9fd81216837e902e303dbb86cb2f Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Thu, 8 Apr 2004 07:52:27 +0000 Subject: [PATCH] On Windows, a single letter followed by colon is used to identify a drive. Therefore, do not assume that finding a colon in a string indicates that we have found a keytab prefix label unless the length of the potential prefix is not equal to one. ticket: new git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16240 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/keytab/ChangeLog | 7 +++++ src/lib/krb5/keytab/ktbase.c | 56 +++++++++++++---------------------- 2 files changed, 27 insertions(+), 36 deletions(-) diff --git a/src/lib/krb5/keytab/ChangeLog b/src/lib/krb5/keytab/ChangeLog index 20bb4c715..e9a8301e7 100644 --- a/src/lib/krb5/keytab/ChangeLog +++ b/src/lib/krb5/keytab/ChangeLog @@ -1,3 +1,10 @@ +2004-04-08 Jeffrey Altman + + * ktbase.c: On Windows, if we see a colon do not assume it means + we found a prefix string unless the length of the prefix is + not equal to one. If it is one, it means we found a drive letter + and not a prefix. + 2004-03-05 Ken Raeburn * ktbase.c: Include k5-thread.h. diff --git a/src/lib/krb5/keytab/ktbase.c b/src/lib/krb5/keytab/ktbase.c index c415361bb..1711ba989 100644 --- a/src/lib/krb5/keytab/ktbase.c +++ b/src/lib/krb5/keytab/ktbase.c @@ -28,7 +28,6 @@ */ #include "k5-int.h" -#include "k5-thread.h" extern const krb5_kt_ops krb5_ktf_ops; extern const krb5_kt_ops krb5_ktf_writable_ops; @@ -36,23 +35,21 @@ extern const krb5_kt_ops krb5_kts_ops; struct krb5_kt_typelist { const krb5_kt_ops *ops; - const struct krb5_kt_typelist *next; + struct krb5_kt_typelist *next; }; -const static struct krb5_kt_typelist krb5_kt_typelist_wrfile = { +static struct krb5_kt_typelist krb5_kt_typelist_wrfile = { &krb5_ktf_writable_ops, 0 }; -const static struct krb5_kt_typelist krb5_kt_typelist_file = { +static struct krb5_kt_typelist krb5_kt_typelist_file = { &krb5_ktf_ops, &krb5_kt_typelist_wrfile }; -const static struct krb5_kt_typelist krb5_kt_typelist_srvtab = { +static struct krb5_kt_typelist krb5_kt_typelist_srvtab = { &krb5_kts_ops, &krb5_kt_typelist_file }; -static const struct krb5_kt_typelist *kt_typehead = &krb5_kt_typelist_srvtab; -/* Lock for protecting the type list. */ -static k5_mutex_t kt_typehead_lock = K5_MUTEX_INITIALIZER; +static struct krb5_kt_typelist *kt_typehead = &krb5_kt_typelist_srvtab; /* @@ -61,29 +58,19 @@ static k5_mutex_t kt_typehead_lock = K5_MUTEX_INITIALIZER; */ krb5_error_code KRB5_CALLCONV -krb5_kt_register(krb5_context context, const krb5_kt_ops *ops) +krb5_kt_register(krb5_context context, krb5_kt_ops *ops) { - const struct krb5_kt_typelist *t; - struct krb5_kt_typelist *newt; - krb5_error_code err; - - err = k5_mutex_lock(&kt_typehead_lock); - if (err) - return err; - for (t = kt_typehead; t && strcmp(t->ops->prefix,ops->prefix);t = t->next) + struct krb5_kt_typelist *t; + for (t = kt_typehead;t && strcmp(t->ops->prefix,ops->prefix);t = t->next) ; if (t) { - k5_mutex_unlock(&kt_typehead_lock); return KRB5_KT_TYPE_EXISTS; } - if (!(newt = (struct krb5_kt_typelist *) malloc(sizeof(*t)))) { - k5_mutex_unlock(&kt_typehead_lock); + if (!(t = (struct krb5_kt_typelist *) malloc(sizeof(*t)))) return ENOMEM; - } - newt->next = kt_typehead; - newt->ops = ops; - kt_typehead = newt; - k5_mutex_unlock(&kt_typehead_lock); + t->next = kt_typehead; + t->ops = ops; + kt_typehead = t; return 0; } @@ -100,11 +87,10 @@ krb5_kt_register(krb5_context context, const krb5_kt_ops *ops) krb5_error_code KRB5_CALLCONV krb5_kt_resolve (krb5_context context, const char *name, krb5_keytab *ktid) { - const struct krb5_kt_typelist *tlist; + struct krb5_kt_typelist *tlist; char *pfx; unsigned int pfxlen; const char *cp, *resid; - krb5_error_code err; cp = strchr (name, ':'); if (!cp) { @@ -112,6 +98,12 @@ krb5_kt_resolve (krb5_context context, const char *name, krb5_keytab *ktid) } pfxlen = cp - name; +#if defined(_WIN32) + if ( pfxlen == 1 ) { + /* We found a drive letter not a prefix */ + return (*krb5_kt_dfl_ops.resolve)(context, name, ktid); + } +#endif resid = name + pfxlen + 1; pfx = malloc (pfxlen+1); @@ -123,15 +115,7 @@ krb5_kt_resolve (krb5_context context, const char *name, krb5_keytab *ktid) *ktid = (krb5_keytab) 0; - err = k5_mutex_lock(&kt_typehead_lock); - if (err) - return err; - tlist = kt_typehead; - /* Don't need to hold the lock, since entries are never modified - or removed once they're in the list. Just need to protect - access to the list head variable itself. */ - k5_mutex_unlock(&kt_typehead_lock); - for (; tlist; tlist = tlist->next) { + for (tlist = kt_typehead; tlist; tlist = tlist->next) { if (strcmp (tlist->ops->prefix, pfx) == 0) { free(pfx); return (*tlist->ops->resolve)(context, resid, ktid); -- 2.26.2