Sams Teach Yourself Samba in 24 Hours

ContentsIndex

Hour 8: Printers

Previous HourNext Hour

Sections in this Chapter:

 

Hour 8
Printers

by Richard Sharpe

In Hour 7, "File Sharing," you looked at file sharing and how to configure it. In this hour, you look at printing with Samba in some detail. Samba's printing philosophy is that if UNIX can print it, Samba can too.

Printing with Samba encompasses the areas of

Figure 8.1 shows how versatile Samba can be, in that it supports printing from Windows (and DOS) clients to printers attached to UNIX systems and enables UNIX systems to print to printers attached to Windows systems.

Figure 8.1
Printing with Samba in a diverse environment.

I will explore each of these areas and configure printing on your Samba server.

If you have not yet read Hour 7, you should go back and do so, because I will build on many of the concepts presented in that hour.

Samba and Printing

From the point of view of a CIFS/SMB client, printing involves opening a file on a special file share, writing to it, and then closing that file. What happens to the file after it is closed by the client is of no concern to the client, but users generally would like such files to be printed. When you configure a print share under Samba, it takes care of getting files printed when they are closed. Figure 8.2 provides a more detailed look at printing from a CIFS/SMB client.

Figure 8.2
A more detailed view of printing from a client.

As you see in Figure 8.2, the steps taken by a client in printing a file are as follows:

Some clients, such as Windows 95, open print files on printer shares with blank (that is "") filenames. Don't be confused by this if you are poring through an smbd log file.

Apart from printing the files of course, clients also often want to be able to query the status of print queues. Samba supports this by returning print queue status information when a client requests that information.

So, because a print share is basically a file share with some extra attributes, you already know most of what you need to create a printer share. Almost all you need to add to a file share is the printable parameter. Here is a first try at a print share:

[first-printer]
    comment = My first printer
    path = /var/spool/samba
    printable = yes

Why does a print share need a path? Well, the files that the client prints need to go somewhere in the file system while they are being written. Typically, this directory is world writable and would have the sticky (t) bit set, so people cannot delete files they do not own.

Now when you restart Samba, what do you see? Figure 8.3 shows what you would see in Windows 9x or Windows NT if you bring up Network Neighborhood and double-click EAGLE.

Figure 8.3
Your first-printer shows up.

As you can see, your printer shows up. If you configure a printer on your client and print something to this share, what happens? You run into a couple of problems. The first is that Samba assumes that the printer associated with this share is called first-printer. Because this printer is unlikely to exist at this stage, the file you printed ends up in the directory specified in the path parameter and sits there. Here is a detailed listing of the directory /var/spool/samba after a file was printed to first-printer:

ls -al /var/log/samba
total 14
drwxrwxrwt   2 root     root         1024 Jan  8 12:09 .
drwxr-xr-x  14 root     root         1024 Dec 30 15:45 ..
-rwxr--r--   1 rsharpe  sharpe      12240 Jan  8 11:59 rjspc1.a00652

To fix this problem, you can add the printer parameter to tell Samba what printer to use. For example, to direct print jobs to lp, use the following parameter in the printer share:

printer = lp

If you add such a parameter to your first-printer share and the printer type is the same as you defined on your client (that is, the client has the correct driver) and you restart Samba, you should see your print jobs appear on the printer the next time you print to that queue.

Unfortunately, the first job you sent to the printer is never queued, because Samba spools a job only when it is closed. The first job sent simply sits in the directory specified by the path until you delete it.

To see that printing is indeed working, stop the queue on your Samba server; for example, if you have a BSD-derived printing system, try:

lpc stop lp

Then check the printer from your client. Under Windows 9x or Windows NT, you should see something like Figure 8.4.

Figure 8.4
Print queue information for your printer share.

Remember to restart the lp queue so that future print jobs are printed.

Printing can be as easy as that, but printing can also be a complex issue. You might have to worry about the printing style used by your Samba server, printer drivers that generate PostScript with those infamous Ctrl-Ds (^D) on the front of them, or a myriad of other issues. You will explore many of them in subsequent sections.

Sams Teach Yourself Samba in 24 Hours

ContentsIndex

Hour 8: Printers

Previous HourNext Hour

Sections in this Chapter: