Bump to cups 2.3.3
[platform/upstream/cups.git] / cups / globals.c
index 28c993b..fd41bae 100644 (file)
@@ -1,16 +1,11 @@
 /*
  * Global variable access routines for CUPS.
  *
- * Copyright 2007-2015 by Apple Inc.
- * Copyright 1997-2007 by Easy Software Products, all rights reserved.
+ * Copyright © 2007-2019 by Apple Inc.
+ * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
  *
- * These coded instructions, statements, and computer programs are the
- * 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
- * missing or damaged, see the license at "http://www.cups.org/".
- *
- * This file is subject to the Apple OS-Developed Software exception.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more
+ * information.
  */
 
 /*
@@ -18,6 +13,9 @@
  */
 
 #include "cups-private.h"
+#ifndef _WIN32
+#  include <pwd.h>
+#endif /* !_WIN32 */
 
 
 /*
@@ -228,8 +226,7 @@ cups_globals_alloc(void)
 
     strlcpy(installdir, "C:/Program Files/cups.org", sizeof(installdir));
 
-    if (!RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\cups.org", 0, KEY_READ,
-                      &key))
+    if (!RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\cups.org", 0, KEY_READ, &key))
     {
      /*
       * Grab the installation directory...
@@ -238,7 +235,7 @@ cups_globals_alloc(void)
       char  *ptr;                      /* Pointer into installdir */
 
       size = sizeof(installdir);
-      RegQueryValueEx(key, "installdir", NULL, NULL, installdir, &size);
+      RegQueryValueExA(key, "installdir", NULL, NULL, installdir, &size);
       RegCloseKey(key);
 
       for (ptr = installdir; *ptr;)
@@ -276,6 +273,8 @@ cups_globals_alloc(void)
   if ((cg->localedir = getenv("LOCALEDIR")) == NULL)
     cg->localedir = localedir;
 
+  cg->home = getenv("HOME");
+
 #else
 #  ifdef HAVE_GETEUID
   if ((geteuid() != getuid() && getuid()) || getegid() != getgid())
@@ -314,6 +313,21 @@ cups_globals_alloc(void)
 
     if ((cg->localedir = getenv("LOCALEDIR")) == NULL)
       cg->localedir = CUPS_LOCALEDIR;
+
+    cg->home = getenv("HOME");
+
+#  ifdef __APPLE__ /* Sandboxing now exposes the container as the home directory */
+    if (cg->home && strstr(cg->home, "/Library/Containers/"))
+      cg->home = NULL;
+#  endif /* !__APPLE__ */
+  }
+
+  if (!cg->home)
+  {
+    struct passwd      *pw;            /* User info */
+
+    if ((pw = getpwuid(getuid())) != NULL)
+      cg->home = _cupsStrAlloc(pw->pw_dir);
   }
 #endif /* _WIN32 */
 
@@ -358,6 +372,9 @@ cups_globals_free(_cups_globals_t *cg)      /* I - Pointer to global data */
 
   cupsFreeOptions(cg->cupsd_num_settings, cg->cupsd_settings);
 
+  if (cg->raster_error.start)
+    free(cg->raster_error.start);
+
   free(cg);
 }
 #endif /* HAVE_PTHREAD_H || _WIN32 */