Blame SOURCES/nfs-utils-1.3.0-server-chgrpcpipefs.patch

64c563
diff --git a/.gitignore b/.gitignore
64c563
index 3d9640d..d26f4be 100644
64c563
--- a/.gitignore
64c563
+++ b/.gitignore
64c563
@@ -70,6 +70,8 @@ tests/nsm_client/nlm_sm_inter_svc.c
64c563
 tests/nsm_client/nlm_sm_inter_xdr.c
64c563
 utils/nfsidmap/nfsidmap
64c563
 systemd/nfs-server-generator
64c563
+systemd/rpc-pipefs-generator
64c563
+systemd/rpc-gssd.service
64c563
 # cscope database files
64c563
 cscope.*
64c563
 # generic editor backup et al
64c563
diff --git a/configure.ac b/configure.ac
64c563
index 3bce774..fce0e15 100644
64c563
--- a/configure.ac
64c563
+++ b/configure.ac
64c563
@@ -498,8 +498,14 @@ AC_SUBST([AM_CFLAGS], ["$my_am_cflags"])
64c563
 # Make sure that $ACLOCAL_FLAGS are used during a rebuild
64c563
 AC_SUBST([ACLOCAL_AMFLAGS], ["-I $ac_macro_dir \$(ACLOCAL_FLAGS)"])
64c563
 
