ONLamp.com    
 Published on ONLamp.com (http://www.onlamp.com/)
 See this if you're having trouble printing code examples


FreeBSD Basics

Accessing Microsoft Files Using Sharity-Light

07/12/2000

Experiments in SMB

Windows still got you trapped? Maybe SAMBA File System support is what you need. Michael Lucas explains how to use SMBFS.

It is possible to access data on a Microsoft computer from your FreeBSD system if the two computers are networked together. In this article, we'll be using a utility called Sharity-Light to allow a computer running Windows NT 4 to export a shared directory to another computer running FreeBSD.

But first, a crash course in NT networking. Microsoft operating systems use the NetBIOS API to facilitate file sharing over the network. The NetBIOS API uses a computer's NetBIOS (or computer) name to find networked resources. A hidden component of this NetBIOS name is a hex number that represents the type of resources and services the computer has made available to other computers on the network.

When a user on an NT computer wishes to access data on another computer, he can issue an UNC (universal naming convention) from the run command. All UNCs have the same syntax:

\\netbiosname\sharename

The \\ tells the NT operating system that the required resource does not exist on this computer; instead, NT needs to go out on the network segment.

The name of the computer the resource lives on is netbiosname.

The name of the shared resource the user wishes to access is sharename.

So, the command:

\\pdc\stuff

tells NT to go out on the network, find a computer named pdc, and look for a shared directory named stuff on that computer.

However, the UNC will fail unless the user at pdc has created a directory called stuff and has shared it. In NetBIOS, only directories can be shared; in order to share files, they must be copied into a shared directory. To share a directory on an NT computer, right-click the Start menu, and click on "Explore." Highlight a directory, right-click, and choose "Properties." Click on the "Sharing" tab and change the default of "Not Shared" to "Shared As."

By default, the Share Name will be the same as the directory name; you can change this if you wish. You can also use the Permissions button to specify which users can access this share. Note, this only affects network users, not users sitting at this computer.

FreeBSD does not use NetBIOS to manage networked resources. Instead it uses NFS, the Network File System. We need a translator to convert NFS requests into the SMB (server message block) requests that NetBIOS understands. If I want Microsoft machines to access data on my FreeBSD computer, I use a utility called Samba to provide the necessary translation. If I want my FreeBSD machine to access data on a Microsoft computer, I use the Sharity-Light utility.

If you installed the ports collection when you installed FreeBSD, and are currently connected to the Internet, issue the following commands (as root) to install Sharity-Light:

cd /usr/ports/net/sharity-light
make
make install

If you didn't install the ports collection, build the package instead. Again, as root, and while connected to the Internet:

mkdir /usr/packages
lynx www.freebsd.org/ports

Cursor down to "net" and press Enter, then cursor down to the package link for sharity light and press Enter, then press d to download. Save the downloaded file in /usr/packages and exit lynx.

As root:

cd /usr/packages
pkg_add shar*

Notice that I'm a lazy typist. I just gave pkg_add enough information to distinguish the package I wished to install; I let the wildcard character * represent the rest of the filename.

Before we can use Sharity-Light, we need to know the NetBIOS name of the NT computer we wish to access, and the name of the share containing the data we need. To determine the NetBIOS name of an NT computer, right-click on that computer's Network Neighborhood icon and click on "Properties." The name in the box next to "Computer Name" is the NetBIOS name. To quickly see which resources that machine has shared, doubleclick on Network Neighborhood, then doubleclick on the NetBIOS name of the computer to see all of its shares.

We will also require a mountpoint for the data. Let's use a mountpoint of /nt_1:

mkdir /nt_1

Lastly, FreeBSD does not use NetBIOS names; it uses host names. If your network does not have a DNS server or a WINS server, you'll need to add an entry for the NT computer in the /etc/hosts file on your FreeBSD computer.

Let's pretend I have an NT computer named alpha with an IP address of 10.0.0.1 and a shared directory named files. My FreeBSD computer is named gamma with an IP address of 10.0.0.3. On gamma, I'll add the following line to /etc/hosts:

10.0.0.1	alpha

Then, I'll test connectivity by pinging alpha's IP address:

ping 10.0.0.1
PING 10.0.0.1 (10.0.0.1): 56 data bytes
64 bytes from 10.0.0.1: icmp_seq=0 ttl=128 time=1.061 ms
64 bytes from 10.0.0.1: icmp_seq=0 ttl=128 time=0.578 ms
64 bytes from 10.0.0.1: icmp_seq=0 ttl=128 time=0.591 ms
64 bytes from 10.0.0.1: icmp_seq=0 ttl=128 time=0.597 ms
^C
---10.0.0.1 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.578/0.707/1.061/0.205 ms

Note that ping will ping forever until you terminate it with Ctrl-C. If you don't get a response, check the cabling between the two computers before trying your ping again.

Having verified connectivity, let's ensure our hosts file is working:

ping alpha

You should get the same ping results as above; if not, double-check the NetBIOS name, look for typos in the /etc/hosts file, and try again.

Once we've verified that the two computers can communicate with each other using TCP/IP, let's try to access the data in the files share of alpha:

cd /usr/local/sbin
./shlight //alpha/files /nt_1 -U administrator -P pass
Using port 4761 for NFS.

Let's see what happened here: shlight is the name of the Sharity Light executable. The UNC to the resource is //alpha/files; notice that Sharity-Light uses the double-slash in Unix-style convention, rather than Microsoft convention.

The -U is mandatory and is followed by a username that is valid on the NT computer; this user does not have to be recreated on the FreeBSD computer. The -P is also mandatory and must be followed by the password associated with that username.>/p>

Note that a port was opened by NFS to manage the connection. To verify the mountpoint:

df
Filesystem     1K-blocks  Used   Avail   Capacity Mounted on
shlight-10924  208592     62256  146336  30%      /nt_1

Now, let's try to access the data:

cd /nt_1
ls

Regardless of whether the file system on alpha is VFAT or NTFS, we should be able to freely copy files back and forth between computers and make changes to files.

cp /etc/resolv.conf /nt_1
pico /nt_1/resolv.conf

Let's add a couple of nonsense lines I would never dream of putting in my real /etc/resolv.conf!!!

hello hello hello

and save the changes.

Walking over to alpha, I double-click on the files share and notice a new file called resolv.conf. I open up this file with Notepad and see the new lines I added from my FreeBSD computer.

When I'm finished accessing the files on the NT computer, I'll need to remember to unmount the share:

cd /usr/local/sbin
./unshlight /nt_1

Interesting things happen if I try to use Sharity-Light as a regular user. In FreeBSD, only root can mount filesystems. What if I'm a regular user who just happens to know the username and password for the administrative account on an NT computer? As a regular user:

cd /usr/local/sbin
./shlight //alpha/files /nt_1 -U administrator -P pass
Using port 1079 for NFS.
nfs mount /nt1: [1] Operation not permitted

The NT computer gave the OK for NFS to mount the share as the username and password were correct. However, NFS won't let a regular user mount a filesystem, so the user gets an error message instead.

Let's deal with some other common error messages when using Sharity-Light. This time as root:

cd /usr/local/sbin
./shlight //alpha/files /nt_1 -U adminstrator -P pass
error connecting to server: [13] Permission denied

This error message indicates an incorrect username or password. In this case, I've misspelled administrator.

./shlight //alpha/share /nt_1 -U administrator -P pass
error connecting to server: [5] Input/output error

This time I gave the incorrect sharename; there is no shared directory on alpha called share.

./shlight //beta/files /nt_1 -U administrator -P pass
beta: unknown host

Either there's no computer named beta, or I forgot to make an entry for it in my /etc/hosts file.

./shlight //alpha/files /nt -U administrator -P pass
nfs mount /nt: [2] No such file or directory

This time I forgot to create a directory named /nt to use as the mountpoint.

One final point: Sharity-Light can be used to mount shared directories located on either FAT or NTFS filesystems located on Microsoft computers; it can also mount data CD-ROMs located on Microsoft computers. However, it can't be used to access printers cabled to Microsoft computers; you'll need the added functionality of Samba to accomplish that task.

Dru Lavigne is a network and systems administrator, IT instructor, author and international speaker. She has over a decade of experience administering and teaching Netware, Microsoft, Cisco, Checkpoint, SCO, Solaris, Linux, and BSD systems. A prolific author, she pens the popular FreeBSD Basics column for O'Reilly and is author of BSD Hacks and The Best of FreeBSD Basics.


Read more FreeBSD Basics columns.

Discuss this article in the Operating Systems Forum.

Return to the BSD DevCenter.

 

Copyright © 2009 O'Reilly Media, Inc.