site  contact  subhomenews

Smallest and simplest Samba client

July 31, 2018 — BarryK

This is something that I have wanted to figure out for a very long time. What is the smallest and simplest setup if I only want a samba client on a PC, not a server?

I am currently rewriting EasyShare, my easy network file and printer sharing GUI app. This is able to use sshfs or samba, but is actually designed such that samba is required. But, is it really, and if so, what files can it be reduced down to for a client-only system? Strangely, this question is not really answered anywhere on the Internet.

My EasyOS and Quirky will not function as a samba server, however, will have a sshfs server, and cups server, so can serve files and printers. However, other computers on the network may have smb or samba servers, and my PC must be able to connect to them.

basically, EasyShare uses the 'arp-scan' utility to discover the ip-addresses on the network, then 'mpscan' to find server ports. For samba/smb servers, 'nbtscan' is used to obtain the netbios-name/hostname, and for computers that serve sshfs, the 'nmap' utility is used to obtain hostname.

The sticking point is how to discover smb shares on the remote computer. Up to now, I used 'smbclient', which brings with it most of the shared libraries of the samba package.

There are some alternatives to automatically discover shares. A "share" is a name that samba assigns to a particular shared folder or printer.

I discovered that VLC multimedia player uses libdsm for samba discovery, though I couldn't see how it can discover shares. Also, libdsm only supports smbv1, which is too old. Windows 10 has dropped support for smbv1 by default, though apparently it can be enabled. However, smbv1 is considered to be a security risk.

Windows 10 does by default support smbv2 and smbv3. Ah, there is a library, 'libsmb2', with example utilities, that supports smbv2 -- however, whatever I tried to do with the utilities, they always crashed.

I did read that 'nmap' can discover smb shares, but I don't know how.

So, I am back on 'smbclient', meaning that the samba package is required. But, what else from the samba package is required? What about those 'smbd' and 'nmbd' daemons?

I was reminded about those daemons a few days ago, when one of the EasyOS testers thought that they might be responsible for his usb-stick (with easyOS on it, from which he booted) running hot after an overnight backup. This reminded me that sometime ago I noticed that the samba daemons were cpu hogs. Up to now, I have always automatically assumed that they are needed, but what for?

Note, there are lots of posts on the Internet about smbd being a cpu hog, just google "smbd is a cpu hog".

I successfully connected to a Windows 10 machine, from a pc running EasyOS and only the 'smbclient' utility -- absolutely nothing else from the samba package.

Furthermore, I studied the compile options, and created the smallest possible 'smbclient' utility. The smbv2 protocol is sufficient, so I compiled samba 3.6.25 -- 4.x is not required. I will document this exactly soon, when I put it into oe-qky-src, my fork of OpenEmbedded.

There are three packages needed, 'nbtscan', which has the 'nbtscan' utility, 'cifs-utils', which has the 'mount.cifs' utility, and the 'smbclient' utility from samba. All of this can be seen in action in script /usr/local/EasyShare/easyshare, in the next release of EasyOS and Quirky.

I have create a PET, smbclient3-3.6.25-pyro64.pet, which is 1.87MB, compared with the 10.5MB samba PET package I was using before.

For the record, here are some links:
libdsm: https://videolabs.github.io/libdsm/
libsmb2: https://github.com/sahlberg/libsmb2 

It is still on the cards that I might find a light-weight share discovery utility to replace smbclient! 

Tags: easy, quirky, linux