e7076f3
--- cups-1.3.7/cups/cups.h.lspp	2008-02-20 00:32:58.000000000 +0000
9161be1
+++ cups-1.3.7/cups/cups.h	2008-05-30 16:59:10.000000000 +0100
cfc9fc5
@@ -15,6 +15,9 @@
cfc9fc5
  *   This file is subject to the Apple OS-Developed Software exception.
cfc9fc5
  */
cfc9fc5
 
cfc9fc5
+/* Copyright (C) 2005 Trusted Computer Solutions, Inc. */
cfc9fc5
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
cfc9fc5
+
cfc9fc5
 #ifndef _CUPS_CUPS_H_
cfc9fc5
 #  define _CUPS_CUPS_H_
cfc9fc5
 
e7076f3
@@ -66,6 +69,12 @@ extern "C" {
cfc9fc5
 #  define CUPS_DATE_ANY		-1
cfc9fc5
 
cfc9fc5
 
cfc9fc5
+# ifdef WITH_LSPP
cfc9fc5
+# define MLS_CONFIG "mls"
cfc9fc5
+# define TE_CONFIG "te"
cfc9fc5
+# define SELINUX_CONFIG "SELinux"
cfc9fc5
+# define UNKNOWN_SL "UNKNOWN SL"
cfc9fc5
+# endif /* WITH_LSPP */
cfc9fc5
 /*
cfc9fc5
  * Types and structures...
cfc9fc5
  */
9161be1
--- cups-1.3.7/scheduler/job.c.lspp	2008-05-30 16:59:10.000000000 +0100
9161be1
+++ cups-1.3.7/scheduler/job.c	2008-05-30 17:01:23.000000000 +0100
e7076f3
@@ -60,6 +60,9 @@
e7076f3
  *   update_job_attrs()         - Update the job-printer-* attributes.
e7076f3
  */
e7076f3
 
e7076f3
+/* Copyright (C) 2005 Trusted Computer Solutions, Inc. */
e7076f3
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
75d0e82
+
e7076f3
 /*
e7076f3
  * Include necessary headers...
e7076f3
  */
e7076f3
@@ -69,6 +72,14 @@
e7076f3
 #include <cups/backend.h>
e7076f3
 #include <cups/dir.h>
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+#include <libaudit.h>
e7076f3
+#include <selinux/selinux.h>
e7076f3
+#include <selinux/context.h>
e7076f3
+#include <selinux/avc.h>
e7076f3
+#include <selinux/flask.h>
e7076f3
+#include <selinux/av_permissions.h>
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 
e7076f3
 /*
e7076f3
  * Local globals...
e7076f3
@@ -1100,6 +1111,23 @@ cupsdLoadJob(cupsd_job_t *job)		/* I - J
e7076f3
     return;
e7076f3
   }
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+  if ((attr = ippFindAttribute(job->attrs, "security-context", IPP_TAG_NAME)) != NULL)
e7076f3
+    cupsdSetString(&job->scon, attr->values[0].string.text);
e7076f3
+  else if (is_lspp_config())
e7076f3
+  {
e7076f3
+   /*
e7076f3
+    * There was no security context so delete the job
e7076f3
+    */
e7076f3
+    cupsdLogMessage(CUPSD_LOG_ERROR, "LoadAllJobs: Missing or bad security-context attribute in control file \"%s\"!",
e7076f3
+                    jobfile);
e7076f3
+    ippDelete(job->attrs);
e7076f3
+    job->attrs = NULL;
e7076f3
+    unlink(jobfile);
e7076f3
+    return;
e7076f3
+  }
e7076f3
+#endif /* WITH_LSPP */
75d0e82
+
e7076f3
   job->sheets     = ippFindAttribute(job->attrs, "job-media-sheets-completed",
e7076f3
                                      IPP_TAG_INTEGER);
e7076f3
   job->job_sheets = ippFindAttribute(job->attrs, "job-sheets", IPP_TAG_NAME);
e7076f3
@@ -1453,6 +1481,13 @@ cupsdSaveJob(cupsd_job_t *job)		/* I - J
e7076f3
 {
e7076f3
   char		filename[1024];		/* Job control filename */
e7076f3
   cups_file_t	*fp;			/* Job file */
e7076f3
+#ifdef WITH_LSPP
e7076f3
+  security_context_t	spoolcon;	/* context of the job control file */
e7076f3
+  context_t		jobcon;		/* contex_t container for job->scon */
e7076f3
+  context_t		tmpcon;		/* Temp context to swap the level */
e7076f3
+  char		*jobclearance;		/* SELinux low end clearance */
e7076f3
+  char		*jobrange;		/* SELinux sensitivity range */
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 
e7076f3
 
e7076f3
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdSaveJob(job=%p(%d)): job->attrs=%p",
e7076f3
@@ -1471,6 +1506,76 @@ cupsdSaveJob(cupsd_job_t *job)		/* I - J
e7076f3
   fchmod(cupsFileNumber(fp), 0600);
e7076f3
   fchown(cupsFileNumber(fp), RunUser, Group);
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+  if (job->scon && strncmp(job->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) != 0)
e7076f3
+  {
e7076f3
+    if (getfilecon(filename, &spoolcon) == -1)
e7076f3
+    {
e7076f3
+      cupsdLogMessage(CUPSD_LOG_ERROR,
e7076f3
+                      "Unable to get context of job control file \"%s\" - %s.",
e7076f3
+                      filename, strerror(errno));
e7076f3
+      return;
e7076f3
+    }
e7076f3
+    jobcon = context_new(job->scon);
e7076f3
+    tmpcon = context_new(spoolcon);
e7076f3
+    freecon(spoolcon);
e7076f3
+    if (!jobcon || !tmpcon)
e7076f3
+    {
e7076f3
+      if (jobcon)
e7076f3
+        context_free(jobcon);
e7076f3
+      if (tmpcon)
e7076f3
+        context_free(tmpcon);
e7076f3
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to get SELinux contexts");
e7076f3
+      return;
e7076f3
+    }
e7076f3
+    jobrange = context_range_get(jobcon);
e7076f3
+    if (jobrange)
e7076f3
+    {
e7076f3
+      jobrange = strdup(jobrange);
e7076f3
+      if ((jobclearance = strtok(jobrange, "-")) != NULL)
e7076f3
+      {
e7076f3
+	if (context_range_set(tmpcon, jobclearance) == -1)
e7076f3
+	{
e7076f3
+	  cupsdLogMessage(CUPSD_LOG_ERROR,
e7076f3
+			  "Unable to set the range for job control file \"%s\" - %s.",
e7076f3
+			  filename, strerror(errno));
e7076f3
+	  free(jobrange);
e7076f3
+	  context_free(tmpcon);
e7076f3
+	  context_free(jobcon);
e7076f3
+	  return;
e7076f3
+	}
e7076f3
+      }
e7076f3
+      else
e7076f3
+      {
e7076f3
+	if (context_range_set(tmpcon, (context_range_get(jobcon))) == -1)
e7076f3
+	{
e7076f3
+	  cupsdLogMessage(CUPSD_LOG_ERROR,
e7076f3
+			  "Unable to set the range for job control file \"%s\" - %s.",
e7076f3
+			  filename, strerror(errno));
e7076f3
+	  free(jobrange);
e7076f3
+	  context_free(tmpcon);
e7076f3
+	  context_free(jobcon);
e7076f3
+	  return;
e7076f3
+	}
e7076f3
+      }
e7076f3
+      free(jobrange);
e7076f3
+    }
e7076f3
+    if (setfilecon(filename, context_str(tmpcon)) == -1)
e7076f3
+    {
e7076f3
+      cupsdLogMessage(CUPSD_LOG_ERROR,
e7076f3
+                      "Unable to set context of job control file \"%s\" - %s.",
e7076f3
+                      filename, strerror(errno));
e7076f3
+      context_free(tmpcon);
e7076f3
+      context_free(jobcon);
e7076f3
+      return;
e7076f3
+    }
e7076f3
+    cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdSaveJob(job=%p): new spool file context=%s",
e7076f3
+                    job, context_str(tmpcon));
e7076f3
+    context_free(tmpcon);
e7076f3
+    context_free(jobcon);
e7076f3
+  }
e7076f3
+#endif /* WITH_LSPP */
75d0e82
+
e7076f3
   job->attrs->state = IPP_IDLE;
e7076f3
 
