- update with latest autofs upstream commits.

This commit is contained in:
Ian Kent 2018-02-19 09:40:19 +08:00
parent 970950e919
commit 8c1733d8ba
8 changed files with 1832 additions and 1 deletions

View File

@ -0,0 +1,42 @@
autofs-5.1.4 - add an example fedfs master map entry to the installed master map
From: Ian Kent <raven@themaw.net>
Add an example of using the fedfs program map (to facilitate access
to fedfs domain mounts) to the installed master map.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
samples/auto.master | 6 ++++++
2 files changed, 7 insertions(+)
diff --git a/CHANGELOG b/CHANGELOG
index bbe8019e..f771a433 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -18,6 +18,7 @@ xx/xx/2018 autofs-5.1.5
- add mount.fedfs.c.
- add fedfs-map-nfs4.c.
- add conditional inclusion of fedfs binaries.
+- add an example fedfs master map entry to the installed master map.
19/12/2017 autofs-5.1.4
- fix spec file url.
diff --git a/samples/auto.master b/samples/auto.master
index 0f2c8ab0..9a9968a3 100644
--- a/samples/auto.master
+++ b/samples/auto.master
@@ -17,6 +17,12 @@
#
+dir:/etc/auto.master.d
#
+# If you have fedfs set up and the related binaries, either
+# built as part of autofs or installed from another package,
+# uncomment this line to use the fedfs program map to access
+# your fedfs mounts.
+#/nfs4 /usr/sbin/fedfs-map-nfs4 nobind
+#
# Include central master map if it can be found using
# nsswitch sources.
#

View File

@ -0,0 +1,184 @@
autofs-5.1.4 - add conditional inclusion of fedfs binaries
From: Ian Kent <raven@themaw.net>
Add conditional inclusion of the fedfs binaries.
Using configure a --with-fedfs is needed to build and install
the fedfs binaries.
Using rpmbuild -tb <autofs tar> it's necessary to add the option
--without fedfs to exclude the fedfs binaries from the resulting
rpm package.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
Makefile.conf.in | 2 ++
Makefile.rules | 6 +++++-
autofs.spec | 12 +++++++++++-
configure | 16 ++++++++++++++++
configure.in | 9 +++++++++
6 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
index 412e3382..bbe8019e 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -17,6 +17,7 @@ xx/xx/2018 autofs-5.1.5
- add fedfs-getsrvinfo.c.
- add mount.fedfs.c.
- add fedfs-map-nfs4.c.
+- add conditional inclusion of fedfs binaries.
19/12/2017 autofs-5.1.4
- fix spec file url.
diff --git a/Makefile.conf.in b/Makefile.conf.in
index 85662654..3fe1a0a0 100644
--- a/Makefile.conf.in
+++ b/Makefile.conf.in
@@ -58,6 +58,8 @@ EXT3FS = @HAVE_E3FSCK@
# Support for calling e4fsck when mounting ext4 filesystems
EXT4FS = @HAVE_E4FSCK@
+FEDFS = @ENABLE_FEDFS@
+
LEX = @PATH_LEX@
YACC = @PATH_YACC@
RPCGEN = @PATH_RPCGEN@
diff --git a/Makefile.rules b/Makefile.rules
index fc9f6019..2ccb1f6e 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -3,12 +3,16 @@
#
# Root directory contents
-SUBDIRS = lib daemon fedfs modules man
+SUBDIRS = lib daemon modules man
INCDIRS = include
INCFILES = COPYING COPYRIGHT NEWS README* TODO Makefile Makefile.rules \
Makefile.conf.in .version .autofs-* configure.in aclocal.m4 \
configure *.patch autofs.spec
+ifeq ($(FEDFS), 1)
+ SUBDIRS += fedfs
+endif
+
# Attempt to be friends with autotools
INSTALLROOT = $(DESTDIR)
diff --git a/autofs.spec b/autofs.spec
index 157c09b4..2cb09ef0 100644
--- a/autofs.spec
+++ b/autofs.spec
@@ -16,6 +16,10 @@
# disable them.
%define with_libtirpc %{?_without_libtirpc: 0} %{?!_without_libtirpc: 1}
+# Use --without fedfs in your rpmbuild command or force values to 0 to
+# disable them.
+%define with_fedfs %{?_without_fedfs: 0} %{?!_without_fedfs: 1}
+
Summary: A tool from automatically mounting and umounting filesystems.
Name: autofs
%define version 5.1.4
@@ -82,6 +86,9 @@ echo %{version}-%{release} > .version
%if %{with_libtirpc}
%define libtirpc_configure_arg --with-libtirpc
%endif
+%if %{with_fedfs}
+ %define fedfs_configure_arg --enable-fedfs
+%endif
%build
CFLAGS="$RPM_OPT_FLAGS -Wall" \
@@ -90,7 +97,8 @@ LDFLAGS="-Wl,-z,now" \
--disable-mount-locking \
--enable-ignore-busy \
%{?systemd_configure_arg:} \
- %{?libtirpc_configure_arg:}
+ %{?libtirpc_configure_arg:} \
+ %{?fedfs_configure_arg:}
CFLAGS="$RPM_OPT_FLAGS -Wall" LDFLAGS="-Wl,-z,now" make initdir=/etc/rc.d/init.d DONTSTRIP=1
%install
@@ -191,8 +199,10 @@ fi
%config(noreplace) /etc/sysconfig/autofs
%config(noreplace) /etc/autofs_ldap_auth.conf
%{_sbindir}/automount
+%if %{with_fedfs}
%{_sbindir}/mount.fedfs
%{_sbindir}/fedfs-map-nfs4
+%endif
%dir %{_libdir}/autofs
%{_libdir}/autofs/*
%{_mandir}/*/*
diff --git a/configure b/configure
index 5c8aae30..9682b36f 100755
--- a/configure
+++ b/configure
@@ -648,6 +648,7 @@ NSL_CFLAGS
LIBCLOCK_GETTIME
KRB5_CONFIG
XML_CONFIG
+ENABLE_FEDFS
sssldir
HAVE_SSS_AUTOFS
PATH_RPCGEN
@@ -743,6 +744,7 @@ with_libtirpc
with_dmalloc
enable_sloppy_mount
enable_no_canon_umount
+enable_fedfs
with_hesiod
with_openldap
with_sasl
@@ -1377,6 +1379,7 @@ Optional Features:
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--enable-sloppy-mount enable the use of the -s option to mount
--enable-no-canon-umount enable the use of the -c option to umount
+ --enable-fedfs enable inclusion of fedfs binaries mount.fedfs and fedfs-map-nfs4
--disable-ext-env disable search in environment for substitution variable
--disable-mount-locking disable use of locking when spawning mount command
--enable-force-shutdown enable USR1 signal to force unlink umount of any
@@ -4246,6 +4249,19 @@ $as_echo "#define HAVE_NO_CANON_UMOUNT 1" >>confdefs.h
fi
+ENABLE_FEDFS=""
+# Check whether --enable-fedfs was given.
+if test "${enable_fedfs+set}" = set; then :
+ enableval=$enable_fedfs;
+else
+ enable_fedfs=no
+fi
+
+if test x$enable_fedfs = xyes; then
+ ENABLE_FEDFS="1"
+fi
+
+
# LDAP SASL auth needs libxml and Kerberos
for ac_prog in xml2-config
do
diff --git a/configure.in b/configure.in
index 4d1208f5..de06a96d 100644
--- a/configure.in
+++ b/configure.in
@@ -195,6 +195,15 @@ if test x$enable_no_canon_umount = xyes; then
AC_DEFINE(HAVE_NO_CANON_UMOUNT, 1, [define if the umount command supports the -c option])
fi
+ENABLE_FEDFS=""
+AC_ARG_ENABLE(fedfs,
+[ --enable-fedfs enable inclusion of fedfs binaries mount.fedfs and fedfs-map-nfs4],,
+ enable_fedfs=no)
+if test x$enable_fedfs = xyes; then
+ ENABLE_FEDFS="1"
+fi
+AC_SUBST(ENABLE_FEDFS)
+
# LDAP SASL auth needs libxml and Kerberos
AF_CHECK_LIBXML()
AF_CHECK_KRB5()

