10.2 Printing to Windows Printers

   

If you have printers connected to systems running Windows 95/98/Me or Windows NT/2000/XP, the printers can also be accessed from your Unix system using tools that are part of the Samba distribution. 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.

10.2.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.... This opens the dialog box shown in Figure 10-5 for a Windows 98 system, or Figure 10-6 on a Windows 2000 system. (The dialog box appears slightly different on other Windows versions, but functions almost identically.)

On Windows 95/98/Me systems, you may need to run file sharing in share-level (rather than user -level) access control mode to access a shared printer from Samba. To check or set this mode, go to Control Panel, then double-click on Network, then click on the Access Control tab. More detailed information on this can be found in Chapter 5.

Figure 10-5. Sharing printers on Windows 98
figs/sam2_1005.gif
Figure 10-6. Sharing printers on Windows 2000
figs/sam2_1006.gif

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

10.2.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 the Common Unix Printing System (CUPS). In the following sections we show you how to install printers for each system.

10.2.2.1 BSD printers

The BSD printing system is used by many Unix variants, including Red Hat Linux. With BSD printing, all the printers on the system have an entry in the /etc/printcap file, which is the database of printer capabilities used by the lpd line printer daemon and other programs that assist with printing. The Red Hat Linux implementation is a bit different in that /etc/printcap is a machine-generated file, which is re-created every time the lpd daemon is restarted by the /etc/rc.d/init.d/lpd script. Instead of editing /etc/printcap , we will add an entry for our printer in /etc/printcap.local , which the system automatically includes verbatim when creating /etc/printcap .

If you are using the version of Samba installed from an RPM file as on Red Hat Linux, you might be able to skip these directions and use the printconf tool, which has support for SMB printers. Unfortunately, this tool might not work correctly if you have installed Samba from the Samba source distribution.

Here is the entry we added to our /etc/printcap.local file to support our Hewlett-Packard DeskJet 932C printer, which is shared by maya , a Windows 98 system:

 lpmaya-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 both 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 zero to allow any size file 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) manual page 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  

We next create the printer's spool directory:

 #  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. We create this file and then fill in the required information:

 #  cd maya  #  >.config  #  chown lp:lp .config  #  chmod 600 .config  

Use your preferred text editor to edit the .config file, and enter three lines, like this:

 server=maya service=hp password="" 

This is for our shared printer having a UNC of \\maya\hp . When we created the printer share, we did not give it a password, so we use a null password here. If your printer share is on a Windows NT/2000/XP system, use your domain password.

Finally, restart the printer daemon:

 #  /etc/rc.d/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.

10.2.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 password = "" 
  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.

10.2.2.3 CUPS printers

