summaryrefslogtreecommitdiffstats
path: root/src/lib/krb5/keytab
diff options
context:
space:
mode:
authorJeffrey Altman <jaltman@secure-endpoints.com>2004-04-08 20:49:27 +0000
committerJeffrey Altman <jaltman@secure-endpoints.com>2004-04-08 20:49:27 +0000
commitbe97fc3c3e50ea361b8a9a91023aa306caa09e9a (patch)
treefbd4037d6ccc368631b027af4effcf997d2e91cd /src/lib/krb5/keytab
parent2b5d25acb0fd9fd81216837e902e303dbb86cb2f (diff)
downloadkrb5-be97fc3c3e50ea361b8a9a91023aa306caa09e9a.tar.gz
krb5-be97fc3c3e50ea361b8a9a91023aa306caa09e9a.tar.xz
krb5-be97fc3c3e50ea361b8a9a91023aa306caa09e9a.zip
ktbase.c - restore the thread safety changes which were accidently
removed in revision 5.29 ticket: new git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16241 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/krb5/keytab')
-rw-r--r--src/lib/krb5/keytab/ChangeLog4
-rw-r--r--src/lib/krb5/keytab/ktbase.c56
2 files changed, 44 insertions, 16 deletions
diff --git a/src/lib/krb5/keytab/ChangeLog b/src/lib/krb5/keytab/ChangeLog
index e9a8301e70..6d84ccd70f 100644
--- a/src/lib/krb5/keytab/ChangeLog
+++ b/src/lib/krb5/keytab/ChangeLog
@@ -1,5 +1,9 @@
2004-04-08 Jeffrey Altman <jaltman@mit.edu>
+ * ktbase.c: Restore the thread safety fixes
+
+2004-04-08 Jeffrey Altman <jaltman@mit.edu>
+
* 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
diff --git a/src/lib/krb5/keytab/ktbase.c b/src/lib/krb5/keytab/ktbase.c
index 1711ba9890..95a0739656 100644
--- a/src/lib/krb5/keytab/ktbase.c
+++ b/src/lib/krb5/keytab/ktbase.c
@@ -28,6 +28,7 @@
*/
#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;
@@ -35,21 +36,23 @@ extern const krb5_kt_ops krb5_kts_ops;
struct krb5_kt_typelist {
const krb5_kt_ops *ops;
- struct krb5_kt_typelist *next;
+ const struct krb5_kt_typelist *next;
};
-static struct krb5_kt_typelist krb5_kt_typelist_wrfile = {
+const static struct krb5_kt_typelist krb5_kt_typelist_wrfile = {
&krb5_ktf_writable_ops,
0
};
-static struct krb5_kt_typelist krb5_kt_typelist_file = {
+const static struct krb5_kt_typelist krb5_kt_typelist_file = {
&krb5_ktf_ops,
&krb5_kt_typelist_wrfile
};
-static struct krb5_kt_typelist krb5_kt_typelist_srvtab = {
+const static struct krb5_kt_typelist krb5_kt_typelist_srvtab = {
&krb5_kts_ops,
&krb5_kt_typelist_file
};
-static struct krb5_kt_typelist *kt_typehead = &krb5_kt_typelist_srvtab;
+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;
/*
@@ -58,19 +61,29 @@ static struct krb5_kt_typelist *kt_typehead = &krb5_kt_typelist_srvtab;
*/
krb5_error_code KRB5_CALLCONV
-krb5_kt_register(krb5_context context, krb5_kt_ops *ops)
+krb5_kt_register(krb5_context context, const krb5_kt_ops *ops)
{
- struct krb5_kt_typelist *t;
- for (t = kt_typehead;t && strcmp(t->ops->prefix,ops->prefix);t = t->next)
+ 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)
;
if (t) {
+ k5_mutex_unlock(&kt_typehead_lock);
return KRB5_KT_TYPE_EXISTS;
}
- if (!(t = (struct krb5_kt_typelist *) malloc(sizeof(*t))))
+ if (!(newt = (struct krb5_kt_typelist *) malloc(sizeof(*t)))) {
+ k5_mutex_unlock(&kt_typehead_lock);
return ENOMEM;
- t->next = kt_typehead;
- t->ops = ops;
- kt_typehead = t;
+ }
+ newt->next = kt_typehead;
+ newt->ops = ops;
+ kt_typehead = newt;
+ k5_mutex_unlock(&kt_typehead_lock);
return 0;
}
@@ -87,10 +100,11 @@ krb5_kt_register(krb5_context context, krb5_kt_ops *ops)
krb5_error_code KRB5_CALLCONV
krb5_kt_resolve (krb5_context context, const char *name, krb5_keytab *ktid)
{
- struct krb5_kt_typelist *tlist;
+ const struct krb5_kt_typelist *tlist;
char *pfx;
unsigned int pfxlen;
const char *cp, *resid;
+ krb5_error_code err;
cp = strchr (name, ':');
if (!cp) {
@@ -98,12 +112,14 @@ 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);
+ return (*krb5_kt_dfl_ops.resolve)(context, name, ktid);
}
-#endif
+#endif
+
resid = name + pfxlen + 1;
pfx = malloc (pfxlen+1);
@@ -115,7 +131,15 @@ krb5_kt_resolve (krb5_context context, const char *name, krb5_keytab *ktid)
*ktid = (krb5_keytab) 0;
- for (tlist = kt_typehead; tlist; tlist = tlist->next) {
+ 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) {
if (strcmp (tlist->ops->prefix, pfx) == 0) {
free(pfx);
return (*tlist->ops->resolve)(context, resid, ktid);