View File

@ -0,0 +1,402 @@
autofs-5.1.4 - add fedfs-getsrvinfo.c
From: Ian Kent <raven@themaw.net>
Add the fedfs domain information discovery library functions.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1
fedfs/fedfs-getsrvinfo.c | 311 ++++++++++++++++++++++++++++++++++++++++++++++
fedfs/fedfs-getsrvinfo.h | 52 ++++++++
3 files changed, 364 insertions(+)
create mode 100644 fedfs/fedfs-getsrvinfo.c
create mode 100644 fedfs/fedfs-getsrvinfo.h
diff --git a/CHANGELOG b/CHANGELOG
index dbfb8389..8d6c737c 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -14,6 +14,7 @@ xx/xx/2018 autofs-5.1.5
- Makefiles.rules: remove 'samples' from SUBDIRS.
- dont allow trailing slash in master map mount points.
- fix libresolv configure check.
+- add fedfs-getsrvinfo.c.
19/12/2017 autofs-5.1.4
- fix spec file url.
diff --git a/fedfs/fedfs-getsrvinfo.c b/fedfs/fedfs-getsrvinfo.c
new file mode 100644
index 00000000..02ad16b5
--- /dev/null
+++ b/fedfs/fedfs-getsrvinfo.c
@@ -0,0 +1,311 @@
+/*
+ * Copyright 2011 Oracle. All rights reserved.
+ *
+ * This file is part of fedfs-utils.
+ *
+ * fedfs-utils is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0 as
+ * published by the Free Software Foundation.
+ *
+ * fedfs-utils is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License version 2.0 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2.0 along with fedfs-utils. If not, see:
+ *
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <stdbool.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+#include <stdio.h>
+#include <errno.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <arpa/nameser_compat.h>
+#include <resolv.h>
+
+#include "fedfs-getsrvinfo.h"
+
+/**
+ * Parsing overlay for DNS query result record header. Fields are
+ * in network byte order.
+ */
+struct rechdr {
+ uint16_t type;
+ uint16_t class;
+ uint32_t ttl;
+ uint16_t length;
+} __attribute__((__packed__));
+
+/**
+ * Parsing overlay for DNS query result SRV record data. Fields
+ * are in network byte order.
+ */
+struct srv {
+ uint16_t priority;
+ uint16_t weight;
+ uint16_t port;
+ unsigned char *target;
+} __attribute__((__packed__));
+
+/**
+ * Return C string matching error value of "status"
+ *
+ * @param status error status returned by getsrvinfo
+ * @return pointer to static NUL-terminated C string containing error message
+ */
+const char *
+gsi_strerror(int status)
+{
+ static char buf[256];
+
+ switch (status) {
+ case ESI_SUCCESS:
+ return "Success";
+ case ESI_NONAME:
+ return "Name not found";
+ case ESI_AGAIN:
+ return "Temporary failure in name resolution";
+ case ESI_FAIL:
+ return "Non-recoverable failure in name resolution";
+ case ESI_NODATA:
+ return "No SRV record returned";
+ case ESI_SERVICE:
+ return "Service is not available";
+ case ESI_MEMORY:
+ return "Memory allocation failure";
+ case ESI_SYSTEM:
+ snprintf(buf, sizeof(buf), "System error (%d): %s",
+ status, strerror(errno));
+ return buf;
+ case ESI_PARSE:
+ return "Failed to parse server response";
+ }
+
+ snprintf(buf, sizeof(buf), "Unknown error (%d)", status);
+ return buf;
+}
+
+/**
+ * Release a list of SRV records allocated by getsrvinfo()
+ *
+ * @param si pointer to first element of a list of struct srvinfo
+ *
+ */
+void freesrvinfo(struct srvinfo *si)
+{
+ struct srvinfo *tmp;
+
+ while (si != NULL) {
+ tmp = si;
+ si = si->si_next;
+ free(tmp->si_target);
+ free(tmp);
+ }
+}
+
+/**
+ * Ordering predicate for srvinfo lists
+ *
+ * @param a a srvinfo list element to compare
+ * @param b another srvinfo list element to compare
+ * @return true if "b" should fall later in the list than "a"
+ *
+ * See RFC 2782. The list is ordered as follows:
+ *
+ * o Lowest priority first.
+ * o In each priority class, highest weight first.
+ */
+static _Bool
+srvinfo_is_after(const struct srvinfo *a, const struct srvinfo *b)
+{
+ if (a->si_priority > b->si_priority)
+ return true;
+ if (a->si_priority < b->si_priority)
+ return false;
+
+ if (a->si_weight < b->si_weight)
+ return true;
+ return false;
+}
+
+/**
+ * Insert a srvinfo element into a list
+ *
+ * @param head pointer to head of list of elements
+ * @param entry new list element to insert
+ *
+ */
+static void
+insert_srvinfo(struct srvinfo **head, struct srvinfo *entry)
+{
+ entry->si_next = *head;
+ *head = entry;
+}
+
+/**
+ * Insert a srvinfo element into a list, in order
+ *
+ * @param head pointer to head of list of elements
+ * @param entry new list element to insert
+ *
+ */
+static void
+insert_srvinfo_sorted(struct srvinfo **head, struct srvinfo *entry)
+{
+ struct srvinfo *spot, *back;
+
+ spot = *head;
+ back = NULL;
+ while (spot && srvinfo_is_after(spot, entry)) {
+ back = spot;
+ spot = spot->si_next;
+ }
+
+ if (spot == (*head))
+ insert_srvinfo(head, entry);
+ else {
+ insert_srvinfo(&spot, entry);
+ /* off the end of the list? */
+ if (spot == entry)
+ back->si_next = entry;
+ }
+}
+
+/**
+ * Retrieve list of SRV records from DNS service
+ *
+ * @param srvname NUL-terminated C string containing record type to look up
+ * @param domainname NUL-terminated C string containing domain name to look up
+ * @param si OUT: list of SRV record information retrieved
+ * @return zero on success, or an ESI_ status code describing the error
+ *
+ * Caller must free list of records using freesrvinfo().
+ */
+int
+getsrvinfo(const char *srvname, const char *domainname, struct srvinfo **si)
+{
+ unsigned char *msg, *eom, *comp_dn;
+ struct srvinfo *results;
+ unsigned short count, i;
+ int status, len;
+ char *exp_dn;
+ HEADER *hdr;
+
+ msg = calloc(1, NS_MAXMSG);
+ exp_dn = calloc(1, NS_MAXDNAME);
+ if (msg == NULL || exp_dn == NULL) {
+ status = ESI_MEMORY;
+ goto out;
+ }
+
+ _res.options |= RES_AAONLY;
+ len = res_querydomain(srvname, domainname, C_IN, T_SRV, msg, NS_MAXMSG);
+ if (len == -1) {
+ switch (h_errno) {
+ case HOST_NOT_FOUND:
+ status = ESI_NONAME;
+ break;
+ case TRY_AGAIN:
+ status = ESI_AGAIN;
+ break;
+ case NO_RECOVERY:
+ status = ESI_FAIL;
+ break;
+ case NO_DATA:
+ status = ESI_NODATA;
+ break;
+ default:
+ fprintf(stderr, "SRV query failed for %s.%s: %s\n",
+ srvname, domainname, hstrerror(h_errno));
+ status = ESI_FAIL;
+ }
+ goto out;
+ }
+
+ hdr = (HEADER *)msg;
+ count = ntohs(hdr->ancount);
+ if (count == 0) {
+ status = ESI_NODATA;
+ goto out;
+ }
+ eom = msg + len;
+
+ comp_dn = &msg[HFIXEDSZ];
+ comp_dn += dn_skipname(comp_dn, eom) + QFIXEDSZ;
+
+ results = NULL;
+ for (i = 0; i < count; i++) {
+ struct srvinfo *new;
+ struct srv *record;
+ int l;
+
+ l = dn_expand(msg, eom, comp_dn, exp_dn, NS_MAXDNAME);
+ if (l == -1) {
+ status = ESI_PARSE;
+ goto out_free;
+ }
+ comp_dn += l;
+
+ record = (struct srv *)&comp_dn[10];
+ comp_dn += 16;
+
+ l = dn_expand(msg, eom, comp_dn, exp_dn, NS_MAXDNAME);
+ if (l == -1) {
+ status = ESI_PARSE;
+ goto out_free;
+ }
+ comp_dn += l;
+
+ if (count == 1 && strcmp(exp_dn, ".") == 0) {
+ status = ESI_SERVICE;
+ goto out_free;
+ }
+
+ new = calloc(1, sizeof(*new));
+ if (new == NULL) {
+ status = ESI_MEMORY;
+ goto out;
+ }
+
+ new->si_target = strdup(exp_dn);
+ if (new->si_target == NULL) {
+ free(new);
+ status = ESI_MEMORY;
+ goto out;
+ }
+ new->si_priority = ntohs(record->priority);
+ new->si_weight = ntohs(record->weight);
+ new->si_port = ntohs(record->port);
+
+ insert_srvinfo_sorted(&results, new);
+ }
+
+ status = ESI_SUCCESS;
+ *si = results;
+
+out:
+ free(exp_dn);
+ free(msg);
+ return status;
+
+out_free:
+ freesrvinfo(results);
+ goto out;
+}
diff --git a/fedfs/fedfs-getsrvinfo.h b/fedfs/fedfs-getsrvinfo.h
new file mode 100644
index 00000000..13170359
--- /dev/null
+++ b/fedfs/fedfs-getsrvinfo.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2011 Oracle. All rights reserved.
+ *
+ * This file is part of fedfs-utils.
+ *
+ * fedfs-utils is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0 as
+ * published by the Free Software Foundation.
+ *
+ * fedfs-utils is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License version 2.0 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2.0 along with fedfs-utils. If not, see:
+ *
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
+ */
+
+#ifndef _FEDFS_GETSRVINFO_H_
+#define _FEDFS_GETSRVINFO_H_
+
+/**
+ * Single list element containing SRV record data
+ */
+struct srvinfo {
+ struct srvinfo *si_next;
+ char *si_target;
+ unsigned short si_priority;
+ unsigned short si_weight;
+ unsigned short si_port;
+};
+
+enum {
+ ESI_SUCCESS = 0,
+ ESI_NONAME = -2,
+ ESI_AGAIN = -3,
+ ESI_FAIL = -4,
+ ESI_NODATA = -5,
+ ESI_SERVICE = -8,
+ ESI_MEMORY = -10,
+ ESI_SYSTEM = -11,
+ ESI_PARSE = -1000,
+};
+
+int getsrvinfo(const char *srvname, const char *domainname,
+ struct srvinfo **si);
+void freesrvinfo(struct srvinfo *si);
+const char *gsi_strerror(int status);
+
+#endif /* !_FEDFS_GETSRVINFO_H_ */

View File

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

View File

@ -0,0 +1,696 @@
autofs-5.1.4 - add mount.fedfs.c
From: Ian Kent <raven@themaw.net>
Add build and install of the mount.fedfs binary.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1
Makefile | 3
Makefile.rules | 2
autofs.spec | 1
fedfs/Makefile | 36 +++
fedfs/fedfs-gpl-boiler.h | 40 ++++
fedfs/fedfs-nls.h | 38 ++++
fedfs/mount.fedfs.c | 485 ++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 605 insertions(+), 1 deletion(-)
create mode 100644 fedfs/Makefile
create mode 100644 fedfs/fedfs-gpl-boiler.h
create mode 100644 fedfs/fedfs-nls.h
create mode 100644 fedfs/mount.fedfs.c
diff --git a/CHANGELOG b/CHANGELOG
index 8d6c737c..88992147 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -15,6 +15,7 @@ xx/xx/2018 autofs-5.1.5
- dont allow trailing slash in master map mount points.
- fix libresolv configure check.
- add fedfs-getsrvinfo.c.
+- add mount.fedfs.c.
19/12/2017 autofs-5.1.4
- fix spec file url.
diff --git a/Makefile b/Makefile
index e560a7cb..99db2c75 100644
--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,9 @@ kernel:
samples:
set -e; if [ -d samples ]; then $(MAKE) -C samples all; fi
+fedfs:
+ set -e; if [ -d fedfs ]; then $(MAKE) -C fedfs all; fi
+
clean:
for i in $(SUBDIRS) samples; do \
if [ -d $$i ]; then $(MAKE) -C $$i clean; fi; done
diff --git a/Makefile.rules b/Makefile.rules
index 4deab3b9..fc9f6019 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -3,7 +3,7 @@
#
# Root directory contents
-SUBDIRS = lib daemon modules man
+SUBDIRS = lib daemon fedfs modules man
INCDIRS = include
INCFILES = COPYING COPYRIGHT NEWS README* TODO Makefile Makefile.rules \
Makefile.conf.in .version .autofs-* configure.in aclocal.m4 \
diff --git a/autofs.spec b/autofs.spec
index 2464e741..2cc0e38f 100644
--- a/autofs.spec
+++ b/autofs.spec
@@ -191,6 +191,7 @@ fi
%config(noreplace) /etc/sysconfig/autofs
%config(noreplace) /etc/autofs_ldap_auth.conf
%{_sbindir}/automount
+%{_sbindir}/mount.fedfs
%dir %{_libdir}/autofs
%{_libdir}/autofs/*
%{_mandir}/*/*
diff --git a/fedfs/Makefile b/fedfs/Makefile
new file mode 100644
index 00000000..cb325bed
--- /dev/null
+++ b/fedfs/Makefile
@@ -0,0 +1,36 @@
+#
+# Makefile for mount.fedfs
+#
+
+-include ../Makefile.conf
+include ../Makefile.rules
+
+SRCS = mount.fedfs.c
+HDRS = fedfs-getsrvinfo.h fedfs-gpl-boiler.h fedfs-nls.h
+
+fedfs-getsrvinfo_OBJ = fedfs-getsrvinfo.o
+
+mount_fedfs_OBJ = mount.fedfs.o
+
+version := $(shell cat ../.version)
+
+CFLAGS += -rdynamic $(DAEMON_CFLAGS) -D_GNU_SOURCE -I../include
+CFLAGS += -DVERSION_STRING=\"$(version)\"
+LDFLAGS += -rdynamic
+
+all: mount.fedfs
+
+mount.fedfs: $(mount_fedfs_OBJ) $(fedfs-getsrvinfo_OBJ) $(HDRS)
+ $(CC) -o mount.fedfs \
+ $(mount_fedfs_OBJ) $(fedfs-getsrvinfo_OBJ) \
+ $(LDFLAGS) $(LIBRESOLV) $(LIBS)
+
+clean:
+ rm -f *.o *.s *~ mount.fedfs
+
+install: all
+ install -d -m 755 $(INSTALLROOT)$(sbindir)
+ if ! test -x $(INSTALLROOT)$(sbindir)/mount.fedfs; \
+ then \
+ install -c mount.fedfs -m 755 $(INSTALLROOT)$(sbindir); \
+ fi
diff --git a/fedfs/fedfs-gpl-boiler.h b/fedfs/fedfs-gpl-boiler.h
new file mode 100644
index 00000000..1353e736
--- /dev/null
+++ b/fedfs/fedfs-gpl-boiler.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2011 Oracle. All rights reserved.
+ *
+ * This file is part of fedfs-utils.
+ *
+ * fedfs-utils is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0 as
+ * published by the Free Software Foundation.
+ *
+ * fedfs-utils is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License version 2.0 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2.0 along with fedfs-utils. If not, see:
+ *
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
+ */
+
+#ifndef _GPL_BOILER_H_
+#define _GPL_BOILER_H_
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/**
+ * GPLv2 boilerplate for usage messages
+ */
+static const char *fedfs_gpl_boilerplate =
+ "\nCopyright 2010, 2011, 2012, 2013 Oracle. "
+ "All rights reserved.\n\n"
+ "License GPLv2: "
+ "<http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>\n"
+ "This is free software. "
+ "You are free to change and redistribute it.\n"
+ "There is NO WARRANTY, to the extent permitted by law.\n";
+
+#endif /* !_GPL_BOILER_H_ */
diff --git a/fedfs/fedfs-nls.h b/fedfs/fedfs-nls.h
new file mode 100644
index 00000000..92f968d3
--- /dev/null
+++ b/fedfs/fedfs-nls.h
@@ -0,0 +1,38 @@
+/*
+ * From util-linux/include/nls.h (GPLv2)
+ */
+
+#ifndef UTIL_LINUX_NLS_H
+#define UTIL_LINUX_NLS_H
+
+int main(int argc, char *argv[]);
+
+#ifndef LOCALEDIR
+#define LOCALEDIR "/usr/share/locale"
+#endif
+
+#ifdef HAVE_LOCALE_H
+# include <locale.h>
+#else
+# undef setlocale
+# define setlocale(Category, Locale) ({}) /* empty */
+#endif
+
+#ifdef ENABLE_NLS
+# include <libintl.h>
+# define _(Text) gettext (Text)
+# ifdef gettext_noop
+# define N_(String) gettext_noop (String)
+# else
+# define N_(String) (String)
+# endif
+#else
+# undef bindtextdomain
+# define bindtextdomain(Domain, Directory) /* empty */
+# undef textdomain
+# define textdomain(Domain) /* empty */
+# define _(Text) (Text)
+# define N_(Text) (Text)
+#endif
+
+#endif /* UTIL_LINUX_NLS_H */
diff --git a/fedfs/mount.fedfs.c b/fedfs/mount.fedfs.c
new file mode 100644
index 00000000..bd434395
--- /dev/null
+++ b/fedfs/mount.fedfs.c
@@ -0,0 +1,485 @@
+/*
+ * Copyright 2011 Oracle. All rights reserved.
+ *
+ * This file is part of fedfs-utils.
+ *
+ * fedfs-utils is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0 as
+ * published by the Free Software Foundation.
+ *
+ * fedfs-utils is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License version 2.0 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2.0 along with fedfs-utils. If not, see:
+ *
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <sys/mount.h>
+#include <sys/wait.h>
+
+#include <stdbool.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <libgen.h>
+#include <errno.h>
+#include <getopt.h>
+#include <locale.h>
+#include <netdb.h>
+#include <langinfo.h>
+
+#include "fedfs-nls.h"
+#include "fedfs-getsrvinfo.h"
+#include "fedfs-gpl-boiler.h"
+
+/**
+ * Top-level directory on client under which we mount NFSv4 domain roots
+ */
+#define FEDFS_NFS4_TLDIR "nfs4"
+
+/**
+ * Name of SRV record containing NFSv4 FedFS root
+ */
+#define FEDFS_NFS_DOMAINROOT "_nfs-domainroot._tcp"
+
+/**
+ * Export path of NFSv4 FedFS root
+ */
+#define FEDFS_NFS_EXPORTPATH "/.domainroot"
+
+/**
+ * Pathname to mount.nfs
+ */
+#define MOUNT_NFS_EXECUTABLE "/sbin/mount.nfs"
+
+/**
+ * Mount status values, lifted from util-linux
+ */
+enum {
+ EX_SUCCESS = 0,
+ EX_USAGE = 1,
+ EX_FAIL = 32,
+};
+
+static char *progname;
+static int nomtab;
+static int verbose;
+static _Bool readonly;
+static _Bool sloppy;
+static _Bool fake;
+
+/**
+ * Short form command line options
+ */
+static const char fedfs_opts[] = "fhno:rsvVw";
+
+/**
+ * Long form command line options
+ */
+static const struct option fedfs_longopts[] =
+{
+ { "fake", 0, NULL, 'f' },
+ { "help", 0, NULL, 'h' },
+ { "no-mtab", 0, NULL, 'n' },
+ { "options", 1, NULL, 'o' },
+ { "read-only", 0, NULL, 'r' },
+ { "read-write", 0, NULL, 'w' },
+ { "ro", 0, NULL, 'r' },
+ { "rw", 0, NULL, 'w' },
+ { "sloppy", 0, NULL, 's' },
+ { "verbose", 0, NULL, 'v' },
+ { "version", 0, NULL, 'V' },
+ { NULL, 0, NULL, 0 }
+};
+
+/**
+ * Display mount.fedfs usage message
+ */
+static void
+mount_usage(void)
+{
+ printf(_("\nUsage: %s remotedir localdir [-fhnrsvVw]\n\n"), progname);
+ printf(_("options:\n"));
+ printf(_("\t-f\t\tFake mount, do not actually mount\n"));
+ printf(_("\t-h\t\tPrint this help\n"));
+ printf(_("\t-n\t\tDo not update /etc/mtab\n"));
+ printf(_("\t-r\t\tMount file system readonly\n"));
+ printf(_("\t-s\t\tTolerate sloppy mount options\n"));
+ printf(_("\t-v\t\tVerbose\n"));
+ printf(_("\t-V\t\tPrint version\n"));
+ printf(_("\t-w\t\tMount file system read-write\n"));
+
+ printf("%s", fedfs_gpl_boilerplate);
+}
+
+/**
+ * Concatenate three strings
+ *
+ * @param s NUL-terminated C string
+ * @param t NUL-terminated C string
+ * @param u NUL-terminated C string
+ * @return pointer to NUL-terminated C string or NULL
+ *
+ * Caller must free the returned string with free(3). Always frees
+ * its first arg - typical use: s = xstrconcat3(s,t,u);
+ *
+ * Lifted from util-linux.
+ */
+static char *
+xstrconcat3(char *s, const char *t, const char *u)
+{
+ _Bool free_s = true;
+ char *result;
+
+ if (s == NULL) {
+ s = "";
+ free_s = false;
+ }
+ if (t == NULL)
+ t = "";
+ if (u == NULL)
+ u = "";
+ result = malloc(strlen(s) + strlen(t) + strlen(u) + 1);
+ if (result == NULL)
+ goto out;
+
+ strcpy(result, s);
+ strcat(result, t);
+ strcat(result, u);
+
+out:
+ if (free_s)
+ free(s);
+ return result;
+}
+
+/**
+ * Exec mount.nfs
+ *
+ * @param server NUL-terminated C string containing name of NFS server
+ * @param port server port to use when mounting
+ * @param domainname NUL-terminated C string containing FedFS domain name
+ * @param export_path NUL-terminated C string containing server export path
+ * @param mounted_on_dir NUL-terminated C string containing local mounted-on directory
+ * @param text_options NUL-terminated C string containing user's mount options
+ *
+ */
+static void
+exec_mount_nfs4(const char *server, unsigned short port,
+ const char *domainname, const char *export_path,
+ const char *mounted_on_dir, const char *text_options)
+{
+ static char special[2048];
+ static char options[2048];
+ char *args[16];
+ int count = 0;
+
+ snprintf(special, sizeof(special), "%s:%s/%s%s", server,
+ FEDFS_NFS_EXPORTPATH, domainname, export_path);
+
+ if (text_options != NULL && strcmp(text_options, "") != 0)
+ snprintf(options, sizeof(options), "%s,vers=4,fg,port=%u",
+ text_options, port);
+ else
+ snprintf(options, sizeof(options), "vers=4,fg,port=%u", port);
+
+ if (verbose) {
+ printf(_("%s: Special device: %s\n"),
+ progname, special);
+ printf(_("%s: Mounted-on directory: %s\n"),
+ progname, mounted_on_dir);
+ printf(_("%s: Mount options: %s\n"),
+ progname, options);
+ }
+
+ args[count++] = MOUNT_NFS_EXECUTABLE;
+ args[count++] = special;
+ args[count++] = (char *)mounted_on_dir;
+ if (verbose)
+ args[count++] = "-v";
+ if (fake)
+ args[count++] = "-f";
+ if (nomtab)
+ args[count++] = "-n";
+ if (readonly)
+ args[count++] = "-r";
+ if (sloppy)
+ args[count++] = "-s";
+ args[count++] = "-o";
+ args[count++] = options;
+
+ args[count] = NULL;
+ execv(args[0], args);
+}
+
+/**
+ * Mount a FedFS domain root via NFSv4
+ *
+ * @param domainname NUL-terminated C string containing FedFS domain name
+ * @param export_path NUL-terminated C string containing server export path
+ * @param mounted_on_dir NUL-terminated C string containing local mounted-on directory
+ * @param text_options NUL-terminated C string containing user's mount options
+ * @return exit status code from the mount.nfs command
+ *
+ * Construct the server:/export string and the mounted-on directory string
+ * based on the DNS SRV query results, then fork and exec mount.nfs to do
+ * the actual mount request.
+ */
+static int
+nfs4_mount(const char *domainname, const char *export_path,
+ const char *mounted_on_dir, const char *text_options)
+{
+ struct srvinfo *tmp, *si = NULL;
+ int error, status;
+
+ status = EX_FAIL;
+
+ error = getsrvinfo(FEDFS_NFS_DOMAINROOT, domainname, &si);
+ switch (error) {
+ case ESI_SUCCESS:
+ break;
+ case ESI_NONAME:
+ fprintf(stderr, _("%s: Domain name %s not found\n"),
+ progname, domainname);
+ goto out;
+ case ESI_SERVICE:
+ fprintf(stderr, _("%s: No FedFS domain root available for %s\n"),
+ progname, domainname);
+ goto out;
+ default:
+ fprintf(stderr, _("%s: Failed to resolve %s: %s\n"),
+ progname, domainname, gsi_strerror(error));
+ goto out;
+ }
+
+ /*
+ * The srvinfo list is already in RFC 2782 sorted order. Try each
+ * SRV record once, in the foreground. Go with the first one that
+ * works.
+ */
+ for (tmp = si; tmp != NULL; tmp = tmp->si_next) {
+ pid_t pid;
+
+ pid = fork();
+ switch (pid) {
+ case 0:
+ exec_mount_nfs4(tmp->si_target, tmp->si_port,
+ domainname, export_path, mounted_on_dir,
+ text_options);
+ /*NOTREACHED*/
+ fprintf(stderr, _("%s: Failed to exec: %s\n"),
+ progname, strerror(errno));
+ exit(EX_FAIL);
+ case -1:
+ fprintf(stderr, _("%s: Failed to fork: %s\n"),
+ progname, strerror(errno));
+ goto out;
+ default:
+ waitpid(pid, &status, 0);
+ if (status == EX_SUCCESS)
+ goto out;
+ }
+ }
+
+out:
+ freesrvinfo(si);
+ return status;
+}
+
+/**
+ * Try one mount request
+ *
+ * @param source NUL-terminated C string containing name of "special device"
+ * @param target NUL-terminated C string containing local mounted-on directory
+ * @param text_options NUL-terminated C string containing user's mount options
+ * @return an exit status code
+ *
+ * Parse the pathname in "source." It contains the file system protocol
+ * and FedFS domain name. Then pass these arguments to the appropriate
+ * mount helper subcommand.
+ */
+static int
+try_mount(const char *source, const char *target, const char *text_options)
+{
+ char *global_name, *topdir, *domainname, *remaining;
+ int result;
+
+ remaining = NULL;
+ result = EX_FAIL;
+
+ global_name = strdup(source);
+ if (global_name == NULL) {
+ fprintf(stderr, _("%s: Unable to parse globally useful name\n"),
+ progname);
+ goto out;
+ }
+
+ topdir = strtok(global_name, "/");
+ if (topdir == NULL) {
+ fprintf(stderr, _("%s: Invalid globally useful name: %s\n"),
+ progname, source);
+ goto out;
+ }
+ if (verbose)
+ printf(_("%s: Top-level directory: %s\n"),
+ progname, topdir);
+
+ domainname = strtok(NULL, "/");
+ if (domainname == NULL) {
+ fprintf(stderr, _("%s: Missing domain name in globally "
+ "useful name: %s\n"), progname, source);
+ goto out;
+ }
+ if (verbose)
+ printf(_("%s: Domain name: %s\n"),
+ progname, domainname);
+
+ remaining = strtok(NULL, "/");
+ if (remaining == NULL) {
+ remaining = strdup("/");
+ if (remaining == NULL) {
+ fprintf(stderr, _("%s: No memory\n"), progname);
+ goto out;
+ }
+ } else {
+ char *tmp;
+
+ tmp = malloc(strlen(remaining) + 1);
+ if (tmp == NULL) {
+ fprintf(stderr, _("%s: No memory\n"), progname);
+ remaining = NULL;
+ goto out;
+ }
+ strcpy(tmp, "/");
+ strcat(tmp, remaining);
+ remaining = tmp;
+ }
+ if (verbose)
+ printf(_("%s: Export path: %s\n"),
+ progname, remaining);
+
+ if (strcmp(topdir, FEDFS_NFS4_TLDIR) == 0)
+ result = nfs4_mount(domainname, remaining, target, text_options);
+#if 0
+ /* example: SMB support plugs in here */
+ else if (strcmp(topdir, FEDFS_SMB_TLDIR) == 0)
+ result = smb_mount(domainname, remaining, target, text_options);
+#endif
+ else
+ fprintf(stderr, _("%s: Unrecognized file system protocol\n"), progname);
+
+out:
+ free(global_name);
+ free(remaining);
+
+ return result;
+}
+
+/**
+ * Program entry point
+ *
+ * @param argc count of command line arguments
+ * @param argv array of NUL-terminated C strings containing command line arguments
+ * @return program exit status
+ */
+int main(int argc, char *argv[])
+{
+ char *source, *target, *text_options;
+ int c, mnt_err;
+
+ (void)setlocale(LC_ALL, "");
+
+ progname = basename(argv[0]);
+
+ if (argv[1] && argv[1][0] == '-') {
+ if(argv[1][1] == 'V')
+ printf("%s (VERSION_STRING)\n", progname);
+ else
+ mount_usage();
+ exit(EX_SUCCESS);
+ }
+
+ if (argc < 3) {
+ mount_usage();
+ exit(EX_USAGE);
+ }
+
+ source = argv[1];
+ target = argv[2];
+
+ mnt_err = EX_USAGE;
+ text_options = NULL;
+ readonly = false;
+ sloppy = false;
+ fake = false;
+ argv[2] = argv[0]; /* so that getopt error messages are correct */
+ while ((c = getopt_long(argc - 2, argv + 2, fedfs_opts,
+ fedfs_longopts, NULL)) != -1) {
+ switch (c) {
+ case 'f':
+ fake = true;
+ break;
+ case 'n':
+ ++nomtab;
+ break;
+ case 'o':
+ /* Ugh. */
+ if (text_options != NULL)
+ text_options = xstrconcat3(text_options, ",", optarg);
+ else
+ text_options = strdup(optarg);
+ if (text_options == NULL) {
+ fprintf(stderr, _("%s: No memory\n"), progname);
+ goto out;
+ }
+ break;
+ case 'r':
+ readonly = true;
+ break;
+ case 's':
+ sloppy = true;
+ break;
+ case 'v':
+ ++verbose;
+ break;
+ case 'V':
+ printf("%s: (VERSION_STRING)\n", progname);
+ mnt_err = EX_SUCCESS;
+ goto out;
+ case 'w':
+ readonly = false;
+ break;
+ case 'h':
+ default:
+ mount_usage();
+ goto out;
+ }
+ }
+
+ /* Extra non-option words at the end are bogus... */
+ if (optind != argc - 2) {
+ mount_usage();
+ goto out;
+ }
+
+ if (getuid() != 0 && geteuid() != 0) {
+ fprintf(stderr, _("%s: Not installed setuid - "
+ "\"user\" FedFS mounts are not supported\n"), progname);
+ mnt_err = EX_FAIL;
+ goto out;
+ }
+
+ mnt_err = try_mount(source, target, text_options);
+
+out:
+ free(text_options);
+ exit(mnt_err);
+}

