How to achieve customized CUPS printing in RHEL ?

Solution Unverified - Updated -

Environment

  • Red Hat Enterprise Linux 6

  • Common Unix Printing System (CUPS)

Issue

  1. How to get SElinux label of the printed file in the filter for using it as a label in a header or footer?

  2. Is it possible to get a printer reply whether the printing job is successful. We need to log a successful execution or a partial execution, e.g. 5 pages of 10-page job are printed successfully.

  3. Is there any particular examples on how to modify the printed file (the postscript one) to add additional pages?

  4. Are there any existing filter/backend examples for creating custom headers and footers?

Resolution

1. How to get SElinux label of the printed file in the filter for using it as a label in a header or footer?

There is no way for a CUPS filter to get the SELinux label of the file that is being printed. The reason for this is that the file being printed is copied to /var/spool/cups and it is the file in /var/spool/cups that is processed by CUPS.
Additional information about the files in /var/spool/cups can be found in the following Knowledgebase Solution
The only way to get the SELinux label of the file would be to pass it as a printing option, for example;

   lp -d <printer> -o label=unconfined_u:object_r::user_home_t:s0 /home/user/file.txt

Then custom filter could add this as a header or footer. We can create a shell script that would list the SELinux label for a file and then automatically add it to the 'lp' command line.

2. Is it possible to get a printer reply whether the printing job is successful. We need to log a successful execution or a partial execution, e.g. 5 pages of 10-page job are printed successfully.

This depends on the communication protocol being used to communicate with the printer.

3. Is there any particular examples on how to modify the printed file (the postscript one) to add additional pages?

The 'gs' command (part of the ghostscript) package can be used to concatenate PostScript files together.
For example, a command like:

   gs -dBATCH -dNOPAUSE -dSAFER -sDEVICE=pswrite -sOutputFile=combined.ps file1.ps file2.ps file3.ps

should combine the files "file1.ps", "file2.ps", and "file3.ps" into the file "combined.ps".

4. Are there any existing filter/backend examples for creating custom headers and footers?

One can check it in source cide, although of course the source code for all the CUPS filters is available from various sources.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.