/*
* PPD utilities for CUPS.
*
- * Copyright 2007-2015 by Apple Inc.
- * Copyright 1997-2006 by Easy Software Products.
+ * Copyright © 2007-2018 by Apple Inc.
+ * Copyright © 1997-2006 by Easy Software Products.
*
* Licensed under Apache License v2.0. See the file "LICENSE" for more
* information.
if (!name)
{
+ DEBUG_puts("2cupsGetPPD3: No printer name, returning NULL.");
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("No printer name"), 1);
return (HTTP_STATUS_NOT_ACCEPTABLE);
}
if (!modtime)
{
+ DEBUG_puts("2cupsGetPPD3: No modtime, returning NULL.");
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("No modification time"), 1);
return (HTTP_STATUS_NOT_ACCEPTABLE);
}
if (!buffer || bufsize <= 1)
{
+ DEBUG_puts("2cupsGetPPD3: No filename buffer, returning NULL.");
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad filename buffer"), 1);
return (HTTP_STATUS_NOT_ACCEPTABLE);
}
if (buffer[0])
{
+ DEBUG_printf(("2cupsGetPPD3: Using filename \"%s\".", buffer));
+
unlink(buffer);
if (symlink(ppdname, buffer) && errno != EEXIST)
const char *tmpdir; /* TMPDIR environment variable */
struct timeval curtime; /* Current time */
+
+#ifdef __APPLE__
+ /*
+ * On macOS and iOS, the TMPDIR environment variable is not always the best
+ * location to place temporary files due to sandboxing. Instead, the confstr
+ * function should be called to get the proper per-user, per-process TMPDIR
+ * value. Currently this only happens if TMPDIR is not set or is set to
+ * "/Users/...".
+ */
+
+ char tmppath[1024]; /* Temporary directory */
+
+ if ((tmpdir = getenv("TMPDIR")) != NULL && !strncmp(tmpdir, "/Users/", 7)))
+ tmpdir = NULL;
+
+ if (!tmpdir)
+ {
+ if (confstr(_CS_DARWIN_USER_TEMP_DIR, tmppath, sizeof(tmppath)))
+ tmpdir = tmppath;
+ else
+ tmpdir = "/private/tmp"; /* This should never happen */
+ }
+#else
/*
* Previously we put root temporary files in the default CUPS temporary
* directory under /var/spool/cups. However, since the scheduler cleans
*/
if ((tmpdir = getenv("TMPDIR")) == NULL)
-# ifdef __APPLE__
- tmpdir = "/private/tmp"; /* /tmp is a symlink to /private/tmp */
-# else
- tmpdir = "/tmp";
-# endif /* __APPLE__ */
+ tmpdir = "/tmp";
+#endif /* __APPLE__ */
+
+ DEBUG_printf(("2cupsGetPPD3: tmpdir=\"%s\".", tmpdir));
/*
* Make the temporary name using the specified directory...
if (!symlink(ppdname, buffer))
break;
+ DEBUG_printf(("2cupsGetPPD3: Symlink \"%s\" to \"%s\" failed: %s", ppdname, buffer, strerror(errno)));
+
tries ++;
}
while (tries < 1000);
if (tries >= 1000)
{
+ DEBUG_puts("2cupsGetPPD3: Unable to symlink after 1000 tries, returning error.");
+
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, NULL, 0);
return (HTTP_STATUS_SERVER_ERROR);
}
if (*modtime >= ppdinfo.st_mtime)
+ {
+ DEBUG_printf(("2cupsGetPPD3: Returning not-modified, filename=\"%s\".", buffer));
return (HTTP_STATUS_NOT_MODIFIED);
+ }
else
{
+ DEBUG_printf(("2cupsGetPPD3: Returning ok, filename=\"%s\", modtime=%ld.", buffer, (long)ppdinfo.st_mtime));
*modtime = ppdinfo.st_mtime;
return (HTTP_STATUS_OK);
}
* Try finding a printer URI for this printer...
*/
+ DEBUG_puts("2cupsGetPPD3: Unable to access local file, copying...");
+
if (!http)
+ {
if ((http = _cupsConnect()) == NULL)
+ {
+ DEBUG_puts("2cupsGetPPD3: Unable to connect to scheduler.");
return (HTTP_STATUS_SERVICE_UNAVAILABLE);
+ }
+ }
- if (!cups_get_printer_uri(http, name, hostname, sizeof(hostname), &port,
- resource, sizeof(resource), 0))
+ if (!cups_get_printer_uri(http, name, hostname, sizeof(hostname), &port, resource, sizeof(resource), 0))
+ {
+ DEBUG_puts("2cupsGetPPD3: Unable to get printer URI.");
return (HTTP_STATUS_NOT_FOUND);
+ }
- DEBUG_printf(("2cupsGetPPD3: Printer hostname=\"%s\", port=%d", hostname,
- port));
+ DEBUG_printf(("2cupsGetPPD3: Printer hostname=\"%s\", port=%d", hostname, port));
if (cupsServer()[0] == '/' && !_cups_strcasecmp(hostname, "localhost") && port == ippPort())
{
else if ((http2 = httpConnect2(hostname, port, NULL, AF_UNSPEC,
cupsEncryption(), 1, 30000, NULL)) == NULL)
{
- DEBUG_puts("1cupsGetPPD3: Unable to connect to server");
+ DEBUG_puts("2cupsGetPPD3: Unable to connect to server");
return (HTTP_STATUS_SERVICE_UNAVAILABLE);
}
* Return the PPD file...
*/
- DEBUG_printf(("1cupsGetPPD3: Returning status %d", status));
+ DEBUG_printf(("2cupsGetPPD3: Returning status %d", status));
return (status);
}