]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Update scheduler to use new environment variable API - this reduces code
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Thu, 22 Sep 2005 20:56:46 +0000 (20:56 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Thu, 22 Sep 2005 20:56:46 +0000 (20:56 +0000)
size and will allow us to add the Apache PassEnv and SetEnv directives
without too much pain.

scheduler/client.c:
    - pipe_command(): Use new cupsdLoadEnv() function.

scheduler/conf.c:
    - ReadConfiguration(): Call cupsdInitEnv() after loading
      cupsd.conf.

scheduler/cupsd.h:
    - Drop TZ global.
    - Add cupsdClearEnv(), cupsdInitEnv(), cupsdLoadEnv(),
      cupsdSetEnv(), and cupsdSetEnvf() functions.

scheduler/dirsvc.c:
    - StartPolling(): Use new cupsdLoadEnv() function.

scheduler/env.c:
    - Added.

scheduler/job.c:
    - StartJob(): Use new cupsdLoadEnv() function.

scheduler/listen.c:
    - StartListening(): Set CUPS_SERVER, CUPS_ENCRYPTION, and
      IPP_PORT environment variables.

scheduler/main.c:
    - main(): Drop TZ environment variable stuff.

scheduler/process.c:
    - Sort functions.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@4691 7a7537e8-13f0-0310-91df-b6672ffda945

scheduler/Dependencies
scheduler/Makefile
scheduler/client.c
scheduler/conf.c
scheduler/cupsd.h
scheduler/dirsvc.c
scheduler/env.c [new file with mode: 0644]
scheduler/job.c
scheduler/listen.c
scheduler/main.c
scheduler/process.c

index e6b21c834c7a86b8474fcf17b97f16eacb83a2c4..e285d40a44982825481d18a73ced42231b395974 100644 (file)
@@ -42,6 +42,12 @@ dirsvc.o: ../cups/ppd.h ../cups/file.h mime.h ../cups/ipp.h ../cups/file.h
 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
@@ -132,9 +138,6 @@ cups-deviced.o: ../cups/string.h ../config.h ../cups/dir.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
@@ -144,3 +147,6 @@ cups-polld.o: ../cups/language.h ../cups/string.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
index 1f4fc178c786821a44809cee85f10f62ad43133c..c0733e416ed80fc915089670b97b062faa84c154 100644 (file)
 
 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
 
 
 #
index 6e99743619ba2ff0267ad71bbaa106a8d988cd89..3d18ec5b1d952be00d6a8ee36beb372da4daa87e 100644 (file)
@@ -3009,31 +3009,16 @@ pipe_command(client_t *con,             /* I - Client connection */
                *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",
@@ -3074,13 +3059,6 @@ pipe_command(client_t *con,              /* I - Client connection */
 
                  "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"
-               };
 
 
  /*
@@ -3193,109 +3171,45 @@ pipe_command(client_t *con,            /* I - Client connection */
   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)
   {
@@ -3311,15 +3225,11 @@ pipe_command(client_t *con,             /* I - Client connection */
     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)
@@ -3349,8 +3259,6 @@ pipe_command(client_t *con,               /* I - Client connection */
   if (con->http.encryption == HTTP_ENCRYPT_ALWAYS)
     envp[envc ++] = "HTTPS=ON";
 
-  envp[envc ++] = (char *)encryptions[LocalEncryption];
-
  /*
   * Terminate the environment array...
   */
index 23358a0d7b4a23cdf302a28987b979852b306c70..b2161003b80d9feaf195ec881b3626c9e5808bbd 100644 (file)
@@ -650,6 +650,12 @@ ReadConfiguration(void)
                  TempDir, strerror(errno));
   }
 
+ /*
+  * Setup environment variables...
+  */
+
+  cupsdInitEnv();
+
  /*
   * Check the MaxClients setting, and then allocate memory for it...
   */
index f698e5bf5acfdefd2b0efaa6a73612500bfc9301..1705fd0f9ab87b3462b024dc58fb5845e4aec09c 100644 (file)
@@ -162,9 +162,6 @@ VAR int                     NeedReload      VALUE(RELOAD_ALL),
                        SignalCount     VALUE(0);
                                        /* Signal handler level */
 
-VAR char               *TZ             VALUE(NULL);
-                                       /* Timezone configuration */
-
 
 /*
  * Prototypes...
@@ -177,16 +174,30 @@ extern void       IgnoreChildSignals(void);
 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);
 
 
 /*
index 0bd80862f421bea05ad190d86993937c9dae9b84..3cca651ef145f4a61072cdc1d1b31b0f901af027 100644 (file)
@@ -1117,6 +1117,7 @@ StartPolling(void)
   char         interval[10];           /* Poll interval */
   int          statusfds[2];           /* Status pipe */
   char         *argv[6];               /* Arguments */
+  char         *envp[100];             /* Environment */
 
 
  /*
@@ -1149,6 +1150,8 @@ StartPolling(void)
   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...
@@ -1176,7 +1179,7 @@ StartPolling(void)
 
     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",
diff --git a/scheduler/env.c b/scheduler/env.c
new file mode 100644 (file)
index 0000000..7da107c
--- /dev/null
@@ -0,0 +1,221 @@
+/*
+ * "$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$".
+ */
index 8da443fa4a6bc3301a642e782a5b15f8c783e64e..81a3d08a5dae3f233f1d544d88496ec3d7b28f33 100644 (file)
@@ -1347,42 +1347,22 @@ StartJob(int       id,                  /* I - Job 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 */
 
@@ -1885,7 +1865,7 @@ StartJob(int       id,                    /* I - Job ID */
        * the POSIX locale...
        */
 
-       strcpy(language, "LANG=C");
+       strcpy(lang, "LANG=C");
        break;
 
     case 2 :
@@ -1893,7 +1873,7 @@ StartJob(int       id,                    /* I - Job ID */
         * Just the language code (ll)...
        */
 
-        snprintf(language, sizeof(language), "LANG=%s",
+        snprintf(lang, sizeof(lang), "LANG=%s",
                 attr->values[0].string.text);
         break;
 
@@ -1902,7 +1882,7 @@ StartJob(int       id,                    /* I - Job ID */
         * 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),
@@ -1923,7 +1903,6 @@ StartJob(int       id,                    /* I - Job ID */
              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);
@@ -1931,88 +1910,17 @@ StartJob(int       id,                  /* I - Job ID */
   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)
   {
@@ -2037,11 +1945,6 @@ StartJob(int       id,                   /* I - Job ID */
     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 ++)
index 51dcd8a235692dd14d76323e451e7e6bcdd353f2..cb6f56af76222d1a1d6a1d290bae2728282fff08 100644 (file)
@@ -108,7 +108,14 @@ StartListening(void)
   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);
@@ -143,7 +150,7 @@ StartListening(void)
   * 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));
@@ -156,7 +163,7 @@ StartListening(void)
 #ifdef AF_LOCAL
     if (lis->address.addr.sa_family == AF_LOCAL)
     {
-      have_domain = 1;
+      have_domain = lis->address.un.sun_path;
       p           = 0;
     }
     else
@@ -330,6 +337,33 @@ StartListening(void)
     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();
 }
 
index b5b967ea2939ea0674cf89f85e9a2b5491f3d4b1..1cffe15b1778693a4ed61f778879a61ec5f8d602 100644 (file)
@@ -280,11 +280,6 @@ main(int  argc,                            /* I - Number of command-line arguments */
   * Set the timezone info...
   */
 
-  if (getenv("TZ") != NULL)
-    SetStringf(&TZ, "TZ=%s", getenv("TZ"));
-  else
-    SetString(&TZ, "");
-
   tzset();
 
 #ifdef LC_TIME
@@ -1053,7 +1048,7 @@ SetStringf(char       **s,                /* O - New string */
            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 */
 
index b409d1a71c19ee15e99e84f887b8efcf5e17be3c..2b50818cfee08d547b877a53e5410d9f9f18b887 100644 (file)
@@ -23,8 +23,8 @@
  *
  * 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.
  */
@@ -202,21 +217,6 @@ cupsdStartProcess(
 }
 
 
-/*
- * '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$".
  */