]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Temporary files are now placed in the correct directory for sandboxed
authorMichael R Sweet <michael.r.sweet@gmail.com>
Wed, 7 Mar 2018 14:03:24 +0000 (09:03 -0500)
committerMichael R Sweet <michael.r.sweet@gmail.com>
Wed, 7 Mar 2018 14:03:24 +0000 (09:03 -0500)
applications on macOS (rdar://problem/37789645)

CHANGES.md
cups/ppd-util.c
cups/tempfile.c

index 7103a2363e0c654b0b56f320d84f4581af08177b..cb79ca75874ddda2a45450c96b1f9f2a4d14c6e3 100644 (file)
@@ -49,6 +49,8 @@ Changes in CUPS v2.2.7
   of "none" (rdar://36566269)
 - TLS connections now properly timeout (rdar://34938533)
 - The IPP backend did not properly detect failed PDF prints (rdar://34055474)
+- Temporary files are now placed in the correct directory for sandboxed
+  applications on macOS (rdar://problem/37789645)
 
 
 Changes in CUPS v2.2.6
index d0194c8034bac8d1eea0d9cefa5c4b01d9b61dad..5f81972af5c888e8c948a81d6630c19b40620d46 100644 (file)
@@ -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.
  *
  * These coded instructions, statements, and computer programs are the
  * property of Apple Inc. and are protected by Federal copyright
@@ -216,6 +216,27 @@ 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.
+       */
+
+        char           tmppath[1024];  /* Temporary directory */
+
+       if ((tmpdir = getenv("TMPDIR")) != NULL && access(tmpdir, W_OK))
+         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
@@ -224,11 +245,8 @@ 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__ */
 
        /*
        * Make the temporary name using the specified directory...
index da705a94ea70fca86636f033ef9c676b5ce31205..1e248694c8f7dcbcf818fdb6be1ecef81168f48f 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Temp file utilities for CUPS.
  *
- * Copyright 2007-2014 by Apple Inc.
- * Copyright 1997-2006 by Easy Software Products.
+ * Copyright © 2007-2018 by Apple Inc.
+ * Copyright © 1997-2006 by Easy Software Products.
  *
  * These coded instructions, statements, and computer programs are the
  * property of Apple Inc. and are protected by Federal copyright
@@ -42,8 +42,10 @@ cupsTempFd(char *filename,           /* I - Pointer to buffer */
   int          fd;                     /* File descriptor for temp file */
   int          tries;                  /* Number of tries */
   const char   *tmpdir;                /* TMPDIR environment var */
+#if defined(__APPLE__) || defined(WIN32)
+  char         tmppath[1024];          /* Temporary directory */
+#endif /* __APPLE__ || WIN32 */
 #ifdef WIN32
-  char         tmppath[1024];          /* Windows temporary directory */
   DWORD                curtime;                /* Current time */
 #else
   struct timeval curtime;              /* Current time */
@@ -60,6 +62,26 @@ cupsTempFd(char *filename,           /* I - Pointer to buffer */
     GetTempPath(sizeof(tmppath), tmppath);
     tmpdir = tmppath;
   }
+
+#elif defined(__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.
+  */
+
+  if ((tmpdir = getenv("TMPDIR")) != NULL && access(tmpdir, W_OK))
+    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
@@ -69,11 +91,7 @@ cupsTempFd(char *filename,           /* I - Pointer to buffer */
   */
 
   if ((tmpdir = getenv("TMPDIR")) == NULL)
-#  if defined(__APPLE__) && !TARGET_OS_IOS
-    tmpdir = "/private/tmp";           /* /tmp is a symlink to /private/tmp */
-#  else
     tmpdir = "/tmp";
-#  endif /* __APPLE__  && !TARGET_OS_IOS */
 #endif /* WIN32 */
 
  /*