Section 7.11. Printing to Windows Printers


7.11. Printing to Windows Printers

If you have printers connected to Windows systems, Samba can help you connect to these from Unix clients. First, it is necessary to create a printer share on the Windows system. Then, set up the printer on the Unix side by configuring a new printer and using a Samba printing program as the printer's filter.

7.11.1. Sharing Windows Printers

Sharing printers on Windows is not unlike sharing files. In fact, it is a little simpler. Open the Control Panel, then double-click the Printers icon to open the Printers window. Right-click the icon for the printer you want to share, and select Sharing . . . to open the dialog box shown in Figure 7-10 for a Windows Me system, or Figure 7-11 on a Windows Server 2003 system. (The dialog box appears slightly different on other Windows versions, but functions almost identically.)

Figure 7-10. Sharing printers on Windows Me


Figure 7-11. Sharing printers on Windows 2003


Click the "Shared as" radio button, then click the OK button. The printer is now accessible by other systems on the network.

7.11.2. Adding a Unix Printer

The Samba distribution comes with three programs that assist with printing on shared printers. The smbprint program works with systems that use the BSD printing system, smbprint.sysv works with systems that use System V printing, and smbspool works with systems that use CUPS. In the following sections, we show you how to install printers for each system.

7.11.2.1. BSD printers

The BSD printing system is used by many Unix variants. Here is the entry we added to our /etc/printcap file to support our HP DeskJet 932C printer, which is shared by maya, a Windows 2003 system:

 lp|maya-hp932c:\     :cm=HP 932C on maya:\     :sd=/var/spool/lpd/maya:\     :af=/var/spool/lpd/maya/acct:\     :if=/usr/local/samba/bin/smbprint:\     :mx=0:\     :lp=/dev/null: 

The first line creates names for the printer. We are calling it maya-hp932c, to describe its location on the network and the type of printer, and lp, so that programs will use it as the default printer. The rest of the lines specify keywords and values. The cm keyword allows us to assign a comment string to the printer. The sd and af keywords assign the printer's spool directory and accounting files, respectively. The if keyword assigns the print filter. We are using the smbprint command to send the output to the shared SMB printer. The mx keyword is set to 0 to allow a file of any size to be printed, and lp is set to /dev/null to discard error messages.

You can follow our model to create an entry for your own printer. If you want to go beyond the capabilities we used, refer to your system's printcap(5) manpage for a complete listing of keywords.

Go to your Samba source distribution's root directory and install the smbprint program like this:

 $ cp examples/printing/smbprint /usr/local/samba/bin 

Next create the printer's spool directory (as the root user):

 $ cd /var/spool/lpd $ mkdir maya $ chown lp:lp maya $ chmod 700 maya 

The smbprint program looks for a file named .config in the printer's spool directory, which contains information on how to connect to the printer share. Therefore, create this file and fill in the required information:

 $ cd maya $ touch .config $ chown lp:lp .config $ chmod 600 .config 

Use your preferred text editor to edit the .config file, and add the following:

 server=maya service=hpcolor username=unix-print password=Pr1n@ter 

This example is for our shared printer, which has a UNC of \\maya\hpcolor. Notice that we are using a username of unix-print and a password of Pr1n@ter. It is important that these credentials do not grant access to any network resources except this printer, in case someone can read the file's contents. If possible, unix-print should be a special account on the Windows server used just for allowing Unix clients to access this printer.

Finally, restart the printer daemon using the normal procedure on your server. The following command works on a Linux system runing BSD printing.

 $ /etc/init.d/lpd restart 

You can now try printing something. Run the following command:

 $ lpr textfile 

If you have everything set up correctly, the file prints on the shared printer. If you get "stair stepping" of text, caused by the printer not returning to the left margin at the beginning of every line, modify the if keyword in your printcap entry to run smbprint with the -t option.

7.11.2.2. System V printers

Sending print jobs from a System V Unix system is a little easier than with the BSD system. Here, you need to edit the smbprint.sysv script in the examples/printing directory of the Samba distribution and do the following:

  1. Change the server, service, and password parameters in the script to match the NetBIOS computer name, its shared printer service, and its password, respectively. For example, the following entries would be correct for the service in the previous example:

     server   = maya service  = hp username = unix-print password = Pr1n@ter 

  2. Run the following commands, which create a reference for the new printer (which we are naming hp_printer) in the printer capabilities file:

     $ lpadmin -p hp_printer -v /dev/null -i./smbprint.sysv $ enable hp_printer $ accept hp_printer 

After you've done that, restart the Samba daemons and try printing to hp_printer using any standard Unix program.

7.11.2.3. CUPS printers

CUPS uses a set of modules, called backends, to send print jobs to various destinations, such as local printers attached to parallel, serial, or USB ports, or over the network using Unix line printer daemon (LPD) protocol, Internet Printing Protocol (IPP), AppleTalk Printer Access Protocol (PAP), and so on. The software package does not come with a backend for SMB; the Samba suite includes the smbspool utility for this purpose.

To enable printing to remote SMB printers using CUPS, create a symbolic link named smb in the CUPS backend directory pointing to smbspool. Depending on installation options, these could be in a number of places in the directory hierarchy, so be sure to check your system. Using a common default installation, the command would look like this:

 $ ln -s /usr/local/samba/bin/smbspool /usr/lib/cups/backend/smb 

Issue a HUP signal to the CUPS daemon, cupsd, and check for the existence of SMB support with the lpinfo -v command. Its output should now include a line that says network smb.

To add a printer, use the CUPS web interface, accessible on the local system at http://localhost:631/, or use the lpadmin command:

 $ lpadmin -p hp932c -E -v smb://maya/hp932c -D "HP 932C on maya" 

This command creates and enables a new print spool called hp932c. The -v argument specifies the printer device, which in this case is accessed over the network using an SMB URI. If the printer is not guest-accessible, you'll need to provide a username and password in the URI. The full format is as follows:

 smb://[username[:password]@][workgroup/]server/printshare 

The lpadmin command makes changes to /etc/cups/printers.conf and sends a HUP signal to the cupsd daemon, resulting in the creation of a local raw printer spool. In this example, print data is passed in raw format to the Windows system, which has the necessary printer drivers and printer description files to format the data appropriately. The -D gives the printer a comment string.

Once you have the printer set up, it's time to test it out. CUPS understands both BSD-style and System V-style printing commands, so you can use whichever is more comfortable. Using the BSD lpr command, try something like:

 $ lpr -P hp932c textfile 

You should now be set up to use the printer from any application on the Unix system.




Using Samba
Using Samba: A File and Print Server for Linux, Unix & Mac OS X, 3rd Edition
ISBN: 0596007698
EAN: 2147483647
Year: 2004
Pages: 135

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net