Blame SOURCES/autofs-5.1.4-add-fedfs-map-nfs4_c.patch

135b98
autofs-5.1.4 - add fedfs-map-nfs4.c
135b98
135b98
From: Ian Kent <raven@themaw.net>
135b98
135b98
Add build (and install) of the fedfs program map, fedfs-map-nfs4.
135b98
135b98
Signed-off-by: Ian Kent <raven@themaw.net>
135b98
---
135b98
 CHANGELOG              |    1 
135b98
 autofs.spec            |    1 
135b98
 fedfs/Makefile         |   12 ++-
135b98
 fedfs/fedfs-map-nfs4.c |  204 ++++++++++++++++++++++++++++++++++++++++++++++++
135b98
 fedfs/fedfs-token.h    |   40 +++++++++
135b98
 5 files changed, 256 insertions(+), 2 deletions(-)
135b98
 create mode 100644 fedfs/fedfs-map-nfs4.c
135b98
 create mode 100644 fedfs/fedfs-token.h
135b98
135b98
diff --git a/CHANGELOG b/CHANGELOG
135b98
index 88992147..412e3382 100644
135b98
--- a/CHANGELOG
135b98
+++ b/CHANGELOG
135b98
@@ -16,6 +16,7 @@ xx/xx/2018 autofs-5.1.5
135b98
 - fix libresolv configure check.
135b98
 - add fedfs-getsrvinfo.c.
135b98
 - add mount.fedfs.c.
135b98
+- add fedfs-map-nfs4.c.
135b98
 
135b98
 19/12/2017 autofs-5.1.4
135b98
 - fix spec file url.
135b98
diff --git a/autofs.spec b/autofs.spec
135b98
index 2cc0e38f..157c09b4 100644
135b98
--- a/autofs.spec
135b98
+++ b/autofs.spec
135b98
@@ -192,6 +192,7 @@ fi
135b98
 %config(noreplace) /etc/autofs_ldap_auth.conf
135b98
 %{_sbindir}/automount
135b98
 %{_sbindir}/mount.fedfs
135b98
+%{_sbindir}/fedfs-map-nfs4
135b98
 %dir %{_libdir}/autofs
135b98
 %{_libdir}/autofs/*
135b98
 %{_mandir}/*/*
135b98
diff --git a/fedfs/Makefile b/fedfs/Makefile
135b98
index cb325bed..dff749e4 100644
135b98
--- a/fedfs/Makefile
135b98
+++ b/fedfs/Makefile
135b98
@@ -6,11 +6,13 @@
135b98
 include ../Makefile.rules
135b98
 
135b98
 SRCS = mount.fedfs.c
135b98
-HDRS = fedfs-getsrvinfo.h fedfs-gpl-boiler.h fedfs-nls.h
135b98
+HDRS = fedfs-getsrvinfo.h fedfs-gpl-boiler.h fedfs-nls.h \
135b98
+       fedfs-token.h
135b98
 
135b98
 fedfs-getsrvinfo_OBJ = fedfs-getsrvinfo.o
135b98
 
135b98
 mount_fedfs_OBJ = mount.fedfs.o
135b98
+fedfs-map-nfs4_OBJ = fedfs-map-nfs4.o
135b98
 
135b98
 version := $(shell cat ../.version)
135b98
 
135b98
@@ -18,18 +20,24 @@ CFLAGS += -rdynamic $(DAEMON_CFLAGS) -D_GNU_SOURCE -I../include
135b98
 CFLAGS += -DVERSION_STRING=\"$(version)\"
135b98
 LDFLAGS += -rdynamic
135b98
 
135b98
-all: mount.fedfs
135b98
+all: mount.fedfs fedfs-map-nfs4
135b98
 
135b98
 mount.fedfs: $(mount_fedfs_OBJ) $(fedfs-getsrvinfo_OBJ) $(HDRS)
135b98
 	$(CC) -o mount.fedfs \
135b98
 	       $(mount_fedfs_OBJ) $(fedfs-getsrvinfo_OBJ) \
135b98
 	       $(LDFLAGS) $(LIBRESOLV) $(LIBS)
135b98
 
135b98
+fedfs-map-nfs4: $(fedfs-map-nfs4_OBJ) $(fedfs-getsrvinfo_OBJ) $(HDRS)
135b98
+	$(CC) -o fedfs-map-nfs4 \
135b98
+	       $(fedfs-map-nfs4_OBJ) $(fedfs-getsrvinfo_OBJ) \
135b98
+	       $(LDFLAGS) $(LIBRESOLV) $(LIBS)
135b98
+
135b98
 clean:
135b98
 	rm -f *.o *.s *~ mount.fedfs
135b98
 
135b98
 install: all
135b98
 	install -d -m 755 $(INSTALLROOT)$(sbindir)
135b98
+	install -c fedfs-map-nfs4 -m 755 $(INSTALLROOT)$(sbindir); \
135b98
 	if ! test -x $(INSTALLROOT)$(sbindir)/mount.fedfs; \
135b98
 	then \
135b98
 		install -c mount.fedfs -m 755 $(INSTALLROOT)$(sbindir); \
135b98
diff --git a/fedfs/fedfs-map-nfs4.c b/fedfs/fedfs-map-nfs4.c
135b98
new file mode 100644
135b98
index 00000000..9f831cd7
135b98
--- /dev/null
135b98
+++ b/fedfs/fedfs-map-nfs4.c
135b98
@@ -0,0 +1,204 @@
135b98
+/*
135b98
+ * Copyright 2011 Oracle.  All rights reserved.
135b98
+ *
135b98
+ * This file is part of fedfs-utils.
135b98
+ *
135b98
+ * fedfs-utils is free software; you can redistribute it and/or modify
135b98
+ * it under the terms of the GNU General Public License version 2.0 as
135b98
+ * published by the Free Software Foundation.
135b98
+ *
135b98
+ * fedfs-utils is distributed in the hope that it will be useful, but
135b98
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
135b98
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
135b98
+ * GNU General Public License version 2.0 for more details.
135b98
+ *
135b98
+ * You should have received a copy of the GNU General Public License
135b98
+ * version 2.0 along with fedfs-utils.  If not, see:
135b98
+ *
135b98
+ *	http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
135b98
+ */
135b98
+
135b98
+#ifdef HAVE_CONFIG_H
135b98
+#include <config.h>
135b98
+#endif
135b98
+
135b98
+#include <sys/types.h>
135b98
+#include <sys/stat.h>
135b98
+#include <sys/socket.h>
135b98
+#include <sys/mount.h>
135b98
+#include <sys/wait.h>
135b98
+
135b98
+#include <stdbool.h>
135b98
+#include <string.h>
135b98
+#include <stdlib.h>
135b98
+#include <unistd.h>
135b98
+#include <stdio.h>
135b98
+#include <libgen.h>
135b98
+#include <errno.h>
135b98
+#include <getopt.h>
135b98
+#include <locale.h>
135b98
+#include <netdb.h>
135b98
+#include <langinfo.h>
135b98
+
135b98
+#include "fedfs-nls.h"
135b98
+#include "fedfs-token.h"
135b98
+#include "fedfs-getsrvinfo.h"
135b98
+#include "fedfs-gpl-boiler.h"
135b98
+
135b98
+/**
135b98
+ * Name of SRV record containing NFSv4 FedFS root
135b98
+ */
135b98
+#define FEDFS_NFS_DOMAINROOT	"_nfs-domainroot._tcp"
135b98
+
135b98
+/**
135b98
+ * Export pathname of NFSv4 FedFS root
135b98
+ */
135b98
+#define FEDFS_NFS_EXPORTPATH	"/.domainroot"
135b98
+
135b98
+static char *progname;
135b98
+
135b98
+/**
135b98
+ * Display usage message
135b98
+ */
135b98
+static void
135b98
+fedfs_map_usage(void)
135b98
+{
135b98
+	printf(_("\nUsage: %s [domain]\n\n"), progname);
135b98
+
135b98
+	printf("%s", fedfs_gpl_boilerplate);
135b98
+}
135b98
+
135b98
+/**
135b98
+ * Construct an NFSv4 map entry for "domainname" with one server
135b98
+ *
135b98
+ * @param si single-entry list of SRV records
135b98
+ * @param domainname NUL-terminated UTF-8 string containing name of FedFS domain
135b98
+ * @return command exit status
135b98
+ */
135b98
+static int fedfs_map_nfs4_oneserver(struct srvinfo *si, const char *domainname)
135b98
+{
135b98
+	printf("-fstype=nfs,vers=4,fg");
135b98
+	if (si->si_port != 2049)
135b98
+		printf(",port=%u", si->si_port);
135b98
+	printf(" %s:%s/%s\n", si->si_target, FEDFS_NFS_EXPORTPATH, domainname);
135b98
+	return 0;
135b98
+}
135b98
+
135b98
+/**
135b98
+ * Construct an NFSv4 map entry for "domainname" with multiple servers
135b98
+ *
135b98
+ * @param si list of SRV records for requested FedFS domain
135b98
+ * @param domainname NUL-terminated UTF-8 string containing name of FedFS domain
135b98
+ * @return command exit status
135b98
+ */
135b98
+static int fedfs_map_nfs4_replicas(struct srvinfo *si, const char *domainname)
135b98
+{
135b98
+	struct srvinfo *cur;
135b98
+	unsigned short port;
135b98
+	_Bool comma;
135b98
+
135b98
+	/*
135b98
+	 * Unfortunately our automounter can't handle a list of
135b98
+	 * replicas where the various servers live on different
135b98
+	 * ports from one another.
135b98
+	 */
135b98
+	port = si->si_port;
135b98
+	for (cur = si; cur != NULL; cur = cur->si_next)
135b98
+		if (cur->si_port != port) {
135b98
+			fprintf(stderr, _("%s: Replicas on different ports not supported\n"),
135b98
+				progname);
135b98
+			return 1;
135b98
+		}
135b98
+
135b98
+	if (port != 2049)
135b98
+		printf("-fstype=nfs,vers=4,fg,port=%u ", port);
135b98
+	else
135b98
+		printf("-fstype=nfs,vers=4,fg ");
135b98
+
135b98
+	/*
135b98
+	 * Note that the export path is required to be indentical
135b98
+	 * for all domain root servers for this domain.
135b98
+	 */
135b98
+	for (comma = false, cur = si; cur != NULL; cur = cur->si_next) {
135b98
+		if (comma)
135b98
+			printf(",");
135b98
+		printf("%s(%u)", cur->si_target, cur->si_weight);
135b98
+		comma = true;
135b98
+	}
135b98
+	printf(":%s/%s\n", FEDFS_NFS_EXPORTPATH, domainname);
135b98
+
135b98
+	return 0;
135b98
+}
135b98
+
135b98
+/**
135b98
+ * Construct an NFSv4 map entry for "domainname"
135b98
+ *
135b98
+ * @param domainname NUL-terminated UTF-8 string containing name of FedFS domain
135b98
+ * @return command exit status
135b98
+ */
135b98
+static int fedfs_map_nfs4(const char *domainname)
135b98
+{
135b98
+	struct srvinfo *cur, *si = NULL;
135b98
+	unsigned int count;
135b98
+	int error, result;
135b98
+
135b98
+	result = 1;
135b98
+	error = getsrvinfo(FEDFS_NFS_DOMAINROOT, domainname, &si);
135b98
+	switch (error) {
135b98
+	case ESI_SUCCESS:
135b98
+		break;
135b98
+	case ESI_NONAME:
135b98
+		fprintf(stderr, _("%s: Domain name %s not found\n"),
135b98
+			progname, domainname);
135b98
+		goto out;
135b98
+	case ESI_SERVICE:
135b98
+		fprintf(stderr, _("%s: No FedFS domain root available for %s\n"),
135b98
+			progname, domainname);
135b98
+		goto out;
135b98
+	default:
135b98
+		fprintf(stderr, _("%s: Failed to resolve %s: %s\n"),
135b98
+			progname, domainname, gsi_strerror(error));
135b98
+		goto out;
135b98
+	}
135b98
+
135b98
+	for (count = 0, cur = si; cur != NULL; cur = cur->si_next)
135b98
+		count++;
135b98
+	if (count == 1)
135b98
+		result = fedfs_map_nfs4_oneserver(si, domainname);
135b98
+	else
135b98
+		result = fedfs_map_nfs4_replicas(si, domainname);
135b98
+
135b98
+out:
135b98
+	freesrvinfo(si);
135b98
+	return result;
135b98
+}
135b98
+
135b98
+/**
135b98
+ * Program entry point
135b98
+ *
135b98
+ * @param argc count of command line arguments
135b98
+ * @param argv array of NUL-terminated C strings containing command line arguments
135b98
+ * @return program exit status
135b98
+ */
135b98
+int main(int argc, char *argv[])
135b98
+{
135b98
+	(void)setlocale(LC_ALL, "");
135b98
+
135b98
+	progname = basename(argv[0]);
135b98
+
135b98
+	if (argc != 2) {
135b98
+		fedfs_map_usage();
135b98
+		return 1;
135b98
+	}
135b98
+
135b98
+	if (strcmp(progname, "fedfs-map-nfs4") == 0)
135b98
+		return fedfs_map_nfs4(argv[1]);
135b98
+#ifdef EXAMPLE
135b98
+	/* CIFS support might plug in here */
135b98
+	else if (strcmp(progname, "fedfs-map-cifs") == 0)
135b98
+		return fedfs_map_cifs(argv[1]);
135b98
+#endif
135b98
+
135b98
+	fprintf(stderr, _("%s: Unsupported file system type\n"), progname);
135b98
+	return 1;
135b98
+}
135b98
diff --git a/fedfs/fedfs-token.h b/fedfs/fedfs-token.h
135b98
new file mode 100644
135b98
index 00000000..5651409d
135b98
--- /dev/null
135b98
+++ b/fedfs/fedfs-token.h
135b98
@@ -0,0 +1,40 @@
135b98
+/*
135b98
+ * Copyright (C) 2007 Oracle.  All rights reserved.
135b98
+ * Copyright (C) 2007 Chuck Lever <chuck.lever@oracle.com>
135b98
+ *
135b98
+ * This file is part of fedfs-utils.
135b98
+ *
135b98
+ * fedfs-utils is free software; you can redistribute it and/or modify
135b98
+ * it under the terms of the GNU General Public License version 2.0 as
135b98
+ * published by the Free Software Foundation.
135b98
+ *
135b98
+ * fedfs-utils is distributed in the hope that it will be useful, but
135b98
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
135b98
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
135b98
+ * GNU General Public License version 2.0 for more details.
135b98
+ *
135b98
+ * You should have received a copy of the GNU General Public License
135b98
+ * version 2.0 along with fedfs-utils.  If not, see:
135b98
+ *
135b98
+ *	http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
135b98
+ */
135b98
+
135b98
+#ifndef _FEDFS_UTILS_TOKEN_H
135b98
+#define _FEDFS_UTILS_TOKEN_H
135b98
+
135b98
+#include <sys/cdefs.h>
135b98
+
135b98
+/**
135b98
+ * Private tokenizer state object
135b98
+ */
135b98
+struct tokenizer;
135b98
+
135b98
+__attribute_malloc__
135b98
+struct tokenizer	*tk_new_tokenizer(const char *string,
135b98
+						const char delimiter);
135b98
+__attribute_malloc__
135b98
+char				*tk_next_token(struct tokenizer *state);
135b98
+void				 tk_free_tokenizer(struct tokenizer *state);
135b98
+int				 tk_tokenizer_error(const struct tokenizer *state);
135b98
+
135b98
+#endif	/* !_FEDFS_UTILS_TOKEN_H */