Sharing a CUPS printer with Samba

Adding a printer in CUPS has been greatly simplified over the past few years. Yet sharing a CUPS printer with Samba in point’n’print mode is still cumbersome. You will find many HOWTOs on the net regarding this topic, but hardly any explains what happens “behind the scenes”, which makes potential troubleshooting hard.

My objective was simple: sharing a printer installed in CUPS with Samba in a way that would enable a Windows user to find that printer as a share on the server and then click on it in order to automatically install its drivers (that’s what point’n’print is all about). In order to achieve that objective, you need to append at least two sections to smb.conf – one responsible for sharing CUPS queues as printers and another one, responsible for a share called print$, where drivers for shared printers will reside. Anyway, the whole operation should begin with adding two lines to the [global] section of smb.conf:

printing = cups
printcap name = cups

This instructs Samba to communicate with CUPS using the libcups library for its printing needs (WARNING: Samba has to be compiled with CUPS support, and CUPS – with Samba support). Next you need to add a [printers] section or several [printer_name] sections to the configuration, depending on whether you want to share all printers accessible via CUPS or just some of them. The contents of the section are the same for both cases:

path = /var/spool/samba
guest ok = no
writable = no
printable = yes
printer name = CUPS_queue_name
printer admin = username

/var/spool/samba should be a folder with sticky bit set (chmod +t /path/to/folder). If you want anonymous users to be able to use the printers, set guest_ok to yes. The writeable parameter should always be set to no (Samba will take care of allowing printer jobs to be written to the given folder if you also set the printable parameter to yes). The printer name parameter should contain the name of the CUPS queue to which jobs sent to the shared printer will be delivered (if you define that parameter in the [printers] section than jobs from all printers shared by Samba will be sent to the queue given, unless a printer name is defined individually for a printer). The printer admin parameter should be set to the name of the user you will access the print$ share with (more below).

Next you should add a section responsible for the print$ share:

path = /var/lib/cups/drivers
browseable = no
guest ok = no
read only = yes
write list = username

/var/lib/cups/drivers is the folder where a directory structure containing drivers for Windows clients will be placed (more below). username should be the same in both sections described above and that user should have write access to the folder given in path.

Aftering adding the above sections to smb.conf and restarting Samba the printer should be visible among server shares. Yet this is not enough for its driver to be automatically installed. To accomplish that you first need to download the CUPS driver for Windows (Windows Driver from CUPS website, in the *.tar.gz format). Unpack the archive contents and run make install from a root shell – it will cause the required files to be copied to /usr/share/cups/drivers. But that’s not all – you need to copy 4 files from a working Windows installation (from the paths listed in cupsaddsmb manual) to /usr/share/cups/drivers: ps5ui.dll, pscript5.dll, pscript.hlp, pscript.ntf (WARNING: if after copying to Linux these files have uppercase names, make sure you rename them to lowercase). If this wasn’t enough, a special program supplied with Samba (cupsaddsmb) has to process the prepared drivers into a folder structure which will enable a Windows client to automatically download drivers. Typical usage of that tool looks like this:

cupsaddsmb -H localhost -U username -h localhost -v CUPS_queue_name

If that command is executed remotely, set the -H parameter to the name or IP address of the host Samba is running on and set the -h parameter to the name or IP address of the host CUPS is running on (it’s usually the same device). The value of the -U parameter should be the same as username in smb.conf sections described above and CUPS_queue_name is the name of the CUPS queue which you want to bind to the drivers prepared. Instead of a queue name you can also use the -a switch, which will bind all printers shared by Samba to the drivers prepared. Error reporting is a bit lousy in cupsaddsmb so it’s best to run it with the -v switch, which makes the program print any potential error mistakes. WARNING: if you run cupsaddsmb with the -v switch and it quits without generating any output then even if the return code is 0 it means the program has failed to work correctly. In that case check Samba and CUPS logs in search for any hints regarding failure reason.

The above steps should enable Windows clients to automatically install drivers after double-clicking the shared printer in Windows Explorer. Unfotunately, despite many attempts, I have failed to share a printer under a different name than its corresponding CUPS queue (cupsaddsmb returns with errors and the drivers aren’t automatically downloaded by the client). In particular, I couldn’t overcome CUPS‘s irritating limit for queue naming – the lack of ability to use spaces.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s