dirsvc.o: ../cups/http.h ../cups/language.h ../cups/debug.h statbuf.h cert.h
dirsvc.o: auth.h client.h policy.h printers.h classes.h job.h conf.h
dirsvc.o: banners.h dirsvc.h network.h subscriptions.h
+env.o: cupsd.h ../cups/http-private.h ../config.h ../cups/http.h
+env.o: ../cups/md5.h ../cups/string.h ../cups/cups.h ../cups/ipp.h
+env.o: ../cups/ppd.h ../cups/file.h mime.h ../cups/ipp.h ../cups/file.h
+env.o: ../cups/http.h ../cups/language.h ../cups/debug.h statbuf.h cert.h
+env.o: auth.h client.h policy.h printers.h classes.h job.h conf.h banners.h
+env.o: dirsvc.h network.h subscriptions.h
main.o: cupsd.h ../cups/http-private.h ../config.h ../cups/http.h
main.o: ../cups/md5.h ../cups/string.h ../cups/cups.h ../cups/ipp.h
main.o: ../cups/ppd.h ../cups/file.h mime.h ../cups/ipp.h ../cups/file.h
cups-driverd.o: util.h ../cups/cups.h ../cups/ipp.h ../cups/http.h
cups-driverd.o: ../cups/md5.h ../cups/ppd.h ../cups/file.h ../cups/file.h
cups-driverd.o: ../cups/string.h ../config.h ../cups/dir.h
-util.o: util.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h
-util.o: ../cups/ppd.h ../cups/file.h ../cups/file.h ../cups/string.h
-util.o: ../config.h
cups-lpd.o: ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h
cups-lpd.o: ../cups/ppd.h ../cups/file.h ../cups/string.h ../config.h
cups-lpd.o: ../cups/language.h
testmime.o: ../cups/string.h ../config.h mime.h ../cups/ipp.h ../cups/file.h
testspeed.o: ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h
testspeed.o: ../cups/ppd.h ../cups/file.h ../cups/language.h ../cups/debug.h
+util.o: util.h ../cups/cups.h ../cups/ipp.h ../cups/http.h ../cups/md5.h
+util.o: ../cups/ppd.h ../cups/file.h ../cups/file.h ../cups/string.h
+util.o: ../config.h
include ../Makedefs
-CUPSDOBJS = auth.o banners.o cert.o classes.o client.o conf.o \
- dirsvc.o main.o ipp.o listen.o job.o log.o network.o \
- policy.o printers.o process.o quotas.o server.o \
- statbuf.o subscriptions.o
-MIMEOBJS = filter.o mime.o type.o
-OBJS = $(CUPSDOBJS) $(MIMEOBJS) \
- cups-deviced.o cups-driverd.o util.o \
+CUPSDOBJS = \
+ auth.o \
+ banners.o \
+ cert.o \
+ classes.o \
+ client.o \
+ conf.o \
+ dirsvc.o \
+ env.o \
+ main.o \
+ ipp.o \
+ listen.o \
+ job.o \
+ log.o \
+ network.o \
+ policy.o \
+ printers.o \
+ process.o \
+ quotas.o \
+ server.o \
+ statbuf.o \
+ subscriptions.o
+MIMEOBJS = \
+ filter.o \
+ mime.o \
+ type.o
+OBJS = \
+ $(CUPSDOBJS) \
+ $(MIMEOBJS) \
+ cups-deviced.o \
+ cups-driverd.o \
cups-lpd.o \
cups-polld.o \
testmime.o \
- testspeed.o
-TARGETS = cupsd cups-deviced cups-driverd cups-lpd cups-polld libmime.a \
- testmime testspeed
+ testspeed.o \
+ util.o
+TARGETS = \
+ cupsd \
+ cups-deviced \
+ cups-driverd \
+ cups-lpd \
+ cups-polld \
+ libmime.a \
+ testmime \
+ testspeed
#
*envp[100]; /* Environment variables */
char content_length[1024], /* CONTENT_LENGTH environment variable */
content_type[1024], /* CONTENT_TYPE environment variable */
- cups_cachedir[1024], /* CUPS_CACHEDIR environment variable */
- cups_datadir[1024], /* CUPS_DATADIR environment variable */
- cups_docroot[1024], /* CUPS_DOCROOT environment variable */
- cups_serverbin[1024], /* CUPS_SERVERBIN environment variable */
- cups_serverroot[1024], /* CUPS_SERVERROOT environment variable */
- cups_statedir[1024], /* CUPS_STATEDIR environment variable */
http_cookie[1024], /* HTTP_COOKIE environment variable */
http_user_agent[1024], /* HTTP_USER_AGENT environment variable */
- ipp_port[1024], /* IPP_PORT environment variable */
lang[1024], /* LANG environment variable */
- ld_library_path[1024], /* LD_LIBRARY_PATH environment variable */
- ld_preload[1024], /* LD_PRELOAD environment variable */
- dyld_library_path[1024],/* DYLD_LIBRARY_PATH environment variable */
- shlib_path[1024], /* SHLIB_PATH environment variable */
- nlspath[1024], /* NLSPATH environment variable */
*query_string, /* QUERY_STRING env variable */
remote_addr[1024], /* REMOTE_ADDR environment variable */
remote_host[1024], /* REMOTE_HOST environment variable */
remote_user[1024], /* REMOTE_USER environment variable */
script_name[1024], /* SCRIPT_NAME environment variable */
server_name[1024], /* SERVER_NAME environment variable */
- server_port[1024], /* SERVER_PORT environment variable */
- tmpdir[1024], /* TMPDIR environment variable */
- vg_args[1024], /* VG_ARGS environment variable */
- ld_assume_kernel[1024]; /* LD_ASSUME_KERNEL environment variable */
+ server_port[1024]; /* SERVER_PORT environment variable */
static const char * const locale_encodings[] =
{ /* Locale charset names */
"ASCII", "ISO8859-1", "ISO8859-2", "ISO8859-3",
"EUC-CN", "EUC-JP", "EUC-KR", "EUC-TW"
};
- static const char * const encryptions[] =
- {
- "CUPS_ENCRYPTION=IfRequested",
- "CUPS_ENCRYPTION=Never",
- "CUPS_ENCRYPTION=Required",
- "CUPS_ENCRYPTION=Always"
- };
/*
else
strcpy(lang, "LANG=C");
- sprintf(ipp_port, "IPP_PORT=%d", LocalPort);
-#ifdef AF_INET6
- if (con->http.hostaddr.addr.sa_family == AF_INET6)
- sprintf(server_port, "SERVER_PORT=%d",
- ntohs(con->http.hostaddr.ipv6.sin6_port));
- else
-#endif /* AF_INET6 */
- sprintf(server_port, "SERVER_PORT=%d",
- ntohs(con->http.hostaddr.ipv4.sin_port));
-
- if (strcmp(con->http.hostname, "localhost") == 0)
- strlcpy(server_name, "SERVER_NAME=localhost", sizeof(server_name));
- else
- snprintf(server_name, sizeof(server_name), "SERVER_NAME=%s", ServerName);
- snprintf(remote_host, sizeof(remote_host), "REMOTE_HOST=%s", con->http.hostname);
strcpy(remote_addr, "REMOTE_ADDR=");
httpAddrString(&(con->http.hostaddr), remote_addr + 12,
sizeof(remote_addr) - 12);
- snprintf(remote_user, sizeof(remote_user), "REMOTE_USER=%s", con->username);
- snprintf(tmpdir, sizeof(tmpdir), "TMPDIR=%s", TempDir);
- snprintf(cups_cachedir, sizeof(cups_cachedir), "CUPS_CACHEDIR=%s", CacheDir);
- snprintf(cups_datadir, sizeof(cups_datadir), "CUPS_DATADIR=%s", DataDir);
- snprintf(cups_docroot, sizeof(cups_docroot), "CUPS_DOCROOT=%s", DocumentRoot);
- snprintf(cups_serverbin, sizeof(cups_serverbin), "CUPS_SERVERBIN=%s", ServerBin);
- snprintf(cups_serverroot, sizeof(cups_serverroot), "CUPS_SERVERROOT=%s", ServerRoot);
- snprintf(cups_statedir, sizeof(cups_statedir), "CUPS_STATEDIR=%s", StateDir);
-
- envc = 0;
-
- envp[envc ++] = "PATH=/bin:/usr/bin";
- envp[envc ++] = "SERVER_SOFTWARE=CUPS/1.1";
- envp[envc ++] = "GATEWAY_INTERFACE=CGI/1.1";
- if (con->http.version == HTTP_1_1)
- envp[envc ++] = "SERVER_PROTOCOL=HTTP/1.1";
- else if (con->http.version == HTTP_1_0)
- envp[envc ++] = "SERVER_PROTOCOL=HTTP/1.0";
- else
- envp[envc ++] = "SERVER_PROTOCOL=HTTP/0.9";
+
+ snprintf(remote_host, sizeof(remote_host), "REMOTE_HOST=%s",
+ con->http.hostname);
+
+ snprintf(script_name, sizeof(script_name), "SCRIPT_NAME=%s", con->uri);
+ if ((uriptr = strchr(script_name, '?')) != NULL)
+ *uriptr = '\0';
+
+ sprintf(server_port, "SERVER_PORT=%d", con->serverport);
+
+ snprintf(server_name, sizeof(server_name), "SERVER_NAME=%s",
+ con->servername);
+
+ envc = cupsdLoadEnv(envp, (int)(sizeof(envp) / sizeof(envp[0])));
+
+ envp[envc ++] = lang;
envp[envc ++] = "REDIRECT_STATUS=1";
- envp[envc ++] = "CUPS_SERVER=localhost";
- envp[envc ++] = ipp_port;
envp[envc ++] = server_name;
envp[envc ++] = server_port;
envp[envc ++] = remote_addr;
envp[envc ++] = remote_host;
- if (con->username[0])
- envp[envc ++] = remote_user;
- envp[envc ++] = lang;
- envp[envc ++] = TZ;
- envp[envc ++] = tmpdir;
- envp[envc ++] = cups_cachedir;
- envp[envc ++] = cups_datadir;
- envp[envc ++] = cups_docroot;
- envp[envc ++] = cups_serverbin;
- envp[envc ++] = cups_serverroot;
- envp[envc ++] = cups_statedir;
-
- if (getenv("VG_ARGS") != NULL)
- {
- snprintf(vg_args, sizeof(vg_args), "VG_ARGS=%s", getenv("VG_ARGS"));
- envp[envc ++] = vg_args;
- }
-
- if (getenv("LD_ASSUME_KERNEL") != NULL)
- {
- snprintf(ld_assume_kernel, sizeof(ld_assume_kernel), "LD_ASSUME_KERNEL=%s",
- getenv("LD_ASSUME_KERNEL"));
- envp[envc ++] = ld_assume_kernel;
- }
-
- if (getenv("LD_LIBRARY_PATH") != NULL)
- {
- snprintf(ld_library_path, sizeof(ld_library_path), "LD_LIBRARY_PATH=%s",
- getenv("LD_LIBRARY_PATH"));
- envp[envc ++] = ld_library_path;
- }
-
- if (getenv("LD_PRELOAD") != NULL)
- {
- snprintf(ld_preload, sizeof(ld_preload), "LD_PRELOAD=%s",
- getenv("LD_PRELOAD"));
- envp[envc ++] = ld_preload;
- }
+ envp[envc ++] = script_name;
- if (getenv("DYLD_LIBRARY_PATH") != NULL)
+ if (con->username[0])
{
- snprintf(dyld_library_path, sizeof(dyld_library_path), "DYLD_LIBRARY_PATH=%s",
- getenv("DYLD_LIBRARY_PATH"));
- envp[envc ++] = dyld_library_path;
- }
+ snprintf(remote_user, sizeof(remote_user), "REMOTE_USER=%s", con->username);
- if (getenv("SHLIB_PATH") != NULL)
- {
- snprintf(shlib_path, sizeof(shlib_path), "SHLIB_PATH=%s",
- getenv("SHLIB_PATH"));
- envp[envc ++] = shlib_path;
+ envp[envc ++] = remote_user;
}
- if (getenv("NLSPATH") != NULL)
- {
- snprintf(nlspath, sizeof(nlspath), "NLSPATH=%s", getenv("NLSPATH"));
- envp[envc ++] = nlspath;
- }
+ if (con->http.version == HTTP_1_1)
+ envp[envc ++] = "SERVER_PROTOCOL=HTTP/1.1";
+ else if (con->http.version == HTTP_1_0)
+ envp[envc ++] = "SERVER_PROTOCOL=HTTP/1.0";
+ else
+ envp[envc ++] = "SERVER_PROTOCOL=HTTP/0.9";
if (con->http.cookie)
{
envp[envc ++] = http_user_agent;
}
- snprintf(script_name, sizeof(script_name), "SCRIPT_NAME=%s", con->uri);
- if ((uriptr = strchr(script_name, '?')) != NULL)
- *uriptr = '\0';
- envp[envc ++] = script_name;
-
if (con->operation == HTTP_GET)
{
for (i = 0; i < argc; i ++)
LogMessage(L_DEBUG2, "argv[%d] = \"%s\"", i, argv[i]);
+
envp[envc ++] = "REQUEST_METHOD=GET";
if (query_string)
if (con->http.encryption == HTTP_ENCRYPT_ALWAYS)
envp[envc ++] = "HTTPS=ON";
- envp[envc ++] = (char *)encryptions[LocalEncryption];
-
/*
* Terminate the environment array...
*/
TempDir, strerror(errno));
}
+ /*
+ * Setup environment variables...
+ */
+
+ cupsdInitEnv();
+
/*
* Check the MaxClients setting, and then allocate memory for it...
*/
SignalCount VALUE(0);
/* Signal handler level */
-VAR char *TZ VALUE(NULL);
- /* Timezone configuration */
-
/*
* Prototypes...
extern void LoadPPDs(const char *d);
extern void ReleaseSignals(void);
extern void SetString(char **s, const char *v);
-extern void SetStringf(char **s, const char *f, ...);
+extern void SetStringf(char **s, const char *f, ...)
+#ifdef __GNUC__
+__attribute__ ((__format__ (__printf__, 2, 3)))
+#endif /* __GNUC__ */
+;
extern void StartServer(void);
extern void StopServer(void);
extern void cupsdClosePipe(int *fds);
extern int cupsdOpenPipe(int *fds);
+extern void cupsdClearEnv(void);
+extern void cupsdInitEnv(void);
+extern int cupsdLoadEnv(char *envp[], int envmax);
+extern void cupsdSetEnv(const char *name, const char *value);
+extern void cupsdSetEnvf(const char *name, const char *value, ...)
+#ifdef __GNUC__
+__attribute__ ((__format__ (__printf__, 2, 3)))
+#endif /* __GNUC__ */
+;
+
+extern int cupsdEndProcess(int pid, int force);
extern int cupsdStartProcess(const char *command, char *argv[],
char *envp[], int infd, int outfd,
int errfd, int backfd, int root, int *pid);
-extern int cupsdEndProcess(int pid, int force);
/*
char interval[10]; /* Poll interval */
int statusfds[2]; /* Status pipe */
char *argv[6]; /* Arguments */
+ char *envp[100]; /* Environment */
/*
argv[4] = bport;
argv[5] = NULL;
+ cupsdLoadEnv(envp, (int)(sizeof(envp) / sizeof(envp[0])));
+
/*
* Create a pipe that receives the status messages from each
* polling daemon...
argv[1] = poll->hostname;
- if (cupsdStartProcess(polld, argv, NULL, -1, -1, statusfds[1], -1,
+ if (cupsdStartProcess(polld, argv, envp, -1, -1, statusfds[1], -1,
0, &(poll->pid)) < 0)
{
LogMessage(L_ERROR, "StartPolling: Unable to fork polling daemon - %s",
--- /dev/null
+/*
+ * "$Id$"
+ *
+ * Environment management routines for the Common UNIX Printing System (CUPS).
+ *
+ * Copyright 1997-2005 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:
+ *
+ * cupsdClearEnv() - Clear common environment variables.
+ * 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.
+ */
+
+/*
+ * Include necessary headers...
+ */
+
+#include "cupsd.h"
+
+
+/*
+ * Local globals...
+ */
+
+static int num_common_env = 0; /* Number of common env vars */
+static char *common_env[100]; /* Common env vars */
+
+
+/*
+ * 'cupsdClearEnv()' - Clear common environment variables.
+ */
+
+void
+cupsdClearEnv(void)
+{
+ int i; /* Looping var */
+
+
+ for (i = 0; i < num_common_env; i ++)
+ ClearString(common_env + i);
+
+ num_common_env = 0;
+}
+
+
+/*
+ * 'cupsdInitEnv()' - Initialize the current environment with standard variables.
+ */
+
+void
+cupsdInitEnv(void)
+{
+ /*
+ * Clear existing environment variables...
+ */
+
+ cupsdClearEnv();
+
+#ifdef __APPLE__
+ /*
+ * Add special voodoo magic for MacOS X - this allows MacOS X programs
+ * to access their bundle resources properly...
+ */
+
+ SetString(common_env, "<CFProcessPath>");
+ 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_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:/bin:/usr/bin", ServerBin);
+ cupsdSetEnv("SHLIB_PATH", NULL);
+ cupsdSetEnv("SOFTWARE", CUPS_MINIMAL);
+ cupsdSetEnv("TMPDIR", TempDir);
+ cupsdSetEnv("TZ", NULL);
+ cupsdSetEnv("USER", "root");
+ cupsdSetEnv("VG_ARGS", NULL);
+}
+
+
+/*
+ * 'cupsdLoadEnv()' - Copy common environment variables into an array.
+ */
+
+int /* O - Number of environment variables */
+cupsdLoadEnv(char *envp[], /* I - Environment array */
+ int envmax) /* I - Maximum number of elements */
+{
+ int i; /* Looping var */
+
+
+ /*
+ * Leave room for a NULL pointer at the end...
+ */
+
+ envmax --;
+
+ /*
+ * Copy pointers to the environment...
+ */
+
+ for (i = 0; i < num_common_env && i < envmax; i ++)
+ envp[i] = common_env[i];
+
+ /*
+ * NULL terminate the environment array and return the number of
+ * elements we added...
+ */
+
+ envp[i] = NULL;
+
+ return (i);
+}
+
+
+/*
+ * 'cupsdSetEnv()' - Set a common environment variable.
+ */
+
+void
+cupsdSetEnv(const char *name, /* I - Name of variable */
+ const char *value) /* I - Value of variable */
+{
+ /*
+ * Check for room...
+ */
+
+ if (num_common_env >= (int)(sizeof(common_env) / sizeof(common_env[0])))
+ {
+ LogMessage(L_ERROR, "cupsdSetEnv: Too many environment variables set!");
+ return;
+ }
+
+ /*
+ * If "value" is NULL, try getting value from current environment...
+ */
+
+ if (!value)
+ value = getenv(name);
+
+ if (!value)
+ return;
+
+ /*
+ * Set the new environment variable...
+ */
+
+ SetStringf(common_env + num_common_env, "%s=%s", name, value);
+
+ LogMessage(L_DEBUG, "cupsdSetEnv: %s\n", common_env[num_common_env]);
+
+ num_common_env ++;
+}
+
+
+/*
+ * 'cupsdSetEnvf()' - Set a formatted common environment variable.
+ */
+
+void
+cupsdSetEnvf(const char *name, /* I - Name of variable */
+ const char *value, /* I - Printf-style value of variable */
+ ...) /* I - Additional args as needed */
+{
+ char v[4096]; /* Formatting string value */
+ va_list ap; /* Argument pointer */
+
+
+ /*
+ * Format the value string...
+ */
+
+ va_start(ap, value);
+ vsnprintf(v, sizeof(v), value, ap);
+ va_end(ap);
+
+ /*
+ * Set the env variable...
+ */
+
+ cupsdSetEnv(name, v);
+}
+
+
+/*
+ * End of "$Id$".
+ */
filterfds[2][2]; /* Pipes used between the filters */
int envc; /* Number of environment variables */
char *argv[8], /* Filter command-line arguments */
+ sani_uri[1024], /* Sanitized DEVICE_URI env var */
filename[1024], /* Job filename */
command[1024], /* Full path to filter/backend command */
jobid[255], /* Job ID string */
title[IPP_MAX_NAME], /* Job title string */
copies[255], /* # copies string */
*envp[100], /* Environment variables */
-#ifdef __APPLE__
- processPath[1050], /* CFProcessPath environment variable */
-#endif /* __APPLE__ */
- path[1024], /* PATH environment variable */
- ipp_port[1024], /* IPP_PORT environment variable */
- language[255], /* LANG environment variable */
charset[255], /* CHARSET environment variable */
+ class_name[255], /* CLASS environment variable */
classification[1024], /* CLASSIFICATION environment variable */
content_type[1024], /* CONTENT_TYPE environment variable */
device_uri[1024], /* DEVICE_URI environment variable */
- sani_uri[1024], /* Sanitized DEVICE_URI env var */
+ lang[255], /* LANG environment variable */
ppd[1024], /* PPD environment variable */
- class_name[255], /* CLASS environment variable */
printer_name[255], /* PRINTER environment variable */
- cups_cachedir[1024], /* CUPS_CACHEDIR environment variable */
- cups_datadir[1024], /* CUPS_DATADIR environment variable */
- cups_docroot[1024], /* CUPS_DOCROOT environment variable */
- cups_fontpath[1024], /* CUPS_FONTPATH environment variable */
- cups_serverbin[1024], /* CUPS_SERVERBIN environment variable */
- cups_serverroot[1024], /* CUPS_SERVERROOT environment variable */
- cups_statedir[1024], /* CUPS_STATEDIR environment variable */
- cache[255], /* RIP_MAX_CACHE environment variable */
- tmpdir[1024], /* TMPDIR environment variable */
- ld_library_path[1024], /* LD_LIBRARY_PATH environment variable */
- ld_preload[1024], /* LD_PRELOAD environment variable */
- dyld_library_path[1024],/* DYLD_LIBRARY_PATH environment variable */
- shlib_path[1024], /* SHLIB_PATH environment variable */
- nlspath[1024], /* NLSPATH environment variable */
- vg_args[1024], /* VG_ARGS environment variable */
- ld_assume_kernel[1024]; /* LD_ASSUME_KERNEL environment variable */
+ rip_max_cache[255]; /* RIP_MAX_CACHE environment variable */
static char *options = NULL; /* Full list of options */
static int optlength = 0; /* Length of option buffer */
* the POSIX locale...
*/
- strcpy(language, "LANG=C");
+ strcpy(lang, "LANG=C");
break;
case 2 :
* Just the language code (ll)...
*/
- snprintf(language, sizeof(language), "LANG=%s",
+ snprintf(lang, sizeof(lang), "LANG=%s",
attr->values[0].string.text);
break;
* Language and country code (ll-cc)...
*/
- snprintf(language, sizeof(language), "LANG=%c%c_%c%c",
+ snprintf(lang, sizeof(lang), "LANG=%c%c_%c%c",
attr->values[0].string.text[0],
attr->values[0].string.text[1],
toupper(attr->values[0].string.text[3] & 255),
attr->values[0].string.text);
}
- snprintf(path, sizeof(path), "PATH=%s/filter:/bin:/usr/bin", ServerBin);
snprintf(content_type, sizeof(content_type), "CONTENT_TYPE=%s/%s",
current->filetypes[current->current_file]->super,
current->filetypes[current->current_file]->type);
cupsdSanitizeURI(printer->device_uri, sani_uri, sizeof(sani_uri));
snprintf(ppd, sizeof(ppd), "PPD=%s/ppd/%s.ppd", ServerRoot, printer->name);
snprintf(printer_name, sizeof(printer_name), "PRINTER=%s", printer->name);
- snprintf(cache, sizeof(cache), "RIP_MAX_CACHE=%s", RIPCache);
- snprintf(cups_cachedir, sizeof(cups_cachedir), "CUPS_CACHEDIR=%s", CacheDir);
- snprintf(cups_datadir, sizeof(cups_datadir), "CUPS_DATADIR=%s", DataDir);
- snprintf(cups_docroot, sizeof(cups_docroot), "CUPS_DOCROOT=%s", DocumentRoot);
- snprintf(cups_fontpath, sizeof(cups_fontpath), "CUPS_FONTPATH=%s", FontPath);
- snprintf(cups_serverbin, sizeof(cups_serverbin), "CUPS_SERVERBIN=%s", ServerBin);
- snprintf(cups_serverroot, sizeof(cups_serverroot), "CUPS_SERVERROOT=%s", ServerRoot);
- snprintf(cups_statedir, sizeof(cups_statedir), "CUPS_STATEDIR=%s", StateDir);
- snprintf(tmpdir, sizeof(tmpdir), "TMPDIR=%s", TempDir);
- sprintf(ipp_port, "IPP_PORT=%d", LocalPort);
-
- envc = 0;
-
- envp[envc ++] = path;
- envp[envc ++] = "SOFTWARE=CUPS/1.1";
- envp[envc ++] = "USER=root";
+ snprintf(rip_max_cache, sizeof(rip_max_cache), "RIP_MAX_CACHE=%s", RIPCache);
+
+ envc = cupsdLoadEnv(envp, (int)(sizeof(envp) / sizeof(envp[0])));
+
envp[envc ++] = charset;
- envp[envc ++] = language;
- if (TZ && TZ[0])
- envp[envc ++] = TZ;
+ envp[envc ++] = lang;
envp[envc ++] = ppd;
- envp[envc ++] = cups_cachedir;
- envp[envc ++] = cups_datadir;
- envp[envc ++] = cups_docroot;
- envp[envc ++] = cups_fontpath;
- envp[envc ++] = cups_serverbin;
- envp[envc ++] = cups_serverroot;
- envp[envc ++] = cups_statedir;
- envp[envc ++] = cache;
- envp[envc ++] = tmpdir;
+ envp[envc ++] = rip_max_cache;
envp[envc ++] = content_type;
envp[envc ++] = device_uri;
envp[envc ++] = printer_name;
- envp[envc ++] = "CUPS_SERVER=localhost";
- envp[envc ++] = ipp_port;
-
- if (getenv("VG_ARGS") != NULL)
- {
- snprintf(vg_args, sizeof(vg_args), "VG_ARGS=%s", getenv("VG_ARGS"));
- envp[envc ++] = vg_args;
- }
-
- if (getenv("LD_ASSUME_KERNEL") != NULL)
- {
- snprintf(ld_assume_kernel, sizeof(ld_assume_kernel), "LD_ASSUME_KERNEL=%s",
- getenv("LD_ASSUME_KERNEL"));
- envp[envc ++] = ld_assume_kernel;
- }
-
- if (getenv("LD_LIBRARY_PATH") != NULL)
- {
- snprintf(ld_library_path, sizeof(ld_library_path), "LD_LIBRARY_PATH=%s",
- getenv("LD_LIBRARY_PATH"));
- envp[envc ++] = ld_library_path;
- }
-
- if (getenv("LD_PRELOAD") != NULL)
- {
- snprintf(ld_preload, sizeof(ld_preload), "LD_PRELOAD=%s",
- getenv("LD_PRELOAD"));
- envp[envc ++] = ld_preload;
- }
-
- if (getenv("DYLD_LIBRARY_PATH") != NULL)
- {
- snprintf(dyld_library_path, sizeof(dyld_library_path), "DYLD_LIBRARY_PATH=%s",
- getenv("DYLD_LIBRARY_PATH"));
- envp[envc ++] = dyld_library_path;
- }
-
- if (getenv("SHLIB_PATH") != NULL)
- {
- snprintf(shlib_path, sizeof(shlib_path), "SHLIB_PATH=%s",
- getenv("SHLIB_PATH"));
- envp[envc ++] = shlib_path;
- }
-
- if (getenv("NLSPATH") != NULL)
- {
- snprintf(nlspath, sizeof(nlspath), "NLSPATH=%s", getenv("NLSPATH"));
- envp[envc ++] = nlspath;
- }
if (Classification && !banner_page)
{
envp[envc ++] = class_name;
}
-#ifdef __APPLE__
- strlcpy(processPath, "<CFProcessPath>", sizeof(processPath));
- envp[envc ++] = processPath;
-#endif /* __APPLE__ */
-
envp[envc] = NULL;
for (i = 0; i < envc; i ++)
listener_t *lis; /* Current listening socket */
struct hostent *host; /* Host entry for server address */
char s[256]; /* String addresss */
- int have_domain; /* Have a domain socket */
+ const char *have_domain; /* Have a domain socket? */
+ static const char * const encryptions[] =
+ { /* Encryption values */
+ "IfRequested",
+ "Never",
+ "Required",
+ "Always"
+ };
LogMessage(L_DEBUG, "StartListening: NumListeners=%d", NumListeners);
* Setup socket listeners...
*/
- for (i = NumListeners, lis = Listeners, LocalPort = 0, have_domain = 0;
+ for (i = NumListeners, lis = Listeners, LocalPort = 0, have_domain = NULL;
i > 0; i --, lis ++)
{
httpAddrString(&(lis->address), s, sizeof(s));
#ifdef AF_LOCAL
if (lis->address.addr.sa_family == AF_LOCAL)
{
- have_domain = 1;
+ have_domain = lis->address.un.sun_path;
p = 0;
}
else
cupsdEndProcess(getpid(), 0);
}
+ /*
+ * Set the CUPS_SERVER and IPP_PORT variables based on the listeners...
+ */
+
+ if (have_domain)
+ {
+ /*
+ * Use domain sockets for the local connection...
+ */
+
+ cupsdSetEnv("CUPS_SERVER", have_domain);
+ }
+ else
+ {
+ /*
+ * Use the default local loopback address for the server...
+ */
+
+ cupsdSetEnv("CUPS_SERVER", "localhost");
+ cupsdSetEnvf("IPP_PORT", "%d", LocalPort);
+ cupsdSetEnv("CUPS_ENCRYPTION", encryptions[LocalEncryption]);
+ }
+
+ /*
+ * Resume listening for connections...
+ */
+
ResumeListening();
}
* Set the timezone info...
*/
- if (getenv("TZ") != NULL)
- SetStringf(&TZ, "TZ=%s", getenv("TZ"));
- else
- SetString(&TZ, "");
-
tzset();
#ifdef LC_TIME
const char *f, /* I - Printf-style format string */
...) /* I - Additional args as needed */
{
- char v[1024]; /* Formatting string value */
+ char v[4096]; /* Formatting string value */
va_list ap; /* Argument pointer */
char *olds; /* Old string */
*
* Contents:
*
- * cupsdStartProcess() - Start a process.
* cupsdEndProcess() - End a process.
+ * cupsdStartProcess() - Start a process.
*/
/*
#include <grp.h>
+/*
+ * 'cupsdEndProcess()' - End a process.
+ */
+
+int /* O - 0 on success, -1 on failure */
+cupsdEndProcess(int pid, /* I - Process ID */
+ int force) /* I - Force child to die */
+{
+ if (force)
+ return (kill(pid, SIGKILL));
+ else
+ return (kill(pid, SIGTERM));
+}
+
+
/*
* 'cupsdStartProcess()' - Start a process.
*/
}
-/*
- * 'cupsdEndProcess()' - End a process.
- */
-
-int /* O - 0 on success, -1 on failure */
-cupsdEndProcess(int pid, /* I - Process ID */
- int force) /* I - Force child to die */
-{
- if (force)
- return (kill(pid, SIGKILL));
- else
- return (kill(pid, SIGTERM));
-}
-
-
/*
* End of "$Id$".
*/