e7076f3
   if (ippWriteIO(fp, (ipp_iocb_t)cupsFileWrite, 1, NULL,
e7076f3
@@ -2484,6 +2589,21 @@ start_job(cupsd_job_t     *job,		/* I - 
e7076f3
 					/* RIP_MAX_CACHE env variable */
e7076f3
   static char		*options = NULL;/* Full list of options */
e7076f3
   static int		optlength = 0;	/* Length of option buffer */
e7076f3
+#ifdef WITH_LSPP
e7076f3
+  const char		*mls_label = NULL;	/* SL to put in classification env var */
e7076f3
+  char			*label_template = NULL;	/* SL to put in classification env var */
e7076f3
+  char			*audit_message = NULL;	/* Audit message string */
e7076f3
+  char			*printerfile = NULL;	/* Device file pointed to by the printer */
e7076f3
+  context_t		jobcon;		/* SELinux context of the job */
e7076f3
+  security_id_t		clisid;		/* SELinux SID for the client */
e7076f3
+  security_id_t		psid;		/* SELinux SID for the printer */
e7076f3
+  context_t		printercon;	/* Printer's context string */
e7076f3
+  struct stat		printerstat;	/* Printer's stat buffer */
e7076f3
+  security_context_t	devcon;		/* Printer's SELinux context */
e7076f3
+  struct avc_entry_ref	avcref;		/* Pointer to the access vector cache */
e7076f3
+  security_class_t	tclass;		/* Object class for the SELinux check */
e7076f3
+  access_vector_t	avr;		/* Access method being requested */
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 
e7076f3
 
e7076f3
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "[Job %d] start_job: file = %d/%d",
e7076f3
@@ -2739,6 +2859,106 @@ start_job(cupsd_job_t     *job,		/* I - 
e7076f3
           fcntl(job->side_pipes[1], F_GETFL) | O_NONBLOCK);
e7076f3
   }
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+  if (is_lspp_config())
e7076f3
+  {
e7076f3
+   /*
e7076f3
+    * Perform an access check before printing, but only if the printer starts with /dev/
e7076f3
+    */
e7076f3
+    printerfile = strstr(printer->device_uri, "/dev/");
e7076f3
+    if (printerfile == NULL && (strncmp(printer->device_uri, "file:/", 6) == 0))
e7076f3
+      printerfile = strdup(printer->device_uri + strlen("file:/"));
75d0e82
+
e7076f3
+    if (printerfile != NULL)
e7076f3
+    {
e7076f3
+      cupsdLogMessage(CUPSD_LOG_DEBUG,
e7076f3
+                      "StartJob: Attempting to check access on printer device %s", printerfile);
e7076f3
+      if (lstat(printerfile, &printerstat) < 0)
e7076f3
+      {
e7076f3
+	if (errno != ENOENT)
e7076f3
+	{
e7076f3
+	  cupsdLogMessage(CUPSD_LOG_ERROR, "StartJob: Unable to stat the printer");
e7076f3
+	  cupsdCancelJob(job, 0, IPP_JOB_ABORTED);
e7076f3
+	  return ;
e7076f3
+	}
e7076f3
+	/*
e7076f3
+	 * The printer does not exist, so for now assume it's a FileDevice
e7076f3
+	 */
e7076f3
+	tclass = SECCLASS_FILE;
e7076f3
+	avr = FILE__WRITE;
e7076f3
+      }
e7076f3
+      else if (S_ISCHR(printerstat.st_mode))
e7076f3
+      {
e7076f3
+	tclass = SECCLASS_CHR_FILE;
e7076f3
+	avr = CHR_FILE__WRITE;
e7076f3
+      }
e7076f3
+      else if (S_ISREG(printerstat.st_mode))
e7076f3
+      {
e7076f3
+	tclass = SECCLASS_FILE;
e7076f3
+	avr = FILE__WRITE;
e7076f3
+      }
e7076f3
+      else
e7076f3
+      {
e7076f3
+	cupsdLogMessage(CUPSD_LOG_ERROR,
e7076f3
+			"StartJob: Printer is not a character device or regular file");
e7076f3
+	cupsdCancelJob(job, 0, IPP_JOB_ABORTED);
e7076f3
+	return ;
e7076f3
+      }
e7076f3
+      avc_init("cupsd_dequeue_", NULL, NULL, NULL, NULL);
e7076f3
+      avc_entry_ref_init(&avcref);
e7076f3
+      if (avc_context_to_sid(job->scon, &clisid) != 0)
e7076f3
+      {
e7076f3
+        cupsdLogMessage(CUPSD_LOG_ERROR,
e7076f3
+                        "StartJob: Unable to determine the SELinux sid for the job");
e7076f3
+        cupsdCancelJob(job, 0, IPP_JOB_ABORTED);
e7076f3
+        return ;
e7076f3
+      }
e7076f3
+      if (getfilecon(printerfile, &devcon) == -1)
e7076f3
+      {
e7076f3
+        cupsdLogMessage(CUPSD_LOG_ERROR, "StartJob: Unable to get the SELinux context of %s",
e7076f3
+                        printerfile);
e7076f3
+        cupsdCancelJob(job, 0, IPP_JOB_ABORTED);
e7076f3
+        return ;
e7076f3
+      }
e7076f3
+      printercon = context_new(devcon);
e7076f3
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "StartJob: printer context %s client context %s",
e7076f3
+                      context_str(printercon), job->scon);
e7076f3
+      context_free(printercon);
75d0e82
+
e7076f3
+      if (avc_context_to_sid(devcon, &psid) != 0)
e7076f3
+      {
e7076f3
+        cupsdLogMessage(CUPSD_LOG_ERROR,
e7076f3
+                        "StartJob: Unable to determine the SELinux sid for the printer");
e7076f3
+        freecon(devcon);
e7076f3
+        cupsdCancelJob(job, 0, IPP_JOB_ABORTED);
e7076f3
+        return ;
e7076f3
+      }
e7076f3
+      freecon(devcon);
75d0e82
+
e7076f3
+      if (avc_has_perm(clisid, psid, tclass, avr, &avcref, NULL) != 0)
e7076f3
+      {
e7076f3
+       /*
e7076f3
+        * The access check failed, so cancel the job and send an audit message
e7076f3
+        */
e7076f3
+        if (AuditLog != -1)
e7076f3
+        {
e7076f3
+          audit_message = NULL;
e7076f3
+          cupsdSetStringf(&audit_message, "job=%d auid=%u acct=%s obj=%s canceled"
e7076f3
+                                          " unable to access printer=%s", job->id,
e7076f3
+                          job->auid, (job->username)?job->username:"?", job->scon, printer->name);
e7076f3
+          audit_log_user_message(AuditLog, AUDIT_USER_LABELED_EXPORT, audit_message,
e7076f3
+                                 ServerName, NULL, NULL, 0);
e7076f3
+          cupsdClearString(&audit_message);
e7076f3
+        }
75d0e82
+
e7076f3
+        cupsdCancelJob(job, 0, IPP_JOB_ABORTED);
75d0e82
+
e7076f3
+        return ;
e7076f3
+      }
e7076f3
+    }
e7076f3
+  }
e7076f3
+#endif /* WITH_LSPP */
75d0e82
+
e7076f3
  /*
e7076f3
   * Determine if we are printing a banner page or not...
e7076f3
   */
e7076f3
@@ -2883,6 +3103,18 @@ start_job(cupsd_job_t     *job,		/* I - 
e7076f3
 	  banner_page)
e7076f3
         continue;
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+     /*
e7076f3
+      * In LSPP mode refuse to honor the page-label
e7076f3
+      */
e7076f3
+      if (is_lspp_config() &&
e7076f3
+          !strcmp(attr->name, "page-label"))
e7076f3
+      {
e7076f3
+        cupsdLogMessage(CUPSD_LOG_DEBUG, "Ignoring page-label option due to LSPP mode");
e7076f3
+        continue;
e7076f3
+      }
e7076f3
+#endif /* WITH_LSPP */
75d0e82
+
e7076f3
      /*
e7076f3
       * Otherwise add them to the list...
e7076f3
       */
e7076f3
@@ -3125,6 +3357,67 @@ start_job(cupsd_job_t     *job,		/* I - 
e7076f3
     }
e7076f3
   }
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+  if (is_lspp_config())
e7076f3
+  {
e7076f3
+    if (!job->scon || strncmp(job->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) == 0)
e7076f3
+    {
e7076f3
+      if (AuditLog != -1)
e7076f3
+      {
e7076f3
+        audit_message = NULL;
e7076f3
+        cupsdSetStringf(&audit_message, "job=%d auid=%u acct=%s printer=%s title=%s",
e7076f3
+                        job->id, job->auid, job->username, printer->name, title);
e7076f3
+        audit_log_user_message(AuditLog, AUDIT_USER_UNLABELED_EXPORT, audit_message,
e7076f3
+                               ServerName, NULL, NULL, 1);
e7076f3
+        cupsdClearString(&audit_message);
e7076f3
+      }
e7076f3
+    }
e7076f3
+    else 
e7076f3
+    {
e7076f3
+      jobcon = context_new(job->scon);
75d0e82
+
e7076f3
+      if ((attr = ippFindAttribute(job->attrs, "job-sheets", IPP_TAG_NAME)) == NULL)
e7076f3
+        label_template = strdup(Classification);
e7076f3
+      else if (attr->num_values > 1 &&
e7076f3
+               strcmp(attr->values[1].string.text, "none") != 0)
e7076f3
+        label_template = strdup(attr->values[1].string.text);
e7076f3
+      else
e7076f3
+        label_template = strdup(attr->values[0].string.text);
75d0e82
+
e7076f3
+      if (strcasecmp(label_template, MLS_CONFIG) == 0)
e7076f3
+        mls_label = context_range_get(jobcon);
e7076f3
+      else if (strcasecmp(label_template, TE_CONFIG) == 0)
e7076f3
+        mls_label = context_type_get(jobcon);
e7076f3
+      else if (strcasecmp(label_template, SELINUX_CONFIG) == 0)
e7076f3
+        mls_label = context_str(jobcon);
e7076f3
+      else
e7076f3
+        mls_label = label_template;
75d0e82
+
e7076f3
+      if (mls_label && (PerPageLabels || banner_page))
e7076f3
+      {
e7076f3
+        snprintf(classification, sizeof(classification), "CLASSIFICATION=LSPP:%s", mls_label);
e7076f3
+        envp[envc ++] = classification;
e7076f3
+      }
75d0e82
+
e7076f3
+      if ((AuditLog != -1) && !banner_page)
e7076f3
+      {
e7076f3
+        audit_message = NULL;
e7076f3
+        cupsdSetStringf(&audit_message, "job=%d auid=%u acct=%s printer=%s title=%s"
e7076f3
+                        " obj=%s label=%s", job->id, job->auid, job->username,
e7076f3
+                        printer->name, title, job->scon, mls_label?mls_label:"none");
e7076f3
+        audit_log_user_message(AuditLog, AUDIT_USER_LABELED_EXPORT, audit_message,
e7076f3
+                               ServerName, NULL, NULL, 1);
e7076f3
+        cupsdClearString(&audit_message);
e7076f3
+      }
e7076f3
+      context_free(jobcon);
e7076f3
+      free(label_template);
e7076f3
+    }
e7076f3
+  }
e7076f3
+  else
e7076f3
+   /*
e7076f3
+    * Fall through to the non-LSPP behavior
e7076f3
+    */
e7076f3
+#endif /* WITH_LSPP */
e7076f3
   if (Classification && !banner_page)
e7076f3
   {
e7076f3
     if ((attr = ippFindAttribute(job->attrs, "job-sheets",
9161be1
--- cups-1.3.7/scheduler/printers.c.lspp	2008-05-30 16:59:10.000000000 +0100
9161be1
+++ cups-1.3.7/scheduler/printers.c	2008-05-30 16:59:10.000000000 +0100
e7076f3
@@ -51,6 +51,8 @@
e7076f3
  *                                 printing desktop tools.
e7076f3
  */
e7076f3
 
e7076f3
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
75d0e82
+
e7076f3
 /*
e7076f3
  * Include necessary headers...
e7076f3
  */
e7076f3
@@ -74,6 +76,10 @@ static void	write_irix_config(cupsd_prin
e7076f3
 static void	write_irix_state(cupsd_printer_t *p);
e7076f3
 #endif /* __sgi */
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+#  include <libaudit.h>
e7076f3
+#  include <selinux/context.h>
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 
e7076f3
 /*
e7076f3
  * 'cupsdAddPrinter()' - Add a printer to the system.
e7076f3
@@ -1817,6 +1823,13 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)
e7076f3
 		{			/* No authentication */
e7076f3
 		  "none"
e7076f3
 		};
e7076f3
+#ifdef WITH_LSPP
e7076f3
+  char		*audit_message;		/* Audit message string */
e7076f3
+  char		*printerfile;		/* Path to a local printer dev */
e7076f3
+  char		*rangestr;		/* Printer's range if its available */
e7076f3
+  security_context_t	devcon;		/* Printer SELinux context */
e7076f3
+  context_t	printercon;		/* context_t for the printer */
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 
e7076f3
 
e7076f3
   DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p->name,
e7076f3
@@ -1960,6 +1973,44 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)
e7076f3
       attr->values[1].string.text = _cupsStrAlloc(Classification ?
e7076f3
 	                                   Classification : p->job_sheets[1]);
e7076f3
     }
e7076f3
+#ifdef WITH_LSPP
e7076f3
+    if (AuditLog != -1)
e7076f3
+    {
e7076f3
+      char uri[HTTP_MAX_URI];
e7076f3
+      audit_message = NULL;
e7076f3
+      rangestr = NULL;
e7076f3
+      printercon = 0;
e7076f3
+      printerfile = strstr(p->device_uri, "/dev/");
e7076f3
+      if (printerfile == NULL && (strncmp(p->device_uri, "file:/", 6) == 0))
e7076f3
+        printerfile = strdup(p->device_uri + strlen("file:/"));
75d0e82
+
e7076f3
+      if (printerfile != NULL)
e7076f3
+      {
e7076f3
+        if (getfilecon(printerfile, &devcon) == -1)
e7076f3
+          cupsdLogMessage(CUPSD_LOG_ERROR, "cupsdSetPrinterAttrs: Unable to get printer context");
e7076f3
+        else
e7076f3
+        {
e7076f3
+          printercon = context_new(devcon);
e7076f3
+          freecon(devcon);
e7076f3
+        }
e7076f3
+      }
75d0e82
+
e7076f3
+      if (printercon && context_range_get(printercon))
e7076f3
+        rangestr = strdup(context_range_get(printercon));
e7076f3
+      else
e7076f3
+        rangestr = strdup("unknown");
75d0e82
+
e7076f3
+      cupsdSanitizeURI(p->device_uri, uri, sizeof(uri));
e7076f3
+      cupsdSetStringf(&audit_message, "printer=%s uri=%s banners=%s,%s range=%s",
e7076f3
+                      p->name, uri, p->job_sheets[0], p->job_sheets[1], rangestr);
e7076f3
+      audit_log_user_message(AuditLog, AUDIT_LABEL_LEVEL_CHANGE, audit_message,
e7076f3
+                             ServerName, NULL, NULL, 1);
e7076f3
+      if (printercon)
e7076f3
+        context_free(printercon);
e7076f3
+      free(rangestr);
e7076f3
+      cupsdClearString(&audit_message);
e7076f3
+    }
e7076f3
+#endif /* WITH_LSPP */
e7076f3
   }
e7076f3
 
e7076f3
   p->raw    = 0;
9161be1
--- cups-1.3.7/scheduler/conf.c.lspp	2008-05-30 16:59:10.000000000 +0100
9161be1
+++ cups-1.3.7/scheduler/conf.c	2008-05-30 16:59:10.000000000 +0100
e7076f3
@@ -26,6 +26,7 @@
e7076f3
  *   read_configuration()     - Read a configuration file.
e7076f3
  *   read_location()          - Read a <Location path> definition.
e7076f3
  *   read_policy()            - Read a <Policy name> definition.
e7076f3
+ *   is_lspp_config()         - Is the system configured for LSPP
e7076f3
  */
e7076f3
 
e7076f3
 /*
e7076f3
@@ -47,6 +48,9 @@
e7076f3
 #  define INADDR_NONE	0xffffffff
e7076f3
 #endif /* !INADDR_NONE */
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+#  include <libaudit.h>
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 
e7076f3
 /*
e7076f3
  * Configuration variable structure...
e7076f3
@@ -160,6 +164,10 @@ static const cupsd_var_t	variables[] =
e7076f3
 #  if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
e7076f3
   { "ServerKey",		&ServerKey,		CUPSD_VARTYPE_PATHNAME },
e7076f3
 #  endif /* HAVE_LIBSSL || HAVE_GNUTLS */
e7076f3
+#ifdef WITH_LSPP
e7076f3
+  { "AuditLog",			&AuditLog,		CUPSD_VARTYPE_INTEGER },
e7076f3
+  { "PerPageLabels",		&PerPageLabels,		CUPSD_VARTYPE_BOOLEAN },
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 #endif /* HAVE_SSL */
e7076f3
   { "ServerName",		&ServerName,		CUPSD_VARTYPE_STRING },
e7076f3
   { "ServerRoot",		&ServerRoot,		CUPSD_VARTYPE_PATHNAME },
e7076f3
@@ -350,6 +358,9 @@ cupsdReadConfiguration(void)
e7076f3
 		*old_requestroot;	/* Old RequestRoot */
e7076f3
   const char	*tmpdir;		/* TMPDIR environment variable */
e7076f3
   struct stat	tmpinfo;		/* Temporary directory info */
e7076f3
+#ifdef WITH_LSPP
e7076f3
+  char		*audit_message;		/* Audit message string */
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 
e7076f3
 
e7076f3
  /*
e7076f3
@@ -611,6 +622,25 @@ cupsdReadConfiguration(void)
e7076f3
 
e7076f3
   RunUser = getuid();
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+  if (AuditLog != -1)
e7076f3
+  {
e7076f3
+   /*
e7076f3
+    * ClassifyOverride is set during read_configuration, if its ON, report it now
e7076f3
+    */
e7076f3
+    if (ClassifyOverride)
e7076f3
+      audit_log_user_message(AuditLog, AUDIT_USYS_CONFIG,
e7076f3
+                "[Config] ClassifyOverride=enabled Users can override print banners",
e7076f3
+                ServerName, NULL, NULL, 1);
e7076f3
+   /*
e7076f3
+    * PerPageLabel is set during read_configuration, if its OFF, report it now
e7076f3
+    */
e7076f3
+    if (!PerPageLabels)
e7076f3
+      audit_log_user_message(AuditLog, AUDIT_USYS_CONFIG,
e7076f3
+                "[Config] PerPageLabels=disabled", ServerName, NULL, NULL, 1);
e7076f3
+  }
e7076f3
+#endif /* WITH_LSPP */
75d0e82
+
e7076f3
  /*
e7076f3
   * See if the ServerName is an IP address...
e7076f3
   */
e7076f3
@@ -885,11 +915,23 @@ cupsdReadConfiguration(void)
e7076f3
   if (MaxActiveJobs > (MaxFDs / 3))
e7076f3
     MaxActiveJobs = MaxFDs / 3;
e7076f3
 
e7076f3
-  if (Classification && !strcasecmp(Classification, "none"))
e7076f3
+  if (Classification && strcasecmp(Classification, "none") == 0)
e7076f3
     cupsdClearString(&Classification);
e7076f3
 
e7076f3
   if (Classification)
e7076f3
+  {
e7076f3
     cupsdLogMessage(CUPSD_LOG_INFO, "Security set to \"%s\"", Classification);
e7076f3
+#ifdef WITH_LSPP
e7076f3
+    if (AuditLog != -1)
e7076f3
+    {
e7076f3
+      audit_message = NULL;
e7076f3
+      cupsdSetStringf(&audit_message, "[Config] Classification=%s", Classification);
e7076f3
+      audit_log_user_message(AuditLog, AUDIT_LABEL_LEVEL_CHANGE, audit_message,
e7076f3
+                             ServerName, NULL, NULL, 1);
e7076f3
+      cupsdClearString(&audit_message);
e7076f3
+    }
e7076f3
+#endif /* WITH_LSPP */
e7076f3
+  }
e7076f3
 
e7076f3
  /*
e7076f3
   * Update the MaxClientsPerHost value, as needed...
e7076f3
@@ -3379,6 +3421,18 @@ read_policy(cups_file_t *fp,		/* I - Con
e7076f3
   return (0);
e7076f3
 }
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+int is_lspp_config()
e7076f3
+{
e7076f3
+  if (Classification != NULL)
e7076f3
+    return ((strcasecmp(Classification, MLS_CONFIG) == 0) 
e7076f3
+            || (strcasecmp(Classification, TE_CONFIG) == 0)
e7076f3
+            || (strcasecmp(Classification, SELINUX_CONFIG) == 0));
e7076f3
+  else
e7076f3
+    return 0;
e7076f3
+}
e7076f3
+#endif /* WITH_LSPP */
75d0e82
+
e7076f3
 
e7076f3
 /*
e7076f3
  * End of "$Id: conf.c 7382 2008-03-20 04:06:01Z mike $".
e7076f3
--- cups-1.3.7/scheduler/job.h.lspp	2008-01-16 22:20:33.000000000 +0000
9161be1
+++ cups-1.3.7/scheduler/job.h	2008-05-30 16:59:31.000000000 +0100
e7076f3
@@ -13,6 +13,13 @@
e7076f3
  *   file is missing or damaged, see the license at "http://www.cups.org/".
e7076f3
  */
e7076f3
 
e7076f3
+/* Copyright (C) 2005 Trusted Computer Solutions, Inc. */
e7076f3
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
75d0e82
+
e7076f3
+#ifdef WITH_LSPP
e7076f3
+#include <selinux/selinux.h>
e7076f3
+#endif /* WITH_LSPP */
75d0e82
+
e7076f3
 /*
e7076f3
  * Job request structure...
e7076f3
  */
e7076f3
@@ -60,6 +67,10 @@ typedef struct cupsd_job_s
e7076f3
   krb5_ccache		ccache;		/* Kerberos credential cache */
e7076f3
   char			*ccname;	/* KRB5CCNAME environment variable */
e7076f3
 #endif /* HAVE_GSSAPI */
e7076f3
+#ifdef WITH_LSPP
e7076f3
+  security_context_t	scon;		/* Security context of job */
e7076f3
+  uid_t			auid;		/* Audit loginuid for this job */
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 } cupsd_job_t;
e7076f3
 
e7076f3
 
9161be1
--- cups-1.3.7/scheduler/main.c.lspp	2008-05-30 16:59:10.000000000 +0100
9161be1
+++ cups-1.3.7/scheduler/main.c	2008-05-30 16:59:10.000000000 +0100
e7076f3
@@ -35,6 +35,8 @@
e7076f3
  *   usage()                   - Show scheduler usage.
e7076f3
  */
e7076f3
 
e7076f3
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
75d0e82
+
e7076f3
 /*
e7076f3
  * Include necessary headers...
e7076f3
  */
e7076f3
@@ -73,6 +75,9 @@
e7076f3
 #  include <dlfcn.h>
e7076f3
 #endif /* __APPLE__ && HAVE_DLFCN_H */
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+#  include <libaudit.h>
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 
e7076f3
 /*
e7076f3
  * Local functions...
e7076f3
@@ -154,6 +159,9 @@ main(int  argc,				/* I - Number of comm
e7076f3
   int			launchd_idle_exit;
e7076f3
 					/* Idle exit on select timeout? */
e7076f3
 #endif	/* HAVE_LAUNCHD */
e7076f3
+#if WITH_LSPP
e7076f3
+  auditfail_t           failmode;       /* Action for audit_open failure */
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 
e7076f3
 
e7076f3
 #ifdef HAVE_GETEUID
e7076f3
@@ -413,6 +421,25 @@ main(int  argc,				/* I - Number of comm
e7076f3
 #endif /* DEBUG */
e7076f3
   }
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+  if ((AuditLog = audit_open()) < 0 )
e7076f3
+  {
e7076f3
+    if (get_auditfail_action(&failmode) == 0)
e7076f3
+    {
e7076f3
+      if (failmode == FAIL_LOG)
e7076f3
+      {
e7076f3
+        cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to connect to audit subsystem.");
e7076f3
+        AuditLog = -1;
e7076f3
+      }
e7076f3
+      else if (failmode == FAIL_TERMINATE)
e7076f3
+      {
e7076f3
+        fprintf(stderr, "cupsd: unable to start auditing, terminating");
e7076f3
+        return -1;
e7076f3
+      }
e7076f3
+    }
e7076f3
+  }
e7076f3
+#endif /* WITH_LSPP */
75d0e82
+
e7076f3
  /*
e7076f3
   * Set the timezone info...
e7076f3
   */
e7076f3
@@ -1160,6 +1187,11 @@ main(int  argc,				/* I - Number of comm
e7076f3
 
e7076f3
   cupsdStopSelect();
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+  if (AuditLog != -1)
e7076f3
+    audit_close(AuditLog);
e7076f3
+#endif /* WITH_LSPP */
75d0e82
+
e7076f3
   return (!stop_scheduler);
e7076f3
 }
e7076f3
 
fada3a1
--- cups-1.3.7/scheduler/ipp.c	2008-05-30 17:01:08.000000000 +0100
fada3a1
+++ cups-1.3.7/scheduler/ipp.c	2008-07-01 12:30:59.000000000 +0100
e7076f3
@@ -36,6 +36,7 @@
e7076f3
  *   cancel_all_jobs()           - Cancel all print jobs.
e7076f3
  *   cancel_job()                - Cancel a print job.
e7076f3
  *   cancel_subscription()       - Cancel a subscription.
e7076f3
+ *   check_context()             - Check the SELinux context for a user and job
e7076f3
  *   check_quotas()              - Check quotas for a printer and user.
e7076f3
  *   copy_attribute()            - Copy a single attribute.
e7076f3
  *   copy_attrs()                - Copy attributes from one request to another.
e7076f3
@@ -93,6 +94,9 @@
e7076f3
  *   validate_user()             - Validate the user for the request.
e7076f3
  */
e7076f3
 
e7076f3
+/* Copyright (C) 2005 Trusted Computer Solutions, Inc. */
e7076f3
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
75d0e82
+
e7076f3
 /*
e7076f3
  * Include necessary headers...
e7076f3
  */
fada3a1
@@ -116,6 +120,14 @@
e7076f3
 #  endif /* HAVE_MEMBERSHIPPRIV_H */
e7076f3
 #endif /* __APPLE__ */
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+#include <libaudit.h>
e7076f3
+#include <selinux/selinux.h>
e7076f3
+#include <selinux/context.h>
e7076f3
+#include <selinux/avc.h>
e7076f3
+#include <selinux/flask.h>
e7076f3
+#include <selinux/av_permissions.h>
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 
e7076f3
 /*
e7076f3
  * Local functions...
fada3a1
@@ -140,6 +152,9 @@
e7076f3
 static void	cancel_all_jobs(cupsd_client_t *con, ipp_attribute_t *uri);
e7076f3
 static void	cancel_job(cupsd_client_t *con, ipp_attribute_t *uri);
e7076f3
 static void	cancel_subscription(cupsd_client_t *con, int id);
e7076f3
+#ifdef WITH_LSPP
e7076f3
+static int	check_context(cupsd_client_t *con, cupsd_job_t *job);
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 static int	check_quotas(cupsd_client_t *con, cupsd_printer_t *p);
e7076f3
 static ipp_attribute_t	*copy_attribute(ipp_t *to, ipp_attribute_t *attr,
e7076f3
 		                        int quickcopy);
fada3a1
@@ -1267,6 +1282,21 @@
e7076f3
   int		kbytes;			/* Size of print file */
e7076f3
   int		i;			/* Looping var */
e7076f3
   int		lowerpagerange;		/* Page range bound */
e7076f3
+#ifdef WITH_LSPP
e7076f3
+  char		*audit_message;		/* Audit message string */
e7076f3
+  char		*printerfile;		/* device file pointed to by the printer */
e7076f3
+  char		*userheader = NULL;	/* User supplied job-sheets[0] */
e7076f3
+  char		*userfooter = NULL;	/* User supplied job-sheets[1] */
e7076f3
+  int		override = 0;		/* Was a banner overrode on a job */
e7076f3
+  security_id_t	clisid;			/* SELinux SID for the client */
e7076f3
+  security_id_t	psid;			/* SELinux SID for the printer */
e7076f3
+  context_t	printercon;		/* Printer's context string */
e7076f3
+  struct stat	printerstat;		/* Printer's stat buffer */
e7076f3
+  security_context_t	devcon;		/* Printer's SELinux context */
e7076f3
+  struct avc_entry_ref	avcref;		/* Pointer to the access vector cache */
e7076f3
+  security_class_t	tclass;		/* Object class for the SELinux check */
e7076f3
+  access_vector_t	avr;		/* Access method being requested */
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 
e7076f3
 
e7076f3
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_job(%p[%d], %p(%s), %p(%s/%s))",
fada3a1
@@ -1454,6 +1484,104 @@
e7076f3
     ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL,
e7076f3
                  title = "Untitled");
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+  if (is_lspp_config())
e7076f3
+  {
e7076f3
+    if (!con->scon || strncmp(con->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) == 0)
e7076f3
+    {
e7076f3
+      cupsdLogMessage(CUPSD_LOG_ERROR, "add_job: missing classification for connection \'%s\'!", printer->name);
e7076f3
+      send_ipp_status(con, IPP_INTERNAL_ERROR, _("Missing required security attributes."));
e7076f3
+      return (NULL);
e7076f3
+    }
75d0e82
+
e7076f3
+   /*
e7076f3
+    * Perform an access check so that if the user gets feedback at enqueue time
e7076f3
+    */
75d0e82
+
e7076f3
+    printerfile = strstr(printer->device_uri, "/dev/");
e7076f3
+    if (printerfile == NULL && (strncmp(printer->device_uri, "file:/", 6) == 0))
e7076f3
+      printerfile = strdup(printer->device_uri + strlen("file:/"));
75d0e82
+
e7076f3
+    if (printerfile != NULL)
e7076f3
+    {
e7076f3
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "add_job: Attempting an access check on printer device %s",
e7076f3
+                      printerfile);
75d0e82
+
e7076f3
+      if (lstat(printerfile, &printerstat) < 0)
e7076f3
+      {
e7076f3
+	if (errno != ENOENT)
e7076f3
+	{
e7076f3
+	  send_ipp_status(con, IPP_NOT_AUTHORIZED, _("Unable to stat the printer"));
e7076f3
+	  return (NULL);
e7076f3
+	}
e7076f3
+	/*
e7076f3
+	 * The printer does not exist, so for now assume it's a FileDevice
e7076f3
+	 */
e7076f3
+	tclass = SECCLASS_FILE;
e7076f3
+	avr = FILE__WRITE;
e7076f3
+      }
e7076f3
+      else if (S_ISCHR(printerstat.st_mode))
e7076f3
+      {
e7076f3
+	tclass = SECCLASS_CHR_FILE;
e7076f3
+	avr = CHR_FILE__WRITE;
e7076f3
+      }
e7076f3
+      else if (S_ISREG(printerstat.st_mode))
e7076f3
+      {
e7076f3
+	tclass = SECCLASS_FILE;
e7076f3
+	avr = FILE__WRITE;
e7076f3
+      }
e7076f3
+      else
e7076f3
+      {
e7076f3
+	send_ipp_status(con, IPP_NOT_AUTHORIZED, _("Printer is not a character device or regular file"));
e7076f3
+	return (NULL);
e7076f3
+      }
e7076f3
+      avc_init("cupsd_enqueue_", NULL, NULL, NULL, NULL);
e7076f3
+      avc_entry_ref_init(&avcref);
e7076f3
+      if (avc_context_to_sid(con->scon, &clisid) != 0)
e7076f3
+      {
e7076f3
+        send_ipp_status(con, IPP_NOT_AUTHORIZED, _("Unable to get the SELinux sid of the client"));
e7076f3
+        return (NULL);
e7076f3
+      }
e7076f3
+      if (getfilecon(printerfile, &devcon) == -1)
e7076f3
+      {
e7076f3
+        send_ipp_status(con, IPP_NOT_AUTHORIZED, _("Unable to get the SELinux context of the printer"));
e7076f3
+        return (NULL);
e7076f3
+      }
e7076f3
+      printercon = context_new(devcon);
e7076f3
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "add_job: printer context %s client context %s",
e7076f3
+                      context_str(printercon), con->scon);
e7076f3
+      context_free(printercon);
75d0e82
+
e7076f3
+      if (avc_context_to_sid(devcon, &psid) != 0)
e7076f3
+      {
e7076f3
+        send_ipp_status(con, IPP_NOT_AUTHORIZED, _("Unable to get the SELinux sid of the printer"));
e7076f3
+        freecon(devcon);
e7076f3
+        return (NULL);
e7076f3
+      }
e7076f3
+      freecon(devcon);
e7076f3
+      if (avc_has_perm(clisid, psid, tclass, avr, &avcref, NULL) != 0)
e7076f3
+      {
e7076f3
+       /*
e7076f3
+        * The access check failed, so cancel the job and send an audit message
e7076f3
+        */
e7076f3
+        if (AuditLog != -1)
e7076f3
+        {
e7076f3
+          audit_message = NULL;
e7076f3
+          cupsdSetStringf(&audit_message, "job=? auid=%u acct=%s obj=%s refused"
e7076f3
+                          " unable to access printer=%s", con->auid,
e7076f3
+                          con->username, con->scon, printer->name);
e7076f3
+          audit_log_user_message(AuditLog, AUDIT_USER_LABELED_EXPORT, audit_message,
e7076f3
+                                 ServerName, NULL, NULL, 0);
e7076f3
+          cupsdClearString(&audit_message);
e7076f3
+        }
75d0e82
+
e7076f3
+        send_ipp_status(con, IPP_NOT_AUTHORIZED, _("SELinux prohibits access to the printer"));
e7076f3
+        return (NULL);
e7076f3
+      }
e7076f3
+    }
e7076f3
+  }
e7076f3
+#endif /* WITH_LSPP */
75d0e82
+
e7076f3
   if ((job = cupsdAddJob(priority, printer->name)) == NULL)
