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