How can I tell smbclient not to translate a particular forward slash into a backward slash?

1.4k views Asked by At

The smbclient utility seems to unconditionally translate forward slashes in the command being passed to the remote Windows system. That might make sense when they are part of a path in the remote file system - smbclient thinks it's helping the user avoid mistakes. But not in a case like this:

auth='-Ubldguru%secret11'
homedir='\AutoHelp\prod'
UNC='//build2.company.com/c$'

keith@build1:~/build2> smbclient $auth --directory $homedir $UNC --command 'dir'
Domain=[BUILDDOM] OS=[Windows 7 Professional 7601 Service Pack 1] Server=[Windows 7 Professional 6.1]
  .                                   D        0  Mon Jun 15 13:19:31 2015
  ..                                  D        0  Mon Jun 15 13:19:31 2015
  adldap                              D        0  Wed Jun 10 15:37:14 2015
  jdfoutput                           D        0  Wed Jun 10 15:39:49 2015
  Version34                           D        0  Wed Jun 10 15:34:39 2015
  WORKING                             A        8  Mon Jun 15 10:33:02 2015
  _COMMON_DITA                        D        0  Tue Jun  9 15:11:21 2015
  _COMMON_GRAPHICS                    D        0  Tue Jun  9 15:11:36 2015

                51174 blocks of size 4194304. 38373 blocks available
keith@build1:~/build2> smbclient $auth --directory $homedir $UNC --command 'dir /s'
Domain=[BUILDDOM] OS=[Windows 7 Professional 7601 Service Pack 1] Server=[Windows 7 Professional 6.1]
NT_STATUS_NO_SUCH_FILE listing \s
keith@build1:~/build2> smbclient $auth --directory $homedir $UNC --command 'dir \/s'
Domain=[BUILDDOM] OS=[Windows 7 Professional 7601 Service Pack 1] Server=[Windows 7 Professional 6.1]
NT_STATUS_NO_SUCH_FILE listing \\s
keith@build1:~/build2> smbclient $auth --directory $homedir $UNC --command 'dir \\/s'
Domain=[BUILDDOM] OS=[Windows 7 Professional 7601 Service Pack 1] Server=[Windows 7 Professional 6.1]
NT_STATUS_NO_SUCH_FILE listing \\\s
keith@build1:~/build2> smbclient $auth --directory $homedir $UNC --command 'dir \\\/s'
Domain=[BUILDDOM] OS=[Windows 7 Professional 7601 Service Pack 1] Server=[Windows 7 Professional 6.1]
NT_STATUS_NO_SUCH_FILE listing \\\\s
keith@build1:~/build2> smbclient $auth --directory $homedir $UNC --command 'dir \\\\/s'
Domain=[BUILDDOM] OS=[Windows 7 Professional 7601 Service Pack 1] Server=[Windows 7 Professional 6.1]
NT_STATUS_NO_SUCH_FILE listing \\\\\s
keith@build1:~/build2>

As you can see in the above, smbclient (and I) know how to get a simple listing at the remote end. The problem is passing flags, which are given with a forward slash, to the remote command. ALL slashes seen by smbclient as it parses its ARGVs are blindly converted to backslashes, and I have found no way to escape the ones that should be forward/plain/real slashes.

(It might have been easier to find help "out there" - provided it even exists - if the man page for smbclient didn't speak specifically of the slashes around the UNC string.)

Am I missing something in the man page? Should I read the source code? Is this well known?

Keith

1

There are 1 answers

1
nobody On

You don't. The smbclient dir command does not take the same options as the dir command in Windows. The one and only parameter it recognizes is an optional "mask" / wildcard pattern. It has no use for forward slashes.

See the full documentation at https://www.samba.org/samba/docs/man/manpages/smbclient.1.html