64c563
+# make _sysconfdir available for substituion in config files
64c563
+# 2 "evals" needed late to expand variable names.
64c563
+AC_SUBST([_sysconfdir])
64c563
+AC_CONFIG_COMMANDS_PRE([eval eval _sysconfdir=$sysconfdir])
64c563
+
64c563
 AC_CONFIG_FILES([
64c563
 	Makefile
64c563
+	systemd/rpc-gssd.service
64c563
 	linux-nfs/Makefile
64c563
 	support/Makefile
64c563
 	support/export/Makefile
64c563
diff --git a/nfs.conf b/nfs.conf
64c563
index c907de6..89cf386 100644
64c563
--- a/nfs.conf
64c563
+++ b/nfs.conf
64c563
@@ -1,7 +1,10 @@
64c563
 #
64c563
-# This is a general conifguration for the 
64c563
+# This is a general configuration for the
64c563
 # NFS daemons and tools
64c563
 #
64c563
+#[general]
64c563
+# pipefs-directory=/var/lib/nfs/rpc_pipefs
64c563
+#
64c563
 #[exportfs]
64c563
 # debug=0
64c563
 #
64c563
@@ -12,7 +15,6 @@
64c563
 # limit-to-legacy-enctypes=0
64c563
 # context-timeout=0
64c563
 # rpc-timeout=5
64c563
-# pipefs-directory=/var/lib/nfs/rpc_pipefs
64c563
 # keytab-file=/etc/krb5.keytab
64c563
 # cred-cache-directory=
64c563
 # preferred-realm=
64c563
diff --git a/support/include/xcommon.h b/support/include/xcommon.h
64c563
index d1a4b18..23c9a13 100644
64c563
--- a/support/include/xcommon.h
64c563
+++ b/support/include/xcommon.h
64c563
@@ -17,6 +17,12 @@
64c563
 #include <stdlib.h>
64c563
 #include <string.h>
64c563
 
64c563
+#ifdef MAJOR_IN_MKDEV
64c563
+#include <sys/mkdev.h>
64c563
+#elif defined(MAJOR_IN_SYSMACROS)
64c563
+#include <sys/sysmacros.h>
64c563
+#endif
64c563
+
64c563
 #define streq(s, t)	(strcmp ((s), (t)) == 0)
64c563
 
64c563
 /* Functions in sundries.c that are used in mount.c and umount.c  */ 
64c563
diff --git a/support/nfs/nfsexport.c b/support/nfs/nfsexport.c
64c563
index f129fd2..c1c736e 100644
64c563
--- a/support/nfs/nfsexport.c
64c563
+++ b/support/nfs/nfsexport.c
64c563
@@ -18,6 +18,7 @@
64c563
 #include <fcntl.h>
64c563
 
64c563
 #include "nfslib.h"
64c563
+#include "xcommon.h"
64c563
 
64c563
 	/* if /proc/net/rpc/... exists, then 
64c563
 	 * write to it, as that interface is more stable.
64c563
diff --git a/systemd/Makefile.am b/systemd/Makefile.am
64c563
index b789916..54a3b64 100644
64c563
--- a/systemd/Makefile.am
64c563
+++ b/systemd/Makefile.am
64c563
@@ -8,6 +8,7 @@ unit_files =  \
64c563
     nfs-blkmap.service \
64c563
     nfs-config.service \
64c563
     nfs-idmapd.service \
64c563
+    rpc_pipefs.target \
64c563
     nfs-mountd.service \
64c563
     nfs-server.service \
64c563
     nfs-utils.service \
64c563
@@ -24,14 +25,23 @@ EXTRA_DIST = $(unit_files) $(man5_MANS) $(man7_MANS)
64c563
 unit_dir = /usr/lib/systemd/system
64c563
 generator_dir = /usr/lib/systemd/system-generators
64c563
 
64c563
-EXTRA_PROGRAMS	= nfs-server-generator
64c563
+EXTRA_PROGRAMS	= nfs-server-generator rpc-pipefs-generator
64c563
 genexecdir = $(generator_dir)
64c563
+
64c563
+COMMON_SRCS = systemd.c systemd.h
64c563
+
64c563
+nfs_server_generator_SOURCES = $(COMMON_SRCS) nfs-server-generator.c
64c563
+
64c563
+rpc_pipefs_generator_SOURCES = $(COMMON_SRCS) rpc-pipefs-generator.c
64c563
+
64c563
 nfs_server_generator_LDADD = ../support/export/libexport.a \
64c563
 			     ../support/nfs/libnfs.a \
64c563
 			     ../support/misc/libmisc.a
64c563
 
64c563
+rpc_pipefs_generator_LDADD = ../support/nfs/libnfs.a
64c563
+
64c563
 if INSTALL_SYSTEMD
64c563
-genexec_PROGRAMS = nfs-server-generator
64c563
+genexec_PROGRAMS = nfs-server-generator rpc-pipefs-generator
64c563
 install-data-hook: $(unit_files)
64c563
 	mkdir -p $(DESTDIR)/$(unitdir)
64c563
 	cp $(unit_files) $(DESTDIR)/$(unitdir)
64c563
diff --git a/systemd/nfs-blkmap.service b/systemd/nfs-blkmap.service
64c563
index ddbf4e9..c844e2d 100644
64c563
--- a/systemd/nfs-blkmap.service
64c563
+++ b/systemd/nfs-blkmap.service
64c563
@@ -2,8 +2,8 @@
64c563
 Description=pNFS block layout mapping daemon
64c563
 DefaultDependencies=no
64c563
 Conflicts=umount.target
64c563
-After=var-lib-nfs-rpc_pipefs.mount
64c563
-Requires=var-lib-nfs-rpc_pipefs.mount
64c563
+After=rpc_pipefs.target
64c563
+Requires=rpc_pipefs.target
64c563
 
64c563
 PartOf=nfs-utils.service
64c563
 
64c563
diff --git a/systemd/nfs-idmapd.service b/systemd/nfs-idmapd.service
64c563
index df3dd9d..38685b6 100644
64c563
--- a/systemd/nfs-idmapd.service
64c563
+++ b/systemd/nfs-idmapd.service
64c563
@@ -1,8 +1,8 @@
64c563
 [Unit]
64c563
 Description=NFSv4 ID-name mapping service
64c563
 DefaultDependencies=no
64c563
-Requires=var-lib-nfs-rpc_pipefs.mount
64c563
-After=var-lib-nfs-rpc_pipefs.mount local-fs.target
64c563
+Requires=rpc_pipefs.target
64c563
+After=rpc_pipefs.target local-fs.target
64c563
 
64c563
 BindsTo=nfs-server.service
64c563
 
64c563
diff --git a/systemd/nfs-server-generator.c b/systemd/nfs-server-generator.c
64c563
index 4aa6509..737f109 100644
64c563
--- a/systemd/nfs-server-generator.c
64c563
+++ b/systemd/nfs-server-generator.c
64c563
@@ -29,6 +29,7 @@
64c563
 #include "misc.h"
64c563
 #include "nfslib.h"
64c563
 #include "exportfs.h"
64c563
+#include "systemd.h"
64c563
 
64c563
 /* A simple "set of strings" to remove duplicates
64c563
  * found in /etc/exports
64c563
@@ -55,35 +56,6 @@ static int is_unique(struct list **lp, char *path)
64c563
 	return 1;
64c563
 }
64c563
 
64c563
-/* We need to convert a path name to a systemd unit
64c563
- * name.  This requires some translation ('/' -> '-')
64c563
- * and some escaping.
64c563
- */
64c563
-static void systemd_escape(FILE *f, char *path)
64c563
-{
64c563
-	while (*path == '/')
64c563
-		path++;
64c563
-	if (!*path) {
64c563
-		/* "/" becomes "-", otherwise leading "/" is ignored */
64c563
-		fputs("-", f);
64c563
-		return;
64c563
-	}
64c563
-	while (*path) {
64c563
-		char c = *path++;
64c563
-
64c563
-		if (c == '/') {
64c563
-			/* multiple non-trailing slashes become '-' */
64c563
-			while (*path == '/')
64c563
-				path++;
64c563
-			if (*path)
64c563
-				fputs("-", f);
64c563
-		} else if (isalnum(c) || c == ':' || c == '.')
64c563
-			fputc(c, f);
64c563
-		else
64c563
-			fprintf(f, "\\x%02x", c & 0xff);
64c563
-	}
64c563
-}
64c563
-
64c563
 static int has_noauto_flag(char *path)
64c563
 {
64c563
 	FILE		*fstab;
64c563
@@ -108,7 +80,7 @@ static int has_noauto_flag(char *path)
64c563
 
64c563
 int main(int argc, char *argv[])
64c563
 {
64c563
-	char		*path;
64c563
+	char		*path, *spath;
64c563
 	char		dirbase[] = "/nfs-server.service.d";
64c563
 	char		filebase[] = "/order-with-mounts.conf";
64c563
 	nfs_export	*exp;
64c563
@@ -167,9 +139,15 @@ int main(int argc, char *argv[])
64c563
 		if (strcmp(mnt->mnt_type, "nfs") != 0 &&
64c563
 		    strcmp(mnt->mnt_type, "nfs4") != 0)
64c563
 			continue;
64c563
-		fprintf(f, "Before= ");
64c563
-		systemd_escape(f, mnt->mnt_dir);
64c563
-		fprintf(f, ".mount\n");
64c563
+
64c563
+		spath = systemd_escape(mnt->mnt_dir, ".mount");
64c563
+		if (!spath) {
64c563
+			fprintf(stderr, 
64c563
+				"nfs-server-generator: convert path failed: %s\n",
64c563
+				mnt->mnt_dir);
64c563
+			continue;
64c563
+		}
64c563
+		fprintf(f, "Before=%s\n", spath);
64c563
 	}
64c563
 
64c563
 	fclose(fstab);
64c563
diff --git a/systemd/nfs.conf.man b/systemd/nfs.conf.man
64c563
index 938b970..9700586 100644
64c563
--- a/systemd/nfs.conf.man
64c563
+++ b/systemd/nfs.conf.man
64c563
@@ -96,6 +96,18 @@ value, which can be one or more from the list
64c563
 .BR all .
64c563
 When a list is given, the members should be comma-separated.
64c563
 .TP
64c563
+.B general
64c563
+Recognized values:
64c563
+.BR pipefs-directory .
64c563
+
64c563
+See
64c563
+.BR blkmapd (8),
64c563
+.BR rpc.idmapd (8),
64c563
+and
64c563
+.BR rpc.gssd (8)
64c563
+for details.
64c563
+
64c563
+.TP
64c563
 .B nfsdcltrack
64c563
 Recognized values:
64c563
 .BR storagedir .
64c563
@@ -198,7 +210,6 @@ Recognized values:
64c563
 .BR limit-to-legacy-enctypes ,
64c563
 .BR context-timeout ,
64c563
 .BR rpc-timeout ,
64c563
-.BR pipefs-directory ,
64c563
 .BR keytab-file ,
64c563
 .BR cred-cache-directory ,
64c563
 .BR preferred-realm .
64c563
diff --git a/systemd/rpc-gssd.service b/systemd/rpc-gssd.service
64c563
deleted file mode 100644
64c563
index 5d6d09f..0000000
64c563
--- a/systemd/rpc-gssd.service
64c563
+++ /dev/null
64c563
@@ -1,19 +0,0 @@
64c563
-[Unit]
64c563
-Description=RPC security service for NFS client and server
64c563
-DefaultDependencies=no
64c563
-Conflicts=umount.target
64c563
-Requires=var-lib-nfs-rpc_pipefs.mount
64c563
-After=var-lib-nfs-rpc_pipefs.mount gssproxy.service
64c563
-
64c563
-ConditionPathExists=/etc/krb5.keytab
64c563
-
64c563
-PartOf=nfs-utils.service
64c563
-
64c563
-Wants=nfs-config.service
64c563
-After=nfs-config.service
64c563
-
64c563
-[Service]
64c563
-EnvironmentFile=-/run/sysconfig/nfs-utils
64c563
-
64c563
-Type=forking
64c563
-ExecStart=/usr/sbin/rpc.gssd $GSSDARGS
64c563
diff --git a/systemd/rpc-gssd.service.in b/systemd/rpc-gssd.service.in
64c563
new file mode 100644
64c563
index 0000000..c75ccbd
64c563
--- /dev/null
64c563
+++ b/systemd/rpc-gssd.service.in
64c563
@@ -0,0 +1,19 @@
64c563
+[Unit]
64c563
+Description=RPC security service for NFS client and server
64c563
+DefaultDependencies=no
64c563
+Conflicts=umount.target
64c563
+Requires=rpc_pipefs.target
64c563
+After=rpc_pipefs.target gssproxy.service
64c563
+
64c563
+ConditionPathExists=@_sysconfdir@/krb5.keytab
64c563
+
64c563
+PartOf=nfs-utils.service
64c563
+
64c563
+Wants=nfs-config.service
64c563
+After=nfs-config.service
64c563
+
64c563
+[Service]
64c563
+EnvironmentFile=-/run/sysconfig/nfs-utils
64c563
+
64c563
+Type=forking
64c563
+ExecStart=/usr/sbin/rpc.gssd $GSSDARGS
64c563
diff --git a/systemd/rpc-pipefs-generator.c b/systemd/rpc-pipefs-generator.c
64c563
new file mode 100644
64c563
index 0000000..66addb9
64c563
--- /dev/null
64c563
+++ b/systemd/rpc-pipefs-generator.c
64c563
@@ -0,0 +1,138 @@
64c563
+/*
64c563
+ * rpc-pipefs-generator:
64c563
+ *   systemd generator to create ordering dependencies between
64c563
+ *   nfs services and the rpc_pipefs mountpoint
64c563
+ */
64c563
+
64c563
+#ifdef HAVE_CONFIG_H
64c563
+#include <config.h>
64c563
+#endif
64c563
+
64c563
+#include <sys/stat.h>
64c563
+#include <sys/types.h>
64c563
+#include <unistd.h>
64c563
+#include <stdlib.h>
64c563
+#include <string.h>
64c563
+#include <ctype.h>
64c563
+#include <stdio.h>
64c563
+#include <mntent.h>
64c563
+
64c563
+#include "nfslib.h"
64c563
+#include "conffile.h"
64c563
+#include "systemd.h"
64c563
+
64c563
+#define RPC_PIPEFS_DEFAULT "/var/lib/nfs/rpc_pipefs"
64c563
+char *conf_path = NFS_CONFFILE;
64c563
+
64c563
+static int generate_mount_unit(const char *pipefs_path, const char *pipefs_unit,
64c563
+			       const char *dirname)
64c563
+{
64c563
+	char	*path;
64c563
+	FILE	*f;
64c563
+
64c563
+	path = malloc(strlen(dirname) + 1 + strlen(pipefs_unit));
64c563
+	if (!path)
64c563
+		return 1;
64c563
+	sprintf(path, "%s/%s", dirname, pipefs_unit);
64c563
+	f = fopen(path, "w");
64c563
+	if (!f)
64c563
+		return 1;
64c563
+
64c563
+	fprintf(f, "# Automatically generated by rpc-pipefs-generator\n\n[Unit]\n");
64c563
+	fprintf(f, "Description=RPC Pipe File System\n");
64c563
+	fprintf(f, "DefaultDependencies=no\n");
64c563
+	fprintf(f, "After=systemd-tmpfiles-setup.service\n");
64c563
+	fprintf(f, "Conflicts=umount.target\n");
64c563
+	fprintf(f, "\n[Mount]\n");
64c563
+	fprintf(f, "What=sunrpc\n");
64c563
+	fprintf(f, "Where=%s\n", pipefs_path);
64c563
+	fprintf(f, "Type=rpc_pipefs\n");
64c563
+
64c563
+	fclose(f);
64c563
+	return 0;
64c563
+}
64c563
+
64c563
+static
64c563
+int generate_target(char *pipefs_path, const char *dirname)
64c563
+{
64c563
+	char	*path;
64c563
+	char	filebase[] = "/rpc_pipefs.target";
64c563
+	char	*pipefs_unit;
64c563
+	FILE	*f;
64c563
+	int 	ret = 0;
64c563
+
64c563
+	pipefs_unit = systemd_escape(pipefs_path, ".mount");
64c563
+	if (!pipefs_unit)
64c563
+		return 1;
64c563
+
64c563
+	ret = generate_mount_unit(pipefs_path, pipefs_unit, dirname);
64c563
+	if (ret)
64c563
+		return ret;
64c563
+
64c563
+	path = malloc(strlen(dirname) + 1 + sizeof(filebase));
64c563
+	if (!path)
64c563
+		return 2;
64c563
+	sprintf(path, "%s", dirname);
64c563
+	mkdir(path, 0755);
64c563
+	strcat(path, filebase);
64c563
+	f = fopen(path, "w");
64c563
+	if (!f)
64c563
+		return 1;
64c563
+
64c563
+	fprintf(f, "# Automatically generated by rpc-pipefs-generator\n\n[Unit]\n");
64c563
+	fprintf(f, "Requires=%s\n", pipefs_unit);
64c563
+	fprintf(f, "After=%s\n", pipefs_unit);
64c563
+	fclose(f);
64c563
+
64c563
+	return 0;
64c563
+}
64c563
+
64c563
+static int is_non_pipefs_mountpoint(char *path)
64c563
+{
64c563
+	FILE		*mtab;
64c563
+	struct mntent	*mnt;
64c563
+
64c563
+	mtab = setmntent("/etc/mtab", "r");
64c563
+	if (!mtab)
64c563
+		return 0;
64c563
+
64c563
+	while ((mnt = getmntent(mtab)) != NULL) {
64c563
+		if (strlen(mnt->mnt_dir) != strlen(path))
64c563
+			continue;
64c563
+		if (strncmp(mnt->mnt_dir, path, strlen(mnt->mnt_dir)))
64c563
+			continue;
64c563
+		if (strncmp(mnt->mnt_type, "rpc_pipefs", strlen(mnt->mnt_type)))
64c563
+			break;
64c563
+	}
64c563
+	fclose(mtab);
64c563
+	return mnt != NULL;
64c563
+}
64c563
+
64c563
+int main(int argc, char *argv[])
64c563
+{
64c563
+	int 	ret;
64c563
+	char	*s;
64c563
+
64c563
+	/* Avoid using any external services */
64c563
+	xlog_syslog(0);
64c563
+
64c563
+	if (argc != 4 || argv[1][0] != '/') {
64c563
+		fprintf(stderr, "rpc-pipefs-generator: create systemd dependencies for nfs services\n");
64c563
+		fprintf(stderr, "Usage: normal-dir early-dir late-dir\n");
64c563
+		exit(1);
64c563
+	}
64c563
+
64c563
+	conf_init();
64c563
+	s = conf_get_str("general", "pipefs-directory");
64c563
+	if (!s)
64c563
+		exit(0);
64c563
+	if (strlen(s) == strlen(RPC_PIPEFS_DEFAULT) &&
64c563
+			strcmp(s, RPC_PIPEFS_DEFAULT) == 0)
64c563
+		exit(0);
64c563
+
64c563
+	if (is_non_pipefs_mountpoint(s))
64c563
+		exit(1);
64c563
+
64c563
+	ret = generate_target(s, argv[1]);
64c563
+	exit(ret);
64c563
+}
64c563
diff --git a/systemd/rpc-svcgssd.service b/systemd/rpc-svcgssd.service
64c563
index 41177b6..a3a555c 100644
64c563
--- a/systemd/rpc-svcgssd.service
64c563
+++ b/systemd/rpc-svcgssd.service
64c563
@@ -1,8 +1,7 @@
64c563
 [Unit]
64c563
 Description=RPC security service for NFS server
64c563
 DefaultDependencies=no
64c563
-Requires=var-lib-nfs-rpc_pipefs.mount
64c563
-After=var-lib-nfs-rpc_pipefs.mount local-fs.target
64c563
+After=local-fs.target
64c563
 PartOf=nfs-server.service
64c563
 PartOf=nfs-utils.service
64c563
 
64c563
diff --git a/systemd/rpc_pipefs.target b/systemd/rpc_pipefs.target
64c563
new file mode 100644
64c563
index 0000000..01d4d27
64c563
--- /dev/null
64c563
+++ b/systemd/rpc_pipefs.target
64c563
@@ -0,0 +1,3 @@
64c563
+[Unit]
64c563
+Requires=var-lib-nfs-rpc_pipefs.mount
64c563
+After=var-lib-nfs-rpc_pipefs.mount
64c563
diff --git a/systemd/systemd.c b/systemd/systemd.c
64c563
new file mode 100644
64c563
index 0000000..17820d4
64c563
--- /dev/null
64c563
+++ b/systemd/systemd.c
64c563
@@ -0,0 +1,133 @@
64c563
+/*
64c563
+ * Helper functions for systemd generators in nfs-utils.
64c563
+ *
64c563
+ * Currently just systemd_escape().
64c563
+ */
64c563
+
64c563
+#include <stdio.h>
64c563
+#include <stdlib.h>
64c563
+#include <ctype.h>
64c563
+#include <string.h>
64c563
+
64c563
+static const char hex[16] =
64c563
+{
64c563
+  '0', '1', '2', '3', '4', '5', '6', '7',
64c563
+  '8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
64c563
+};
64c563
+
64c563
+/*
64c563
+ * determine length of the string that systemd_escape() needs to allocate
64c563
+ */
64c563
+static int systemd_len(char *path)
64c563
+{
64c563
+	char *p;
64c563
+	int len = 0;
64c563
+
64c563
+	p = path;
64c563
+	while (*p == '/')
64c563
+		/* multiple leading "/" are ignored */
64c563
+		p++;
64c563
+
64c563
+	if (!*p)
64c563
+		/* root directory "/" becomes is encoded as a single "-" */
64c563
+		return 1;
64c563
+
64c563
+	if (*p == '.')
64c563
+		/*
64c563
+		 * replace "." with "\x2d" escape sequence if
64c563
+		 * it's the first character in escaped path
64c563
+		 * */
64c563
+		len += 4;
64c563
+
64c563
+	while (*p) {
64c563
+		unsigned char c = *p++;
64c563
+
64c563
+		if (c == '/') {
64c563
+			/* multiple non-trailing slashes become '-' */
64c563
+			while (*p == '/')
64c563
+				p++;
64c563
+			if (*p)
64c563
+				len++;
64c563
+		} else if (isalnum(c) || c == ':' || c == '.' || c == '_')
64c563
+			/* these characters are not replaced */
64c563
+			len++;
64c563
+		else
64c563
+			/* replace with "\x2d" escape sequence */
64c563
+			len += 4;
64c563
+	}
64c563
+
64c563
+	return len;
64c563
+}
64c563
+
64c563
+/*
64c563
+ * convert c to "\x2d" escape sequence and append to string
64c563
+ * at position p, advancing p
64c563
+ */
64c563
+static char *hexify(unsigned char c, char *p)
64c563
+{
64c563
+	*p++ = '\\';
64c563
+	*p++ = 'x';
64c563
+	*p++ = hex[c >> 4];
64c563
+	*p++ = hex[c & 0xf];
64c563
+	return p;
64c563
+}
64c563
+
64c563
+/*
64c563
+ * convert a path to a unit name according to the logic in systemd.unit(5):
64c563
+ *
64c563
+ *     Basically, given a path, "/" is replaced by "-", and all other
64c563
+ *     characters which are not ASCII alphanumerics are replaced by C-style
64c563
+ *     "\x2d" escapes (except that "_" is never replaced and "." is only
64c563
+ *     replaced when it would be the first character in the escaped path).
64c563
+ *     The root directory "/" is encoded as single dash, while otherwise the
64c563
+ *     initial and ending "/" are removed from all paths during
64c563
+ *     transformation.
64c563
+ *
64c563
+ * NB: Although the systemd.unit(5) doesn't mention it, the ':' character
64c563
+ * is not escaped.
64c563
+ */
64c563
+char *systemd_escape(char *path, char *suffix)
64c563
+{
64c563
+	char *result;
64c563
+	char *p;
64c563
+	int len;
64c563
+
64c563
+	len = systemd_len(path);
64c563
+	result = malloc(len + strlen(suffix) + 1);
64c563
+	p = result;
64c563
+	while (*path == '/')
64c563
+		/* multiple leading "/" are ignored */
64c563
+		path++;
64c563
+	if (!*path) {
64c563
+		/* root directory "/" becomes is encoded as a single "-" */
64c563
+		*p++ = '-';
64c563
+		goto out;
64c563
+	}
64c563
+	if (*path == '.')
64c563
+		/*
64c563
+		 * replace "." with "\x2d" escape sequence if
64c563
+		 * it's the first character in escaped path
64c563
+		 * */
64c563
+		p = hexify(*path++, p);
64c563
+
64c563
+	while (*path) {
64c563
+		unsigned char c = *path++;
64c563
+
64c563
+		if (c == '/') {
64c563
+			/* multiple non-trailing slashes become '-' */
64c563
+			while (*path == '/')
64c563
+				path++;
64c563
+			if (*path)
64c563
+				*p++ = '-';
64c563
+		} else if (isalnum(c) || c == ':' || c == '.' || c == '_')
64c563
+			/* these characters are not replaced */
64c563
+			*p++ = c;
64c563
+		else
64c563
+			/* replace with "\x2d" escape sequence */
64c563
+			p = hexify(c, p);
64c563
+	}
64c563
+
64c563
+out:
64c563
+	sprintf(p, "%s", suffix);
64c563
+	return result;
64c563
+}
64c563
diff --git a/systemd/systemd.h b/systemd/systemd.h
64c563
new file mode 100644
64c563
index 0000000..25235ec
64c563
--- /dev/null
64c563
+++ b/systemd/systemd.h
64c563
@@ -0,0 +1,6 @@
64c563
+#ifndef SYSTEMD_H
64c563
+#define SYSTEMD_H
64c563
+
64c563
+char *systemd_escape(char *path, char *suffix);
64c563
+
64c563
+#endif /* SYSTEMD_H */
64c563
diff --git a/utils/blkmapd/blkmapd.man b/utils/blkmapd/blkmapd.man
64c563
index 914b80f..4b3d3f0 100644
64c563
--- a/utils/blkmapd/blkmapd.man
64c563
+++ b/utils/blkmapd/blkmapd.man
64c563
@@ -43,9 +43,24 @@ Performs device discovery only then exits.
64c563
 Runs
64c563
 .B blkmapd
64c563
 in the foreground and sends output to stderr (as opposed to syslogd)
64c563
+.SH CONFIGURATION FILE
64c563
+The
64c563
+.B blkmapd
64c563
+daemon recognizes the following value from the
64c563
+.B [general]
64c563
+section of the
64c563
+.I /etc/nfs.conf
64c563
+configuration file:
64c563
+.TP
64c563
+.B pipefs-directory
64c563
+Tells
64c563
+.B blkmapd
64c563
+where to look for the rpc_pipefs filesystem.  The default value is
64c563
+.IR /var/lib/nfs/rpc_pipefs .
64c563
 .SH SEE ALSO
64c563
 .BR nfs (5),
64c563
-.BR dmsetup (8)
64c563
+.BR dmsetup (8),
64c563
+.BR nfs.conf (5)
64c563
 .sp
64c563
 RFC 5661 for the NFS version 4.1 specification.
64c563
 .br
64c563
diff --git a/utils/blkmapd/device-discovery.c b/utils/blkmapd/device-discovery.c
64c563
index b010628..a419947 100644
64c563
--- a/utils/blkmapd/device-discovery.c
64c563
+++ b/utils/blkmapd/device-discovery.c
64c563
@@ -50,19 +50,36 @@
64c563
 #include <errno.h>
64c563
 #include <libdevmapper.h>
64c563
 
64c563
+#ifdef HAVE_CONFIG_H
64c563
+#include "config.h"
64c563
+#endif /* HAVE_CONFIG_H */
64c563
+
64c563
 #include "device-discovery.h"
64c563
+#include "xcommon.h"
64c563
+#include "nfslib.h"
64c563
+#include "conffile.h"
64c563
 
64c563
 #define EVENT_SIZE (sizeof(struct inotify_event))
64c563
 #define EVENT_BUFSIZE (1024 * EVENT_SIZE)
64c563
 
64c563
-#define BL_PIPE_FILE	"/var/lib/nfs/rpc_pipefs/nfs/blocklayout"
64c563
-#define NFSPIPE_DIR	"/var/lib/nfs/rpc_pipefs/nfs"
64c563
 #define RPCPIPE_DIR	"/var/lib/nfs/rpc_pipefs"
64c563
 #define PID_FILE	"/var/run/blkmapd.pid"
64c563
 
64c563
+#define CONF_SAVE(w, f) do {			\
64c563
+	char *p = f;				\
64c563
+	if (p != NULL)				\
64c563
+		(w) = p;			\
64c563
+} while (0)
64c563
+
64c563
+static char bl_pipe_file[PATH_MAX];
64c563
+static char nfspipe_dir[PATH_MAX];
64c563
+static char rpcpipe_dir[PATH_MAX];
64c563
+
64c563
 struct bl_disk *visible_disk_list;
64c563
 int    bl_watch_fd, bl_pipe_fd, nfs_pipedir_wfd, rpc_pipedir_wfd;
64c563
 int    pidfd = -1;
64c563
+char   *conf_path = NULL;
64c563
+
64c563
 
64c563
 struct bl_disk_path *bl_get_path(const char *filepath,
64c563
 				 struct bl_disk_path *paths)
64c563
@@ -357,8 +374,8 @@ static void bl_rpcpipe_cb(void)
64c563
 				continue;
64c563
 			if (event->mask & IN_CREATE) {
64c563
 				BL_LOG_WARNING("nfs pipe dir created\n");
64c563
-				bl_watch_dir(NFSPIPE_DIR, &nfs_pipedir_wfd);
64c563
-				bl_pipe_fd = open(BL_PIPE_FILE, O_RDWR);
64c563
+				bl_watch_dir(nfspipe_dir, &nfs_pipedir_wfd);
64c563
+				bl_pipe_fd = open(bl_pipe_file, O_RDWR);
64c563
 			} else if (event->mask & IN_DELETE) {
64c563
 				BL_LOG_WARNING("nfs pipe dir deleted\n");
64c563
 				inotify_rm_watch(bl_watch_fd, nfs_pipedir_wfd);
64c563
@@ -371,7 +388,7 @@ static void bl_rpcpipe_cb(void)
64c563
 				continue;
64c563
 			if (event->mask & IN_CREATE) {
64c563
 				BL_LOG_WARNING("blocklayout pipe file created\n");
64c563
-				bl_pipe_fd = open(BL_PIPE_FILE, O_RDWR);
64c563
+				bl_pipe_fd = open(bl_pipe_file, O_RDWR);
64c563
 				if (bl_pipe_fd < 0)
64c563
 					BL_LOG_ERR("open %s failed: %s\n",
64c563
 						event->name, strerror(errno));
64c563
@@ -437,6 +454,19 @@ int main(int argc, char **argv)
64c563
 	int opt, dflag = 0, fg = 0, ret = 1;
64c563
 	struct stat statbuf;
64c563
 	char pidbuf[64];
64c563
+	char *xrpcpipe_dir = NULL;
64c563
+
64c563
+	strncpy(rpcpipe_dir, RPCPIPE_DIR, sizeof(rpcpipe_dir));
64c563
+	conf_path = NFS_CONFFILE;
64c563
+	conf_init();
64c563
+	CONF_SAVE(xrpcpipe_dir, conf_get_str("general", "pipefs-directory"));
64c563
+	if (xrpcpipe_dir != NULL)
64c563
+		strlcpy(rpcpipe_dir, xrpcpipe_dir, sizeof(rpcpipe_dir));
64c563
+
64c563
+	strncpy(nfspipe_dir, rpcpipe_dir, sizeof(nfspipe_dir));
64c563
+	strlcat(nfspipe_dir, "/nfs", sizeof(nfspipe_dir));
64c563
+	strncpy(bl_pipe_file, rpcpipe_dir, sizeof(bl_pipe_file));
64c563
+	strlcat(bl_pipe_file, "/nfs/blocklayout", sizeof(bl_pipe_file));
64c563
 
64c563
 	while ((opt = getopt(argc, argv, "hdf")) != -1) {
64c563
 		switch (opt) {
64c563
@@ -501,12 +531,12 @@ int main(int argc, char **argv)
64c563
 	}
64c563
 
64c563
 	/* open pipe file */
64c563
-	bl_watch_dir(RPCPIPE_DIR, &rpc_pipedir_wfd);
64c563
-	bl_watch_dir(NFSPIPE_DIR, &nfs_pipedir_wfd);
64c563
+	bl_watch_dir(rpcpipe_dir, &rpc_pipedir_wfd);
64c563
+	bl_watch_dir(nfspipe_dir, &nfs_pipedir_wfd);
64c563
 
64c563
-	bl_pipe_fd = open(BL_PIPE_FILE, O_RDWR);
64c563
+	bl_pipe_fd = open(bl_pipe_file, O_RDWR);
64c563
 	if (bl_pipe_fd < 0)
64c563
-		BL_LOG_ERR("open pipe file %s failed: %s\n", BL_PIPE_FILE, strerror(errno));
64c563
+		BL_LOG_ERR("open pipe file %s failed: %s\n", bl_pipe_file, strerror(errno));
64c563
 
64c563
 	while (1) {
64c563
 		/* discover device when needed */
64c563
diff --git a/utils/gssd/gssd.c b/utils/gssd/gssd.c
64c563
index c5c03fb..10d50d3 100644
64c563
--- a/utils/gssd/gssd.c
64c563
+++ b/utils/gssd/gssd.c
64c563
@@ -857,6 +857,10 @@ read_gss_conf(void)
64c563
 	s = conf_get_str("gssd", "pipefs-directory");
64c563
 	if (!s)
64c563
 		s = conf_get_str("general", "pipefs-directory");
64c563
+	else
64c563
+		printerr(0, "WARNING: Specifying pipefs-directory in the [gssd] "
64c563
+			 "section of %s is deprecated.  Use the [general] "
64c563
+			 "section instead.", NFS_CONFFILE);
64c563
 	if (s)
64c563
 		pipefs_path = s;
64c563
 	s = conf_get_str("gssd", "keytab-file");
64c563
diff --git a/utils/gssd/gssd.man b/utils/gssd/gssd.man
64c563
index 87eef02..e620f0d 100644
64c563
--- a/utils/gssd/gssd.man
64c563
+++ b/utils/gssd/gssd.man
64c563
@@ -335,10 +335,6 @@ Equivalent to
64c563
 Equivalent to
64c563
 .BR -t .
64c563
 .TP
64c563
-.B pipefs-directory
64c563
-Equivalent to
64c563
-.BR -p .
64c563
-.TP
64c563
 .B keytab-file
64c563
 Equivalent to
64c563
 .BR -k .
64c563
@@ -350,6 +346,14 @@ Equivalent to
64c563
 .B preferred-realm
64c563
 Equivalent to
64c563
 .BR -R .
64c563
+.P
64c563
+In addtion, the following value is recognized from the
64c563
+.B [general]
64c563
+section:
64c563
+.TP
64c563
+.B pipefs-directory
64c563
+Equivalent to
64c563
+.BR -p .
64c563
 
64c563
 .SH SEE ALSO
64c563
 .BR rpc.svcgssd (8),
64c563
diff --git a/utils/idmapd/idmapd.c b/utils/idmapd/idmapd.c
64c563
index f55d2e1..03efbea 100644
64c563
--- a/utils/idmapd/idmapd.c
64c563
+++ b/utils/idmapd/idmapd.c
64c563
@@ -166,7 +166,7 @@ static uid_t nobodyuid;
64c563
 static gid_t nobodygid;
64c563
 
64c563
 /* Used by conffile.c in libnfs.a */
64c563
-char *conf_path;
64c563
+char *conf_path = NULL;
64c563
 
64c563
 static int
64c563
 flush_nfsd_cache(char *path, time_t now)
64c563
@@ -220,7 +220,6 @@ main(int argc, char **argv)
64c563
 	int ret;
64c563
 	char *progname;
64c563
 
64c563
-	conf_path = _PATH_IDMAPDCONF;
64c563
 	nobodyuser = NFS4NOBODY_USER;
64c563
 	nobodygroup = NFS4NOBODY_GROUP;
64c563
 	strlcpy(pipefsdir, PIPEFS_DIR, sizeof(pipefsdir));
64c563
@@ -234,8 +233,11 @@ main(int argc, char **argv)
64c563
 #define GETOPTSTR "hvfd:p:U:G:c:CS"
64c563
 	opterr=0; /* Turn off error messages */
64c563
 	while ((opt = getopt(argc, argv, GETOPTSTR)) != -1) {
64c563
-		if (opt == 'c')
64c563
+		if (opt == 'c') {
64c563
+			warnx("-c is deprecated and may be removed in the "
64c563
+			      "future.  See idmapd(8).");
64c563
 			conf_path = optarg;
64c563
+		}
64c563
 		if (opt == '?') {
64c563
 			if (strchr(GETOPTSTR, optopt))
64c563
 				warnx("'-%c' option requires an argument.", optopt);
64c563
@@ -247,17 +249,33 @@ main(int argc, char **argv)
64c563
 	}
64c563
 	optind = 1;
64c563
 
64c563
-	if (stat(conf_path, &sb) == -1 && (errno == ENOENT || errno == EACCES)) {
64c563
-		warn("Skipping configuration file \"%s\"", conf_path);
64c563
-		conf_path = NULL;
64c563
+	if (conf_path) { /* deprecated -c option was specified */
64c563
+		if (stat(conf_path, &sb) == -1 && (errno == ENOENT || errno == EACCES)) {
64c563
+			warn("Skipping configuration file \"%s\"", conf_path);
64c563
+			conf_path = NULL;
64c563
+		} else {
64c563
+			conf_init();
64c563
+			verbose = conf_get_num("General", "Verbosity", 0);
64c563
+			cache_entry_expiration = conf_get_num("General",
64c563
+					"Cache-Expiration", DEFAULT_IDMAP_CACHE_EXPIRY);
64c563
+			CONF_SAVE(xpipefsdir, conf_get_str("General", "Pipefs-Directory"));
64c563
+			if (xpipefsdir != NULL)
64c563
+				strlcpy(pipefsdir, xpipefsdir, sizeof(pipefsdir));
64c563
+			CONF_SAVE(nobodyuser, conf_get_str("Mapping", "Nobody-User"));
64c563
+			CONF_SAVE(nobodygroup, conf_get_str("Mapping", "Nobody-Group"));
64c563
+		}
64c563
 	} else {
64c563
+		conf_path = NFS_CONFFILE;
64c563
 		conf_init();
64c563
-		verbose = conf_get_num("General", "Verbosity", 0);
64c563
-		cache_entry_expiration = conf_get_num("General",
64c563
-				"Cache-Expiration", DEFAULT_IDMAP_CACHE_EXPIRY);
64c563
 		CONF_SAVE(xpipefsdir, conf_get_str("General", "Pipefs-Directory"));
64c563
 		if (xpipefsdir != NULL)
64c563
 			strlcpy(pipefsdir, xpipefsdir, sizeof(pipefsdir));
64c563
+
64c563
+		conf_path = _PATH_IDMAPDCONF;
64c563
+		conf_init();
64c563
+		verbose = conf_get_num("General", "Verbosity", 0);
64c563
+		cache_entry_expiration = conf_get_num("General",
64c563
+				"cache-expiration", DEFAULT_IDMAP_CACHE_EXPIRY);
64c563
 		CONF_SAVE(nobodyuser, conf_get_str("Mapping", "Nobody-User"));
64c563
 		CONF_SAVE(nobodygroup, conf_get_str("Mapping", "Nobody-Group"));
64c563
 	}
64c563
diff --git a/utils/idmapd/idmapd.man b/utils/idmapd/idmapd.man
64c563
index b9200c7..fb5fc1e 100644
64c563
--- a/utils/idmapd/idmapd.man
64c563
+++ b/utils/idmapd/idmapd.man
64c563
@@ -50,11 +50,28 @@ The default value is \&"/var/lib/nfs/rpc_pipefs\&".
64c563
 .It Fl c Ar path
64c563
 Use configuration file
64c563
 .Ar path .
64c563
+This option is deprecated.
64c563
 .It Fl C
64c563
 Client-only: perform no idmapping for any NFS server, even if one is detected.
64c563
 .It Fl S
64c563
 Server-only: perform no idmapping for any NFS client, even if one is detected.
64c563
 .El
64c563
+.Sh CONFIGURATION FILES
64c563
+.Nm
64c563
+recognizes the following value from the
64c563
+.Sy [general]
64c563
+section of the
64c563
+.Pa /etc/nfs.conf
64c563
+configuration file:
64c563
+.Bl -tag -width Ds_imagedir
64c563
+.It Sy pipefs-directory
64c563
+Equivalent to
64c563
+.Sy -p .
64c563
+.El
64c563
+.Pp
64c563
+All other settings related to id mapping are found in the
64c563
+.Pa /etc/idmapd.conf
64c563
+configuration file.
64c563
 .Sh EXAMPLES
64c563
 .Cm rpc.idmapd -f -vvv
64c563
 .Pp
64c563
@@ -71,9 +88,11 @@ messages to console, and with a verbosity level of 3.
64c563
 .\" This next request is for sections 1, 6, 7 & 8 only.
64c563
 .\" .Sh ENVIRONMENT
64c563
 .Sh FILES
64c563
-.Pa /etc/idmapd.conf
64c563
+.Pa /etc/idmapd.conf ,
64c563
+.Pa /etc/nfs.conf
64c563
 .Sh SEE ALSO
64c563
 .Xr idmapd.conf 5 ,
64c563
+.Xr nfs.conf 5 ,
64c563
 .Xr nfsidmap 8
64c563
 .\".Sh SEE ALSO
64c563
 .\".Xr nylon.conf 4
64c563
diff --git a/utils/mountd/cache.c b/utils/mountd/cache.c
64c563
index 3bc13ca..f23fb5a 100644
64c563
--- a/utils/mountd/cache.c
64c563
+++ b/utils/mountd/cache.c
64c563
@@ -31,6 +31,7 @@
64c563
 #include "mountd.h"
64c563
 #include "fsloc.h"
64c563
 #include "pseudoflavors.h"
64c563
+#include "xcommon.h"
64c563
 
64c563
 #ifdef USE_BLKID
64c563
 #include "blkid/blkid.h"