/*
* "$Id: globals.c 7870 2008-08-27 18:14:10Z mike $"
*
- * Global variable access routines for the Common UNIX Printing System (CUPS).
+ * Global variable access routines for CUPS.
*
- * Copyright 2007-2009 by Apple Inc.
+ * Copyright 2007-2010 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
* Include necessary headers...
*/
-#include "http-private.h"
-#include "globals.h"
-#include <stdlib.h>
+#include "cups-private.h"
/*
static void
cups_env_init(_cups_globals_t *g) /* I - Global data */
{
+#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 */
+
+
+ /*
+ * Open the registry...
+ */
+
+ strcpy(installdir, "C:/Program Files/cups.org");
+
+ if (!RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\cups.org", 0, KEY_READ,
+ &key))
+ {
+ /*
+ * Grab the installation directory...
+ */
+
+ size = sizeof(installdir);
+ RegQueryValueEx(key, "installdir", NULL, NULL, installdir, &size);
+ RegCloseKey(key);
+ }
+
+ snprintf(confdir, sizeof(confdir), "%s/conf", installdir);
+ snprintf(localedir, sizeof(localedir), "%s/locale", installdir);
+
if ((g->cups_datadir = getenv("CUPS_DATADIR")) == NULL)
- g->cups_datadir = CUPS_DATADIR;
+ g->cups_datadir = installdir;
if ((g->cups_serverbin = getenv("CUPS_SERVERBIN")) == NULL)
- g->cups_serverbin = CUPS_SERVERBIN;
+ g->cups_serverbin = installdir;
if ((g->cups_serverroot = getenv("CUPS_SERVERROOT")) == NULL)
- g->cups_serverroot = CUPS_SERVERROOT;
+ g->cups_serverroot = confdir;
if ((g->cups_statedir = getenv("CUPS_STATEDIR")) == NULL)
- g->cups_statedir = CUPS_STATEDIR;
+ g->cups_statedir = confdir;
if ((g->localedir = getenv("LOCALEDIR")) == NULL)
- g->localedir = CUPS_LOCALEDIR;
+ g->localedir = localedir;
+
+#else
+# ifdef HAVE_GETEUID
+ if ((geteuid() != getuid() && getuid()) || getegid() != getgid())
+# else
+ if (!getuid())
+# endif /* HAVE_GETEUID */
+ {
+ /*
+ * When running setuid/setgid, don't allow environment variables to override
+ * the directories...
+ */
+
+ g->cups_datadir = CUPS_DATADIR;
+ g->cups_serverbin = CUPS_SERVERBIN;
+ g->cups_serverroot = CUPS_SERVERROOT;
+ g->cups_statedir = CUPS_STATEDIR;
+ g->localedir = CUPS_LOCALEDIR;
+ }
+ else
+ {
+ /*
+ * Allow directories to be overridden by environment variables.
+ */
+
+ if ((g->cups_datadir = getenv("CUPS_DATADIR")) == NULL)
+ g->cups_datadir = CUPS_DATADIR;
+
+ if ((g->cups_serverbin = getenv("CUPS_SERVERBIN")) == NULL)
+ g->cups_serverbin = CUPS_SERVERBIN;
+
+ if ((g->cups_serverroot = getenv("CUPS_SERVERROOT")) == NULL)
+ g->cups_serverroot = CUPS_SERVERROOT;
+
+ if ((g->cups_statedir = getenv("CUPS_STATEDIR")) == NULL)
+ g->cups_statedir = CUPS_STATEDIR;
+
+ if ((g->localedir = getenv("LOCALEDIR")) == NULL)
+ g->localedir = CUPS_LOCALEDIR;
+ }
+#endif /* WIN32 */
}
_cups_globals_t *globals; /* Pointer to global data */
- /*
+ /*
* Initialize the global data exactly once...
*/