Blame SOURCES/cups-lspp.patch

87cf9a
diff -up cups-1.6.3/config.h.in.lspp cups-1.6.3/config.h.in
87cf9a
--- cups-1.6.3/config.h.in.lspp	2015-06-10 11:45:38.074441762 +0200
87cf9a
+++ cups-1.6.3/config.h.in	2015-06-10 11:45:38.158441533 +0200
87cf9a
@@ -747,6 +747,13 @@ static __inline int _cups_abs(int i) { r
87cf9a
 #  endif /* __GNUC__ || __STDC_VERSION__ */
87cf9a
 #endif /* !HAVE_ABS && !abs */
87cf9a
 
87cf9a
+/*
87cf9a
+ * Are we trying to meet LSPP requirements?
87cf9a
+ */
87cf9a
+
87cf9a
+#undef WITH_LSPP
87cf9a
+
87cf9a
+
87cf9a
 #endif /* !_CUPS_CONFIG_H_ */
87cf9a
 
87cf9a
 /*
87cf9a
diff -up cups-1.6.3/config-scripts/cups-lspp.m4.lspp cups-1.6.3/config-scripts/cups-lspp.m4
87cf9a
--- cups-1.6.3/config-scripts/cups-lspp.m4.lspp	2015-06-10 11:45:38.157441536 +0200
87cf9a
+++ cups-1.6.3/config-scripts/cups-lspp.m4	2015-06-10 11:45:38.157441536 +0200
87cf9a
@@ -0,0 +1,36 @@
87cf9a
+dnl
87cf9a
+dnl   LSPP code for the Common UNIX Printing System (CUPS).
87cf9a
+dnl
87cf9a
+dnl   Copyright 2005-2006 by Hewlett-Packard Development Company, L.P.
87cf9a
+dnl
87cf9a
+dnl   This program is free software; you can redistribute it and/or modify
87cf9a
+dnl   it under the terms of the GNU General Public License as published by
87cf9a
+dnl   the Free Software Foundation; version 2.
87cf9a
+dnl
87cf9a
+dnl   This program is distributed in the hope that it will be useful, but
87cf9a
+dnl   WITHOUT ANY WARRANTY; without even the implied warranty of
87cf9a
+dnl   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
87cf9a
+dnl   General Public License for more details.
87cf9a
+dnl
87cf9a
+dnl   You should have received a copy of the GNU General Public License
87cf9a
+dnl   along with this program; if not, write to the Free Software Foundation,
87cf9a
+dnl   Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301 USA
87cf9a
+dnl
87cf9a
+
87cf9a
+dnl Are we trying to meet LSPP requirements
87cf9a
+AC_ARG_ENABLE(lspp, [  --enable-lspp           turn on auditing and label support, default=no])
87cf9a
+
87cf9a
+if test x"$enable_lspp" != xno; then
87cf9a
+    case "$uname" in
87cf9a
+        Linux)
87cf9a
+            AC_CHECK_LIB(audit,audit_log_user_message, [LIBAUDIT="-laudit" AC_SUBST(LIBAUDIT)])
87cf9a
+            AC_CHECK_HEADER(libaudit.h)
87cf9a
+            AC_CHECK_LIB(selinux,getpeercon, [LIBSELINUX="-lselinux" AC_SUBST(LIBSELINUX)])
87cf9a
+            AC_CHECK_HEADER(selinux/selinux.h)
87cf9a
+            AC_DEFINE(WITH_LSPP)
87cf9a
+            ;;
87cf9a
+        *)
87cf9a
+            # All others
87cf9a
+            ;;
87cf9a
+    esac
87cf9a
+fi
87cf9a
diff -up cups-1.6.3/configure.in.lspp cups-1.6.3/configure.in
87cf9a
--- cups-1.6.3/configure.in.lspp	2015-06-10 11:45:38.075441759 +0200
87cf9a
+++ cups-1.6.3/configure.in	2015-06-10 11:45:38.158441533 +0200
87cf9a
@@ -37,6 +37,8 @@ sinclude(config-scripts/cups-systemd.m4)
87cf9a
 sinclude(config-scripts/cups-defaults.m4)
87cf9a
 sinclude(config-scripts/cups-scripting.m4)
87cf9a
 
87cf9a
+sinclude(config-scripts/cups-lspp.m4)
87cf9a
+
87cf9a
 INSTALL_LANGUAGES=""
87cf9a
 UNINSTALL_LANGUAGES=""
87cf9a
 LANGFILES=""
87cf9a
diff -up cups-1.6.3/data/Makefile.lspp cups-1.6.3/data/Makefile
87cf9a
--- cups-1.6.3/data/Makefile.lspp	2015-06-10 11:45:38.075441759 +0200
87cf9a
+++ cups-1.6.3/data/Makefile	2015-06-10 11:45:38.158441533 +0200
87cf9a
@@ -25,7 +25,11 @@ BANNERS	=	\
87cf9a
 		secret \
87cf9a
 		standard \
87cf9a
 		topsecret \
87cf9a
-		unclassified
87cf9a
+		unclassified \
87cf9a
+		selinux \
87cf9a
+		mls \
87cf9a
+		te
87cf9a
+
87cf9a
 
87cf9a
 DATAFILES =	\
87cf9a
 		testprint
87cf9a
diff -up cups-1.6.3/data/mls.lspp cups-1.6.3/data/mls
87cf9a
--- cups-1.6.3/data/mls.lspp	2015-06-10 11:45:38.158441533 +0200
87cf9a
+++ cups-1.6.3/data/mls	2015-06-10 11:45:38.158441533 +0200
87cf9a
@@ -0,0 +1,261 @@
87cf9a
+%!PS-Adobe-3.0
87cf9a
+%%BoundingBox: 0 0 612 792
87cf9a
+%%Pages: 1
87cf9a
+%%LanguageLevel: 1
87cf9a
+%%DocumentData: Clean7Bit
87cf9a
+%%DocumentSuppliedResources: procset bannerprint/1.0
87cf9a
+%%DocumentNeededResources: font Helvetica Helvetica-Bold Times-Roman
87cf9a
+%%Creator: Michael Sweet, Easy Software Products
87cf9a
+%%CreationDate: May 10, 2000
87cf9a
+%%Title: Test Page
87cf9a
+%%EndComments
87cf9a
+%%BeginProlog
87cf9a
+%%BeginResource procset bannerprint 1.1 0
87cf9a
+%
87cf9a
+%   PostScript banner page for the Common UNIX Printing System ("CUPS").
87cf9a
+%
87cf9a
+%   Copyright 1993-2005 by Easy Software Products
87cf9a
+%
87cf9a
+%   These coded instructions, statements, and computer programs are the
87cf9a
+%   property of Easy Software Products and are protected by Federal
87cf9a
+%   copyright law.  Distribution and use rights are outlined in the file
87cf9a
+%   "LICENSE.txt" which should have been included with this file.  If this
87cf9a
+%   file is missing or damaged please contact Easy Software Products
87cf9a
+%   at:
87cf9a
+%
87cf9a
+%       Attn: CUPS Licensing Information
87cf9a
+%       Easy Software Products
87cf9a
+%       44141 Airport View Drive, Suite 204
87cf9a
+%       Hollywood, Maryland 20636 USA
87cf9a
+%
87cf9a
+%       Voice: (301) 373-9600
87cf9a
+%       EMail: cups-info@cups.org
87cf9a
+%         WWW: http://www.cups.org
87cf9a
+%
87cf9a
+/CENTER {			% Draw centered text
87cf9a
+				% (name) CENTER -
87cf9a
+  dup stringwidth pop		% Get the width of the string
87cf9a
+  0.5 mul neg 0 rmoveto		% Shift left 1/2 of the distance
87cf9a
+  show				% Show the string
87cf9a
+} bind def
87cf9a
+/RIGHT {			% Draw right-justified text
87cf9a
+				% (name) RIGHT -
87cf9a
+  dup stringwidth pop		% Get the width of the string
87cf9a
+  neg 0 rmoveto			% Shift left the entire distance
87cf9a
+  show				% Show the string
87cf9a
+} bind def
87cf9a
+/NUMBER {			% Draw a number
87cf9a
+				% power n NUMBER -
87cf9a
+  1 index 1 eq {		% power == 1?
87cf9a
+    round cvi exch pop		% Convert "n" to integer
87cf9a
+  } {
87cf9a
+    1 index mul round exch div	% Truncate extra decimal places
87cf9a
+  } ifelse
87cf9a
+  100 string cvs show		% Convert to a string and show it...
87cf9a
+} bind def
87cf9a
+/CUPSLOGO {			% Draw the CUPS logo
87cf9a
+				% height CUPSLOGO
87cf9a
+  % Start with a big C...
87cf9a
+  /Helvetica findfont 1 index scalefont setfont
87cf9a
+  0 setgray
87cf9a
+  0 0 moveto
87cf9a
+  (C) show
87cf9a
+
87cf9a
+  % Then "UNIX Printing System" much smaller...
87cf9a
+  /Helvetica-Bold findfont 1 index 9 div scalefont setfont
87cf9a
+  0.25 mul
87cf9a
+  dup dup 2.0 mul moveto
87cf9a
+  (UNIX) show
87cf9a
+  dup dup 1.6 mul moveto
87cf9a
+  (Printing) show
87cf9a
+  dup 1.2 mul moveto
87cf9a
+  (System) show
87cf9a
+} bind def
87cf9a
+/ESPLOGO {			% Draw the ESP logo
87cf9a
+				% height ESPLOGO
87cf9a
+  % Compute the size of the logo...
87cf9a
+  0 0
87cf9a
+  2 index 1.5 mul 3 index
87cf9a
+
87cf9a
+  % Do the "metallic" fill from 10% black to 40% black...
87cf9a
+  1 -0.001 0 {
87cf9a
+    dup			% loopval
87cf9a
+    -0.15 mul		% loopval * -0.15
87cf9a
+    0.9 add		% 0.9 - loopval * 0.15
87cf9a
+    setgray		% set gray shade
87cf9a
+
87cf9a
+    0			% x
87cf9a
+    1 index neg		% loopval
87cf9a
+    1 add		% 1 - loopval
87cf9a
+    3 index		% height
87cf9a
+    mul			% height * (1 - loopval)
87cf9a
+    moveto		% starting point
87cf9a
+
87cf9a
+    dup			% loopval
87cf9a
+    3 index		% width
87cf9a
+    mul			% loopval * width
87cf9a
+    2 index		% height
87cf9a
+    lineto		% Next point
87cf9a
+
87cf9a
+    0			% x
87cf9a
+    2 index		% height
87cf9a
+    lineto		% Next point
87cf9a
+
87cf9a
+    closepath
87cf9a
+    fill
87cf9a
+
87cf9a
+    dup			% loopval
87cf9a
+    0.15 mul		% loopval * 0.15
87cf9a
+    0.6 add		% 0.6 + loopval * 0.15
87cf9a
+    setgray
87cf9a
+
87cf9a
+    dup			% loopval
87cf9a
+    neg 1 add		% 1 - loopval
87cf9a
+    3 index		% width
87cf9a
+    mul			% (1 - loopval) * width
87cf9a
+    0			% y
87cf9a
+    moveto		% Starting point
87cf9a
+
87cf9a
+    2 index		% width
87cf9a
+    exch		% loopval
87cf9a
+    2 index		% height
87cf9a
+    mul			% loopval * height
87cf9a
+    lineto		% Next point
87cf9a
+
87cf9a
+    1 index		% width
87cf9a
+    0			% y
87cf9a
+    lineto		% Next point
87cf9a
+
87cf9a
+    closepath
87cf9a
+    fill
87cf9a
+  } for
87cf9a
+
87cf9a
+  0 setgray rectstroke
87cf9a
+
87cf9a
+  /Helvetica-BoldOblique findfont 1 index 3 div scalefont setfont
87cf9a
+  dup 40 div
87cf9a
+
87cf9a
+  dup 4 mul 1 index 25 mul moveto (E) show
87cf9a
+  dup 10 mul 1 index 15 mul moveto (S) show
87cf9a
+  dup 16 mul 1 index 5 mul moveto (P) show
87cf9a
+
87cf9a
+  /Helvetica-BoldOblique findfont 2 index 5 div scalefont setfont
87cf9a
+  dup 14 mul 1 index 29 mul moveto (asy) show
87cf9a
+  dup 20 mul 1 index 19 mul moveto (oftware) show
87cf9a
+  dup 26 mul 1 index 9 mul moveto (roducts) show
87cf9a
+
87cf9a
+  pop
87cf9a
+} bind def
87cf9a
+%%EndResource
87cf9a
+%%EndProlog
87cf9a
+%%Page: 1 1
87cf9a
+gsave
87cf9a
+
87cf9a
+  % Determine the imageable area and device resolution...
87cf9a
+  initclip newpath clippath pathbbox	% Get bounding rectangle
87cf9a
+  72 div /pageTop exch def		% Get top margin in inches
87cf9a
+  72 div /pageRight exch def		% Get right margin in inches
87cf9a
+  72 div /pageBottom exch def		% Get bottom margin in inches
87cf9a
+  72 div /pageLeft exch def		% Get left margin in inches
87cf9a
+
87cf9a
+  /pageWidth pageRight pageLeft sub def	% pageWidth = pageRight - pageLeft
87cf9a
+  /pageHeight pageTop pageBottom sub def% pageHeight = pageTop - pageBottom
87cf9a
+
87cf9a
+  /boxWidth				% width of text box
87cf9a
+  pageWidth pageHeight lt
87cf9a
+  { pageWidth 54 mul }
87cf9a
+  { pageHeight 42 mul }
87cf9a
+  ifelse def
87cf9a
+
87cf9a
+  newpath				% Clear bounding path
87cf9a
+
87cf9a
+  % Create fonts...
87cf9a
+  /bigFont /Helvetica-Bold findfont	% bigFont = Helvetica-Bold
87cf9a
+  pageHeight 3 mul scalefont def	% size = pageHeight * 3 (nominally 33)
87cf9a
+
87cf9a
+  /mediumFont /Helvetica findfont	% mediumFont = Helvetica
87cf9a
+  pageHeight 1.5 mul scalefont def	% size = pageHeight * 1.5 (nominally 16.5)
87cf9a
+
87cf9a
+  % Offset page to account for lower-left margin...
87cf9a
+  pageLeft 72 mul
87cf9a
+  pageBottom 72 mul
87cf9a
+  translate
87cf9a
+
87cf9a
+  % Job information box...
87cf9a
+  pageWidth 36 mul 9 add		% x = pageWidth * 1/2 * 72 + 9
87cf9a
+  boxWidth 0.5 mul sub			% x-= 1/2 box width
87cf9a
+  pageHeight 30 mul 9 sub		% y = pageHeight * 1/2 * 72 - 9
87cf9a
+  boxWidth				% w = box width
87cf9a
+  pageHeight 14 mul			% h = pageHeight * 1/2 * 72
87cf9a
+  0.5 setgray rectfill			% Draw a shadow
87cf9a
+
87cf9a
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
87cf9a
+  boxWidth 0.5 mul sub			% x-= 1/2 box width
87cf9a
+  pageHeight 30 mul			% y = pageHeight * 1/4 * 72
87cf9a
+  boxWidth				% w = box width
87cf9a
+  pageHeight 14 mul			% h = pageHeight * 1/2 * 72
87cf9a
+
87cf9a
+  4 copy 1 setgray rectfill		% Clear the box to white
87cf9a
+  0 setgray rectstroke			% Draw a black box around it...
87cf9a
+
87cf9a
+  % Job information text...
87cf9a
+  mediumFont setfont			% Medium sized font
87cf9a
+
87cf9a
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
87cf9a
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
87cf9a
+  pageHeight 5 mul add			% y += 2 lines
87cf9a
+  2 copy				% Copy X & Y
87cf9a
+  moveto
87cf9a
+  (Job ID: ) RIGHT
87cf9a
+  moveto
87cf9a
+  ({printer-name}-{job-id}) show
87cf9a
+
87cf9a
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
87cf9a
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
87cf9a
+  pageHeight 2 mul add			% y += 1 line
87cf9a
+  2 copy				% Copy X & Y
87cf9a
+  moveto
87cf9a
+  (Title: ) RIGHT
87cf9a
+  moveto
87cf9a
+  ({job-name}) show
87cf9a
+
87cf9a
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
87cf9a
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
87cf9a
+  pageHeight -1 mul add			% y -= 1 line
87cf9a
+  2 copy				% Copy X & Y
87cf9a
+  moveto
87cf9a
+  (Requesting User: ) RIGHT
87cf9a
+  moveto
87cf9a
+  ({job-originating-user-name}) show
87cf9a
+
87cf9a
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
87cf9a
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
87cf9a
+  pageHeight -4 mul add			% y -= 2 lines
87cf9a
+  2 copy				% Copy X & Y
87cf9a
+  moveto
87cf9a
+  (Billing Info: ) RIGHT
87cf9a
+  moveto
87cf9a
+  ({?job-billing}) show
87cf9a
+
87cf9a
+  % Then the CUPS logo....
87cf9a
+  gsave
87cf9a
+    pageWidth 4 mul
87cf9a
+    pageWidth 6 mul
87cf9a
+    translate
87cf9a
+    pageWidth 9 mul CUPSLOGO
87cf9a
+  grestore
87cf9a
+
87cf9a
+  % And the ESP logo....
87cf9a
+  gsave
87cf9a
+    pageWidth 59 mul
87cf9a
+    pageWidth 6 mul
87cf9a
+    translate
87cf9a
+    pageWidth 6 mul ESPLOGO
87cf9a
+  grestore
87cf9a
+% Show the page...
87cf9a
+grestore
87cf9a
+showpage
87cf9a
+%
87cf9a
+% End of "$Id: mls_template,v 1.1 2005/06/27 18:44:46 colmo Exp $".
87cf9a
+%
87cf9a
+%%EOF
87cf9a
diff -up cups-1.6.3/data/selinux.lspp cups-1.6.3/data/selinux
87cf9a
--- cups-1.6.3/data/selinux.lspp	2015-06-10 11:45:38.158441533 +0200
87cf9a
+++ cups-1.6.3/data/selinux	2015-06-10 11:45:38.158441533 +0200
87cf9a
@@ -0,0 +1,261 @@
87cf9a
+%!PS-Adobe-3.0
87cf9a
+%%BoundingBox: 0 0 612 792
87cf9a
+%%Pages: 1
87cf9a
+%%LanguageLevel: 1
87cf9a
+%%DocumentData: Clean7Bit
87cf9a
+%%DocumentSuppliedResources: procset bannerprint/1.0
87cf9a
+%%DocumentNeededResources: font Helvetica Helvetica-Bold Times-Roman
87cf9a
+%%Creator: Michael Sweet, Easy Software Products
87cf9a
+%%CreationDate: May 10, 2000
87cf9a
+%%Title: Test Page
87cf9a
+%%EndComments
87cf9a
+%%BeginProlog
87cf9a
+%%BeginResource procset bannerprint 1.1 0
87cf9a
+%
87cf9a
+%   PostScript banner page for the Common UNIX Printing System ("CUPS").
87cf9a
+%
87cf9a
+%   Copyright 1993-2005 by Easy Software Products
87cf9a
+%
87cf9a
+%   These coded instructions, statements, and computer programs are the
87cf9a
+%   property of Easy Software Products and are protected by Federal
87cf9a
+%   copyright law.  Distribution and use rights are outlined in the file
87cf9a
+%   "LICENSE.txt" which should have been included with this file.  If this
87cf9a
+%   file is missing or damaged please contact Easy Software Products
87cf9a
+%   at:
87cf9a
+%
87cf9a
+%       Attn: CUPS Licensing Information
87cf9a
+%       Easy Software Products
87cf9a
+%       44141 Airport View Drive, Suite 204
87cf9a
+%       Hollywood, Maryland 20636 USA
87cf9a
+%
87cf9a
+%       Voice: (301) 373-9600
87cf9a
+%       EMail: cups-info@cups.org
87cf9a
+%         WWW: http://www.cups.org
87cf9a
+%
87cf9a
+/CENTER {			% Draw centered text
87cf9a
+				% (name) CENTER -
87cf9a
+  dup stringwidth pop		% Get the width of the string
87cf9a
+  0.5 mul neg 0 rmoveto		% Shift left 1/2 of the distance
87cf9a
+  show				% Show the string
87cf9a
+} bind def
87cf9a
+/RIGHT {			% Draw right-justified text
87cf9a
+				% (name) RIGHT -
87cf9a
+  dup stringwidth pop		% Get the width of the string
87cf9a
+  neg 0 rmoveto			% Shift left the entire distance
87cf9a
+  show				% Show the string
87cf9a
+} bind def
87cf9a
+/NUMBER {			% Draw a number
87cf9a
+				% power n NUMBER -
87cf9a
+  1 index 1 eq {		% power == 1?
87cf9a
+    round cvi exch pop		% Convert "n" to integer
87cf9a
+  } {
87cf9a
+    1 index mul round exch div	% Truncate extra decimal places
87cf9a
+  } ifelse
87cf9a
+  100 string cvs show		% Convert to a string and show it...
87cf9a
+} bind def
87cf9a
+/CUPSLOGO {			% Draw the CUPS logo
87cf9a
+				% height CUPSLOGO
87cf9a
+  % Start with a big C...
87cf9a
+  /Helvetica findfont 1 index scalefont setfont
87cf9a
+  0 setgray
87cf9a
+  0 0 moveto
87cf9a
+  (C) show
87cf9a
+
87cf9a
+  % Then "UNIX Printing System" much smaller...
87cf9a
+  /Helvetica-Bold findfont 1 index 9 div scalefont setfont
87cf9a
+  0.25 mul
87cf9a
+  dup dup 2.0 mul moveto
87cf9a
+  (UNIX) show
87cf9a
+  dup dup 1.6 mul moveto
87cf9a
+  (Printing) show
87cf9a
+  dup 1.2 mul moveto
87cf9a
+  (System) show
87cf9a
+} bind def
87cf9a
+/ESPLOGO {			% Draw the ESP logo
87cf9a
+				% height ESPLOGO
87cf9a
+  % Compute the size of the logo...
87cf9a
+  0 0
87cf9a
+  2 index 1.5 mul 3 index
87cf9a
+
87cf9a
+  % Do the "metallic" fill from 10% black to 40% black...
87cf9a
+  1 -0.001 0 {
87cf9a
+    dup			% loopval
87cf9a
+    -0.15 mul		% loopval * -0.15
87cf9a
+    0.9 add		% 0.9 - loopval * 0.15
87cf9a
+    setgray		% set gray shade
87cf9a
+
87cf9a
+    0			% x
87cf9a
+    1 index neg		% loopval
87cf9a
+    1 add		% 1 - loopval
87cf9a
+    3 index		% height
87cf9a
+    mul			% height * (1 - loopval)
87cf9a
+    moveto		% starting point
87cf9a
+
87cf9a
+    dup			% loopval
87cf9a
+    3 index		% width
87cf9a
+    mul			% loopval * width
87cf9a
+    2 index		% height
87cf9a
+    lineto		% Next point
87cf9a
+
87cf9a
+    0			% x
87cf9a
+    2 index		% height
87cf9a
+    lineto		% Next point
87cf9a
+
87cf9a
+    closepath
87cf9a
+    fill
87cf9a
+
87cf9a
+    dup			% loopval
87cf9a
+    0.15 mul		% loopval * 0.15
87cf9a
+    0.6 add		% 0.6 + loopval * 0.15
87cf9a
+    setgray
87cf9a
+
87cf9a
+    dup			% loopval
87cf9a
+    neg 1 add		% 1 - loopval
87cf9a
+    3 index		% width
87cf9a
+    mul			% (1 - loopval) * width
87cf9a
+    0			% y
87cf9a
+    moveto		% Starting point
87cf9a
+
87cf9a
+    2 index		% width
87cf9a
+    exch		% loopval
87cf9a
+    2 index		% height
87cf9a
+    mul			% loopval * height
87cf9a
+    lineto		% Next point
87cf9a
+
87cf9a
+    1 index		% width
87cf9a
+    0			% y
87cf9a
+    lineto		% Next point
87cf9a
+
87cf9a
+    closepath
87cf9a
+    fill
87cf9a
+  } for
87cf9a
+
87cf9a
+  0 setgray rectstroke
87cf9a
+
87cf9a
+  /Helvetica-BoldOblique findfont 1 index 3 div scalefont setfont
87cf9a
+  dup 40 div
87cf9a
+
87cf9a
+  dup 4 mul 1 index 25 mul moveto (E) show
87cf9a
+  dup 10 mul 1 index 15 mul moveto (S) show
87cf9a
+  dup 16 mul 1 index 5 mul moveto (P) show
87cf9a
+
87cf9a
+  /Helvetica-BoldOblique findfont 2 index 5 div scalefont setfont
87cf9a
+  dup 14 mul 1 index 29 mul moveto (asy) show
87cf9a
+  dup 20 mul 1 index 19 mul moveto (oftware) show
87cf9a
+  dup 26 mul 1 index 9 mul moveto (roducts) show
87cf9a
+
87cf9a
+  pop
87cf9a
+} bind def
87cf9a
+%%EndResource
87cf9a
+%%EndProlog
87cf9a
+%%Page: 1 1
87cf9a
+gsave
87cf9a
+
87cf9a
+  % Determine the imageable area and device resolution...
87cf9a
+  initclip newpath clippath pathbbox	% Get bounding rectangle
87cf9a
+  72 div /pageTop exch def		% Get top margin in inches
87cf9a
+  72 div /pageRight exch def		% Get right margin in inches
87cf9a
+  72 div /pageBottom exch def		% Get bottom margin in inches
87cf9a
+  72 div /pageLeft exch def		% Get left margin in inches
87cf9a
+
87cf9a
+  /pageWidth pageRight pageLeft sub def	% pageWidth = pageRight - pageLeft
87cf9a
+  /pageHeight pageTop pageBottom sub def% pageHeight = pageTop - pageBottom
87cf9a
+
87cf9a
+  /boxWidth				% width of text box
87cf9a
+  pageWidth pageHeight lt
87cf9a
+  { pageWidth 54 mul }
87cf9a
+  { pageHeight 42 mul }
87cf9a
+  ifelse def
87cf9a
+
87cf9a
+  newpath				% Clear bounding path
87cf9a
+
87cf9a
+  % Create fonts...
87cf9a
+  /bigFont /Helvetica-Bold findfont	% bigFont = Helvetica-Bold
87cf9a
+  pageHeight 3 mul scalefont def	% size = pageHeight * 3 (nominally 33)
87cf9a
+
87cf9a
+  /mediumFont /Helvetica findfont	% mediumFont = Helvetica
87cf9a
+  pageHeight 1.5 mul scalefont def	% size = pageHeight * 1.5 (nominally 16.5)
87cf9a
+
87cf9a
+  % Offset page to account for lower-left margin...
87cf9a
+  pageLeft 72 mul
87cf9a
+  pageBottom 72 mul
87cf9a
+  translate
87cf9a
+
87cf9a
+  % Job information box...
87cf9a
+  pageWidth 36 mul 9 add		% x = pageWidth * 1/2 * 72 + 9
87cf9a
+  boxWidth 0.5 mul sub			% x-= 1/2 box width
87cf9a
+  pageHeight 30 mul 9 sub		% y = pageHeight * 1/2 * 72 - 9
87cf9a
+  boxWidth				% w = box width
87cf9a
+  pageHeight 14 mul			% h = pageHeight * 1/2 * 72
87cf9a
+  0.5 setgray rectfill			% Draw a shadow
87cf9a
+
87cf9a
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
87cf9a
+  boxWidth 0.5 mul sub			% x-= 1/2 box width
87cf9a
+  pageHeight 30 mul			% y = pageHeight * 1/4 * 72
87cf9a
+  boxWidth				% w = box width
87cf9a
+  pageHeight 14 mul			% h = pageHeight * 1/2 * 72
87cf9a
+
87cf9a
+  4 copy 1 setgray rectfill		% Clear the box to white
87cf9a
+  0 setgray rectstroke			% Draw a black box around it...
87cf9a
+
87cf9a
+  % Job information text...
87cf9a
+  mediumFont setfont			% Medium sized font
87cf9a
+
87cf9a
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
87cf9a
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
87cf9a
+  pageHeight 5 mul add			% y += 2 lines
87cf9a
+  2 copy				% Copy X & Y
87cf9a
+  moveto
87cf9a
+  (Job ID: ) RIGHT
87cf9a
+  moveto
87cf9a
+  ({printer-name}-{job-id}) show
87cf9a
+
87cf9a
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
87cf9a
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
87cf9a
+  pageHeight 2 mul add			% y += 1 line
87cf9a
+  2 copy				% Copy X & Y
87cf9a
+  moveto
87cf9a
+  (Title: ) RIGHT
87cf9a
+  moveto
87cf9a
+  ({job-name}) show
87cf9a
+
87cf9a
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
87cf9a
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
87cf9a
+  pageHeight -1 mul add			% y -= 1 line
87cf9a
+  2 copy				% Copy X & Y
87cf9a
+  moveto
87cf9a
+  (Requesting User: ) RIGHT
87cf9a
+  moveto
87cf9a
+  ({job-originating-user-name}) show
87cf9a
+
87cf9a
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
87cf9a
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
87cf9a
+  pageHeight -4 mul add			% y -= 2 lines
87cf9a
+  2 copy				% Copy X & Y
87cf9a
+  moveto
87cf9a
+  (Billing Info: ) RIGHT
87cf9a
+  moveto
87cf9a
+  ({?job-billing}) show
87cf9a
+
87cf9a
+  % Then the CUPS logo....
87cf9a
+  gsave
87cf9a
+    pageWidth 4 mul
87cf9a
+    pageWidth 6 mul
87cf9a
+    translate
87cf9a
+    pageWidth 9 mul CUPSLOGO
87cf9a
+  grestore
87cf9a
+
87cf9a
+  % And the ESP logo....
87cf9a
+  gsave
87cf9a
+    pageWidth 59 mul
87cf9a
+    pageWidth 6 mul
87cf9a
+    translate
87cf9a
+    pageWidth 6 mul ESPLOGO
87cf9a
+  grestore
87cf9a
+% Show the page...
87cf9a
+grestore
87cf9a
+showpage
87cf9a
+%
87cf9a
+% End of "$Id: mls_template,v 1.1 2005/06/27 18:44:46 colmo Exp $".
87cf9a
+%
87cf9a
+%%EOF
87cf9a
diff -up cups-1.6.3/data/te.lspp cups-1.6.3/data/te
87cf9a
--- cups-1.6.3/data/te.lspp	2015-06-10 11:45:38.159441530 +0200
87cf9a
+++ cups-1.6.3/data/te	2015-06-10 11:45:38.159441530 +0200
87cf9a
@@ -0,0 +1,261 @@
87cf9a
+%!PS-Adobe-3.0
87cf9a
+%%BoundingBox: 0 0 612 792
87cf9a
+%%Pages: 1
87cf9a
+%%LanguageLevel: 1
87cf9a
+%%DocumentData: Clean7Bit
87cf9a
+%%DocumentSuppliedResources: procset bannerprint/1.0
87cf9a
+%%DocumentNeededResources: font Helvetica Helvetica-Bold Times-Roman
87cf9a
+%%Creator: Michael Sweet, Easy Software Products
87cf9a
+%%CreationDate: May 10, 2000
87cf9a
+%%Title: Test Page
87cf9a
+%%EndComments
87cf9a
+%%BeginProlog
87cf9a
+%%BeginResource procset bannerprint 1.1 0
87cf9a
+%
87cf9a
+%   PostScript banner page for the Common UNIX Printing System ("CUPS").
87cf9a
+%
87cf9a
+%   Copyright 1993-2005 by Easy Software Products
87cf9a
+%
87cf9a
+%   These coded instructions, statements, and computer programs are the
87cf9a
+%   property of Easy Software Products and are protected by Federal
87cf9a
+%   copyright law.  Distribution and use rights are outlined in the file
87cf9a
+%   "LICENSE.txt" which should have been included with this file.  If this
87cf9a
+%   file is missing or damaged please contact Easy Software Products
87cf9a
+%   at:
87cf9a
+%
87cf9a
+%       Attn: CUPS Licensing Information
87cf9a
+%       Easy Software Products
87cf9a
+%       44141 Airport View Drive, Suite 204
87cf9a
+%       Hollywood, Maryland 20636 USA
87cf9a
+%
87cf9a
+%       Voice: (301) 373-9600
87cf9a
+%       EMail: cups-info@cups.org
87cf9a
+%         WWW: http://www.cups.org
87cf9a
+%
87cf9a
+/CENTER {			% Draw centered text
87cf9a
+				% (name) CENTER -
87cf9a
+  dup stringwidth pop		% Get the width of the string
87cf9a
+  0.5 mul neg 0 rmoveto		% Shift left 1/2 of the distance
87cf9a
+  show				% Show the string
87cf9a
+} bind def
87cf9a
+/RIGHT {			% Draw right-justified text
87cf9a
+				% (name) RIGHT -
87cf9a
+  dup stringwidth pop		% Get the width of the string
87cf9a
+  neg 0 rmoveto			% Shift left the entire distance
87cf9a
+  show				% Show the string
87cf9a
+} bind def
87cf9a
+/NUMBER {			% Draw a number
87cf9a
+				% power n NUMBER -
87cf9a
+  1 index 1 eq {		% power == 1?
87cf9a
+    round cvi exch pop		% Convert "n" to integer
87cf9a
+  } {
87cf9a
+    1 index mul round exch div	% Truncate extra decimal places
87cf9a
+  } ifelse
87cf9a
+  100 string cvs show		% Convert to a string and show it...
87cf9a
+} bind def
87cf9a
+/CUPSLOGO {			% Draw the CUPS logo
87cf9a
+				% height CUPSLOGO
87cf9a
+  % Start with a big C...
87cf9a
+  /Helvetica findfont 1 index scalefont setfont
87cf9a
+  0 setgray
87cf9a
+  0 0 moveto
87cf9a
+  (C) show
87cf9a
+
87cf9a
+  % Then "UNIX Printing System" much smaller...
87cf9a
+  /Helvetica-Bold findfont 1 index 9 div scalefont setfont
87cf9a
+  0.25 mul
87cf9a
+  dup dup 2.0 mul moveto
87cf9a
+  (UNIX) show
87cf9a
+  dup dup 1.6 mul moveto
87cf9a
+  (Printing) show
87cf9a
+  dup 1.2 mul moveto
87cf9a
+  (System) show
87cf9a
+} bind def
87cf9a
+/ESPLOGO {			% Draw the ESP logo
87cf9a
+				% height ESPLOGO
87cf9a
+  % Compute the size of the logo...
87cf9a
+  0 0
87cf9a
+  2 index 1.5 mul 3 index
87cf9a
+
87cf9a
+  % Do the "metallic" fill from 10% black to 40% black...
87cf9a
+  1 -0.001 0 {
87cf9a
+    dup			% loopval
87cf9a
+    -0.15 mul		% loopval * -0.15
87cf9a
+    0.9 add		% 0.9 - loopval * 0.15
87cf9a
+    setgray		% set gray shade
87cf9a
+
87cf9a
+    0			% x
87cf9a
+    1 index neg		% loopval
87cf9a
+    1 add		% 1 - loopval
87cf9a
+    3 index		% height
87cf9a
+    mul			% height * (1 - loopval)
87cf9a
+    moveto		% starting point
87cf9a
+
87cf9a
+    dup			% loopval
87cf9a
+    3 index		% width
87cf9a
+    mul			% loopval * width
87cf9a
+    2 index		% height
87cf9a
+    lineto		% Next point
87cf9a
+
87cf9a
+    0			% x
87cf9a
+    2 index		% height
87cf9a
+    lineto		% Next point
87cf9a
+
87cf9a
+    closepath
87cf9a
+    fill
87cf9a
+
87cf9a
+    dup			% loopval
87cf9a
+    0.15 mul		% loopval * 0.15
87cf9a
+    0.6 add		% 0.6 + loopval * 0.15
87cf9a
+    setgray
87cf9a
+
87cf9a
+    dup			% loopval
87cf9a
+    neg 1 add		% 1 - loopval
87cf9a
+    3 index		% width
87cf9a
+    mul			% (1 - loopval) * width
87cf9a
+    0			% y
87cf9a
+    moveto		% Starting point
87cf9a
+
87cf9a
+    2 index		% width
87cf9a
+    exch		% loopval
87cf9a
+    2 index		% height
87cf9a
+    mul			% loopval * height
87cf9a
+    lineto		% Next point
87cf9a
+
87cf9a
+    1 index		% width
87cf9a
+    0			% y
87cf9a
+    lineto		% Next point
87cf9a
+
87cf9a
+    closepath
87cf9a
+    fill
87cf9a
+  } for
87cf9a
+
87cf9a
+  0 setgray rectstroke
87cf9a
+
87cf9a
+  /Helvetica-BoldOblique findfont 1 index 3 div scalefont setfont
87cf9a
+  dup 40 div
87cf9a
+
87cf9a
+  dup 4 mul 1 index 25 mul moveto (E) show
87cf9a
+  dup 10 mul 1 index 15 mul moveto (S) show
87cf9a
+  dup 16 mul 1 index 5 mul moveto (P) show
87cf9a
+
87cf9a
+  /Helvetica-BoldOblique findfont 2 index 5 div scalefont setfont
87cf9a
+  dup 14 mul 1 index 29 mul moveto (asy) show
87cf9a
+  dup 20 mul 1 index 19 mul moveto (oftware) show
87cf9a
+  dup 26 mul 1 index 9 mul moveto (roducts) show
87cf9a
+
87cf9a
+  pop
87cf9a
+} bind def
87cf9a
+%%EndResource
87cf9a
+%%EndProlog
87cf9a
+%%Page: 1 1
87cf9a
+gsave
87cf9a
+
87cf9a
+  % Determine the imageable area and device resolution...
87cf9a
+  initclip newpath clippath pathbbox	% Get bounding rectangle
87cf9a
+  72 div /pageTop exch def		% Get top margin in inches
87cf9a
+  72 div /pageRight exch def		% Get right margin in inches
87cf9a
+  72 div /pageBottom exch def		% Get bottom margin in inches
87cf9a
+  72 div /pageLeft exch def		% Get left margin in inches
87cf9a
+
87cf9a
+  /pageWidth pageRight pageLeft sub def	% pageWidth = pageRight - pageLeft
87cf9a
+  /pageHeight pageTop pageBottom sub def% pageHeight = pageTop - pageBottom
87cf9a
+
87cf9a
+  /boxWidth				% width of text box
87cf9a
+  pageWidth pageHeight lt
87cf9a
+  { pageWidth 54 mul }
87cf9a
+  { pageHeight 42 mul }
87cf9a
+  ifelse def
87cf9a
+
87cf9a
+  newpath				% Clear bounding path
87cf9a
+
87cf9a
+  % Create fonts...
87cf9a
+  /bigFont /Helvetica-Bold findfont	% bigFont = Helvetica-Bold
87cf9a
+  pageHeight 3 mul scalefont def	% size = pageHeight * 3 (nominally 33)
87cf9a
+
87cf9a
+  /mediumFont /Helvetica findfont	% mediumFont = Helvetica
87cf9a
+  pageHeight 1.5 mul scalefont def	% size = pageHeight * 1.5 (nominally 16.5)
87cf9a
+
87cf9a
+  % Offset page to account for lower-left margin...
87cf9a
+  pageLeft 72 mul
87cf9a
+  pageBottom 72 mul
87cf9a
+  translate
87cf9a
+
87cf9a
+  % Job information box...
87cf9a
+  pageWidth 36 mul 9 add		% x = pageWidth * 1/2 * 72 + 9
87cf9a
+  boxWidth 0.5 mul sub			% x-= 1/2 box width
87cf9a
+  pageHeight 30 mul 9 sub		% y = pageHeight * 1/2 * 72 - 9
87cf9a
+  boxWidth				% w = box width
87cf9a
+  pageHeight 14 mul			% h = pageHeight * 1/2 * 72
87cf9a
+  0.5 setgray rectfill			% Draw a shadow
87cf9a
+
87cf9a
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
87cf9a
+  boxWidth 0.5 mul sub			% x-= 1/2 box width
87cf9a
+  pageHeight 30 mul			% y = pageHeight * 1/4 * 72
87cf9a
+  boxWidth				% w = box width
87cf9a
+  pageHeight 14 mul			% h = pageHeight * 1/2 * 72
87cf9a
+
87cf9a
+  4 copy 1 setgray rectfill		% Clear the box to white
87cf9a
+  0 setgray rectstroke			% Draw a black box around it...
87cf9a
+
87cf9a
+  % Job information text...
87cf9a
+  mediumFont setfont			% Medium sized font
87cf9a
+
87cf9a
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
87cf9a
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
87cf9a
+  pageHeight 5 mul add			% y += 2 lines
87cf9a
+  2 copy				% Copy X & Y
87cf9a
+  moveto
87cf9a
+  (Job ID: ) RIGHT
87cf9a
+  moveto
87cf9a
+  ({printer-name}-{job-id}) show
87cf9a
+
87cf9a
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
87cf9a
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
87cf9a
+  pageHeight 2 mul add			% y += 1 line
87cf9a
+  2 copy				% Copy X & Y
87cf9a
+  moveto
87cf9a
+  (Title: ) RIGHT
87cf9a
+  moveto
87cf9a
+  ({job-name}) show
87cf9a
+
87cf9a
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
87cf9a
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
87cf9a
+  pageHeight -1 mul add			% y -= 1 line
87cf9a
+  2 copy				% Copy X & Y
87cf9a
+  moveto
87cf9a
+  (Requesting User: ) RIGHT
87cf9a
+  moveto
87cf9a
+  ({job-originating-user-name}) show
87cf9a
+
87cf9a
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
87cf9a
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
87cf9a
+  pageHeight -4 mul add			% y -= 2 lines
87cf9a
+  2 copy				% Copy X & Y
87cf9a
+  moveto
87cf9a
+  (Billing Info: ) RIGHT
87cf9a
+  moveto
87cf9a
+  ({?job-billing}) show
87cf9a
+
87cf9a
+  % Then the CUPS logo....
87cf9a
+  gsave
87cf9a
+    pageWidth 4 mul
87cf9a
+    pageWidth 6 mul
87cf9a
+    translate
87cf9a
+    pageWidth 9 mul CUPSLOGO
87cf9a
+  grestore
87cf9a
+
87cf9a
+  % And the ESP logo....
87cf9a
+  gsave
87cf9a
+    pageWidth 59 mul
87cf9a
+    pageWidth 6 mul
87cf9a
+    translate
87cf9a
+    pageWidth 6 mul ESPLOGO
87cf9a
+  grestore
87cf9a
+% Show the page...
87cf9a
+grestore
87cf9a
+showpage
87cf9a
+%
87cf9a
+% End of "$Id: mls_template,v 1.1 2005/06/27 18:44:46 colmo Exp $".
87cf9a
+%
87cf9a
+%%EOF
87cf9a
diff -up cups-1.6.3/filter/common.c.lspp cups-1.6.3/filter/common.c
87cf9a
--- cups-1.6.3/filter/common.c.lspp	2013-06-07 03:12:52.000000000 +0200
87cf9a
+++ cups-1.6.3/filter/common.c	2015-06-10 11:45:38.159441530 +0200
87cf9a
@@ -30,6 +30,12 @@
87cf9a
  * Include necessary headers...
87cf9a
  */
87cf9a
 
87cf9a
+#include "config.h"
87cf9a
+#ifdef WITH_LSPP
87cf9a
+#define _GNU_SOURCE
87cf9a
+#include <string.h>
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
 #include "common.h"
87cf9a
 #include <locale.h>
87cf9a
 
87cf9a
@@ -312,6 +318,18 @@ WriteLabelProlog(const char *label,	/* I
87cf9a
 {
87cf9a
   const char	*classification;	/* CLASSIFICATION environment variable */
87cf9a
   const char	*ptr;			/* Temporary string pointer */
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  int           i,                      /* counter */
87cf9a
+                n,                      /* counter */
87cf9a
+                lines,                  /* number of lines needed */
87cf9a
+                line_len,               /* index into tmp_label */
87cf9a
+                label_len,              /* length of the label in characters */
87cf9a
+                label_index,            /* index into the label */
87cf9a
+                longest,                /* length of the longest line */
87cf9a
+                longest_line,           /* index to the longest line */
87cf9a
+                max_width;              /* maximum width in characters */
87cf9a
+  char          **wrapped_label;        /* label with line breaks */
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
 
87cf9a
  /*
87cf9a
@@ -334,6 +352,124 @@ WriteLabelProlog(const char *label,	/* I
87cf9a
     return;
87cf9a
   }
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  if (strncmp(classification, "LSPP:", 5) == 0 && label == NULL)
87cf9a
+  {
87cf9a
+   /*
87cf9a
+    * Based on the 12pt fixed width font below determine the max_width
87cf9a
+    */
87cf9a
+    max_width = width / 8;
87cf9a
+    longest_line = 0;
87cf9a
+    longest = 0;
87cf9a
+    classification += 5; // Skip the "LSPP:"
87cf9a
+    label_len = strlen(classification);
87cf9a
+
87cf9a
+    if (label_len > max_width)
87cf9a
+    {
87cf9a
+      lines = 1 + (int)(label_len / max_width);
87cf9a
+      line_len = (int)(label_len / lines);
87cf9a
+      wrapped_label = malloc(sizeof(*wrapped_label) * lines);
87cf9a
+      label_index = i = n = 0;
87cf9a
+      while (classification[label_index])
87cf9a
+      {
87cf9a
+        if ((label_index + line_len) > label_len)
87cf9a
+          break;
87cf9a
+        switch (classification[label_index + line_len + i])
87cf9a
+        {
87cf9a
+          case ':':
87cf9a
+          case ',':
87cf9a
+          case '-':
87cf9a
+            i++;
87cf9a
+            wrapped_label[n++] = strndup(&classification[label_index], (line_len + i));
87cf9a
+            label_index += line_len + i;
87cf9a
+            i = 0;
87cf9a
+            break;
87cf9a
+          default:
87cf9a
+            i++;
87cf9a
+            break;
87cf9a
+        }
87cf9a
+        if ((i + line_len) == max_width)
87cf9a
+        {
87cf9a
+          wrapped_label[n++] = strndup(&(classification[label_index]), (line_len + i));
87cf9a
+          label_index = label_index + line_len + i;
87cf9a
+          i = 0;
87cf9a
+        }
87cf9a
+      }
87cf9a
+      wrapped_label[n] = strndup(&classification[label_index], label_len - label_index);
87cf9a
+    }
87cf9a
+    else
87cf9a
+    {
87cf9a
+      lines = 1;
87cf9a
+      wrapped_label = malloc(sizeof(*wrapped_label));
87cf9a
+      wrapped_label[0] = (char*)classification;
87cf9a
+    }
87cf9a
+
87cf9a
+    for (n = 0; n < lines; n++ )
87cf9a
+    {
87cf9a
+      printf("userdict/ESPp%c(", ('a' + n));
87cf9a
+      for (ptr = wrapped_label[n], i = 0; *ptr; ptr ++, i++)
87cf9a
+        if (*ptr < 32 || *ptr > 126)
87cf9a
+          printf("\\%03o", *ptr);
87cf9a
+        else
87cf9a
+        {
87cf9a
+          if (*ptr == '(' || *ptr == ')' || *ptr == '\\')
87cf9a
+            putchar('\\');
87cf9a
+
87cf9a
+          printf("%c", *ptr);
87cf9a
+        }
87cf9a
+      if (i > longest)
87cf9a
+      {
87cf9a
+        longest = i;
87cf9a
+        longest_line = n;
87cf9a
+      }
87cf9a
+      printf(")put\n");
87cf9a
+    }
87cf9a
+
87cf9a
+   /*
87cf9a
+    * For LSPP use a fixed width font so that line wrapping can be calculated
87cf9a
+    */
87cf9a
+
87cf9a
+    puts("userdict/ESPlf /Nimbus-Mono findfont 12 scalefont put");
87cf9a
+
87cf9a
+   /*
87cf9a
+    * Finally, the procedure to write the labels on the page...
87cf9a
+    */
87cf9a
+
87cf9a
+    printf("userdict/ESPwl{\n"
87cf9a
+           "  ESPlf setfont\n");
87cf9a
+    printf("  ESPp%c stringwidth pop dup 12 add exch -0.5 mul %.0f add\n ",
87cf9a
+           'a' + longest_line, width * 0.5f);
87cf9a
+    for (n = 1; n < lines; n++)
87cf9a
+      printf(" dup");
87cf9a
+    printf("\n  1 setgray\n");
87cf9a
+    printf("  dup 6 sub %.0f %d index %.0f ESPrf\n",
87cf9a
+           (bottom - 2.0), (2 + lines), 6.0 + (16.0 * lines));
87cf9a
+    printf("  dup 6 sub %.0f %d index %.0f ESPrf\n",
87cf9a
+           (top - 6.0 - (16.0 * lines)), (2 + lines), 4.0 + (16.0 * lines));
87cf9a
+    printf("  0 setgray\n");
87cf9a
+    printf("  dup 6 sub %.0f %d index %.0f ESPrs\n",
87cf9a
+           (bottom - 2.0), (2 + lines), 6.0 + (16.0 * lines));
87cf9a
+    printf("  dup 6 sub %.0f %d index %.0f ESPrs\n",
87cf9a
+           (top - 6.0 - (16.0 * lines)), (2 + lines), 4.0 + (16.0 * lines));
87cf9a
+    for (n = 0; n < lines; n ++)
87cf9a
+    {
87cf9a
+      printf("  dup %.0f moveto ESPp%c show\n",
87cf9a
+             bottom + 6.0 + ((lines - (n+1)) * 16.0), 'a' + n);
87cf9a
+      printf("  %.0f moveto ESPp%c show\n", top + 2.0 - ((n + 1) * 16.0), 'a' + n);
87cf9a
+    }
87cf9a
+    printf("  pop\n"
87cf9a
+           "}bind put\n");
87cf9a
+
87cf9a
+   /*
87cf9a
+    * Do some clean up at the end of the LSPP special case
87cf9a
+    */
87cf9a
+    free(wrapped_label);
87cf9a
+
87cf9a
+  }
87cf9a
+  else
87cf9a
+  {
87cf9a
+#endif /* !WITH_LSPP */
87cf9a
+  
87cf9a
  /*
87cf9a
   * Set the classification + page label string...
87cf9a
   */
87cf9a
@@ -414,7 +550,10 @@ WriteLabelProlog(const char *label,	/* I
87cf9a
   printf("  %.0f moveto ESPpl show\n", top - 14.0);
87cf9a
   puts("pop");
87cf9a
   puts("}bind put");
87cf9a
+  }
87cf9a
+#ifdef WITH_LSPP
87cf9a
 }
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
 
87cf9a
 /*
87cf9a
diff -up cups-1.6.3/filter/pstops.c.lspp cups-1.6.3/filter/pstops.c
87cf9a
--- cups-1.6.3/filter/pstops.c.lspp	2013-06-07 03:12:52.000000000 +0200
87cf9a
+++ cups-1.6.3/filter/pstops.c	2015-06-10 11:45:38.159441530 +0200
87cf9a
@@ -3202,6 +3202,18 @@ write_label_prolog(pstops_doc_t *doc,	/*
87cf9a
 {
87cf9a
   const char	*classification;	/* CLASSIFICATION environment variable */
87cf9a
   const char	*ptr;			/* Temporary string pointer */
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  int           i,                      /* counter */
87cf9a
+                n,                      /* counter */
87cf9a
+                lines,                  /* number of lines needed */
87cf9a
+                line_len,               /* index into tmp_label */
87cf9a
+                label_len,              /* length of the label in characters */
87cf9a
+                label_index,            /* index into the label */
87cf9a
+                longest,                /* length of the longest line */
87cf9a
+                longest_line,           /* index to the longest line */
87cf9a
+                max_width;              /* maximum width in characters */
87cf9a
+  char          **wrapped_label;        /* label with line breaks */
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
 
87cf9a
  /*
87cf9a
@@ -3224,6 +3236,124 @@ write_label_prolog(pstops_doc_t *doc,	/*
87cf9a
     return;
87cf9a
   }
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  if (strncmp(classification, "LSPP:", 5) == 0 && label == NULL)
87cf9a
+  {
87cf9a
+   /*
87cf9a
+    * Based on the 12pt fixed width font below determine the max_width
87cf9a
+    */
87cf9a
+    max_width = width / 8;
87cf9a
+    longest_line = 0;
87cf9a
+    longest = 0;
87cf9a
+    classification += 5; // Skip the "LSPP:"
87cf9a
+    label_len = strlen(classification);
87cf9a
+
87cf9a
+    if (label_len > max_width)
87cf9a
+    {
87cf9a
+      lines = 1 + (int)(label_len / max_width);
87cf9a
+      line_len = (int)(label_len / lines);
87cf9a
+      wrapped_label = malloc(sizeof(*wrapped_label) * lines);
87cf9a
+      label_index = i = n = 0;
87cf9a
+      while (classification[label_index])
87cf9a
+      {
87cf9a
+        if ((label_index + line_len) > label_len)
87cf9a
+          break;
87cf9a
+        switch (classification[label_index + line_len + i])
87cf9a
+        {
87cf9a
+          case ':':
87cf9a
+          case ',':
87cf9a
+          case '-':
87cf9a
+            i++;
87cf9a
+            wrapped_label[n++] = strndup(&classification[label_index], (line_len + i));
87cf9a
+            label_index += line_len + i;
87cf9a
+            i = 0;
87cf9a
+            break;
87cf9a
+          default:
87cf9a
+            i++;
87cf9a
+            break;
87cf9a
+        }
87cf9a
+        if ((i + line_len) == max_width)
87cf9a
+        {
87cf9a
+          wrapped_label[n++] = strndup(&(classification[label_index]), (line_len + i));
87cf9a
+          label_index = label_index + line_len + i;
87cf9a
+          i = 0;
87cf9a
+        }
87cf9a
+      }
87cf9a
+      wrapped_label[n] = strndup(&classification[label_index], label_len - label_index);
87cf9a
+    }
87cf9a
+    else
87cf9a
+    {
87cf9a
+      lines = 1;
87cf9a
+      wrapped_label = malloc(sizeof(*wrapped_label));
87cf9a
+      wrapped_label[0] = (char*)classification;
87cf9a
+    }
87cf9a
+
87cf9a
+    for (n = 0; n < lines; n++ )
87cf9a
+    {
87cf9a
+      printf("userdict/ESPp%c(", ('a' + n));
87cf9a
+      for (ptr = wrapped_label[n], i = 0; *ptr; ptr ++, i++)
87cf9a
+        if (*ptr < 32 || *ptr > 126)
87cf9a
+          printf("\\%03o", *ptr);
87cf9a
+        else
87cf9a
+        {
87cf9a
+          if (*ptr == '(' || *ptr == ')' || *ptr == '\\')
87cf9a
+            putchar('\\');
87cf9a
+
87cf9a
+          printf("%c", *ptr);
87cf9a
+        }
87cf9a
+      if (i > longest)
87cf9a
+      {
87cf9a
+        longest = i;
87cf9a
+        longest_line = n;
87cf9a
+      }
87cf9a
+      printf(")put\n");
87cf9a
+    }
87cf9a
+
87cf9a
+   /*
87cf9a
+    * For LSPP use a fixed width font so that line wrapping can be calculated
87cf9a
+    */
87cf9a
+
87cf9a
+    puts("userdict/ESPlf /Nimbus-Mono findfont 12 scalefont put");
87cf9a
+
87cf9a
+   /*
87cf9a
+    * Finally, the procedure to write the labels on the page...
87cf9a
+    */
87cf9a
+
87cf9a
+    printf("userdict/ESPwl{\n"
87cf9a
+           "  ESPlf setfont\n");
87cf9a
+    printf("  ESPp%c stringwidth pop dup 12 add exch -0.5 mul %.0f add\n ",
87cf9a
+           'a' + longest_line, width * 0.5f);
87cf9a
+    for (n = 1; n < lines; n++)
87cf9a
+      printf(" dup");
87cf9a
+    printf("\n  1 setgray\n");
87cf9a
+    printf("  dup 6 sub %.0f %d index %.0f ESPrf\n",
87cf9a
+           (bottom - 2.0), (2 + lines), 6.0 + (16.0 * lines));
87cf9a
+    printf("  dup 6 sub %.0f %d index %.0f ESPrf\n",
87cf9a
+           (top - 6.0 - (16.0 * lines)), (2 + lines), 4.0 + (16.0 * lines));
87cf9a
+    printf("  0 setgray\n");
87cf9a
+    printf("  dup 6 sub %.0f %d index %.0f ESPrs\n",
87cf9a
+           (bottom - 2.0), (2 + lines), 6.0 + (16.0 * lines));
87cf9a
+    printf("  dup 6 sub %.0f %d index %.0f ESPrs\n",
87cf9a
+           (top - 6.0 - (16.0 * lines)), (2 + lines), 4.0 + (16.0 * lines));
87cf9a
+    for (n = 0; n < lines; n ++)
87cf9a
+    {
87cf9a
+      printf("  dup %.0f moveto ESPp%c show\n",
87cf9a
+             bottom + 6.0 + ((lines - (n+1)) * 16.0), 'a' + n);
87cf9a
+      printf("  %.0f moveto ESPp%c show\n", top + 2.0 - ((n + 1) * 16.0), 'a' + n);
87cf9a
+    }
87cf9a
+    printf("  pop\n"
87cf9a
+           "}bind put\n");
87cf9a
+
87cf9a
+   /*
87cf9a
+    * Do some clean up at the end of the LSPP special case
87cf9a
+    */
87cf9a
+    free(wrapped_label);
87cf9a
+
87cf9a
+  }
87cf9a
+  else
87cf9a
+  {
87cf9a
+#endif /* !WITH_LSPP */
87cf9a
+
87cf9a
  /*
87cf9a
   * Set the classification + page label string...
87cf9a
   */
87cf9a
@@ -3302,7 +3432,10 @@ write_label_prolog(pstops_doc_t *doc,	/*
87cf9a
   doc_printf(doc, "  %.0f moveto ESPpl show\n", top - 14.0);
87cf9a
   doc_puts(doc, "pop\n");
87cf9a
   doc_puts(doc, "}bind put\n");
87cf9a
+  }
87cf9a
+#ifdef WITH_LSPP
87cf9a
 }
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
 
87cf9a
 /*
87cf9a
diff -up cups-1.6.3/Makedefs.in.lspp cups-1.6.3/Makedefs.in
87cf9a
--- cups-1.6.3/Makedefs.in.lspp	2015-06-10 11:45:38.075441759 +0200
87cf9a
+++ cups-1.6.3/Makedefs.in	2015-06-10 11:45:38.157441536 +0200
87cf9a
@@ -146,7 +146,7 @@ LDFLAGS		=	-L../cgi-bin -L../cups -L../f
87cf9a
 			@LDFLAGS@ @RELROFLAGS@ @PIEFLAGS@ $(OPTIM)
87cf9a
 LINKCUPS	=	@LINKCUPS@ $(LIBGSSAPI) $(SSLLIBS) $(DNSSDLIBS) $(LIBZ)
87cf9a
 LINKCUPSIMAGE	=	@LINKCUPSIMAGE@
87cf9a
-LIBS		=	$(LINKCUPS) $(COMMONLIBS)
87cf9a
+LIBS		=	$(LINKCUPS) $(COMMONLIBS) @LIBAUDIT@ @LIBSELINUX@
87cf9a
 OPTIM		=	@OPTIM@
87cf9a
 OPTIONS		=
87cf9a
 PAMLIBS		=	@PAMLIBS@
87cf9a
diff -up cups-1.6.3/scheduler/client.c.lspp cups-1.6.3/scheduler/client.c
87cf9a
--- cups-1.6.3/scheduler/client.c.lspp	2015-06-10 11:45:38.140441582 +0200
87cf9a
+++ cups-1.6.3/scheduler/client.c	2015-06-10 11:45:38.160441528 +0200
87cf9a
@@ -41,6 +41,7 @@
87cf9a
  *   valid_host()	    - Is the Host: field valid?
87cf9a
  *   write_file()	    - Send a file via HTTP.
87cf9a
  *   write_pipe()	    - Flag that data is available on the CGI pipe.
87cf9a
+ *   client_pid_to_auid()   - Get the audit login uid of the client.
87cf9a
  */
87cf9a
 
87cf9a
 /*
87cf9a
@@ -49,10 +50,16 @@
87cf9a
 
87cf9a
 #include "cupsd.h"
87cf9a
 
87cf9a
+#define _GNU_SOURCE
87cf9a
 #ifdef HAVE_TCPD_H
87cf9a
 #  include <tcpd.h>
87cf9a
 #endif /* HAVE_TCPD_H */
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+#include <selinux/selinux.h>
87cf9a
+#include <selinux/context.h>
87cf9a
+#include <fcntl.h>
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
 /*
87cf9a
  * Local globals...
87cf9a
@@ -371,6 +378,57 @@ cupsdAcceptClient(cupsd_listener_t *lis)
87cf9a
   }
87cf9a
 #endif /* HAVE_TCPD_H */
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  if (is_lspp_config())
87cf9a
+  {
87cf9a
+    struct ucred cr;
87cf9a
+    unsigned int cl=sizeof(cr);
87cf9a
+
87cf9a
+    if (getsockopt(con->http.fd, SOL_SOCKET, SO_PEERCRED, &cr, &cl) == 0)
87cf9a
+    {
87cf9a
+     /*
87cf9a
+      * client_pid_to_auid() can be racey
87cf9a
+      * In this case the pid is based on a socket connected to the client
87cf9a
+      */
87cf9a
+      if ((con->auid = client_pid_to_auid(cr.pid)) == -1)
87cf9a
+      {
87cf9a
+        close(con->http.fd);
87cf9a
+        cupsdLogMessage(CUPSD_LOG_ERROR, "cupsdAcceptClient: "
87cf9a
+                        "unable to determine client auid for client pid=%d", cr.pid);
87cf9a
+        free(con);
87cf9a
+        return;
87cf9a
+      }
87cf9a
+      cupsdLogMessage(CUPSD_LOG_INFO, "cupsdAcceptClient: peer's pid=%d, uid=%d, gid=%d, auid=%d",
87cf9a
+                      cr.pid, cr.uid, cr.gid, con->auid);
87cf9a
+    }
87cf9a
+    else
87cf9a
+    {
87cf9a
+      close(con->http.fd);
87cf9a
+      cupsdLogMessage(CUPSD_LOG_ERROR, "cupsdAcceptClient: getsockopt() failed");
87cf9a
+      free(con);
87cf9a
+      return; 
87cf9a
+    }
87cf9a
+
87cf9a
+   /*
87cf9a
+    * get the context of the peer connection
87cf9a
+    */
87cf9a
+    if (getpeercon(con->http.fd, &con->scon))
87cf9a
+    {
87cf9a
+      close(con->http.fd);
87cf9a
+      cupsdLogMessage(CUPSD_LOG_ERROR, "cupsdAcceptClient: getpeercon() failed");
87cf9a
+      free(con);
87cf9a
+      return; 
87cf9a
+    }
87cf9a
+
87cf9a
+    cupsdLogMessage(CUPSD_LOG_INFO, "cupsdAcceptClient: client context=%s", con->scon);
87cf9a
+  }
87cf9a
+  else
87cf9a
+  {
87cf9a
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdAcceptClient: skipping getpeercon()");
87cf9a
+    cupsdSetString(&con->scon, UNKNOWN_SL);
87cf9a
+  }
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
 #ifdef AF_LOCAL
87cf9a
   if (con->http.hostaddr->addr.sa_family == AF_LOCAL)
87cf9a
     cupsdLogMessage(CUPSD_LOG_DEBUG, "[Client %d] Accepted from %s (Domain)",
87cf9a
@@ -678,6 +736,13 @@ cupsdReadClient(cupsd_client_t *con)	/*
87cf9a
   mime_type_t		*type;		/* MIME type of file */
87cf9a
   cupsd_printer_t	*p;		/* Printer */
87cf9a
   static unsigned	request_id = 0;	/* Request ID for temp files */
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  security_context_t	spoolcon;	/* context of the job file */
87cf9a
+  context_t		clicon;		/* contex_t container for con->scon */
87cf9a
+  context_t		tmpcon;		/* temp context to swap the level */
87cf9a
+  char			*clirange;	/* SELinux sensitivity range */
87cf9a
+  char			*cliclearance;	/* SELinux low end clearance */
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
 
87cf9a
   status = HTTP_CONTINUE;
87cf9a
@@ -2137,6 +2202,67 @@ cupsdReadClient(cupsd_client_t *con)	/*
87cf9a
 	    fchmod(con->file, 0640);
87cf9a
 	    fchown(con->file, RunUser, Group);
87cf9a
             fcntl(con->file, F_SETFD, fcntl(con->file, F_GETFD) | FD_CLOEXEC);
87cf9a
+#ifdef WITH_LSPP
87cf9a
+	    if (strncmp(con->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) != 0)
87cf9a
+	    {
87cf9a
+	      if (getfilecon(con->filename, &spoolcon) == -1)
87cf9a
+	      {
87cf9a
+		cupsdSendError(con, HTTP_SERVER_ERROR, CUPSD_AUTH_NONE);
87cf9a
+		return (cupsdCloseClient(con));
87cf9a
+	      }
87cf9a
+	      clicon = context_new(con->scon);
87cf9a
+	      tmpcon = context_new(spoolcon);
87cf9a
+	      freecon(spoolcon);
87cf9a
+	      if (!clicon || !tmpcon)
87cf9a
+	      {
87cf9a
+		cupsdSendError(con, HTTP_SERVER_ERROR, CUPSD_AUTH_NONE);
87cf9a
+		if (clicon)
87cf9a
+		  context_free(clicon);
87cf9a
+		if (tmpcon)
87cf9a
+		  context_free(tmpcon);
87cf9a
+		return (cupsdCloseClient(con));
87cf9a
+	      }
87cf9a
+	      clirange = context_range_get(clicon);
87cf9a
+	      if (clirange)
87cf9a
+	      {
87cf9a
+		clirange = strdup(clirange);
87cf9a
+		if ((cliclearance = strtok(clirange, "-")) != NULL)
87cf9a
+		{
87cf9a
+		  if (context_range_set(tmpcon, cliclearance) == -1)
87cf9a
+		  {
87cf9a
+		    cupsdSendError(con, HTTP_SERVER_ERROR, CUPSD_AUTH_NONE);
87cf9a
+		    free(clirange);
87cf9a
+		    context_free(tmpcon);
87cf9a
+		    context_free(clicon);
87cf9a
+		    return (cupsdCloseClient(con));
87cf9a
+		  }
87cf9a
+		}
87cf9a
+		else
87cf9a
+		{
87cf9a
+		  if (context_range_set(tmpcon, (context_range_get(clicon))) == -1)
87cf9a
+		  {
87cf9a
+		    cupsdSendError(con, HTTP_SERVER_ERROR, CUPSD_AUTH_NONE);
87cf9a
+		    free(clirange);
87cf9a
+		    context_free(tmpcon);
87cf9a
+		    context_free(clicon);
87cf9a
+		    return (cupsdCloseClient(con));
87cf9a
+		  }
87cf9a
+		}
87cf9a
+		free(clirange);
87cf9a
+	      }
87cf9a
+	      if (setfilecon(con->filename, context_str(tmpcon)) == -1)
87cf9a
+	      {
87cf9a
+		cupsdSendError(con, HTTP_SERVER_ERROR, CUPSD_AUTH_NONE);
87cf9a
+		context_free(tmpcon);
87cf9a
+		context_free(clicon);
87cf9a
+		return (cupsdCloseClient(con));
87cf9a
+	      }
87cf9a
+	      cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdReadClient: %s set to %s", 
87cf9a
+			      con->filename, context_str(tmpcon));
87cf9a
+	      context_free(tmpcon);
87cf9a
+	      context_free(clicon);
87cf9a
+	    }
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 	  }
87cf9a
 
87cf9a
 	  if (con->http.state != HTTP_POST_SEND)
87cf9a
@@ -3647,6 +3773,49 @@ is_path_absolute(const char *path)	/* I
87cf9a
   return (1);
87cf9a
 }
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+/*
87cf9a
+ * 'client_pid_to_auid()' - Using the client's pid, read /proc and determine the loginuid.
87cf9a
+ */
87cf9a
+
87cf9a
+uid_t client_pid_to_auid(pid_t clipid)
87cf9a
+{
87cf9a
+  uid_t uid;
87cf9a
+  int len, in;
87cf9a
+  char buf[16] = {0};
87cf9a
+  char fname[32] = {0};
87cf9a
+
87cf9a
+
87cf9a
+ /*
87cf9a
+  * Hopefully this pid is still the one we are interested in.
87cf9a
+  */
87cf9a
+  snprintf(fname, 32, "/proc/%d/loginuid", clipid);
87cf9a
+  in = open(fname, O_NOFOLLOW|O_RDONLY);
87cf9a
+
87cf9a
+  if (in < 0)
87cf9a
+    return -1;
87cf9a
+
87cf9a
+  errno = 0;
87cf9a
+
87cf9a
+  do {
87cf9a
+    len = read(in, buf, sizeof(buf));
87cf9a
+  } while (len < 0 && errno == EINTR);
87cf9a
+
87cf9a
+  close(in);
87cf9a
+
87cf9a
+  if (len < 0 || len >= sizeof(buf))
87cf9a
+    return -1;
87cf9a
+
87cf9a
+  errno = 0;
87cf9a
+  buf[len] = 0;
87cf9a
+  uid = strtol(buf, 0, 10);
87cf9a
+
87cf9a
+  if (errno != 0)
87cf9a
+    return -1;
87cf9a
+  else
87cf9a
+    return uid;
87cf9a
+}
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
 /*
87cf9a
  * 'pipe_command()' - Pipe the output of a command to the remote client.
87cf9a
diff -up cups-1.6.3/scheduler/client.h.lspp cups-1.6.3/scheduler/client.h
87cf9a
--- cups-1.6.3/scheduler/client.h.lspp	2015-06-10 11:45:38.076441756 +0200
87cf9a
+++ cups-1.6.3/scheduler/client.h	2015-06-10 11:45:38.160441528 +0200
87cf9a
@@ -18,6 +18,13 @@
87cf9a
 #endif /* HAVE_AUTHORIZATION_H */
87cf9a
 
87cf9a
 
87cf9a
+/* Copyright (C) 2005 Trusted Computer Solutions, Inc. */
87cf9a
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
87cf9a
+
87cf9a
+#ifdef WITH_LSPP
87cf9a
+#include <selinux/selinux.h>
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
 /*
87cf9a
  * HTTP client structure...
87cf9a
  */
87cf9a
@@ -63,6 +70,10 @@ struct cupsd_client_s
87cf9a
 #ifdef HAVE_AUTHORIZATION_H
87cf9a
   AuthorizationRef	authref;	/* Authorization ref */
87cf9a
 #endif /* HAVE_AUTHORIZATION_H */
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  security_context_t	scon;		/* Security context of connection */
87cf9a
+  uid_t			auid;		/* Audit loginuid of the client */
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 };
87cf9a
 
87cf9a
 #define HTTP(con) &((con)->http)
87cf9a
@@ -135,6 +146,9 @@ extern void	cupsdStartListening(void);
87cf9a
 extern void	cupsdStopListening(void);
87cf9a
 extern void	cupsdUpdateCGI(void);
87cf9a
 extern void	cupsdWriteClient(cupsd_client_t *con);
87cf9a
+#ifdef WITH_LSPP
87cf9a
+extern uid_t	client_pid_to_auid(pid_t clipid);
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
 #ifdef HAVE_SSL
87cf9a
 extern int	cupsdEndTLS(cupsd_client_t *con);
87cf9a
diff -up cups-1.6.3/scheduler/conf.c.lspp cups-1.6.3/scheduler/conf.c
87cf9a
--- cups-1.6.3/scheduler/conf.c.lspp	2015-06-10 11:45:38.140441582 +0200
87cf9a
+++ cups-1.6.3/scheduler/conf.c	2015-06-10 11:45:38.161441525 +0200
87cf9a
@@ -34,6 +34,7 @@
87cf9a
  *   read_location()	      - Read a <Location path> definition.
87cf9a
  *   read_policy()	      - Read a <Policy name> definition.
87cf9a
  *   set_policy_defaults()    - Set default policy values as needed.
87cf9a
+ *   is_lspp_config()         - Is the system configured for LSPP
87cf9a
  */
87cf9a
 
87cf9a
 /*
87cf9a
@@ -59,6 +60,9 @@
87cf9a
 #  define INADDR_NONE	0xffffffff
87cf9a
 #endif /* !INADDR_NONE */
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+#  include <libaudit.h>
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
 /*
87cf9a
  * Configuration variable structure...
87cf9a
@@ -146,6 +150,10 @@ static const cupsd_var_t	cupsd_vars[] =
87cf9a
   { "ServerName",		&ServerName,		CUPSD_VARTYPE_STRING },
87cf9a
   { "StrictConformance",	&StrictConformance,	CUPSD_VARTYPE_BOOLEAN },
87cf9a
   { "Timeout",			&Timeout,		CUPSD_VARTYPE_TIME },
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  { "AuditLog",			&AuditLog,		CUPSD_VARTYPE_INTEGER },
87cf9a
+  { "PerPageLabels",		&PerPageLabels,		CUPSD_VARTYPE_BOOLEAN },
87cf9a
+#endif /* WITH_LSPP */
87cf9a
   { "WebInterface",		&WebInterface,		CUPSD_VARTYPE_BOOLEAN }
87cf9a
 };
87cf9a
 static const cupsd_var_t	cupsfiles_vars[] =
87cf9a
@@ -546,6 +554,9 @@ cupsdReadConfiguration(void)
87cf9a
   const char	*tmpdir;		/* TMPDIR environment variable */
87cf9a
   struct stat	tmpinfo;		/* Temporary directory info */
87cf9a
   cupsd_policy_t *p;			/* Policy */
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  char		*audit_message;		/* Audit message string */
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
 
87cf9a
  /*
87cf9a
@@ -853,6 +864,25 @@ cupsdReadConfiguration(void)
87cf9a
 
87cf9a
   RunUser = getuid();
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  if (AuditLog != -1)
87cf9a
+  {
87cf9a
+   /*
87cf9a
+    * ClassifyOverride is set during read_configuration, if its ON, report it now
87cf9a
+    */
87cf9a
+    if (ClassifyOverride)
87cf9a
+      audit_log_user_message(AuditLog, AUDIT_USYS_CONFIG,
87cf9a
+                "[Config] ClassifyOverride=enabled Users can override print banners",
87cf9a
+                ServerName, NULL, NULL, 1);
87cf9a
+   /*
87cf9a
+    * PerPageLabel is set during read_configuration, if its OFF, report it now
87cf9a
+    */
87cf9a
+    if (!PerPageLabels)
87cf9a
+      audit_log_user_message(AuditLog, AUDIT_USYS_CONFIG,
87cf9a
+                "[Config] PerPageLabels=disabled", ServerName, NULL, NULL, 1);
87cf9a
+  }
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
   cupsdLogMessage(CUPSD_LOG_INFO, "Remote access is %s.",
87cf9a
                   RemotePort ? "enabled" : "disabled");
87cf9a
 
87cf9a
@@ -1255,7 +1285,19 @@ cupsdReadConfiguration(void)
87cf9a
     cupsdClearString(&Classification);
87cf9a
 
87cf9a
   if (Classification)
87cf9a
+  {
87cf9a
     cupsdLogMessage(CUPSD_LOG_INFO, "Security set to \"%s\"", Classification);
87cf9a
+#ifdef WITH_LSPP
87cf9a
+    if (AuditLog != -1)
87cf9a
+    {
87cf9a
+      audit_message = NULL;
87cf9a
+      cupsdSetStringf(&audit_message, "[Config] Classification=%s", Classification);
87cf9a
+      audit_log_user_message(AuditLog, AUDIT_LABEL_LEVEL_CHANGE, audit_message,
87cf9a
+                             ServerName, NULL, NULL, 1);
87cf9a
+      cupsdClearString(&audit_message);
87cf9a
+    }
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+  }
87cf9a
 
87cf9a
  /*
87cf9a
   * Check the MaxClients setting, and then allocate memory for it...
87cf9a
@@ -3641,6 +3683,18 @@ read_location(cups_file_t *fp,		/* I - C
87cf9a
   return ((FatalErrors & CUPSD_FATAL_CONFIG) ? 0 : linenum);
87cf9a
 }
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+int is_lspp_config()
87cf9a
+{
87cf9a
+  if (Classification != NULL)
87cf9a
+    return ((_cups_strcasecmp(Classification, MLS_CONFIG) == 0) 
87cf9a
+            || (_cups_strcasecmp(Classification, TE_CONFIG) == 0)
87cf9a
+            || (_cups_strcasecmp(Classification, SELINUX_CONFIG) == 0));
87cf9a
+  else
87cf9a
+    return 0;
87cf9a
+}
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
 
87cf9a
 /*
87cf9a
  * 'read_policy()' - Read a <Policy name> definition.
87cf9a
diff -up cups-1.6.3/scheduler/conf.h.lspp cups-1.6.3/scheduler/conf.h
87cf9a
--- cups-1.6.3/scheduler/conf.h.lspp	2015-06-10 11:45:38.108441669 +0200
87cf9a
+++ cups-1.6.3/scheduler/conf.h	2015-06-10 11:45:38.161441525 +0200
87cf9a
@@ -251,6 +251,13 @@ VAR int			SSLOptions		VALUE(CUPSD_SSL_NO
87cf9a
 					/* SSL/TLS options */
87cf9a
 #endif /* HAVE_SSL */
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+VAR int			AuditLog		VALUE(-1),
87cf9a
+					/* File descriptor for audit */
87cf9a
+			PerPageLabels		VALUE(TRUE);
87cf9a
+					/* Put the label on each page */
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
 #ifdef HAVE_LAUNCHD
87cf9a
 VAR int			LaunchdTimeout		VALUE(10);
87cf9a
 					/* Time after which an idle cupsd will exit */
87cf9a
@@ -269,6 +276,9 @@ int			HaveServerCreds		VALUE(0);
87cf9a
 gss_cred_id_t		ServerCreds;	/* Server's GSS credentials */
87cf9a
 #endif /* HAVE_GSSAPI */
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+extern int		is_lspp_config(void);
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
 /*
87cf9a
  * Prototypes...
87cf9a
diff -up cups-1.6.3/scheduler/cupsd.h.lspp cups-1.6.3/scheduler/cupsd.h
87cf9a
--- cups-1.6.3/scheduler/cupsd.h.lspp	2015-06-10 11:45:38.093441710 +0200
87cf9a
+++ cups-1.6.3/scheduler/cupsd.h	2015-06-10 11:45:38.161441525 +0200
87cf9a
@@ -13,6 +13,8 @@
87cf9a
  *   file is missing or damaged, see the license at "http://www.cups.org/".
87cf9a
  */
87cf9a
 
87cf9a
+/* Copyright (C) 2005 Trusted Computer Solutions, Inc. */
87cf9a
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
87cf9a
 
87cf9a
 /*
87cf9a
  * Include necessary headers.
87cf9a
@@ -37,13 +39,20 @@
87cf9a
 #  include <unistd.h>
87cf9a
 #endif /* WIN32 */
87cf9a
 
87cf9a
+#include "config.h"
87cf9a
+#ifdef WITH_LSPP
87cf9a
+#  define MLS_CONFIG "mls"
87cf9a
+#  define TE_CONFIG "te"
87cf9a
+#  define SELINUX_CONFIG "SELinux"
87cf9a
+#  define UNKNOWN_SL "UNKNOWN SL"
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
 #include "mime.h"
87cf9a
 
87cf9a
 #if defined(HAVE_CDSASSL)
87cf9a
 #  include <CoreFoundation/CoreFoundation.h>
87cf9a
 #endif /* HAVE_CDSASSL */
87cf9a
 
87cf9a
-
87cf9a
 /*
87cf9a
  * Some OS's don't have hstrerror(), most notably Solaris...
87cf9a
  */
87cf9a
diff -up cups-1.6.3/scheduler/ipp.c.lspp cups-1.6.3/scheduler/ipp.c
87cf9a
--- cups-1.6.3/scheduler/ipp.c.lspp	2015-06-10 11:45:38.155441541 +0200
87cf9a
+++ cups-1.6.3/scheduler/ipp.c	2015-06-10 11:46:28.871303698 +0200
87cf9a
@@ -35,6 +35,7 @@
87cf9a
  *   cancel_all_jobs()           - Cancel all or selected print jobs.
87cf9a
  *   cancel_job()                - Cancel a print job.
87cf9a
  *   cancel_subscription()       - Cancel a subscription.
87cf9a
+ *   check_context()             - Check the SELinux context for a user and job
87cf9a
  *   check_rss_recipient()       - Check that we do not have a duplicate RSS
87cf9a
  *                                 feed URI.
87cf9a
  *   check_quotas()              - Check quotas for a printer and user.
87cf9a
@@ -99,6 +100,9 @@
87cf9a
  *   validate_user()             - Validate the user for the request.
87cf9a
  */
87cf9a
 
87cf9a
+/* Copyright (C) 2005 Trusted Computer Solutions, Inc. */
87cf9a
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
87cf9a
+
87cf9a
 /*
87cf9a
  * Include necessary headers...
87cf9a
  */
87cf9a
@@ -122,6 +126,14 @@ extern int mbr_check_membership_by_id(uu
87cf9a
 #  endif /* HAVE_MEMBERSHIPPRIV_H */
87cf9a
 #endif /* __APPLE__ */
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+#include <libaudit.h>
87cf9a
+#include <selinux/selinux.h>
87cf9a
+#include <selinux/context.h>
87cf9a
+#include <selinux/avc.h>
87cf9a
+#include <selinux/flask.h>
87cf9a
+#include <selinux/av_permissions.h>
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
 /*
87cf9a
  * Local functions...
87cf9a
@@ -146,6 +158,9 @@ static void	cancel_all_jobs(cupsd_client
87cf9a
 static void	cancel_job(cupsd_client_t *con, ipp_attribute_t *uri);
87cf9a
 static void	cancel_subscription(cupsd_client_t *con, int id);
87cf9a
 static int	check_rss_recipient(const char *recipient);
87cf9a
+#ifdef WITH_LSPP
87cf9a
+static int	check_context(cupsd_client_t *con, cupsd_job_t *job);
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 static int	check_quotas(cupsd_client_t *con, cupsd_printer_t *p);
87cf9a
 static void	close_job(cupsd_client_t *con, ipp_attribute_t *uri);
87cf9a
 static void	copy_attrs(ipp_t *to, ipp_t *from, cups_array_t *ra,
87cf9a
@@ -1299,6 +1314,21 @@ add_job(cupsd_client_t  *con,		/* I - Cl
87cf9a
     "time-at-creation",
87cf9a
     "time-at-processing"
87cf9a
   };
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  char		*audit_message;		/* Audit message string */
87cf9a
+  char		*printerfile;		/* device file pointed to by the printer */
87cf9a
+  char		*userheader = NULL;	/* User supplied job-sheets[0] */
87cf9a
+  char		*userfooter = NULL;	/* User supplied job-sheets[1] */
87cf9a
+  int		override = 0;		/* Was a banner overrode on a job */
87cf9a
+  security_id_t	clisid;			/* SELinux SID for the client */
87cf9a
+  security_id_t	psid;			/* SELinux SID for the printer */
87cf9a
+  context_t	printercon;		/* Printer's context string */
87cf9a
+  struct stat	printerstat;		/* Printer's stat buffer */
87cf9a
+  security_context_t	devcon;		/* Printer's SELinux context */
87cf9a
+  struct avc_entry_ref	avcref;		/* Pointer to the access vector cache */
87cf9a
+  security_class_t	tclass;		/* Object class for the SELinux check */
87cf9a
+  access_vector_t	avr;		/* Access method being requested */
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
 
87cf9a
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_job(%p[%d], %p(%s), %p(%s/%s))",
87cf9a
@@ -1639,6 +1669,106 @@ add_job(cupsd_client_t  *con,		/* I - Cl
87cf9a
     }
87cf9a
   }
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  if (is_lspp_config())
87cf9a
+  {
87cf9a
+    if (!con->scon || strncmp(con->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) == 0)
87cf9a
+    {
87cf9a
+      cupsdLogMessage(CUPSD_LOG_ERROR, "add_job: missing classification for connection \'%s\'!", printer->name);
87cf9a
+      send_ipp_status(con, IPP_INTERNAL_ERROR, _("Missing required security attributes."));
87cf9a
+      return (NULL);
87cf9a
+    }
87cf9a
+
87cf9a
+   /*
87cf9a
+    * Perform an access check so that if the user gets feedback at enqueue time
87cf9a
+    */
87cf9a
+
87cf9a
+    printerfile = strstr(printer->device_uri, "/dev/");
87cf9a
+    if (printerfile == NULL && (strncmp(printer->device_uri, "file:/", 6) == 0))
87cf9a
+      printerfile = printer->device_uri + strlen("file:");
87cf9a
+
87cf9a
+    if (printerfile != NULL)
87cf9a
+    {
87cf9a
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "add_job: Attempting an access check on printer device %s",
87cf9a
+                      printerfile);
87cf9a
+
87cf9a
+      if (lstat(printerfile, &printerstat) < 0)
87cf9a
+      {
87cf9a
+	if (errno != ENOENT)
87cf9a
+	{
87cf9a
+	  send_ipp_status(con, IPP_NOT_AUTHORIZED, _("Unable to stat the printer"));
87cf9a
+	  return (NULL);
87cf9a
+	}
87cf9a
+	/*
87cf9a
+	 * The printer does not exist, so for now assume it's a FileDevice
87cf9a
+	 */
87cf9a
+	tclass = SECCLASS_FILE;
87cf9a
+	avr = FILE__WRITE;
87cf9a
+      }
87cf9a
+      else if (S_ISCHR(printerstat.st_mode))
87cf9a
+      {
87cf9a
+	tclass = SECCLASS_CHR_FILE;
87cf9a
+	avr = CHR_FILE__WRITE;
87cf9a
+      }
87cf9a
+      else if (S_ISREG(printerstat.st_mode))
87cf9a
+      {
87cf9a
+	tclass = SECCLASS_FILE;
87cf9a
+	avr = FILE__WRITE;
87cf9a
+      }
87cf9a
+      else
87cf9a
+      {
87cf9a
+	send_ipp_status(con, IPP_NOT_AUTHORIZED, _("Printer is not a character device or regular file"));
87cf9a
+	return (NULL);
87cf9a
+      }
87cf9a
+      static avc_initialized = 0;
87cf9a
+      if (!avc_initialized++)
87cf9a
+          avc_init("cupsd_enqueue_", NULL, NULL, NULL, NULL);
87cf9a
+      avc_entry_ref_init(&avcref);
87cf9a
+      if (avc_context_to_sid(con->scon, &clisid) != 0)
87cf9a
+      {
87cf9a
+        send_ipp_status(con, IPP_NOT_AUTHORIZED, _("Unable to get the SELinux sid of the client"));
87cf9a
+        return (NULL);
87cf9a
+      }
87cf9a
+      if (getfilecon(printerfile, &devcon) == -1)
87cf9a
+      {
87cf9a
+        send_ipp_status(con, IPP_NOT_AUTHORIZED, _("Unable to get the SELinux context of the printer"));
87cf9a
+        return (NULL);
87cf9a
+      }
87cf9a
+      printercon = context_new(devcon);
87cf9a
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "add_job: printer context %s client context %s",
87cf9a
+                      context_str(printercon), con->scon);
87cf9a
+      context_free(printercon);
87cf9a
+
87cf9a
+      if (avc_context_to_sid(devcon, &psid) != 0)
87cf9a
+      {
87cf9a
+        send_ipp_status(con, IPP_NOT_AUTHORIZED, _("Unable to get the SELinux sid of the printer"));
87cf9a
+        freecon(devcon);
87cf9a
+        return (NULL);
87cf9a
+      }
87cf9a
+      freecon(devcon);
87cf9a
+      if (avc_has_perm(clisid, psid, tclass, avr, &avcref, NULL) != 0)
87cf9a
+      {
87cf9a
+       /*
87cf9a
+        * The access check failed, so cancel the job and send an audit message
87cf9a
+        */
87cf9a
+        if (AuditLog != -1)
87cf9a
+        {
87cf9a
+          audit_message = NULL;
87cf9a
+          cupsdSetStringf(&audit_message, "job=? auid=%u acct=%s obj=%s refused"
87cf9a
+                          " unable to access printer=%s", con->auid,
87cf9a
+                          con->username, con->scon, printer->name);
87cf9a
+          audit_log_user_message(AuditLog, AUDIT_USER_LABELED_EXPORT, audit_message,
87cf9a
+                                 ServerName, NULL, NULL, 0);
87cf9a
+          cupsdClearString(&audit_message);
87cf9a
+        }
87cf9a
+
87cf9a
+        send_ipp_status(con, IPP_NOT_AUTHORIZED, _("SELinux prohibits access to the printer"));
87cf9a
+        return (NULL);
87cf9a
+      }
87cf9a
+    }
87cf9a
+  }
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
   if ((job = cupsdAddJob(priority, printer->name)) == NULL)
87cf9a
   {
87cf9a
     send_ipp_status(con, IPP_INTERNAL_ERROR,
87cf9a
@@ -1647,6 +1777,32 @@ add_job(cupsd_client_t  *con,		/* I - Cl
87cf9a
     return (NULL);
87cf9a
   }
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  if (is_lspp_config())
87cf9a
+  {
87cf9a
+   /*
87cf9a
+    * duplicate the security context and auid of the connection into the job structure
87cf9a
+    */
87cf9a
+    job->scon = strdup(con->scon);
87cf9a
+    job->auid = con->auid;
87cf9a
+
87cf9a
+   /* 
87cf9a
+    * add the security context to the request so that on a restart the security
87cf9a
+    * attributes will be able to be restored
87cf9a
+    */
87cf9a
+    ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "security-context", 
87cf9a
+		 NULL, job->scon);
87cf9a
+  }
87cf9a
+  else
87cf9a
+  {
87cf9a
+   /*
87cf9a
+    * Fill in the security context of the job as unlabeled
87cf9a
+    */
87cf9a
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "add_job: setting context of job to %s", UNKNOWN_SL);
87cf9a
+    cupsdSetString(&job->scon, UNKNOWN_SL);
87cf9a
+  }
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
   job->dtype   = printer->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_REMOTE);
