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

e19a30
diff -up nfs-utils-1.3.0/utils/gssd/gssd_proc.c.orig nfs-utils-1.3.0/utils/gssd/gssd_proc.c
e19a30
--- nfs-utils-1.3.0/utils/gssd/gssd_proc.c.orig	2014-09-17 14:22:54.003055871 -0400
e19a30
+++ nfs-utils-1.3.0/utils/gssd/gssd_proc.c	2014-09-17 14:36:02.917808209 -0400
e19a30
@@ -77,6 +77,7 @@
e19a30
 #include "context.h"
e19a30
 #include "nfsrpc.h"
e19a30
 #include "nfslib.h"
e19a30
+#include "gss_names.h"
e19a30
 
e19a30
 /*
e19a30
  * pollarray:
e19a30
@@ -681,19 +682,25 @@ parse_enctypes(char *enctypes)
e19a30
 	return 0;
e19a30
 }
e19a30
 
e19a30
-static int
e19a30
+static void
e19a30
 do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
e19a30
-	    gss_buffer_desc *context_token, OM_uint32 lifetime_rec)
e19a30
+	    gss_buffer_desc *context_token, OM_uint32 lifetime_rec,
e19a30
+	    gss_buffer_desc *acceptor)
e19a30
 {
e19a30
 	char    *buf = NULL, *p = NULL, *end = NULL;
e19a30
 	unsigned int timeout = context_timeout;
e19a30
 	unsigned int buf_size = 0;
e19a30
 
e19a30
-	printerr(1, "doing downcall lifetime_rec %u\n", lifetime_rec);
e19a30
+	printerr(1, "doing downcall: lifetime_rec=%u acceptor=%.*s\n",
e19a30
+		lifetime_rec, acceptor->length, acceptor->value);
e19a30
 	buf_size = sizeof(uid) + sizeof(timeout) + sizeof(pd->pd_seq_win) +
e19a30
 		sizeof(pd->pd_ctx_hndl.length) + pd->pd_ctx_hndl.length +
e19a30
-		sizeof(context_token->length) + context_token->length;
e19a30
+		sizeof(context_token->length) + context_token->length +
e19a30
+		sizeof(acceptor->length) + acceptor->length;
e19a30
 	p = buf = malloc(buf_size);
e19a30
+	if (!buf)
e19a30
+		goto out_err;
e19a30
+
e19a30
 	end = buf + buf_size;
e19a30
 
e19a30
 	/* context_timeout set by -t option overrides context lifetime */
e19a30
@@ -704,14 +711,15 @@ do_downcall(int k5_fd, uid_t uid, struct
e19a30
 	if (WRITE_BYTES(&p, end, pd->pd_seq_win)) goto out_err;
e19a30
 	if (write_buffer(&p, end, &pd->pd_ctx_hndl)) goto out_err;
e19a30
 	if (write_buffer(&p, end, context_token)) goto out_err;
e19a30
+	if (write_buffer(&p, end, acceptor)) goto out_err;
e19a30
 
e19a30
 	if (write(k5_fd, buf, p - buf) < p - buf) goto out_err;
e19a30
-	if (buf) free(buf);
e19a30
-	return 0;
e19a30
+	free(buf);
e19a30
+	return;
e19a30
 out_err:
e19a30
-	if (buf) free(buf);
e19a30
+	free(buf);
e19a30
 	printerr(1, "Failed to write downcall!\n");
e19a30
-	return -1;
e19a30
+	return;
e19a30
 }
e19a30
 
e19a30
 static int
