]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/conf.c
Remove all of the Subversion keywords from various source files.
[thirdparty/cups.git] / scheduler / conf.c
index a58de4204b019058d3dfeb95c3875146589f3b6d..5f97fa3b8eaa0663497f9b8d134739a00d602eff 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * "$Id$"
- *
  * Configuration routines for the CUPS scheduler.
  *
  * Copyright 2007-2015 by Apple Inc.
 #include <stdarg.h>
 #include <grp.h>
 #include <sys/utsname.h>
+#ifdef HAVE_ASL_H
+#  include <asl.h>
+#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+#  define SD_JOURNAL_SUPPRESS_LOCATION
+#  include <systemd/sd-journal.h>
+#endif /* HAVE_ASL_H */
 #include <syslog.h>
 
 #ifdef HAVE_LIBPAPER
@@ -269,8 +273,20 @@ cupsdCheckPermissions(
                          "Unable to create directory \"%s\" - %s", filename,
                          strerror(errno));
         else
-         syslog(LOG_ERR, "Unable to create directory \"%s\" - %s", filename,
-                strerror(errno));
+#ifdef HAVE_ASL_H
+        {
+         asl_object_t  m;              /* Log message */
+
+         m = asl_new(ASL_TYPE_MSG);
+         asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
+         asl_log(NULL, m, ASL_LEVEL_ERR, "Unable to create directory \"%s\" - %s", filename, strerror(errno));
+         asl_release(m);
+       }
+#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+         sd_journal_print(LOG_ERR, "Unable to create directory \"%s\" - %s", filename, strerror(errno));
+#else
+         syslog(LOG_ERR, "Unable to create directory \"%s\" - %s", filename, strerror(errno));
+#endif /* HAVE_ASL_H */
 
         return (-1);
       }
@@ -307,7 +323,20 @@ cupsdCheckPermissions(
     if (create_dir >= 0)
       cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is not a directory.", filename);
     else
+#ifdef HAVE_ASL_H
+    {
+      asl_object_t     m;              /* Log message */
+
+      m = asl_new(ASL_TYPE_MSG);
+      asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
+      asl_log(NULL, m, ASL_LEVEL_ERR, "\"%s\" is not a directory.", filename);
+      asl_release(m);
+    }
+#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+      sd_journal_print(LOG_ERR, "\"%s\" is not a directory.", filename);
+#else
       syslog(LOG_ERR, "\"%s\" is not a directory.", filename);
+#endif /* HAVE_ASL_H */
 
     return (-1);
   }
@@ -336,8 +365,20 @@ cupsdCheckPermissions(
                        "Unable to change ownership of \"%s\" - %s", filename,
                        strerror(errno));
       else
-       syslog(LOG_ERR, "Unable to change ownership of \"%s\" - %s", filename,
-              strerror(errno));
+#ifdef HAVE_ASL_H
+      {
+       asl_object_t    m;              /* Log message */
+
+       m = asl_new(ASL_TYPE_MSG);
+       asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
+       asl_log(NULL, m, ASL_LEVEL_ERR, "Unable to change ownership of \"%s\" - %s", filename, strerror(errno));
+       asl_release(m);
+      }
+#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+       sd_journal_print(LOG_ERR, "Unable to change ownership of \"%s\" - %s", filename, strerror(errno));
+#else
+       syslog(LOG_ERR, "Unable to change ownership of \"%s\" - %s", filename, strerror(errno));
+#endif /* HAVE_ASL_H */
 
       return (1);
     }
@@ -356,8 +397,20 @@ cupsdCheckPermissions(
                        "Unable to change permissions of \"%s\" - %s", filename,
                        strerror(errno));
       else
-       syslog(LOG_ERR, "Unable to change permissions of \"%s\" - %s", filename,
-              strerror(errno));
+#ifdef HAVE_ASL_H
+      {
+       asl_object_t    m;              /* Log message */
+
+       m = asl_new(ASL_TYPE_MSG);
+       asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
+       asl_log(NULL, m, ASL_LEVEL_ERR, "Unable to change permissions of \"%s\" - %s", filename, strerror(errno));
+       asl_release(m);
+      }
+#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+       sd_journal_print(LOG_ERR, "Unable to change permissions of \"%s\" - %s", filename, strerror(errno));
+#else
+       syslog(LOG_ERR, "Unable to change permissions of \"%s\" - %s", filename, strerror(errno));
+#endif /* HAVE_ASL_H */
 
       return (1);
     }
@@ -782,8 +835,20 @@ cupsdReadConfiguration(void)
       if (TestConfigFile)
         printf("\"%s\" contains errors.\n", CupsFilesFile);
       else
-        syslog(LOG_LPR, "Unable to read \"%s\" due to errors.",
-               CupsFilesFile);
+#ifdef HAVE_ASL_H
+      {
+       asl_object_t    m;              /* Log message */
+
+       m = asl_new(ASL_TYPE_MSG);
+       asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
+       asl_log(NULL, m, ASL_LEVEL_ERR, "Unable to read \"%s\" due to errors.", CupsFilesFile);
+       asl_release(m);
+      }
+#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+       sd_journal_print(LOG_ERR, "Unable to read \"%s\" due to errors.", CupsFilesFile);
+#else
+        syslog(LOG_LPR, "Unable to read \"%s\" due to errors.", CupsFilesFile);
+#endif /* HAVE_ASL_H */
 
       return (0);
     }
@@ -792,8 +857,20 @@ cupsdReadConfiguration(void)
     cupsdLogMessage(CUPSD_LOG_INFO, "No %s, using defaults.", CupsFilesFile);
   else
   {
-    syslog(LOG_LPR, "Unable to open \"%s\": %s", CupsFilesFile,
-          strerror(errno));
+#ifdef HAVE_ASL_H
+    asl_object_t       m;              /* Log message */
+
+    m = asl_new(ASL_TYPE_MSG);
+    asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
+    asl_log(NULL, m, ASL_LEVEL_ERR, "Unable to open \"%s\" - %s", CupsFilesFile, strerror(errno));
+    asl_release(m);
+
+#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+    sd_journal_print(LOG_ERR, "Unable to open \"%s\" - %s", CupsFilesFile, strerror(errno));
+#else
+    syslog(LOG_LPR, "Unable to open \"%s\" - %s", CupsFilesFile, strerror(errno));
+#endif /* HAVE_ASL_H */
+
     return (0);
   }
 
@@ -806,8 +883,19 @@ cupsdReadConfiguration(void)
 
   if ((fp = cupsFileOpen(ConfigurationFile, "r")) == NULL)
   {
-    syslog(LOG_LPR, "Unable to open \"%s\": %s", ConfigurationFile,
-          strerror(errno));
+#ifdef HAVE_ASL_H
+    asl_object_t       m;              /* Log message */
+
+    m = asl_new(ASL_TYPE_MSG);
+    asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
+    asl_log(NULL, m, ASL_LEVEL_ERR, "Unable to open \"%s\" - %s", ConfigurationFile, strerror(errno));
+    asl_release(m);
+#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+    sd_journal_print(LOG_ERR, "Unable to open \"%s\" - %s", ConfigurationFile, strerror(errno));
+#else
+    syslog(LOG_LPR, "Unable to open \"%s\" - %s", ConfigurationFile, strerror(errno));
+#endif /* HAVE_ASL_H */
+
     return (0);
   }
 
@@ -820,8 +908,20 @@ cupsdReadConfiguration(void)
     if (TestConfigFile)
       printf("\"%s\" contains errors.\n", ConfigurationFile);
     else
-      syslog(LOG_LPR, "Unable to read \"%s\" due to errors.",
-            ConfigurationFile);
+#ifdef HAVE_ASL_H
+    {
+      asl_object_t     m;              /* Log message */
+
+      m = asl_new(ASL_TYPE_MSG);
+      asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
+      asl_log(NULL, m, ASL_LEVEL_ERR, "Unable to read \"%s\" due to errors.", ConfigurationFile);
+      asl_release(m);
+    }
+#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+      sd_journal_print(LOG_ERR, "Unable to read \"%s\" due to errors.", ConfigurationFile);
+#else
+      syslog(LOG_LPR, "Unable to read \"%s\" due to errors.", ConfigurationFile);
+#endif /* HAVE_ASL_H */
 
     return (0);
   }
@@ -948,12 +1048,24 @@ cupsdReadConfiguration(void)
   * Open the system log for cupsd if necessary...
   */
 
-#ifdef HAVE_VSYSLOG
+  if (!LogStderr)
+  {
+    if (!strcmp(AccessLog, "stderr"))
+      cupsdSetString(&AccessLog, "syslog");
+
+    if (!strcmp(ErrorLog, "stderr"))
+      cupsdSetString(&ErrorLog, "syslog");
+
+    if (!strcmp(PageLog, "stderr"))
+      cupsdSetString(&PageLog, "syslog");
+  }
+
+#if defined(HAVE_VSYSLOG) && !defined(HAVE_ASL_H) && !defined(HAVE_SYSTEMD_SD_JOURNAL_H)
   if (!strcmp(AccessLog, "syslog") ||
       !strcmp(ErrorLog, "syslog") ||
       !strcmp(PageLog, "syslog"))
     openlog("cupsd", LOG_PID | LOG_NOWAIT | LOG_NDELAY, LOG_LPR);
-#endif /* HAVE_VSYSLOG */
+#endif /* HAVE_VSYSLOG && !HAVE_ASL_H && !HAVE_SYSTEMD_SD_JOURNAL_H */
 
  /*
   * Make sure each of the log files exists and gets rotated as necessary...
@@ -3990,121 +4102,106 @@ set_policy_defaults(cupsd_policy_t *pol)/* I - Policy */
   * Verify that we have an explicit policy for Validate-Job, Cancel-Jobs,
   * Cancel-My-Jobs, Close-Job, and CUPS-Get-Document, which ensures that
   * upgrades do not introduce new security issues...
+  *
+  * CUPS STR #4659: Allow a lone <Limit All> policy.
   */
 
-  if ((op = cupsdFindPolicyOp(pol, IPP_VALIDATE_JOB)) == NULL ||
-      op->op == IPP_ANY_OPERATION)
+  if (cupsArrayCount(pol->ops) > 1)
   {
-    if ((op = cupsdFindPolicyOp(pol, IPP_PRINT_JOB)) != NULL &&
-       op->op != IPP_ANY_OPERATION)
+    if ((op = cupsdFindPolicyOp(pol, IPP_VALIDATE_JOB)) == NULL ||
+       op->op == IPP_ANY_OPERATION)
     {
-     /*
-      * Add a new limit for Validate-Job using the Print-Job limit as a
-      * template...
-      */
+      if ((op = cupsdFindPolicyOp(pol, IPP_PRINT_JOB)) != NULL &&
+         op->op != IPP_ANY_OPERATION)
+      {
+       /*
+       * Add a new limit for Validate-Job using the Print-Job limit as a
+       * template...
+       */
 
-      cupsdLogMessage(CUPSD_LOG_WARN,
-                     "No limit for Validate-Job defined in policy %s "
-                     "- using Print-Job's policy.", pol->name);
+       cupsdLogMessage(CUPSD_LOG_WARN, "No limit for Validate-Job defined in policy %s - using Print-Job's policy.", pol->name);
 
-      cupsdAddPolicyOp(pol, op, IPP_VALIDATE_JOB);
+       cupsdAddPolicyOp(pol, op, IPP_VALIDATE_JOB);
+      }
+      else
+       cupsdLogMessage(CUPSD_LOG_WARN, "No limit for Validate-Job defined in policy %s and no suitable template found.", pol->name);
     }
-    else
-      cupsdLogMessage(CUPSD_LOG_WARN,
-                     "No limit for Validate-Job defined in policy %s "
-                     "and no suitable template found.", pol->name);
-  }
 
-  if ((op = cupsdFindPolicyOp(pol, IPP_CANCEL_JOBS)) == NULL ||
-      op->op == IPP_ANY_OPERATION)
-  {
-    if ((op = cupsdFindPolicyOp(pol, IPP_PAUSE_PRINTER)) != NULL &&
-       op->op != IPP_ANY_OPERATION)
+    if ((op = cupsdFindPolicyOp(pol, IPP_CANCEL_JOBS)) == NULL ||
+       op->op == IPP_ANY_OPERATION)
     {
-     /*
-      * Add a new limit for Cancel-Jobs using the Pause-Printer limit as a
-      * template...
-      */
+      if ((op = cupsdFindPolicyOp(pol, IPP_PAUSE_PRINTER)) != NULL &&
+         op->op != IPP_ANY_OPERATION)
+      {
+       /*
+       * Add a new limit for Cancel-Jobs using the Pause-Printer limit as a
+       * template...
+       */
 
-      cupsdLogMessage(CUPSD_LOG_WARN,
-                     "No limit for Cancel-Jobs defined in policy %s "
-                     "- using Pause-Printer's policy.", pol->name);
+       cupsdLogMessage(CUPSD_LOG_WARN, "No limit for Cancel-Jobs defined in policy %s - using Pause-Printer's policy.", pol->name);
 
-      cupsdAddPolicyOp(pol, op, IPP_CANCEL_JOBS);
+       cupsdAddPolicyOp(pol, op, IPP_CANCEL_JOBS);
+      }
+      else
+       cupsdLogMessage(CUPSD_LOG_WARN, "No limit for Cancel-Jobs defined in policy %s and no suitable template found.", pol->name);
     }
-    else
-      cupsdLogMessage(CUPSD_LOG_WARN,
-                     "No limit for Cancel-Jobs defined in policy %s "
-                     "and no suitable template found.", pol->name);
-  }
 
