0b0e738
diff -up cups-1.4.6/config.h.in.lspp cups-1.4.6/config.h.in
0b0e738
--- cups-1.4.6/config.h.in.lspp	2011-01-12 16:39:06.572141559 +0000
0b0e738
+++ cups-1.4.6/config.h.in	2011-01-12 16:39:06.613139484 +0000
e3a2a9f
@@ -672,6 +672,12 @@
e3a2a9f
 #undef HAVE_SYS_STATVFS_H
e3a2a9f
 #undef HAVE_SYS_VFS_H
8936a5c
 
8936a5c
+/*
8936a5c
+ * Are we trying to meet LSPP requirements?
8936a5c
+ */
8936a5c
+
8936a5c
+#undef WITH_LSPP
8936a5c
+
e3a2a9f
 
8936a5c
 #endif /* !_CUPS_CONFIG_H_ */
8936a5c
 
0b0e738
diff -up cups-1.4.6/config-scripts/cups-lspp.m4.lspp cups-1.4.6/config-scripts/cups-lspp.m4
0b0e738
--- cups-1.4.6/config-scripts/cups-lspp.m4.lspp	2011-01-12 16:39:06.613139484 +0000
0b0e738
+++ cups-1.4.6/config-scripts/cups-lspp.m4	2011-01-12 16:39:06.613139484 +0000
8936a5c
@@ -0,0 +1,36 @@
8936a5c
+dnl
8936a5c
+dnl   LSPP code for the Common UNIX Printing System (CUPS).
8936a5c
+dnl
8936a5c
+dnl   Copyright 2005-2006 by Hewlett-Packard Development Company, L.P.
8936a5c
+dnl
8936a5c
+dnl   This program is free software; you can redistribute it and/or modify
8936a5c
+dnl   it under the terms of the GNU General Public License as published by
8936a5c
+dnl   the Free Software Foundation; version 2.
8936a5c
+dnl
8936a5c
+dnl   This program is distributed in the hope that it will be useful, but
8936a5c
+dnl   WITHOUT ANY WARRANTY; without even the implied warranty of
8936a5c
+dnl   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
8936a5c
+dnl   General Public License for more details.
8936a5c
+dnl
8936a5c
+dnl   You should have received a copy of the GNU General Public License
8936a5c
+dnl   along with this program; if not, write to the Free Software Foundation,
8936a5c
+dnl   Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301 USA
8936a5c
+dnl
8936a5c
+
8936a5c
+dnl Are we trying to meet LSPP requirements
8936a5c
+AC_ARG_ENABLE(lspp, [  --enable-lspp           turn on auditing and label support, default=no])
8936a5c
+
8936a5c
+if test x"$enable_lspp" != xno; then
8936a5c
+    case "$uname" in
8936a5c
+        Linux)
8936a5c
+            AC_CHECK_LIB(audit,audit_log_user_message, [LIBAUDIT="-laudit" AC_SUBST(LIBAUDIT)])
8936a5c
+            AC_CHECK_HEADER(libaudit.h)
8936a5c
+            AC_CHECK_LIB(selinux,getpeercon, [LIBSELINUX="-lselinux" AC_SUBST(LIBSELINUX)])
8936a5c
+            AC_CHECK_HEADER(selinux/selinux.h)
8936a5c
+            AC_DEFINE(WITH_LSPP)
8936a5c
+            ;;
8936a5c
+        *)
8936a5c
+            # All others
8936a5c
+            ;;
8936a5c
+    esac
8936a5c
+fi
0b0e738
diff -up cups-1.4.6/configure.in.lspp cups-1.4.6/configure.in
0b0e738
--- cups-1.4.6/configure.in.lspp	2010-06-22 22:42:44.000000000 +0100
0b0e738
+++ cups-1.4.6/configure.in	2011-01-12 16:39:06.614139432 +0000
8936a5c
@@ -42,6 +42,8 @@ sinclude(config-scripts/cups-pap.m4)
8936a5c
 sinclude(config-scripts/cups-pdf.m4)
8936a5c
 sinclude(config-scripts/cups-scripting.m4)
8936a5c
 
8936a5c
+sinclude(config-scripts/cups-lspp.m4)
8936a5c
+
8936a5c
 INSTALL_LANGUAGES=""
8936a5c
 UNINSTALL_LANGUAGES=""
8936a5c
 LANGFILES=""
0b0e738
diff -up cups-1.4.6/cups/cups.h.lspp cups-1.4.6/cups/cups.h
0b0e738
--- cups-1.4.6/cups/cups.h.lspp	2010-11-17 19:59:14.000000000 +0000
0b0e738
+++ cups-1.4.6/cups/cups.h	2011-01-12 16:39:06.615139383 +0000
cfc9fc5
@@ -15,6 +15,9 @@
cfc9fc5
  *   This file is subject to the Apple OS-Developed Software exception.
cfc9fc5
  */
cfc9fc5
 
cfc9fc5
+/* Copyright (C) 2005 Trusted Computer Solutions, Inc. */
cfc9fc5
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
cfc9fc5
+
cfc9fc5
 #ifndef _CUPS_CUPS_H_
cfc9fc5
 #  define _CUPS_CUPS_H_
cfc9fc5
 
bf1ed41
@@ -86,6 +89,12 @@ extern "C" {
cb06f24
 #  define CUPS_WHICHJOBS_COMPLETED 1
cfc9fc5
 
cfc9fc5
 
cfc9fc5
+# ifdef WITH_LSPP
cfc9fc5
+# define MLS_CONFIG "mls"
cfc9fc5
+# define TE_CONFIG "te"
cfc9fc5
+# define SELINUX_CONFIG "SELinux"
cfc9fc5
+# define UNKNOWN_SL "UNKNOWN SL"
cfc9fc5
+# endif /* WITH_LSPP */
cfc9fc5
 /*
cfc9fc5
  * Types and structures...
cfc9fc5
  */
0b0e738
diff -up cups-1.4.6/data/Makefile.lspp cups-1.4.6/data/Makefile
0b0e738
--- cups-1.4.6/data/Makefile.lspp	2008-11-12 19:30:57.000000000 +0000
0b0e738
+++ cups-1.4.6/data/Makefile	2011-01-12 16:39:06.616139335 +0000
8936a5c
@@ -25,7 +25,10 @@ BANNERS	=	\
8936a5c
 		secret \
8936a5c
 		standard \
8936a5c
 		topsecret \
8936a5c
-		unclassified
8936a5c
+		unclassified \
8936a5c
+		selinux \
8936a5c
+		mls \
8936a5c
+		te
e7076f3
 
8936a5c
 CHARMAPS =	\
8936a5c
 		euc-cn.txt \
0b0e738
diff -up cups-1.4.6/data/mls.lspp cups-1.4.6/data/mls
0b0e738
--- cups-1.4.6/data/mls.lspp	2011-01-12 16:39:06.617139286 +0000
0b0e738
+++ cups-1.4.6/data/mls	2011-01-12 16:39:06.617139286 +0000
8936a5c
@@ -0,0 +1,261 @@
8936a5c
+%!PS-Adobe-3.0
8936a5c
+%%BoundingBox: 0 0 612 792
8936a5c
+%%Pages: 1
8936a5c
+%%LanguageLevel: 1
8936a5c
+%%DocumentData: Clean7Bit
8936a5c
+%%DocumentSuppliedResources: procset bannerprint/1.0
8936a5c
+%%DocumentNeededResources: font Helvetica Helvetica-Bold Times-Roman
8936a5c
+%%Creator: Michael Sweet, Easy Software Products
8936a5c
+%%CreationDate: May 10, 2000
8936a5c
+%%Title: Test Page
8936a5c
+%%EndComments
8936a5c
+%%BeginProlog
8936a5c
+%%BeginResource procset bannerprint 1.1 0
8936a5c
+%
8936a5c
+%   PostScript banner page for the Common UNIX Printing System ("CUPS").
8936a5c
+%
8936a5c
+%   Copyright 1993-2005 by Easy Software Products
8936a5c
+%
8936a5c
+%   These coded instructions, statements, and computer programs are the
8936a5c
+%   property of Easy Software Products and are protected by Federal
8936a5c
+%   copyright law.  Distribution and use rights are outlined in the file
8936a5c
+%   "LICENSE.txt" which should have been included with this file.  If this
8936a5c
+%   file is missing or damaged please contact Easy Software Products
8936a5c
+%   at:
8936a5c
+%
8936a5c
+%       Attn: CUPS Licensing Information
8936a5c
+%       Easy Software Products
8936a5c
+%       44141 Airport View Drive, Suite 204
8936a5c
+%       Hollywood, Maryland 20636 USA
8936a5c
+%
8936a5c
+%       Voice: (301) 373-9600
8936a5c
+%       EMail: cups-info@cups.org
8936a5c
+%         WWW: http://www.cups.org
8936a5c
+%
8936a5c
+/CENTER {			% Draw centered text
8936a5c
+				% (name) CENTER -
8936a5c
+  dup stringwidth pop		% Get the width of the string
8936a5c
+  0.5 mul neg 0 rmoveto		% Shift left 1/2 of the distance
8936a5c
+  show				% Show the string
8936a5c
+} bind def
8936a5c
+/RIGHT {			% Draw right-justified text
8936a5c
+				% (name) RIGHT -
8936a5c
+  dup stringwidth pop		% Get the width of the string
8936a5c
+  neg 0 rmoveto			% Shift left the entire distance
8936a5c
+  show				% Show the string
8936a5c
+} bind def
8936a5c
+/NUMBER {			% Draw a number
8936a5c
+				% power n NUMBER -
8936a5c
+  1 index 1 eq {		% power == 1?
8936a5c
+    round cvi exch pop		% Convert "n" to integer
8936a5c
+  } {
8936a5c
+    1 index mul round exch div	% Truncate extra decimal places
8936a5c
+  } ifelse
8936a5c
+  100 string cvs show		% Convert to a string and show it...
8936a5c
+} bind def
8936a5c
+/CUPSLOGO {			% Draw the CUPS logo
8936a5c
+				% height CUPSLOGO
8936a5c
+  % Start with a big C...
8936a5c
+  /Helvetica findfont 1 index scalefont setfont
8936a5c
+  0 setgray
8936a5c
+  0 0 moveto
8936a5c
+  (C) show
75d0e82
+
8936a5c
+  % Then "UNIX Printing System" much smaller...
8936a5c
+  /Helvetica-Bold findfont 1 index 9 div scalefont setfont
8936a5c
+  0.25 mul
8936a5c
+  dup dup 2.0 mul moveto
8936a5c
+  (UNIX) show
8936a5c
+  dup dup 1.6 mul moveto
8936a5c
+  (Printing) show
8936a5c
+  dup 1.2 mul moveto
8936a5c
+  (System) show
8936a5c
+} bind def
8936a5c
+/ESPLOGO {			% Draw the ESP logo
8936a5c
+				% height ESPLOGO
8936a5c
+  % Compute the size of the logo...
8936a5c
+  0 0
8936a5c
+  2 index 1.5 mul 3 index
75d0e82
+
8936a5c
+  % Do the "metallic" fill from 10% black to 40% black...
8936a5c
+  1 -0.001 0 {
8936a5c
+    dup			% loopval
8936a5c
+    -0.15 mul		% loopval * -0.15
8936a5c
+    0.9 add		% 0.9 - loopval * 0.15
8936a5c
+    setgray		% set gray shade
75d0e82
+
8936a5c
+    0			% x
8936a5c
+    1 index neg		% loopval
8936a5c
+    1 add		% 1 - loopval
8936a5c
+    3 index		% height
8936a5c
+    mul			% height * (1 - loopval)
8936a5c
+    moveto		% starting point
75d0e82
+
8936a5c
+    dup			% loopval
8936a5c
+    3 index		% width
8936a5c
+    mul			% loopval * width
8936a5c
+    2 index		% height
8936a5c
+    lineto		% Next point
75d0e82
+
8936a5c
+    0			% x
8936a5c
+    2 index		% height
8936a5c
+    lineto		% Next point
75d0e82
+
8936a5c
+    closepath
8936a5c
+    fill
fada3a1
+
8936a5c
+    dup			% loopval
8936a5c
+    0.15 mul		% loopval * 0.15
8936a5c
+    0.6 add		% 0.6 + loopval * 0.15
8936a5c
+    setgray
75d0e82
+
8936a5c
+    dup			% loopval
8936a5c
+    neg 1 add		% 1 - loopval
8936a5c
+    3 index		% width
8936a5c
+    mul			% (1 - loopval) * width
8936a5c
+    0			% y
8936a5c
+    moveto		% Starting point
75d0e82
+
8936a5c
+    2 index		% width
8936a5c
+    exch		% loopval
8936a5c
+    2 index		% height
8936a5c
+    mul			% loopval * height
8936a5c
+    lineto		% Next point
75d0e82
+
8936a5c
+    1 index		% width
8936a5c
+    0			% y
8936a5c
+    lineto		% Next point
75d0e82
+
8936a5c
+    closepath
8936a5c
+    fill
8936a5c
+  } for
75d0e82
+
8936a5c
+  0 setgray rectstroke
75d0e82
+
8936a5c
+  /Helvetica-BoldOblique findfont 1 index 3 div scalefont setfont
8936a5c
+  dup 40 div
75d0e82
+
8936a5c
+  dup 4 mul 1 index 25 mul moveto (E) show
8936a5c
+  dup 10 mul 1 index 15 mul moveto (S) show
8936a5c
+  dup 16 mul 1 index 5 mul moveto (P) show
75d0e82
+
8936a5c
+  /Helvetica-BoldOblique findfont 2 index 5 div scalefont setfont
8936a5c
+  dup 14 mul 1 index 29 mul moveto (asy) show
8936a5c
+  dup 20 mul 1 index 19 mul moveto (oftware) show
8936a5c
+  dup 26 mul 1 index 9 mul moveto (roducts) show
75d0e82
+
8936a5c
+  pop
8936a5c
+} bind def
8936a5c
+%%EndResource
8936a5c
+%%EndProlog
8936a5c
+%%Page: 1 1
8936a5c
+gsave
75d0e82
+
8936a5c
+  % Determine the imageable area and device resolution...
8936a5c
+  initclip newpath clippath pathbbox	% Get bounding rectangle
8936a5c
+  72 div /pageTop exch def		% Get top margin in inches
8936a5c
+  72 div /pageRight exch def		% Get right margin in inches
8936a5c
+  72 div /pageBottom exch def		% Get bottom margin in inches
8936a5c
+  72 div /pageLeft exch def		% Get left margin in inches
75d0e82
+
8936a5c
+  /pageWidth pageRight pageLeft sub def	% pageWidth = pageRight - pageLeft
8936a5c
+  /pageHeight pageTop pageBottom sub def% pageHeight = pageTop - pageBottom
75d0e82
+
8936a5c
+  /boxWidth				% width of text box
8936a5c
+  pageWidth pageHeight lt
8936a5c
+  { pageWidth 54 mul }
8936a5c
+  { pageHeight 42 mul }
8936a5c
+  ifelse def
75d0e82
+
8936a5c
+  newpath				% Clear bounding path
75d0e82
+
8936a5c
+  % Create fonts...
8936a5c
+  /bigFont /Helvetica-Bold findfont	% bigFont = Helvetica-Bold
8936a5c
+  pageHeight 3 mul scalefont def	% size = pageHeight * 3 (nominally 33)
75d0e82
+
8936a5c
+  /mediumFont /Helvetica findfont	% mediumFont = Helvetica
8936a5c
+  pageHeight 1.5 mul scalefont def	% size = pageHeight * 1.5 (nominally 16.5)
8936a5c
+
8936a5c
+  % Offset page to account for lower-left margin...
8936a5c
+  pageLeft 72 mul
8936a5c
+  pageBottom 72 mul
8936a5c
+  translate
8936a5c
+
8936a5c
+  % Job information box...
8936a5c
+  pageWidth 36 mul 9 add		% x = pageWidth * 1/2 * 72 + 9
8936a5c
+  boxWidth 0.5 mul sub			% x-= 1/2 box width
8936a5c
+  pageHeight 30 mul 9 sub		% y = pageHeight * 1/2 * 72 - 9
8936a5c
+  boxWidth				% w = box width
8936a5c
+  pageHeight 14 mul			% h = pageHeight * 1/2 * 72
8936a5c
+  0.5 setgray rectfill			% Draw a shadow
75d0e82
+
8936a5c
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
8936a5c
+  boxWidth 0.5 mul sub			% x-= 1/2 box width
8936a5c
+  pageHeight 30 mul			% y = pageHeight * 1/4 * 72
8936a5c
+  boxWidth				% w = box width
8936a5c
+  pageHeight 14 mul			% h = pageHeight * 1/2 * 72
75d0e82
+
8936a5c
+  4 copy 1 setgray rectfill		% Clear the box to white
8936a5c
+  0 setgray rectstroke			% Draw a black box around it...
75d0e82
+
8936a5c
+  % Job information text...
8936a5c
+  mediumFont setfont			% Medium sized font
75d0e82
+
8936a5c
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
8936a5c
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
8936a5c
+  pageHeight 5 mul add			% y += 2 lines
8936a5c
+  2 copy				% Copy X & Y
8936a5c
+  moveto
8936a5c
+  (Job ID: ) RIGHT
8936a5c
+  moveto
8936a5c
+  ({printer-name}-{job-id}) show
75d0e82
+
8936a5c
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
8936a5c
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
8936a5c
+  pageHeight 2 mul add			% y += 1 line
8936a5c
+  2 copy				% Copy X & Y
8936a5c
+  moveto
8936a5c
+  (Title: ) RIGHT
8936a5c
+  moveto
8936a5c
+  ({job-name}) show
e7076f3
+
8936a5c
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
8936a5c
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
8936a5c
+  pageHeight -1 mul add			% y -= 1 line
8936a5c
+  2 copy				% Copy X & Y
8936a5c
+  moveto
8936a5c
+  (Requesting User: ) RIGHT
8936a5c
+  moveto
8936a5c
+  ({job-originating-user-name}) show
cfc9fc5
+
8936a5c
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
8936a5c
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
8936a5c
+  pageHeight -4 mul add			% y -= 2 lines
8936a5c
+  2 copy				% Copy X & Y
8936a5c
+  moveto
8936a5c
+  (Billing Info: ) RIGHT
8936a5c
+  moveto
8936a5c
+  ({?job-billing}) show
8936a5c
+
8936a5c
+  % Then the CUPS logo....
8936a5c
+  gsave
8936a5c
+    pageWidth 4 mul
8936a5c
+    pageWidth 6 mul
8936a5c
+    translate
8936a5c
+    pageWidth 9 mul CUPSLOGO
8936a5c
+  grestore
8936a5c
+
8936a5c
+  % And the ESP logo....
8936a5c
+  gsave
8936a5c
+    pageWidth 59 mul
8936a5c
+    pageWidth 6 mul
8936a5c
+    translate
8936a5c
+    pageWidth 6 mul ESPLOGO
8936a5c
+  grestore
8936a5c
+% Show the page...
8936a5c
+grestore
8936a5c
+showpage
8936a5c
+%
8936a5c
+% End of "$Id: mls_template,v 1.1 2005/06/27 18:44:46 colmo Exp $".
8936a5c
+%
8936a5c
+%%EOF
0b0e738
diff -up cups-1.4.6/data/selinux.lspp cups-1.4.6/data/selinux
0b0e738
--- cups-1.4.6/data/selinux.lspp	2011-01-12 16:39:06.618139236 +0000
0b0e738
+++ cups-1.4.6/data/selinux	2011-01-12 16:39:06.618139236 +0000
8936a5c
@@ -0,0 +1,261 @@
8936a5c
+%!PS-Adobe-3.0
8936a5c
+%%BoundingBox: 0 0 612 792
8936a5c
+%%Pages: 1
8936a5c
+%%LanguageLevel: 1
8936a5c
+%%DocumentData: Clean7Bit
8936a5c
+%%DocumentSuppliedResources: procset bannerprint/1.0
8936a5c
+%%DocumentNeededResources: font Helvetica Helvetica-Bold Times-Roman
8936a5c
+%%Creator: Michael Sweet, Easy Software Products
8936a5c
+%%CreationDate: May 10, 2000
8936a5c
+%%Title: Test Page
8936a5c
+%%EndComments
8936a5c
+%%BeginProlog
8936a5c
+%%BeginResource procset bannerprint 1.1 0
8936a5c
+%
8936a5c
+%   PostScript banner page for the Common UNIX Printing System ("CUPS").
8936a5c
+%
8936a5c
+%   Copyright 1993-2005 by Easy Software Products
8936a5c
+%
8936a5c
+%   These coded instructions, statements, and computer programs are the
8936a5c
+%   property of Easy Software Products and are protected by Federal
8936a5c
+%   copyright law.  Distribution and use rights are outlined in the file
8936a5c
+%   "LICENSE.txt" which should have been included with this file.  If this
8936a5c
+%   file is missing or damaged please contact Easy Software Products
8936a5c
+%   at:
8936a5c
+%
8936a5c
+%       Attn: CUPS Licensing Information
8936a5c
+%       Easy Software Products
8936a5c
+%       44141 Airport View Drive, Suite 204
8936a5c
+%       Hollywood, Maryland 20636 USA
8936a5c
+%
8936a5c
+%       Voice: (301) 373-9600
8936a5c
+%       EMail: cups-info@cups.org
8936a5c
+%         WWW: http://www.cups.org
8936a5c
+%
8936a5c
+/CENTER {			% Draw centered text
8936a5c
+				% (name) CENTER -
8936a5c
+  dup stringwidth pop		% Get the width of the string
8936a5c
+  0.5 mul neg 0 rmoveto		% Shift left 1/2 of the distance
8936a5c
+  show				% Show the string
8936a5c
+} bind def
8936a5c
+/RIGHT {			% Draw right-justified text
8936a5c
+				% (name) RIGHT -
8936a5c
+  dup stringwidth pop		% Get the width of the string
8936a5c
+  neg 0 rmoveto			% Shift left the entire distance
8936a5c
+  show				% Show the string
8936a5c
+} bind def
8936a5c
+/NUMBER {			% Draw a number
8936a5c
+				% power n NUMBER -
8936a5c
+  1 index 1 eq {		% power == 1?
8936a5c
+    round cvi exch pop		% Convert "n" to integer
8936a5c
+  } {
8936a5c
+    1 index mul round exch div	% Truncate extra decimal places
8936a5c
+  } ifelse
8936a5c
+  100 string cvs show		% Convert to a string and show it...
8936a5c
+} bind def
8936a5c
+/CUPSLOGO {			% Draw the CUPS logo
8936a5c
+				% height CUPSLOGO
8936a5c
+  % Start with a big C...
8936a5c
+  /Helvetica findfont 1 index scalefont setfont
8936a5c
+  0 setgray
8936a5c
+  0 0 moveto
8936a5c
+  (C) show
8936a5c
+
8936a5c
+  % Then "UNIX Printing System" much smaller...
8936a5c
+  /Helvetica-Bold findfont 1 index 9 div scalefont setfont
8936a5c
+  0.25 mul
8936a5c
+  dup dup 2.0 mul moveto
8936a5c
+  (UNIX) show
8936a5c
+  dup dup 1.6 mul moveto
8936a5c
+  (Printing) show
8936a5c
+  dup 1.2 mul moveto
8936a5c
+  (System) show
8936a5c
+} bind def
8936a5c
+/ESPLOGO {			% Draw the ESP logo
8936a5c
+				% height ESPLOGO
8936a5c
+  % Compute the size of the logo...
8936a5c
+  0 0
8936a5c
+  2 index 1.5 mul 3 index
cfc9fc5
+
8936a5c
+  % Do the "metallic" fill from 10% black to 40% black...
8936a5c
+  1 -0.001 0 {
8936a5c
+    dup			% loopval
8936a5c
+    -0.15 mul		% loopval * -0.15
8936a5c
+    0.9 add		% 0.9 - loopval * 0.15
8936a5c
+    setgray		% set gray shade
cfc9fc5
+
8936a5c
+    0			% x
8936a5c
+    1 index neg		% loopval
8936a5c
+    1 add		% 1 - loopval
8936a5c
+    3 index		% height
8936a5c
+    mul			% height * (1 - loopval)
8936a5c
+    moveto		% starting point
cfc9fc5
+
8936a5c
+    dup			% loopval
8936a5c
+    3 index		% width
8936a5c
+    mul			% loopval * width
8936a5c
+    2 index		% height
8936a5c
+    lineto		% Next point
cfc9fc5
+
8936a5c
+    0			% x
8936a5c
+    2 index		% height
8936a5c
+    lineto		% Next point
e7076f3
+
8936a5c
+    closepath
8936a5c
+    fill
e7076f3
+
8936a5c
+    dup			% loopval
8936a5c
+    0.15 mul		% loopval * 0.15
8936a5c
+    0.6 add		% 0.6 + loopval * 0.15
8936a5c
+    setgray
e7076f3
+
8936a5c
+    dup			% loopval
8936a5c
+    neg 1 add		% 1 - loopval
8936a5c
+    3 index		% width
8936a5c
+    mul			% (1 - loopval) * width
8936a5c
+    0			% y
8936a5c
+    moveto		% Starting point
e7076f3
+
8936a5c
+    2 index		% width
8936a5c
+    exch		% loopval
8936a5c
+    2 index		% height
8936a5c
+    mul			% loopval * height
8936a5c
+    lineto		% Next point
e7076f3
+
8936a5c
+    1 index		% width
8936a5c
+    0			% y
8936a5c
+    lineto		% Next point
e7076f3
+
8936a5c
+    closepath
8936a5c
+    fill
8936a5c
+  } for
cfc9fc5
+
8936a5c
+  0 setgray rectstroke
cfc9fc5
+
8936a5c
+  /Helvetica-BoldOblique findfont 1 index 3 div scalefont setfont
8936a5c
+  dup 40 div
cfc9fc5
+
8936a5c
+  dup 4 mul 1 index 25 mul moveto (E) show
8936a5c
+  dup 10 mul 1 index 15 mul moveto (S) show
8936a5c
+  dup 16 mul 1 index 5 mul moveto (P) show
e7076f3
+
8936a5c
+  /Helvetica-BoldOblique findfont 2 index 5 div scalefont setfont
8936a5c
+  dup 14 mul 1 index 29 mul moveto (asy) show
8936a5c
+  dup 20 mul 1 index 19 mul moveto (oftware) show
8936a5c
+  dup 26 mul 1 index 9 mul moveto (roducts) show
f4b6623
+
8936a5c
+  pop
8936a5c
+} bind def
8936a5c
+%%EndResource
8936a5c
+%%EndProlog
8936a5c
+%%Page: 1 1
8936a5c
+gsave
f4b6623
+
8936a5c
+  % Determine the imageable area and device resolution...
8936a5c
+  initclip newpath clippath pathbbox	% Get bounding rectangle
8936a5c
+  72 div /pageTop exch def		% Get top margin in inches
8936a5c
+  72 div /pageRight exch def		% Get right margin in inches
8936a5c
+  72 div /pageBottom exch def		% Get bottom margin in inches
8936a5c
+  72 div /pageLeft exch def		% Get left margin in inches
e7076f3
+
8936a5c
+  /pageWidth pageRight pageLeft sub def	% pageWidth = pageRight - pageLeft
8936a5c
+  /pageHeight pageTop pageBottom sub def% pageHeight = pageTop - pageBottom
f4b6623
+
8936a5c
+  /boxWidth				% width of text box
8936a5c
+  pageWidth pageHeight lt
8936a5c
+  { pageWidth 54 mul }
8936a5c
+  { pageHeight 42 mul }
8936a5c
+  ifelse def
f4b6623
+
8936a5c
+  newpath				% Clear bounding path
e7076f3
+
8936a5c
+  % Create fonts...
8936a5c
+  /bigFont /Helvetica-Bold findfont	% bigFont = Helvetica-Bold
8936a5c
+  pageHeight 3 mul scalefont def	% size = pageHeight * 3 (nominally 33)
e7076f3
+
8936a5c
+  /mediumFont /Helvetica findfont	% mediumFont = Helvetica
8936a5c
+  pageHeight 1.5 mul scalefont def	% size = pageHeight * 1.5 (nominally 16.5)
e7076f3
+
8936a5c
+  % Offset page to account for lower-left margin...
8936a5c
+  pageLeft 72 mul
8936a5c
+  pageBottom 72 mul
8936a5c
+  translate
e7076f3
+
8936a5c
+  % Job information box...
8936a5c
+  pageWidth 36 mul 9 add		% x = pageWidth * 1/2 * 72 + 9
8936a5c
+  boxWidth 0.5 mul sub			% x-= 1/2 box width
8936a5c
+  pageHeight 30 mul 9 sub		% y = pageHeight * 1/2 * 72 - 9
8936a5c
+  boxWidth				% w = box width
8936a5c
+  pageHeight 14 mul			% h = pageHeight * 1/2 * 72
8936a5c
+  0.5 setgray rectfill			% Draw a shadow
f4b6623
+
8936a5c
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
8936a5c
+  boxWidth 0.5 mul sub			% x-= 1/2 box width
8936a5c
+  pageHeight 30 mul			% y = pageHeight * 1/4 * 72
8936a5c
+  boxWidth				% w = box width
8936a5c
+  pageHeight 14 mul			% h = pageHeight * 1/2 * 72
e7076f3
+
8936a5c
+  4 copy 1 setgray rectfill		% Clear the box to white
8936a5c
+  0 setgray rectstroke			% Draw a black box around it...
e7076f3
+
8936a5c
+  % Job information text...
8936a5c
+  mediumFont setfont			% Medium sized font
f4b6623
+
8936a5c
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
8936a5c
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
8936a5c
+  pageHeight 5 mul add			% y += 2 lines
8936a5c
+  2 copy				% Copy X & Y
8936a5c
+  moveto
8936a5c
+  (Job ID: ) RIGHT
8936a5c
+  moveto
8936a5c
+  ({printer-name}-{job-id}) show
e7076f3
+
8936a5c
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
8936a5c
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
8936a5c
+  pageHeight 2 mul add			% y += 1 line
8936a5c
+  2 copy				% Copy X & Y
8936a5c
+  moveto
8936a5c
+  (Title: ) RIGHT
8936a5c
+  moveto
8936a5c
+  ({job-name}) show
e7076f3
+
8936a5c
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
8936a5c
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
8936a5c
+  pageHeight -1 mul add			% y -= 1 line
8936a5c
+  2 copy				% Copy X & Y
8936a5c
+  moveto
8936a5c
+  (Requesting User: ) RIGHT
8936a5c
+  moveto
8936a5c
+  ({job-originating-user-name}) show
e7076f3
+
8936a5c
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
8936a5c
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
8936a5c
+  pageHeight -4 mul add			% y -= 2 lines
8936a5c
+  2 copy				% Copy X & Y
8936a5c
+  moveto
8936a5c
+  (Billing Info: ) RIGHT
8936a5c
+  moveto
8936a5c
+  ({?job-billing}) show
e7076f3
+
8936a5c
+  % Then the CUPS logo....
8936a5c
+  gsave
8936a5c
+    pageWidth 4 mul
8936a5c
+    pageWidth 6 mul
8936a5c
+    translate
8936a5c
+    pageWidth 9 mul CUPSLOGO
8936a5c
+  grestore
f4b6623
+
8936a5c
+  % And the ESP logo....
8936a5c
+  gsave
8936a5c
+    pageWidth 59 mul
8936a5c
+    pageWidth 6 mul
8936a5c
+    translate
8936a5c
+    pageWidth 6 mul ESPLOGO
8936a5c
+  grestore
8936a5c
+% Show the page...
8936a5c
+grestore
8936a5c
+showpage
8936a5c
+%
8936a5c
+% End of "$Id: mls_template,v 1.1 2005/06/27 18:44:46 colmo Exp $".
8936a5c
+%
8936a5c
+%%EOF
0b0e738
diff -up cups-1.4.6/data/te.lspp cups-1.4.6/data/te
0b0e738
--- cups-1.4.6/data/te.lspp	2011-01-12 16:39:06.620139134 +0000
0b0e738
+++ cups-1.4.6/data/te	2011-01-12 16:39:06.620139134 +0000
e7076f3
@@ -0,0 +1,261 @@
e7076f3
+%!PS-Adobe-3.0
e7076f3
+%%BoundingBox: 0 0 612 792
e7076f3
+%%Pages: 1
e7076f3
+%%LanguageLevel: 1
e7076f3
+%%DocumentData: Clean7Bit
e7076f3
+%%DocumentSuppliedResources: procset bannerprint/1.0
e7076f3
+%%DocumentNeededResources: font Helvetica Helvetica-Bold Times-Roman
e7076f3
+%%Creator: Michael Sweet, Easy Software Products
e7076f3
+%%CreationDate: May 10, 2000
e7076f3
+%%Title: Test Page
e7076f3
+%%EndComments
e7076f3
+%%BeginProlog
e7076f3
+%%BeginResource procset bannerprint 1.1 0
e7076f3
+%
e7076f3
+%   PostScript banner page for the Common UNIX Printing System ("CUPS").
e7076f3
+%
e7076f3
+%   Copyright 1993-2005 by Easy Software Products
e7076f3
+%
e7076f3
+%   These coded instructions, statements, and computer programs are the
e7076f3
+%   property of Easy Software Products and are protected by Federal
e7076f3
+%   copyright law.  Distribution and use rights are outlined in the file
e7076f3
+%   "LICENSE.txt" which should have been included with this file.  If this
e7076f3
+%   file is missing or damaged please contact Easy Software Products
e7076f3
+%   at:
e7076f3
+%
e7076f3
+%       Attn: CUPS Licensing Information
e7076f3
+%       Easy Software Products
e7076f3
+%       44141 Airport View Drive, Suite 204
e7076f3
+%       Hollywood, Maryland 20636 USA
e7076f3
+%
e7076f3
+%       Voice: (301) 373-9600
e7076f3
+%       EMail: cups-info@cups.org
e7076f3
+%         WWW: http://www.cups.org
e7076f3
+%
e7076f3
+/CENTER {			% Draw centered text
e7076f3
+				% (name) CENTER -
e7076f3
+  dup stringwidth pop		% Get the width of the string
e7076f3
+  0.5 mul neg 0 rmoveto		% Shift left 1/2 of the distance
e7076f3
+  show				% Show the string
e7076f3
+} bind def
e7076f3
+/RIGHT {			% Draw right-justified text
e7076f3
+				% (name) RIGHT -
e7076f3
+  dup stringwidth pop		% Get the width of the string
e7076f3
+  neg 0 rmoveto			% Shift left the entire distance
e7076f3
+  show				% Show the string
e7076f3
+} bind def
e7076f3
+/NUMBER {			% Draw a number
e7076f3
+				% power n NUMBER -
e7076f3
+  1 index 1 eq {		% power == 1?
e7076f3
+    round cvi exch pop		% Convert "n" to integer
e7076f3
+  } {
e7076f3
+    1 index mul round exch div	% Truncate extra decimal places
e7076f3
+  } ifelse
e7076f3
+  100 string cvs show		% Convert to a string and show it...
e7076f3
+} bind def
e7076f3
+/CUPSLOGO {			% Draw the CUPS logo
e7076f3
+				% height CUPSLOGO
e7076f3
+  % Start with a big C...
e7076f3
+  /Helvetica findfont 1 index scalefont setfont
e7076f3
+  0 setgray
e7076f3
+  0 0 moveto
e7076f3
+  (C) show
75d0e82
+
e7076f3
+  % Then "UNIX Printing System" much smaller...
e7076f3
+  /Helvetica-Bold findfont 1 index 9 div scalefont setfont
e7076f3
+  0.25 mul
e7076f3
+  dup dup 2.0 mul moveto
e7076f3
+  (UNIX) show
e7076f3
+  dup dup 1.6 mul moveto
e7076f3
+  (Printing) show
e7076f3
+  dup 1.2 mul moveto
e7076f3
+  (System) show
e7076f3
+} bind def
e7076f3
+/ESPLOGO {			% Draw the ESP logo
e7076f3
+				% height ESPLOGO
e7076f3
+  % Compute the size of the logo...
e7076f3
+  0 0
e7076f3
+  2 index 1.5 mul 3 index
75d0e82
+
e7076f3
+  % Do the "metallic" fill from 10% black to 40% black...
e7076f3
+  1 -0.001 0 {
e7076f3
+    dup			% loopval
e7076f3
+    -0.15 mul		% loopval * -0.15
e7076f3
+    0.9 add		% 0.9 - loopval * 0.15
e7076f3
+    setgray		% set gray shade
75d0e82
+
e7076f3
+    0			% x
e7076f3
+    1 index neg		% loopval
e7076f3
+    1 add		% 1 - loopval
e7076f3
+    3 index		% height
e7076f3
+    mul			% height * (1 - loopval)
e7076f3
+    moveto		% starting point
75d0e82
+
e7076f3
+    dup			% loopval
e7076f3
+    3 index		% width
e7076f3
+    mul			% loopval * width
e7076f3
+    2 index		% height
e7076f3
+    lineto		% Next point
5dd9863
+
e7076f3
+    0			% x
e7076f3
+    2 index		% height
e7076f3
+    lineto		% Next point
5dd9863
+
e7076f3
+    closepath
e7076f3
+    fill
75d0e82
+
e7076f3
+    dup			% loopval
e7076f3
+    0.15 mul		% loopval * 0.15
e7076f3
+    0.6 add		% 0.6 + loopval * 0.15
e7076f3
+    setgray
f4b6623
+
e7076f3
+    dup			% loopval
e7076f3
+    neg 1 add		% 1 - loopval
e7076f3
+    3 index		% width
e7076f3
+    mul			% (1 - loopval) * width
e7076f3
+    0			% y
e7076f3
+    moveto		% Starting point
f4b6623
+
e7076f3
+    2 index		% width
e7076f3
+    exch		% loopval
e7076f3
+    2 index		% height
e7076f3
+    mul			% loopval * height
e7076f3
+    lineto		% Next point
f4b6623
+
e7076f3
+    1 index		% width
e7076f3
+    0			% y
e7076f3
+    lineto		% Next point
75d0e82
+
e7076f3
+    closepath
e7076f3
+    fill
e7076f3
+  } for
d042370
+
e7076f3
+  0 setgray rectstroke
d042370
+
e7076f3
+  /Helvetica-BoldOblique findfont 1 index 3 div scalefont setfont
e7076f3
+  dup 40 div
5dd9863
+
e7076f3
+  dup 4 mul 1 index 25 mul moveto (E) show
e7076f3
+  dup 10 mul 1 index 15 mul moveto (S) show
e7076f3
+  dup 16 mul 1 index 5 mul moveto (P) show
e7076f3
+
e7076f3
+  /Helvetica-BoldOblique findfont 2 index 5 div scalefont setfont
e7076f3
+  dup 14 mul 1 index 29 mul moveto (asy) show
e7076f3
+  dup 20 mul 1 index 19 mul moveto (oftware) show
e7076f3
+  dup 26 mul 1 index 9 mul moveto (roducts) show
e7076f3
+
e7076f3
+  pop
e7076f3
+} bind def
e7076f3
+%%EndResource
e7076f3
+%%EndProlog
e7076f3
+%%Page: 1 1
e7076f3
+gsave
e7076f3
+
8936a5c
+  % Determine the imageable area and device resolution...
8936a5c
+  initclip newpath clippath pathbbox	% Get bounding rectangle
8936a5c
+  72 div /pageTop exch def		% Get top margin in inches
8936a5c
+  72 div /pageRight exch def		% Get right margin in inches
8936a5c
+  72 div /pageBottom exch def		% Get bottom margin in inches
8936a5c
+  72 div /pageLeft exch def		% Get left margin in inches
8936a5c
+
8936a5c
+  /pageWidth pageRight pageLeft sub def	% pageWidth = pageRight - pageLeft
8936a5c
+  /pageHeight pageTop pageBottom sub def% pageHeight = pageTop - pageBottom
8936a5c
+
8936a5c
+  /boxWidth				% width of text box
8936a5c
+  pageWidth pageHeight lt
8936a5c
+  { pageWidth 54 mul }
8936a5c
+  { pageHeight 42 mul }
8936a5c
+  ifelse def
8936a5c
+
8936a5c
+  newpath				% Clear bounding path
8936a5c
+
8936a5c
+  % Create fonts...
8936a5c
+  /bigFont /Helvetica-Bold findfont	% bigFont = Helvetica-Bold
8936a5c
+  pageHeight 3 mul scalefont def	% size = pageHeight * 3 (nominally 33)
8936a5c
+
8936a5c
+  /mediumFont /Helvetica findfont	% mediumFont = Helvetica
8936a5c
+  pageHeight 1.5 mul scalefont def	% size = pageHeight * 1.5 (nominally 16.5)
8936a5c
+
8936a5c
+  % Offset page to account for lower-left margin...
8936a5c
+  pageLeft 72 mul
8936a5c
+  pageBottom 72 mul
8936a5c
+  translate
8936a5c
+
8936a5c
+  % Job information box...
8936a5c
+  pageWidth 36 mul 9 add		% x = pageWidth * 1/2 * 72 + 9
8936a5c
+  boxWidth 0.5 mul sub			% x-= 1/2 box width
8936a5c
+  pageHeight 30 mul 9 sub		% y = pageHeight * 1/2 * 72 - 9
8936a5c
+  boxWidth				% w = box width
8936a5c
+  pageHeight 14 mul			% h = pageHeight * 1/2 * 72
8936a5c
+  0.5 setgray rectfill			% Draw a shadow
8936a5c
+
8936a5c
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
8936a5c
+  boxWidth 0.5 mul sub			% x-= 1/2 box width
8936a5c
+  pageHeight 30 mul			% y = pageHeight * 1/4 * 72
8936a5c
+  boxWidth				% w = box width
8936a5c
+  pageHeight 14 mul			% h = pageHeight * 1/2 * 72
8936a5c
+
8936a5c
+  4 copy 1 setgray rectfill		% Clear the box to white
8936a5c
+  0 setgray rectstroke			% Draw a black box around it...
8936a5c
+
8936a5c
+  % Job information text...
8936a5c
+  mediumFont setfont			% Medium sized font
8936a5c
+
8936a5c
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
8936a5c
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
8936a5c
+  pageHeight 5 mul add			% y += 2 lines
8936a5c
+  2 copy				% Copy X & Y
8936a5c
+  moveto
8936a5c
+  (Job ID: ) RIGHT
8936a5c
+  moveto
8936a5c
+  ({printer-name}-{job-id}) show
8936a5c
+
8936a5c
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
8936a5c
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
8936a5c
+  pageHeight 2 mul add			% y += 1 line
8936a5c
+  2 copy				% Copy X & Y
8936a5c
+  moveto
8936a5c
+  (Title: ) RIGHT
8936a5c
+  moveto
8936a5c
+  ({job-name}) show
8936a5c
+
8936a5c
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
8936a5c
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
8936a5c
+  pageHeight -1 mul add			% y -= 1 line
8936a5c
+  2 copy				% Copy X & Y
8936a5c
+  moveto
8936a5c
+  (Requesting User: ) RIGHT
8936a5c
+  moveto
8936a5c
+  ({job-originating-user-name}) show
8936a5c
+
8936a5c
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
8936a5c
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
8936a5c
+  pageHeight -4 mul add			% y -= 2 lines
8936a5c
+  2 copy				% Copy X & Y
8936a5c
+  moveto
8936a5c
+  (Billing Info: ) RIGHT
8936a5c
+  moveto
8936a5c
+  ({?job-billing}) show
8936a5c
+
8936a5c
+  % Then the CUPS logo....
8936a5c
+  gsave
8936a5c
+    pageWidth 4 mul
8936a5c
+    pageWidth 6 mul
8936a5c
+    translate
8936a5c
+    pageWidth 9 mul CUPSLOGO
8936a5c
+  grestore
8936a5c
+
8936a5c
+  % And the ESP logo....
8936a5c
+  gsave
8936a5c
+    pageWidth 59 mul
8936a5c
+    pageWidth 6 mul
8936a5c
+    translate
8936a5c
+    pageWidth 6 mul ESPLOGO
8936a5c
+  grestore
8936a5c
+% Show the page...
8936a5c
+grestore
8936a5c
+showpage
8936a5c
+%
8936a5c
+% End of "$Id: mls_template,v 1.1 2005/06/27 18:44:46 colmo Exp $".
8936a5c
+%
8936a5c
+%%EOF
0b0e738
diff -up cups-1.4.6/filter/common.c.lspp cups-1.4.6/filter/common.c
0b0e738
--- cups-1.4.6/filter/common.c.lspp	2007-07-11 22:46:42.000000000 +0100
0b0e738
+++ cups-1.4.6/filter/common.c	2011-01-12 16:39:06.624138928 +0000
8936a5c
@@ -30,6 +30,12 @@
8936a5c
  * Include necessary headers...
8936a5c
  */
8936a5c
 
8936a5c
+#include "config.h"
8936a5c
+#ifdef WITH_LSPP
8936a5c
+#define _GNU_SOURCE
8936a5c
+#include <string.h>
8936a5c
+#endif /* WITH_LSPP */
8936a5c
+
8936a5c
 #include "common.h"
8936a5c
 #include <locale.h>
8936a5c
 
8936a5c
@@ -312,6 +318,18 @@ WriteLabelProlog(const char *label,	/* I
8936a5c
 {
8936a5c
   const char	*classification;	/* CLASSIFICATION environment variable */
8936a5c
   const char	*ptr;			/* Temporary string pointer */
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  int           i,                      /* counter */
8936a5c
+                n,                      /* counter */
8936a5c
+                lines,                  /* number of lines needed */
8936a5c
+                line_len,               /* index into tmp_label */
8936a5c
+                label_len,              /* length of the label in characters */
8936a5c
+                label_index,            /* index into the label */
8936a5c
+                longest,                /* length of the longest line */
8936a5c
+                longest_line,           /* index to the longest line */
8936a5c
+                max_width;              /* maximum width in characters */
8936a5c
+  char          **wrapped_label;        /* label with line breaks */
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 
8936a5c
 
8936a5c
  /*
8936a5c
@@ -334,6 +352,124 @@ WriteLabelProlog(const char *label,	/* I
8936a5c
     return;
8936a5c
   }
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  if (strncmp(classification, "LSPP:", 5) == 0 && label == NULL)
8936a5c
+  {
8936a5c
+   /*
8936a5c
+    * Based on the 12pt fixed width font below determine the max_width
8936a5c
+    */
8936a5c
+    max_width = width / 8;
8936a5c
+    longest_line = 0;
8936a5c
+    longest = 0;
8936a5c
+    classification += 5; // Skip the "LSPP:"
8936a5c
+    label_len = strlen(classification);
8936a5c
+
8936a5c
+    if (label_len > max_width)
8936a5c
+    {
8936a5c
+      lines = 1 + (int)(label_len / max_width);
8936a5c
+      line_len = (int)(label_len / lines);
8936a5c
+      wrapped_label = malloc(sizeof(wrapped_label) * lines);
8936a5c
+      label_index = i = n = 0;
8936a5c
+      while (classification[label_index])
8936a5c
+      {
8936a5c
+        if ((label_index + line_len) > label_len)
8936a5c
+          break;
8936a5c
+        switch (classification[label_index + line_len + i])
8936a5c
+        {
8936a5c
+          case ':':
8936a5c
+          case ',':
8936a5c
+          case '-':
8936a5c
+            i++;
8936a5c
+            wrapped_label[n++] = strndup(&classification[label_index], (line_len + i));
8936a5c
+            label_index += line_len + i;
8936a5c
+            i = 0;
8936a5c
+            break;
8936a5c
+          default:
8936a5c
+            i++;
8936a5c
+            break;
8936a5c
+        }
8936a5c
+        if ((i + line_len) == max_width)
8936a5c
+        {
8936a5c
+          wrapped_label[n++] = strndup(&(classification[label_index]), (line_len + i));
8936a5c
+          label_index = label_index + line_len + i;
8936a5c
+          i = 0;
8936a5c
+        }
8936a5c
+      }
8936a5c
+      wrapped_label[n] = strndup(&classification[label_index], label_len - label_index);
8936a5c
+    }
8936a5c
+    else
8936a5c
+    {
8936a5c
+      lines = 1;
8936a5c
+      wrapped_label = malloc(sizeof(wrapped_label));
8936a5c
+      wrapped_label[0] = (char*)classification;
8936a5c
+    }
8936a5c
+
8936a5c
+    for (n = 0; n < lines; n++ )
8936a5c
+    {
8936a5c
+      printf("userdict/ESPp%c(", ('a' + n));
8936a5c
+      for (ptr = wrapped_label[n], i = 0; *ptr; ptr ++, i++)
8936a5c
+        if (*ptr < 32 || *ptr > 126)
8936a5c
+          printf("\\%03o", *ptr);
8936a5c
+        else
8936a5c
+        {
8936a5c
+          if (*ptr == '(' || *ptr == ')' || *ptr == '\\')
8936a5c
+            putchar('\\');
e7076f3
+
8936a5c
+          printf("%c", *ptr);
8936a5c
+        }
8936a5c
+      if (i > longest)
8936a5c
+      {
8936a5c
+        longest = i;
8936a5c
+        longest_line = n;
8936a5c
+      }
8936a5c
+      printf(")put\n");
8936a5c
+    }
e7076f3
+
8936a5c
+   /*
8936a5c
+    * For LSPP use a fixed width font so that line wrapping can be calculated
8936a5c
+    */
75d0e82
+
8936a5c
+    puts("userdict/ESPlf /Nimbus-Mono findfont 12 scalefont put");
75d0e82
+
8936a5c
+   /*
8936a5c
+    * Finally, the procedure to write the labels on the page...
8936a5c
+    */
75d0e82
+
8936a5c
+    printf("userdict/ESPwl{\n"
8936a5c
+           "  ESPlf setfont\n");
8936a5c
+    printf("  ESPp%c stringwidth pop dup 12 add exch -0.5 mul %.0f add\n ",
8936a5c
+           'a' + longest_line, width * 0.5f);
8936a5c
+    for (n = 1; n < lines; n++)
8936a5c
+      printf(" dup");
8936a5c
+    printf("\n  1 setgray\n");
8936a5c
+    printf("  dup 6 sub %.0f %d index %.0f ESPrf\n",
8936a5c
+           (bottom - 2.0), (2 + lines), 6.0 + (16.0 * lines));
8936a5c
+    printf("  dup 6 sub %.0f %d index %.0f ESPrf\n",
8936a5c
+           (top - 6.0 - (16.0 * lines)), (2 + lines), 4.0 + (16.0 * lines));
8936a5c
+    printf("  0 setgray\n");
8936a5c
+    printf("  dup 6 sub %.0f %d index %.0f ESPrs\n",
8936a5c
+           (bottom - 2.0), (2 + lines), 6.0 + (16.0 * lines));
8936a5c
+    printf("  dup 6 sub %.0f %d index %.0f ESPrs\n",
8936a5c
+           (top - 6.0 - (16.0 * lines)), (2 + lines), 4.0 + (16.0 * lines));
8936a5c
+    for (n = 0; n < lines; n ++)
8936a5c
+    {
8936a5c
+      printf("  dup %.0f moveto ESPp%c show\n",
8936a5c
+             bottom + 6.0 + ((lines - (n+1)) * 16.0), 'a' + n);
8936a5c
+      printf("  %.0f moveto ESPp%c show\n", top + 2.0 - ((n + 1) * 16.0), 'a' + n);
8936a5c
+    }
8936a5c
+    printf("  pop\n"
8936a5c
+           "}bind put\n");
22cc213
+
8936a5c
+   /*
8936a5c
+    * Do some clean up at the end of the LSPP special case
8936a5c
+    */
8936a5c
+    free(wrapped_label);
75d0e82
+
8936a5c
+  }
8936a5c
+  else
8936a5c
+  {
8936a5c
+#endif /* !WITH_LSPP */
8936a5c
+  
8936a5c
  /*
8936a5c
   * Set the classification + page label string...
8936a5c
   */
8936a5c
@@ -414,7 +550,10 @@ WriteLabelProlog(const char *label,	/* I
8936a5c
   printf("  %.0f moveto ESPpl show\n", top - 14.0);
8936a5c
   puts("pop");
8936a5c
   puts("}bind put");
8936a5c
+  }
8936a5c
+#ifdef WITH_LSPP
8936a5c
 }
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 
8936a5c
 
8936a5c
 /*
0b0e738
diff -up cups-1.4.6/filter/pstops.c.lspp cups-1.4.6/filter/pstops.c
0b0e738
--- cups-1.4.6/filter/pstops.c.lspp	2011-01-12 16:39:06.420149233 +0000
0b0e738
+++ cups-1.4.6/filter/pstops.c	2011-01-12 16:39:06.626138829 +0000
0b0e738
@@ -3326,6 +3326,18 @@ write_label_prolog(pstops_doc_t *doc,	/*
92b094f
 {
92b094f
   const char	*classification;	/* CLASSIFICATION environment variable */
92b094f
   const char	*ptr;			/* Temporary string pointer */
92b094f
+#ifdef WITH_LSPP
92b094f
+  int           i,                      /* counter */
92b094f
+                n,                      /* counter */
92b094f
+                lines,                  /* number of lines needed */
92b094f
+                line_len,               /* index into tmp_label */
92b094f
+                label_len,              /* length of the label in characters */
92b094f
+                label_index,            /* index into the label */
92b094f
+                longest,                /* length of the longest line */
92b094f
+                longest_line,           /* index to the longest line */
92b094f
+                max_width;              /* maximum width in characters */
92b094f
+  char          **wrapped_label;        /* label with line breaks */
92b094f
+#endif /* WITH_LSPP */
92b094f
 
92b094f
 
92b094f
  /*
0b0e738
@@ -3348,6 +3360,124 @@ write_label_prolog(pstops_doc_t *doc,	/*
92b094f
     return;
92b094f
   }
92b094f
 
92b094f
+#ifdef WITH_LSPP
92b094f
+  if (strncmp(classification, "LSPP:", 5) == 0 && label == NULL)
92b094f
+  {
92b094f
+   /*
92b094f
+    * Based on the 12pt fixed width font below determine the max_width
92b094f
+    */
92b094f
+    max_width = width / 8;
92b094f
+    longest_line = 0;
92b094f
+    longest = 0;
92b094f
+    classification += 5; // Skip the "LSPP:"
92b094f
+    label_len = strlen(classification);
92b094f
+
92b094f
+    if (label_len > max_width)
92b094f
+    {
92b094f
+      lines = 1 + (int)(label_len / max_width);
92b094f
+      line_len = (int)(label_len / lines);
92b094f
+      wrapped_label = malloc(sizeof(wrapped_label) * lines);
92b094f
+      label_index = i = n = 0;
92b094f
+      while (classification[label_index])
92b094f
+      {
92b094f
+        if ((label_index + line_len) > label_len)
92b094f
+          break;
92b094f
+        switch (classification[label_index + line_len + i])
92b094f
+        {
92b094f
+          case ':':
92b094f
+          case ',':
92b094f
+          case '-':
92b094f
+            i++;
92b094f
+            wrapped_label[n++] = strndup(&classification[label_index], (line_len + i));
92b094f
+            label_index += line_len + i;
92b094f
+            i = 0;
92b094f
+            break;
92b094f
+          default:
92b094f
+            i++;
92b094f
+            break;
92b094f
+        }
92b094f
+        if ((i + line_len) == max_width)
92b094f
+        {
92b094f
+          wrapped_label[n++] = strndup(&(classification[label_index]), (line_len + i));
92b094f
+          label_index = label_index + line_len + i;
92b094f
+          i = 0;
92b094f
+        }
92b094f
+      }
92b094f
+      wrapped_label[n] = strndup(&classification[label_index], label_len - label_index);
92b094f
+    }
92b094f
+    else
92b094f
+    {
92b094f
+      lines = 1;
92b094f
+      wrapped_label = malloc(sizeof(wrapped_label));
92b094f
+      wrapped_label[0] = (char*)classification;
92b094f
+    }
92b094f
+
92b094f
+    for (n = 0; n < lines; n++ )
92b094f
+    {
92b094f
+      printf("userdict/ESPp%c(", ('a' + n));
92b094f
+      for (ptr = wrapped_label[n], i = 0; *ptr; ptr ++, i++)
92b094f
+        if (*ptr < 32 || *ptr > 126)
92b094f
+          printf("\\%03o", *ptr);
92b094f
+        else
92b094f
+        {
92b094f
+          if (*ptr == '(' || *ptr == ')' || *ptr == '\\')
92b094f
+            putchar('\\');
92b094f
+
92b094f
+          printf("%c", *ptr);
92b094f
+        }
92b094f
+      if (i > longest)
92b094f
+      {
92b094f
+        longest = i;
92b094f
+        longest_line = n;
92b094f
+      }
92b094f
+      printf(")put\n");
92b094f
+    }
92b094f
+
92b094f
+   /*
92b094f
+    * For LSPP use a fixed width font so that line wrapping can be calculated
92b094f
+    */
92b094f
+
92b094f
+    puts("userdict/ESPlf /Nimbus-Mono findfont 12 scalefont put");
92b094f
+
92b094f
+   /*
92b094f
+    * Finally, the procedure to write the labels on the page...
92b094f
+    */
92b094f
+
92b094f
+    printf("userdict/ESPwl{\n"
92b094f
+           "  ESPlf setfont\n");
92b094f
+    printf("  ESPp%c stringwidth pop dup 12 add exch -0.5 mul %.0f add\n ",
92b094f
+           'a' + longest_line, width * 0.5f);
92b094f
+    for (n = 1; n < lines; n++)
92b094f
+      printf(" dup");
92b094f
+    printf("\n  1 setgray\n");
92b094f
+    printf("  dup 6 sub %.0f %d index %.0f ESPrf\n",
92b094f
+           (bottom - 2.0), (2 + lines), 6.0 + (16.0 * lines));
92b094f
+    printf("  dup 6 sub %.0f %d index %.0f ESPrf\n",
92b094f
+           (top - 6.0 - (16.0 * lines)), (2 + lines), 4.0 + (16.0 * lines));
92b094f
+    printf("  0 setgray\n");
92b094f
+    printf("  dup 6 sub %.0f %d index %.0f ESPrs\n",
92b094f
+           (bottom - 2.0), (2 + lines), 6.0 + (16.0 * lines));
92b094f
+    printf("  dup 6 sub %.0f %d index %.0f ESPrs\n",
92b094f
+           (top - 6.0 - (16.0 * lines)), (2 + lines), 4.0 + (16.0 * lines));
92b094f
+    for (n = 0; n < lines; n ++)
92b094f
+    {
92b094f
+      printf("  dup %.0f moveto ESPp%c show\n",
92b094f
+             bottom + 6.0 + ((lines - (n+1)) * 16.0), 'a' + n);
92b094f
+      printf("  %.0f moveto ESPp%c show\n", top + 2.0 - ((n + 1) * 16.0), 'a' + n);
92b094f
+    }
92b094f
+    printf("  pop\n"
92b094f
+           "}bind put\n");
92b094f
+
92b094f
+   /*
92b094f
+    * Do some clean up at the end of the LSPP special case
92b094f
+    */
92b094f
+    free(wrapped_label);
92b094f
+
92b094f
+  }
92b094f
+  else
92b094f
+  {
92b094f
+#endif /* !WITH_LSPP */
92b094f
+
92b094f
  /*
92b094f
   * Set the classification + page label string...
92b094f
   */
0b0e738
@@ -3426,7 +3556,10 @@ write_label_prolog(pstops_doc_t *doc,	/*
92b094f
   doc_printf(doc, "  %.0f moveto ESPpl show\n", top - 14.0);
92b094f
   doc_puts(doc, "pop\n");
92b094f
   doc_puts(doc, "}bind put\n");
92b094f
+  }
92b094f
+#ifdef WITH_LSPP
92b094f
 }
92b094f
+#endif /* WITH_LSPP */
92b094f
 
92b094f
 
92b094f
 /*
0b0e738
diff -up cups-1.4.6/Makedefs.in.lspp cups-1.4.6/Makedefs.in
0b0e738
--- cups-1.4.6/Makedefs.in.lspp	2011-01-12 16:39:06.527143831 +0000
0b0e738
+++ cups-1.4.6/Makedefs.in	2011-01-12 16:39:06.631138575 +0000
1e5683c
@@ -146,7 +146,7 @@ LIBCUPSORDER	=	@LIBCUPSORDER@
8936a5c
 LIBCUPSIMAGEORDER =	@LIBCUPSIMAGEORDER@
a1088d0
 LINKCUPS	=	@LINKCUPS@ $(SSLLIBS) $(DNSSDLIBS)
8936a5c
 LINKCUPSIMAGE	=	@LINKCUPSIMAGE@
8936a5c
-LIBS		=	$(LINKCUPS) $(COMMONLIBS)
8936a5c
+LIBS		=	$(LINKCUPS) $(COMMONLIBS) @LIBAUDIT@ @LIBSELINUX@
8936a5c
 OPTIM		=	@OPTIM@
8936a5c
 OPTIONS		=
8936a5c
 PAMLIBS		=	@PAMLIBS@
1e5683c
@@ -258,7 +258,7 @@ DBUSDIR		=	@DBUSDIR@
cb06f24
 # Rules...
cb06f24
 #
cb06f24
 
cb06f24
-.SILENT:
cb06f24
+
cb06f24
 .SUFFIXES:	.1 .1.gz .1m .1m.gz .3 .3.gz .5 .5.gz .7 .7.gz .8 .8.gz .a .c .cxx .h .man .o .32.o .64.o .gz
cb06f24
 
cb06f24
 .c.o:
0b0e738
diff -up cups-1.4.6/scheduler/client.c.lspp cups-1.4.6/scheduler/client.c
0b0e738
--- cups-1.4.6/scheduler/client.c.lspp	2010-10-17 05:13:56.000000000 +0100
0b0e738
+++ cups-1.4.6/scheduler/client.c	2011-01-12 16:39:06.636138325 +0000
ca53cd4
@@ -44,6 +44,7 @@
ca53cd4
  *   valid_host()           - Is the Host: field valid?
ca53cd4
  *   write_file()           - Send a file via HTTP.
ca53cd4
  *   write_pipe()           - Flag that data is available on the CGI pipe.
ca53cd4
+ *   client_pid_to_auid()   - Get the audit login uid of the client.
8936a5c
  */
8936a5c
 
8936a5c
 /*
ca53cd4
@@ -52,6 +53,7 @@
8936a5c
 
8936a5c
 #include "cupsd.h"
8936a5c
 
cb06f24
+#define _GNU_SOURCE
cb06f24
 #ifdef HAVE_CDSASSL
cb06f24
 #  include <Security/Security.h>
e3a2a9f
 #  include <Security/SecItem.h>
e3a2a9f
@@ -90,6 +92,12 @@ extern const char *cssmErrorString(int e
cb06f24
 #  include <tcpd.h>
cb06f24
 #endif /* HAVE_TCPD_H */
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+#include <selinux/selinux.h>
8936a5c
+#include <selinux/context.h>
8936a5c
+#include <fcntl.h>
8936a5c
+#endif /* WITH_LSPP */
e7076f3
+
8936a5c
 
8936a5c
 /*
8936a5c
  * Local functions...
e3a2a9f
@@ -391,6 +399,57 @@ cupsdAcceptClient(cupsd_listener_t *lis)
8936a5c
   }
cb06f24
 #endif /* HAVE_TCPD_H */
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  if (is_lspp_config())
8936a5c
+  {
8936a5c
+    struct ucred cr;
8936a5c
+    unsigned int cl=sizeof(cr);
e7076f3
+
8936a5c
+    if (getsockopt(con->http.fd, SOL_SOCKET, SO_PEERCRED, &cr, &cl) == 0)
8936a5c
+    {
8936a5c
+     /*
8936a5c
+      * client_pid_to_auid() can be racey
8936a5c
+      * In this case the pid is based on a socket connected to the client
8936a5c
+      */
8936a5c
+      if ((con->auid = client_pid_to_auid(cr.pid)) == -1)
8936a5c
+      {
8936a5c
+        close(con->http.fd);
8936a5c
+        cupsdLogMessage(CUPSD_LOG_ERROR, "cupsdAcceptClient: "
8936a5c
+                        "unable to determine client auid for client pid=%d", cr.pid);
8936a5c
+        free(con);
8936a5c
+        return;
8936a5c
+      }
8936a5c
+      cupsdLogMessage(CUPSD_LOG_INFO, "cupsdAcceptClient: peer's pid=%d, uid=%d, gid=%d, auid=%d",
8936a5c
+                      cr.pid, cr.uid, cr.gid, con->auid);
8936a5c
+    }
8936a5c
+    else
8936a5c
+    {
8936a5c
+      close(con->http.fd);
8936a5c
+      cupsdLogMessage(CUPSD_LOG_ERROR, "cupsdAcceptClient: getsockopt() failed");
8936a5c
+      free(con);
8936a5c
+      return; 
8936a5c
+    }
e7076f3
+
8936a5c
+   /*
8936a5c
+    * get the context of the peer connection
8936a5c
+    */
8936a5c
+    if (getpeercon(con->http.fd, &con->scon))
8936a5c
+    {
8936a5c
+      close(con->http.fd);
8936a5c
+      cupsdLogMessage(CUPSD_LOG_ERROR, "cupsdAcceptClient: getpeercon() failed");
8936a5c
+      free(con);
8936a5c
+      return; 
8936a5c
+    }
e7076f3
+
8936a5c
+    cupsdLogMessage(CUPSD_LOG_INFO, "cupsdAcceptClient: client context=%s", con->scon);
8936a5c
+  }
8936a5c
+  else
8936a5c
+  {
8936a5c
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdAcceptClient: skipping getpeercon()");
8936a5c
+    cupsdSetString(&con->scon, UNKNOWN_SL);
8936a5c
+  }
8936a5c
+#endif /* WITH_LSPP */
8936a5c
+
8936a5c
 #ifdef AF_INET6
8936a5c
   if (con->http.hostaddr->addr.sa_family == AF_INET6)
8936a5c
     cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdAcceptClient: %d from %s:%d (IPv6)",
9ed0ac5
@@ -781,6 +840,13 @@ cupsdReadClient(cupsd_client_t *con)	/* 
8936a5c
   mime_type_t		*type;		/* MIME type of file */
8936a5c
   cupsd_printer_t	*p;		/* Printer */
8936a5c
   static unsigned	request_id = 0;	/* Request ID for temp files */
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  security_context_t	spoolcon;	/* context of the job file */
8936a5c
+  context_t		clicon;		/* contex_t container for con->scon */
8936a5c
+  context_t		tmpcon;		/* temp context to swap the level */
8936a5c
+  char			*clirange;	/* SELinux sensitivity range */
8936a5c
+  char			*cliclearance;	/* SELinux low end clearance */
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 
8936a5c
 
8936a5c
   status = HTTP_CONTINUE;
9ed0ac5
@@ -2135,6 +2201,67 @@ cupsdReadClient(cupsd_client_t *con)	/* 
8936a5c
 	    fchmod(con->file, 0640);
8936a5c
 	    fchown(con->file, RunUser, Group);
8936a5c
             fcntl(con->file, F_SETFD, fcntl(con->file, F_GETFD) | FD_CLOEXEC);
8936a5c
+#ifdef WITH_LSPP
8936a5c
+	    if (strncmp(con->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) != 0)
8936a5c
+	    {
8936a5c
+	      if (getfilecon(con->filename, &spoolcon) == -1)
8936a5c
+	      {
8936a5c
+		cupsdSendError(con, HTTP_SERVER_ERROR, CUPSD_AUTH_NONE);
8936a5c
+		return (cupsdCloseClient(con));
8936a5c
+	      }
8936a5c
+	      clicon = context_new(con->scon);
8936a5c
+	      tmpcon = context_new(spoolcon);
8936a5c
+	      freecon(spoolcon);
8936a5c
+	      if (!clicon || !tmpcon)
8936a5c
+	      {
8936a5c
+		cupsdSendError(con, HTTP_SERVER_ERROR, CUPSD_AUTH_NONE);
8936a5c
+		if (clicon)
8936a5c
+		  context_free(clicon);
8936a5c
+		if (tmpcon)
8936a5c
+		  context_free(tmpcon);
8936a5c
+		return (cupsdCloseClient(con));
8936a5c
+	      }
8936a5c
+	      clirange = context_range_get(clicon);
8936a5c
+	      if (clirange)
8936a5c
+	      {
8936a5c
+		clirange = strdup(clirange);
8936a5c
+		if ((cliclearance = strtok(clirange, "-")) != NULL)
8936a5c
+		{
8936a5c
+		  if (context_range_set(tmpcon, cliclearance) == -1)
8936a5c
+		  {
8936a5c
+		    cupsdSendError(con, HTTP_SERVER_ERROR, CUPSD_AUTH_NONE);
8936a5c
+		    free(clirange);
8936a5c
+		    context_free(tmpcon);
8936a5c
+		    context_free(clicon);
8936a5c
+		    return (cupsdCloseClient(con));
8936a5c
+		  }
8936a5c
+		}
8936a5c
+		else
8936a5c
+		{
8936a5c
+		  if (context_range_set(tmpcon, (context_range_get(clicon))) == -1)
8936a5c
+		  {
8936a5c
+		    cupsdSendError(con, HTTP_SERVER_ERROR, CUPSD_AUTH_NONE);
8936a5c
+		    free(clirange);
8936a5c
+		    context_free(tmpcon);
8936a5c
+		    context_free(clicon);
8936a5c
+		    return (cupsdCloseClient(con));
8936a5c
+		  }
8936a5c
+		}
8936a5c
+		free(clirange);
8936a5c
+	      }
8936a5c
+	      if (setfilecon(con->filename, context_str(tmpcon)) == -1)
8936a5c
+	      {
8936a5c
+		cupsdSendError(con, HTTP_SERVER_ERROR, CUPSD_AUTH_NONE);
8936a5c
+		context_free(tmpcon);
8936a5c
+		context_free(clicon);
8936a5c
+		return (cupsdCloseClient(con));
8936a5c
+	      }
8936a5c
+	      cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdReadClient: %s set to %s", 
8936a5c
+			      con->filename, context_str(tmpcon));
8936a5c
+	      context_free(tmpcon);
8936a5c
+	      context_free(clicon);
8936a5c
+	    }
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 	  }
8936a5c
 
8936a5c
 	  if (con->http.state != HTTP_POST_SEND)
e3a2a9f
@@ -4641,6 +4768,50 @@ make_certificate(cupsd_client_t *con)	/*
8936a5c
 #endif /* HAVE_SSL */
8936a5c
 
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+/*
8936a5c
+ * 'client_pid_to_auid()' - Using the client's pid, read /proc and determine the loginuid.
8936a5c
+ */
e7076f3
+
8936a5c
+uid_t client_pid_to_auid(pid_t clipid)
8936a5c
+{
8936a5c
+  uid_t uid;
8936a5c
+  int len, in;
8936a5c
+  char buf[16] = {0};
8936a5c
+  char fname[32] = {0};
e7076f3
+
e7076f3
+
8936a5c
+ /*
8936a5c
+  * Hopefully this pid is still the one we are interested in.
8936a5c
+  */
8936a5c
+  snprintf(fname, 32, "/proc/%d/loginuid", clipid);
8936a5c
+  in = open(fname, O_NOFOLLOW|O_RDONLY);
e7076f3
+
8936a5c
+  if (in < 0)
8936a5c
+    return -1;
e7076f3
+
8936a5c
+  errno = 0;
75d0e82
+
8936a5c
+  do {
8936a5c
+    len = read(in, buf, sizeof(buf));
8936a5c
+  } while (len < 0 && errno == EINTR);
22cc213
+
8936a5c
+  close(in);
38627a4
+
8936a5c
+  if (len < 0 || len >= sizeof(buf))
8936a5c
+    return -1;
38627a4
+
8936a5c
+  errno = 0;
8936a5c
+  buf[len] = 0;
8936a5c
+  uid = strtol(buf, 0, 10);
75d0e82
+
8936a5c
+  if (errno != 0)
8936a5c
+    return -1;
8936a5c
+  else
8936a5c
+    return uid;
8936a5c
+}
8936a5c
+#endif /* WITH_LSPP */
9ad376b
+
8936a5c
 /*
8936a5c
  * 'pipe_command()' - Pipe the output of a command to the remote client.
8936a5c
  */
0b0e738
diff -up cups-1.4.6/scheduler/client.h.lspp cups-1.4.6/scheduler/client.h
0b0e738
--- cups-1.4.6/scheduler/client.h.lspp	2009-05-26 23:01:23.000000000 +0100
0b0e738
+++ cups-1.4.6/scheduler/client.h	2011-01-12 16:39:06.638138222 +0000
cb06f24
@@ -18,6 +18,13 @@
8936a5c
 #endif /* HAVE_AUTHORIZATION_H */
8936a5c
 
cb06f24
 
8936a5c
+/* Copyright (C) 2005 Trusted Computer Solutions, Inc. */
8936a5c
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
9ad376b
+
8936a5c
+#ifdef WITH_LSPP
8936a5c
+#include <selinux/selinux.h>
8936a5c
+#endif /* WITH_LSPP */
d042370
+
8936a5c
 /*
8936a5c
  * HTTP client structure...
8936a5c
  */
ca53cd4
@@ -64,6 +71,10 @@ struct cupsd_client_s
8936a5c
 #ifdef HAVE_AUTHORIZATION_H
8936a5c
   AuthorizationRef	authref;	/* Authorization ref */
8936a5c
 #endif /* HAVE_AUTHORIZATION_H */
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  security_context_t	scon;		/* Security context of connection */
8936a5c
+  uid_t			auid;		/* Audit loginuid of the client */
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 };
8936a5c
 
8936a5c
 #define HTTP(con) &((con)->http)
ca53cd4
@@ -133,6 +144,9 @@ extern void	cupsdStartListening(void);
8936a5c
 extern void	cupsdStopListening(void);
8936a5c
 extern void	cupsdUpdateCGI(void);
8936a5c
 extern void	cupsdWriteClient(cupsd_client_t *con);
8936a5c
+#ifdef WITH_LSPP
8936a5c
+extern uid_t	client_pid_to_auid(pid_t clipid);
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 
8936a5c
 
8936a5c
 /*
0b0e738
diff -up cups-1.4.6/scheduler/conf.c.lspp cups-1.4.6/scheduler/conf.c
0b0e738
--- cups-1.4.6/scheduler/conf.c.lspp	2011-01-12 16:39:06.362152165 +0000
0b0e738
+++ cups-1.4.6/scheduler/conf.c	2011-01-12 16:39:06.643137971 +0000
046ffba
@@ -29,6 +29,7 @@
8936a5c
  *   read_configuration()     - Read a configuration file.
8936a5c
  *   read_location()          - Read a <Location path> definition.
8936a5c
  *   read_policy()            - Read a <Policy name> definition.
8936a5c
+ *   is_lspp_config()         - Is the system configured for LSPP
8936a5c
  */
8936a5c
 
8936a5c
 /*
ca53cd4
@@ -54,6 +55,9 @@
8936a5c
 #  define INADDR_NONE	0xffffffff
8936a5c
 #endif /* !INADDR_NONE */
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+#  include <libaudit.h>
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 
8936a5c
 /*
8936a5c
  * Configuration variable structure...
bf1ed41
@@ -172,6 +176,10 @@ static const cupsd_var_t	variables[] =
8936a5c
 #  if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
8936a5c
   { "ServerKey",		&ServerKey,		CUPSD_VARTYPE_PATHNAME },
8936a5c
 #  endif /* HAVE_LIBSSL || HAVE_GNUTLS */
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  { "AuditLog",			&AuditLog,		CUPSD_VARTYPE_INTEGER },
8936a5c
+  { "PerPageLabels",		&PerPageLabels,		CUPSD_VARTYPE_BOOLEAN },
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 #endif /* HAVE_SSL */
8936a5c
   { "ServerName",		&ServerName,		CUPSD_VARTYPE_STRING },
8936a5c
   { "ServerRoot",		&ServerRoot,		CUPSD_VARTYPE_PATHNAME },
bf1ed41
@@ -430,6 +438,9 @@ cupsdReadConfiguration(void)
8936a5c
   const char	*tmpdir;		/* TMPDIR environment variable */
8936a5c
   struct stat	tmpinfo;		/* Temporary directory info */
cb06f24
   cupsd_policy_t *p;			/* Policy */
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  char		*audit_message;		/* Audit message string */
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 
8936a5c
 
8936a5c
  /*
bf1ed41
@@ -713,6 +724,25 @@ cupsdReadConfiguration(void)
8936a5c
 
8936a5c
   RunUser = getuid();
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  if (AuditLog != -1)
8936a5c
+  {
8936a5c
+   /*
8936a5c
+    * ClassifyOverride is set during read_configuration, if its ON, report it now
8936a5c
+    */
8936a5c
+    if (ClassifyOverride)
8936a5c
+      audit_log_user_message(AuditLog, AUDIT_USYS_CONFIG,
8936a5c
+                "[Config] ClassifyOverride=enabled Users can override print banners",
8936a5c
+                ServerName, NULL, NULL, 1);
8936a5c
+   /*
8936a5c
+    * PerPageLabel is set during read_configuration, if its OFF, report it now
8936a5c
+    */
8936a5c
+    if (!PerPageLabels)
8936a5c
+      audit_log_user_message(AuditLog, AUDIT_USYS_CONFIG,
8936a5c
+                "[Config] PerPageLabels=disabled", ServerName, NULL, NULL, 1);
8936a5c
+  }
8936a5c
+#endif /* WITH_LSPP */
f4b6623
+
a1088d0
   cupsdLogMessage(CUPSD_LOG_INFO, "Remote access is %s.",
ca53cd4
                   RemotePort ? "enabled" : "disabled");
a1088d0
 
bf1ed41
@@ -1081,11 +1111,23 @@ cupsdReadConfiguration(void)
cb06f24
   * Update classification setting as needed...
cb06f24
   */
8936a5c
 
8936a5c
-  if (Classification && !strcasecmp(Classification, "none"))
8936a5c
+  if (Classification && strcasecmp(Classification, "none") == 0)
8936a5c
     cupsdClearString(&Classification);
8936a5c
 
8936a5c
   if (Classification)
8936a5c
+  {
8936a5c
     cupsdLogMessage(CUPSD_LOG_INFO, "Security set to \"%s\"", Classification);
8936a5c
+#ifdef WITH_LSPP
8936a5c
+    if (AuditLog != -1)
8936a5c
+    {
8936a5c
+      audit_message = NULL;
8936a5c
+      cupsdSetStringf(&audit_message, "[Config] Classification=%s", Classification);
8936a5c
+      audit_log_user_message(AuditLog, AUDIT_LABEL_LEVEL_CHANGE, audit_message,
8936a5c
+                             ServerName, NULL, NULL, 1);
8936a5c
+      cupsdClearString(&audit_message);
8936a5c
+    }
8936a5c
+#endif /* WITH_LSPP */
8936a5c
+  }
8936a5c
 
8936a5c
  /*
cb06f24
   * Check the MaxClients setting, and then allocate memory for it...
e3a2a9f
@@ -3657,6 +3699,18 @@ read_location(cups_file_t *fp,		/* I - C
cb98b41
   return ((FatalErrors & CUPSD_FATAL_CONFIG) ? 0 : linenum);
8936a5c
 }
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+int is_lspp_config()
8936a5c
+{
8936a5c
+  if (Classification != NULL)
8936a5c
+    return ((strcasecmp(Classification, MLS_CONFIG) == 0) 
8936a5c
+            || (strcasecmp(Classification, TE_CONFIG) == 0)
8936a5c
+            || (strcasecmp(Classification, SELINUX_CONFIG) == 0));
8936a5c
+  else
8936a5c
+    return 0;
8936a5c
+}
8936a5c
+#endif /* WITH_LSPP */
e7076f3
+
8936a5c
 
8936a5c
 /*
cb98b41
  * 'read_policy()' - Read a <Policy name> definition.
0b0e738
diff -up cups-1.4.6/scheduler/conf.h.lspp cups-1.4.6/scheduler/conf.h
0b0e738
--- cups-1.4.6/scheduler/conf.h.lspp	2011-01-12 16:39:06.365152014 +0000
0b0e738
+++ cups-1.4.6/scheduler/conf.h	2011-01-12 16:39:06.645137869 +0000
bf1ed41
@@ -250,6 +250,12 @@ VAR char		*ServerKey		VALUE(NULL);
cb06f24
 VAR int			SSLOptions		VALUE(CUPSD_SSL_NONE);
cb06f24
 					/* SSL/TLS options */
8936a5c
 #endif /* HAVE_SSL */
8936a5c
+#ifdef WITH_LSPP
8936a5c
+VAR int			AuditLog		VALUE(-1),
8936a5c
+					/* File descriptor for audit */
8936a5c
+			PerPageLabels		VALUE(TRUE);
8936a5c
+					/* Put the label on each page */
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 
8936a5c
 #ifdef HAVE_LAUNCHD
cb06f24
 VAR int			LaunchdTimeout		VALUE(DEFAULT_KEEPALIVE);
bf1ed41
@@ -266,6 +272,9 @@ VAR char		*SystemGroupAuthKey	VALUE(NULL
8936a5c
 					/* System group auth key */
8936a5c
 #endif /* HAVE_AUTHORIZATION_H */
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+extern int	is_lspp_config(void);
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 
8936a5c
 /*
8936a5c
  * Prototypes...
0b0e738
diff -up cups-1.4.6/scheduler/ipp.c.lspp cups-1.4.6/scheduler/ipp.c
0b0e738
--- cups-1.4.6/scheduler/ipp.c.lspp	2011-01-12 16:39:06.561142113 +0000
0b0e738
+++ cups-1.4.6/scheduler/ipp.c	2011-01-12 16:39:06.655137365 +0000
cb06f24
@@ -41,6 +41,7 @@
8936a5c
  *   cancel_all_jobs()           - Cancel all print jobs.
8936a5c
  *   cancel_job()                - Cancel a print job.
8936a5c
  *   cancel_subscription()       - Cancel a subscription.
8936a5c
+ *   check_context()             - Check the SELinux context for a user and job
8936a5c
  *   check_quotas()              - Check quotas for a printer and user.
34fc0f7
  *   check_rss_recipient()       - Check that we do not have a duplicate RSS
34fc0f7
  *                                 feed URI.
a1088d0
@@ -102,6 +103,9 @@
8936a5c
  *   validate_user()             - Validate the user for the request.
8936a5c
  */
8936a5c
 
8936a5c
+/* Copyright (C) 2005 Trusted Computer Solutions, Inc. */
8936a5c
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
e7076f3
+
8936a5c
 /*
8936a5c
  * Include necessary headers...
8936a5c
  */
ca53cd4
@@ -124,6 +128,14 @@ extern int mbr_check_membership_by_id(uu
8936a5c
 #  endif /* HAVE_MEMBERSHIPPRIV_H */
8936a5c
 #endif /* __APPLE__ */
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+#include <libaudit.h>
8936a5c
+#include <selinux/selinux.h>
8936a5c
+#include <selinux/context.h>
8936a5c
+#include <selinux/avc.h>
8936a5c
+#include <selinux/flask.h>
8936a5c
+#include <selinux/av_permissions.h>
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 
8936a5c
 /*
8936a5c
  * Local functions...
ca53cd4
@@ -157,6 +169,9 @@ static void	cancel_all_jobs(cupsd_client
8936a5c
 static void	cancel_job(cupsd_client_t *con, ipp_attribute_t *uri);
8936a5c
 static void	cancel_subscription(cupsd_client_t *con, int id);
34fc0f7
 static int	check_rss_recipient(const char *recipient);
8936a5c
+#ifdef WITH_LSPP
8936a5c
+static int	check_context(cupsd_client_t *con, cupsd_job_t *job);
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 static int	check_quotas(cupsd_client_t *con, cupsd_printer_t *p);
8936a5c
 static ipp_attribute_t	*copy_attribute(ipp_t *to, ipp_attribute_t *attr,
8936a5c
 		                        int quickcopy);
e3a2a9f
@@ -1354,6 +1369,21 @@ add_job(cupsd_client_t  *con,		/* I - Cl
bf1ed41
   ipp_attribute_t *media_col,		/* media-col attribute */
bf1ed41
 		*media_margin;		/* media-*-margin attribute */
bf1ed41
   ipp_t		*unsup_col;		/* media-col in unsupported response */
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  char		*audit_message;		/* Audit message string */
8936a5c
+  char		*printerfile;		/* device file pointed to by the printer */
8936a5c
+  char		*userheader = NULL;	/* User supplied job-sheets[0] */
8936a5c
+  char		*userfooter = NULL;	/* User supplied job-sheets[1] */
8936a5c
+  int		override = 0;		/* Was a banner overrode on a job */
8936a5c
+  security_id_t	clisid;			/* SELinux SID for the client */
8936a5c
+  security_id_t	psid;			/* SELinux SID for the printer */
8936a5c
+  context_t	printercon;		/* Printer's context string */
8936a5c
+  struct stat	printerstat;		/* Printer's stat buffer */
8936a5c
+  security_context_t	devcon;		/* Printer's SELinux context */
8936a5c
+  struct avc_entry_ref	avcref;		/* Pointer to the access vector cache */
8936a5c
+  security_class_t	tclass;		/* Object class for the SELinux check */
8936a5c
+  access_vector_t	avr;		/* Access method being requested */
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 
8936a5c
 
8936a5c
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_job(%p[%d], %p(%s), %p(%s/%s))",
9ed0ac5
@@ -1612,6 +1642,106 @@ add_job(cupsd_client_t  *con,		/* I - Cl
8936a5c
     ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL,
6100ed1
                  "Untitled");
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  if (is_lspp_config())
8936a5c
+  {
8936a5c
+    if (!con->scon || strncmp(con->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) == 0)
8936a5c
+    {
8936a5c
+      cupsdLogMessage(CUPSD_LOG_ERROR, "add_job: missing classification for connection \'%s\'!", printer->name);
8936a5c
+      send_ipp_status(con, IPP_INTERNAL_ERROR, _("Missing required security attributes."));
8936a5c
+      return (NULL);
8936a5c
+    }
e7076f3
+
8936a5c
+   /*
8936a5c
+    * Perform an access check so that if the user gets feedback at enqueue time
8936a5c
+    */
f4b6623
+
8936a5c
+    printerfile = strstr(printer->device_uri, "/dev/");
8936a5c
+    if (printerfile == NULL && (strncmp(printer->device_uri, "file:/", 6) == 0))
08a85d3
+      printerfile = printer->device_uri + strlen("file:");
f4b6623
+
8936a5c
+    if (printerfile != NULL)
8936a5c
+    {
8936a5c
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "add_job: Attempting an access check on printer device %s",
8936a5c
+                      printerfile);
f4b6623
+
8936a5c
+      if (lstat(printerfile, &printerstat) < 0)
8936a5c
+      {
8936a5c
+	if (errno != ENOENT)
8936a5c
+	{
8936a5c
+	  send_ipp_status(con, IPP_NOT_AUTHORIZED, _("Unable to stat the printer"));
8936a5c
+	  return (NULL);
8936a5c
+	}
8936a5c
+	/*
8936a5c
+	 * The printer does not exist, so for now assume it's a FileDevice
8936a5c
+	 */
8936a5c
+	tclass = SECCLASS_FILE;
8936a5c
+	avr = FILE__WRITE;
8936a5c
+      }
8936a5c
+      else if (S_ISCHR(printerstat.st_mode))
8936a5c
+      {
8936a5c
+	tclass = SECCLASS_CHR_FILE;
8936a5c
+	avr = CHR_FILE__WRITE;
8936a5c
+      }
8936a5c
+      else if (S_ISREG(printerstat.st_mode))
8936a5c
+      {
8936a5c
+	tclass = SECCLASS_FILE;
8936a5c
+	avr = FILE__WRITE;
8936a5c
+      }
8936a5c
+      else
8936a5c
+      {
8936a5c
+	send_ipp_status(con, IPP_NOT_AUTHORIZED, _("Printer is not a character device or regular file"));
8936a5c
+	return (NULL);
8936a5c
+      }
9ed0ac5
+      static avc_initialized = 0;
9ed0ac5
+      if (!avc_initialized++)
9ed0ac5
+          avc_init("cupsd_enqueue_", NULL, NULL, NULL, NULL);
8936a5c
+      avc_entry_ref_init(&avcref);
8936a5c
+      if (avc_context_to_sid(con->scon, &clisid) != 0)
8936a5c
+      {
8936a5c
+        send_ipp_status(con, IPP_NOT_AUTHORIZED, _("Unable to get the SELinux sid of the client"));
8936a5c
+        return (NULL);
8936a5c
+      }
8936a5c
+      if (getfilecon(printerfile, &devcon) == -1)
8936a5c
+      {
8936a5c
+        send_ipp_status(con, IPP_NOT_AUTHORIZED, _("Unable to get the SELinux context of the printer"));
8936a5c
+        return (NULL);
8936a5c
+      }
8936a5c
+      printercon = context_new(devcon);
8936a5c
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "add_job: printer context %s client context %s",
8936a5c
+                      context_str(printercon), con->scon);
8936a5c
+      context_free(printercon);
f4b6623
+
8936a5c
+      if (avc_context_to_sid(devcon, &psid) != 0)
8936a5c
+      {
8936a5c
+        send_ipp_status(con, IPP_NOT_AUTHORIZED, _("Unable to get the SELinux sid of the printer"));
8936a5c
+        freecon(devcon);
8936a5c
+        return (NULL);
8936a5c
+      }
8936a5c
+      freecon(devcon);
8936a5c
+      if (avc_has_perm(clisid, psid, tclass, avr, &avcref, NULL) != 0)
8936a5c
+      {
8936a5c
+       /*
8936a5c
+        * The access check failed, so cancel the job and send an audit message
8936a5c
+        */
8936a5c
+        if (AuditLog != -1)
8936a5c
+        {
8936a5c
+          audit_message = NULL;
8936a5c
+          cupsdSetStringf(&audit_message, "job=? auid=%u acct=%s obj=%s refused"
8936a5c
+                          " unable to access printer=%s", con->auid,
8936a5c
+                          con->username, con->scon, printer->name);
8936a5c
+          audit_log_user_message(AuditLog, AUDIT_USER_LABELED_EXPORT, audit_message,
8936a5c
+                                 ServerName, NULL, NULL, 0);
8936a5c
+          cupsdClearString(&audit_message);
8936a5c
+        }
f4b6623
+
8936a5c
+        send_ipp_status(con, IPP_NOT_AUTHORIZED, _("SELinux prohibits access to the printer"));
8936a5c
+        return (NULL);
8936a5c
+      }
8936a5c
+    }
8936a5c
+  }
8936a5c
+#endif /* WITH_LSPP */
f4b6623
+
8936a5c
   if ((job = cupsdAddJob(priority, printer->name)) == NULL)
8936a5c
   {
8936a5c
     send_ipp_status(con, IPP_INTERNAL_ERROR,
9ed0ac5
@@ -1620,6 +1750,32 @@ add_job(cupsd_client_t  *con,		/* I - Cl
8936a5c
     return (NULL);
8936a5c
   }
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  if (is_lspp_config())
8936a5c
+  {
8936a5c
+   /*
8936a5c
+    * duplicate the security context and auid of the connection into the job structure
8936a5c
+    */
8936a5c
+    job->scon = strdup(con->scon);
8936a5c
+    job->auid = con->auid;
f4b6623
+
8936a5c
+   /* 
8936a5c
+    * add the security context to the request so that on a restart the security
8936a5c
+    * attributes will be able to be restored
8936a5c
+    */
8936a5c
+    ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "security-context", 
8936a5c
+		 NULL, job->scon);
8936a5c
+  }
8936a5c
+  else
8936a5c
+  {
8936a5c
+   /*
8936a5c
+    * Fill in the security context of the job as unlabeled
8936a5c
+    */
8936a5c
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "add_job: setting context of job to %s", UNKNOWN_SL);
8936a5c
+    cupsdSetString(&job->scon, UNKNOWN_SL);
8936a5c
+  }
8936a5c
+#endif /* WITH_LSPP */
f4b6623
+
8936a5c
   job->dtype   = printer->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
8936a5c
                                   CUPS_PRINTER_REMOTE);
8936a5c
   job->attrs   = con->request;
9ed0ac5
@@ -1825,6 +1981,29 @@ add_job(cupsd_client_t  *con,		/* I - Cl
1e5683c
       attr->values[0].string.text = _cupsStrRetain(printer->job_sheets[0]);
1e5683c
       attr->values[1].string.text = _cupsStrRetain(printer->job_sheets[1]);
8936a5c
     }
8936a5c
+#ifdef WITH_LSPP
8936a5c
+    else
8936a5c
+    {
8936a5c
+     /*
8936a5c
+      * The option was present, so capture the user supplied strings
8936a5c
+      */
8936a5c
+      userheader = strdup(attr->values[0].string.text);
f4b6623
+
8936a5c
+      if (attr->num_values > 1)
8936a5c
+        userfooter = strdup(attr->values[1].string.text);
8936a5c
+  
8936a5c
+      if (Classification != NULL && (strcmp(userheader, Classification) == 0)
8936a5c
+          && userfooter &&(strcmp(userfooter, Classification) == 0))
8936a5c
+      {
8936a5c
+       /*
8936a5c
+        * Since both values are Classification, the user is not trying to Override
8936a5c
+        */
8936a5c
+        free(userheader);
8936a5c
+        if (userfooter) free(userfooter);
8936a5c
+        userheader = userfooter = NULL;
8936a5c
+      }
8936a5c
+    }
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 
8936a5c
     job->job_sheets = attr;
8936a5c
 
9ed0ac5
@@ -1855,6 +2034,9 @@ add_job(cupsd_client_t  *con,		/* I - Cl
cb06f24
 	                		     "job-sheets=\"%s,none\", "
cb06f24
 					     "job-originating-user-name=\"%s\"",
cb06f24
 	              Classification, job->username);
8936a5c
+#ifdef WITH_LSPP
cb06f24
+	  override = 1;
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 	}
8936a5c
 	else if (attr->num_values == 2 &&
8936a5c
 	         strcmp(attr->values[0].string.text,
9ed0ac5
@@ -1873,6 +2055,9 @@ add_job(cupsd_client_t  *con,		/* I - Cl
cb06f24
 					     "job-originating-user-name=\"%s\"",
cb06f24
 		      attr->values[0].string.text,
cb06f24
 		      attr->values[1].string.text, job->username);
8936a5c
+#ifdef WITH_LSPP
cb06f24
+	  override = 1;
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 	}
8936a5c
 	else if (strcmp(attr->values[0].string.text, Classification) &&
8936a5c
 	         strcmp(attr->values[0].string.text, "none") &&
9ed0ac5
@@ -1893,6 +2078,9 @@ add_job(cupsd_client_t  *con,		/* I - Cl
cb06f24
 			"job-originating-user-name=\"%s\"",
cb06f24
 			attr->values[0].string.text,
cb06f24
 			attr->values[1].string.text, job->username);
8936a5c
+#ifdef WITH_LSPP
cb06f24
+	  override = 1;
8936a5c
+#endif /* WITH_LSPP */
8936a5c
         }
8936a5c
       }
8936a5c
       else if (strcmp(attr->values[0].string.text, Classification) &&
9ed0ac5
@@ -1933,8 +2121,52 @@ add_job(cupsd_client_t  *con,		/* I - Cl
cb06f24
 		      "job-sheets=\"%s\", "
cb06f24
 		      "job-originating-user-name=\"%s\"",
cb06f24
 		      Classification, job->username);
8936a5c
+#ifdef WITH_LSPP
cb06f24
+	override = 1;
8936a5c
+#endif /* WITH_LSPP */
8936a5c
+      }
8936a5c
+#ifdef WITH_LSPP
8936a5c
+      if (is_lspp_config() && AuditLog != -1)
8936a5c
+      {
8936a5c
+        audit_message = NULL;
f4b6623
+
8936a5c
+        if (userheader || userfooter)
8936a5c
+        {
8936a5c
+          if (!override)
8936a5c
+          {
8936a5c
+           /*
8936a5c
+            * The user overrode the banner, so audit it
8936a5c
+            */
8936a5c
+            cupsdSetStringf(&audit_message, "job=%d user supplied job-sheets=%s,%s"
8936a5c
+                            " using banners=%s,%s", job->id, userheader,
8936a5c
+                            userfooter, attr->values[0].string.text,
8936a5c
+                            (attr->num_values > 1) ? attr->values[1].string.text : "(null)");
8936a5c
+            audit_log_user_message(AuditLog, AUDIT_LABEL_OVERRIDE, audit_message,
8936a5c
+                                   ServerName, NULL, NULL, 1);
cb06f24
+	  }
8936a5c
+          else
8936a5c
+          {
8936a5c
+           /*
8936a5c
+            * The user tried to override the banner, audit the failure
8936a5c
+            */
8936a5c
+            cupsdSetStringf(&audit_message, "job=%d user supplied job-sheets=%s,%s"
8936a5c
+                            " ignored banners=%s,%s", job->id, userheader,
8936a5c
+                            userfooter, attr->values[0].string.text,
8936a5c
+                            (attr->num_values > 1) ? attr->values[1].string.text : "(null)");
8936a5c
+            audit_log_user_message(AuditLog, AUDIT_LABEL_OVERRIDE, audit_message,
8936a5c
+                                   ServerName, NULL, NULL, 0);
cb06f24
+	  }
8936a5c
+          cupsdClearString(&audit_message);
cb06f24
+	}
8936a5c
       }
cb06f24
+
8936a5c
+      if (userheader)
8936a5c
+        free(userheader);
8936a5c
+      if (userfooter)
8936a5c
+        free(userfooter);
8936a5c
+#endif /* WITH_LSPP */
cb06f24
     }