e7076f3
   {
e7076f3
     send_ipp_status(con, IPP_INTERNAL_ERROR,
fada3a1
@@ -1462,6 +1590,32 @@
e7076f3
     return (NULL);
e7076f3
   }
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+  if (is_lspp_config())
e7076f3
+  {
e7076f3
+   /*
e7076f3
+    * duplicate the security context and auid of the connection into the job structure
e7076f3
+    */
e7076f3
+    job->scon = strdup(con->scon);
e7076f3
+    job->auid = con->auid;
75d0e82
+
e7076f3
+   /* 
e7076f3
+    * add the security context to the request so that on a restart the security
e7076f3
+    * attributes will be able to be restored
e7076f3
+    */
e7076f3
+    ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "security-context", 
e7076f3
+		 NULL, job->scon);
e7076f3
+  }
e7076f3
+  else
e7076f3
+  {
e7076f3
+   /*
e7076f3
+    * Fill in the security context of the job as unlabeled
e7076f3
+    */
e7076f3
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "add_job: setting context of job to %s", UNKNOWN_SL);
e7076f3
+    cupsdSetString(&job->scon, UNKNOWN_SL);
e7076f3
+  }
e7076f3
+#endif /* WITH_LSPP */
75d0e82
+
e7076f3
   job->dtype   = printer->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