-  if ((op = cupsdFindPolicyOp(pol, IPP_CANCEL_MY_JOBS)) == NULL ||
-      op->op == IPP_ANY_OPERATION)
-  {
-    if ((op = cupsdFindPolicyOp(pol, IPP_SEND_DOCUMENT)) != NULL &&
-       op->op != IPP_ANY_OPERATION)
+    if ((op = cupsdFindPolicyOp(pol, IPP_CANCEL_MY_JOBS)) == NULL ||
+       op->op == IPP_ANY_OPERATION)
     {
-     /*
-      * Add a new limit for Cancel-My-Jobs using the Send-Document limit as
-      * a template...
-      */
+      if ((op = cupsdFindPolicyOp(pol, IPP_SEND_DOCUMENT)) != NULL &&
+         op->op != IPP_ANY_OPERATION)
+      {
+       /*
+       * Add a new limit for Cancel-My-Jobs using the Send-Document limit as
+       * a template...
+       */
 
-      cupsdLogMessage(CUPSD_LOG_WARN,
-                     "No limit for Cancel-My-Jobs defined in policy %s "
-                     "- using Send-Document's policy.", pol->name);
+       cupsdLogMessage(CUPSD_LOG_WARN, "No limit for Cancel-My-Jobs defined in policy %s - using Send-Document's policy.", pol->name);
 
-      cupsdAddPolicyOp(pol, op, IPP_CANCEL_MY_JOBS);
+       cupsdAddPolicyOp(pol, op, IPP_CANCEL_MY_JOBS);
+      }
+      else
+       cupsdLogMessage(CUPSD_LOG_WARN, "No limit for Cancel-My-Jobs defined in policy %s and no suitable template found.", pol->name);
     }
-    else
-      cupsdLogMessage(CUPSD_LOG_WARN,
-                     "No limit for Cancel-My-Jobs defined in policy %s "
-                     "and no suitable template found.", pol->name);
-  }
 
-  if ((op = cupsdFindPolicyOp(pol, IPP_CLOSE_JOB)) == NULL ||
-      op->op == IPP_ANY_OPERATION)
-  {
-    if ((op = cupsdFindPolicyOp(pol, IPP_SEND_DOCUMENT)) != NULL &&
-       op->op != IPP_ANY_OPERATION)
+    if ((op = cupsdFindPolicyOp(pol, IPP_CLOSE_JOB)) == NULL ||
+       op->op == IPP_ANY_OPERATION)
     {
-     /*
-      * Add a new limit for Close-Job using the Send-Document limit as a
-      * template...
-      */
+      if ((op = cupsdFindPolicyOp(pol, IPP_SEND_DOCUMENT)) != NULL &&
+         op->op != IPP_ANY_OPERATION)
+      {
+       /*
+       * Add a new limit for Close-Job using the Send-Document limit as a
+       * template...
+       */
 
-      cupsdLogMessage(CUPSD_LOG_WARN,
-                     "No limit for Close-Job defined in policy %s "
-                     "- using Send-Document's policy.", pol->name);
+       cupsdLogMessage(CUPSD_LOG_WARN, "No limit for Close-Job defined in policy %s - using Send-Document's policy.", pol->name);
 
-      cupsdAddPolicyOp(pol, op, IPP_CLOSE_JOB);
+       cupsdAddPolicyOp(pol, op, IPP_CLOSE_JOB);
+      }
+      else
+       cupsdLogMessage(CUPSD_LOG_WARN, "No limit for Close-Job defined in policy %s and no suitable template found.", pol->name);
     }
-    else
-      cupsdLogMessage(CUPSD_LOG_WARN,
-                     "No limit for Close-Job defined in policy %s "
-                     "and no suitable template found.", pol->name);
-  }
 
