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

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