Blame SOURCES/nfs-utils-1.3.0-rpcgssd-multithread.patch

851484
diff --git a/aclocal/kerberos5.m4 b/aclocal/kerberos5.m4
851484
index 0bf35d3..8a0f3e4 100644
851484
--- a/aclocal/kerberos5.m4
851484
+++ b/aclocal/kerberos5.m4
851484
@@ -43,15 +43,6 @@ AC_DEFUN([AC_KERBEROS_V5],[
851484
                    -f $dir/lib/libgssapi_krb5.so \) ; then
851484
          AC_DEFINE(HAVE_KRB5, 1, [Define this if you have MIT Kerberos libraries])
851484
          KRBDIR="$dir"
851484
-  dnl If we are using MIT K5 1.3.1 and before, we *MUST* use the
851484
-  dnl private function (gss_krb5_ccache_name) to get correct
851484
-  dnl behavior of changing the ccache used by gssapi.
851484
-  dnl Starting in 1.3.2, we *DO NOT* want to use
851484
-  dnl gss_krb5_ccache_name, instead we want to set KRB5CCNAME
851484
-  dnl to get gssapi to use a different ccache
851484
-         if test $K5VERS -le 131; then
851484
-           AC_DEFINE(USE_GSS_KRB5_CCACHE_NAME, 1, [Define this if the private function, gss_krb5_cache_name, must be used to tell the Kerberos library which credentials cache to use. Otherwise, this is done by setting the KRB5CCNAME environment variable])
851484
-         fi
851484
          gssapi_lib=gssapi_krb5
851484
          break
851484
       dnl The following ugly hack brought on by the split installation
851484
@@ -92,8 +83,6 @@ AC_DEFUN([AC_KERBEROS_V5],[
851484
     AC_DEFINE(HAVE_LUCID_CONTEXT_SUPPORT, 1, [Define this if the Kerberos GSS library supports gss_krb5_export_lucid_sec_context]), ,$KRBLIBS)
851484
   AC_CHECK_LIB($gssapi_lib, gss_krb5_set_allowable_enctypes,
851484
     AC_DEFINE(HAVE_SET_ALLOWABLE_ENCTYPES, 1, [Define this if the Kerberos GSS library supports gss_krb5_set_allowable_enctypes]), ,$KRBLIBS)
851484
-  AC_CHECK_LIB($gssapi_lib, gss_krb5_ccache_name,
851484
-    AC_DEFINE(HAVE_GSS_KRB5_CCACHE_NAME, 1, [Define this if the Kerberos GSS library supports gss_krb5_ccache_name]), ,$KRBLIBS)
851484
   AC_CHECK_LIB($gssapi_lib, gss_krb5_free_lucid_sec_context,
851484
     AC_DEFINE(HAVE_GSS_KRB5_FREE_LUCID_SEC_CONTEXT, 1, [Define this if the Kerberos GSS library supports gss_krb5_free_lucid_sec_context]), ,$KRBLIBS)
851484
 
851484
diff --git a/aclocal/libpthread.m4 b/aclocal/libpthread.m4
851484
new file mode 100644
851484
index 0000000..e87d2a0
851484
--- /dev/null
851484
+++ b/aclocal/libpthread.m4
851484
@@ -0,0 +1,13 @@
851484
+dnl Checks for pthreads library and headers
851484
+dnl
851484
+AC_DEFUN([AC_LIBPTHREAD], [
851484
+
851484
+    dnl Check for library, but do not add -lpthreads to LIBS
851484
+    AC_CHECK_LIB([pthread], [pthread_create], [LIBPTHREAD=-lpthread],
851484
+                 [AC_MSG_ERROR([libpthread not found.])])
851484
+  AC_SUBST(LIBPTHREAD)
851484
+
851484
+  AC_CHECK_HEADERS([pthread.h], ,
851484
+                   [AC_MSG_ERROR([libpthread headers not found.])])
851484
+
851484
+])dnl
851484
diff --git a/configure.ac b/configure.ac
851484
index 4ee4db5..56f7f3e 100644
851484
--- a/configure.ac
851484
+++ b/configure.ac
851484
@@ -355,6 +355,9 @@ if test "$enable_gss" = yes; then
851484
   dnl Invoked after AC_KERBEROS_V5; AC_LIBRPCSECGSS needs to have KRBLIBS set
851484
   AC_LIBRPCSECGSS
851484
 
851484
+  dnl Check for pthreads
851484
+  AC_LIBPTHREAD
851484
+
851484
   dnl librpcsecgss already has a dependency on libgssapi,
851484
   dnl but we need to make sure we get the right version
851484
   if test "$enable_gss" = yes; then
851484
diff --git a/utils/gssd/Makefile.am b/utils/gssd/Makefile.am
851484
index fd488a1..f387c16 100644
851484
--- a/utils/gssd/Makefile.am
851484
+++ b/utils/gssd/Makefile.am
851484
@@ -42,7 +42,8 @@ gssd_LDADD = \
851484
 	$(RPCSECGSS_LIBS) \
851484
 	$(KRBLIBS) \
851484
 	$(GSSAPI_LIBS) \
851484
-	$(LIBTIRPC)
851484
+	$(LIBTIRPC) \
851484
+	$(LIBPTHREAD)
851484
 
851484
 gssd_LDFLAGS = \
851484
 	$(KRBLDFLAGS)
851484
diff --git a/utils/gssd/gssd.c b/utils/gssd/gssd.c
851484
index 7ba27b1..43fccaf 100644
851484
--- a/utils/gssd/gssd.c
851484
+++ b/utils/gssd/gssd.c
851484
@@ -87,7 +87,9 @@ unsigned int  rpc_timeout = 5;
851484
 char *preferred_realm = NULL;
851484
 /* Avoid DNS reverse lookups on server names */
851484
 static bool avoid_dns = true;
851484
-
851484
+int thread_started = false;
851484
+pthread_mutex_t pmutex = PTHREAD_MUTEX_INITIALIZER;
851484
+pthread_cond_t pcond = PTHREAD_COND_INITIALIZER;
851484
 
851484
 TAILQ_HEAD(topdir_list_head, topdir) topdir_list;
851484
 
851484
@@ -361,20 +363,91 @@ gssd_destroy_client(struct clnt_info *clp)
851484
 
851484
 static void gssd_scan(void);
851484
 
851484
+static int
851484
+start_upcall_thread(void (*func)(struct clnt_upcall_info *), void *info)
851484
+{
851484
+	pthread_attr_t attr;
851484
+	pthread_t th;
851484
+	int ret;
851484
+
851484
+	ret = pthread_attr_init(&attr);
851484
+	if (ret != 0) {
851484
+		printerr(0, "ERROR: failed to init pthread attr: ret %d: %s\n",
851484
+			 ret, strerror(errno));
851484
+		return ret;
851484
+	}
851484
+	ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
851484
+	if (ret != 0) {
851484
+		printerr(0, "ERROR: failed to create pthread attr: ret %d: "
851484
+			 "%s\n", ret, strerror(errno));
851484
+		return ret;
851484
+	}
851484
+
851484
+	ret = pthread_create(&th, &attr, (void *)func, (void *)info);
851484
+	if (ret != 0)
851484
+		printerr(0, "ERROR: pthread_create failed: ret %d: %s\n",
851484
+			 ret, strerror(errno));
851484
+	return ret;
851484
+}
851484
+
851484
+static struct clnt_upcall_info *alloc_upcall_info(struct clnt_info *clp)
851484
+{
851484
+	struct clnt_upcall_info *info;
851484
+
851484
+	info = malloc(sizeof(struct clnt_upcall_info));
851484
+	if (info == NULL)
851484
+		return NULL;
851484
+	info->clp = clp;
851484
+
851484
+	return info;
851484
+}
851484
+
851484
+/* For each upcall read the upcall info into the buffer, then create a
851484
+ * thread in a detached state so that resources are released back into
851484
+ * the system without the need for a join.
851484
+ */
851484
 static void
851484
 gssd_clnt_gssd_cb(int UNUSED(fd), short UNUSED(which), void *data)
851484
 {
851484
 	struct clnt_info *clp = data;
851484
+	struct clnt_upcall_info *info;
851484
+
851484
+	info = alloc_upcall_info(clp);
851484
+	if (info == NULL)
851484
+		return;
851484
+
851484
+	info->lbuflen = read(clp->gssd_fd, info->lbuf, sizeof(info->lbuf));
851484
+	if (info->lbuflen <= 0 || info->lbuf[info->lbuflen-1] != '\n') {
851484
+		printerr(0, "WARNING: %s: failed reading request\n", __func__);
851484
+		free(info);
851484
+		return;
851484
+	}
851484
+	info->lbuf[info->lbuflen-1] = 0;
851484
 
851484
-	handle_gssd_upcall(clp);
851484
+	if (start_upcall_thread(handle_gssd_upcall, info))
851484
+		free(info);
851484
 }
851484
 
851484
 static void
851484
 gssd_clnt_krb5_cb(int UNUSED(fd), short UNUSED(which), void *data)
851484
 {
851484
 	struct clnt_info *clp = data;
851484
+	struct clnt_upcall_info *info;
851484
+
851484
+	info = alloc_upcall_info(clp);
851484
+	if (info == NULL)
851484
+		return;
851484
+
851484
+	if (read(clp->krb5_fd, &info->uid,
851484
+			sizeof(info->uid)) < (ssize_t)sizeof(info->uid)) {
851484
+		printerr(0, "WARNING: %s: failed reading uid from krb5 "
851484
+			 "upcall pipe: %s\n", __func__, strerror(errno));
851484
+		free(info);
851484
+		return;
851484
+	}
851484
 
851484
-	handle_krb5_upcall(clp);
851484
+	if (start_upcall_thread(handle_krb5_upcall, info))
851484
+		free(info);
851484
 }
851484
 
851484
 static struct clnt_info *
851484
diff --git a/utils/gssd/gssd.h b/utils/gssd/gssd.h
851484
index c6937c5..f4f5975 100644
851484
--- a/utils/gssd/gssd.h
851484
+++ b/utils/gssd/gssd.h
851484
@@ -36,6 +36,7 @@
851484
 #include <gssapi/gssapi.h>
851484
 #include <event.h>
851484
 #include <stdbool.h>
851484
+#include <pthread.h>
851484
 
851484
 #ifndef GSSD_PIPEFS_DIR
851484
 #define GSSD_PIPEFS_DIR		"/var/lib/nfs/rpc_pipefs"
851484
@@ -48,7 +49,7 @@
851484
 #define GSSD_DEFAULT_MACHINE_CRED_SUFFIX	"machine"
851484
 #define GSSD_DEFAULT_KEYTAB_FILE		"/etc/krb5.keytab"
851484
 #define GSSD_SERVICE_NAME			"nfs"
851484
-
851484
+#define RPC_CHAN_BUF_SIZE			32768
851484
 /*
851484
  * The gss mechanisms that we can handle
851484
  */
851484
@@ -61,6 +62,10 @@ extern int			root_uses_machine_creds;
851484
 extern unsigned int 		context_timeout;
851484
 extern unsigned int rpc_timeout;
851484
 extern char			*preferred_realm;
851484
+extern pthread_mutex_t ple_lock;
851484
+extern pthread_cond_t pcond;
851484
+extern pthread_mutex_t pmutex;
851484
+extern int thread_started;
851484
 
851484
 struct clnt_info {
851484
 	TAILQ_ENTRY(clnt_info)	list;
851484
@@ -80,8 +85,15 @@ struct clnt_info {
851484
 	struct			sockaddr_storage addr;
851484
 };
851484
 
851484
-void handle_krb5_upcall(struct clnt_info *clp);
851484
-void handle_gssd_upcall(struct clnt_info *clp);
851484
+struct clnt_upcall_info {
851484
+	struct clnt_info 	*clp;
851484
+	char			lbuf[RPC_CHAN_BUF_SIZE];
851484
+	int			lbuflen;
851484
+	uid_t			uid;
851484
+};
851484
+
851484
+void handle_krb5_upcall(struct clnt_upcall_info *clp);
851484
+void handle_gssd_upcall(struct clnt_upcall_info *clp);
851484
 
851484
 
851484
 #endif /* _RPC_GSSD_H_ */
851484
diff --git a/utils/gssd/gssd_proc.c b/utils/gssd/gssd_proc.c
851484
index 69c6a34..fda7595 100644
851484
--- a/utils/gssd/gssd_proc.c
851484
+++ b/utils/gssd/gssd_proc.c
851484
@@ -69,6 +69,7 @@
851484
 #include <netdb.h>
851484
 #include <sys/types.h>
851484
 #include <sys/wait.h>
851484
+#include <syscall.h>
851484
 
851484
 #include "gssd.h"
851484
 #include "err_util.h"
851484
@@ -442,7 +443,7 @@ change_identity(uid_t uid)
851484
 	struct passwd	*pw;
851484
 
851484
 	/* drop list of supplimentary groups first */
851484
-	if (setgroups(0, NULL) != 0) {
851484
+	if (syscall(SYS_setgroups, 0, 0) != 0) {
851484
 		printerr(0, "WARNING: unable to drop supplimentary groups!");
851484
 		return errno;
851484
 	}
851484
@@ -459,20 +460,18 @@ change_identity(uid_t uid)
851484
 		}
851484
 	}
851484
 
851484
-	/*
851484
-	 * Switch the GIDs. Note that we leave the saved-set-gid alone in an
851484
-	 * attempt to prevent attacks via ptrace()
851484
+	/* Switch the UIDs and GIDs. */
851484
+	/* For the threaded version we have to set uid,gid per thread instead
851484
+	 * of per process. glibc setresuid() when called from a thread, it'll
851484
+	 * send a signal to all other threads to synchronize the uid in all
851484
+	 * other threads. To bypass this, we have to call syscall() directly.
851484
 	 */
851484
-	if (setresgid(pw->pw_gid, pw->pw_gid, -1) != 0) {
851484
+	if (syscall(SYS_setresgid, pw->pw_gid, pw->pw_gid, pw->pw_gid) != 0) {
851484
 		printerr(0, "WARNING: failed to set gid to %u!\n", pw->pw_gid);
851484
 		return errno;
851484
 	}
851484
 
851484
-	/*
851484
-	 * Switch UIDs, but leave saved-set-uid alone to prevent ptrace() by
851484
-	 * other processes running with this uid.
851484
-	 */
851484
-	if (setresuid(uid, uid, -1) != 0) {
851484
+	if (syscall(SYS_setresuid, uid, uid, uid) != 0) {
851484
 		printerr(0, "WARNING: Failed to setuid for user with uid %u\n",
851484
 				uid);
851484
 		return errno;
851484
@@ -554,7 +553,15 @@ krb5_use_machine_creds(struct clnt_info *clp, uid_t uid, char *tgtname,
851484
 			goto out;
851484
 		}
851484
 		for (ccname = credlist; ccname && *ccname; ccname++) {
851484
-			gssd_setup_krb5_machine_gss_ccache(*ccname);
851484
+			u_int min_stat;
851484
+
851484
+			if (gss_krb5_ccache_name(&min_stat, *ccname, NULL) !=
851484
+					GSS_S_COMPLETE) {
851484
+				printerr(1, "WARNING: gss_krb5_ccache_name "
851484
+					 "with name '%s' failed (%s)\n",
851484
+					 *ccname, error_message(min_stat));
851484
+				continue;
851484
+			}
851484
 			if ((create_auth_rpc_client(clp, tgtname, rpc_clnt,
851484
 						&auth, uid,
851484
 						AUTHTYPE_KRB5,
851484
@@ -602,7 +609,6 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
851484
 	gss_buffer_desc		token;
851484
 	int			err, downcall_err = -EACCES;
851484
 	OM_uint32		maj_stat, min_stat, lifetime_rec;
851484
-	pid_t			pid, childpid = -1;
851484
 	gss_name_t		gacceptor = GSS_C_NO_NAME;
851484
 	gss_OID			mech;
851484
 	gss_buffer_desc		acceptor  = {0};
851484
@@ -635,36 +641,6 @@ process_krb5_upcall(struct clnt_info *clp, uid_t uid, int fd, char *tgtname,
851484
 	if (uid != 0 || (uid == 0 && root_uses_machine_creds == 0 &&
851484
 				service == NULL)) {
851484
 
851484
-		/* already running as uid 0 */
851484
-		if (uid == 0)
851484
-			goto no_fork;
851484
-
851484
-		pid = fork();
851484
-		switch(pid) {
851484
-		case 0:
851484
-			/* Child: fall through to rest of function */
851484
-			childpid = getpid();
851484
-			unsetenv("KRB5CCNAME");
851484
-			printerr(2, "CHILD forked pid %d \n", childpid);
851484
-			break;
851484
-		case -1:
851484
-			/* fork() failed! */
851484
-			printerr(0, "WARNING: unable to fork() to handle"
851484
-				"upcall: %s\n", strerror(errno));
851484
-			return;
851484
-		default:
851484
-			/* Parent: just wait on child to exit and return */
851484
-			do {
851484
-				pid = wait(&err;;
851484
-			} while(pid == -1 && errno != -ECHILD);
851484
-
851484
-			if (WIFSIGNALED(err))
851484
-				printerr(0, "WARNING: forked child was killed"
851484
-					 "with signal %d\n", WTERMSIG(err));
851484
-			return;
851484
-		}
851484
-no_fork:
851484
-
851484
 		auth = krb5_not_machine_creds(clp, uid, tgtname, &downcall_err,
851484
 						&err, &rpc_clnt);
851484
 		if (err)
851484
@@ -730,11 +706,7 @@ out:
851484
 	if (rpc_clnt)
851484
 		clnt_destroy(rpc_clnt);
851484
 
851484
-	pid = getpid();
851484
-	if (pid == childpid)
851484
-		exit(0);
851484
-	else
851484
-		return;
851484
+	return;
851484
 
851484
 out_return_error:
851484
 	do_error_downcall(fd, uid, downcall_err);
851484
@@ -742,27 +714,21 @@ out_return_error:
851484
 }
851484
 
851484
 void
851484
-handle_krb5_upcall(struct clnt_info *clp)
851484
+handle_krb5_upcall(struct clnt_upcall_info *info)
851484
 {
851484
-	uid_t			uid;
851484
-
851484
-	if (read(clp->krb5_fd, &uid, sizeof(uid)) < (ssize_t)sizeof(uid)) {
851484
-		printerr(0, "WARNING: failed reading uid from krb5 "
851484
-			    "upcall pipe: %s\n", strerror(errno));
851484
-		return;
851484
-	}
851484
+	struct clnt_info *clp = info->clp;
851484
 
851484
-	printerr(2, "\n%s: uid %d (%s)\n", __func__, uid, clp->relpath);
851484
+	printerr(2, "\n%s: uid %d (%s)\n", __func__, info->uid, clp->relpath);
851484
 
851484
-	process_krb5_upcall(clp, uid, clp->krb5_fd, NULL, NULL);
851484
+	process_krb5_upcall(clp, info->uid, clp->krb5_fd, NULL, NULL);
851484
+	free(info);
851484
 }
851484
 
851484
 void
851484
-handle_gssd_upcall(struct clnt_info *clp)
851484
+handle_gssd_upcall(struct clnt_upcall_info *info)
851484
 {
851484
+	struct clnt_info	*clp = info->clp;
851484
 	uid_t			uid;
851484
-	char			*lbuf = NULL;
851484
-	int			lbuflen = 0;
851484
 	char			*p;
851484
 	char			*mech = NULL;
851484
 	char			*uidstr = NULL;
851484
@@ -770,15 +736,9 @@ handle_gssd_upcall(struct clnt_info *clp)
851484
 	char			*service = NULL;
851484
 	char			*enctypes = NULL;
851484
 
851484
-	if (readline(clp->gssd_fd, &lbuf, &lbuflen) != 1) {
851484
-		printerr(0, "WARNING: handle_gssd_upcall: "
851484
-			    "failed reading request\n");
851484
-		return;
851484
-	}
851484
-
851484
-	printerr(2, "\n%s: '%s' (%s)\n", __func__, lbuf, clp->relpath);
851484
+	printerr(2, "\n%s: '%s' (%s)\n", __func__, info->lbuf, clp->relpath);
851484
 
851484
-	for (p = strtok(lbuf, " "); p; p = strtok(NULL, " ")) {
851484
+	for (p = strtok(info->lbuf, " "); p; p = strtok(NULL, " ")) {
851484
 		if (!strncmp(p, "mech=", strlen("mech=")))
851484
 			mech = p + strlen("mech=");
851484
 		else if (!strncmp(p, "uid=", strlen("uid=")))
851484
@@ -794,8 +754,8 @@ handle_gssd_upcall(struct clnt_info *clp)
851484
 	if (!mech || strlen(mech) < 1) {
851484
 		printerr(0, "WARNING: handle_gssd_upcall: "
851484
 			    "failed to find gss mechanism name "
851484
-			    "in upcall string '%s'\n", lbuf);
851484
-		return;
851484
+			    "in upcall string '%s'\n", info->lbuf);
851484
+		goto out;
851484
 	}
851484
 
851484
 	if (uidstr) {
851484
@@ -807,21 +767,21 @@ handle_gssd_upcall(struct clnt_info *clp)
851484
 	if (!uidstr) {
851484
 		printerr(0, "WARNING: handle_gssd_upcall: "
851484
 			    "failed to find uid "
851484
-			    "in upcall string '%s'\n", lbuf);
851484
-		return;
851484
+			    "in upcall string '%s'\n", info->lbuf);
851484
+		goto out;
851484
 	}
851484
 
851484
 	if (enctypes && parse_enctypes(enctypes) != 0) {
851484
 		printerr(0, "WARNING: handle_gssd_upcall: "
851484
 			 "parsing encryption types failed: errno %d\n", errno);
851484
-		return;
851484
+		goto out;
851484
 	}
851484
 
851484
 	if (target && strlen(target) < 1) {
851484
 		printerr(0, "WARNING: handle_gssd_upcall: "
851484
 			 "failed to parse target name "
851484
-			 "in upcall string '%s'\n", lbuf);
851484
-		return;
851484
+			 "in upcall string '%s'\n", info->lbuf);
851484
+		goto out;
851484
 	}
851484
 
851484
 	/*
851484
@@ -835,8 +795,8 @@ handle_gssd_upcall(struct clnt_info *clp)
851484
 	if (service && strlen(service) < 1) {
851484
 		printerr(0, "WARNING: handle_gssd_upcall: "
851484
 			 "failed to parse service type "
851484
-			 "in upcall string '%s'\n", lbuf);
851484
-		return;
851484
+			 "in upcall string '%s'\n", info->lbuf);
851484
+		goto out;
851484
 	}
851484
 
851484
 	if (strcmp(mech, "krb5") == 0 && clp->servername)
851484
@@ -847,5 +807,8 @@ handle_gssd_upcall(struct clnt_info *clp)
851484
 				 "received unknown gss mech '%s'\n", mech);
851484
 		do_error_downcall(clp->gssd_fd, uid, -EACCES);
851484
 	}
851484
+out:
851484
+	free(info);
851484
+	return;
851484
 }
851484
 
851484
diff --git a/utils/gssd/krb5_util.c b/utils/gssd/krb5_util.c
851484
index 3849b6a..bc29787 100644
851484
--- a/utils/gssd/krb5_util.c
851484
+++ b/utils/gssd/krb5_util.c
851484
@@ -128,6 +128,7 @@
851484
 
851484
 /* Global list of principals/cache file names for machine credentials */
851484
 struct gssd_k5_kt_princ *gssd_k5_kt_princ_list = NULL;
851484
+pthread_mutex_t ple_lock = PTHREAD_MUTEX_INITIALIZER;
851484
 
851484
 #ifdef HAVE_SET_ALLOWABLE_ENCTYPES
851484
 int limit_to_legacy_enctypes = 0;
851484
@@ -467,37 +468,6 @@ gssd_get_single_krb5_cred(krb5_context context,
851484
 }
851484
 
851484
 /*
851484
- * Depending on the version of Kerberos, we either need to use
851484
- * a private function, or simply set the environment variable.
851484
- */
851484
-static void
851484
-gssd_set_krb5_ccache_name(char *ccname)
851484
-{
851484
-#ifdef USE_GSS_KRB5_CCACHE_NAME
851484
-	u_int	maj_stat, min_stat;
851484
-
851484
-	printerr(3, "using gss_krb5_ccache_name to select krb5 ccache %s\n",
851484
-		 ccname);
851484
-	maj_stat = gss_krb5_ccache_name(&min_stat, ccname, NULL);
851484
-	if (maj_stat != GSS_S_COMPLETE) {
851484
-		printerr(0, "WARNING: gss_krb5_ccache_name with "
851484
-			"name '%s' failed (%s)\n",
851484
-			ccname, error_message(min_stat));
851484
-	}
851484
-#else
851484
-	/*
851484
-	 * Set the KRB5CCNAME environment variable to tell the krb5 code
851484
-	 * which credentials cache to use.  (Instead of using the private
851484
-	 * function above for which there is no generic gssapi
851484
-	 * equivalent.)
851484
-	 */
851484
-	printerr(3, "using environment variable to select krb5 ccache %s\n",
851484
-		 ccname);
851484
-	setenv("KRB5CCNAME", ccname, 1);
851484
-#endif
851484
-}
851484
-
851484
-/*
851484
  * Given a principal, find a matching ple structure
851484
  */
851484
 static struct gssd_k5_kt_princ *
851484
@@ -586,10 +556,12 @@ get_ple_by_princ(krb5_context context, krb5_principal princ)
851484
 
851484
 	/* Need to serialize list if we ever become multi-threaded! */
851484
 
851484
+	pthread_mutex_lock(&ple_lock);
851484
 	ple = find_ple_by_princ(context, princ);
851484
 	if (ple == NULL) {
851484
 		ple = new_ple(context, princ);
851484
 	}
851484
+	pthread_mutex_unlock(&ple_lock);
851484
 
851484
 	return ple;
851484
 }
851484
@@ -1091,6 +1063,7 @@ gssd_setup_krb5_user_gss_ccache(uid_t uid, char *servername, char *dirpattern)
851484
 	const char		*cctype;
851484
 	struct dirent		*d;
851484
 	int			err, i, j;
851484
+	u_int			maj_stat, min_stat;
851484
 
851484
 	printerr(3, "looking for client creds with uid %u for "
851484
 		    "server %s in %s\n", uid, servername, dirpattern);
851484
@@ -1126,22 +1099,16 @@ gssd_setup_krb5_user_gss_ccache(uid_t uid, char *servername, char *dirpattern)
851484
 
851484
 	printerr(2, "using %s as credentials cache for client with "
851484
 		    "uid %u for server %s\n", buf, uid, servername);
851484
-	gssd_set_krb5_ccache_name(buf);
851484
-	return 0;
851484
-}
851484
 
851484
-/*
851484
- * Let the gss code know where to find the machine credentials ccache.
851484
- *
851484
- * Returns:
851484
- *	void
851484
- */
851484
-void
851484
-gssd_setup_krb5_machine_gss_ccache(char *ccname)
851484
-{
851484
-	printerr(2, "using %s as credentials cache for machine creds\n",
851484
-		 ccname);
851484
-	gssd_set_krb5_ccache_name(ccname);
851484
+	printerr(3, "using gss_krb5_ccache_name to select krb5 ccache %s\n",
851484
+		 buf);
851484
+	maj_stat = gss_krb5_ccache_name(&min_stat, buf, NULL);
851484
+	if (maj_stat != GSS_S_COMPLETE) {
851484
+		printerr(0, "ERROR: unable to get user cred cache '%s' "
851484
+			 "failed (%s)\n", buf, error_message(min_stat));
851484
+		return maj_stat;
851484
+	}
851484
+	return 0;
851484
 }
851484
 
851484
 /*
851484
diff --git a/utils/gssd/krb5_util.h b/utils/gssd/krb5_util.h
851484
index a319588..e3bbb07 100644
851484
--- a/utils/gssd/krb5_util.h
851484
+++ b/utils/gssd/krb5_util.h
851484
@@ -27,7 +27,6 @@ int gssd_setup_krb5_user_gss_ccache(uid_t uid, char *servername,
851484
 				     char *dirname);
851484
 int  gssd_get_krb5_machine_cred_list(char ***list);
851484
 void gssd_free_krb5_machine_cred_list(char **list);
851484
-void gssd_setup_krb5_machine_gss_ccache(char *servername);
851484
 void gssd_destroy_krb5_machine_creds(void);
851484
 int  gssd_refresh_krb5_machine_credential(char *hostname,
851484
 					  struct gssd_k5_kt_princ *ple, 
851484
@@ -55,8 +54,6 @@ int limit_krb5_enctypes(struct rpc_gss_sec *sec);
851484
 #define k5_free_unparsed_name(ctx, name)	free(name)
851484
 #define k5_free_default_realm(ctx, realm)	free(realm)
851484
 #define k5_free_kt_entry(ctx, kte)		krb5_kt_free_entry((ctx),(kte))
851484
-#undef USE_GSS_KRB5_CCACHE_NAME
851484
-#define USE_GSS_KRB5_CCACHE_NAME 1
851484
 #endif
851484
 
851484
 #endif /* KRB5_UTIL_H */