87cf9a
   job->attrs   = con->request;
87cf9a
   job->dirty   = 1;
87cf9a
@@ -1818,6 +1974,29 @@ add_job(cupsd_client_t  *con,		/* I - Cl
87cf9a
       ippSetString(job->attrs, &attr, 0, printer->job_sheets[0]);
87cf9a
       ippSetString(job->attrs, &attr, 1, printer->job_sheets[1]);
87cf9a
     }
87cf9a
+#ifdef WITH_LSPP
87cf9a
+    else
87cf9a
+    {
87cf9a
+     /*
87cf9a
+      * The option was present, so capture the user supplied strings
87cf9a
+      */
87cf9a
+      userheader = strdup(attr->values[0].string.text);
87cf9a
+
87cf9a
+      if (attr->num_values > 1)
87cf9a
+        userfooter = strdup(attr->values[1].string.text);
87cf9a
+
87cf9a
+      if (Classification != NULL && (strcmp(userheader, Classification) == 0)
87cf9a
+          && userfooter &&(strcmp(userfooter, Classification) == 0))
87cf9a
+      {
87cf9a
+       /*
87cf9a
+        * Since both values are Classification, the user is not trying to Override
87cf9a
+        */
87cf9a
+        free(userheader);
87cf9a
+        if (userfooter) free(userfooter);
87cf9a
+        userheader = userfooter = NULL;
87cf9a
+      }
87cf9a
+    }
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
     job->job_sheets = attr;
