Subject: bin/26616: amd does not play nice with smbmount
To: None <gnats-bugs@gnats.netbsd.org>
From: Hauke Fath <hf@spg.tu-darmstadt.de>
List: netbsd-bugs
Date: 08/11/2004 13:29:13
>Number:         26616
>Category:       bin
>Synopsis:       amd does not play nice with smbmount
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Aug 11 11:30:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Hauke Fath <hf@spg.tu-darmstadt.de>
>Release:        NetBSD 2.0_BETA
>Organization:
-- 
/~\  The ASCII Ribbon Campaign                    Hauke Fath
\ /    No HTML/RTF in email	        Institut für Nachrichtentechnik
 X     No Word docs in email	                  TU Darmstadt
/ \  Respect for open standards              Ruf +49-6151-16-3281
>Environment:
	
	
System: NetBSD heiligenberg 2.0_BETA NetBSD 2.0_BETA (HEILIGENBERG) #2: Mon Jul 26 15:58:29 CEST 2004 hf@heiligenberg:/var/obj/netbsd-builds/2_0/i386/sys/arch/i386/compile/HEILIGENBERG i386
Architecture: i386
Machine: i386
>Description:

	amd(8) goes too far in beautifying unix paths by reducing
	multiple successive slashes to one. This hurts smbmount(8)
	which wants the remote share specified as '//server/share' and
	therefore cannot be used easily with amd's 'program'
	filesystem.

>How-To-Repeat:

	Set up an amd map like

mucke           type:=program;\
                rhost:=venus;rfs:=/mp3;fs=/local/mp3;\
                mount="/sbin/mount mount -r -t smbfs -o-N,-I${rhost} //${rhost}/${rfs} ${fs}";\
                unmount="/sbin/umount umount ${fs}"

for guest smb mount. Find that it doesn't work. Replace the mount call
with a wrapper script, and see that any occurrence of '//' is turned
into '/', no matter what tricks you try.

>Fix:

The following patch by Erez Zadok applies with fuzz to netbsd-2-0 and fixes the problem

<snip>

Date: Sat, 7 Aug 2004 13:06:56 -0400
Message-Id: <200408071706.i77H6unt022774@agora.fsl.cs.sunysb.edu>
From: Erez Zadok <ezk@cs.sunysb.edu>
To: Hauke Fath <hf@spg.tu-darmstadt.de>
Cc: am-utils@am-utils.org
In-reply-to: Your message of "Wed, 04 Aug 2004 13:58:13 +0200."
             <4110CF55.1060506@spg.tu-darmstadt.de> 
Subject: Re: Double slashes in amd variables?

Hauke, thanks for the report.  You're right: it was impossible to get double
slashes.  Amd translates all escape sequences including \/, and later on it
normalizes slashes into a single slash.  This normalization is done for
historical reasons, to make the strings look pretty after a bunch of
variable expansion and concatenation and to deal with some old OSs where a
double slash had a real meaning.

I fixed it now.  With the fix, you can now put "\\\/\\\/" to get two
consecutive slashes in an amd map.  The fix will be in the 6.1 branch
nightly cvs snapshot by tomorrow.  If you want, apply this patch below to
get that functionality now.

Please let me know if it works for you.

Erez.


Index: ChangeLog
===================================================================
RCS file: /home/cvsroot/am-utils/ChangeLog,v
retrieving revision 1.471
diff -u -r1.471 ChangeLog
--- ChangeLog	7 Aug 2004 16:32:49 -0000	1.471
+++ ChangeLog	7 Aug 2004 17:00:35 -0000
@@ -1,3 +1,11 @@
+2004-08-07  Erez Zadok  <ezk@cs.sunysb.edu>
+
+	* doc/am-utils.texi (Program Filesystem): document how to get
+	double slashes in Amd maps.
+
+	* amd/opts.c (normalize_slash): support escaped slashes, needed
+	for SMB mounts.  Use '\\\/\\\/' in a string to get a double slash.
+
 2004-08-06  Erez Zadok  <ezk@cs.sunysb.edu>
 
 	* amd/amfs_program.c (amfs_program_match): bug fix.  Complain if
Index: NEWS
===================================================================
RCS file: /home/cvsroot/am-utils/NEWS,v
retrieving revision 1.88
diff -u -r1.88 NEWS
--- NEWS	7 Aug 2004 16:32:49 -0000	1.88
+++ NEWS	7 Aug 2004 17:00:35 -0000
@@ -31,6 +31,9 @@
 - restructured the restarting of already-mounted filesystems, in the process
   also fixing a problem with restarting nfsx components
 
+- support escaped slashes, needed for SMB mounts.  Use '\\\/\\\/' in a
+  string to get a double slash.
+
 - bugs fixed:
 	* various memory management problems (leaks, etc)
 	* fixed nfsx support
Index: amd/opts.c
===================================================================
RCS file: /home/cvsroot/am-utils/amd/opts.c,v
retrieving revision 1.28
diff -u -r1.28 opts.c
--- amd/opts.c	6 Jan 2004 03:56:20 -0000	1.28
+++ amd/opts.c	7 Aug 2004 17:00:35 -0000
@@ -307,6 +307,7 @@
 
 /*
  * expand backslash escape sequences
+ * (escaped slash is handled separately in normalize_slash)
  */
 static char
 backslash(char **p)
@@ -929,6 +930,9 @@
       /* assert(*f != '/'); */
       /* keep copying up to next / */
       while (*f && *f != '/') {
+	/* support escaped slashes '\/' */
+	if (f[0] == '\\' && f[1] == '/')
+	  f++;			/* skip backslash */
 	*t++ = *f++;
       }
 
Index: doc/am-utils.texi
===================================================================
RCS file: /home/cvsroot/am-utils/doc/am-utils.texi,v
retrieving revision 1.85
diff -u -r1.85 am-utils.texi
--- doc/am-utils.texi	3 Aug 2004 18:37:23 -0000	1.85
+++ doc/am-utils.texi	7 Aug 2004 17:00:36 -0000
@@ -3542,6 +3542,15 @@
 shell.  Therefore, if a script is to be used as a mount/umount
 program, it @dfn{must} begin with a @code{#!} interpreter specification.
 
+Often, this program mount type is used for Samba mounts, where you
+need a double slash in pathnames.  However, @i{Amd} normalizes
+sequences of slashes into one slash.  Therefore, you must use an
+escaped slash, preceded by an escaped backslash.  So to get a double
+slash in the mount command, you need the eight character sequence
+@samp{\\\/\\\/} in your map.  For example:
+
+@samp{mount="/sbin/mount mount -r -t smbfs -o-N,-Ihostname \\\/\\\/guest@@venus/mp3"}
+
 If a filesystem type is to be heavily used, it may be worthwhile adding
 a new filesystem type into @i{Amd}, but for most uses the program
 filesystem should suffice.

</snip>

Please request a pull-up to netbsd-2-0 (probably also netbsd-1-6?).

The following could be a template for a map in '/usr/share/examples/amd': 

# $NetBSD$
#
# /smb - smbmount(8) a share by cd'ing into it
# Make sure /smb and the local mountpoint /local/mp3 exist

mucke		type:=program;\
		rhost:=venus;rfs:=/mp3;fs=/local/mp3;\
		mount="/sbin/mount mount -r -t smbfs -o-N,-I${rhost} \\\/\\\/${rhost}/${rfs} ${fs}";\
		unmount="/sbin/umount umount ${fs}"
>Release-Note:
>Audit-Trail:
>Unformatted: