diff options
author | Michael R Sweet <michaelrsweet@gmail.com> | 2018-02-27 15:32:20 -0500 |
---|---|---|
committer | Michael R Sweet <michaelrsweet@gmail.com> | 2018-02-27 15:32:20 -0500 |
commit | 818bbe7af2c235dc975249ae1231eedd8353de64 (patch) | |
tree | b5677d1df7ef8845f778b9afa0cbd7f60ae06895 /cups/ppd-util.c | |
parent | 9b440f8a5cfa0214833196db7ea0639036eaec34 (diff) | |
download | cups-818bbe7af2c235dc975249ae1231eedd8353de64.tar.gz |
cupsGetPPD* still used the old TMPDIR code.
Also fix the check to look for /Users/... since /var/folders is OK.
Diffstat (limited to 'cups/ppd-util.c')
-rw-r--r-- | cups/ppd-util.c | 69 |
1 files changed, 56 insertions, 13 deletions
diff --git a/cups/ppd-util.c b/cups/ppd-util.c index 939e63288..fd1c0b02f 100644 --- a/cups/ppd-util.c +++ b/cups/ppd-util.c @@ -1,8 +1,8 @@ /* * 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. @@ -150,18 +150,21 @@ cupsGetPPD3(http_t *http, /* I - HTTP connection or @code CUPS_HTTP_DEFAUL 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); } @@ -196,6 +199,8 @@ cupsGetPPD3(http_t *http, /* I - HTTP connection or @code CUPS_HTTP_DEFAUL if (buffer[0]) { + DEBUG_printf(("2cupsGetPPD3: Using filename \"%s\".", buffer)); + unlink(buffer); if (symlink(ppdname, buffer) && errno != EEXIST) @@ -211,6 +216,29 @@ cupsGetPPD3(http_t *http, /* I - HTTP connection or @code CUPS_HTTP_DEFAUL 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 @@ -219,11 +247,10 @@ cupsGetPPD3(http_t *http, /* I - HTTP connection or @code CUPS_HTTP_DEFAUL */ 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... @@ -254,12 +281,16 @@ cupsGetPPD3(http_t *http, /* I - HTTP connection or @code CUPS_HTTP_DEFAUL 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); @@ -267,9 +298,13 @@ cupsGetPPD3(http_t *http, /* I - HTTP connection or @code CUPS_HTTP_DEFAUL } 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); } @@ -281,16 +316,24 @@ cupsGetPPD3(http_t *http, /* I - HTTP connection or @code CUPS_HTTP_DEFAUL * 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()) { @@ -334,7 +377,7 @@ cupsGetPPD3(http_t *http, /* I - HTTP connection or @code CUPS_HTTP_DEFAUL 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); } @@ -406,7 +449,7 @@ cupsGetPPD3(http_t *http, /* I - HTTP connection or @code CUPS_HTTP_DEFAUL * Return the PPD file... */ - DEBUG_printf(("1cupsGetPPD3: Returning status %d", status)); + DEBUG_printf(("2cupsGetPPD3: Returning status %d", status)); return (status); } |