87cf9a
 
87cf9a
@@ -1848,6 +2027,9 @@ add_job(cupsd_client_t  *con,		/* I - Cl
87cf9a
 	                		     "job-sheets=\"%s,none\", "
87cf9a
 					     "job-originating-user-name=\"%s\"",
87cf9a
 	              Classification, job->username);
87cf9a
+#ifdef WITH_LSPP
87cf9a
+	  override = 1;
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 	}
87cf9a
 	else if (attr->num_values == 2 &&
87cf9a
 	         strcmp(attr->values[0].string.text,
87cf9a
@@ -1866,6 +2048,9 @@ add_job(cupsd_client_t  *con,		/* I - Cl
87cf9a
 					     "job-originating-user-name=\"%s\"",
87cf9a
 		      attr->values[0].string.text,
87cf9a
 		      attr->values[1].string.text, job->username);
87cf9a
+#ifdef WITH_LSPP
87cf9a
+	  override = 1;
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 	}
87cf9a
 	else if (strcmp(attr->values[0].string.text, Classification) &&
87cf9a
 	         strcmp(attr->values[0].string.text, "none") &&
87cf9a
@@ -1886,6 +2071,9 @@ add_job(cupsd_client_t  *con,		/* I - Cl
87cf9a
 			"job-originating-user-name=\"%s\"",
87cf9a
 			attr->values[0].string.text,
87cf9a
 			attr->values[1].string.text, job->username);
87cf9a
+#ifdef WITH_LSPP
87cf9a
+	  override = 1;
87cf9a
+#endif /* WITH_LSPP */
87cf9a
         }