e7076f3
                                   CUPS_PRINTER_REMOTE);
e7076f3
   job->attrs   = con->request;
fada3a1
@@ -1668,6 +1822,29 @@
e7076f3
       attr->values[0].string.text = _cupsStrAlloc(printer->job_sheets[0]);
e7076f3
       attr->values[1].string.text = _cupsStrAlloc(printer->job_sheets[1]);
e7076f3
     }
e7076f3
+#ifdef WITH_LSPP
e7076f3
+    else
e7076f3
+    {
e7076f3
+     /*
e7076f3
+      * The option was present, so capture the user supplied strings
e7076f3
+      */
e7076f3
+      userheader = strdup(attr->values[0].string.text);
75d0e82
+
e7076f3
+      if (attr->num_values > 1)
e7076f3
+        userfooter = strdup(attr->values[1].string.text);
e7076f3
+  
e7076f3
+      if (Classification != NULL && (strcmp(userheader, Classification) == 0)
e7076f3
+          && userfooter &&(strcmp(userfooter, Classification) == 0))
e7076f3
+      {
e7076f3
+       /*
e7076f3
+        * Since both values are Classification, the user is not trying to Override
e7076f3
+        */
e7076f3
+        free(userheader);
e7076f3
+        if (userfooter) free(userfooter);
e7076f3
+        userheader = userfooter = NULL;
e7076f3
+      }
e7076f3
+    }
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 
e7076f3
     job->job_sheets = attr;
e7076f3
 
fada3a1
@@ -1698,6 +1875,9 @@
e7076f3
 	                		    "job-sheets=\"%s,none\", "
e7076f3
 					    "job-originating-user-name=\"%s\"",
e7076f3
 	        	 job->id, Classification, job->username);
e7076f3
+#ifdef WITH_LSPP
e7076f3
+          override = 1;
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 	}
e7076f3
 	else if (attr->num_values == 2 &&
e7076f3
 	         strcmp(attr->values[0].string.text,
fada3a1
@@ -1716,6 +1896,9 @@
e7076f3
 					    "job-originating-user-name=\"%s\"",
e7076f3
 	        	 job->id, attr->values[0].string.text,
e7076f3
 			 attr->values[1].string.text, job->username);
e7076f3
+#ifdef WITH_LSPP
e7076f3
+          override = 1;
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 	}
e7076f3
 	else if (strcmp(attr->values[0].string.text, Classification) &&
e7076f3
 	         strcmp(attr->values[0].string.text, "none") &&
fada3a1
@@ -1736,6 +1919,9 @@
e7076f3
 			    "job-originating-user-name=\"%s\"",
e7076f3
 	        	    job->id, attr->values[0].string.text,
e7076f3
 			    attr->values[1].string.text, job->username);
e7076f3
+#ifdef WITH_LSPP
e7076f3
+          override = 1;
e7076f3
+#endif /* WITH_LSPP */
e7076f3
         }
e7076f3
       }
e7076f3
       else if (strcmp(attr->values[0].string.text, Classification) &&
fada3a1
@@ -1776,7 +1962,50 @@
e7076f3
 	                  "job-sheets=\"%s\", "
e7076f3
 			  "job-originating-user-name=\"%s\"",
e7076f3
 	        	 job->id, Classification, job->username);
e7076f3
+#ifdef WITH_LSPP
e7076f3
+        override = 1;
e7076f3
+#endif /* WITH_LSPP */
e7076f3
+      }
e7076f3
+#ifdef WITH_LSPP
e7076f3
+      if (is_lspp_config() && AuditLog != -1)
e7076f3
+      {
e7076f3
+        audit_message = NULL;
75d0e82
+
e7076f3
+        if (userheader || userfooter)
e7076f3
+        {
e7076f3
+          if (!override)
e7076f3
+          {
e7076f3
+           /*
e7076f3
+            * The user overrode the banner, so audit it
e7076f3
+            */
e7076f3
+            cupsdSetStringf(&audit_message, "job=%d user supplied job-sheets=%s,%s"
e7076f3
+                            " using banners=%s,%s", job->id, userheader,
e7076f3
+                            userfooter, attr->values[0].string.text,
e7076f3
+                            (attr->num_values > 1) ? attr->values[1].string.text : "(null)");
e7076f3
+            audit_log_user_message(AuditLog, AUDIT_LABEL_OVERRIDE, audit_message,
e7076f3
+                                   ServerName, NULL, NULL, 1);
e7076f3
+      }
e7076f3
+          else
e7076f3
+          {
e7076f3
+           /*
e7076f3
+            * The user tried to override the banner, audit the failure
e7076f3
+            */
e7076f3
+            cupsdSetStringf(&audit_message, "job=%d user supplied job-sheets=%s,%s"
e7076f3
+                            " ignored banners=%s,%s", job->id, userheader,
e7076f3
+                            userfooter, attr->values[0].string.text,
e7076f3
+                            (attr->num_values > 1) ? attr->values[1].string.text : "(null)");
e7076f3
+            audit_log_user_message(AuditLog, AUDIT_LABEL_OVERRIDE, audit_message,
e7076f3
+                                   ServerName, NULL, NULL, 0);
e7076f3
       }
fada3a1
+          cupsdClearString(&audit_message);
fada3a1
+      }
fada3a1
+    }
fada3a1
+
e7076f3
+      if (userheader)
e7076f3
+        free(userheader);
e7076f3
+      if (userfooter)
e7076f3
+        free(userfooter);
e7076f3
+#endif /* WITH_LSPP */
fada3a1
     }
fada3a1
 
