10.1 Sending Print Jobs to Samba

   

A printer shared by the Samba server shows up in the list of shares offered in the Network Neighborhood. If the printer is registered on the client machine and the client has the correct printer driver installed, the client can effortlessly send print jobs to a printer attached to a Samba server. Figure 10-1 shows a Samba printer as it appears in the Network Neighborhood of a Windows client.

Figure 10-1. A Samba printer in the Network Neighborhood
figs/sam2_1001.gif

To administer printers with Samba, you should understand the basic process by which printing takes place on a network. On the client system, the application software prints by utilizing the system's printer driver for the printer that will be creating the actual output. It is the printer driver software running on the client system that translates the application's high-level calls into a stream of binary data specific to the model of printer in use. In the case of a serial, parallel, or USB printer, the data is stored in a temporary file in the local system's printer queue and then sent through the respective port directly to the printer. For a network printer, the file is sent over the network.

Because the data has already been processed through a printer driver by the time it reaches the Samba host, make sure the printer on the Unix system is configured without any printer driver and that it will print whatever data it receives in raw form. If you already have the printer configured for use by Unix applications, you might need to set up another queue for it to print documents received from Windows clients correctly.

Sending a print job to a printer on a Samba server involves four steps:

  1. Opening and authenticating a connection to the printer share

  2. Copying the file over the network

  3. Closing the connection

  4. Printing and deleting the copy of the file

When a print job arrives at a Samba server, the print data is temporarily written to disk in the directory specified by the path option of the printer share. Samba then executes a Unix print command to send that datafile to the printer. The job is then printed as the authenticated user of the share. Note that this can be the guest user , depending on how the share is configured.

10.1.1 Print Commands

To print the document, you'll need to inform Samba of the command used to print and delete a file. On Linux, which uses a BSD-style printing system, a command that does this is:

 lpr -r -P   printer     file   

This command tells lpr to retrieve the name of the printer in the system configuration file ( /etc/printcap ) and interpret the rules it finds there to decide how to process the data and which physical device to send it to. Note that because the -r option has been specified, the file will be deleted after it has been printed. Of course, the file removed is just a copy stored on the Samba server; the original document on the client is unaffected.

The process is similar on System V Unix. Here, printing and deleting become a compound command:

 lp -d   printer   -s   file   ; rm   file   

In this case, the /etc/printcap file is replaced with a different set of configuration files residing in /usr/spool/lp . Because the lp command has no option to delete the file after it is printed, we have added the rm command.

10.1.2 A Minimal Printing Setup

Let's start with a simple yet illustrative printing share. Assuming that you're on a Linux system and you have a printer called netprinter listed in the printer capabilities file, the following addition to your smb.conf file makes the printer accessible through the network:

 [printer1]     printable = yes     print command = /usr/bin/lpr -P%p -r %s     printer = netprinter     printing = BSD     path = /var/tmp 

The variable %s in the print command option is replaced with the name of the file to be printed when Samba executes the command. There are four Samba configuration-file variables specifically for use with printing options. They are shown in Table 10-1.

Table 10-1. Printing variables

Variable

Definition

%s

The full pathname of the file on the Samba server to be printed

%f

The name of the file itself (without the preceding path) on the Samba server to be printed

%p

The name of the Unix printer to use

%j

The number of the print job (for use with lprm , lppause , and lpresume )

For other flavors of Unix, it is necessary to modify both the printing and print command options. For System V Unix, we would specify:

 [printer1]     printing = SYSV     print command = lp -d%p -s %s; rm %s 

With the printing = SYSV parameter, we notify Samba that the local printing system uses the System V Unix method. As mentioned earlier, the %p variable resolves to the name of the printer, while the %s variable resolves to the name of the file.

Clients might need to request the status of a print job sent to the Samba server. Because Samba sends print jobs to the Unix printing system for spooling, there might be a number of jobs in the queue at any given time. Consequently, Samba needs to communicate to the client not only the status of the current printing job, but also which documents are waiting to be printed on that printer. Samba also has to provide the client the ability to pause print jobs, resume print jobs, and remove print jobs from the printing queue. Samba provides options for each of these tasks . As you might expect, they borrow functionality from the following existing Unix commands:

  • lpq

  • lprm

  • lppause

  • lpresume