87cf9a
       }
87cf9a
       else if (strcmp(attr->values[0].string.text, Classification) &&
87cf9a
@@ -1926,8 +2114,52 @@ add_job(cupsd_client_t  *con,		/* I - Cl
87cf9a
 		      "job-sheets=\"%s\", "
87cf9a
 		      "job-originating-user-name=\"%s\"",
87cf9a
 		      Classification, job->username);
87cf9a
+#ifdef WITH_LSPP
87cf9a
+	override = 1;
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+      }
87cf9a
+#ifdef WITH_LSPP
87cf9a
+      if (is_lspp_config() && AuditLog != -1)
87cf9a
+      {
87cf9a
+        audit_message = NULL;
87cf9a
+
87cf9a
+        if (userheader || userfooter)
87cf9a
+        {
87cf9a
+          if (!override)
87cf9a
+          {
87cf9a
+           /*
87cf9a
+            * The user overrode the banner, so audit it
87cf9a
+            */
87cf9a
+            cupsdSetStringf(&audit_message, "job=%d user supplied job-sheets=%s,%s"
87cf9a
+                            " using banners=%s,%s", job->id, userheader,
87cf9a
+                            userfooter, attr->values[0].string.text,
87cf9a
+                            (attr->num_values > 1) ? attr->values[1].string.text : "(null)");
87cf9a
+            audit_log_user_message(AuditLog, AUDIT_LABEL_OVERRIDE, audit_message,
87cf9a
+                                   ServerName, NULL, NULL, 1);
87cf9a
+	  }
87cf9a
+          else
87cf9a
+          {
87cf9a
+           /*
87cf9a
+            * The user tried to override the banner, audit the failure
87cf9a
+            */
87cf9a
+            cupsdSetStringf(&audit_message, "job=%d user supplied job-sheets=%s,%s"
87cf9a
+                            " ignored banners=%s,%s", job->id, userheader,
87cf9a
+                            userfooter, attr->values[0].string.text,
87cf9a
+                            (attr->num_values > 1) ? attr->values[1].string.text : "(null)");
87cf9a
+            audit_log_user_message(AuditLog, AUDIT_LABEL_OVERRIDE, audit_message,
87cf9a
+                                   ServerName, NULL, NULL, 0);
87cf9a
+	  }
87cf9a
+          cupsdClearString(&audit_message);
87cf9a
+	}
87cf9a
       }
