X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=scheduler%2Fenv.c;h=71ab98d6b8b642f704e061a77d2fa4dd46bf3d39;hb=dc84a5a4cdb6900256a6ea9f627336bc19903dcc;hp=b9c49dc3fabd5ab16821c9a3db2c29acdd2fd2b7;hpb=e1d6a77454308ff30d6da778be9d7b570e4f00b0;p=thirdparty%2Fcups.git diff --git a/scheduler/env.c b/scheduler/env.c index b9c49dc3f..71ab98d6b 100644 --- a/scheduler/env.c +++ b/scheduler/env.c @@ -1,34 +1,10 @@ /* - * "$Id: env.c 5305 2006-03-18 03:05:12Z mike $" + * Environment management routines for the CUPS scheduler. * - * Environment management routines for the Common UNIX Printing System (CUPS). + * Copyright 2007-2016 by Apple Inc. + * Copyright 1997-2006 by Easy Software Products, all rights reserved. * - * Copyright 1997-2006 by Easy Software Products, all rights reserved. - * - * These coded instructions, statements, and computer programs are the - * property of Easy Software Products 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 please contact Easy Software Products - * at: - * - * Attn: CUPS Licensing Information - * Easy Software Products - * 44141 Airport View Drive, Suite 204 - * Hollywood, Maryland 20636 USA - * - * Voice: (301) 373-9600 - * EMail: cups-info@cups.org - * WWW: http://www.cups.org - * - * Contents: - * - * cupsdInitEnv() - Initialize the current environment with standard - * variables. - * cupsdLoadEnv() - Copy common environment variables into an array. - * cupsdSetEnv() - Set a common environment variable. - * cupsdSetEnvf() - Set a formatted common environment variable. - * clear_env() - Clear common environment variables. + * Licensed under Apache License v2.0. See the file "LICENSE" for more information. */ /* @@ -51,6 +27,7 @@ static char *common_env[MAX_ENV]; /* Common env vars */ */ static void clear_env(void); +static int find_env(const char *name); /* @@ -68,43 +45,15 @@ cupsdInitEnv(void) #if defined(__APPLE__) /* - * Add special voodoo magic for MacOS X 10.4 and later - this allows MacOS - * X programs to access their bundle resources properly... + * Add special voodoo magic for macOS - this allows macOS + * programs to access their bundle resources properly... * - * This string is replaced in cupsdStartProcess() when we are running on - * versions of MacOS X prior to 10.4... + * This string is replaced in cupsdStartProcess()... */ cupsdSetString(common_env, ""); num_common_env = 1; #endif /* __APPLE__ */ - - /* - * Set common variables... - */ - - cupsdSetEnv("CUPS_CACHEDIR", CacheDir); - cupsdSetEnv("CUPS_DATADIR", DataDir); - cupsdSetEnv("CUPS_DOCROOT", DocumentRoot); - cupsdSetEnv("CUPS_FONTPATH", FontPath); - cupsdSetEnv("CUPS_REQUESTROOT", RequestRoot); - cupsdSetEnv("CUPS_SERVERBIN", ServerBin); - cupsdSetEnv("CUPS_SERVERROOT", ServerRoot); - cupsdSetEnv("CUPS_STATEDIR", StateDir); - cupsdSetEnv("DYLD_LIBRARY_PATH", NULL); - cupsdSetEnv("LD_ASSUME_KERNEL", NULL); - cupsdSetEnv("LD_LIBRARY_PATH", NULL); - cupsdSetEnv("LD_PRELOAD", NULL); - cupsdSetEnv("NLSPATH", NULL); - cupsdSetEnvf("PATH", "%s/filter:" CUPS_BINDIR ":" CUPS_SBINDIR - ":/bin:/usr/bin", ServerBin); - cupsdSetEnv("SERVER_ADMIN", ServerAdmin); - cupsdSetEnv("SHLIB_PATH", NULL); - cupsdSetEnv("SOFTWARE", CUPS_MINIMAL); - cupsdSetEnv("TMPDIR", TempDir); - cupsdSetEnv("TZ", NULL); - cupsdSetEnv("USER", "root"); - cupsdSetEnv("VG_ARGS", NULL); } @@ -151,8 +100,7 @@ void cupsdSetEnv(const char *name, /* I - Name of variable */ const char *value) /* I - Value of variable */ { - int i, /* Looping var */ - namelen; /* Length of name */ + int i; /* Index into environent array */ /* @@ -166,14 +114,17 @@ cupsdSetEnv(const char *name, /* I - Name of variable */ return; /* - * See if this variable has already been defined... + * Do not allow dynamic linker variables when running as root... */ - for (i = 0, namelen = strlen(name); i < num_common_env; i ++) - if (!strncmp(common_env[i], name, namelen) && common_env[i][namelen] == '=') - break; + if (!RunUser && (!strncmp(name, "DYLD_", 5) || !strncmp(name, "LD_", 3))) + return; - if (i >= num_common_env) + /* + * See if this variable has already been defined... + */ + + if ((i = find_env(name)) < 0) { /* * Check for room... @@ -186,6 +137,7 @@ cupsdSetEnv(const char *name, /* I - Name of variable */ return; } + i = num_common_env; num_common_env ++; } @@ -195,7 +147,7 @@ cupsdSetEnv(const char *name, /* I - Name of variable */ cupsdSetStringf(common_env + i, "%s=%s", name, value); - cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdSetEnv: %s\n", common_env[i]); + cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdSetEnv: %s", common_env[i]); } @@ -228,6 +180,49 @@ cupsdSetEnvf(const char *name, /* I - Name of variable */ } +/* + * 'cupsdUpdateEnv()' - Update the environment for the configured directories. + */ + +void +cupsdUpdateEnv(void) +{ + /* + * Set common variables... + */ + +#define set_if_undefined(name,value) if (find_env(name) < 0) cupsdSetEnv(name,value) + + set_if_undefined("CUPS_CACHEDIR", CacheDir); + set_if_undefined("CUPS_DATADIR", DataDir); + set_if_undefined("CUPS_DOCROOT", DocumentRoot); + set_if_undefined("CUPS_FONTPATH", FontPath); + set_if_undefined("CUPS_REQUESTROOT", RequestRoot); + set_if_undefined("CUPS_SERVERBIN", ServerBin); + set_if_undefined("CUPS_SERVERROOT", ServerRoot); + set_if_undefined("CUPS_STATEDIR", StateDir); + set_if_undefined("DYLD_INSERT_LIBRARIES", NULL); + set_if_undefined("DYLD_LIBRARY_PATH", NULL); + set_if_undefined("HOME", TempDir); + set_if_undefined("LD_ASSUME_KERNEL", NULL); + set_if_undefined("LD_LIBRARY_PATH", NULL); + set_if_undefined("LD_PRELOAD", NULL); + set_if_undefined("NLSPATH", NULL); + if (find_env("PATH") < 0) + cupsdSetEnvf("PATH", "%s/filter:" CUPS_BINDIR ":" CUPS_SBINDIR + ":/bin:/usr/bin", ServerBin); + set_if_undefined("SERVER_ADMIN", ServerAdmin); + set_if_undefined("SHLIB_PATH", NULL); + set_if_undefined("SOFTWARE", CUPS_MINIMAL); + set_if_undefined("TMPDIR", TempDir); + set_if_undefined("TZ", NULL); + set_if_undefined("USER", "root"); + set_if_undefined("VG_ARGS", NULL); + + cupsdSetEnvf("CUPS_MAX_MESSAGE", "%d", CUPSD_SB_BUFFER_SIZE - 1); +} + + /* * 'clear_env()' - Clear common environment variables. */ @@ -246,5 +241,19 @@ clear_env(void) /* - * End of "$Id: env.c 5305 2006-03-18 03:05:12Z mike $". + * 'find_env()' - Find a common environment variable. */ + +static int /* O - Index or -1 if not found */ +find_env(const char *name) /* I - Variable name */ +{ + int i; /* Looping var */ + size_t namelen; /* Length of name */ + + + for (i = 0, namelen = strlen(name); i < num_common_env; i ++) + if (!strncmp(common_env[i], name, namelen) && common_env[i][namelen] == '=') + return (i); + + return (-1); +}