Ian Kent a3a09e
autofs-5.0.5 - special case cifs escapes
Ian Kent a3a09e
Ian Kent a3a09e
From: Ian Kent <raven@themaw.net>
Ian Kent a3a09e
Ian Kent a3a09e
Since "\" is a valid seperator for cifs shares it can't be used to escape
Ian Kent a3a09e
characters in the share name passed to mount.cifs. So we have no choice
Ian Kent a3a09e
but to require that the seperator we use is "/" and de-quote the string
Ian Kent a3a09e
before sending it to mount.cifs.
Ian Kent a3a09e
---
Ian Kent a3a09e
Ian Kent a3a09e
 CHANGELOG               |    1 +
Ian Kent a3a09e
 modules/mount_generic.c |   36 ++++++++++++++++++++++++++++++------
Ian Kent a3a09e
 2 files changed, 31 insertions(+), 6 deletions(-)
Ian Kent a3a09e
Ian Kent a3a09e
Ian Kent a3a09e
diff --git a/CHANGELOG b/CHANGELOG
Ian Kent a3a09e
index fadb229..671c979 100644
Ian Kent a3a09e
--- a/CHANGELOG
Ian Kent a3a09e
+++ b/CHANGELOG
Ian Kent a3a09e
@@ -3,6 +3,7 @@
Ian Kent a3a09e
 - fix included map read fail handling.
Ian Kent a3a09e
 - refactor ldap sasl bind handling.
Ian Kent a3a09e
 - add mount wait timeout parameter.
Ian Kent a3a09e
+- special case cifs escapes.
Ian Kent a3a09e
 
Ian Kent a3a09e
 03/09/2009 autofs-5.0.5
Ian Kent a3a09e
 -----------------------
Ian Kent a3a09e
diff --git a/modules/mount_generic.c b/modules/mount_generic.c
Ian Kent a3a09e
index 8edad8b..da85d1a 100644
Ian Kent a3a09e
--- a/modules/mount_generic.c
Ian Kent a3a09e
+++ b/modules/mount_generic.c
Ian Kent a3a09e
@@ -39,6 +39,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
Ian Kent a3a09e
 {
Ian Kent a3a09e
 	char fullpath[PATH_MAX];
Ian Kent a3a09e
 	char buf[MAX_ERR_BUF];
Ian Kent a3a09e
+	char *loc;
Ian Kent a3a09e
 	int err;
Ian Kent a3a09e
 	int len, status, existed = 1;
Ian Kent a3a09e
 
Ian Kent a3a09e
@@ -74,22 +75,44 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
Ian Kent a3a09e
 	if (!status)
Ian Kent a3a09e
 		existed = 0;
Ian Kent a3a09e
 
Ian Kent a3a09e
+	/*
Ian Kent a3a09e
+	 * Special case quoting for cifs share names.
Ian Kent a3a09e
+	 *
Ian Kent a3a09e
+	 * Since "\" is a valid seperator for cifs shares it can't be
Ian Kent a3a09e
+	 * used to escape characters in the share name passed to
Ian Kent a3a09e
+	 * mount.cifs. So we have no choice but to require that the
Ian Kent a3a09e
+	 * seperator we use is "/" and de-quote the string before
Ian Kent a3a09e
+	 * sending it to mount.cifs.
Ian Kent a3a09e
+	 */
Ian Kent a3a09e
+	loc = NULL;
Ian Kent a3a09e
+	if (strcmp(fstype, "cifs"))
Ian Kent a3a09e
+		loc = strdup(what);
Ian Kent a3a09e
+	else
Ian Kent a3a09e
+		loc = dequote(what, strlen(what), ap->logopt);
Ian Kent a3a09e
+	if (!loc) {
Ian Kent a3a09e
+		error(ap->logopt,
Ian Kent a3a09e
+		      MODPREFIX "failed to alloc buffer for mount location");
Ian Kent a3a09e
+		return 1;
Ian Kent a3a09e
+	}
Ian Kent a3a09e
+
Ian Kent a3a09e
 	if (options && options[0]) {
Ian Kent a3a09e
 		debug(ap->logopt,
Ian Kent a3a09e
 		      MODPREFIX "calling mount -t %s " SLOPPY "-o %s %s %s",
Ian Kent a3a09e
-		      fstype, options, what, fullpath);
Ian Kent a3a09e
+		      fstype, options, loc, fullpath);
Ian Kent a3a09e
 
Ian Kent a3a09e
 		err = spawn_mount(ap->logopt, "-t", fstype,
Ian Kent a3a09e
-			     SLOPPYOPT "-o", options, what, fullpath, NULL);
Ian Kent a3a09e
+			     SLOPPYOPT "-o", options, loc, fullpath, NULL);
Ian Kent a3a09e
 	} else {
Ian Kent a3a09e
 		debug(ap->logopt, MODPREFIX "calling mount -t %s %s %s",
Ian Kent a3a09e
-		      fstype, what, fullpath);
Ian Kent a3a09e
-		err = spawn_mount(ap->logopt, "-t", fstype, what, fullpath, NULL);
Ian Kent a3a09e
+		      fstype, loc, fullpath);
Ian Kent a3a09e
+		err = spawn_mount(ap->logopt, "-t", fstype, loc, fullpath, NULL);
Ian Kent a3a09e
 	}
Ian Kent a3a09e
 
Ian Kent a3a09e
 	if (err) {
Ian Kent a3a09e
 		info(ap->logopt, MODPREFIX "failed to mount %s (type %s) on %s",
Ian Kent a3a09e
-		     what, fstype, fullpath);
Ian Kent a3a09e
+		     loc, fstype, fullpath);
Ian Kent a3a09e
+
Ian Kent a3a09e
+		free(loc);
Ian Kent a3a09e
 
Ian Kent a3a09e
 		if (ap->type != LKP_INDIRECT)
Ian Kent a3a09e
 			return 1;
Ian Kent a3a09e
@@ -100,7 +123,8 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
Ian Kent a3a09e
 		return 1;
Ian Kent a3a09e
 	} else {
Ian Kent a3a09e
 		info(ap->logopt, MODPREFIX "mounted %s type %s on %s",
Ian Kent a3a09e
-		    what, fstype, fullpath);
Ian Kent a3a09e
+		     loc, fstype, fullpath);
Ian Kent a3a09e
+		free(loc);
Ian Kent a3a09e
 		return 0;
Ian Kent a3a09e
 	}
Ian Kent a3a09e
 }