87cf9a
+
87cf9a
+      if (userheader)
87cf9a
+        free(userheader);
87cf9a
+      if (userfooter)
87cf9a
+        free(userfooter);
87cf9a
+#endif /* WITH_LSPP */
87cf9a
     }
87cf9a
+    
87cf9a
 
87cf9a
    /*
87cf9a
     * See if we need to add the starting sheet...
87cf9a
@@ -3690,6 +3922,111 @@ check_rss_recipient(
87cf9a
 }
87cf9a
 
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+/*
87cf9a
+ * 'check_context()' - Check SELinux security context of a user and job
87cf9a
+ */
87cf9a
+
87cf9a
+static int				/* O - 1 if OK, 0 if not, -1 on error */
87cf9a
+check_context(cupsd_client_t *con,	/* I - Client connection */
87cf9a
+             cupsd_job_t    *job)	/* I - Job */
87cf9a
+{
87cf9a
+  int			enforcing;	/* is SELinux in enforcing mode */
87cf9a
+  char			filename[1024]; /* Filename of the spool file */
87cf9a
+  security_id_t		clisid;		/* SELinux SID of the client */
87cf9a
+  security_id_t		jobsid;		/* SELinux SID of the job */
87cf9a
+  security_id_t		filesid;	/* SELinux SID of the spool file */
87cf9a
+  struct avc_entry_ref	avcref;		/* AVC entry cache pointer */
87cf9a
+  security_class_t	tclass;		/* SELinux security class */
87cf9a
+  access_vector_t	avr;		/* SELinux access being queried */
87cf9a
+  security_context_t	spoolfilecon;	/* SELinux context of the spool file */
87cf9a
+
87cf9a
+
87cf9a
+ /*
87cf9a
+  * Validate the input to be sure there are contexts to work with...
87cf9a
+  */
87cf9a
+
87cf9a
+  if (con->scon == NULL || job->scon == NULL
87cf9a
+      || strncmp(con->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) == 0
87cf9a
+      || strncmp(job->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) == 0)
87cf9a
+    return -1;
87cf9a
+
87cf9a
+  if ((enforcing = security_getenforce()) == -1)
87cf9a
+  {
87cf9a
+    cupsdLogMessage(CUPSD_LOG_ERROR, "Error while determining SELinux enforcement");
87cf9a
+    return -1;
87cf9a
+  }
87cf9a
+  cupsdLogMessage(CUPSD_LOG_DEBUG, "check_context: client context %s job context %s", con->scon, job->scon);
87cf9a
+
87cf9a
+
87cf9a
+ /*
87cf9a
+  * Initialize the avc engine...
87cf9a
+  */
87cf9a
+
87cf9a
+  static avc_initialized = 0;
87cf9a
+  if (! avc_initialized++)
87cf9a
+  {
87cf9a
+    if (avc_init("cupsd", NULL, NULL, NULL, NULL) < 0)
87cf9a
+    {
87cf9a
+      cupsdLogMessage(CUPSD_LOG_ERROR, "check_context: unable avc_init");
87cf9a
+      return -1;
87cf9a
+    } 
87cf9a
+  } 
87cf9a
+  if (avc_context_to_sid(con->scon, &clisid) != 0)
87cf9a
+  {
87cf9a
+    cupsdLogMessage(CUPSD_LOG_ERROR, "check_context: unable to convert %s to SELinux sid", con->scon);
87cf9a
+    return -1;
87cf9a
+  }
87cf9a
+  if (avc_context_to_sid(job->scon, &jobsid) != 0)
87cf9a
+  {
87cf9a
+    cupsdLogMessage(CUPSD_LOG_ERROR, "check_context: unable to convert %s to SELinux sid", job->scon);
87cf9a
+    return -1;
87cf9a
+  }
87cf9a
+  avc_entry_ref_init(&avcref);
87cf9a
+  tclass = SECCLASS_FILE;
87cf9a
+  avr = FILE__READ;
87cf9a
+
87cf9a
+ /*
87cf9a
+  * Perform the check with the client as the subject, first with the job as the object
87cf9a
+  *   if that fails then with the spool file as the object...
87cf9a
+  */
87cf9a
+
87cf9a
+  if (avc_has_perm_noaudit(clisid, jobsid, tclass, avr, &avcref, NULL) != 0)
87cf9a
+  {
87cf9a
+    cupsdLogMessage(CUPSD_LOG_INFO, "check_context: SELinux denied access based on the client context");
87cf9a
+
87cf9a
+    snprintf(filename, sizeof(filename), "%s/c%05d", RequestRoot, job->id);
87cf9a
+    if (getfilecon(filename, &spoolfilecon) == -1)
87cf9a
+    {
87cf9a
+      cupsdLogMessage(CUPSD_LOG_ERROR, "check_context: Unable to get spoolfile context");
87cf9a
+      return -1;
87cf9a
+    }
87cf9a
+    if (avc_context_to_sid(spoolfilecon, &filesid) != 0)
87cf9a
+    {
87cf9a
+      cupsdLogMessage(CUPSD_LOG_ERROR, "check_context: Unable to determine the SELinux sid for the spool file");
87cf9a
+      freecon(spoolfilecon);
87cf9a
+      return -1;
87cf9a
+    }
87cf9a
+    freecon(spoolfilecon);
87cf9a
+    if (avc_has_perm_noaudit(clisid, filesid, tclass, avr, &avcref, NULL) != 0)
87cf9a
+    {
87cf9a
+      cupsdLogMessage(CUPSD_LOG_INFO, "check_context: SELinux denied access to the spool file");
87cf9a
+      return 0;
87cf9a
+    }
87cf9a
+    cupsdLogMessage(CUPSD_LOG_INFO, "check_context: SELinux allowed access to the spool file");
87cf9a
+    return 1;
87cf9a
+  }
87cf9a
+  else
87cf9a
+    if (enforcing == 0)
87cf9a
+        cupsdLogMessage(CUPSD_LOG_INFO, "check_context: allowing operation due to permissive mode");
87cf9a
+    else
87cf9a
+        cupsdLogMessage(CUPSD_LOG_INFO, "check_context: SELinux allowed access based on the client context");
87cf9a
+
87cf9a
+  return 1;
87cf9a
+}
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
+
87cf9a
 /*
87cf9a
  * 'check_quotas()' - Check quotas for a printer and user.
87cf9a
  */