View File

@ -0,0 +1,48 @@
autofs-5.1.4 - dont allow trailing slash in master map mount points
From: Ian Kent <raven@themaw.net>
If a master map mount point path has a trailing '/' this can cause
problems so remove them at parse time.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
lib/master_parse.y | 5 +++++
2 files changed, 6 insertions(+)
diff --git a/CHANGELOG b/CHANGELOG
index 1e5ec15b..a7bb89dc 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -12,6 +12,7 @@ xx/xx/2018 autofs-5.1.5
- use_hostname_for_mounts shouldn't prevent selection among replicas.
- fix monotonic_elapsed.
- Makefiles.rules: remove 'samples' from SUBDIRS.
+- dont allow trailing slash in master map mount points.
19/12/2017 autofs-5.1.4
- fix spec file url.
diff --git a/lib/master_parse.y b/lib/master_parse.y
index 42e03c2d..761ade9b 100644
--- a/lib/master_parse.y
+++ b/lib/master_parse.y
@@ -749,6 +749,7 @@ int master_parse_entry(const char *buffer, unsigned int default_timeout, unsigne
struct map_source *source;
unsigned int logopt = logging;
unsigned int m_logopt = master->logopt;
+ size_t mp_len;
int ret;
local_init_vars();
@@ -763,6 +764,10 @@ int master_parse_entry(const char *buffer, unsigned int default_timeout, unsigne
return 0;
}
+ mp_len = strlen(path);
+ while (mp_len && path[--mp_len] == '/')
+ path[mp_len] = 0;
+
nc = master->nc;
/* Add null map entries to the null map cache */

View File

@ -0,0 +1,94 @@
autofs-5.1.4 - fix libresolv configure check
From: Ian Kent <raven@themaw.net>
The libresolv functions are not found by AC_CHECK_LIB() unless
they are prefixed with "__".
So change the library check to also look for __<function> during
the check.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
configure | 41 +++++++++++++++++++++++++++++++++++++++++
configure.in | 2 +-
3 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG b/CHANGELOG
index a7bb89dc..dbfb8389 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -13,6 +13,7 @@ xx/xx/2018 autofs-5.1.5
- fix monotonic_elapsed.
- Makefiles.rules: remove 'samples' from SUBDIRS.
- dont allow trailing slash in master map mount points.
+- fix libresolv configure check.
19/12/2017 autofs-5.1.4
- fix spec file url.
diff --git a/configure b/configure
index 2d517aac..5c8aae30 100755
--- a/configure
+++ b/configure
@@ -4821,6 +4821,47 @@ fi
$as_echo "$ac_cv_lib_resolv_res_query" >&6; }
if test "x$ac_cv_lib_resolv_res_query" = xyes; then :
LIBRESOLV="-lresolv"
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for __res_query in -lresolv" >&5
+$as_echo_n "checking for __res_query in -lresolv... " >&6; }
+if ${ac_cv_lib_resolv___res_query+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_check_lib_save_LIBS=$LIBS
+LIBS="-lresolv $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char __res_query ();
+int
+main ()
+{
+return __res_query ();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_lib_resolv___res_query=yes
+else
+ ac_cv_lib_resolv___res_query=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_resolv___res_query" >&5
+$as_echo "$ac_cv_lib_resolv___res_query" >&6; }
+if test "x$ac_cv_lib_resolv___res_query" = xyes; then :
+ LIBRESOLV="-lresolv"
+fi
+
fi
diff --git a/configure.in b/configure.in
index d74775cc..4d1208f5 100644
--- a/configure.in
+++ b/configure.in
@@ -217,7 +217,7 @@ AC_SUBST(NSL_LIBS)
NSL_CFLAGS=""
])
-AC_CHECK_LIB(resolv, res_query, LIBRESOLV="-lresolv")
+AC_CHECK_LIB(resolv, res_query, LIBRESOLV="-lresolv", AC_CHECK_LIB(resolv, __res_query, LIBRESOLV="-lresolv"))
AC_SUBST(LIBRESOLV)
#

