/*
- * "$Id: log.c 5493 2006-05-05 16:33:57Z mike $"
+ * "$Id: log.c 6875 2007-08-27 23:25:06Z mike $"
*
* Log file routines for the Common UNIX Printing System (CUPS).
*
- * Copyright 1997-2006 by Easy Software Products, all rights reserved.
+ * Copyright 2007-2008 by Apple Inc.
+ * Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
- * property of Easy Software Products and are protected by Federal
- * copyright law. Distribution and use rights are outlined in the file
- * "LICENSE.txt" which should have been included with this file. If this
- * file is missing or damaged please contact Easy Software Products
- * at:
- *
- * Attn: CUPS Licensing Information
- * Easy Software Products
- * 44141 Airport View Drive, Suite 204
- * Hollywood, Maryland 20636 USA
- *
- * Voice: (301) 373-9600
- * EMail: cups-info@cups.org
- * WWW: http://www.cups.org
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file. If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
* Contents:
*
- * cupsdGetDateTime() - Returns a pointer to a date/time string.
- * cupsdLogMessage() - Log a message to the error log file.
- * cupsdLogPage() - Log a page to the page log file.
- * cupsdLogRequest() - Log an HTTP request in Common Log Format.
- * check_log_file() - Open/rotate a log file if it needs it.
+ * cupsdGetDateTime() - Returns a pointer to a date/time string.
+ * cupsdLogGSSMessage() - Log a GSSAPI error...
+ * cupsdLogMessage() - Log a message to the error log file.
+ * cupsdLogPage() - Log a page to the page log file.
+ * cupsdLogRequest() - Log an HTTP request in Common Log Format.
+ * check_log_file() - Open/rotate a log file if it needs it.
*/
/*
}
+#ifdef HAVE_GSSAPI
+/*
+ * 'cupsdLogGSSMessage()' - Log a GSSAPI error...
+ */
+
+int /* O - 1 on success, 0 on error */
+cupsdLogGSSMessage(
+ int level, /* I - Log level */
+ int major_status, /* I - Major GSSAPI status */
+ int minor_status, /* I - Minor GSSAPI status */
+ const char *message, /* I - printf-style message string */
+ ...) /* I - Additional args as needed */
+{
+ OM_uint32 err_major_status, /* Major status code for display */
+ err_minor_status; /* Minor status code for display */
+ OM_uint32 msg_ctx; /* Message context */
+ gss_buffer_desc major_status_string = GSS_C_EMPTY_BUFFER,
+ /* Major status message */
+ minor_status_string = GSS_C_EMPTY_BUFFER;
+ /* Minor status message */
+ int ret; /* Return value */
+
+
+ msg_ctx = 0;
+ err_major_status = gss_display_status(&err_minor_status,
+ major_status,
+ GSS_C_GSS_CODE,
+ GSS_C_NO_OID,
+ &msg_ctx,
+ &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);
+
+ ret = cupsdLogMessage(level, "%s: %s, %s", message,
+ (char *)major_status_string.value,
+ (char *)minor_status_string.value);
+ gss_release_buffer(&err_minor_status, &major_status_string);
+ gss_release_buffer(&err_minor_status, &minor_status_string);
+
+ return (ret);
+}
+#endif /* HAVE_GSSAPI */
+
+
/*
* 'cupsdLogMessage()' - Log a message to the error log file.
*/
* See if we want to log this message...
*/
+ if (TestConfigFile)
+ {
+ if (level <= CUPSD_LOG_WARN)
+ {
+ va_start(ap, message);
+ vfprintf(stderr, message, ap);
+ putc('\n', stderr);
+ va_end(ap);
+ }
+
+ return (1);
+ }
+
if (level > LogLevel || !ErrorLog)
return (1);
if (len >= linesize)
{
+ char *temp; /* Temporary string pointer */
+
+
len ++;
if (len < 8192)
else if (len > 65536)
len = 65536;
- line = realloc(line, len);
+ temp = realloc(line, len);
- if (line)
- linesize = len;
- else
+ if (temp)
{
- cupsFilePrintf(ErrorFile,
- "ERROR: Unable to allocate memory for line - %s\n",
- strerror(errno));
- cupsFileFlush(ErrorFile);
-
- return (0);
+ line = temp;
+ linesize = len;
}
va_start(ap, message);
if (!strcmp(AccessLog, "syslog"))
{
- syslog(LOG_INFO, "REQUEST %s - %s \"%s %s HTTP/%d.%d\" %d " CUPS_LLFMT "\n",
+ syslog(LOG_INFO,
+ "REQUEST %s - %s \"%s %s HTTP/%d.%d\" %d " CUPS_LLFMT " %s %s\n",
con->http.hostname, con->username[0] != '\0' ? con->username : "-",
states[con->operation], con->uri,
con->http.version / 100, con->http.version % 100,
- code, CUPS_LLCAST con->bytes);
+ code, CUPS_LLCAST con->bytes,
+ con->request ?
+ ippOpString(con->request->request.op.operation_id) : "-",
+ con->response ?
+ ippErrorString(con->response->request.status.status_code) : "-");
return (1);
}
check_log_file(cups_file_t **lf, /* IO - Log file */
const char *logname) /* I - Log filename */
{
- char backname[1024], /* Backup log filename */
- filename[1024], /* Formatted log filename */
- *ptr; /* Pointer into filename */
+ char backname[1024], /* Backup log filename */
+ filename[1024], /* Formatted log filename */
+ *ptr; /* Pointer into filename */
+ const char *logptr; /* Pointer into log filename */
/*
else
filename[0] = '\0';
- for (ptr = filename + strlen(filename);
- *logname && ptr < (filename + sizeof(filename) - 1);
- logname ++)
- if (*logname == '%')
+ for (logptr = logname, ptr = filename + strlen(filename);
+ *logptr && ptr < (filename + sizeof(filename) - 1);
+ logptr ++)
+ if (*logptr == '%')
{
/*
* Format spec...
*/
- logname ++;
- if (*logname == 's')
+ logptr ++;
+ if (*logptr == 's')
{
/*
* Insert the server name...
* Otherwise just insert the character...
*/
- *ptr++ = *logname;
+ *ptr++ = *logptr;
}
}
else
- *ptr++ = *logname;
+ *ptr++ = *logptr;
*ptr = '\0';
}
if ((*lf = cupsFileOpen(filename, "a")) == NULL)
{
- syslog(LOG_ERR, "Unable to open log file \"%s\" - %s", filename,
- strerror(errno));
+ /*
+ * If the file is in CUPS_LOGDIR then try to create a missing directory...
+ */
- return (0);
+ if (!strncmp(filename, CUPS_LOGDIR, strlen(CUPS_LOGDIR)))
+ {
+ cupsdCheckPermissions(CUPS_LOGDIR, NULL, 0755, RunUser, Group, 1, -1);
+
+ *lf = cupsFileOpen(filename, "a");
+ }
+
+ if (*lf == NULL)
+ {
+ syslog(LOG_ERR, "Unable to open log file \"%s\" - %s", filename,
+ strerror(errno));
+ return (0);
+ }
}
if (strncmp(filename, "/dev/", 5))
/*
- * End of "$Id: log.c 5493 2006-05-05 16:33:57Z mike $".
+ * End of "$Id: log.c 6875 2007-08-27 23:25:06Z mike $".
*/