CUPS [2] uses a set of modules, called backends , to send print jobs to various destinations, such as local printers attached to parallel, serial, or Universal Serial Bus (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.

[2] CUPS is open source software (http://www.opensource.org) developed by Easy Software Products. For more information, visit http://www.cups.org.

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 creates and enables the 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 option is used to give 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.

10.2.3 Samba Printing Options

Table 10-2 summarizes the Samba printing options.

Table 10-2. Printing configuration options

Option

Parameters

Function

Default

Scope

printing

bsd , sysv , cups , hpux , aix , qnx , plp , softq , or lprng

Printing system type of the Samba host

System-dependent

Share

printable (print ok)

boolean

Marks a share as a printing share

no

Share

printer (printer name)

string (Unix printer name)

Name for the printer that is shown to clients

System-dependent

Share

lpq cache time

numeric (time in seconds)

Amount of time in seconds that Samba will cache the printer queue status

10

Global

postscript

boolean

Treats all print jobs as PostScript by prefixing %! at the beginning of each file

no

Share

load printers

boolean

If yes , automatically loads each printer in the printcap file as printing shares

yes

Global

print command

string (shell command)

Unix command to perform printing

See below

Share

lpq command

string (shell command)

Unix command to return the status of the printing queue

See below

Share

lprm command

string (shell command)

Unix command to remove a job from the printing queue

See below

Share

lppause command

string (shell command)

Unix command to pause a job on the printing queue

See below

Share

lpresume command

string (shell command)

Unix command to resume a paused job on the printing queue

See below

Share

printcap name

(printcap)

string (filename)

Location of the printer capabilities file

System-dependent

Global

min print space

numeric (size in kilobytes)

Minimum amount of free disk space that must be present to print

Share

queuepause command

string (shell command)

Unix command to pause a queue

See below

Share

queueresume command

string (shell command)

Unix command to resume a queue

See below

Share

10.2.3.1 printing

The printing configuration option tells Samba which printing system to use. There are several different families of commands to control printing and print statusing. Samba supports seven different types, as shown in Table 10-3.

Table 10-3. Printing system types

Variable

Definition

BSD

Berkeley Unix system

SYSV

System V

CUPS

Common Unix Printing System

AIX

IBM's AIX operating system

HPUX

Hewlett-Packard Unix

QNX

QNX Realtime Operating System

LPRNG

LPR Next Generation

SOFTQ

SOFTQ system

PLP

Portable Line Printer

The value for this option must be one of these seven selections. For example:

 printing = SYSV 

The default value of this option is system-dependent and is configured when Samba is first compiled. For most systems, the configure script automatically detects the printing system to be used and configures it properly in the Samba makefile. However, if your system is a PLP, LPRNG, or QNX printing system, you need to specify this explicitly in the makefile or the printing share.

The most common system types are BSD, SYSV, and CUPS. Each printer on a BSD Unix server is described in the printer capabilities file ”normally /etc/printcap . See the section on the printcap file parameter for more information on this topic.

Setting the printing configuration option automatically sets at least three other printing options for the service in question: print command , lpq command , and lprm command . If you are running Samba on a system that doesn't support any of the printing styles listed in Table 10-3, simply set the commands for each of these manually.

10.2.3.2 printable

The printable option must be set to yes to flag a share as a printing service. If this option is not set, the share will be treated as a disk share instead. You can set the option as follows:

 [printer1]     printable = yes 
10.2.3.3 printer

The option, also called printer name , specifies the name of the printer on the server to which the share points. This option has no default and should be set explicitly in the configuration file, even though Unix systems themselves often recognize a default name such as lp for a printer. For example:

 [deskjet]     printer = hpdkjet1 
10.2.3.4 lpq cache time

The global lpq cache time option allows you to set the number of seconds for which Samba will remember the current printer status. After this time elapses, Samba will issue an lpq command (or whatever command you specify with the lpq command option) to get a more up-to-date status that it can report to users. This defaults to 10 seconds, but can be increased if your lpq command takes an unusually long time to run or you have lots of clients. A time setting of 0 disables caching of queue status. The following example resets the time to 30 seconds:

 [deskjet]     lpq cache time = 30 
10.2.3.5 postscript

The postscript option forces the printer to treat all data sent to it as PostScript. It does this by prefixing the characters %! to the beginning of the first line of each job. It is normally used with PCs that insert a ^D (control-D or "end-of-file" mark) in front of the first line of a PostScript file. It will not, obviously, turn a non-PostScript printer into a PostScript one. The default value of this options is no . You can override it as follows:

 [deskjet]     postscript = yes 
10.2.3.6 load printers

The load printers option tells Samba to create shares for all known printer names and load those shares into the browse list. Samba will create and list a printer share for each printer name in /etc/printcap (or the system equivalent). For example, if your printcap file looks like this: [3]

[3] We have placed annotated comments off to the right in case you've never dealt with this file before.

 lp:\   :sd=/var/spool/lpd/lp:\  spool directory  :mx#0:\  maximum file size (none)  :sh:\  supress burst header (no)  :lp=/dev/lp1:\  device name for output  :if=/var/spool/lpd/lp/filter:  text filter  laser:\   :sd=/var/spool/lpd/laser:\  spool directory  :mx#0:\  maximum file size (none)  :sh:\  supress burst header (no)  :lp=/dev/laser:\  device name for output  :if=/var/spool/lpd/lp/filter:  text filter  

the shares [lp] and [laser] are automatically created as valid print shares when Samba is started. Both shares borrow the configuration options specified in the [printers] section to configure themselves and are available in the browse list for the Samba server. The default value for this option is yes . If you prefer to specify each printer explicitly in your configuration file, use the following:

 [global]     load printers = no 
10.2.3.7 print command, lpq command, lprm command,lppause command, lpresume command

These options tell Samba which Unix commands control and send data to the printer. The Unix commands involved are: lpr (send to Line PRinter), lpq (List Printer Queue), lprm (Line Printer ReMove), and optionally lppause and lpresume . Samba provides an option named after each command, in case you need to override any of the system defaults. For example, consider the following:

 lpq command = /usr/ucb/lpq %p 

This would set lpq command to use /usr/ucb/lpq . Similarly:

 lprm command = /usr/local/bin/lprm -P%p %j 

would set the Samba printer remove command to /usr/local/bin/lprm and provide it the print job number using the %j variable.

The default values for each option are dependent on the value of the printing option. Table 10-4 shows the default commands for each printing option. The most popular printing system is BSD.

Table 10-4. Default commands for various printing options

Option

BSD, AIX, PLP, LPRNG

SYSV, HPUX

QNX

SOFTQ

print command

lpr -r -P%p %s

lp -c -d%p %s; rm %s

lp -r -P%p %s

lp -d%p -s %s; rm %s

lpq command

lpq -P%p

lpstat -o%p

lpq -P%p

lpstat -o%p

lprm command

lprm -P%p %j

cancel %p-%j

cancel %p-%j

cancel %p-%j

lppause command

lp -i %p-%j -H hold

(SYSV only)

None

None

None

lpresume command

lp -i %p-%j -H resume

(SYSV only)

None

None

qstat -s -j%j -r

It is usually unnecessary to reset these options in Samba, with the possible exception of the print command . This option might need to be set explicitly if your printing system doesn't have a -r (remove after printing) option on the printing command. For example:

 print command = /usr/local/lpr -P%p %s; /bin/rm %s 

With a bit of judicious programming, these smb.conf options can also be used for debugging:

 print command = cat %s >>/tmp/printlog; lpr -r -P%p %s 

Using the previous configuration, it is possible to verify that files are actually being delivered to the Samba server. If they are, their contents will show up in the file /tmp/printlog .

After BSD, the next most popular kind of printing system is SYSV (or System V) printing, plus some SYSV variants for IBM's AIX and Hewlett-Packard's HP-UX. These systems do not have an /etc/printcap file. Instead, the printcap file option can be set to an appropriate lpstat command for the system. This tells Samba to get a list of printers from the lpstat command. Alternatively, you can set the global configuration option printcap name to the name of a dummy printcap file you provide. In the latter case, the file must contain a series of lines such as:

 lpprint1My Printer 1 print2My Printer 2 print3My Printer 3 

Each line names a printer followed by aliases for it. In this example, the first printer is called lp , print1 , or My Printer 1 , whichever the user prefers to use. The first name is used in place of %p in any command Samba executes for that printer.

Two additional printer types are also supported by Samba: LPRNG (LPR New Generation) and PLP (Public Line Printer). These are public domain and open source printing systems and are used by many sites to overcome problems with vendor-supplied software. Samba also supports the printing systems of the SOFTQ and QNX real-time operating systems.

10.2.3.8 printcap name

If the printcap name option (also called printcap ) appears in a printing share, Samba uses the file specified as the system printer capabilities file (normally /etc/printcap ). However, you can reset it to a file consisting of only the printers you want to share over the network. The value must be the filename (with its complete path specified) of a printer capabilities file on the server:

 [deskjet]     printcap name = /usr/local/samba/lib/printcap 

The CUPS printing system uses its own method of determining printer capabilities, rather than the standard printcap file. In this case, set printcap name as follows:

 [global]     printing = cups     printcap name = cups 
10.2.3.9 min print space

The min print space option sets the amount of space that must be available on the disk that contains the spool directory if printing is to be allowed. Setting it to zero (the default) turns the check off; setting it to any other number sets the amount of free space in kilobytes required. This option helps to avoid having print jobs fill up the remaining disk space on the server, which can cause other processes to fail:

 [deskjet]     min print space = 4000 
10.2.3.10 queuepause command

This configuration option specifies a command that tells Samba how to pause an entire print queue, as opposed to a single job on the queue. The default value depends on the printing type chosen . You should not need to alter this option.

10.2.3.11 queueresume command

This configuration option specifies a command that tells Samba how to resume a paused print queue, as opposed to resuming a single job on the print queue. The default value depends on the printing type chosen. You should not need to alter this option.

   


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

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