cb06f24
+    
cb06f24
 
8936a5c
    /*
8936a5c
     * See if we need to add the starting sheet...
9ed0ac5
@@ -4289,6 +4521,107 @@ check_rss_recipient(
8936a5c
 }
8936a5c
 
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+/*
8936a5c
+ * 'check_context()' - Check SELinux security context of a user and job
8936a5c
+ */
f4b6623
+
8936a5c
+static int				/* O - 1 if OK, 0 if not, -1 on error */
8936a5c
+check_context(cupsd_client_t *con,	/* I - Client connection */
8936a5c
+             cupsd_job_t    *job)	/* I - Job */
8936a5c
+{
8936a5c
+  int			enforcing;	/* is SELinux in enforcing mode */
8936a5c
+  char			filename[1024]; /* Filename of the spool file */
8936a5c
+  security_id_t		clisid;		/* SELinux SID of the client */
8936a5c
+  security_id_t		jobsid;		/* SELinux SID of the job */
8936a5c
+  security_id_t		filesid;	/* SELinux SID of the spool file */
8936a5c
+  struct avc_entry_ref	avcref;		/* AVC entry cache pointer */
8936a5c
+  security_class_t	tclass;		/* SELinux security class */
8936a5c
+  access_vector_t	avr;		/* SELinux access being queried */
8936a5c
+  security_context_t	spoolfilecon;	/* SELinux context of the spool file */
f4b6623
+
75d0e82
+
8936a5c
+ /*
8936a5c
+  * Validate the input to be sure there are contexts to work with...
8936a5c
+  */
f4b6623
+
8936a5c
+  if (con->scon == NULL || job->scon == NULL
8936a5c
+      || strncmp(con->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) == 0
8936a5c
+      || strncmp(job->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) == 0)
8936a5c
+    return -1;
75d0e82
+
8936a5c
+  if ((enforcing = security_getenforce()) == -1)
8936a5c
+  {
8936a5c
+    cupsdLogMessage(CUPSD_LOG_ERROR, "Error while determining SELinux enforcement");
8936a5c
+    return -1;
8936a5c
+  }
8936a5c
+  cupsdLogMessage(CUPSD_LOG_DEBUG, "check_context: client context %s job context %s", con->scon, job->scon);
75d0e82
+
75d0e82
+
8936a5c
+ /*
8936a5c
+  * Initialize the avc engine...
8936a5c
+  */
22cc213
+
9ed0ac5
+  static avc_initialized = 0;
9ed0ac5
+  if (! avc_initialized++)
8936a5c
+  {
9ed0ac5
+    if (avc_init("cupsd", NULL, NULL, NULL, NULL) < 0)
9ed0ac5
+    {
9ed0ac5
+      cupsdLogMessage(CUPSD_LOG_ERROR, "check_context: unable avc_init");
9ed0ac5
+      return -1;
9ed0ac5
+    } 
8936a5c
+  } 
8936a5c
+  if (avc_context_to_sid(con->scon, &clisid) != 0)
8936a5c
+  {
8936a5c
+    cupsdLogMessage(CUPSD_LOG_ERROR, "check_context: unable to convert %s to SELinux sid", con->scon);
8936a5c
+    return -1;
8936a5c
+  }
8936a5c
+  avc_context_to_sid(job->scon, &jobsid);
8936a5c
+  avc_entry_ref_init(&avcref);
8936a5c
+  tclass = SECCLASS_FILE;
8936a5c
+  avr = FILE__READ;
f4b6623
+
8936a5c
+ /*
8936a5c
+  * Perform the check with the client as the subject, first with the job as the object
8936a5c
+  *   if that fails then with the spool file as the object...
8936a5c
+  */
f4b6623
+
8936a5c
+  if (avc_has_perm_noaudit(clisid, jobsid, tclass, avr, &avcref, NULL) != 0)
8936a5c
+  {
8936a5c
+    cupsdLogMessage(CUPSD_LOG_INFO, "check_context: SELinux denied access based on the client context");
5dd9863
+
8936a5c
+    snprintf(filename, sizeof(filename), "%s/c%05d", RequestRoot, job->id);
8936a5c
+    if (getfilecon(filename, &spoolfilecon) == -1)
8936a5c
+    {
8936a5c
+      cupsdLogMessage(CUPSD_LOG_ERROR, "check_context: Unable to get spoolfile context");
8936a5c
+      return -1;
8936a5c
+    }
8936a5c
+    if (avc_context_to_sid(spoolfilecon, &filesid) != 0)
8936a5c
+    {
8936a5c
+      cupsdLogMessage(CUPSD_LOG_ERROR, "check_context: Unable to determine the SELinux sid for the spool file");
8936a5c
+      freecon(spoolfilecon);
8936a5c
+      return -1;
8936a5c
+    }
8936a5c
+    freecon(spoolfilecon);
8936a5c
+    if (avc_has_perm_noaudit(clisid, filesid, tclass, avr, &avcref, NULL) != 0)
8936a5c
+    {
8936a5c
+      cupsdLogMessage(CUPSD_LOG_INFO, "check_context: SELinux denied access to the spool file");
8936a5c
+      return 0;
8936a5c
+    }
8936a5c
+    cupsdLogMessage(CUPSD_LOG_INFO, "check_context: SELinux allowed access to the spool file");
8936a5c
+    return 1;
8936a5c
+  }
8936a5c
+  else
8936a5c
+    if (enforcing == 0)
8936a5c
+        cupsdLogMessage(CUPSD_LOG_INFO, "check_context: allowing operation due to permissive mode");
8936a5c
+    else
8936a5c
+        cupsdLogMessage(CUPSD_LOG_INFO, "check_context: SELinux allowed access based on the client context");
f4b6623
+
8936a5c
+  return 1;
8936a5c
+}
8936a5c
+#endif /* WITH_LSPP */
f4b6623
+
f4b6623
+
8936a5c
 /*
8936a5c
  * 'check_quotas()' - Check quotas for a printer and user.
8936a5c
  */
