]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/adminutil.c
Load cups into easysw/current.
[thirdparty/cups.git] / cups / adminutil.c
index 185b90d1dae6f24c8b60fc251e4f5048ee6b9d41..edef4f909f09295f550ee303f089feddf8e069d0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: adminutil.c 181 2006-06-22 20:01:18Z jlovell $"
+ * "$Id: adminutil.c 5970 2006-09-19 20:11:08Z mike $"
  *
  *   Administration utility API definitions for the Common UNIX Printing
  *   System (CUPS).
@@ -103,7 +103,7 @@ cupsAdminCreateWindowsPPD(
                        linenum;        /* Current line number */
   time_t               curtime;        /* Current time */
   struct tm            *curdate;       /* Current date */
-  static const char    *pattrs[] =     /* Printer attributes we want */
+  static const char * const pattrs[] = /* Printer attributes we want */
                        {
                          "job-hold-until-supported",
                          "job-hold-until-default",
@@ -772,19 +772,31 @@ _cupsAdminGetServerSettings(
       if (!value)
         continue;
 
-      if (!strcasecmp(line, "Port"))
-      {
-       remote_access = 1;
-      }
-      else if (!strcasecmp(line, "Listen"))
+      if (!strcasecmp(line, "Port") || !strcasecmp(line, "Listen"))
       {
        char    *port;                  /* Pointer to port number, if any */
 
 
        if ((port = strrchr(value, ':')) != NULL)
          *port = '\0';
+       else if (isdigit(*value & 255))
+       {
+        /*
+         * Listen on a port number implies remote access...
+         */
+
+         remote_access = 1;
+         continue;
+       }
 
-       if (strcasecmp(value, "localhost") && strcmp(value, "127.0.0.1"))
+       if (strcasecmp(value, "localhost") && strcmp(value, "127.0.0.1")
+#ifdef AF_LOCAL
+            && *value != '/'
+#endif /* AF_LOCAL */
+#ifdef AF_INET6
+            && strcmp(value, "::1")
+#endif /* AF_INET6 */
+           )
          remote_access = 1;
       }
       else if (!strcasecmp(line, "Browsing"))
@@ -860,7 +872,14 @@ _cupsAdminGetServerSettings(
        in_location       = 0;
       }
       else if (!strcasecmp(line, "Allow") && in_admin_location &&
-               strcasecmp(value, "localhost") && strcasecmp(value, "127.0.0.1"))
+               strcasecmp(value, "localhost") && strcasecmp(value, "127.0.0.1")
+#ifdef AF_LOCAL
+              && *value != '/'
+#endif /* AF_LOCAL */
+#ifdef AF_INET6
+              && strcmp(value, "::1")
+#endif /* AF_INET6 */
+              )
       {
        remote_admin = 1;
       }
@@ -934,6 +953,8 @@ _cupsAdminSetServerSettings(
 {
   int          i;                      /* Looping var */
   http_status_t status;                        /* GET/PUT status */
+  const char   *server_port_env;       /* SERVER_PORT env var */
+  int          server_port;            /* IPP port for server */
   cups_file_t  *cupsd;                 /* cupsd.conf file */
   char         cupsdconf[1024];        /* cupsd.conf filename */
   int          remote;                 /* Remote cupsd.conf file? */
@@ -1067,6 +1088,17 @@ _cupsAdminSetServerSettings(
   wrote_root_location  = 0;
   indent               = 0;
 
+  if ((server_port_env = getenv("SERVER_PORT")) != NULL)
+  {
+    if ((server_port = atoi(server_port_env)) <= 0)
+      server_port = ippPort();
+  }
+  else
+    server_port = ippPort();
+
+  if (server_port <= 0)
+    server_port = IPP_PORT;
+
   while (cupsFileGetConf(cupsd, line, sizeof(line), &value, &linenum))
   {
     if (!strcasecmp(line, "Port") || !strcasecmp(line, "Listen"))
@@ -1078,20 +1110,24 @@ _cupsAdminSetServerSettings(
        if (share_printers || remote_admin)
        {
          cupsFilePuts(temp, "# Allow remote access\n");
-         cupsFilePrintf(temp, "Port %d\n", ippPort());
+         cupsFilePrintf(temp, "Port %d\n", server_port);
        }
        else
        {
          cupsFilePuts(temp, "# Only listen for connections from the local "
                             "machine.\n");
-         cupsFilePrintf(temp, "Listen 127.0.0.1:%d\n", ippPort());
+         cupsFilePrintf(temp, "Listen localhost:%d\n", server_port);
        }
 
 #ifdef CUPS_DEFAULT_DOMAINSOCKET
-        if (!access(CUPS_DEFAULT_DOMAINSOCKET, 0))
+        if ((!value || strcmp(CUPS_DEFAULT_DOMAINSOCKET, value)) &&
+           !access(CUPS_DEFAULT_DOMAINSOCKET, 0))
           cupsFilePuts(temp, "Listen " CUPS_DEFAULT_DOMAINSOCKET "\n");
 #endif /* CUPS_DEFAULT_DOMAINSOCKET */
       }
+      else if (value && value[0] == '/' &&
+               strcmp(CUPS_DEFAULT_DOMAINSOCKET, value))
+        cupsFilePrintf(temp, "Listen %s\n", value);
     }
     else if (!strcasecmp(line, "Browsing") ||
              !strcasecmp(line, "BrowseAddress") ||
@@ -1440,7 +1476,7 @@ _cupsAdminSetServerSettings(
     {
       cupsFilePuts(temp,
                    "# Only listen for connections from the local machine.\n");
-      cupsFilePrintf(temp, "Listen 127.0.0.1:%d\n", ippPort());
+      cupsFilePrintf(temp, "Listen localhost:%d\n", ippPort());
     }
 
 #ifdef CUPS_DEFAULT_DOMAINSOCKET
@@ -1681,8 +1717,9 @@ do_samba_command(const char *command,     /* I - Command to run */
   {
     status = -1;
 
-    _cupsLangPrintf(stderr, _("cupsaddsmb: Unable to run \"%s\": %s\n"),
-                    command, strerror(errno));
+    if (logfile)
+      _cupsLangPrintf(logfile, _("Unable to run \"%s\": %s\n"),
+                      command, strerror(errno));
   }
   else
   {
@@ -1767,7 +1804,7 @@ get_cupsd_conf(
     * Read cupsd.conf via a HTTP GET request...
     */
 
-    if ((fd = cupsTempFd(name, sizeof(name))) < 0)
+    if ((fd = cupsTempFd(name, namesize)) < 0)
     {
       *name = '\0';
 
@@ -1928,5 +1965,5 @@ write_option(cups_file_t     *dstfp,      /* I - PPD file */
 
 
 /*
- * End of "$Id: adminutil.c 181 2006-06-22 20:01:18Z jlovell $".
+ * End of "$Id: adminutil.c 5970 2006-09-19 20:11:08Z mike $".
  */