]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/globals.c
Update ipp documentation to reflect the behavior of configuring WiFi on IPP USB printers.
[thirdparty/cups.git] / cups / globals.c
index 276bbcf5bfda592cff369164cfa2873520b702ed..fd41baefe5150769b119007914a2c2c0fb5c5f72 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
- * 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 */
 
 
 /*
@@ -34,23 +32,23 @@ static _cups_threadkey_t cups_globals_key = _CUPS_THREADKEY_INITIALIZER;
 static pthread_once_t  cups_globals_key_once = PTHREAD_ONCE_INIT;
                                        /* One-time initialization object */
 #endif /* HAVE_PTHREAD_H */
-#if defined(HAVE_PTHREAD_H) || defined(WIN32)
+#if defined(HAVE_PTHREAD_H) || defined(_WIN32)
 static _cups_mutex_t   cups_global_mutex = _CUPS_MUTEX_INITIALIZER;
                                        /* Global critical section */
-#endif /* HAVE_PTHREAD_H || WIN32 */
+#endif /* HAVE_PTHREAD_H || _WIN32 */
 
 
 /*
  * Local functions...
  */
 
-#ifdef WIN32
+#ifdef _WIN32
 static void            cups_fix_path(char *path);
-#endif /* WIN32 */
+#endif /* _WIN32 */
 static _cups_globals_t *cups_globals_alloc(void);
-#if defined(HAVE_PTHREAD_H) || defined(WIN32)
+#if defined(HAVE_PTHREAD_H) || defined(_WIN32)
 static void            cups_globals_free(_cups_globals_t *g);
-#endif /* HAVE_PTHREAD_H || WIN32 */
+#endif /* HAVE_PTHREAD_H || _WIN32 */
 #ifdef HAVE_PTHREAD_H
 static void            cups_globals_init(void);
 #endif /* HAVE_PTHREAD_H */
@@ -65,7 +63,7 @@ _cupsGlobalLock(void)
 {
 #ifdef HAVE_PTHREAD_H
   pthread_mutex_lock(&cups_global_mutex);
-#elif defined(WIN32)
+#elif defined(_WIN32)
   EnterCriticalSection(&cups_global_mutex.m_criticalSection);
 #endif /* HAVE_PTHREAD_H */
 }
@@ -120,13 +118,13 @@ _cupsGlobalUnlock(void)
 {
 #ifdef HAVE_PTHREAD_H
   pthread_mutex_unlock(&cups_global_mutex);
-#elif defined(WIN32)
+#elif defined(_WIN32)
   LeaveCriticalSection(&cups_global_mutex.m_criticalSection);
 #endif /* HAVE_PTHREAD_H */
 }
 
 
-#ifdef WIN32
+#ifdef _WIN32
 /*
  * 'DllMain()' - Main entry for library.
  */
@@ -170,7 +168,7 @@ DllMain(HINSTANCE hinst,            /* I - DLL module handle */
 
   return (TRUE);
 }
-#endif /* WIN32 */
+#endif /* _WIN32 */
 
 
 /*
@@ -182,13 +180,13 @@ cups_globals_alloc(void)
 {
   _cups_globals_t *cg = malloc(sizeof(_cups_globals_t));
                                        /* Pointer to global data */
-#ifdef WIN32
+#ifdef _WIN32
   HKEY         key;                    /* Registry key */
   DWORD                size;                   /* Size of string */
   static char  installdir[1024] = "",  /* Install directory */
                confdir[1024] = "",     /* Server root directory */
                localedir[1024] = "";   /* Locale directory */
-#endif /* WIN32 */
+#endif /* _WIN32 */
 
 
   if (!cg)
@@ -219,7 +217,7 @@ cups_globals_alloc(void)
   * Then set directories as appropriate...
   */
 
-#ifdef WIN32
+#ifdef _WIN32
   if (!installdir[0])
   {
    /*
@@ -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,8 +313,23 @@ 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__ */
   }
-#endif /* WIN32 */
+
+  if (!cg->home)
+  {
+    struct passwd      *pw;            /* User info */
+
+    if ((pw = getpwuid(getuid())) != NULL)
+      cg->home = _cupsStrAlloc(pw->pw_dir);
+  }
+#endif /* _WIN32 */
 
   return (cg);
 }
@@ -325,7 +339,7 @@ cups_globals_alloc(void)
  * 'cups_globals_free()' - Free global data.
  */
 
-#if defined(HAVE_PTHREAD_H) || defined(WIN32)
+#if defined(HAVE_PTHREAD_H) || defined(_WIN32)
 static void
 cups_globals_free(_cups_globals_t *cg) /* I - Pointer to global data */
 {
@@ -358,9 +372,12 @@ 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 */
+#endif /* HAVE_PTHREAD_H || _WIN32 */
 
 
 #ifdef HAVE_PTHREAD_H