9ed0ac5
@@ -4843,6 +5176,15 @@ copy_banner(cupsd_client_t *con,	/* I - 
8936a5c
   char		attrname[255],		/* Name of attribute */
8936a5c
 		*s;			/* Pointer into name */
8936a5c
   ipp_attribute_t *attr;		/* Attribute */
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  const char	*mls_label;		/* SL of print job */
8936a5c
+  char		*jobrange;		/* SELinux sensitivity range */
8936a5c
+  char		*jobclearance;		/* SELinux low end clearance */
8936a5c
+  context_t	jobcon;			/* SELinux context of the job */
8936a5c
+  context_t	tmpcon;			/* Temp context to set the level */
8936a5c
+  security_context_t	spoolcon;	/* Context of the file in the spool */
8936a5c
+#endif /* WITH_LSPP */
f4b6623
+
8936a5c
 
8936a5c
 
34fc0f7
   cupsdLogMessage(CUPSD_LOG_DEBUG2,
9ed0ac5
@@ -4878,6 +5220,82 @@ copy_banner(cupsd_client_t *con,	/* I - 
8936a5c
 
8936a5c
   fchmod(cupsFileNumber(out), 0640);
8936a5c
   fchown(cupsFileNumber(out), RunUser, Group);
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  if (job->scon != NULL &&
8936a5c
+      strncmp(job->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) != 0)
8936a5c
+  {
8936a5c
+    if (getfilecon(filename, &spoolcon) == -1)
8936a5c
+    {
8936a5c
+      cupsdLogMessage(CUPSD_LOG_ERROR,
8936a5c
+                      "copy_banner: Unable to get the context of the banner file %s - %s",
8936a5c
+                      filename, strerror(errno));
8936a5c
+      job->num_files --;
8936a5c
+      return (0);
8936a5c
+    }
8936a5c
+    tmpcon = context_new(spoolcon);
8936a5c
+    jobcon = context_new(job->scon);
8936a5c
+    freecon(spoolcon);
8936a5c
+    if (!tmpcon || !jobcon)
8936a5c
+    {
8936a5c
+      if (tmpcon)
8936a5c
+        context_free(tmpcon);
8936a5c
+      if (jobcon)
8936a5c
+        context_free(jobcon);
8936a5c
+      cupsdLogMessage(CUPSD_LOG_ERROR,
8936a5c
+                      "copy_banner: Unable to get the SELinux contexts");
8936a5c
+      job->num_files --;
8936a5c
+      return (0);
8936a5c
+    }
8936a5c
+    jobrange = context_range_get(jobcon);
8936a5c
+    if (jobrange)
8936a5c
+    {
8936a5c
+      jobrange = strdup(jobrange);
8936a5c
+      if ((jobclearance = strtok(jobrange, "-")) != NULL)
8936a5c
+      {
8936a5c
+	if (context_range_set(tmpcon, jobclearance) == -1)
8936a5c
+	{
8936a5c
+	  cupsdLogMessage(CUPSD_LOG_ERROR,
8936a5c
+			  "copy_banner: Unable to set the level of the context for file %s - %s",
8936a5c
+			  filename, strerror(errno));
8936a5c
+	  free(jobrange);
8936a5c
+	  context_free(jobcon);
8936a5c
+	  context_free(tmpcon);
8936a5c
+	  job->num_files --;
8936a5c
+	  return (0);
8936a5c
+	}
8936a5c
+      }
8936a5c
+      else
8936a5c
+      {
8936a5c
+	if (context_range_set(tmpcon, (context_range_get(jobcon))) == -1)
8936a5c
+	{
8936a5c
+	  cupsdLogMessage(CUPSD_LOG_ERROR,
8936a5c
+			  "copy_banner: Unable to set the level of the context for file %s - %s",
8936a5c
+			  filename, strerror(errno));
8936a5c
+	  free(jobrange);
8936a5c
+	  context_free(jobcon);
8936a5c
+	  context_free(tmpcon);
8936a5c
+	  job->num_files --;
8936a5c
+	  return (0);
8936a5c
+	}
8936a5c
+      }
8936a5c
+      free(jobrange);
8936a5c
+    }
8936a5c
+    if (setfilecon(filename, context_str(tmpcon)) == -1)
8936a5c
+    {
8936a5c
+      cupsdLogMessage(CUPSD_LOG_ERROR,
8936a5c
+                      "copy_banner: Unable to set the context of the banner file %s - %s",
8936a5c
+                      filename, strerror(errno));
8936a5c
+      context_free(jobcon);
8936a5c
+      context_free(tmpcon);
8936a5c
+      job->num_files --;
8936a5c
+      return (0);
8936a5c
+    }
8936a5c
+    cupsdLogMessage(CUPSD_LOG_DEBUG2, "copy_banner: %s set to %s",
8936a5c
+                    filename, context_str(tmpcon));
8936a5c
+    context_free(jobcon);
8936a5c
+    context_free(tmpcon);
8936a5c
+  }
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 
8936a5c
  /*
8936a5c
   * Try the localized banner file under the subdirectory...
9ed0ac5
@@ -4972,6 +5390,24 @@ copy_banner(cupsd_client_t *con,	/* I - 
8936a5c
       else
8936a5c
         s = attrname;
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+      if (strcmp(s, "mls-label") == 0)
8936a5c
+      {
8936a5c
+        if (job->scon != NULL && strncmp(job->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) != 0)
8936a5c
+        {
8936a5c
+          jobcon = context_new(job->scon);
8936a5c
+          if (strcasecmp(name, MLS_CONFIG) == 0)
8936a5c
+            mls_label = context_range_get(jobcon);
8936a5c
+          else if (strcasecmp(name, TE_CONFIG) == 0)
8936a5c
+            mls_label = context_type_get(jobcon);
8936a5c
+          else // default to using the whole context string
8936a5c
+            mls_label = context_str(jobcon);
8936a5c
+          cupsFilePuts(out, mls_label);
8936a5c
+          context_free(jobcon);
8936a5c
+        }
8936a5c
+        continue;
8936a5c
+      }
8936a5c
+#endif /* WITH_LSPP */
8936a5c
       if (!strcmp(s, "printer-name"))
8936a5c
       {
8936a5c
         cupsFilePuts(out, job->dest);
9ed0ac5
@@ -6945,6 +7381,22 @@ get_job_attrs(cupsd_client_t  *con,	/* I
8936a5c
     return;
8936a5c
   }
8936a5c
 
f4b6623
+
8936a5c
+#ifdef WITH_LSPP
8936a5c
+ /*
8936a5c
+  * Check SELinux...
8936a5c
+  */
8936a5c
+  if (is_lspp_config() && check_context(con, job) != 1)
8936a5c
+  {
8936a5c
+   /*
8936a5c
+    * Unfortunately we have to lie to the user...
8936a5c
+    */
8936a5c
+    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid);
8936a5c
+    return;
8936a5c
+  }
8936a5c
+#endif /* WITH_LSPP */
d042370
+
ee6b344
+
8936a5c
  /*
8936a5c
   * Copy attributes...
8936a5c
   */
9ed0ac5
@@ -7175,6 +7627,11 @@ get_jobs(cupsd_client_t  *con,		/* I - C
a1088d0
     if (username[0] && strcasecmp(username, job->username))
a1088d0
       continue;
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+    if (is_lspp_config() && check_context(con, job) != 1)
8936a5c
+      continue;
8936a5c
+#endif /* WITH_LSPP */
e7076f3
+
a1088d0
     if (count > 0)
a1088d0
       ippAddSeparator(con->response);
8936a5c
 
9ed0ac5
@@ -11594,6 +12051,11 @@ validate_user(cupsd_job_t    *job,	/* I 
8936a5c
 
8936a5c
   strlcpy(username, get_username(con), userlen);
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  if (is_lspp_config() && check_context(con, job) != 1)
8936a5c
+    return 0;
8936a5c
+#endif /* WITH_LSPP */
e7076f3
+
8936a5c
  /*
8936a5c
   * Check the username against the owner...
8936a5c
   */
0b0e738
diff -up cups-1.4.6/scheduler/job.c.lspp cups-1.4.6/scheduler/job.c
0b0e738
--- cups-1.4.6/scheduler/job.c.lspp	2011-01-12 16:39:06.481146153 +0000
0b0e738
+++ cups-1.4.6/scheduler/job.c	2011-01-12 16:39:06.664136910 +0000
ca53cd4
@@ -66,6 +66,9 @@
8936a5c
  *   update_job_attrs()         - Update the job-printer-* attributes.
8936a5c
  */
8936a5c
 
8936a5c
+/* Copyright (C) 2005 Trusted Computer Solutions, Inc. */
8936a5c
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
e7076f3
+
8936a5c
 /*
8936a5c
  * Include necessary headers...
8936a5c
  */
ca53cd4
@@ -75,6 +78,14 @@
8936a5c
 #include <cups/backend.h>
8936a5c
 #include <cups/dir.h>
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+#include <libaudit.h>
8936a5c
+#include <selinux/selinux.h>
8936a5c
+#include <selinux/context.h>
8936a5c
+#include <selinux/avc.h>
8936a5c
+#include <selinux/flask.h>
8936a5c
+#include <selinux/av_permissions.h>
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 
8936a5c
 /*
a1088d0
  * Design Notes for Job Management
0b0e738
@@ -508,6 +519,14 @@ cupsdContinueJob(cupsd_job_t *job)	/* I 
a1088d0
 					/* PRINTER env variable */
a1088d0
 			rip_max_cache[255];
a1088d0
 					/* RIP_MAX_CACHE env variable */
a1088d0
+#ifdef WITH_LSPP
a1088d0
+  char			*audit_message = NULL;	/* Audit message string */
a1088d0
+  context_t		jobcon;		/* SELinux context of the job */
a1088d0
+  char			*label_template = NULL;	/* SL to put in classification
a1088d0
+						   env var */
a1088d0
+  const char		*mls_label = NULL;	/* SL to put in classification
a1088d0
+						   env var */
a1088d0
+#endif /* WITH_LSPP */
a1088d0
 
a1088d0
 
a1088d0
   cupsdLogMessage(CUPSD_LOG_DEBUG2,
0b0e738
@@ -932,6 +951,67 @@ cupsdContinueJob(cupsd_job_t *job)	/* I 
a1088d0
     }
a1088d0
   }
a1088d0
 
a1088d0
+#ifdef WITH_LSPP
a1088d0
+  if (is_lspp_config())
a1088d0
+  {
a1088d0
+    if (!job->scon || strncmp(job->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) == 0)
a1088d0
+    {
a1088d0
+      if (AuditLog != -1)
a1088d0
+      {
a1088d0
+        audit_message = NULL;
a1088d0
+        cupsdSetStringf(&audit_message, "job=%d auid=%u acct=%s printer=%s title=%s",
a1088d0
+                        job->id, job->auid, job->username, job->printer->name, title);
a1088d0
+        audit_log_user_message(AuditLog, AUDIT_USER_UNLABELED_EXPORT, audit_message,
a1088d0
+                               ServerName, NULL, NULL, 1);
a1088d0
+        cupsdClearString(&audit_message);
a1088d0
+      }
a1088d0
+    }
a1088d0
+    else 
a1088d0
+    {
a1088d0
+      jobcon = context_new(job->scon);
a1088d0
+
a1088d0
+      if ((attr = ippFindAttribute(job->attrs, "job-sheets", IPP_TAG_NAME)) == NULL)
a1088d0
+        label_template = strdup(Classification);
a1088d0
+      else if (attr->num_values > 1 &&
a1088d0
+               strcmp(attr->values[1].string.text, "none") != 0)
a1088d0
+        label_template = strdup(attr->values[1].string.text);
a1088d0
+      else
a1088d0
+        label_template = strdup(attr->values[0].string.text);
a1088d0
+
a1088d0
+      if (strcasecmp(label_template, MLS_CONFIG) == 0)
a1088d0
+        mls_label = context_range_get(jobcon);
a1088d0
+      else if (strcasecmp(label_template, TE_CONFIG) == 0)
a1088d0
+        mls_label = context_type_get(jobcon);
a1088d0
+      else if (strcasecmp(label_template, SELINUX_CONFIG) == 0)
a1088d0
+        mls_label = context_str(jobcon);
a1088d0
+      else
a1088d0
+        mls_label = label_template;
a1088d0
+
a1088d0
+      if (mls_label && (PerPageLabels || banner_page))
a1088d0
+      {
a1088d0
+        snprintf(classification, sizeof(classification), "CLASSIFICATION=LSPP:%s", mls_label);
a1088d0
+        envp[envc ++] = classification;
a1088d0
+      }
a1088d0
+
a1088d0
+      if ((AuditLog != -1) && !banner_page)
a1088d0
+      {
a1088d0
+        audit_message = NULL;
a1088d0
+        cupsdSetStringf(&audit_message, "job=%d auid=%u acct=%s printer=%s title=%s"
a1088d0
+                        " obj=%s label=%s", job->id, job->auid, job->username,
a1088d0
+                        job->printer->name, title, job->scon, mls_label?mls_label:"none");
a1088d0
+        audit_log_user_message(AuditLog, AUDIT_USER_LABELED_EXPORT, audit_message,
a1088d0
+                               ServerName, NULL, NULL, 1);
a1088d0
+        cupsdClearString(&audit_message);
a1088d0
+      }
a1088d0
+      context_free(jobcon);
a1088d0
+      free(label_template);
a1088d0
+    }
a1088d0
+  }
a1088d0
+  else
a1088d0
+   /*
a1088d0
+    * Fall through to the non-LSPP behavior
a1088d0
+    */
a1088d0
+#endif /* WITH_LSPP */
a1088d0
   if (Classification && !banner_page)
a1088d0
   {
a1088d0
     if ((attr = ippFindAttribute(job->attrs, "job-sheets",
0b0e738
@@ -1629,6 +1709,20 @@ cupsdLoadJob(cupsd_job_t *job)		/* I - J
3244c62
     goto error;
8936a5c
   }
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  if ((attr = ippFindAttribute(job->attrs, "security-context", IPP_TAG_NAME)) != NULL)
8936a5c
+    cupsdSetString(&job->scon, attr->values[0].string.text);
8936a5c
+  else if (is_lspp_config())
8936a5c
+  {
8936a5c
+   /*
8936a5c
+    * There was no security context so delete the job
8936a5c
+    */
8936a5c
+    cupsdLogMessage(CUPSD_LOG_ERROR, "LoadAllJobs: Missing or bad security-context attribute in control file \"%s\"!",
8936a5c
+                    jobfile);
3244c62
+    goto error;
8936a5c
+  }
8936a5c
+#endif /* WITH_LSPP */
e7076f3
+
8936a5c
   job->sheets     = ippFindAttribute(job->attrs, "job-media-sheets-completed",
8936a5c
                                      IPP_TAG_INTEGER);
8936a5c
   job->job_sheets = ippFindAttribute(job->attrs, "job-sheets", IPP_TAG_NAME);
0b0e738
@@ -2016,6 +2110,14 @@ cupsdSaveJob(cupsd_job_t *job)		/* I - J
8936a5c
 {
8936a5c
   char		filename[1024];		/* Job control filename */
8936a5c
   cups_file_t	*fp;			/* Job file */
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  security_context_t	spoolcon;	/* context of the job control file */
8936a5c
+  context_t		jobcon;		/* contex_t container for job->scon */
8936a5c
+  context_t		tmpcon;		/* Temp context to swap the level */
a1088d0
+  char			*jobclearance;	/* SELinux low end clearance */
a1088d0
+  const char		*jobrange;	/* SELinux sensitivity range */
a1088d0
+  char			*jobrange_copy;	/* SELinux sensitivity range */
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 
8936a5c
 
8936a5c
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdSaveJob(job=%p(%d)): job->attrs=%p",
0b0e738
@@ -2034,6 +2136,76 @@ cupsdSaveJob(cupsd_job_t *job)		/* I - J
8936a5c
   fchmod(cupsFileNumber(fp), 0600);
8936a5c
   fchown(cupsFileNumber(fp), RunUser, Group);
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  if (job->scon && strncmp(job->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) != 0)
8936a5c
+  {
8936a5c
+    if (getfilecon(filename, &spoolcon) == -1)
8936a5c
+    {
8936a5c
+      cupsdLogMessage(CUPSD_LOG_ERROR,
8936a5c
+                      "Unable to get context of job control file \"%s\" - %s.",
8936a5c
+                      filename, strerror(errno));
8936a5c
+      return;
8936a5c
+    }
8936a5c
+    jobcon = context_new(job->scon);
8936a5c
+    tmpcon = context_new(spoolcon);
8936a5c
+    freecon(spoolcon);
8936a5c
+    if (!jobcon || !tmpcon)
8936a5c
+    {
8936a5c
+      if (jobcon)
8936a5c
+        context_free(jobcon);
8936a5c
+      if (tmpcon)
8936a5c
+        context_free(tmpcon);
8936a5c
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to get SELinux contexts");
8936a5c
+      return;
8936a5c
+    }
8936a5c
+    jobrange = context_range_get(jobcon);
8936a5c
+    if (jobrange)
8936a5c
+    {
a1088d0
+      jobrange_copy = strdup(jobrange);
a1088d0
+      if ((jobclearance = strtok(jobrange_copy, "-")) != NULL)
8936a5c
+      {
8936a5c
+	if (context_range_set(tmpcon, jobclearance) == -1)
8936a5c
+	{
8936a5c
+	  cupsdLogMessage(CUPSD_LOG_ERROR,
8936a5c
+			  "Unable to set the range for job control file \"%s\" - %s.",
8936a5c
+			  filename, strerror(errno));
a1088d0
+	  free(jobrange_copy);
8936a5c
+	  context_free(tmpcon);
8936a5c
+	  context_free(jobcon);
8936a5c
+	  return;
8936a5c
+	}
8936a5c
+      }
8936a5c
+      else
8936a5c
+      {
8936a5c
+	if (context_range_set(tmpcon, (context_range_get(jobcon))) == -1)
8936a5c
+	{
8936a5c
+	  cupsdLogMessage(CUPSD_LOG_ERROR,
8936a5c
+			  "Unable to set the range for job control file \"%s\" - %s.",
8936a5c
+			  filename, strerror(errno));
a1088d0
+	  free(jobrange_copy);
8936a5c
+	  context_free(tmpcon);
8936a5c
+	  context_free(jobcon);
8936a5c
+	  return;
8936a5c
+	}
8936a5c
+      }
a1088d0
+      free(jobrange_copy);
8936a5c
+    }
8936a5c
+    if (setfilecon(filename, context_str(tmpcon)) == -1)
8936a5c
+    {
8936a5c
+      cupsdLogMessage(CUPSD_LOG_ERROR,
8936a5c
+                      "Unable to set context of job control file \"%s\" - %s.",
8936a5c
+                      filename, strerror(errno));
8936a5c
+      context_free(tmpcon);
8936a5c
+      context_free(jobcon);
8936a5c
+      return;
8936a5c
+    }
8936a5c
+    cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdSaveJob(job=%p): new spool file context=%s",
8936a5c
+                    job, context_str(tmpcon));
8936a5c
+    context_free(tmpcon);
8936a5c
+    context_free(jobcon);
8936a5c
+  }
8936a5c
+#endif /* WITH_LSPP */
e7076f3
+
8936a5c
   job->attrs->state = IPP_IDLE;
8936a5c
 
8936a5c
   if (ippWriteIO(fp, (ipp_iocb_t)cupsFileWrite, 1, NULL,
0b0e738
@@ -3341,6 +3513,18 @@ get_options(cupsd_job_t *job,		/* I - Jo
a1088d0
 	  banner_page)
a1088d0
         continue;
a1088d0
 
a1088d0
+#ifdef WITH_LSPP
a1088d0
+     /*
a1088d0
+      * In LSPP mode refuse to honor the page-label
a1088d0
+      */
a1088d0
+      if (is_lspp_config() &&
a1088d0
+          !strcmp(attr->name, "page-label"))
a1088d0
+      {
a1088d0
+        cupsdLogMessage(CUPSD_LOG_DEBUG, "Ignoring page-label option due to LSPP mode");
a1088d0
+        continue;
a1088d0
+      }
a1088d0
+#endif /* WITH_LSPP */
a1088d0
+
a1088d0
      /*
a1088d0
       * Otherwise add them to the list...
a1088d0
       */
0b0e738
@@ -4029,6 +4213,19 @@ static void
a1088d0
 start_job(cupsd_job_t     *job,		/* I - Job ID */
a1088d0
           cupsd_printer_t *printer)	/* I - Printer to print job */
a1088d0
 {
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  char			*audit_message = NULL;	/* Audit message string */
8936a5c
+  char			*printerfile = NULL;	/* Device file pointed to by the printer */
8936a5c
+  security_id_t		clisid;		/* SELinux SID for the client */
8936a5c
+  security_id_t		psid;		/* SELinux SID for the printer */
8936a5c
+  context_t		printercon;	/* Printer's context string */
8936a5c
+  struct stat		printerstat;	/* Printer's stat buffer */
8936a5c
+  security_context_t	devcon;		/* Printer's SELinux context */
8936a5c
+  struct avc_entry_ref	avcref;		/* Pointer to the access vector cache */
8936a5c
+  security_class_t	tclass;		/* Object class for the SELinux check */
8936a5c
+  access_vector_t	avr;		/* Access method being requested */
8936a5c
+#endif /* WITH_LSPP */
a1088d0
+
a1088d0
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "start_job(job=%p(%d), printer=%p(%s))",
a1088d0
                   job, job->id, printer, printer->name);
8936a5c
 
0b0e738
@@ -4151,6 +4348,108 @@ start_job(cupsd_job_t     *job,		/* I - 
7e278ad
   fcntl(job->side_pipes[1], F_SETFD,
7e278ad
 	fcntl(job->side_pipes[1], F_GETFD) | FD_CLOEXEC);
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  if (is_lspp_config())
8936a5c
+  {
8936a5c
+   /*
8936a5c
+    * Perform an access check before printing, but only if the printer starts with /dev/
8936a5c
+    */
8936a5c
+    printerfile = strstr(printer->device_uri, "/dev/");
8936a5c
+    if (printerfile == NULL && (strncmp(printer->device_uri, "file:/", 6) == 0))
08a85d3
+      printerfile = printer->device_uri + strlen("file:");
e7076f3
+
8936a5c
+    if (printerfile != NULL)
8936a5c
+    {
8936a5c
+      cupsdLogMessage(CUPSD_LOG_DEBUG,
8936a5c
+                      "StartJob: Attempting to check access on printer device %s", printerfile);
8936a5c
+      if (lstat(printerfile, &printerstat) < 0)
8936a5c
+      {
8936a5c
+	if (errno != ENOENT)
8936a5c
+	{
8936a5c
+	  cupsdLogMessage(CUPSD_LOG_ERROR, "StartJob: Unable to stat the printer");
a1088d0
+	  cupsdSetJobState(job, IPP_JOB_ABORTED, CUPSD_JOB_DEFAULT, NULL);
8936a5c
+	  return ;
8936a5c
+	}
8936a5c
+	/*
8936a5c
+	 * The printer does not exist, so for now assume it's a FileDevice
8936a5c
+	 */
8936a5c
+	tclass = SECCLASS_FILE;
8936a5c
+	avr = FILE__WRITE;
8936a5c
+      }
8936a5c
+      else if (S_ISCHR(printerstat.st_mode))
8936a5c
+      {
8936a5c
+	tclass = SECCLASS_CHR_FILE;
8936a5c
+	avr = CHR_FILE__WRITE;
8936a5c
+      }
8936a5c
+      else if (S_ISREG(printerstat.st_mode))
8936a5c
+      {
8936a5c
+	tclass = SECCLASS_FILE;
8936a5c
+	avr = FILE__WRITE;
8936a5c
+      }
8936a5c
+      else
8936a5c
+      {
8936a5c
+	cupsdLogMessage(CUPSD_LOG_ERROR,
8936a5c
+			"StartJob: Printer is not a character device or regular file");
a1088d0
+	cupsdSetJobState(job, IPP_JOB_ABORTED, CUPSD_JOB_DEFAULT, NULL);
8936a5c
+	return ;
8936a5c
+      }
9ed0ac5
+      static avc_initialized = 0;
9ed0ac5
+      if (!avc_initialized++)
9ed0ac5
+          avc_init("cupsd_dequeue_", NULL, NULL, NULL, NULL);
8936a5c
+      avc_entry_ref_init(&avcref);
8936a5c
+      if (avc_context_to_sid(job->scon, &clisid) != 0)
8936a5c
+      {
8936a5c
+        cupsdLogMessage(CUPSD_LOG_ERROR,
8936a5c
+                        "StartJob: Unable to determine the SELinux sid for the job");
a1088d0
+        cupsdSetJobState(job, IPP_JOB_ABORTED, CUPSD_JOB_DEFAULT, NULL);
8936a5c
+        return ;
8936a5c
+      }
8936a5c
+      if (getfilecon(printerfile, &devcon) == -1)
8936a5c
+      {
8936a5c
+        cupsdLogMessage(CUPSD_LOG_ERROR, "StartJob: Unable to get the SELinux context of %s",
8936a5c
+                        printerfile);
a1088d0
+        cupsdSetJobState(job, IPP_JOB_ABORTED, CUPSD_JOB_DEFAULT, NULL);
8936a5c
+        return ;
8936a5c
+      }
8936a5c
+      printercon = context_new(devcon);
8936a5c
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "StartJob: printer context %s client context %s",
8936a5c
+                      context_str(printercon), job->scon);
8936a5c
+      context_free(printercon);
e7076f3
+
8936a5c
+      if (avc_context_to_sid(devcon, &psid) != 0)
8936a5c
+      {
8936a5c
+        cupsdLogMessage(CUPSD_LOG_ERROR,
8936a5c
+                        "StartJob: Unable to determine the SELinux sid for the printer");
8936a5c
+        freecon(devcon);
a1088d0
+        cupsdSetJobState(job, IPP_JOB_ABORTED, CUPSD_JOB_DEFAULT, NULL);
8936a5c
+        return ;
8936a5c
+      }
8936a5c
+      freecon(devcon);
e7076f3
+
8936a5c
+      if (avc_has_perm(clisid, psid, tclass, avr, &avcref, NULL) != 0)
8936a5c
+      {
8936a5c
+       /*
8936a5c
+        * The access check failed, so cancel the job and send an audit message
8936a5c
+        */
8936a5c
+        if (AuditLog != -1)
8936a5c
+        {
8936a5c
+          audit_message = NULL;
8936a5c
+          cupsdSetStringf(&audit_message, "job=%d auid=%u acct=%s obj=%s canceled"
8936a5c
+                                          " unable to access printer=%s", job->id,
8936a5c
+                          job->auid, (job->username)?job->username:"?", job->scon, printer->name);
8936a5c
+          audit_log_user_message(AuditLog, AUDIT_USER_LABELED_EXPORT, audit_message,
8936a5c
+                                 ServerName, NULL, NULL, 0);
8936a5c
+          cupsdClearString(&audit_message);
8936a5c
+        }
ee6b344
+
a1088d0
+        cupsdSetJobState(job, IPP_JOB_ABORTED, CUPSD_JOB_DEFAULT, NULL);
ee6b344
+
8936a5c
+        return ;
8936a5c
+      }
8936a5c
+    }
8936a5c
+  }
8936a5c
+#endif /* WITH_LSPP */
ee6b344
+
8936a5c
  /*
a1088d0
   * Now start the first file in the job...
8936a5c
   */
0b0e738
diff -up cups-1.4.6/scheduler/job.h.lspp cups-1.4.6/scheduler/job.h
0b0e738
--- cups-1.4.6/scheduler/job.h.lspp	2009-05-11 23:46:01.000000000 +0100
0b0e738
+++ cups-1.4.6/scheduler/job.h	2011-01-12 16:39:06.667136759 +0000
8936a5c
@@ -13,6 +13,13 @@
8936a5c
  *   file is missing or damaged, see the license at "http://www.cups.org/".
8936a5c
  */
8936a5c
 
8936a5c
+/* Copyright (C) 2005 Trusted Computer Solutions, Inc. */
8936a5c
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
d042370
+
8936a5c
+#ifdef WITH_LSPP
8936a5c
+#include <selinux/selinux.h>
8936a5c
+#endif /* WITH_LSPP */
f4b6623
+
8936a5c
 /*
a1088d0
  * Constants...
8936a5c
  */
ca53cd4
@@ -83,6 +90,10 @@ struct cupsd_job_s			/**** Job request *
8936a5c
   krb5_ccache		ccache;		/* Kerberos credential cache */
8936a5c
   char			*ccname;	/* KRB5CCNAME environment variable */
8936a5c
 #endif /* HAVE_GSSAPI */
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  security_context_t	scon;		/* Security context of job */
8936a5c
+  uid_t			auid;		/* Audit loginuid for this job */
8936a5c
+#endif /* WITH_LSPP */
ca53cd4
 };
8936a5c
 
ca53cd4
 typedef struct cupsd_joblog_s		/**** Job log message ****/
0b0e738
diff -up cups-1.4.6/scheduler/main.c.lspp cups-1.4.6/scheduler/main.c
0b0e738
--- cups-1.4.6/scheduler/main.c.lspp	2011-01-12 16:39:06.589140699 +0000
0b0e738
+++ cups-1.4.6/scheduler/main.c	2011-01-12 16:39:06.669136658 +0000
bf1ed41
@@ -37,6 +37,8 @@
bf1ed41
  *   usage()               - Show scheduler usage.
8936a5c
  */
8936a5c
 
8936a5c
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
ee6b344
+
8936a5c
 /*
8936a5c
  * Include necessary headers...
8936a5c
  */
bf1ed41
@@ -76,6 +78,9 @@
8936a5c
 #  include <dlfcn.h>
8936a5c
 #endif /* __APPLE__ && HAVE_DLFCN_H */
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+#  include <libaudit.h>
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 
8936a5c
 /*
8936a5c
  * Local functions...
0b0e738
@@ -149,6 +154,9 @@ main(int  argc,				/* I - Number of comm
0b2684f
 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
0b2684f
   struct sigaction	action;		/* Actions for POSIX signals */
0b2684f
 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
8936a5c
+#if WITH_LSPP
8936a5c
+  auditfail_t           failmode;       /* Action for audit_open failure */
8936a5c
+#endif /* WITH_LSPP */
0b2684f
 #ifdef __sgi
0b2684f
   cups_file_t		*fp;		/* Fake lpsched lock file */
0b2684f
   struct stat		statbuf;	/* Needed for checking lpsched FIFO */
0b0e738
@@ -478,6 +486,25 @@ main(int  argc,				/* I - Number of comm
8936a5c
 #endif /* DEBUG */
8936a5c
   }
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  if ((AuditLog = audit_open()) < 0 )
8936a5c
+  {
8936a5c
+    if (get_auditfail_action(&failmode) == 0)
8936a5c
+    {
8936a5c
+      if (failmode == FAIL_LOG)
8936a5c
+      {
8936a5c
+        cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to connect to audit subsystem.");
8936a5c
+        AuditLog = -1;
8936a5c
+      }
8936a5c
+      else if (failmode == FAIL_TERMINATE)
8936a5c
+      {
8936a5c
+        fprintf(stderr, "cupsd: unable to start auditing, terminating");
8936a5c
+        return -1;
8936a5c
+      }
8936a5c
+    }
8936a5c
+  }
8936a5c
+#endif /* WITH_LSPP */
e7076f3
+
8936a5c
  /*
8936a5c
   * Set the timezone info...
8936a5c
   */
0b0e738
@@ -1258,6 +1285,11 @@ main(int  argc,				/* I - Number of comm
8936a5c
 
8936a5c
   cupsdStopSelect();
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  if (AuditLog != -1)
8936a5c
+    audit_close(AuditLog);
8936a5c
+#endif /* WITH_LSPP */
ee6b344
+
8936a5c
   return (!stop_scheduler);
8936a5c
 }
8936a5c
 
0b0e738
diff -up cups-1.4.6/scheduler/printers.c.lspp cups-1.4.6/scheduler/printers.c
0b0e738
--- cups-1.4.6/scheduler/printers.c.lspp	2011-01-12 16:39:06.602140044 +0000
0b0e738
+++ cups-1.4.6/scheduler/printers.c	2011-01-12 16:39:06.678136203 +0000
bf1ed41
@@ -59,6 +59,8 @@
a1088d0
  *   write_xml_string()         - Write a string with XML escaping.
8936a5c
  */
8936a5c
 
8936a5c
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
ee6b344
+
8936a5c
 /*
8936a5c
  * Include necessary headers...
8936a5c
  */
e3a2a9f
@@ -103,6 +105,10 @@ static void	write_irix_state(cupsd_print
8936a5c
 #endif /* __sgi */
cb06f24
 static void	write_xml_string(cups_file_t *fp, const char *s);
8936a5c
 
8936a5c
+#ifdef WITH_LSPP
8936a5c
+#  include <libaudit.h>
8936a5c
+#  include <selinux/context.h>
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 
8936a5c
 /*
8936a5c
  * 'cupsdAddPrinter()' - Add a printer to the system.
0b2684f
@@ -2267,6 +2273,13 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)
ca53cd4
 		  "username",
ca53cd4
 		  "password"
8936a5c
 		};
8936a5c
+#ifdef WITH_LSPP
8936a5c
+  char		*audit_message;		/* Audit message string */
8936a5c
+  char		*printerfile;		/* Path to a local printer dev */
8936a5c
+  char		*rangestr;		/* Printer's range if its available */
8936a5c
+  security_context_t	devcon;		/* Printer SELinux context */
8936a5c
+  context_t	printercon;		/* context_t for the printer */
8936a5c
+#endif /* WITH_LSPP */
8936a5c
 
8936a5c
 
8936a5c
   DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p->name,
0b2684f
@@ -2397,6 +2410,45 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)
8936a5c
       attr->values[1].string.text = _cupsStrAlloc(Classification ?
8936a5c
 	                                   Classification : p->job_sheets[1]);
8936a5c
     }
8936a5c
+#ifdef WITH_LSPP
8936a5c
+    if (AuditLog != -1)
8936a5c
+    {
8936a5c
+      audit_message = NULL;
8936a5c
+      rangestr = NULL;
8936a5c
+      printercon = 0;
8936a5c
+      printerfile = strstr(p->device_uri, "/dev/");
8936a5c
+      if (printerfile == NULL && (strncmp(p->device_uri, "file:/", 6) == 0))
08a85d3
+        printerfile = p->device_uri + strlen("file:");
4f25cbd
+
8936a5c
+      if (printerfile != NULL)
8936a5c
+      {
8936a5c
+        if (getfilecon(printerfile, &devcon) == -1)
e0e1f21
+        {
e0e1f21
+          if(is_selinux_enabled())
e0e1f21
+            cupsdLogMessage(CUPSD_LOG_ERROR, "cupsdSetPrinterAttrs: Unable to get printer context");
e0e1f21
+        }
8936a5c
+        else
8936a5c
+        {
8936a5c
+          printercon = context_new(devcon);
8936a5c
+          freecon(devcon);
8936a5c
+        }
8936a5c
+      }
e7076f3
+
8936a5c
+      if (printercon && context_range_get(printercon))
8936a5c
+        rangestr = strdup(context_range_get(printercon));
8936a5c
+      else
8936a5c
+        rangestr = strdup("unknown");
e7076f3
+
8936a5c
+      cupsdSetStringf(&audit_message, "printer=%s uri=%s banners=%s,%s range=%s",
cb06f24
+                      p->name, p->sanitized_device_uri, p->job_sheets[0], p->job_sheets[1], rangestr);
8936a5c
+      audit_log_user_message(AuditLog, AUDIT_LABEL_LEVEL_CHANGE, audit_message,
8936a5c
+                             ServerName, NULL, NULL, 1);
8936a5c
+      if (printercon)
8936a5c
+        context_free(printercon);
8936a5c
+      free(rangestr);
8936a5c
+      cupsdClearString(&audit_message);
8936a5c
+    }
8936a5c
+#endif /* WITH_LSPP */
8936a5c
   }
8936a5c
 
8936a5c
   p->raw    = 0;
0b2684f
@@ -5536,7 +5588,6 @@ write_irix_state(cupsd_printer_t *p)	/* 
cb06f24
 }
cb06f24
 #endif /* __sgi */
cb06f24
 
cb06f24
-
cb06f24
 /*
cb06f24
  * 'write_xml_string()' - Write a string with XML escaping.
cb06f24
  */