View File

@ -8,7 +8,7 @@
Summary: A tool for automatically mounting and unmounting filesystems
Name: autofs
Version: 5.1.4
Release: 11%{?dist}
Release: 12%{?dist}
Epoch: 1
License: GPLv2+
Group: System Environment/Daemons
@ -26,6 +26,13 @@ Patch10: autofs-5.1.4-account-for-libnsl-changes.patch
Patch11: autofs-5.1.4-use_hostname_for_mounts-shouldnt-prevent-selection-among-replicas.patch
Patch12: autofs-5.1.4-fix-monotonic_elapsed.patch
Patch13: autofs-5.1.4-Makefiles.rules-remove-samples-from-SUBDIRS.patch
Patch14: autofs-5.1.4-dont-allow-trailing-slash-in-master-map-mount-points.patch
Patch15: autofs-5.1.4-fix-libresolv-configure-check.patch
Patch16: autofs-5.1.4-add-fedfs-getsrvinfo_c.patch
Patch17: autofs-5.1.4-add-mount_fedfs_c.patch
Patch18: autofs-5.1.4-add-fedfs-map-nfs4_c.patch
Patch19: autofs-5.1.4-add-conditional-inclusion-of-fedfs-binaries.patch
Patch20: autofs-5.1.4-add-an-example-fedfs-master-map-entry-to-the-installed-master-map.patch
%if %{with_systemd}
BuildRequires: systemd-units
@ -98,6 +105,13 @@ echo %{version}-%{release} > .version
%patch11 -p1
%patch12 -p1
%patch13 -p1
%patch14 -p1
%patch15 -p1
%patch16 -p1
%patch17 -p1
%patch18 -p1
%patch19 -p1
%patch20 -p1
%build
LDFLAGS=-Wl,-z,now
@ -192,6 +206,15 @@ fi
%dir /etc/auto.master.d
%changelog
* Mon Feb 19 2018 Ian Kent <ikent@redhat.com> - 1:5.1.4-12
- dont allow trailing slash in master map mount points.
- fix libresolv configure check.
- add fedfs-getsrvinfo.c.
- add mount.fedfs.c.
- add fedfs-map-nfs4.c
- add conditional inclusion of fedfs binaries.
- add an example fedfs master map entry to the installed master map.
* Fri Feb 09 2018 Igor Gnatenko <ignatenkobrain@fedoraproject.org> - 1:5.1.4-11
- Escape macros in %%changelog