Blame SOURCES/autofs-5.1.5-add-glibc-getmntent.patch

1c5f92
autofs-5.1.5 - add glibc getmntent_r()
1c5f92
1c5f92
From: Ian Kent <raven@themaw.net>
1c5f92
1c5f92
Add a slightly modified version of the glibc getmntent_r() function
1c5f92
so autofs can read the proc mount table directly.
1c5f92
1c5f92
Signed-off-by: Ian Kent <raven@themaw.net>
1c5f92
---
1c5f92
 CHANGELOG    |    1 
1c5f92
 lib/mounts.c |   95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1c5f92
 2 files changed, 96 insertions(+)
1c5f92
1c5f92
--- autofs-5.1.4.orig/CHANGELOG
1c5f92
+++ autofs-5.1.4/CHANGELOG
1c5f92
@@ -66,6 +66,7 @@ xx/xx/2018 autofs-5.1.5
1c5f92
 - use bit flags for autofs mount types in mnt_list.
1c5f92
 - use mp instead of path in mnt_list entries.
1c5f92
 - always use PROC_MOUNTS to make mount lists.
1c5f92
+- add glibc getmntent_r().
1c5f92
 
1c5f92
 19/12/2017 autofs-5.1.4
1c5f92
 - fix spec file url.
1c5f92
--- autofs-5.1.4.orig/lib/mounts.c
1c5f92
+++ autofs-5.1.4/lib/mounts.c
1c5f92
@@ -786,6 +786,101 @@ done:
1c5f92
 	return ret;
1c5f92
 }
1c5f92
 
1c5f92
+/* From glibc decode_name() */
1c5f92
+/* Since the values in a line are separated by spaces, a name cannot
1c5f92
+ * contain a space.  Therefore some programs encode spaces in names
1c5f92
+ * by the strings "\040".  We undo the encoding when reading an entry.
1c5f92
+ * The decoding happens in place.
1c5f92
+ */
1c5f92
+static char *local_decode_name(char *buf)
1c5f92
+{
1c5f92
+	char *rp = buf;
1c5f92
+	char *wp = buf;
1c5f92
+
1c5f92
+	do {
1c5f92
+		if (rp[0] == '\\' && rp[1] == '0' &&
1c5f92
+		    rp[2] == '4' && rp[3] == '0') {
1c5f92
+			/* \040 is a SPACE.  */
1c5f92
+			*wp++ = ' ';
1c5f92
+			rp += 3;
1c5f92
+		} else if (rp[0] == '\\' && rp[1] == '0' &&
1c5f92
+			   rp[2] == '1' && rp[3] == '1') {
1c5f92
+			/* \011 is a TAB.  */
1c5f92
+			*wp++ = '\t';
1c5f92
+			rp += 3;
1c5f92
+		} else if (rp[0] == '\\' && rp[1] == '0' &&
1c5f92
+			   rp[2] == '1' && rp[3] == '2') {
1c5f92
+			/* \012 is a NEWLINE.  */
1c5f92
+			*wp++ = '\n';
1c5f92
+			rp += 3;
1c5f92
+		} else if (rp[0] == '\\' && rp[1] == '\\') {
1c5f92
+			/*
1c5f92
+			 * We have to escape \\ to be able to represent
1c5f92
+			 * all characters.
1c5f92
+			 */
1c5f92
+			*wp++ = '\\';
1c5f92
+			rp += 1;
1c5f92
+		} else if (rp[0] == '\\' && rp[1] == '1' &&
1c5f92
+			   rp[2] == '3' && rp[3] == '4') {
1c5f92
+			/* \134 is also \\.  */
1c5f92
+			*wp++ = '\\';
1c5f92
+			rp += 3;
1c5f92
+		} else
1c5f92
+			*wp++ = *rp;
1c5f92
+	} while (*rp++ != '\0');
1c5f92
+
1c5f92
+	return buf;
1c5f92
+}
1c5f92
+
1c5f92
+/* From glibc getmntent_r() */
1c5f92
+static struct mntent *
1c5f92
+local_getmntent_r(FILE *tab, struct mntent *mnt, char *buf, int size)
1c5f92
+{
1c5f92
+	char *cp, *head;
1c5f92
+
1c5f92
+	do {
1c5f92
+		char *end_ptr;
1c5f92
+
1c5f92
+		if (fgets(buf, size, tab) == NULL)
1c5f92
+			return 0;
1c5f92
+
1c5f92
+		end_ptr = strchr(buf, '\n');
1c5f92
+		if (end_ptr != NULL) {
1c5f92
+			while (end_ptr[-1] == ' ' || end_ptr[-1] == '\t')
1c5f92
+				end_ptr--;
1c5f92
+			*end_ptr = '\0';
1c5f92
+		} else {
1c5f92
+			/* Whole line was not read. Do it now but forget it. */
1c5f92
+			char tmp[1024];
1c5f92
+			while (fgets(tmp, sizeof tmp, tab) != NULL)
1c5f92
+				if (strchr(tmp, '\n') != NULL)
1c5f92
+					break;
1c5f92
+		}
1c5f92
+
1c5f92
+		head = buf + strspn(buf, " \t");
1c5f92
+	/* skip empty lines and comment lines */
1c5f92
+	} while (head[0] == '\0' || head[0] == '#');
1c5f92
+
1c5f92
+	cp = strsep(&head, " \t");
1c5f92
+	mnt->mnt_fsname = cp != NULL ? local_decode_name(cp) : (char *) "";
1c5f92
+	if (head)
1c5f92
+		head += strspn(head, " \t");
1c5f92
+	cp = strsep(&head, " \t");
1c5f92
+	mnt->mnt_dir = cp != NULL ? local_decode_name (cp) : (char *) "";
1c5f92
+	if (head)
1c5f92
+		head += strspn(head, " \t");
1c5f92
+	cp = strsep(&head, " \t");
1c5f92
+	mnt->mnt_type = cp != NULL ? local_decode_name (cp) : (char *) "";
1c5f92
+	if (head)
1c5f92
+		head += strspn (head, " \t");
1c5f92
+	cp = strsep (&head, " \t");
1c5f92
+	mnt->mnt_opts = cp != NULL ? local_decode_name (cp) : (char *) "";
1c5f92
+
1c5f92
+	/* autofs doesn't need freq or passno */
1c5f92
+
1c5f92
+	return mnt;
1c5f92
+}
1c5f92
+
1c5f92
 /*
1c5f92
  * Get list of mounts under path in longest->shortest order
1c5f92
  */