walters / rpms / nfs-utils

Forked from rpms/nfs-utils 6 years ago
Clone
8339594
diff --git a/support/export/xtab.c b/support/export/xtab.c
8339594
index 3b1dcce..2a43193 100644
8339594
--- a/support/export/xtab.c
8339594
+++ b/support/export/xtab.c
8339594
@@ -19,7 +19,9 @@
8339594
 #include "exportfs.h"
8339594
 #include "xio.h"
8339594
 #include "xlog.h"
8339594
+#include "v4root.h"
8339594
 
8339594
+int v4root_needed;
8339594
 static void cond_rename(char *newfile, char *oldfile);
8339594
 
8339594
 static int
8339594
@@ -36,6 +38,8 @@ xtab_read(char *xtab, char *lockfn, int is_export)
8339594
 	if ((lockid = xflock(lockfn, "r")) < 0)
8339594
 		return 0;
8339594
 	setexportent(xtab, "r");
8339594
+	if (is_export == 1)
8339594
+		v4root_needed = 1;
8339594
 	while ((xp = getexportent(is_export==0, 0)) != NULL) {
8339594
 		if (!(exp = export_lookup(xp->e_hostname, xp->e_path, is_export != 1)) &&
8339594
 		    !(exp = export_create(xp, is_export!=1))) {
8339594
@@ -48,6 +52,8 @@ xtab_read(char *xtab, char *lockfn, int is_export)
8339594
 		case 1:
8339594
 			exp->m_xtabent = 1;
8339594
 			exp->m_mayexport = 1;
8339594
+			if ((xp->e_flags & NFSEXP_FSID) && xp->e_fsid == 0)
8339594
+				v4root_needed = 0;
8339594
 			break;
8339594
 		case 2:
8339594
 			exp->m_exported = -1;/* may be exported */
8339594
diff --git a/support/include/nfs/export.h b/support/include/nfs/export.h
8339594
index f7a99ba..76953ac 100644
8339594
--- a/support/include/nfs/export.h
8339594
+++ b/support/include/nfs/export.h
8339594
@@ -24,6 +24,7 @@
8339594
 #define NFSEXP_FSID		0x2000
8339594
 #define	NFSEXP_CROSSMOUNT	0x4000
8339594
 #define NFSEXP_NOACL		0x8000 /* reserved for possible ACL related use */
8339594
-#define NFSEXP_ALLFLAGS		0xFFFF
8339594
+#define NFSEXP_V4ROOT       0x10000
8339594
+#define NFSEXP_ALLFLAGS		0x1FFFF
8339594
 
8339594
 #endif /* _NSF_EXPORT_H */
8339594
diff --git a/support/include/pseudoflavors.h b/support/include/pseudoflavors.h
8339594
index c21087b..c7ba8a2 100644
8339594
--- a/support/include/pseudoflavors.h
8339594
+++ b/support/include/pseudoflavors.h
8339594
@@ -15,3 +15,4 @@ struct flav_info {
8339594
 
8339594
 extern struct flav_info flav_map[];
8339594
 extern const int flav_map_size;
8339594
+extern unsigned int flavors_setall(struct exportent *ep);
8339594
diff --git a/support/include/v4root.h b/support/include/v4root.h
8339594
new file mode 100644
8339594
index 0000000..706c15c
8339594
--- /dev/null
8339594
+++ b/support/include/v4root.h
8339594
@@ -0,0 +1,15 @@
8339594
+/*
8339594
+ * Copyright (C) 2009 Red Hat <nfs@redhat.com>
8339594
+ * support/include/v4root.h
8339594
+ *
8339594
+ * Support routines for dynamic pseudo roots.
8339594
+ *
8339594
+ */
8339594
+
8339594
+#ifndef V4ROOT_H
8339594
+#define V4ROOT_H
8339594
+
8339594
+extern int v4root_needed;
8339594
+extern void v4root_set(void);
8339594
+
8339594
+#endif /* V4ROOT_H */
8339594
diff --git a/support/nfs/exports.c b/support/nfs/exports.c
8339594
index 1aaebf4..fe9ed3a 100644
8339594
--- a/support/nfs/exports.c
8339594
+++ b/support/nfs/exports.c
8339594
@@ -39,16 +39,18 @@ struct flav_info flav_map[] = {
8339594
 	{ "krb5",	RPC_AUTH_GSS_KRB5	},
8339594
 	{ "krb5i",	RPC_AUTH_GSS_KRB5I	},
8339594
 	{ "krb5p",	RPC_AUTH_GSS_KRB5P	},
8339594
+	{ "unix",	AUTH_UNIX		},
8339594
+	{ "sys",	AUTH_SYS		},
8339594
+	{ "null",	AUTH_NULL		},
8339594
+	{ "none",	AUTH_NONE		},
8339594
+#ifdef NOLONGERSUPPORTED
8339594
 	{ "lipkey",	RPC_AUTH_GSS_LKEY	},
8339594
 	{ "lipkey-i",	RPC_AUTH_GSS_LKEYI	},
8339594
 	{ "lipkey-p",	RPC_AUTH_GSS_LKEYP	},
8339594
 	{ "spkm3",	RPC_AUTH_GSS_SPKM	},
8339594
 	{ "spkm3i",	RPC_AUTH_GSS_SPKMI	},
8339594
 	{ "spkm3p",	RPC_AUTH_GSS_SPKMP	},
8339594
-	{ "unix",	AUTH_UNIX		},
8339594
-	{ "sys",	AUTH_SYS		},
8339594
-	{ "null",	AUTH_NULL		},
8339594
-	{ "none",	AUTH_NONE		},
8339594
+#endif
8339594
 };
8339594
 
8339594
 const int flav_map_size = sizeof(flav_map)/sizeof(flav_map[0]);
8339594
@@ -436,6 +438,20 @@ static unsigned int parse_flavors(char *str, struct exportent *ep)
8339594
 	}
8339594
 	return out;
8339594
 }
8339594
+unsigned int flavors_setall(struct exportent *ep)
8339594
+{
8339594
+	struct flav_info *flav;
8339594
+	unsigned int out=0;
8339594
+	int bit;
8339594
+
8339594
+	for (flav = flav_map; flav < flav_map + flav_map_size; flav++) {
8339594
+		bit = secinfo_addflavor(flav, ep);
8339594
+		if (bit < 0)
8339594
+			return 0;
8339594
+		out |= 1<
8339594
+	}
8339594
+	return out;
8339594
+}
8339594
 
8339594
 /* Sets the bits in @mask for the appropriate security flavor flags. */
8339594
 static void setflags(int mask, unsigned int active, struct exportent *ep)
8339594
diff --git a/utils/mountd/Makefile.am b/utils/mountd/Makefile.am
8339594
index 1e76cf8..eba81fc 100644
8339594
--- a/utils/mountd/Makefile.am
8339594
+++ b/utils/mountd/Makefile.am
8339594
@@ -8,7 +8,7 @@ KPREFIX		= @kprefix@
8339594
 sbin_PROGRAMS	= mountd
8339594
 
8339594
 mountd_SOURCES = mountd.c mount_dispatch.c auth.c rmtab.c cache.c \
8339594
-		 svc_run.c fsloc.c mountd.h
8339594
+		 svc_run.c fsloc.c v4root.c mountd.h
8339594
 mountd_LDADD = ../../support/export/libexport.a \
8339594
 	       ../../support/nfs/libnfs.a \
8339594
 	       ../../support/misc/libmisc.a \
8339594
diff --git a/utils/mountd/auth.c b/utils/mountd/auth.c
8339594
index 5a7ff8c..2ed80bc 100644
8339594
--- a/utils/mountd/auth.c
8339594
+++ b/utils/mountd/auth.c
8339594
@@ -20,6 +20,7 @@
8339594
 #include "exportfs.h"
8339594
 #include "mountd.h"
8339594
 #include "xmalloc.h"
8339594
+#include "v4root.h"
8339594
 
8339594
 enum auth_error
8339594
 {
8339594
@@ -102,6 +103,8 @@ auth_reload()
8339594
 	memset(&my_client, 0, sizeof(my_client));
8339594
 	xtab_export_read();
8339594
 	check_useipaddr();
8339594
+	v4root_set();
8339594
+
8339594
 	++counter;
8339594
 
8339594
 	return counter;
8339594
diff --git a/utils/mountd/mountd.c b/utils/mountd/mountd.c
8339594
index 888fd8c..179ef17 100644
8339594
--- a/utils/mountd/mountd.c
8339594
+++ b/utils/mountd/mountd.c
8339594
@@ -540,6 +540,10 @@ get_exportlist(void)
8339594
 
8339594
 	for (i = 0; i < MCL_MAXTYPES; i++) {
8339594
 		for (exp = exportlist[i].p_head; exp; exp = exp->m_next) {
8339594
+			 /* Don't show pseudo exports */
8339594
+			if (exp->m_export.e_flags & NFSEXP_V4ROOT)
8339594
+				continue;
8339594
+
8339594
 			for (e = elist; e != NULL; e = e->ex_next) {
8339594
 				if (!strcmp(exp->m_export.e_path, e->ex_dir))
8339594
 					break;
8339594
diff --git a/utils/mountd/v4root.c b/utils/mountd/v4root.c
8339594
new file mode 100644
2a2e83f
index 0000000..b1e483a
8339594
--- /dev/null
8339594
+++ b/utils/mountd/v4root.c
2a2e83f
@@ -0,0 +1,218 @@
8339594
+/*
8339594
+ * Copyright (C) 2009 Red Hat <nfs@redhat.com>
8339594
+ *
8339594
+ * support/export/v4root.c
8339594
+ *
8339594
+ * Routines used to support NFSv4 pseudo roots
8339594
+ *
8339594
+ */
8339594
+
8339594
+#ifdef HAVE_CONFIG_H
8339594
+#include <config.h>
8339594
+#endif
8339594
+
8339594
+#include <sys/types.h>
8339594
+#include <sys/stat.h>
8339594
+#include <sys/queue.h>
8339594
+#include <stdio.h>
8339594
+#include <stdlib.h>
8339594
+#include <ctype.h>
8339594
+
8339594
+#include <unistd.h>
8339594
+#include <errno.h>
8339594
+
8339594
+#include "xlog.h"
8339594
+#include "exportfs.h"
8339594
+#include "nfslib.h"
8339594
+#include "misc.h"
8339594
+#include "pseudoflavors.h"
8339594
+#include "v4root.h"
8339594
+
8339594
+#ifndef _PATH_PSEUDO_ROOT
8339594
+#define _PATH_PSEUDO_ROOT		"/"
8339594
+#endif
8339594
+
8339594
+#ifndef _PSEUDO_ROOT_FSID
8339594
+#define _PSEUDO_ROOT_FSID	0
8339594
+#endif
8339594
+
8339594
+void v4root_set(void);
8339594
+void v4root_unset(void);
8339594
+static int v4root_support(void);
8339594
+
8339594
+static struct exportent *v4root_create(char *, nfs_export *);
8339594
+
8339594
+int v4root_needed;
8339594
+static nfs_export pseudo_root = {
8339594
+	.m_next = NULL,
8339594
+	.m_client = NULL,
8339594
+	.m_export = {
8339594
+		.e_hostname = "*",
8339594
+		.e_path = _PATH_PSEUDO_ROOT,
8339594
+		.e_flags = NFSEXP_READONLY | NFSEXP_ROOTSQUASH
8339594
+				| NFSEXP_NOSUBTREECHECK | NFSEXP_FSID
8339594
+				| NFSEXP_CROSSMOUNT | NFSEXP_V4ROOT,
8339594
+		.e_anonuid = 65534,
8339594
+		.e_anongid = 65534,
8339594
+		.e_squids = NULL,
8339594
+		.e_nsquids = 0,
8339594
+		.e_sqgids = NULL,
8339594
+		.e_nsqgids = 0,
8339594
+		.e_fsid = 0,
8339594
+		.e_mountpoint = NULL,
8339594
+		.e_secinfo[0].flav = NULL,
8339594
+	},
8339594
+	.m_exported = 0,
8339594
+	.m_xtabent = 1,
8339594
+	.m_mayexport = 1,
8339594
+	.m_changed = 0,
8339594
+	.m_warned = 0,
8339594
+};
8339594
+
8339594
+/*
8339594
+ * Create a pseudo export
8339594
+ */
8339594
+static struct exportent *
8339594
+v4root_create(char *path, nfs_export *export)
8339594
+{
8339594
+	nfs_export *exp;
8339594
+	struct exportent eep;
8339594
+	struct exportent *curexp = &export->m_export;
8339594
+
8339594
+	dupexportent(&eep, curexp);
8339594
+	eep.e_hostname = strdup(curexp->e_hostname);
8339594
+	strncpy(eep.e_path, path, sizeof(eep.e_path));
8339594
+	exp = export_create(&eep, 0);
8339594
+	if (exp == NULL)
8339594
+		return NULL;
8339594
+
8339594
+	exp->m_export.e_flags |= NFSEXP_V4ROOT;
8339594
+	if (strcmp(path, _PATH_PSEUDO_ROOT) != 0)
8339594
+		exp->m_export.e_flags &= ~NFSEXP_FSID;
8339594
+
8339594
+	xlog(D_CALL, "v4root_create: path '%s'", exp->m_export.e_path);
8339594
+
8339594
+	return &exp->m_export;
8339594
+}
8339594
+
8339594
+/*
8339594
+ * Make sure the kernel has pseudo root support.
8339594
+ */
8339594
+static int
8339594
+v4root_support()
8339594
+{
8339594
+	static int kernel_support = -1;
8339594
+	char *ptr, version[64];
8339594
+	int major, minor;
8339594
+	FILE *fp;
8339594
+
8339594
+	if (kernel_support != -1)
8339594
+		return kernel_support;
8339594
+
8339594
+	kernel_support = 0;
8339594
+	fp = fopen("/proc/fs/nfsd/exports", "r");
8339594
+	if (fp == NULL)
8339594
+		goto out;
8339594
+
8339594
+	ptr = fgets(version, 64, fp);
8339594
+	fclose(fp);
8339594
+	if (ptr == NULL)
8339594
+		goto out;
8339594
+
8339594
+	while(*ptr && isdigit(*ptr) == 0)
8339594
+		ptr++;
8339594
+	if (*ptr == '\0')
8339594
+		goto out;
8339594
+
8339594
+	major = minor = 0;
8339594
+	sscanf(ptr, " %d.%d",&major, &minor);
8339594
+	if (major >= 1 && minor >= 2)
8339594
+		kernel_support = 1;
8339594
+out:
8339594
+	if (!kernel_support) {
8339594
+		xlog(L_WARNING, "Kernel does not have pseudo root support.");
8339594
+		xlog(L_WARNING, "NFS v4 mounts will be disabled unless fsid=0");
8339594
+		xlog(L_WARNING, "is specfied in /etc/exports file.");
8339594
+	}
8339594
+
8339594
+	return kernel_support;
8339594
+}
8339594
+
8339594
+/*
8339594
+ * Create pseudo exports by running through the real export 
8339594
+ * looking at the components of the path that make up the export. 
8339594
+ * Those path components, if not exported, will become pseudo 
8339594
+ * exports allowing them to be found when the kernel does an upcall 
8339594
+ * looking for components of the v4 mount.
8339594
+ */
8339594
+void
8339594
+v4root_set()
8339594
+{
8339594
+	nfs_export	*exp, *nxt;
8339594
+	struct exportent *proot;
8339594
+	int	i, insecure = 0, secflavors = 0;
8339594
+	char *path, *ptr;
8339594
+	char *hostname;
8339594
+
8339594
+	if (!v4root_needed)
8339594
+		return;
8339594
+
8339594
+	if (!v4root_support())
8339594
+		return;
8339594
+
8339594
+	proot = v4root_create(_PATH_PSEUDO_ROOT, &pseudo_root);
8339594
+	if (proot == NULL) {
8339594
+		xlog(L_WARNING, "v4root_set: Unable to create "
8339594
+			"pseudo export for '%s'", _PATH_PSEUDO_ROOT);
8339594
+		return;
8339594
+	}
8339594
+
8339594
+	for (i = 0; i < MCL_MAXTYPES; i++) {
8339594
+		for (exp = exportlist[i].p_head; exp; exp = nxt) {
8339594
+			nxt = exp->m_next;
8339594
+			hostname = exp->m_export.e_hostname;
8339594
+
8339594
+			path = strdup(exp->m_export.e_path);
8339594
+			ptr = path + 1;
8339594
+			while ((ptr = strchr(ptr, '/')) != NULL) {
8339594
+				*ptr = '\0';
8339594
+				if (export_lookup(hostname, path, 0) == NULL)
8339594
+					if (v4root_create(path, exp) == NULL) {
8339594
+						xlog(L_WARNING, "v4root_set: Unable to create "
8339594
+							"pseudo export for '%s'", path);
8339594
+						break;
8339594
+					}
8339594
+				*ptr = '/';
8339594
+				ptr++;
8339594
+			}
8339594
+			/* Make note of insecure exports */
8339594
+			if (!insecure)
8339594
+				insecure = (exp->m_export.e_flags & NFSEXP_INSECURE_PORT);
8339594
+
8339594
+			/* Make note of security flavors being set */
8339594
+			if (!secflavors)
8339594
+				secflavors = (exp->m_export.e_secinfo[0].flav != NULL);
8339594
+
8339594
+			free(path);
8339594
+		}
8339594
+	}
8339594
+
8339594
+	/*
8339594
+	 * If there are any insecure exports, the pseudo root
8339594
+	 * also has to be insecure
8339594
+	 */
8339594
+	if (insecure) {
8339594
+		proot->e_flags |= NFSEXP_INSECURE_PORT;
8339594
+	}
8339594
+
8339594
+	/*
8339594
+	 * Make sure the pseudo root is accessible from all
2a2e83f
+	 * security flavors when it needs to be.
8339594
+	 */
2a2e83f
+	if (secflavors && !flavors_setall(proot)) {
2a2e83f
+		xlog(L_WARNING, "v4root_set: Unable to set security "
2a2e83f
+			"flavors on pseudo root");
8339594
+	}
8339594
+
2a2e83f
+}
8339594
+