-  if ((op = cupsdFindPolicyOp(pol, CUPS_GET_DOCUMENT)) == NULL ||
-      op->op == IPP_ANY_OPERATION)
-  {
-    if ((op = cupsdFindPolicyOp(pol, IPP_SEND_DOCUMENT)) != NULL &&
-       op->op != IPP_ANY_OPERATION)
+    if ((op = cupsdFindPolicyOp(pol, CUPS_GET_DOCUMENT)) == NULL ||
+       op->op == IPP_ANY_OPERATION)
     {
-     /*
-      * Add a new limit for CUPS-Get-Document using the Send-Document
-      * limit as a template...
-      */
+      if ((op = cupsdFindPolicyOp(pol, IPP_SEND_DOCUMENT)) != NULL &&
+         op->op != IPP_ANY_OPERATION)
+      {
+       /*
+       * Add a new limit for CUPS-Get-Document using the Send-Document
+       * limit as a template...
+       */
 
-      cupsdLogMessage(CUPSD_LOG_WARN,
-                     "No limit for CUPS-Get-Document defined in policy %s "
-                     "- using Send-Document's policy.", pol->name);
+       cupsdLogMessage(CUPSD_LOG_WARN, "No limit for CUPS-Get-Document defined in policy %s - using Send-Document's policy.", pol->name);
 
-      cupsdAddPolicyOp(pol, op, CUPS_GET_DOCUMENT);
+       cupsdAddPolicyOp(pol, op, CUPS_GET_DOCUMENT);
+      }
+      else
+       cupsdLogMessage(CUPSD_LOG_WARN, "No limit for CUPS-Get-Document defined in policy %s and no suitable template found.", pol->name);
     }
-    else
-      cupsdLogMessage(CUPSD_LOG_WARN,
-                     "No limit for CUPS-Get-Document defined in policy %s "
-                     "and no suitable template found.", pol->name);
   }
 
  /*
@@ -4114,18 +4211,14 @@ set_policy_defaults(cupsd_policy_t *pol)/* I - Policy */
 
   if (!pol->job_access)
   {
-    cupsdLogMessage(CUPSD_LOG_WARN,
-                   "No JobPrivateAccess defined in policy %s "
-                   "- using defaults.", pol->name);
+    cupsdLogMessage(CUPSD_LOG_WARN, "No JobPrivateAccess defined in policy %s - using defaults.", pol->name);
     cupsdAddString(&(pol->job_access), "@OWNER");
     cupsdAddString(&(pol->job_access), "@SYSTEM");
   }
 
   if (!pol->job_attrs)
   {
-    cupsdLogMessage(CUPSD_LOG_WARN,
-                   "No JobPrivateValues defined in policy %s "
-                   "- using defaults.", pol->name);
+    cupsdLogMessage(CUPSD_LOG_WARN, "No JobPrivateValues defined in policy %s - using defaults.", pol->name);
     cupsdAddString(&(pol->job_attrs), "job-name");
     cupsdAddString(&(pol->job_attrs), "job-originating-host-name");
     cupsdAddString(&(pol->job_attrs), "job-originating-user-name");
@@ -4134,18 +4227,14 @@ set_policy_defaults(cupsd_policy_t *pol)/* I - Policy */
 
   if (!pol->sub_access)
   {
-    cupsdLogMessage(CUPSD_LOG_WARN,
-                   "No SubscriptionPrivateAccess defined in policy %s "
-                   "- using defaults.", pol->name);
+    cupsdLogMessage(CUPSD_LOG_WARN, "No SubscriptionPrivateAccess defined in policy %s - using defaults.", pol->name);
     cupsdAddString(&(pol->sub_access), "@OWNER");
     cupsdAddString(&(pol->sub_access), "@SYSTEM");
   }
 
   if (!pol->sub_attrs)
   {
-    cupsdLogMessage(CUPSD_LOG_WARN,
-                   "No SubscriptionPrivateValues defined in policy %s "
-                   "- using defaults.", pol->name);
+    cupsdLogMessage(CUPSD_LOG_WARN, "No SubscriptionPrivateValues defined in policy %s - using defaults.", pol->name);
     cupsdAddString(&(pol->sub_attrs), "notify-events");
     cupsdAddString(&(pol->sub_attrs), "notify-pull-method");
     cupsdAddString(&(pol->sub_attrs), "notify-recipient-uri");
@@ -4153,8 +4242,3 @@ set_policy_defaults(cupsd_policy_t *pol)/* I - Policy */
     cupsdAddString(&(pol->sub_attrs), "notify-user-data");
   }
 }
-
-
-/*
- * End of "$Id$".
- */