We cover these options in more detail later in this chapter. For the most part, Samba provides reasonable default values for them based on the value of the printing configuration option, so you can probably get by without having to formulate your own commands for them.

Here are a few important items to remember about printing shares:

  • You must put printable = yes in all printer shares (even [printers] ) so that Samba knows they are printer shares. If you forget, the shares will be unusable for printing and will instead be treated as disk shares.

  • If you set the path configuration option in the printer section, any files sent to the printer(s) will be copied to the directory you specify instead of to the default location of /tmp . Because the amount of disk space allocated to /tmp can be relatively small in some Unix operating systems, many administrators prefer to use /var/tmp, /var/spool/tmp , or some other directory instead.

  • If you set guest ok = yes in a printer share and Samba is configured for share-level security, anyone can send data to the printer as the guest account user.

Using one or more Samba machines as a print server gives you a great deal of flexibility on your LAN. You can easily partition your available printers, restricting some to members of one department, or you can maintain a bank of printers available to all. In addition, you can restrict a printer to a select few by adding the valid users option to its share definition:

 [deskjet]     printable = yes     path = /var/spool/samba/print     valid users = elizabeth cozy jack heather alexander lina emerald 

All the other share accessibility options work for printing shares as well.

10.1.3 The [printers] Share

If a share named [printers] is in the configuration file, Samba will automatically read in your printer capabilities file and create a printing share for each printer that appears in the file. For example, if the Samba server had lp , pcl , and ps printers in its printer capabilities file, Samba would provide three printer shares with those names , each configured with the options in the [printers] share.

Recall that Samba obeys the following rules when a client requests a share that has not been created with an explicit share definition in the smb.conf file:

  • If the share name matches a username in the system password file and a [ homes ] share exists, a new share is created with the name of the user and is initialized using the values given in the [homes] and [global] sections.

  • Otherwise, if the name matches a printer in the system printer capabilities file and a [printers] share exists, a new share is created with the name of the printer and initialized using the values given in the [printers] section. (Variables in the [global] section do not apply here.)

  • If neither of those succeeds, Samba looks for a default service share. If none is found, it returns an error.

This brings to light an important point: be careful that you do not give a printer the same name as a user. Otherwise, users end up connecting to a disk share when they might have wanted a printer share instead.

Here is an example [printers] share for a Linux system. Some of these options are already defaults; however, we have listed them anyway for illustrative purposes:

 [printers]     printable = yes     printing = BSD     printcap name = /etc/printcap     print command = /usr/bin/lpr -P%p -r %s     path = /var/spool/lpd/tmp     min print space = 2000 

Here, we've given Samba global options that specify the printing type (BSD), a print command to send data to the printer and later remove the temporary file, the location of our printer capabilities file, and a minimum disk space for printing of 2MB.

In addition, we've created a [printers] share for each system printer. Our temporary spooling directory is specified by the path option: /var/spool/lpd/tmp . Each share is marked as printable ”this is a necessary option, even in the [printers] section.

10.1.4 Testing the Configuration

After running testparm and restarting the Samba daemons, you can check to make sure everything is set up correctly by using smbclient to send a file to the printer. Connect to the printer using the command:

 #  smbclient /   server   /   printshare  

and then use the print command to print a file:

 smb: />  print   textfile  

If you connect to a print share served by a Windows 95/98/Me system configured to use user-mode security and cannot authenticate using what you know to be a correct username and password, try reconfiguring the Windows system to use share-mode security.

When you print something through the Samba server via smbclient , the following actions should occur:

  • The job appears ( briefly ) in the Samba spool directory specified by the path.

  • The job shows up in your print system's spool directory.

  • The job disappears from the spool directory that Samba used.

If smbclient cannot print, you can reset the print command option to collect debugging information:

 print command = echo "printed %s on %p" >>/tmp/printlog 

