Getting CUPS to work with windows print servers

 - disper
 - tirp

Valid HTML 4.0!
Valid CSS!
Viewable with ANY browser!

One of the most popular print servers on Linux (and Mac OSX) is CUPS. My experiences with it are fairly good, but now and then I encounter some problems. This was also the case on our university, where windows servers are used as print servers. One has to login using the domain account and the printed pages are payed using PAS credit.

Note: newer versions of CUPS along with the system-config-printer graphical front-end seem to be able to print without customisation. So you can forget about the rest of the page. Good!

It may be useful to note my experience with some Infotec multi-function copiers. They have both a postscript (PS) and a PCL print queue. While the former appears to be benificial (CUPS uses postscript as its default format), large postscript files may cause the printer/copier to hang for a very long time (days). Using the PCL queue takes more processing on the client but seems to avoid this problem.

CUPS uses smbspool(8) to print pages to windows servers. This did not appear to work, whereas printing with smbclient(1) did (some relief). Wanting to get it working, I created a custom CUPS backend that uses the latter instead of the former. This also allowed me to solve the problem of the windows password being visible in the device uri (which is shown in the web interface). Note that this still is a work in progress: it is being used with success, but now and then I encounter issues. This page will be updated accordingly.

Following are sections for using the aforementioned programs. The final section gives a possible solution for using windows print servers with CUPS when smbspool(8) isn't working.

Printing with smbspool

A CUPS backend(7) is a program, usually located in /usr/lib/cups/backend/, that sends a job to a printer or print server. CUPS uses smbspool(8), which is part of samba, to spool jobs to windows servers. To this end, there is a symbolic link from /usr/lib/cups/backend/smb to /usr/bin/smbspool.

To test the backend, it is possible to invoke smbspool(8) by hand. For example:

DEVICE_URI="smb://server/printer" smbspool 1234 me sometitle 1 <test.ps

Printing with smbclient

It is also possible to use smbclient(1) to print. When logging into a printer share on a windows server, one can issue the print command to print a file. For example:

smbclient -W Domain -U me //server/printer
Added interface ip=xxx.xxx.xxx.xxx bcast=xxx.xxx.xxx.xxx nmask=xxx.xxx.xxx.xxx
Password: password
Domain=[Domain] OS=[Windows Server 2003 3790 Service Pack 2] Server=[Windows Server 2003 5.2]
smb: \> print test.ps
printing file test.ps as test.ps
xxxxx bytes printed
smb: \> quit

A CUPS backend using smbclient

When smbspool(8) doesn't work, it may be possible to get printing working with smbclient(1) instead. This can be done by adding a custom CUPS backend. Download the file smbc, save it as /usr/lib/cups/backend/smbc and make it executable. Make sure to make it owned by root.

You should still create the file /etc/samba/printing.auth containing your windows credentials, like this:

username = s123456
password = mypassword
domain   = TUE

To protect it from prying eyes, make it owned by user cupsys (or whatever CUPS backends are run by on your system) and make it readable for that user only. For Ubuntu users: this user is cupsys on Feisty, but lp on Gutsy.

Remains to setup CUPS. I recommend to add a printer using the web interface with a device uri with protocol smbc, like smbc://physfp.phys.tue.nl/n-IS2060PS

If you happen to use AppArmor in enforcing mode, you'll need to add #include <abstractions/samba> to the cupsd profile.

Revision history

  • 22 Aug 2007 - created
  • 28 Aug 2007 - removed num-copies, fixed filename parameter, added discovery
  • 04 Sep 2007 - added debugging info
  • 29 Oct 2007 - added error handling, got it working on Gutsy too