e7076f3
    /*
fada3a1
@@ -3391,6 +3620,103 @@
e7076f3
 }
e7076f3
 
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+/*
e7076f3
+ * 'check_context()' - Check SELinux security context of a user and job
e7076f3
+ */
75d0e82
+
e7076f3
+static int				/* O - 1 if OK, 0 if not, -1 on error */
e7076f3
+check_context(cupsd_client_t *con,	/* I - Client connection */
e7076f3
+             cupsd_job_t    *job)	/* I - Job */
e7076f3
+{
e7076f3
+  int			enforcing;	/* is SELinux in enforcing mode */
e7076f3
+  char			filename[1024]; /* Filename of the spool file */
e7076f3
+  security_id_t		clisid;		/* SELinux SID of the client */
e7076f3
+  security_id_t		jobsid;		/* SELinux SID of the job */
e7076f3
+  security_id_t		filesid;	/* SELinux SID of the spool file */
e7076f3
+  struct avc_entry_ref	avcref;		/* AVC entry cache pointer */
e7076f3
+  security_class_t	tclass;		/* SELinux security class */
e7076f3
+  access_vector_t	avr;		/* SELinux access being queried */
e7076f3
+  security_context_t	spoolfilecon;	/* SELinux context of the spool file */
75d0e82
+
75d0e82
+
e7076f3
+ /*
e7076f3
+  * Validate the input to be sure there are contexts to work with...
e7076f3
+  */
75d0e82
+
e7076f3
+  if (con->scon == NULL || job->scon == NULL
e7076f3
+      || strncmp(con->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) == 0
e7076f3
+      || strncmp(job->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) == 0)
e7076f3
+    return -1;
75d0e82
+
e7076f3
+  if ((enforcing = security_getenforce()) == -1)
e7076f3
+  {
e7076f3
+    cupsdLogMessage(CUPSD_LOG_ERROR, "Error while determining SELinux enforcement");
e7076f3
+    return -1;
e7076f3
+  }
e7076f3
+  cupsdLogMessage(CUPSD_LOG_DEBUG, "check_context: client context %s job context %s", con->scon, job->scon);
75d0e82
+
75d0e82
+
e7076f3
+ /*
e7076f3
+  * Initialize the avc engine...
e7076f3
+  */
75d0e82
+
e7076f3
+  if (avc_init("cupsd", NULL, NULL, NULL, NULL) < 0)
e7076f3
+  {
e7076f3
+    cupsdLogMessage(CUPSD_LOG_ERROR, "check_context: unable avc_init");
e7076f3
+    return -1;
e7076f3
+  } 
e7076f3
+  if (avc_context_to_sid(con->scon, &clisid) != 0)
e7076f3
+  {
e7076f3
+    cupsdLogMessage(CUPSD_LOG_ERROR, "check_context: unable to convert %s to SELinux sid", con->scon);
e7076f3
+    return -1;
e7076f3
+  }
e7076f3
+  avc_context_to_sid(job->scon, &jobsid);
e7076f3
+  avc_entry_ref_init(&avcref);
e7076f3
+  tclass = SECCLASS_FILE;
e7076f3
+  avr = FILE__READ;
75d0e82
+
e7076f3
+ /*
e7076f3
+  * Perform the check with the client as the subject, first with the job as the object
e7076f3
+  *   if that fails then with the spool file as the object...
e7076f3
+  */
75d0e82
+
e7076f3
+  if (avc_has_perm_noaudit(clisid, jobsid, tclass, avr, &avcref, NULL) != 0)
e7076f3
+  {
e7076f3
+    cupsdLogMessage(CUPSD_LOG_INFO, "check_context: SELinux denied access based on the client context");
75d0e82
+
e7076f3
+    snprintf(filename, sizeof(filename), "%s/c%05d", RequestRoot, job->id);
e7076f3
+    if (getfilecon(filename, &spoolfilecon) == -1)
e7076f3
+    {
e7076f3
+      cupsdLogMessage(CUPSD_LOG_ERROR, "check_context: Unable to get spoolfile context");
e7076f3
+      return -1;
e7076f3
+    }
e7076f3
+    if (avc_context_to_sid(spoolfilecon, &filesid) != 0)
e7076f3
+    {
e7076f3
+      cupsdLogMessage(CUPSD_LOG_ERROR, "check_context: Unable to determine the SELinux sid for the spool file");
e7076f3
+      freecon(spoolfilecon);
e7076f3
+      return -1;
e7076f3
+    }
e7076f3
+    freecon(spoolfilecon);
e7076f3
+    if (avc_has_perm_noaudit(clisid, filesid, tclass, avr, &avcref, NULL) != 0)
e7076f3
+    {
e7076f3
+      cupsdLogMessage(CUPSD_LOG_INFO, "check_context: SELinux denied access to the spool file");
e7076f3
+      return 0;
e7076f3
+    }
e7076f3
+    cupsdLogMessage(CUPSD_LOG_INFO, "check_context: SELinux allowed access to the spool file");
e7076f3
+    return 1;
e7076f3
+  }
e7076f3
+  else
e7076f3
+    if (enforcing == 0)
e7076f3
+        cupsdLogMessage(CUPSD_LOG_INFO, "check_context: allowing operation due to permissive mode");
e7076f3
+    else
e7076f3
+        cupsdLogMessage(CUPSD_LOG_INFO, "check_context: SELinux allowed access based on the client context");
75d0e82
+
e7076f3
+  return 1;
e7076f3
+}
e7076f3
+#endif /* WITH_LSPP */
75d0e82
+
75d0e82
+
e7076f3
 /*
e7076f3
  * 'check_quotas()' - Check quotas for a printer and user.
e7076f3
  */
fada3a1
@@ -3912,6 +4238,15 @@
e7076f3
   char		attrname[255],		/* Name of attribute */
e7076f3
 		*s;			/* Pointer into name */
e7076f3
   ipp_attribute_t *attr;		/* Attribute */
e7076f3
+#ifdef WITH_LSPP
e7076f3
+  const char	*mls_label;		/* SL of print job */
e7076f3
+  char		*jobrange;		/* SELinux sensitivity range */
e7076f3
+  char		*jobclearance;		/* SELinux low end clearance */
e7076f3
+  context_t	jobcon;			/* SELinux context of the job */
e7076f3
+  context_t	tmpcon;			/* Temp context to set the level */
e7076f3
+  security_context_t	spoolcon;	/* Context of the file in the spool */
e7076f3
+#endif /* WITH_LSPP */
75d0e82
+
f4b6623
 
e7076f3
 
e7076f3
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "copy_banner(%p[%d], %p[%d], %s)",
fada3a1
@@ -3946,6 +4281,82 @@
e7076f3
 
e7076f3
   fchmod(cupsFileNumber(out), 0640);
e7076f3
   fchown(cupsFileNumber(out), RunUser, Group);
e7076f3
+#ifdef WITH_LSPP
fada3a1
+  if (job->scon != NULL &&
fada3a1
+      strncmp(job->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) != 0)
e7076f3
+  {
e7076f3
+    if (getfilecon(filename, &spoolcon) == -1)
e7076f3
+    {
e7076f3
+      cupsdLogMessage(CUPSD_LOG_ERROR,
e7076f3
+                      "copy_banner: Unable to get the context of the banner file %s - %s",
e7076f3
+                      filename, strerror(errno));
e7076f3
+      job->num_files --;
e7076f3
+      return (0);
e7076f3
+    }
e7076f3
+    tmpcon = context_new(spoolcon);
fada3a1
+    jobcon = context_new(job->scon);
e7076f3
+    freecon(spoolcon);
e7076f3
+    if (!tmpcon || !jobcon)
e7076f3
+    {
e7076f3
+      if (tmpcon)
e7076f3
+        context_free(tmpcon);
e7076f3
+      if (jobcon)
e7076f3
+        context_free(jobcon);
e7076f3
+      cupsdLogMessage(CUPSD_LOG_ERROR,
e7076f3
+                      "copy_banner: Unable to get the SELinux contexts");
e7076f3
+      job->num_files --;
e7076f3
+      return (0);
e7076f3
+    }
e7076f3
+    jobrange = context_range_get(jobcon);
e7076f3
+    if (jobrange)
e7076f3
+    {
e7076f3
+      jobrange = strdup(jobrange);
e7076f3
+      if ((jobclearance = strtok(jobrange, "-")) != NULL)
e7076f3
+      {
e7076f3
+	if (context_range_set(tmpcon, jobclearance) == -1)
e7076f3
+	{
e7076f3
+	  cupsdLogMessage(CUPSD_LOG_ERROR,
e7076f3
+			  "copy_banner: Unable to set the level of the context for file %s - %s",
e7076f3
+			  filename, strerror(errno));
e7076f3
+	  free(jobrange);
e7076f3
+	  context_free(jobcon);
e7076f3
+	  context_free(tmpcon);
e7076f3
+	  job->num_files --;
e7076f3
+	  return (0);
e7076f3
+	}
e7076f3
+      }
e7076f3
+      else
e7076f3
+      {
e7076f3
+	if (context_range_set(tmpcon, (context_range_get(jobcon))) == -1)
e7076f3
+	{
e7076f3
+	  cupsdLogMessage(CUPSD_LOG_ERROR,
e7076f3
+			  "copy_banner: Unable to set the level of the context for file %s - %s",
e7076f3
+			  filename, strerror(errno));
e7076f3
+	  free(jobrange);
e7076f3
+	  context_free(jobcon);
e7076f3
+	  context_free(tmpcon);
e7076f3
+	  job->num_files --;
e7076f3
+	  return (0);
e7076f3
+	}
e7076f3
+      }
e7076f3
+      free(jobrange);
e7076f3
+    }
e7076f3
+    if (setfilecon(filename, context_str(tmpcon)) == -1)
e7076f3
+    {
e7076f3
+      cupsdLogMessage(CUPSD_LOG_ERROR,
e7076f3
+                      "copy_banner: Unable to set the context of the banner file %s - %s",
e7076f3
+                      filename, strerror(errno));
e7076f3
+      context_free(jobcon);
e7076f3
+      context_free(tmpcon);
e7076f3
+      job->num_files --;
e7076f3
+      return (0);
e7076f3
+    }
e7076f3
+    cupsdLogMessage(CUPSD_LOG_DEBUG2, "copy_banner: %s set to %s",
e7076f3
+                    filename, context_str(tmpcon));
e7076f3
+    context_free(jobcon);
e7076f3
+    context_free(tmpcon);
e7076f3
+  }
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 
e7076f3
  /*
e7076f3
   * Try the localized banner file under the subdirectory...
fada3a1
@@ -4040,6 +4451,24 @@
e7076f3
       else
e7076f3
         s = attrname;
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+      if (strcmp(s, "mls-label") == 0)
e7076f3
+      {
fada3a1
+        if (job->scon != NULL && strncmp(job->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) != 0)
e7076f3
+        {
fada3a1
+          jobcon = context_new(job->scon);
e7076f3
+          if (strcasecmp(name, MLS_CONFIG) == 0)
e7076f3
+            mls_label = context_range_get(jobcon);
e7076f3
+          else if (strcasecmp(name, TE_CONFIG) == 0)
e7076f3
+            mls_label = context_type_get(jobcon);
e7076f3
+          else // default to using the whole context string
e7076f3
+            mls_label = context_str(jobcon);
e7076f3
+          cupsFilePuts(out, mls_label);
e7076f3
+          context_free(jobcon);
e7076f3
+        }
e7076f3
+        continue;
e7076f3
+      }
e7076f3
+#endif /* WITH_LSPP */
e7076f3
       if (!strcmp(s, "printer-name"))
e7076f3
       {
e7076f3
         cupsFilePuts(out, job->dest);
fada3a1
@@ -5765,6 +6194,22 @@
e7076f3
     return;
e7076f3
   }
e7076f3
 
75d0e82
+
e7076f3
+#ifdef WITH_LSPP
e7076f3
+ /*
e7076f3
+  * Check SELinux...
e7076f3
+  */
e7076f3
+  if (is_lspp_config() && check_context(con, job) != 1)
e7076f3
+  {
e7076f3
+   /*
e7076f3
+    * Unfortunately we have to lie to the user...
e7076f3
+    */
e7076f3
+    send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid);
e7076f3
+    return;
e7076f3
+  }
e7076f3
+#endif /* WITH_LSPP */
75d0e82
+
75d0e82
+
e7076f3
  /*
e7076f3
   * Copy attributes...
e7076f3
   */
fada3a1
@@ -5970,6 +6415,11 @@
e7076f3
     if (count > 0)
e7076f3
       ippAddSeparator(con->response);
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+    if (is_lspp_config() && check_context(con, job) != 1)
e7076f3
+      continue;
e7076f3
+#endif /* WITH_LSPP */
75d0e82
+
e7076f3
     count ++;
e7076f3
 
e7076f3
     cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs: count = %d", count);
fada3a1
@@ -10042,6 +10492,11 @@
e7076f3
 
e7076f3
   strlcpy(username, get_username(con), userlen);
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+  if (is_lspp_config() && check_context(con, job) != 1)
e7076f3
+    return 0;
e7076f3
+#endif /* WITH_LSPP */
75d0e82
+
e7076f3
  /*
e7076f3
   * Check the username against the owner...
e7076f3
   */
9161be1
--- cups-1.3.7/scheduler/conf.h.lspp	2008-05-30 16:59:10.000000000 +0100
9161be1
+++ cups-1.3.7/scheduler/conf.h	2008-05-30 16:59:10.000000000 +0100
e7076f3
@@ -193,6 +193,12 @@ VAR char		*ServerKey		VALUE(NULL);
e7076f3
 					/* Server key file */
e7076f3
 #  endif /* HAVE_LIBSSL || HAVE_GNUTLS */
e7076f3
 #endif /* HAVE_SSL */
e7076f3
+#ifdef WITH_LSPP
e7076f3
+VAR int			AuditLog		VALUE(-1),
e7076f3
+					/* File descriptor for audit */
e7076f3
+			PerPageLabels		VALUE(TRUE);
e7076f3
+					/* Put the label on each page */
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 
e7076f3
 #ifdef HAVE_LAUNCHD
e7076f3
 VAR int			LaunchdTimeout		VALUE(DEFAULT_TIMEOUT);