87cf9a
@@ -4142,6 +4479,15 @@ copy_banner(cupsd_client_t *con,	/* I -
87cf9a
   char		attrname[255],		/* Name of attribute */
87cf9a
 		*s;			/* Pointer into name */
87cf9a
   ipp_attribute_t *attr;		/* Attribute */
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  const char	*mls_label;		/* SL of print job */
87cf9a
+  char		*jobrange;		/* SELinux sensitivity range */
87cf9a
+  char		*jobclearance;		/* SELinux low end clearance */
87cf9a
+  context_t	jobcon;			/* SELinux context of the job */
87cf9a
+  context_t	tmpcon;			/* Temp context to set the level */
87cf9a
+  security_context_t	spoolcon;	/* Context of the file in the spool */
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
 
87cf9a
 
87cf9a
   cupsdLogMessage(CUPSD_LOG_DEBUG2,
87cf9a
@@ -4177,6 +4523,82 @@ copy_banner(cupsd_client_t *con,	/* I -
87cf9a
 
87cf9a
   fchmod(cupsFileNumber(out), 0640);
87cf9a
   fchown(cupsFileNumber(out), RunUser, Group);
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  if (job->scon != NULL &&
87cf9a
+      strncmp(job->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) != 0)
87cf9a
+  {
87cf9a
+    if (getfilecon(filename, &spoolcon) == -1)
87cf9a
+    {
87cf9a
+      cupsdLogMessage(CUPSD_LOG_ERROR,
87cf9a
+                      "copy_banner: Unable to get the context of the banner file %s - %s",
87cf9a
+                      filename, strerror(errno));
87cf9a
+      job->num_files --;
87cf9a
+      return (0);
87cf9a
+    }
87cf9a
+    tmpcon = context_new(spoolcon);
87cf9a
+    jobcon = context_new(job->scon);
87cf9a
+    freecon(spoolcon);
87cf9a
+    if (!tmpcon || !jobcon)
87cf9a
+    {
87cf9a
+      if (tmpcon)
87cf9a
+        context_free(tmpcon);
87cf9a
+      if (jobcon)
87cf9a
+        context_free(jobcon);
87cf9a
+      cupsdLogMessage(CUPSD_LOG_ERROR,
87cf9a
+                      "copy_banner: Unable to get the SELinux contexts");
87cf9a
+      job->num_files --;
87cf9a
+      return (0);
87cf9a
+    }
87cf9a
+    jobrange = context_range_get(jobcon);
87cf9a
+    if (jobrange)
87cf9a
+    {
87cf9a
+      jobrange = strdup(jobrange);
87cf9a
+      if ((jobclearance = strtok(jobrange, "-")) != NULL)
87cf9a
+      {
87cf9a
+	if (context_range_set(tmpcon, jobclearance) == -1)
87cf9a
+	{
87cf9a
+	  cupsdLogMessage(CUPSD_LOG_ERROR,
87cf9a
+			  "copy_banner: Unable to set the level of the context for file %s - %s",
87cf9a
+			  filename, strerror(errno));
87cf9a
+	  free(jobrange);
87cf9a
+	  context_free(jobcon);
87cf9a
+	  context_free(tmpcon);
87cf9a
+	  job->num_files --;
87cf9a
+	  return (0);
87cf9a
+	}
87cf9a
+      }
87cf9a
+      else
87cf9a
+      {
87cf9a
+	if (context_range_set(tmpcon, (context_range_get(jobcon))) == -1)
87cf9a
+	{
87cf9a
+	  cupsdLogMessage(CUPSD_LOG_ERROR,
87cf9a
+			  "copy_banner: Unable to set the level of the context for file %s - %s",
87cf9a
+			  filename, strerror(errno));
87cf9a
+	  free(jobrange);
87cf9a
+	  context_free(jobcon);
87cf9a
+	  context_free(tmpcon);
87cf9a
+	  job->num_files --;
87cf9a
+	  return (0);
87cf9a
+	}
87cf9a
+      }
87cf9a
+      free(jobrange);
87cf9a
+    }
87cf9a
+    if (setfilecon(filename, context_str(tmpcon)) == -1)
87cf9a
+    {
87cf9a
+      cupsdLogMessage(CUPSD_LOG_ERROR,
87cf9a
+                      "copy_banner: Unable to set the context of the banner file %s - %s",
87cf9a
+                      filename, strerror(errno));
87cf9a
+      context_free(jobcon);
87cf9a
+      context_free(tmpcon);
87cf9a
+      job->num_files --;
87cf9a
+      return (0);
87cf9a
+    }
87cf9a
+    cupsdLogMessage(CUPSD_LOG_DEBUG2, "copy_banner: %s set to %s",
87cf9a
+                    filename, context_str(tmpcon));
87cf9a
+    context_free(jobcon);
87cf9a
+    context_free(tmpcon);
87cf9a
+  }
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
  /*
87cf9a
   * Try the localized banner file under the subdirectory...
87cf9a
@@ -4271,6 +4693,24 @@ copy_banner(cupsd_client_t *con,	/* I -
87cf9a
       else
87cf9a
         s = attrname;
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+      if (strcmp(s, "mls-label") == 0)
87cf9a
+      {
87cf9a
+        if (job->scon != NULL && strncmp(job->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) != 0)
87cf9a
+        {
87cf9a
+          jobcon = context_new(job->scon);
87cf9a
+          if (_cups_strcasecmp(name, MLS_CONFIG) == 0)
87cf9a
+            mls_label = context_range_get(jobcon);
87cf9a
+          else if (_cups_strcasecmp(name, TE_CONFIG) == 0)
87cf9a
+            mls_label = context_type_get(jobcon);
87cf9a
+          else // default to using the whole context string
87cf9a
+            mls_label = context_str(jobcon);
87cf9a
+          cupsFilePuts(out, mls_label);
87cf9a
+          context_free(jobcon);
87cf9a
+        }
87cf9a
+        continue;
87cf9a
+      }
87cf9a
+#endif /* WITH_LSPP */
87cf9a
       if (!strcmp(s, "printer-name"))
87cf9a
       {
87cf9a
         cupsFilePuts(out, job->dest);
87cf9a
@@ -6348,6 +6788,22 @@ get_job_attrs(cupsd_client_t  *con,	/* I
87cf9a
 
87cf9a
   exclude = cupsdGetPrivateAttrs(policy, con, printer, job->username);
87cf9a
 
87cf9a
+
87cf9a
+#ifdef WITH_LSPP
87cf9a
+ /*
87cf9a
+  * Check SELinux...
87cf9a
+  */
87cf9a
+  if (is_lspp_config() && check_context(con, job) != 1)
87cf9a
+  {
87cf9a
+   /*
87cf9a
+    * Unfortunately we have to lie to the user...
87cf9a
+    */
87cf9a
+    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid);
87cf9a
+    return;
87cf9a
+  }
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
+
87cf9a
  /*
87cf9a
   * Copy attributes...
87cf9a
   */
87cf9a
@@ -6701,6 +7157,11 @@ get_jobs(cupsd_client_t  *con,		/* I - C
87cf9a
       if (username[0] && _cups_strcasecmp(username, job->username))
87cf9a
 	continue;
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+      if (is_lspp_config() && check_context(con, job) != 1)
87cf9a
+	continue;
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
       if (count > 0)
87cf9a
 	ippAddSeparator(con->response);
87cf9a
 
87cf9a
@@ -11259,6 +11720,11 @@ validate_user(cupsd_job_t    *job,	/* I
87cf9a
 
87cf9a
   strlcpy(username, get_username(con), userlen);
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  if (is_lspp_config() && check_context(con, job) != 1)
87cf9a
+    return 0;
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
  /*
87cf9a
   * Check the username against the owner...
87cf9a
   */
87cf9a
diff -up cups-1.6.3/scheduler/job.c.lspp cups-1.6.3/scheduler/job.c
87cf9a
--- cups-1.6.3/scheduler/job.c.lspp	2015-06-10 11:45:38.155441541 +0200
87cf9a
+++ cups-1.6.3/scheduler/job.c	2015-06-10 11:45:38.164441517 +0200
87cf9a
@@ -68,6 +68,9 @@
87cf9a
  *   update_job_attrs() 	- Update the job-printer-* attributes.
87cf9a
  */
87cf9a
 
87cf9a
+/* Copyright (C) 2005 Trusted Computer Solutions, Inc. */
87cf9a
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
87cf9a
+
87cf9a
 /*
87cf9a
  * Include necessary headers...
87cf9a
  */
87cf9a
@@ -83,6 +86,14 @@
87cf9a
 #  endif /* HAVE_IOKIT_PWR_MGT_IOPMLIBPRIVATE_H */
87cf9a
 #endif /* __APPLE__ */
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+#include <libaudit.h>
87cf9a
+#include <selinux/selinux.h>
87cf9a
+#include <selinux/context.h>
87cf9a
+#include <selinux/avc.h>
87cf9a
+#include <selinux/flask.h>
87cf9a
+#include <selinux/av_permissions.h>
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
 /*
87cf9a
  * Design Notes for Job Management
87cf9a
@@ -580,6 +591,14 @@ cupsdContinueJob(cupsd_job_t *job)	/* I
87cf9a
 					/* PRINTER_STATE_REASONS env var */
87cf9a
 			rip_max_cache[255];
87cf9a
 					/* RIP_MAX_CACHE env variable */
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  char			*audit_message = NULL;	/* Audit message string */
87cf9a
+  context_t		jobcon;		/* SELinux context of the job */
87cf9a
+  char			*label_template = NULL;	/* SL to put in classification
87cf9a
+						   env var */
87cf9a
+  const char		*mls_label = NULL;	/* SL to put in classification
87cf9a
+						   env var */
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
 
87cf9a
   cupsdLogMessage(CUPSD_LOG_DEBUG2,
87cf9a
@@ -1092,6 +1111,67 @@ cupsdContinueJob(cupsd_job_t *job)	/* I
87cf9a
   if (final_content_type[0])
87cf9a
     envp[envc ++] = final_content_type;
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  if (is_lspp_config())
87cf9a
+  {
87cf9a
+    if (!job->scon || strncmp(job->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) == 0)
87cf9a
+    {
87cf9a
+      if (AuditLog != -1)
87cf9a
+      {
87cf9a
+        audit_message = NULL;
87cf9a
+        cupsdSetStringf(&audit_message, "job=%d auid=%u acct=%s printer=%s title=%s",
87cf9a
+                        job->id, job->auid, job->username, job->printer->name, title);
87cf9a
+        audit_log_user_message(AuditLog, AUDIT_USER_UNLABELED_EXPORT, audit_message,
87cf9a
+                               ServerName, NULL, NULL, 1);
87cf9a
+        cupsdClearString(&audit_message);
87cf9a
+      }
87cf9a
+    }
87cf9a
+    else 
87cf9a
+    {
87cf9a
+      jobcon = context_new(job->scon);
87cf9a
+
87cf9a
+      if ((attr = ippFindAttribute(job->attrs, "job-sheets", IPP_TAG_NAME)) == NULL)
87cf9a
+        label_template = strdup(Classification);
87cf9a
+      else if (attr->num_values > 1 &&
87cf9a
+               strcmp(attr->values[1].string.text, "none") != 0)
87cf9a
+        label_template = strdup(attr->values[1].string.text);
87cf9a
+      else
87cf9a
+        label_template = strdup(attr->values[0].string.text);
87cf9a
+
87cf9a
+      if (_cups_strcasecmp(label_template, MLS_CONFIG) == 0)
87cf9a
+        mls_label = context_range_get(jobcon);
87cf9a
+      else if (_cups_strcasecmp(label_template, TE_CONFIG) == 0)
87cf9a
+        mls_label = context_type_get(jobcon);
87cf9a
+      else if (_cups_strcasecmp(label_template, SELINUX_CONFIG) == 0)
87cf9a
+        mls_label = context_str(jobcon);
87cf9a
+      else
87cf9a
+        mls_label = label_template;
87cf9a
+
87cf9a
+      if (mls_label && (PerPageLabels || banner_page))
87cf9a
+      {
87cf9a
+        snprintf(classification, sizeof(classification), "CLASSIFICATION=LSPP:%s", mls_label);
87cf9a
+        envp[envc ++] = classification;
87cf9a
+      }
87cf9a
+
87cf9a
+      if ((AuditLog != -1) && !banner_page)
87cf9a
+      {
87cf9a
+        audit_message = NULL;
87cf9a
+        cupsdSetStringf(&audit_message, "job=%d auid=%u acct=%s printer=%s title=%s"
87cf9a
+                        " obj=%s label=%s", job->id, job->auid, job->username,
87cf9a
+                        job->printer->name, title, job->scon, mls_label?mls_label:"none");
87cf9a
+        audit_log_user_message(AuditLog, AUDIT_USER_LABELED_EXPORT, audit_message,
87cf9a
+                               ServerName, NULL, NULL, 1);
87cf9a
+        cupsdClearString(&audit_message);
87cf9a
+      }
87cf9a
+      context_free(jobcon);
87cf9a
+      free(label_template);
87cf9a
+    }
87cf9a
+  }
87cf9a
+  else
87cf9a
+   /*
87cf9a
+    * Fall through to the non-LSPP behavior
87cf9a
+    */
87cf9a
+#endif /* WITH_LSPP */
87cf9a
   if (Classification && !banner_page)
87cf9a
   {
87cf9a
     if ((attr = ippFindAttribute(job->attrs, "job-sheets",
87cf9a
@@ -1866,6 +1946,20 @@ cupsdLoadJob(cupsd_job_t *job)		/* I - J
87cf9a
       ippSetString(job->attrs, &job->reasons, 0, "none");
87cf9a
   }
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  if ((attr = ippFindAttribute(job->attrs, "security-context", IPP_TAG_NAME)) != NULL)
87cf9a
+    cupsdSetString(&job->scon, attr->values[0].string.text);
87cf9a
+  else if (is_lspp_config())
87cf9a
+  {
87cf9a
+   /*
87cf9a
+    * There was no security context so delete the job
87cf9a
+    */
87cf9a
+    cupsdLogMessage(CUPSD_LOG_ERROR, "LoadAllJobs: Missing or bad security-context attribute in control file \"%s\"!",
87cf9a
+                    jobfile);
87cf9a
+    goto error;
87cf9a
+  }
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
   job->sheets     = ippFindAttribute(job->attrs, "job-media-sheets-completed",
87cf9a
                                      IPP_TAG_INTEGER);
87cf9a
   job->job_sheets = ippFindAttribute(job->attrs, "job-sheets", IPP_TAG_NAME);
87cf9a
@@ -2259,6 +2353,14 @@ cupsdSaveJob(cupsd_job_t *job)		/* I - J
87cf9a
 {
87cf9a
   char		filename[1024];		/* Job control filename */
87cf9a
   cups_file_t	*fp;			/* Job file */
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  security_context_t	spoolcon;	/* context of the job control file */
87cf9a
+  context_t		jobcon;		/* contex_t container for job->scon */
87cf9a
+  context_t		tmpcon;		/* Temp context to swap the level */
87cf9a
+  char			*jobclearance;	/* SELinux low end clearance */
87cf9a
+  const char		*jobrange;	/* SELinux sensitivity range */
87cf9a
+  char			*jobrange_copy;	/* SELinux sensitivity range */
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
 
87cf9a
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdSaveJob(job=%p(%d)): job->attrs=%p",
87cf9a
@@ -2271,6 +2373,76 @@ cupsdSaveJob(cupsd_job_t *job)		/* I - J
87cf9a
 
87cf9a
   fchown(cupsFileNumber(fp), RunUser, Group);
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  if (job->scon && strncmp(job->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) != 0)
87cf9a
+  {
87cf9a
+    if (getfilecon(filename, &spoolcon) == -1)
87cf9a
+    {
87cf9a
+      cupsdLogMessage(CUPSD_LOG_ERROR,
87cf9a
+                      "Unable to get context of job control file \"%s\" - %s.",
87cf9a
+                      filename, strerror(errno));
87cf9a
+      return;
87cf9a
+    }
87cf9a
+    jobcon = context_new(job->scon);
87cf9a
+    tmpcon = context_new(spoolcon);
87cf9a
+    freecon(spoolcon);
87cf9a
+    if (!jobcon || !tmpcon)
87cf9a
+    {
87cf9a
+      if (jobcon)
87cf9a
+        context_free(jobcon);
87cf9a
+      if (tmpcon)
87cf9a
+        context_free(tmpcon);
87cf9a
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to get SELinux contexts");
87cf9a
+      return;
87cf9a
+    }
87cf9a
+    jobrange = context_range_get(jobcon);
87cf9a
+    if (jobrange)
87cf9a
+    {
87cf9a
+      jobrange_copy = strdup(jobrange);
87cf9a
+      if ((jobclearance = strtok(jobrange_copy, "-")) != NULL)
87cf9a
+      {
87cf9a
+	if (context_range_set(tmpcon, jobclearance) == -1)
87cf9a
+	{
87cf9a
+	  cupsdLogMessage(CUPSD_LOG_ERROR,
87cf9a
+			  "Unable to set the range for job control file \"%s\" - %s.",
87cf9a
+			  filename, strerror(errno));
87cf9a
+	  free(jobrange_copy);
87cf9a
+	  context_free(tmpcon);
87cf9a
+	  context_free(jobcon);
87cf9a
+	  return;
87cf9a
+	}
87cf9a
+      }
87cf9a
+      else
87cf9a
+      {
87cf9a
+	if (context_range_set(tmpcon, (context_range_get(jobcon))) == -1)
87cf9a
+	{
87cf9a
+	  cupsdLogMessage(CUPSD_LOG_ERROR,
87cf9a
+			  "Unable to set the range for job control file \"%s\" - %s.",
87cf9a
+			  filename, strerror(errno));
87cf9a
+	  free(jobrange_copy);
87cf9a
+	  context_free(tmpcon);
87cf9a
+	  context_free(jobcon);
87cf9a
+	  return;
87cf9a
+	}
87cf9a
+      }
87cf9a
+      free(jobrange_copy);
87cf9a
+    }
87cf9a
+    if (setfilecon(filename, context_str(tmpcon)) == -1)
87cf9a
+    {
87cf9a
+      cupsdLogMessage(CUPSD_LOG_ERROR,
87cf9a
+                      "Unable to set context of job control file \"%s\" - %s.",
87cf9a
+                      filename, strerror(errno));
87cf9a
+      context_free(tmpcon);
87cf9a
+      context_free(jobcon);
87cf9a
+      return;
87cf9a
+    }
87cf9a
+    cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdSaveJob(job=%p): new spool file context=%s",
87cf9a
+                    job, context_str(tmpcon));
87cf9a
+    context_free(tmpcon);
87cf9a
+    context_free(jobcon);
87cf9a
+  }
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
   job->attrs->state = IPP_IDLE;
87cf9a
 
87cf9a
   if (ippWriteIO(fp, (ipp_iocb_t)cupsFileWrite, 1, NULL,
87cf9a
@@ -3780,6 +3952,18 @@ get_options(cupsd_job_t *job,		/* I - Jo
87cf9a
 	  banner_page)
87cf9a
         continue;
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+     /*
87cf9a
+      * In LSPP mode refuse to honor the page-label
87cf9a
+      */
87cf9a
+      if (is_lspp_config() &&
87cf9a
+          !strcmp(attr->name, "page-label"))
87cf9a
+      {
87cf9a
+        cupsdLogMessage(CUPSD_LOG_DEBUG, "Ignoring page-label option due to LSPP mode");
87cf9a
+        continue;
87cf9a
+      }
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
      /*
87cf9a
       * Otherwise add them to the list...
87cf9a
       */
87cf9a
@@ -4504,6 +4688,19 @@ static void
87cf9a
 start_job(cupsd_job_t     *job,		/* I - Job ID */
87cf9a
           cupsd_printer_t *printer)	/* I - Printer to print job */
87cf9a
 {
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  char			*audit_message = NULL;	/* Audit message string */
87cf9a
+  char			*printerfile = NULL;	/* Device file pointed to by the printer */
87cf9a
+  security_id_t		clisid;		/* SELinux SID for the client */
87cf9a
+  security_id_t		psid;		/* SELinux SID for the printer */
87cf9a
+  context_t		printercon;	/* Printer's context string */
87cf9a
+  struct stat		printerstat;	/* Printer's stat buffer */
87cf9a
+  security_context_t	devcon;		/* Printer's SELinux context */
87cf9a
+  struct avc_entry_ref	avcref;		/* Pointer to the access vector cache */
87cf9a
+  security_class_t	tclass;		/* Object class for the SELinux check */
87cf9a
+  access_vector_t	avr;		/* Access method being requested */
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "start_job(job=%p(%d), printer=%p(%s))",
87cf9a
                   job, job->id, printer, printer->name);
87cf9a
 
87cf9a
@@ -4646,6 +4843,108 @@ start_job(cupsd_job_t     *job,		/* I -
87cf9a
   fcntl(job->side_pipes[1], F_SETFD,
87cf9a
 	fcntl(job->side_pipes[1], F_GETFD) | FD_CLOEXEC);
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  if (is_lspp_config())
87cf9a
+  {
87cf9a
+   /*
87cf9a
+    * Perform an access check before printing, but only if the printer starts with /dev/
87cf9a
+    */
87cf9a
+    printerfile = strstr(printer->device_uri, "/dev/");
87cf9a
+    if (printerfile == NULL && (strncmp(printer->device_uri, "file:/", 6) == 0))
87cf9a
+      printerfile = printer->device_uri + strlen("file:");
87cf9a
+
87cf9a
+    if (printerfile != NULL)
87cf9a
+    {
87cf9a
+      cupsdLogMessage(CUPSD_LOG_DEBUG,
87cf9a
+                      "StartJob: Attempting to check access on printer device %s", printerfile);
87cf9a
+      if (lstat(printerfile, &printerstat) < 0)
87cf9a
+      {
87cf9a
+	if (errno != ENOENT)
87cf9a
+	{
87cf9a
+	  cupsdLogMessage(CUPSD_LOG_ERROR, "StartJob: Unable to stat the printer");
87cf9a
+	  cupsdSetJobState(job, IPP_JOB_ABORTED, CUPSD_JOB_DEFAULT, NULL);
87cf9a
+	  return ;
87cf9a
+	}
87cf9a
+	/*
87cf9a
+	 * The printer does not exist, so for now assume it's a FileDevice
87cf9a
+	 */
87cf9a
+	tclass = SECCLASS_FILE;
87cf9a
+	avr = FILE__WRITE;
87cf9a
+      }
87cf9a
+      else if (S_ISCHR(printerstat.st_mode))
87cf9a
+      {
87cf9a
+	tclass = SECCLASS_CHR_FILE;
87cf9a
+	avr = CHR_FILE__WRITE;
87cf9a
+      }
87cf9a
+      else if (S_ISREG(printerstat.st_mode))
87cf9a
+      {
87cf9a
+	tclass = SECCLASS_FILE;
87cf9a
+	avr = FILE__WRITE;
87cf9a
+      }
87cf9a
+      else
87cf9a
+      {
87cf9a
+	cupsdLogMessage(CUPSD_LOG_ERROR,
87cf9a
+			"StartJob: Printer is not a character device or regular file");
87cf9a
+	cupsdSetJobState(job, IPP_JOB_ABORTED, CUPSD_JOB_DEFAULT, NULL);
87cf9a
+	return ;
87cf9a
+      }
87cf9a
+      static avc_initialized = 0;
87cf9a
+      if (!avc_initialized++)
87cf9a
+          avc_init("cupsd_dequeue_", NULL, NULL, NULL, NULL);
87cf9a
+      avc_entry_ref_init(&avcref);
87cf9a
+      if (avc_context_to_sid(job->scon, &clisid) != 0)
87cf9a
+      {
87cf9a
+        cupsdLogMessage(CUPSD_LOG_ERROR,
87cf9a
+                        "StartJob: Unable to determine the SELinux sid for the job");
87cf9a
+        cupsdSetJobState(job, IPP_JOB_ABORTED, CUPSD_JOB_DEFAULT, NULL);
87cf9a
+        return ;
87cf9a
+      }
87cf9a
+      if (getfilecon(printerfile, &devcon) == -1)
87cf9a
+      {
87cf9a
+        cupsdLogMessage(CUPSD_LOG_ERROR, "StartJob: Unable to get the SELinux context of %s",
87cf9a
+                        printerfile);
87cf9a
+        cupsdSetJobState(job, IPP_JOB_ABORTED, CUPSD_JOB_DEFAULT, NULL);
87cf9a
+        return ;
87cf9a
+      }
87cf9a
+      printercon = context_new(devcon);
87cf9a
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "StartJob: printer context %s client context %s",
87cf9a
+                      context_str(printercon), job->scon);
87cf9a
+      context_free(printercon);
87cf9a
+
87cf9a
+      if (avc_context_to_sid(devcon, &psid) != 0)
87cf9a
+      {
87cf9a
+        cupsdLogMessage(CUPSD_LOG_ERROR,
87cf9a
+                        "StartJob: Unable to determine the SELinux sid for the printer");
87cf9a
+        freecon(devcon);
87cf9a
+        cupsdSetJobState(job, IPP_JOB_ABORTED, CUPSD_JOB_DEFAULT, NULL);
87cf9a
+        return ;
87cf9a
+      }
87cf9a
+      freecon(devcon);
87cf9a
+
87cf9a
+      if (avc_has_perm(clisid, psid, tclass, avr, &avcref, NULL) != 0)
87cf9a
+      {
87cf9a
+       /*
87cf9a
+        * The access check failed, so cancel the job and send an audit message
87cf9a
+        */
87cf9a
+        if (AuditLog != -1)
87cf9a
+        {
87cf9a
+          audit_message = NULL;
87cf9a
+          cupsdSetStringf(&audit_message, "job=%d auid=%u acct=%s obj=%s canceled"
87cf9a
+                                          " unable to access printer=%s", job->id,
87cf9a
+                          job->auid, (job->username)?job->username:"?", job->scon, printer->name);
87cf9a
+          audit_log_user_message(AuditLog, AUDIT_USER_LABELED_EXPORT, audit_message,
87cf9a
+                                 ServerName, NULL, NULL, 0);
87cf9a
+          cupsdClearString(&audit_message);
87cf9a
+        }
87cf9a
+
87cf9a
+        cupsdSetJobState(job, IPP_JOB_ABORTED, CUPSD_JOB_DEFAULT, NULL);
87cf9a
+
87cf9a
+        return ;
87cf9a
+      }
87cf9a
+    }
87cf9a
+  }
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
  /*
87cf9a
   * Now start the first file in the job...
87cf9a
   */
87cf9a
diff -up cups-1.6.3/scheduler/job.h.lspp cups-1.6.3/scheduler/job.h
87cf9a
--- cups-1.6.3/scheduler/job.h.lspp	2013-06-07 03:12:52.000000000 +0200
87cf9a
+++ cups-1.6.3/scheduler/job.h	2015-06-10 11:45:38.164441517 +0200
87cf9a
@@ -13,6 +13,13 @@
87cf9a
  *   file is missing or damaged, see the license at "http://www.cups.org/".
87cf9a
  */
87cf9a
 
87cf9a
+/* Copyright (C) 2005 Trusted Computer Solutions, Inc. */
87cf9a
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
87cf9a
+
87cf9a
+#ifdef WITH_LSPP
87cf9a
+#include <selinux/selinux.h>
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
 /*
87cf9a
  * Constants...
87cf9a
  */
87cf9a
@@ -82,6 +89,10 @@ struct cupsd_job_s			/**** Job request *
87cf9a
   int			progress;	/* Printing progress */
87cf9a
   int			num_keywords;	/* Number of PPD keywords */
87cf9a
   cups_option_t		*keywords;	/* PPD keywords */
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  security_context_t	scon;		/* Security context of job */
87cf9a
+  uid_t			auid;		/* Audit loginuid for this job */
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 };
87cf9a
 
87cf9a
 typedef struct cupsd_joblog_s		/**** Job log message ****/
87cf9a
diff -up cups-1.6.3/scheduler/main.c.lspp cups-1.6.3/scheduler/main.c
87cf9a
--- cups-1.6.3/scheduler/main.c.lspp	2015-06-10 11:45:38.095441704 +0200
87cf9a
+++ cups-1.6.3/scheduler/main.c	2015-06-10 11:45:38.164441517 +0200
87cf9a
@@ -38,6 +38,8 @@
87cf9a
  *   usage()               - Show scheduler usage.
87cf9a
  */
87cf9a
 
87cf9a
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
87cf9a
+
87cf9a
 /*
87cf9a
  * Include necessary headers...
87cf9a
  */
87cf9a
@@ -80,6 +82,9 @@
87cf9a
 #  include <sys/param.h>
87cf9a
 #endif /* HAVE_SYS_PARAM_H */
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+#  include <libaudit.h>
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
 /*
87cf9a
  * Local functions...
87cf9a
@@ -143,6 +148,9 @@ main(int  argc,				/* I - Number of comm
87cf9a
 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
87cf9a
   struct sigaction	action;		/* Actions for POSIX signals */
87cf9a
 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
87cf9a
+#if WITH_LSPP
87cf9a
+  auditfail_t           failmode;       /* Action for audit_open failure */
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 #ifdef __sgi
87cf9a
   cups_file_t		*fp;		/* Fake lpsched lock file */
87cf9a
   struct stat		statbuf;	/* Needed for checking lpsched FIFO */
87cf9a
@@ -526,6 +534,25 @@ main(int  argc,				/* I - Number of comm
87cf9a
 #endif /* DEBUG */
87cf9a
   }
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  if ((AuditLog = audit_open()) < 0 )
87cf9a
+  {
87cf9a
+    if (get_auditfail_action(&failmode) == 0)
87cf9a
+    {
87cf9a
+      if (failmode == FAIL_LOG)
87cf9a
+      {
87cf9a
+        cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to connect to audit subsystem.");
87cf9a
+        AuditLog = -1;
87cf9a
+      }
87cf9a
+      else if (failmode == FAIL_TERMINATE)
87cf9a
+      {
87cf9a
+        fprintf(stderr, "cupsd: unable to start auditing, terminating");
87cf9a
+        return -1;
87cf9a
+      }
87cf9a
+    }
87cf9a
+  }
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
  /*
87cf9a
   * Set the timezone info...
87cf9a
   */
87cf9a
@@ -1238,6 +1265,11 @@ main(int  argc,				/* I - Number of comm
87cf9a
 
87cf9a
   cupsdStopSelect();
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  if (AuditLog != -1)
87cf9a
+    audit_close(AuditLog);
87cf9a
+#endif /* WITH_LSPP */
87cf9a
+
87cf9a
   return (!stop_scheduler);
87cf9a
 }
87cf9a
 
87cf9a
diff -up cups-1.6.3/scheduler/printers.c.lspp cups-1.6.3/scheduler/printers.c
87cf9a
--- cups-1.6.3/scheduler/printers.c.lspp	2015-06-10 11:45:38.087441726 +0200
87cf9a
+++ cups-1.6.3/scheduler/printers.c	2015-06-10 11:45:38.165441514 +0200
87cf9a
@@ -56,6 +56,8 @@
87cf9a
  *   write_xml_string()         - Write a string with XML escaping.
87cf9a
  */
87cf9a
 
87cf9a
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
87cf9a
+
87cf9a
 /*
87cf9a
  * Include necessary headers...
87cf9a
  */
87cf9a
@@ -80,6 +82,10 @@
87cf9a
 #  include <asl.h>
87cf9a
 #endif /* __APPLE__ */
87cf9a
 
87cf9a
+#ifdef WITH_LSPP
87cf9a
+#  include <libaudit.h>
87cf9a
+#  include <selinux/context.h>
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
 /*
87cf9a
  * Local functions...
87cf9a
@@ -2107,6 +2113,13 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)
87cf9a
   ipp_attribute_t *attr;		/* Attribute data */
87cf9a
   char		*name,			/* Current user/group name */
87cf9a
 		*filter;		/* Current filter */
87cf9a
+#ifdef WITH_LSPP
87cf9a
+  char		*audit_message;		/* Audit message string */
87cf9a
+  char		*printerfile;		/* Path to a local printer dev */
87cf9a
+  char		*rangestr;		/* Printer's range if its available */
87cf9a
+  security_context_t	devcon;		/* Printer SELinux context */
87cf9a
+  context_t	printercon;		/* context_t for the printer */
87cf9a
+#endif /* WITH_LSPP */
87cf9a
 
87cf9a
 
87cf9a
   DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p->name,
87cf9a
@@ -2229,6 +2242,45 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)
87cf9a
       attr->values[1].string.text = _cupsStrAlloc(Classification ?
87cf9a
 	                                   Classification : p->job_sheets[1]);
87cf9a
     }
87cf9a
+#ifdef WITH_LSPP
87cf9a
+    if (AuditLog != -1)
87cf9a
+    {
87cf9a
+      audit_message = NULL;
87cf9a
+      rangestr = NULL;
87cf9a
+      printercon = 0;
87cf9a
+      printerfile = strstr(p->device_uri, "/dev/");
87cf9a
+      if (printerfile == NULL && (strncmp(p->device_uri, "file:/", 6) == 0))
87cf9a
+        printerfile = p->device_uri + strlen("file:");
87cf9a
+
87cf9a
+      if (printerfile != NULL)
87cf9a
+      {
87cf9a
+        if (getfilecon(printerfile, &devcon) == -1)
87cf9a
+        {
87cf9a
+          if(is_selinux_enabled())
87cf9a
+            cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdSetPrinterAttrs: Unable to get printer context");
87cf9a
+        }
87cf9a
+        else
87cf9a
+        {
87cf9a
+          printercon = context_new(devcon);
87cf9a
+          freecon(devcon);
87cf9a
+        }
87cf9a
+      }
87cf9a
+
87cf9a
+      if (printercon && context_range_get(printercon))
87cf9a
+        rangestr = strdup(context_range_get(printercon));
87cf9a
+      else
87cf9a
+        rangestr = strdup("unknown");
87cf9a
+
87cf9a
+      cupsdSetStringf(&audit_message, "printer=%s uri=%s banners=%s,%s range=%s",
87cf9a
+                      p->name, p->sanitized_device_uri, p->job_sheets[0], p->job_sheets[1], rangestr);
87cf9a
+      audit_log_user_message(AuditLog, AUDIT_LABEL_LEVEL_CHANGE, audit_message,
87cf9a
+                             ServerName, NULL, NULL, 1);
87cf9a
+      if (printercon)
87cf9a
+        context_free(printercon);
87cf9a
+      free(rangestr);
87cf9a
+      cupsdClearString(&audit_message);
87cf9a
+    }
87cf9a
+#endif /* WITH_LSPP */
87cf9a
   }
87cf9a
 
87cf9a
   p->raw    = 0;
87cf9a
@@ -5315,7 +5367,6 @@ write_irix_state(cupsd_printer_t *p)	/*
87cf9a
 }
87cf9a
 #endif /* __sgi */
87cf9a
 
87cf9a
-
87cf9a
 /*
87cf9a
  * 'write_xml_string()' - Write a string with XML escaping.
87cf9a
  */