#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
"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);
}
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);
}
"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);
}
"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);
}
* to use it...
*/
- if (gss_init_sec_context == NULL)
+ if (&gss_init_sec_context == NULL)
return (default_auth_type = CUPSD_AUTH_BASIC);
# endif /* __APPLE__ */
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);
}
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);
}
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);
}
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);
}
* 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...
* Log the error and reset the group to a safe value...
*/
- cupsdLogMessage(CUPSD_LOG_NOTICE,
+ cupsdLogMessage(CUPSD_LOG_ERROR,
"Group and SystemGroup cannot use the same groups.");
if (FatalErrors & (CUPSD_FATAL_CONFIG | CUPSD_FATAL_PERMISSIONS))
return (0);
cupsdUpdateEnv();
+ /*
+ * Validate the default error policy...
+ */
+
+ if (strcmp(ErrorPolicy, "retry-current-job") &&
+ strcmp(ErrorPolicy, "abort-job") &&
+ strcmp(ErrorPolicy, "retry-job") &&
+ strcmp(ErrorPolicy, "stop-printer"))
+ {
+ cupsdLogMessage(CUPSD_LOG_ALERT, "Invalid ErrorPolicy \"%s\", resetting to \"stop-printer\".", ErrorPolicy);
+ cupsdSetString(&ErrorPolicy, "stop-printer");
+ }
+
/*
* Update default paper size setting as needed...
*/
* 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);
}
/*
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");
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");