Friday, January 8, 2010

Accessing Shares with smbsh and smbfs





Accessing Shares with
smbsh and smbfs



The smbclient program is not the only way to access Windows
shares. Linux provides two other alternatives: the smbsh shell and the
amazingly useful smbfs file system.



The first option is smbsh, which is actually just a bash shell
invoked inside a Samba "wrapper." The wrapper is a shared library
that intercepts file-related system calls in order to create a virtual
directory at /smb. Any dynamically linked
program run under this environment will be able to access a Windows network as
if it were part of the local file system.



The virtual directory is organized as class=docemphasis1>/smb/<server>/<share>/<path�>/<file>.
For example,



$ ls /smb


will list all available machines in a workgroup, and the
command



$ cp /smb/HOMER/site-local/sql/tables.sql ./


will copy a file on //HOMER/site-local
to the current directory. Keep in mind that smbsh will not work with statically
linked programs, and in fact the Samba documentation refers to the SMB
"wrapper" as "a hack."



Fortunately, there is a better option
available: Windows shares can actually be mounted on a Linux file system just
as if they were local partitions! This is equiva lent to the Windows and
Netware operations of mapping a network volume. However, instead of adding a
volume as a separate drive letter, the share can be mounted anywhere on the
Linux file system. The smbfs kernel module and the smbmount utility are
responsible for this bit of magic. Support for Samba file systems is included
in the kernel source distribution, but you may need to enable that support in
the kernel configuration and recompile. The configuration option is under the
Filesystems/ Network filesystems menu. Kernel recompilation is covered in
lang=EN-GB style='color:#003399'>Chapter 1.



# insmod smbfs
# smbmount //KEARNEY/C$ /mnt/remote-cdrom
lang=EN-GB># df
Filesystem�� 1k-blocks���� Used� Available� Use%� Mounted on
lang=EN-GB>/dev/hdc1������ 101075��� 40254����� 55602�� 42%� /
lang=EN-GB>/dev/hdc5������ 147740��� 32032���� 108079�� 23%� /var
lang=EN-GB>/dev/hdc6������ 147740���� 2039���� 138072��� 1%� /tmp
lang=EN-GB>/dev/hdc7����� 1981000� 1251183���� 627405�� 67%� /usr
lang=EN-GB>/dev/hdc4����� 5723816� 3859608��� 1567809�� 71%� /home
lang=EN-GB>//kearney/c$��� 101075��� 40254����� 55602�� 42%� /mnt/kearney-cdrive


The insmod ensures that the smbfs kernel
module is installed. Of course, this step is not necessary if SMB file system
support is precompiled into the kernel. The standard mount command cannot build
the appropriate data structures necessary for the smbfs modules, so Samba
provides the smbmount command. The syntax is similar, but the first argument
should be a share name instead of a device name. Share names ending with a
dollar sign are not shown by Windows Explorer. This is a Microsoft-specific way
to implement "hidden" shares.
Samba will always show these
shares, however.



In the case of authenticated shares (and none of your shares
allow anonymous logins, right?), the username and domain required to connect to
the share can be provided with the -o
option:



# smbmount //KEARNEY/C$ /mnt -o username=pcurtis,workgroup=WORKGROUP, uid=root,gid=staff,fmask=0664,dmask=0775
�� password:


You will need to enter a password to complete the connection.
The other options set the user, group, and permissions under which the mounted
files will appear. In this example, the SMB file system is made available
read-only to any user on the machine, except for root and any user in the group
staff.



 





No comments: