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

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