e19a30
@@ -1035,6 +1043,9 @@ process_krb5_upcall(struct clnt_info *cl
e19a30
 	gss_cred_id_t		gss_cred;
e19a30
 	OM_uint32		maj_stat, min_stat, lifetime_rec;
e19a30
 	pid_t			pid;
e19a30
+	gss_name_t		gacceptor = GSS_C_NO_NAME;
e19a30
+	gss_OID			mech;
e19a30
+	gss_buffer_desc		acceptor  = {0};
e19a30
 
e19a30
 	pid = fork();
e19a30
 	switch(pid) {
e19a30
@@ -1175,15 +1186,24 @@ process_krb5_upcall(struct clnt_info *cl
e19a30
 		goto out_return_error;
e19a30
 	}
e19a30
 
e19a30
-	/* Grab the context lifetime to pass to the kernel. lifetime_rec
e19a30
-	 * is set to zero on error */
e19a30
-	maj_stat = gss_inquire_context(&min_stat, pd.pd_ctx, NULL, NULL,
e19a30
-				       &lifetime_rec, NULL, NULL, NULL, NULL);
e19a30
-
e19a30
-	if (maj_stat)
e19a30
-		printerr(1, "WARNING: Failed to inquire context for lifetme "
e19a30
-			    "maj_stat %u\n", maj_stat);
e19a30
+	/* Grab the context lifetime and acceptor name out of the ctx. */
e19a30
+	maj_stat = gss_inquire_context(&min_stat, pd.pd_ctx, NULL, &gacceptor,
e19a30
+				       &lifetime_rec, &mech, NULL, NULL, NULL);
e19a30
+
e19a30
+	if (maj_stat != GSS_S_COMPLETE) {
e19a30
+		printerr(1, "WARNING: Failed to inquire context "
e19a30
+			    "maj_stat (0x%x)\n", maj_stat);
e19a30
+		lifetime_rec = 0;
e19a30
+	} else {
e19a30
+		get_hostbased_client_buffer(gacceptor, mech, &acceptor);
e19a30
+		gss_release_name(&min_stat, &gacceptor);
e19a30
+	}
e19a30
 
e19a30
+	/*
e19a30
+	 * The serialization can mean turning pd.pd_ctx into a lucid context. If
e19a30
+	 * that happens then the pd.pd_ctx will be unusable, so we must never
e19a30
+	 * try to use it after this point.
e19a30
+	 */
e19a30
 	if (serialize_context_for_kernel(&pd.pd_ctx, &token, &krb5oid, NULL)) {
e19a30
 		printerr(0, "WARNING: Failed to serialize krb5 context for "
e19a30
 			    "user with uid %d for server %s\n",
e19a30
@@ -1191,9 +1211,10 @@ process_krb5_upcall(struct clnt_info *cl
e19a30
 		goto out_return_error;
e19a30
 	}
e19a30
 
e19a30
-	do_downcall(fd, uid, &pd, &token, lifetime_rec);
e19a30
+	do_downcall(fd, uid, &pd, &token, lifetime_rec, &acceptor);
e19a30
 
e19a30
 out:
e19a30
+	gss_release_buffer(&min_stat, &acceptor);
e19a30
 	if (token.value)
e19a30
 		free(token.value);
e19a30
 #ifdef HAVE_AUTHGSS_FREE_PRIVATE_DATA
e19a30
diff -up nfs-utils-1.3.0/utils/gssd/gss_names.c.orig nfs-utils-1.3.0/utils/gssd/gss_names.c
e19a30
--- nfs-utils-1.3.0/utils/gssd/gss_names.c.orig	2014-09-17 14:35:16.646945303 -0400
e19a30
+++ nfs-utils-1.3.0/utils/gssd/gss_names.c	2014-09-17 14:35:16.646945303 -0400
e19a30
@@ -0,0 +1,138 @@
e19a30
+/*
e19a30
+  Copyright (c) 2000 The Regents of the University of Michigan.
e19a30
+  All rights reserved.
e19a30
+
e19a30
+  Copyright (c) 2002 Bruce Fields <bfields@UMICH.EDU>
e19a30
+
e19a30
+  Redistribution and use in source and binary forms, with or without
e19a30
+  modification, are permitted provided that the following conditions
e19a30
+  are met:
e19a30
+
e19a30
+  1. Redistributions of source code must retain the above copyright
e19a30
+     notice, this list of conditions and the following disclaimer.
e19a30
+  2. Redistributions in binary form must reproduce the above copyright
e19a30
+     notice, this list of conditions and the following disclaimer in the
e19a30
+     documentation and/or other materials provided with the distribution.
e19a30
+  3. Neither the name of the University nor the names of its
e19a30
+     contributors may be used to endorse or promote products derived
e19a30
+     from this software without specific prior written permission.
e19a30
+
e19a30
+  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
e19a30
+  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
e19a30
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
e19a30
+  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
e19a30
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
e19a30
+  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
e19a30
+  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
e19a30
+  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
e19a30
+  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
e19a30
+  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
e19a30
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
e19a30
+*/
e19a30
+
e19a30
+#ifdef HAVE_CONFIG_H
e19a30
+#include <config.h>
e19a30
+#endif	/* HAVE_CONFIG_H */
e19a30
+
e19a30
+#include <sys/param.h>
e19a30
+#include <sys/stat.h>
e19a30
+#include <rpc/rpc.h>
e19a30
+
e19a30
+#include <pwd.h>
e19a30
+#include <stdio.h>
e19a30
+#include <unistd.h>
e19a30
+#include <ctype.h>
e19a30
+#include <string.h>
e19a30
+#include <fcntl.h>
e19a30
+#include <errno.h>
e19a30
+#include <nfsidmap.h>
e19a30
+#include <nfslib.h>
e19a30
+#include <time.h>
e19a30
+
e19a30
+#include "svcgssd.h"
e19a30
+#include "gss_util.h"
e19a30
+#include "err_util.h"
e19a30
+#include "context.h"
e19a30
+#include "misc.h"
e19a30
+#include "gss_oids.h"
e19a30
+#include "svcgssd_krb5.h"
e19a30
+
e19a30
+static int
e19a30
+get_krb5_hostbased_name(gss_buffer_desc *name, char **hostbased_name)
e19a30
+{
e19a30
+	char *p, *sname = NULL;
e19a30
+	if (strchr(name->value, '@') && strchr(name->value, '/')) {
e19a30
+		if ((sname = calloc(name->length, 1)) == NULL) {
e19a30
+			printerr(0, "ERROR: get_krb5_hostbased_name failed "
e19a30
+				 "to allocate %d bytes\n", name->length);
e19a30
+			return -1;
e19a30
+		}
e19a30
+		/* read in name and instance and replace '/' with '@' */
e19a30
+		sscanf(name->value, "%[^@]", sname);
e19a30
+		p = strrchr(sname, '/');
e19a30
+		if (p == NULL) {    /* The '@' preceeded the '/' */
e19a30
+			free(sname);
e19a30
+			return -1;
e19a30
+		}
e19a30
+		*p = '@';
e19a30
+	}
e19a30
+	*hostbased_name = sname;
e19a30
+	return 0;
e19a30
+}
e19a30
+
e19a30
+int
e19a30
+get_hostbased_client_name(gss_name_t client_name, gss_OID mech,
e19a30
+			  char **hostbased_name)
e19a30
+{
e19a30
+	u_int32_t	maj_stat, min_stat;
e19a30
+	gss_buffer_desc	name;
e19a30
+	gss_OID		name_type = GSS_C_NO_OID;
e19a30
+	char		*cname;
e19a30
+	int		res = -1;
e19a30
+
e19a30
+	*hostbased_name = NULL;	    /* preset in case we fail */
e19a30
+
e19a30
+	/* Get the client's gss authenticated name */
e19a30
+	maj_stat = gss_display_name(&min_stat, client_name, &name, &name_type);
e19a30
+	if (maj_stat != GSS_S_COMPLETE) {
e19a30
+		pgsserr("get_hostbased_client_name: gss_display_name",
e19a30
+			maj_stat, min_stat, mech);
e19a30
+		goto out_err;
e19a30
+	}
e19a30
+	if (name.length >= 0xffff) {	    /* don't overflow */
e19a30
+		printerr(0, "ERROR: get_hostbased_client_name: "
e19a30
+			 "received gss_name is too long (%d bytes)\n",
e19a30
+			 name.length);
e19a30
+		goto out_rel_buf;
e19a30
+	}
e19a30
+
e19a30
+	/* For Kerberos, transform the NT_KRB5_PRINCIPAL name to
e19a30
+	 * an NT_HOSTBASED_SERVICE name */
e19a30
+	if (g_OID_equal(&krb5oid, mech)) {
e19a30
+		if (get_krb5_hostbased_name(&name, &cname) == 0)
e19a30
+			*hostbased_name = cname;
e19a30
+	} else {
e19a30
+		printerr(1, "WARNING: unknown/unsupport mech OID\n");
e19a30
+	}
e19a30
+
e19a30
+	res = 0;
e19a30
+out_rel_buf:
e19a30
+	gss_release_buffer(&min_stat, &name);
e19a30
+out_err:
e19a30
+	return res;
e19a30
+}
e19a30
+
e19a30
+void
e19a30
+get_hostbased_client_buffer(gss_name_t client_name, gss_OID mech,
e19a30
+			    gss_buffer_t buf)
e19a30
+{
e19a30
+	char *hname;
e19a30
+
e19a30
+	if (!get_hostbased_client_name(client_name, mech, &hname)) {
e19a30
+		buf->length = strlen(hname) + 1;
e19a30
+		buf->value = hname;
e19a30
+	} else {
e19a30
+		buf->length = 0;
e19a30
+		buf->value = NULL;
e19a30
+	}
e19a30
+}
e19a30
diff -up nfs-utils-1.3.0/utils/gssd/gss_names.h.orig nfs-utils-1.3.0/utils/gssd/gss_names.h
e19a30
--- nfs-utils-1.3.0/utils/gssd/gss_names.h.orig	2014-09-17 14:35:16.646945303 -0400
e19a30
+++ nfs-utils-1.3.0/utils/gssd/gss_names.h	2014-09-17 14:35:16.646945303 -0400
e19a30
@@ -0,0 +1,36 @@
e19a30
+/*
e19a30
+  Copyright (c) 2000 The Regents of the University of Michigan.
e19a30
+  All rights reserved.
e19a30
+
e19a30
+  Copyright (c) 2002 Bruce Fields <bfields@UMICH.EDU>
e19a30
+
e19a30
+  Redistribution and use in source and binary forms, with or without
e19a30
+  modification, are permitted provided that the following conditions
e19a30
+  are met:
e19a30
+
e19a30
+  1. Redistributions of source code must retain the above copyright
e19a30
+     notice, this list of conditions and the following disclaimer.
e19a30
+  2. Redistributions in binary form must reproduce the above copyright
e19a30
+     notice, this list of conditions and the following disclaimer in the
e19a30
+     documentation and/or other materials provided with the distribution.
e19a30
+  3. Neither the name of the University nor the names of its
e19a30
+     contributors may be used to endorse or promote products derived
e19a30
+     from this software without specific prior written permission.
e19a30
+
e19a30
+  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
e19a30
+  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
e19a30
+  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
e19a30
+  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
e19a30
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
e19a30
+  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
e19a30
+  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
e19a30
+  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
e19a30
+  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
e19a30
+  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
e19a30
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
e19a30
+*/
e19a30
+
e19a30
+extern int get_hostbased_client_name(gss_name_t client_name, gss_OID mech,
e19a30
+					char **hostbased_name);
e19a30
+extern void get_hostbased_client_buffer(gss_name_t client_name,
e19a30
+			gss_OID mech, gss_buffer_t buf);
e19a30
diff -up nfs-utils-1.3.0/utils/gssd/Makefile.am.orig nfs-utils-1.3.0/utils/gssd/Makefile.am
e19a30
--- nfs-utils-1.3.0/utils/gssd/Makefile.am.orig	2014-03-25 11:12:07.000000000 -0400
e19a30
+++ nfs-utils-1.3.0/utils/gssd/Makefile.am	2014-09-17 14:35:16.645945284 -0400
e19a30
@@ -18,11 +18,13 @@ COMMON_SRCS = \
e19a30
 	context_lucid.c \
e19a30
 	gss_util.c \
e19a30
 	gss_oids.c \
e19a30
+	gss_names.c \
e19a30
 	err_util.c \
e19a30
 	\
e19a30
 	context.h \
e19a30
 	err_util.h \
e19a30
 	gss_oids.h \
e19a30
+	gss_names.h \
e19a30
 	gss_util.h
e19a30
 
e19a30
 gssd_SOURCES = \
e19a30
diff -up nfs-utils-1.3.0/utils/gssd/svcgssd_proc.c.orig nfs-utils-1.3.0/utils/gssd/svcgssd_proc.c
e19a30
--- nfs-utils-1.3.0/utils/gssd/svcgssd_proc.c.orig	2014-03-25 11:12:07.000000000 -0400
e19a30
+++ nfs-utils-1.3.0/utils/gssd/svcgssd_proc.c	2014-09-17 14:35:16.646945303 -0400
e19a30
@@ -59,6 +59,7 @@
e19a30
 #include "misc.h"
e19a30
 #include "gss_oids.h"
e19a30
 #include "svcgssd_krb5.h"
e19a30
+#include "gss_names.h"
e19a30
 
e19a30
 extern char * mech2file(gss_OID mech);
e19a30
 #define SVCGSSD_CONTEXT_CHANNEL "/proc/net/rpc/auth.rpcsec.context/channel"
e19a30
@@ -315,71 +316,6 @@ print_hexl(const char *description, unsi
e19a30
 }
e19a30
 #endif
e19a30
 
e19a30
-static int
e19a30
-get_krb5_hostbased_name (gss_buffer_desc *name, char **hostbased_name)
e19a30
-{
e19a30
-	char *p, *sname = NULL;
e19a30
-	if (strchr(name->value, '@') && strchr(name->value, '/')) {
e19a30
-		if ((sname = calloc(name->length, 1)) == NULL) {
e19a30
-			printerr(0, "ERROR: get_krb5_hostbased_name failed "
e19a30
-				 "to allocate %d bytes\n", name->length);
e19a30
-			return -1;
e19a30
-		}
e19a30
-		/* read in name and instance and replace '/' with '@' */
e19a30
-		sscanf(name->value, "%[^@]", sname);
e19a30
-		p = strrchr(sname, '/');
e19a30
-		if (p == NULL) {    /* The '@' preceeded the '/' */
e19a30
-			free(sname);
e19a30
-			return -1;
e19a30
-		}
e19a30
-		*p = '@';
e19a30
-	}
e19a30
-	*hostbased_name = sname;
e19a30
-	return 0;
e19a30
-}
e19a30
-
e19a30
-static int
e19a30
-get_hostbased_client_name(gss_name_t client_name, gss_OID mech,
e19a30
-			  char **hostbased_name)
e19a30
-{
e19a30
-	u_int32_t	maj_stat, min_stat;
e19a30
-	gss_buffer_desc	name;
e19a30
-	gss_OID		name_type = GSS_C_NO_OID;
e19a30
-	char		*cname;
e19a30
-	int		res = -1;
e19a30
-
e19a30
-	*hostbased_name = NULL;	    /* preset in case we fail */
e19a30
-
e19a30
-	/* Get the client's gss authenticated name */
e19a30
-	maj_stat = gss_display_name(&min_stat, client_name, &name, &name_type);
e19a30
-	if (maj_stat != GSS_S_COMPLETE) {
e19a30
-		pgsserr("get_hostbased_client_name: gss_display_name",
e19a30
-			maj_stat, min_stat, mech);
e19a30
-		goto out_err;
e19a30
-	}
e19a30
-	if (name.length >= 0xffff) {	    /* don't overflow */
e19a30
-		printerr(0, "ERROR: get_hostbased_client_name: "
e19a30
-			 "received gss_name is too long (%d bytes)\n",
e19a30
-			 name.length);
e19a30
-		goto out_rel_buf;
e19a30
-	}
e19a30
-
e19a30
-	/* For Kerberos, transform the NT_KRB5_PRINCIPAL name to
e19a30
-	 * an NT_HOSTBASED_SERVICE name */
e19a30
-	if (g_OID_equal(&krb5oid, mech)) {
e19a30
-		if (get_krb5_hostbased_name(&name, &cname) == 0)
e19a30
-			*hostbased_name = cname;
e19a30
-	} else {
e19a30
-		printerr(1, "WARNING: unknown/unsupport mech OID\n");
e19a30
-	}
e19a30
-
e19a30
-	res = 0;
e19a30
-out_rel_buf:
e19a30
-	gss_release_buffer(&min_stat, &name);
e19a30
-out_err:
e19a30
-	return res;
e19a30
-}
e19a30
-
e19a30
 void
e19a30
 handle_nullreq(FILE *f) {
e19a30
 	/* XXX initialize to a random integer to reduce chances of unnecessary