e7076f3
@@ -211,6 +217,9 @@ VAR char		*SystemGroupAuthKey	VALUE(NULL
e7076f3
 					/* System group auth key */
e7076f3
 #endif /* HAVE_AUTHORIZATION_H */
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+extern int	is_lspp_config(void);
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 
e7076f3
 /*
e7076f3
  * Prototypes...
e7076f3
--- cups-1.3.7/scheduler/client.c.lspp	2008-02-12 00:20:32.000000000 +0000
9161be1
+++ cups-1.3.7/scheduler/client.c	2008-05-30 16:59:10.000000000 +0100
e7076f3
@@ -39,12 +39,14 @@
e7076f3
  *   pipe_command()          - Pipe the output of a command to the remote client.
e7076f3
  *   write_file()            - Send a file via HTTP.
e7076f3
  *   write_pipe()            - Flag that data is available on the CGI pipe.
e7076f3
+ *   client_pid_to_auid()    - Get the audit login uid of the client.
e7076f3
  */
e7076f3
 
e7076f3
 /*
cfc9fc5
  * Include necessary headers...
cfc9fc5
  */
cfc9fc5
 
cfc9fc5
+#define _GNU_SOURCE
e7076f3
 #include <cups/http-private.h>
e7076f3
 #include "cupsd.h"
e7076f3
 
e7076f3
@@ -76,6 +78,12 @@ extern const char *cssmErrorString(int e
e7076f3
 #  include <gnutls/x509.h>
e7076f3
 #endif /* HAVE_GNUTLS */
cfc9fc5
 
cfc9fc5
+#ifdef WITH_LSPP
e7076f3
+#include <selinux/selinux.h>
e7076f3
+#include <selinux/context.h>
e7076f3
+#include <fcntl.h>
cfc9fc5
+#endif /* WITH_LSPP */
e7076f3
+
cfc9fc5
 
e7076f3
 /*
e7076f3
  * Local functions...
e7076f3
@@ -349,6 +357,57 @@ cupsdAcceptClient(cupsd_listener_t *lis)
e7076f3
     }
cfc9fc5
   }
cfc9fc5
 
cfc9fc5
+#ifdef WITH_LSPP
e7076f3
+  if (is_lspp_config())
cfc9fc5
+  {
e7076f3
+    struct ucred cr;
e7076f3
+    unsigned int cl=sizeof(cr);
cfc9fc5
+
e7076f3
+    if (getsockopt(con->http.fd, SOL_SOCKET, SO_PEERCRED, &cr, &cl) == 0)
cfc9fc5
+    {
e7076f3
+     /*
e7076f3
+      * client_pid_to_auid() can be racey
e7076f3
+      * In this case the pid is based on a socket connected to the client
e7076f3
+      */
e7076f3
+      if ((con->auid = client_pid_to_auid(cr.pid)) == -1)
cfc9fc5
+      {
e7076f3
+        close(con->http.fd);
e7076f3
+        cupsdLogMessage(CUPSD_LOG_ERROR, "cupsdAcceptClient: "
e7076f3
+                        "unable to determine client auid for client pid=%d", cr.pid);
e7076f3
+        free(con);
e7076f3
+        return;
cfc9fc5
+      }
e7076f3
+      cupsdLogMessage(CUPSD_LOG_INFO, "cupsdAcceptClient: peer's pid=%d, uid=%d, gid=%d, auid=%d",
e7076f3
+                      cr.pid, cr.uid, cr.gid, con->auid);
cfc9fc5
+    }
cfc9fc5
+    else
cfc9fc5
+    {
e7076f3
+      close(con->http.fd);
e7076f3
+      cupsdLogMessage(CUPSD_LOG_ERROR, "cupsdAcceptClient: getsockopt() failed");
e7076f3
+      free(con);
e7076f3
+      return; 
cfc9fc5
+    }
cfc9fc5
+
e7076f3
+   /*
e7076f3
+    * get the context of the peer connection
e7076f3
+    */
e7076f3
+    if (getpeercon(con->http.fd, &con->scon))
cfc9fc5
+    {
e7076f3
+      close(con->http.fd);
e7076f3
+      cupsdLogMessage(CUPSD_LOG_ERROR, "cupsdAcceptClient: getpeercon() failed");
e7076f3
+      free(con);
e7076f3
+      return; 
cfc9fc5
+    }
cfc9fc5
+
e7076f3
+    cupsdLogMessage(CUPSD_LOG_INFO, "cupsdAcceptClient: client context=%s", con->scon);
e7076f3
+  }
e7076f3
+  else
e7076f3
+  {
e7076f3
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdAcceptClient: skipping getpeercon()");
e7076f3
+    cupsdSetString(&con->scon, UNKNOWN_SL);
e7076f3
+  }
e7076f3
+#endif /* WITH_LSPP */
cfc9fc5
+
e7076f3
 #ifdef AF_INET6
e7076f3
   if (con->http.hostaddr->addr.sa_family == AF_INET6)
e7076f3
     cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdAcceptClient: %d from %s:%d (IPv6)",
e7076f3
@@ -731,6 +790,13 @@ cupsdReadClient(cupsd_client_t *con)	/* 
e7076f3
   mime_type_t		*type;		/* MIME type of file */
e7076f3
   cupsd_printer_t	*p;		/* Printer */
e7076f3
   static unsigned	request_id = 0;	/* Request ID for temp files */
e7076f3
+#ifdef WITH_LSPP
e7076f3
+  security_context_t	spoolcon;	/* context of the job file */
e7076f3
+  context_t		clicon;		/* contex_t container for con->scon */
e7076f3
+  context_t		tmpcon;		/* temp context to swap the level */
e7076f3
+  char			*clirange;	/* SELinux sensitivity range */
e7076f3
+  char			*cliclearance;	/* SELinux low end clearance */
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 
e7076f3
 
e7076f3
   status = HTTP_CONTINUE;
e7076f3
@@ -2011,6 +2077,67 @@ cupsdReadClient(cupsd_client_t *con)	/* 
e7076f3
 	    fchmod(con->file, 0640);
e7076f3
 	    fchown(con->file, RunUser, Group);
e7076f3
             fcntl(con->file, F_SETFD, fcntl(con->file, F_GETFD) | FD_CLOEXEC);
e7076f3
+#ifdef WITH_LSPP
e7076f3
+	    if (strncmp(con->scon, UNKNOWN_SL, strlen(UNKNOWN_SL)) != 0)
e7076f3
+	    {
e7076f3
+	      if (getfilecon(con->filename, &spoolcon) == -1)
e7076f3
+	      {
e7076f3
+		cupsdSendError(con, HTTP_SERVER_ERROR, CUPSD_AUTH_NONE);
e7076f3
+		return (cupsdCloseClient(con));
e7076f3
+	      }
e7076f3
+	      clicon = context_new(con->scon);
e7076f3
+	      tmpcon = context_new(spoolcon);
e7076f3
+	      freecon(spoolcon);
e7076f3
+	      if (!clicon || !tmpcon)
e7076f3
+	      {
e7076f3
+		cupsdSendError(con, HTTP_SERVER_ERROR, CUPSD_AUTH_NONE);
e7076f3
+		if (clicon)
e7076f3
+		  context_free(clicon);
e7076f3
+		if (tmpcon)
e7076f3
+		  context_free(tmpcon);
e7076f3
+		return (cupsdCloseClient(con));
e7076f3
+	      }
e7076f3
+	      clirange = context_range_get(clicon);
e7076f3
+	      if (clirange)
e7076f3
+	      {
e7076f3
+		clirange = strdup(clirange);
e7076f3
+		if ((cliclearance = strtok(clirange, "-")) != NULL)
e7076f3
+		{
e7076f3
+		  if (context_range_set(tmpcon, cliclearance) == -1)
e7076f3
+		  {
e7076f3
+		    cupsdSendError(con, HTTP_SERVER_ERROR, CUPSD_AUTH_NONE);
e7076f3
+		    free(clirange);
e7076f3
+		    context_free(tmpcon);
e7076f3
+		    context_free(clicon);
e7076f3
+		    return (cupsdCloseClient(con));
e7076f3
+		  }
e7076f3
+		}
e7076f3
+		else
e7076f3
+		{
e7076f3
+		  if (context_range_set(tmpcon, (context_range_get(clicon))) == -1)
e7076f3
+		  {
e7076f3
+		    cupsdSendError(con, HTTP_SERVER_ERROR, CUPSD_AUTH_NONE);
e7076f3
+		    free(clirange);
e7076f3
+		    context_free(tmpcon);
e7076f3
+		    context_free(clicon);
e7076f3
+		    return (cupsdCloseClient(con));
e7076f3
+		  }
e7076f3
+		}
e7076f3
+		free(clirange);
e7076f3
+	      }
e7076f3
+	      if (setfilecon(con->filename, context_str(tmpcon)) == -1)
e7076f3
+	      {
e7076f3
+		cupsdSendError(con, HTTP_SERVER_ERROR, CUPSD_AUTH_NONE);
e7076f3
+		context_free(tmpcon);
e7076f3
+		context_free(clicon);
e7076f3
+		return (cupsdCloseClient(con));
e7076f3
+	      }
e7076f3
+	      cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdReadClient: %s set to %s", 
e7076f3
+			      con->filename, context_str(tmpcon));
e7076f3
+	      context_free(tmpcon);
e7076f3
+	      context_free(clicon);
e7076f3
+	    }
e7076f3
+#endif /* WITH_LSPP */
e7076f3
 	  }
e7076f3
 
e7076f3
 	  if (con->http.state != HTTP_POST_SEND)
e7076f3
@@ -4253,6 +4380,50 @@ make_certificate(cupsd_client_t *con)	/*
e7076f3
 #endif /* HAVE_SSL */
e7076f3
 
e7076f3
 
e7076f3
+#ifdef WITH_LSPP
e7076f3
+/*
e7076f3
+ * 'client_pid_to_auid()' - Using the client's pid, read /proc and determine the loginuid.
e7076f3
+ */
cfc9fc5
+
e7076f3
+uid_t client_pid_to_auid(pid_t clipid)
e7076f3
+{
e7076f3
+  uid_t uid;
e7076f3
+  int len, in;
e7076f3
+  char buf[16] = {0};
e7076f3
+  char fname[32] = {0};
e7076f3
+
e7076f3
+
e7076f3
+ /*
e7076f3
+  * Hopefully this pid is still the one we are interested in.
e7076f3
+  */
e7076f3
+  snprintf(fname, 32, "/proc/%d/loginuid", clipid);
e7076f3
+  in = open(fname, O_NOFOLLOW|O_RDONLY);
e7076f3
+
e7076f3
+  if (in < 0)
e7076f3
+    return -1;
e7076f3
+
e7076f3
+  errno = 0;
e7076f3
+
e7076f3
+  do {
e7076f3
+    len = read(in, buf, sizeof(buf));
e7076f3
+  } while (len < 0 && errno == EINTR);
e7076f3
+
e7076f3
+  close(in);
cfc9fc5
+
e7076f3
+  if (len < 0 || len >= sizeof(buf))
e7076f3
+    return -1;
cfc9fc5
+
e7076f3
+  errno = 0;
e7076f3
+  buf[len] = 0;
e7076f3
+  uid = strtol(buf, 0, 10);
cfc9fc5
+
e7076f3
+  if (errno != 0)
e7076f3
+    return -1;
cfc9fc5
+  else
e7076f3
+    return uid;
e7076f3
+}
cfc9fc5
+#endif /* WITH_LSPP */
e7076f3
+
cfc9fc5
 /*
e7076f3
  * 'pipe_command()' - Pipe the output of a command to the remote client.
e7076f3
  */
e7076f3
--- cups-1.3.7/scheduler/client.h.lspp	2007-10-22 19:52:13.000000000 +0100
9161be1
+++ cups-1.3.7/scheduler/client.h	2008-05-30 16:59:10.000000000 +0100
28dab77
@@ -17,6 +17,13 @@
28dab77
 #  include <Security/Authorization.h>
28dab77
 #endif /* HAVE_AUTHORIZATION_H */
75d0e82
 
f4b6623
+/* Copyright (C) 2005 Trusted Computer Solutions, Inc. */
f4b6623
+/* (c) Copyright 2005-2006 Hewlett-Packard Development Company, L.P. */
f4b6623
+
75d0e82
+#ifdef WITH_LSPP
f4b6623
+#include <selinux/selinux.h>
75d0e82
+#endif /* WITH_LSPP */
f4b6623
+
75d0e82
 /*
f4b6623
  * HTTP client structure...
f4b6623
  */
e7076f3
@@ -62,6 +69,10 @@ struct cupsd_client_s
28dab77
 #ifdef HAVE_AUTHORIZATION_H
28dab77
   AuthorizationRef	authref;	/* Authorization ref */
28dab77
 #endif /* HAVE_AUTHORIZATION_H */
d042370
+#ifdef WITH_LSPP
f4b6623
+  security_context_t	scon;		/* Security context of connection */
f4b6623
+  uid_t			auid;		/* Audit loginuid of the client */
d042370
+#endif /* WITH_LSPP */
f4b6623
 };
d042370
 
f4b6623
 #define HTTP(con) &((con)->http)
e7076f3
@@ -129,6 +140,9 @@ extern void	cupsdStartListening(void);
f4b6623
 extern void	cupsdStopListening(void);
f4b6623
 extern void	cupsdUpdateCGI(void);
28dab77
 extern void	cupsdWriteClient(cupsd_client_t *con);
75d0e82
+#ifdef WITH_LSPP
f4b6623
+extern uid_t	client_pid_to_auid(pid_t clipid);
75d0e82
+#endif /* WITH_LSPP */
d042370
 
d042370
 
d042370
 /*
e7076f3
--- cups-1.3.7/config.h.in.lspp	2008-01-07 18:26:57.000000000 +0000
9161be1
+++ cups-1.3.7/config.h.in	2008-05-30 16:59:10.000000000 +0100
e7076f3
@@ -530,6 +530,13 @@
e7076f3
 #undef HAVE_REMOVEFILE
f4b6623
 
75d0e82
 
e7076f3
+/*
e7076f3
+ * Are we trying to meet LSPP requirements?
e7076f3
+ */
e7076f3
+
e7076f3
+#undef WITH_LSPP
f4b6623
+
f4b6623
+
e7076f3
 #endif /* !_CUPS_CONFIG_H_ */
