4.2. Printing with CUPS
Although file shares are an important feature of many Samba servers, printer shares are also important. Before you can configure a Samba printer share, though, you must have a working local printer configuration. Most Linux distributions now use the Common Unix Printing System (CUPS; http://www.cups.org) as the local printing software. Therefore, before moving on to describing Samba printer share configuration, I present some basic information on CUPS configuration.
4.2.1. Installing CUPS
Because CUPS is a standard part of most Linux distributions, it may be installed on your system already. Use your package tools to look for a package called cups. If it's not installed, your computer either has no printing system installed or it uses an older printing system, such as LPRng or BSD LPD.
If your system uses an older printing system, you can either uninstall it and install CUPS in its place or forgo CUPS and use the older system instead. Samba configuration is similar in either case, and if local printing is working to your satisfaction, leaving your current printing system in place is likely to be the less troublesome solution, so you may want to skip ahead to Section 4.3. If you want to switch to CUPS, you should uninstall your existing printing software, if it's installed. In an RPM-based distribution, the -e parameter to rpm can uninstall the software: rpm -e lprng uninstalls the lprng package, if that's what your system uses. In Debian or its derivatives, the -r parameter to dpkg should do the job, as in dpkg -r lprng.
Once your system is shed of any printing system, the best way to install CUPS is to use a package for your distribution. These packages include SysV startup scripts designed for your distribution, as well as sample configuration files and perhaps patches. As with uninstalling programs, using your package system is usually the best approach. Some tools, such as Debian's apt-get and Gentoo's emerge, work over the network; for instance, typing emerge cups on a Gentoo system downloads and installs CUPS. Other tools, such as rpm on an RPM-based system or Debian's dpkg, require that you have a package file available locally. Frequently, these files are available on your installation CD-ROMs.
If you're using an older distribution, or one of the rare modern ones that doesn't yet provide CUPS as at least an option, you can obtain the CUPS source code from its web page. You must then compile and install the software locally. Consult the CUPS documentation if you need help doing this.
Linux printing, like the Unix printing systems before it, typically works on a PostScript model: printers are assumed to be PostScript printers, and programs that print generate PostScript files. (Some programs with simpler printing needs generate plain-text printing output, though.) Most printers sold today aren't PostScript models, though. For this reason, CUPS, like other printing tools, relies on Ghostscript (http://www.cs.wisc.edu/~ghost/) and related tools to convert PostScript into formats suitable for whatever printer you actually use. Frequently, installing CUPS automatically installs Ghostscript and perhaps a set of drivers and descriptions that CUPS uses to help pass data through Ghostscript. Particularly if you use a lower-level package management tool, you may need to install these tools manually before you can install CUPS; the package tool will complain about an unmet dependency if you haven't installed the appropriate prerequisites. In some cases, you may need to search for and manually install some driver files. One site that's likely to be helpful in this respect is the Linux Printing web site, http://www.linuxprinting.org/printer_list.cgi. Enter your printer brand and model in the selection boxes, and then click the Show button to obtain a report on the printer's compatibility with Linux. This page may include links to special drivers for some particularly new and exotic models. In most cases, downloading the PostScript Printer Description (PPD) file is worthwhile; it's often not necessary, but when it is, you can quickly add it to your system's printer list.
A basic CUPS installation knows how to handle generic PostScript printers and a few common non-PostScript models from a handful of manufacturers. If you begin following the options presented in the Section 4.2.2 and can't locate your printer model, you may need to track down and install additional drivers and/or CUPS printer descriptions. These are available from several different sources:
After you install one of these packages and restart the CUPS daemon, you should be able to select your printer by make and model in the CUPS configuration tools. In a few cases, though, you'll need to select a compatible model. For instance, many mid-range laser printers use the Printer Control Language (PCL) created by Hewlett-Packard (HP). Thus, you may be able to get a printer working by selecting an appropriate HP LaserJet model even if yours is another make. Consult your printer's documentation to learn if it's compatible with a more popular model.
4.2.2. Adding Printers to CUPS
The simplest way to add printers to CUPS is to use the CUPS web-based administration tool. This tool runs on port 631 and is accessible by entering http://localhost:631 in a web browser running on the computer you want to configure. (You may be able to use the hostname rather than localhost, or even access a CUPS server from another computer on your network, depending on the CUPS security settings.) The result is a list of CUPS server options, such as Manage Printer Classes and Manage Jobs. Click the Manage Printers item to add, delete, or modify printer definitions. If this is the first time you've done this in your current session, you'll be asked for an administrative username and password. Type root and the root password. The result should resemble Figure 4-2, although this figure shows a system with several printers already configured, and yours may show none set up.
Figure 4-2. CUPS provides a web-based tool for managing printers
To add a local printer using the web-based interface, follow these steps from the printer administration screen shown in Figure 4-2:
Of course, the CUPS web interface, like other Linux GUI administration tools, works by modifying text files. In the case of CUPS, most configuration files reside in /etc/cups and its subdirectories. In particular, the file printers.conf defines the actual printers. If you prefer to directly modify the configuration file yourself, you can do so by editing this file. Printer definitions begin with the string Printer or DefaultPrinter (the latter is for the default printer; there should be only one of these) followed by the printer name and enclosed in angle brackets (<>). Subsequent lines set the options entered in the web-based tool; each begins with a keyword and continues with a string of some sort. A few options, such as State, are adjusted by CUPS as it operates. An example entry looks like this:
<DefaultPrinter hp4000> Info Hewlett-Packard HP LaserJet 4000 Series Location Parallel printer on /dev/lp1 DeviceURI parallel:/dev/lp1 State Idle Accepting Yes JobSheets none none QuotaPeriod 0 PageLimit 0 KLimit 0 </Printer>
As a general rule, it's easiest to create printer definitions using the CUPS web-based tool. Directly editing the printers.conf file can be tricky because you must know the syntax for all of the options, as well as option names. Directly editing the file can be a handy way to quickly make a change, though, such as changing the default printer.
4.2.3. Adjusting CUPS Browsing and Security
In addition to printers.conf, another CUPS configuration file is critically important: cupsd.conf. This file, which also resides in /etc/cups, controls overall server operations, including security features and browsing. In the context of CUPS, browsing refers to the automatic discovery of printers that are shared via the Internet Printing Protocol (IPP), the printing protocol used by CUPS for CUPS-to-CUPS printer sharing. One of the main advantages of CUPS over earlier Linux printing systems is that CUPS supports browsing. This fact can greatly simplify printer configuration on Linux clients: just ensure that the server and client support browsing, and the client will automatically detect remote printers and add them to its printer list. If you subsequently add a printer to a CUPS server, you won't need to touch the clients; they'll detect the new printers within a matter of minutes.
To enable browsing on a CUPS server, open cupsd.conf in a text editor, and look for the Browsing line, which will probably be about half-way through the file:
The default value for this option is On, meaning that browsing is enabled. Some distributions set this parameter to Off, though, presumably as a security precaution. If you want a server to announce its printers to other computers, be sure that Browsing is set to On.
You may also want to adjust the BrowseAddress lines, which appear shortly after the Browsing option. This parameter specifies the network addresses to which browse lists should be broadcast. On a small LAN, a value of @LOCAL should do well. This option tells CUPS to broadcast browse lists to its local network interfaces. You can also specify network blocks using broadcast IP addresses, as in 192.168.17.255 to send broadcasts to the 192.168.17.0/24 network. In fact, you can include several BrowseAddress lines to specify multiple networks:
BrowseAddress @LOCAL BrowseAddress 192.168.17.255
On the client side, the BrowseAllow and BrowseDeny options specify addresses from which browse packets should or should not be accepted. You can set these options as DNS hostnames, as domain names preceded by dots (as in .example.com), as IP addresses, as IP address/netmask pairs, or in various other forms. You can also use the same @LOCAL notation accepted by BrowseAddress. Typically, you'll set a CUPS client to accept browse packets from your local network, and perhaps from some others:
BrowseAllow @LOCAL BrowseAllow 192.168.17.0/24
The default for BrowseAllow is All, which accepts all browse packets. This configuration is appropriate for CUPS clients on small LANs, but if you're configuring a system on a larger network, you may want to restrict the remote printers it adds by explicitly setting BrowseAllow.
Most of the options in cupsd.conf are global; they apply to the CUPS configuration as a whole. CUPS also supports more fine-grained control in sections that are delimited by Location directives. These begin with the keyword Location and a location name, surrounded by angle brackets (<>), and end with </Location>:
<Location /printers> Order Deny,Allow Deny From All Allow from 127.0.0.1 Allow from 192.168.1.0/24 Allow from 172.24.21.0/24 Allow From @LOCAL </Location>
This example uses the Allow directive to tell CUPS to grant access to the specified computers and networks. This example also controls access to the /printers location, which, as you might expect, provides the means to access printers. Other locations of interest include the root (/), which sets the default security policy; /jobs, which controls the ability to adjust job priorities, delete jobs, and so on; and /admin, which controls administrative functions such as adding new printers. This last section frequently includes AuthType and AuthClass options, which tell CUPS to require authentication; after all, you don't want to let just anybody access the printer administration tools.