]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/log.c
Merge changes from CUPS 1.4svn-r7961.
[thirdparty/cups.git] / scheduler / log.c
index ea6d7755db552e9ca3d457731ba788edb18909ba..19cb0cc86711388a328348e0fe248c4940d8aabe 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: log.c 7699 2008-06-27 20:44:23Z mike $"
+ * "$Id: log.c 7918 2008-09-08 22:03:01Z mike $"
  *
  *   Log file routines for the Common UNIX Printing System (CUPS).
  *
@@ -47,7 +47,7 @@ static char   *log_line = NULL;       /* Line for output file */
  */
 
 static int     check_log_file(cups_file_t **lf, const char *logname);
-static char    *format_log_line(const char *message, va_list ap);
+static int     format_log_line(const char *message, va_list ap);
 
 
 /*
@@ -150,12 +150,8 @@ cupsdLogGSSMessage(
                                           &major_status_string);
 
   if (!GSS_ERROR(err_major_status))
-    err_major_status = gss_display_status(&err_minor_status,
-                                         minor_status,
-                                         GSS_C_MECH_CODE,
-                                         GSS_C_NULL_OID,
-                                         &msg_ctx,
-                                         &minor_status_string);
+    gss_display_status(&err_minor_status, minor_status, GSS_C_MECH_CODE,
+                       GSS_C_NULL_OID, &msg_ctx, &minor_status_string);
 
   ret = cupsdLogMessage(level, "%s: %s, %s", message,
                        (char *)major_status_string.value,
@@ -179,8 +175,8 @@ cupsdLogJob(cupsd_job_t *job,               /* I - Job */
            ...)                        /* I - Additional arguments as needed */
 {
   va_list              ap;             /* Argument pointer */
-  char                 jobmsg[1024],   /* Format string for job message */
-                       *line;          /* Message line */
+  char                 jobmsg[1024];   /* Format string for job message */
+  int                  status;         /* Formatting status */
 
 
  /*
@@ -196,12 +192,16 @@ cupsdLogJob(cupsd_job_t *job,             /* I - Job */
 
   snprintf(jobmsg, sizeof(jobmsg), "[Job %d] %s", job->id, message);
 
-  va_start(ap, message);
-  line = format_log_line(jobmsg, ap);
-  va_end(ap);
+  do
+  {
+    va_start(ap, message);
+    status = format_log_line(jobmsg, ap);
+    va_end(ap);
+  }
+  while (status == 0);
 
-  if (line)
-    return (cupsdWriteErrorLog(level, line));
+  if (status > 0)
+    return (cupsdWriteErrorLog(level, log_line));
   else
     return (cupsdWriteErrorLog(CUPSD_LOG_ERROR,
                                "Unable to allocate memory for log line!"));
@@ -218,7 +218,7 @@ cupsdLogMessage(int        level,   /* I - Log level */
                ...)                    /* I - Additional args as needed */
 {
   va_list              ap;             /* Argument pointer */
-  char                 *line;          /* Message line */
+  int                  status;         /* Formatting status */
 
 
  /*
@@ -245,12 +245,16 @@ cupsdLogMessage(int        level, /* I - Log level */
   * Format and write the log message...
   */
 
-  va_start(ap, message);
-  line = format_log_line(message, ap);
-  va_end(ap);
+  do
+  {
+    va_start(ap, message);
+    status = format_log_line(message, ap);
+    va_end(ap);
+  }
+  while (status == 0);
 
-  if (line)
-    return (cupsdWriteErrorLog(level, line));
+  if (status > 0)
+    return (cupsdWriteErrorLog(level, log_line));
   else
     return (cupsdWriteErrorLog(CUPSD_LOG_ERROR,
                                "Unable to allocate memory for log line!"));
@@ -481,6 +485,112 @@ cupsdLogRequest(cupsd_client_t *con,      /* I - Request to log */
                };
 
 
+ /*
+  * Filter requests as needed...
+  */
+
+  if (AccessLogLevel < CUPSD_ACCESSLOG_ALL)
+  {
+   /*
+    * Eliminate simple GET requests...
+    */
+
+    if ((con->operation == HTTP_GET &&
+         strncmp(con->uri, "/admin/conf", 11) &&
+        strncmp(con->uri, "/admin/log", 10)) ||
+       (con->operation == HTTP_POST && !con->request &&
+        strncmp(con->uri, "/admin", 6)) ||
+       (con->operation != HTTP_POST && con->operation != HTTP_PUT))
+      return (1);
+
+    if (con->request && con->response &&
+        con->response->request.status.status_code < IPP_REDIRECTION_OTHER_SITE)
+    {
+     /*
+      * Check successful requests...
+      */
+
+      ipp_op_t op = con->request->request.op.operation_id;
+      static cupsd_accesslog_t standard_ops[] =
+      {
+        CUPSD_ACCESSLOG_ALL,   /* reserved */
+        CUPSD_ACCESSLOG_ALL,   /* reserved */
+        CUPSD_ACCESSLOG_ACTIONS,/* Print-Job */
+        CUPSD_ACCESSLOG_ACTIONS,/* Print-URI */
+        CUPSD_ACCESSLOG_ACTIONS,/* Validate-Job */
+        CUPSD_ACCESSLOG_ACTIONS,/* Create-Job */
+        CUPSD_ACCESSLOG_ACTIONS,/* Send-Document */
+        CUPSD_ACCESSLOG_ACTIONS,/* Send-URI */
+        CUPSD_ACCESSLOG_ACTIONS,/* Cancel-Job */
+        CUPSD_ACCESSLOG_ALL,   /* Get-Job-Attributes */
+        CUPSD_ACCESSLOG_ALL,   /* Get-Jobs */
+        CUPSD_ACCESSLOG_ALL,   /* Get-Printer-Attributes */
+        CUPSD_ACCESSLOG_ACTIONS,/* Hold-Job */
+        CUPSD_ACCESSLOG_ACTIONS,/* Release-Job */
+        CUPSD_ACCESSLOG_ACTIONS,/* Restart-Job */
+       CUPSD_ACCESSLOG_ALL,    /* reserved */
+        CUPSD_ACCESSLOG_CONFIG,        /* Pause-Printer */
+        CUPSD_ACCESSLOG_CONFIG,        /* Resume-Printer */
+        CUPSD_ACCESSLOG_CONFIG,        /* Purge-Jobs */
+        CUPSD_ACCESSLOG_CONFIG,        /* Set-Printer-Attributes */
+        CUPSD_ACCESSLOG_ACTIONS,/* Set-Job-Attributes */
+        CUPSD_ACCESSLOG_CONFIG,        /* Get-Printer-Supported-Values */
+        CUPSD_ACCESSLOG_ACTIONS,/* Create-Printer-Subscription */
+        CUPSD_ACCESSLOG_ACTIONS,/* Create-Job-Subscription */
+        CUPSD_ACCESSLOG_ALL,   /* Get-Subscription-Attributes */
+        CUPSD_ACCESSLOG_ALL,   /* Get-Subscriptions */
+        CUPSD_ACCESSLOG_ACTIONS,/* Renew-Subscription */
+        CUPSD_ACCESSLOG_ACTIONS,/* Cancel-Subscription */
+        CUPSD_ACCESSLOG_ALL,   /* Get-Notifications */
+        CUPSD_ACCESSLOG_ACTIONS,/* Send-Notifications */
+        CUPSD_ACCESSLOG_ALL,   /* reserved */
+        CUPSD_ACCESSLOG_ALL,   /* reserved */
+        CUPSD_ACCESSLOG_ALL,   /* reserved */
+        CUPSD_ACCESSLOG_ALL,   /* Get-Print-Support-Files */
+        CUPSD_ACCESSLOG_CONFIG,        /* Enable-Printer */
+        CUPSD_ACCESSLOG_CONFIG,        /* Disable-Printer */
+        CUPSD_ACCESSLOG_CONFIG,        /* Pause-Printer-After-Current-Job */
+        CUPSD_ACCESSLOG_ACTIONS,/* Hold-New-Jobs */
+        CUPSD_ACCESSLOG_ACTIONS,/* Release-Held-New-Jobs */
+        CUPSD_ACCESSLOG_CONFIG,        /* Deactivate-Printer */
+        CUPSD_ACCESSLOG_CONFIG,        /* Activate-Printer */
+        CUPSD_ACCESSLOG_CONFIG,        /* Restart-Printer */
+        CUPSD_ACCESSLOG_CONFIG,        /* Shutdown-Printer */
+        CUPSD_ACCESSLOG_CONFIG,        /* Startup-Printer */
+        CUPSD_ACCESSLOG_ACTIONS,/* Reprocess-Job */
+        CUPSD_ACCESSLOG_ACTIONS,/* Cancel-Current-Job */
+        CUPSD_ACCESSLOG_ACTIONS,/* Suspend-Current-Job */
+        CUPSD_ACCESSLOG_ACTIONS,/* Resume-Job */
+        CUPSD_ACCESSLOG_ACTIONS,/* Promote-Job */
+        CUPSD_ACCESSLOG_ACTIONS        /* Schedule-Job-After */
+      };
+      static cupsd_accesslog_t cups_ops[] =
+      {
+        CUPSD_ACCESSLOG_ALL,   /* CUPS-Get-Default */
+        CUPSD_ACCESSLOG_ALL,   /* CUPS-Get-Printers */
+        CUPSD_ACCESSLOG_CONFIG,        /* CUPS-Add-Modify-Printer */
+        CUPSD_ACCESSLOG_CONFIG,        /* CUPS-Delete-Printer */
+        CUPSD_ACCESSLOG_ALL,   /* CUPS-Get-Classes */
+        CUPSD_ACCESSLOG_CONFIG,        /* CUPS-Add-Modify-Class */
+        CUPSD_ACCESSLOG_CONFIG,        /* CUPS-Delete-Class */
+        CUPSD_ACCESSLOG_CONFIG,        /* CUPS-Accept-Jobs */
+        CUPSD_ACCESSLOG_CONFIG,        /* CUPS-Reject-Jobs */
+        CUPSD_ACCESSLOG_CONFIG,        /* CUPS-Set-Default */
+        CUPSD_ACCESSLOG_CONFIG,        /* CUPS-Get-Devices */
+        CUPSD_ACCESSLOG_CONFIG,        /* CUPS-Get-PPDs */
+        CUPSD_ACCESSLOG_ACTIONS,/* CUPS-Move-Job */
+        CUPSD_ACCESSLOG_ACTIONS,/* CUPS-Authenticate-Job */
+        CUPSD_ACCESSLOG_ALL    /* CUPS-Get-PPD */
+      };
+      
+
+      if ((op <= IPP_SCHEDULE_JOB_AFTER && standard_ops[op] > AccessLogLevel) ||
+          (op >= CUPS_GET_DEFAULT && op <= CUPS_GET_PPD &&
+          cups_ops[op - CUPS_GET_DEFAULT] > AccessLogLevel))
+        return (1);
+    }
+  }
+
 #ifdef HAVE_VSYSLOG
  /*
   * See if we are logging accesses via syslog...
@@ -697,7 +807,20 @@ check_log_file(cups_file_t **lf,   /* IO - Log file */
 
       if (!strncmp(filename, CUPS_LOGDIR, strlen(CUPS_LOGDIR)))
       {
-        cupsdCheckPermissions(CUPS_LOGDIR, NULL, 0755, RunUser, Group, 1, -1);
+       /*
+        * Try updating the permissions of the containing log directory, using
+       * the log file permissions as a basis...
+       */
+
+        int log_dir_perm = 0300 | LogFilePerm;
+                                       /* LogFilePerm + owner write/search */
+       if (log_dir_perm & 0040)
+         log_dir_perm |= 0010;         /* Add group search */
+       if (log_dir_perm & 0004)
+         log_dir_perm |= 0001;         /* Add other search */
+
+        cupsdCheckPermissions(CUPS_LOGDIR, NULL, log_dir_perm, RunUser, Group,
+                             1, -1);
 
         *lf = cupsFileOpen(filename, "a");
       }
@@ -706,6 +829,10 @@ check_log_file(cups_file_t **lf,   /* IO - Log file */
       {
        syslog(LOG_ERR, "Unable to open log file \"%s\" - %s", filename,
               strerror(errno));
+
+        if (FatalErrors & CUPSD_FATAL_LOG)
+         cupsdEndProcess(getpid(), 0);
+
        return (0);
       }
     }
@@ -745,6 +872,9 @@ check_log_file(cups_file_t **lf,    /* IO - Log file */
       syslog(LOG_ERR, "Unable to open log file \"%s\" - %s", filename,
              strerror(errno));
 
+      if (FatalErrors & CUPSD_FATAL_LOG)
+       cupsdEndProcess(getpid(), 0);
+
       return (0);
     }
 
@@ -768,11 +898,11 @@ check_log_file(cups_file_t **lf,  /* IO - Log file */
  * to format_log_line()...
  */
 
-static char *                          /* O - Text or NULL on error */
+static int                             /* O - -1 for fatal, 0 for retry, 1 for success */
 format_log_line(const char *message,   /* I - Printf-style format string */
                 va_list    ap)         /* I - Argument list */
 {
-  int  len;                            /* Length of formatted line */
+  int          len;                    /* Length of formatted line */
 
 
  /*
@@ -785,7 +915,7 @@ format_log_line(const char *message,        /* I - Printf-style format string */
     log_line     = malloc(log_linesize);
 
     if (!log_line)
-      return (NULL);
+      return (-1);
   }
 
  /*
@@ -816,15 +946,15 @@ format_log_line(const char *message,      /* I - Printf-style format string */
     {
       log_line     = temp;
       log_linesize = len;
-    }
 
-    len = vsnprintf(log_line, log_linesize, message, ap);
+      return (0);
+    }
   }
 
-  return (log_line);
+  return (1);
 }
 
 
 /*
- * End of "$Id: log.c 7699 2008-06-27 20:44:23Z mike $".
+ * End of "$Id: log.c 7918 2008-09-08 22:03:01Z mike $".
  */