f4b6623
 
f4b6623
 /*
e7076f3
--- cups-1.3.7/Makedefs.in.lspp	2008-01-22 22:37:21.000000000 +0000
9161be1
+++ cups-1.3.7/Makedefs.in	2008-05-30 16:59:10.000000000 +0100
e7076f3
@@ -134,7 +134,7 @@ LIBCUPSORDER	=	@LIBCUPSORDER@
e7076f3
 LIBCUPSIMAGEORDER =	@LIBCUPSIMAGEORDER@
e7076f3
 LINKCUPS	=	@LINKCUPS@ $(SSLLIBS)
e7076f3
 LINKCUPSIMAGE	=	@LINKCUPSIMAGE@
e7076f3
-LIBS		=	$(LINKCUPS) $(COMMONLIBS)
e7076f3
+LIBS		=	$(LINKCUPS) $(COMMONLIBS) @LIBAUDIT@ @LIBSELINUX@
e7076f3
 OPTIM		=	@OPTIM@
e7076f3
 OPTIONS		=
e7076f3
 PAMLIBS		=	@PAMLIBS@
e7076f3
--- cups-1.3.7/configure.in.lspp	2007-07-25 00:47:12.000000000 +0100
9161be1
+++ cups-1.3.7/configure.in	2008-05-30 16:59:10.000000000 +0100
e7076f3
@@ -42,6 +42,8 @@ sinclude(config-scripts/cups-pap.m4)
e7076f3
 sinclude(config-scripts/cups-pdf.m4)
e7076f3
 sinclude(config-scripts/cups-scripting.m4)
f4b6623
 
e7076f3
+sinclude(config-scripts/cups-lspp.m4)
e7076f3
+
e7076f3
 INSTALL_LANGUAGES=""
e7076f3
 UNINSTALL_LANGUAGES=""
e7076f3
 LANGFILES=""
9161be1
--- /dev/null	2008-05-30 08:00:32.690000973 +0100
9161be1
+++ cups-1.3.7/config-scripts/cups-lspp.m4	2008-05-30 16:59:10.000000000 +0100
e7076f3
@@ -0,0 +1,36 @@
e7076f3
+dnl
e7076f3
+dnl   LSPP code for the Common UNIX Printing System (CUPS).
e7076f3
+dnl
e7076f3
+dnl   Copyright 2005-2006 by Hewlett-Packard Development Company, L.P.
e7076f3
+dnl
e7076f3
+dnl   This program is free software; you can redistribute it and/or modify
e7076f3
+dnl   it under the terms of the GNU General Public License as published by
e7076f3
+dnl   the Free Software Foundation; version 2.
e7076f3
+dnl
e7076f3
+dnl   This program is distributed in the hope that it will be useful, but
e7076f3
+dnl   WITHOUT ANY WARRANTY; without even the implied warranty of
e7076f3
+dnl   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
e7076f3
+dnl   General Public License for more details.
e7076f3
+dnl
e7076f3
+dnl   You should have received a copy of the GNU General Public License
e7076f3
+dnl   along with this program; if not, write to the Free Software Foundation,
e7076f3
+dnl   Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301 USA
e7076f3
+dnl
e7076f3
+
e7076f3
+dnl Are we trying to meet LSPP requirements
e7076f3
+AC_ARG_ENABLE(lspp, [  --enable-lspp           turn on auditing and label support, default=no])
e7076f3
+
e7076f3
+if test x"$enable_lspp" != xno; then
e7076f3
+    case "$uname" in
e7076f3
+        Linux)
e7076f3
+            AC_CHECK_LIB(audit,audit_log_user_message, [LIBAUDIT="-laudit" AC_SUBST(LIBAUDIT)])
e7076f3
+            AC_CHECK_HEADER(libaudit.h)
e7076f3
+            AC_CHECK_LIB(selinux,getpeercon, [LIBSELINUX="-lselinux" AC_SUBST(LIBSELINUX)])
e7076f3
+            AC_CHECK_HEADER(selinux/selinux.h)
e7076f3
+            AC_DEFINE(WITH_LSPP)
e7076f3
+            ;;
e7076f3
+        *)
e7076f3
+            # All others
e7076f3
+            ;;
e7076f3
+    esac
e7076f3
+fi
e7076f3
--- cups-1.3.7/filter/common.c.lspp	2007-07-11 22:46:42.000000000 +0100
9161be1
+++ cups-1.3.7/filter/common.c	2008-05-30 16:59:10.000000000 +0100
e7076f3
@@ -30,6 +30,12 @@
f4b6623
  * Include necessary headers...
f4b6623
  */
f4b6623
 
e7076f3
+#include "config.h"
e7076f3
+#ifdef WITH_LSPP
f4b6623
+#define _GNU_SOURCE
e7076f3
+#include <string.h>
e7076f3
+#endif /* WITH_LSPP */
e7076f3
+
e7076f3
 #include "common.h"
e7076f3
 #include <locale.h>
f4b6623
 