A common problem with Samba printer configuration is forgetting to use the full pathnames for commands. Another frequent problem is not having the correct permissions on the spooling directory. [1] As usual, check your Samba log files and system log files for error messages. If you use BSD printing, you can change the lp keyword in the printer's printcap entry to something other than /dev/null , allowing you to collect error messages from the printing system.

[1] If you are using Linux, you can use the checkpc command to check for this type of error.

More information on debugging printers is in the file docs/textdocs/Printing.txt in the Samba source distribution. The Unix print systems are covered in detail in leen Frisch's Essential Systems Administration (published by O'Reilly).

10.1.5 Enabling SMB Printer Sharing in Mac OS X

With Samba preinstalled with Mac OS X, sharing access to a printer among Windows clients is easy. First, of course, you should set up local access using the Print Center application (located in /Applications/Utilities ). Under the Printers menu, select Add Printer..., and make the appropriate selection from the pop-up menu. For example, if the printer is directly attached, select USB; if the printer is powered on, it should appear in the list. Choose the printer, and press the Add button.

Edit /etc/smb.conf , uncommenting the [printers] share and making any additional configuration changes you feel are necessary. Finally, enable the Samba startup item as described in Chapter 2, either by checking Windows File Sharing in Sharing Preferences or by manually editing /etc/hostconfig . Now your printer can be used by remote Windows clients.

On Mac OS X and some other BSD-based systems, you can test your configuration using smbutil . The following will send the file named print_test_file to the printer named printshare on the server bsdserver :

 %  smbutil print //bsdserver/printshare print_test_file  

See Chapter 5 for more information on using smbutil .

10.1.6 Setting Up and Testing a Windows Client

Now that Samba is offering a workable printer, you can set up your access to it on a Windows client. Browse through the Samba server in the Network Neighborhood. It should now show each printer that is available. For example, in Figure 10-1, we saw a printer called lp .

Next, you need to have the Windows client recognize the printer. Double-click the printer icon to get started. If you try to select an uninstalled printer (as you just did), Windows will ask you if it should help configure it for the Windows system. Click the Yes or OK button, and the Printer Wizard will open .

If you are installing a printer on Windows 95/98/Me, the first thing the wizard will ask is whether you need to print from DOS. Let's assume you don't, so choose the "No" radio button and press the Next > button to get to the manufacturer/model window, as shown in Figure 10-2.

Figure 10-2. Setting the manufacturer and model of the printer
figs/sam2_1002.gif

In this dialog box, you should see a large list of manufacturers and models for a huge number of printers. Select the manufacturer of your printer in the left side of the dialog box, and then the exact model of the printer in the list on the right side.

In some cases, you might not find your printer in the list, or the version of the printer driver included with Windows might be out of date. In cases such as these, consult the printer manufacturer's documentation on how to install the driver. Typically, you will click the Have Disk... button to install the driver from a CD-ROM or disk file.

If you don't see your printer on the list, but you know it's a PostScript printer, select Apple as the manufacturer and Apple LaserWriter as the model. This will give you the most basic PostScript printer setup ”and arguably one of the most reliable. If you already have PostScript printers attached, you will be asked about replacing or reusing the existing driver. Be aware that if you replace it with a new one, you might make your other printers fail. Therefore, we recommend you keep using your existing printer drivers as long as they're working properly.

Click the Next > or OK button. On Windows 95/98/Me, the Printer Wizard asks you to name the printer. On Windows NT/2000/XP, you need to right-click the printer's icon and select Properties to assign the printer a name. Figure 10-3 shows how we've named our printer to show that it's shared by the mixtec Samba server.

Figure 10-3. Setting the printer name
figs/sam2_1003.gif

Finally, on Windows 95/98/Me the Printing Wizard asks if it should print a test page. Click the "Yes" radio button, then the Finish button, and you should be presented with the dialog box shown in Figure 10-4. On Windows NT/2000/XP, the printer test function is also accessed through the printer's Properties dialog box.

Figure 10-4. Sending a test page to the printer
figs/sam2_1004.gif

If the test printing was unsuccessful , click the No button and the Printing Wizard will walk you through some debugging steps for the client side of the process. If the test printing does work, the remote printer will now be available to all Windows applications through the File and Print menu items.

   


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