e7076f3
@@ -312,6 +318,18 @@ WriteLabelProlog(const char *label,	/* I
e7076f3
 {
e7076f3
   const char	*classification;	/* CLASSIFICATION environment variable */
e7076f3
   const char	*ptr;			/* Temporary string pointer */
f4b6623
+#ifdef WITH_LSPP
e7076f3
+  int           i,                      /* counter */
e7076f3
+                n,                      /* counter */
e7076f3
+                lines,                  /* number of lines needed */
e7076f3
+                line_len,               /* index into tmp_label */
e7076f3
+                label_len,              /* length of the label in characters */
e7076f3
+                label_index,            /* index into the label */
e7076f3
+                longest,                /* length of the longest line */
e7076f3
+                longest_line,           /* index to the longest line */
e7076f3
+                max_width;              /* maximum width in characters */
e7076f3
+  char          **wrapped_label;        /* label with line breaks */
f4b6623
+#endif /* WITH_LSPP */
f4b6623
 
e7076f3
 
e7076f3
  /*
e7076f3
@@ -334,6 +352,124 @@ WriteLabelProlog(const char *label,	/* I
e7076f3
     return;
f4b6623
   }
f4b6623
 
f4b6623
+#ifdef WITH_LSPP
e7076f3
+  if (strncmp(classification, "LSPP:", 5) == 0 && label == NULL)
f4b6623
+  {
e7076f3
+   /*
e7076f3
+    * Based on the 12pt fixed width font below determine the max_width
e7076f3
+    */
e7076f3
+    max_width = width / 8;
e7076f3
+    longest_line = 0;
e7076f3
+    longest = 0;
e7076f3
+    classification += 5; // Skip the "LSPP:"
e7076f3
+    label_len = strlen(classification);
f4b6623
+
e7076f3
+    if (label_len > max_width)
d042370
+    {
e7076f3
+      lines = 1 + (int)(label_len / max_width);
e7076f3
+      line_len = (int)(label_len / lines);
e7076f3
+      wrapped_label = malloc(sizeof(wrapped_label) * lines);
e7076f3
+      label_index = i = n = 0;
e7076f3
+      while (classification[label_index])
d042370
+      {
e7076f3
+        if ((label_index + line_len) > label_len)
e7076f3
+          break;
e7076f3
+        switch (classification[label_index + line_len + i])
e7076f3
+        {
e7076f3
+          case ':':
e7076f3
+          case ',':
e7076f3
+          case '-':
e7076f3
+            i++;
e7076f3
+            wrapped_label[n++] = strndup(&classification[label_index], (line_len + i));
e7076f3
+            label_index += line_len + i;
e7076f3
+            i = 0;
e7076f3
+            break;
e7076f3
+          default:
e7076f3
+            i++;
e7076f3
+            break;
e7076f3
+        }
e7076f3
+        if ((i + line_len) == max_width)
e7076f3
+        {
e7076f3
+          wrapped_label[n++] = strndup(&(classification[label_index]), (line_len + i));
e7076f3
+          label_index = label_index + line_len + i;
e7076f3
+          i = 0;
e7076f3
+        }
d042370
+      }
e7076f3
+      wrapped_label[n] = strndup(&classification[label_index], label_len - label_index);
d042370
+    }
d042370
+    else
d042370
+    {
e7076f3
+      lines = 1;
e7076f3
+      wrapped_label = malloc(sizeof(wrapped_label));
e7076f3
+      wrapped_label[0] = (char*)classification;
e7076f3
+    }
e7076f3
+
e7076f3
+    for (n = 0; n < lines; n++ )
e7076f3
+    {
e7076f3
+      printf("userdict/ESPp%c(", ('a' + n));
e7076f3
+      for (ptr = wrapped_label[n], i = 0; *ptr; ptr ++, i++)
e7076f3
+        if (*ptr < 32 || *ptr > 126)
e7076f3
+          printf("\\%03o", *ptr);
e7076f3
+        else
e7076f3
+        {
e7076f3
+          if (*ptr == '(' || *ptr == ')' || *ptr == '\\')
e7076f3
+            putchar('\\');
e7076f3
+
e7076f3
+          printf("%c", *ptr);
e7076f3
+        }
e7076f3
+      if (i > longest)
e7076f3
+      {
e7076f3
+        longest = i;
e7076f3
+        longest_line = n;
e7076f3
+      }
e7076f3
+      printf(")put\n");
d042370
+    }
f4b6623
+
f4b6623
+   /*
e7076f3
+    * For LSPP use a fixed width font so that line wrapping can be calculated
f4b6623
+    */
e7076f3
+
e7076f3
+    puts("userdict/ESPlf /Nimbus-Mono findfont 12 scalefont put");
e7076f3
+
e7076f3
+   /*
e7076f3
+    * Finally, the procedure to write the labels on the page...
e7076f3
+    */
e7076f3
+
e7076f3
+    printf("userdict/ESPwl{\n"
e7076f3
+           "  ESPlf setfont\n");
e7076f3
+    printf("  ESPp%c stringwidth pop dup 12 add exch -0.5 mul %.0f add\n ",
e7076f3
+           'a' + longest_line, width * 0.5f);
e7076f3
+    for (n = 1; n < lines; n++)
e7076f3
+      printf(" dup");
e7076f3
+    printf("\n  1 setgray\n");
e7076f3
+    printf("  dup 6 sub %.0f %d index %.0f ESPrf\n",
e7076f3
+           (bottom - 2.0), (2 + lines), 6.0 + (16.0 * lines));
e7076f3
+    printf("  dup 6 sub %.0f %d index %.0f ESPrf\n",
e7076f3
+           (top - 6.0 - (16.0 * lines)), (2 + lines), 4.0 + (16.0 * lines));
e7076f3
+    printf("  0 setgray\n");
e7076f3
+    printf("  dup 6 sub %.0f %d index %.0f ESPrs\n",
e7076f3
+           (bottom - 2.0), (2 + lines), 6.0 + (16.0 * lines));
e7076f3
+    printf("  dup 6 sub %.0f %d index %.0f ESPrs\n",
e7076f3
+           (top - 6.0 - (16.0 * lines)), (2 + lines), 4.0 + (16.0 * lines));
e7076f3
+    for (n = 0; n < lines; n ++)
d042370
+    {
e7076f3
+      printf("  dup %.0f moveto ESPp%c show\n",
e7076f3
+             bottom + 6.0 + ((lines - (n+1)) * 16.0), 'a' + n);
e7076f3
+      printf("  %.0f moveto ESPp%c show\n", top + 2.0 - ((n + 1) * 16.0), 'a' + n);
d042370
+    }
e7076f3
+    printf("  pop\n"
e7076f3
+           "}bind put\n");
e7076f3
+
e7076f3
+   /*
e7076f3
+    * Do some clean up at the end of the LSPP special case
e7076f3
+    */
e7076f3
+    free(wrapped_label);
f4b6623
+
f4b6623
+  }
f4b6623
+  else
f4b6623
+  {
e7076f3
+#endif /* !WITH_LSPP */
e7076f3
+  
e7076f3
  /*
e7076f3
   * Set the classification + page label string...
e7076f3
   */
e7076f3
@@ -414,7 +550,10 @@ WriteLabelProlog(const char *label,	/* I
e7076f3
   printf("  %.0f moveto ESPpl show\n", top - 14.0);
e7076f3
   puts("pop");
e7076f3
   puts("}bind put");
d042370
+  }
d042370
+#ifdef WITH_LSPP
e7076f3
 }
f4b6623
+#endif /* WITH_LSPP */
f4b6623
 
f4b6623
 
e7076f3
 /*
e7076f3
--- cups-1.3.7/data/Makefile.lspp	2007-10-10 23:00:43.000000000 +0100
9161be1
+++ cups-1.3.7/data/Makefile	2008-05-30 16:59:10.000000000 +0100
e7076f3
@@ -25,7 +25,10 @@ BANNERS	=	\
e7076f3
 		secret \
e7076f3
 		standard \
e7076f3
 		topsecret \
e7076f3
-		unclassified
e7076f3
+		unclassified \
e7076f3
+		selinux \
e7076f3
+		mls \
e7076f3
+		te
f4b6623
 
e7076f3
 CHARMAPS =	\
e7076f3
 		euc-cn.txt \
9161be1
--- /dev/null	2008-05-30 08:00:32.690000973 +0100
9161be1
+++ cups-1.3.7/data/te	2008-05-30 16:59:10.000000000 +0100
e7076f3
@@ -0,0 +1,261 @@
e7076f3
+%!PS-Adobe-3.0
e7076f3
+%%BoundingBox: 0 0 612 792
e7076f3
+%%Pages: 1
e7076f3
+%%LanguageLevel: 1
e7076f3
+%%DocumentData: Clean7Bit
e7076f3
+%%DocumentSuppliedResources: procset bannerprint/1.0
e7076f3
+%%DocumentNeededResources: font Helvetica Helvetica-Bold Times-Roman
e7076f3
+%%Creator: Michael Sweet, Easy Software Products
e7076f3
+%%CreationDate: May 10, 2000
e7076f3
+%%Title: Test Page
e7076f3
+%%EndComments
e7076f3
+%%BeginProlog
e7076f3
+%%BeginResource procset bannerprint 1.1 0
e7076f3
+%
e7076f3
+%   PostScript banner page for the Common UNIX Printing System ("CUPS").
e7076f3
+%
e7076f3
+%   Copyright 1993-2005 by Easy Software Products
e7076f3
+%
e7076f3
+%   These coded instructions, statements, and computer programs are the
e7076f3
+%   property of Easy Software Products and are protected by Federal
e7076f3
+%   copyright law.  Distribution and use rights are outlined in the file
e7076f3
+%   "LICENSE.txt" which should have been included with this file.  If this
e7076f3
+%   file is missing or damaged please contact Easy Software Products
e7076f3
+%   at:
e7076f3
+%
e7076f3
+%       Attn: CUPS Licensing Information
e7076f3
+%       Easy Software Products
e7076f3
+%       44141 Airport View Drive, Suite 204
e7076f3
+%       Hollywood, Maryland 20636 USA
e7076f3
+%
e7076f3
+%       Voice: (301) 373-9600
e7076f3
+%       EMail: cups-info@cups.org
e7076f3
+%         WWW: http://www.cups.org
e7076f3
+%
e7076f3
+/CENTER {			% Draw centered text
e7076f3
+				% (name) CENTER -
e7076f3
+  dup stringwidth pop		% Get the width of the string
e7076f3
+  0.5 mul neg 0 rmoveto		% Shift left 1/2 of the distance
e7076f3
+  show				% Show the string
e7076f3
+} bind def
e7076f3
+/RIGHT {			% Draw right-justified text
e7076f3
+				% (name) RIGHT -
e7076f3
+  dup stringwidth pop		% Get the width of the string
e7076f3
+  neg 0 rmoveto			% Shift left the entire distance
e7076f3
+  show				% Show the string
e7076f3
+} bind def
e7076f3
+/NUMBER {			% Draw a number
e7076f3
+				% power n NUMBER -
e7076f3
+  1 index 1 eq {		% power == 1?
e7076f3
+    round cvi exch pop		% Convert "n" to integer
e7076f3
+  } {
e7076f3
+    1 index mul round exch div	% Truncate extra decimal places
e7076f3
+  } ifelse
e7076f3
+  100 string cvs show		% Convert to a string and show it...
e7076f3
+} bind def
e7076f3
+/CUPSLOGO {			% Draw the CUPS logo
e7076f3
+				% height CUPSLOGO
e7076f3
+  % Start with a big C...
e7076f3
+  /Helvetica findfont 1 index scalefont setfont
e7076f3
+  0 setgray
e7076f3
+  0 0 moveto
e7076f3
+  (C) show
75d0e82
+
e7076f3
+  % Then "UNIX Printing System" much smaller...
e7076f3
+  /Helvetica-Bold findfont 1 index 9 div scalefont setfont
e7076f3
+  0.25 mul
e7076f3
+  dup dup 2.0 mul moveto
e7076f3
+  (UNIX) show
e7076f3
+  dup dup 1.6 mul moveto
e7076f3
+  (Printing) show
e7076f3
+  dup 1.2 mul moveto
e7076f3
+  (System) show
e7076f3
+} bind def
e7076f3
+/ESPLOGO {			% Draw the ESP logo
e7076f3
+				% height ESPLOGO
e7076f3
+  % Compute the size of the logo...
e7076f3
+  0 0
e7076f3
+  2 index 1.5 mul 3 index
75d0e82
+
e7076f3
+  % Do the "metallic" fill from 10% black to 40% black...
e7076f3
+  1 -0.001 0 {
e7076f3
+    dup			% loopval
e7076f3
+    -0.15 mul		% loopval * -0.15
e7076f3
+    0.9 add		% 0.9 - loopval * 0.15
e7076f3
+    setgray		% set gray shade
75d0e82
+
e7076f3
+    0			% x
e7076f3
+    1 index neg		% loopval
e7076f3
+    1 add		% 1 - loopval
e7076f3
+    3 index		% height
e7076f3
+    mul			% height * (1 - loopval)
e7076f3
+    moveto		% starting point
75d0e82
+
e7076f3
+    dup			% loopval
e7076f3
+    3 index		% width
e7076f3
+    mul			% loopval * width
e7076f3
+    2 index		% height
e7076f3
+    lineto		% Next point
5dd9863
+
e7076f3
+    0			% x
e7076f3
+    2 index		% height
e7076f3
+    lineto		% Next point
5dd9863
+
e7076f3
+    closepath
e7076f3
+    fill
75d0e82
+
e7076f3
+    dup			% loopval
e7076f3
+    0.15 mul		% loopval * 0.15
e7076f3
+    0.6 add		% 0.6 + loopval * 0.15
e7076f3
+    setgray
f4b6623
+
e7076f3
+    dup			% loopval
e7076f3
+    neg 1 add		% 1 - loopval
e7076f3
+    3 index		% width
e7076f3
+    mul			% (1 - loopval) * width
e7076f3
+    0			% y
e7076f3
+    moveto		% Starting point
f4b6623
+
e7076f3
+    2 index		% width
e7076f3
+    exch		% loopval
e7076f3
+    2 index		% height
e7076f3
+    mul			% loopval * height
e7076f3
+    lineto		% Next point
f4b6623
+
e7076f3
+    1 index		% width
e7076f3
+    0			% y
e7076f3
+    lineto		% Next point
75d0e82
+
e7076f3
+    closepath
e7076f3
+    fill
e7076f3
+  } for
d042370
+
e7076f3
+  0 setgray rectstroke
d042370
+
e7076f3
+  /Helvetica-BoldOblique findfont 1 index 3 div scalefont setfont
e7076f3
+  dup 40 div
5dd9863
+
e7076f3
+  dup 4 mul 1 index 25 mul moveto (E) show
e7076f3
+  dup 10 mul 1 index 15 mul moveto (S) show
e7076f3
+  dup 16 mul 1 index 5 mul moveto (P) show
e7076f3
+
e7076f3
+  /Helvetica-BoldOblique findfont 2 index 5 div scalefont setfont
e7076f3
+  dup 14 mul 1 index 29 mul moveto (asy) show
e7076f3
+  dup 20 mul 1 index 19 mul moveto (oftware) show
e7076f3
+  dup 26 mul 1 index 9 mul moveto (roducts) show
e7076f3
+
e7076f3
+  pop
e7076f3
+} bind def
e7076f3
+%%EndResource
e7076f3
+%%EndProlog
e7076f3
+%%Page: 1 1
e7076f3
+gsave
e7076f3
+
e7076f3
+  % Determine the imageable area and device resolution...
e7076f3
+  initclip newpath clippath pathbbox	% Get bounding rectangle
e7076f3
+  72 div /pageTop exch def		% Get top margin in inches
e7076f3
+  72 div /pageRight exch def		% Get right margin in inches
e7076f3
+  72 div /pageBottom exch def		% Get bottom margin in inches
e7076f3
+  72 div /pageLeft exch def		% Get left margin in inches
e7076f3
+
e7076f3
+  /pageWidth pageRight pageLeft sub def	% pageWidth = pageRight - pageLeft
e7076f3
+  /pageHeight pageTop pageBottom sub def% pageHeight = pageTop - pageBottom
e7076f3
+
e7076f3
+  /boxWidth				% width of text box
e7076f3
+  pageWidth pageHeight lt
e7076f3
+  { pageWidth 54 mul }
e7076f3
+  { pageHeight 42 mul }
e7076f3
+  ifelse def
75d0e82
+
e7076f3
+  newpath				% Clear bounding path
75d0e82
+
e7076f3
+  % Create fonts...
e7076f3
+  /bigFont /Helvetica-Bold findfont	% bigFont = Helvetica-Bold
e7076f3
+  pageHeight 3 mul scalefont def	% size = pageHeight * 3 (nominally 33)
75d0e82
+
e7076f3
+  /mediumFont /Helvetica findfont	% mediumFont = Helvetica
e7076f3
+  pageHeight 1.5 mul scalefont def	% size = pageHeight * 1.5 (nominally 16.5)
22cc213
+
e7076f3
+  % Offset page to account for lower-left margin...
e7076f3
+  pageLeft 72 mul
e7076f3
+  pageBottom 72 mul
e7076f3
+  translate
75d0e82
+
e7076f3
+  % Job information box...
e7076f3
+  pageWidth 36 mul 9 add		% x = pageWidth * 1/2 * 72 + 9
e7076f3
+  boxWidth 0.5 mul sub			% x-= 1/2 box width
e7076f3
+  pageHeight 30 mul 9 sub		% y = pageHeight * 1/2 * 72 - 9
e7076f3
+  boxWidth				% w = box width
e7076f3
+  pageHeight 14 mul			% h = pageHeight * 1/2 * 72
e7076f3
+  0.5 setgray rectfill			% Draw a shadow
e7076f3
+
e7076f3
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
e7076f3
+  boxWidth 0.5 mul sub			% x-= 1/2 box width
e7076f3
+  pageHeight 30 mul			% y = pageHeight * 1/4 * 72
e7076f3
+  boxWidth				% w = box width
e7076f3
+  pageHeight 14 mul			% h = pageHeight * 1/2 * 72
e7076f3
+
e7076f3
+  4 copy 1 setgray rectfill		% Clear the box to white
e7076f3
+  0 setgray rectstroke			% Draw a black box around it...
e7076f3
+
e7076f3
+  % Job information text...
e7076f3
+  mediumFont setfont			% Medium sized font
e7076f3
+
e7076f3
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
e7076f3
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
e7076f3
+  pageHeight 5 mul add			% y += 2 lines
e7076f3
+  2 copy				% Copy X & Y
e7076f3
+  moveto
e7076f3
+  (Job ID: ) RIGHT
e7076f3
+  moveto
e7076f3
+  ({printer-name}-{job-id}) show
e7076f3
+
e7076f3
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
e7076f3
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
e7076f3
+  pageHeight 2 mul add			% y += 1 line
e7076f3
+  2 copy				% Copy X & Y
e7076f3
+  moveto
e7076f3
+  (Title: ) RIGHT
e7076f3
+  moveto
e7076f3
+  ({job-name}) show
e7076f3
+
e7076f3
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
e7076f3
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
e7076f3
+  pageHeight -1 mul add			% y -= 1 line
e7076f3
+  2 copy				% Copy X & Y
e7076f3
+  moveto
e7076f3
+  (Requesting User: ) RIGHT
e7076f3
+  moveto
e7076f3
+  ({job-originating-user-name}) show
e7076f3
+
e7076f3
+  pageWidth 36 mul			% x = pageWidth * 1/2 * 72
e7076f3
+  pageHeight 36 mul			% y = pageHeight * 1/2 * 72
e7076f3
+  pageHeight -4 mul add			% y -= 2 lines
e7076f3
+  2 copy				% Copy X & Y
e7076f3
+  moveto
e7076f3
+  (Billing Info: ) RIGHT
e7076f3
+  moveto
e7076f3
+  ({?job-billing}) show
e7076f3
+
e7076f3
+  % Then the CUPS logo....
e7076f3
+  gsave
e7076f3
+    pageWidth 4 mul
e7076f3
+    pageWidth 6 mul
e7076f3
+    translate
e7076f3
+    pageWidth 9 mul CUPSLOGO
e7076f3
+  grestore
e7076f3
+
e7076f3
+  % And the ESP logo....
e7076f3
+  gsave
e7076f3
+    pageWidth 59 mul
e7076f3
+    pageWidth 6 mul
e7076f3
+    translate
e7076f3
+    pageWidth 6 mul ESPLOGO
e7076f3
+  grestore
e7076f3
+% Show the page...
e7076f3
+grestore
e7076f3
+sh