]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/adminutil.c
Load cups into easysw/current.
[thirdparty/cups.git] / cups / adminutil.c
index 44ffe6ed9fa2abddf076674f2739e70b7f5da8ca..edef4f909f09295f550ee303f089feddf8e069d0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: adminutil.c 5240 2006-03-07 21:55:29Z mike $"
+ * "$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",
@@ -168,7 +168,7 @@ cupsAdminCreateWindowsPPD(
   * Create a temporary output file using the destination buffer...
   */
 
-  if ((dstfp = cupsTempFile2(buffer, bufsize)) < 0)
+  if ((dstfp = cupsTempFile2(buffer, bufsize)) == NULL)
   {
     cupsFileClose(srcfp);
 
@@ -222,18 +222,18 @@ cupsAdminCreateWindowsPPD(
       */
 
       cupsFilePrintf(dstfp, "*%% Commented out for CUPS Windows Driver...\n"
-                            "*%%%s", line + 1);
+                            "*%%%s\n", line + 1);
       continue;
     }
     else if (!strncmp(line, "*JCLOpenUI", 10))
     {
       jcloption = 1;
-      cupsFilePuts(dstfp, line);
+      cupsFilePrintf(dstfp, "%s\n", line);
     }
     else if (!strncmp(line, "*JCLCloseUI", 11))
     {
       jcloption = 0;
-      cupsFilePuts(dstfp, line);
+      cupsFilePrintf(dstfp, "%s\n", line);
     }
     else if (jcloption &&
              strncmp(line, "*End", 4) &&
@@ -312,12 +312,13 @@ cupsAdminCreateWindowsPPD(
       }
 
       snprintf(ptr + 1, sizeof(line) - (ptr - line + 1),
-               "%%cupsJobTicket: %s=%s\n\"\n*End\n", option, choice);
+               "%%cupsJobTicket: %s=%s\n\"\n*End", option, choice);
 
-      cupsFilePrintf(dstfp, "*%% Changed for CUPS Windows Driver...\n%s", line);
+      cupsFilePrintf(dstfp, "*%% Changed for CUPS Windows Driver...\n%s\n",
+                     line);
     }
     else
-      cupsFilePuts(dstfp, line);
+      cupsFilePrintf(dstfp, "%s\n", line);
   }
 
   cupsFileClose(srcfp);
@@ -382,7 +383,7 @@ cupsAdminExportSamba(
     const char *samba_password,                /* I - Samba password */
     FILE       *logfile)               /* I - Log file, if any */
 {
-  int                  status;         /* Status of smbclient/rpcclient commands */
+  int                  status;         /* Status of Samba commands */
   int                  have_drivers;   /* Have drivers? */
   char                 file[1024],     /* File to test for */
                        authfile[1024], /* Temporary authentication file */
@@ -728,7 +729,15 @@ _cupsAdminGetServerSettings(
                                sizeof(cupsdconf), &remote)) == HTTP_OK)
   {
     if ((cupsd = cupsFileOpen(cupsdconf, "r")) == NULL)
-      _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
+    {
+      char     message[1024];          /* Message string */
+
+
+      snprintf(message, sizeof(message),
+               _cupsLangString(cupsLangDefault(), _("open of %s failed: %s")),
+               cupsdconf, strerror(errno));
+      _cupsSetError(IPP_INTERNAL_ERROR, message);
+    }
   }
   else
     cupsd = NULL;
@@ -763,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"))
@@ -851,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;
       }
@@ -925,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? */
@@ -1058,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"))
@@ -1069,19 +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());
+         cupsFilePuts(temp, "# Only listen for connections from the local "
+                            "machine.\n");
+         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") ||
@@ -1096,11 +1142,14 @@ _cupsAdminSetServerSettings(
         if (remote_printers || share_printers)
        {
          if (remote_printers && share_printers)
-           cupsFilePuts(temp, "# Enable printer sharing and shared printers.\n");
+           cupsFilePuts(temp,
+                        "# Enable printer sharing and shared printers.\n");
          else if (remote_printers)
-           cupsFilePuts(temp, "# Show shared printers on the local network.\n");
+           cupsFilePuts(temp,
+                        "# Show shared printers on the local network.\n");
          else
-           cupsFilePuts(temp, "# Share local printers on the local network.\n");
+           cupsFilePuts(temp,
+                        "# Share local printers on the local network.\n");
 
          cupsFilePuts(temp, "Browsing On\n");
          cupsFilePuts(temp, "BrowseOrder allow,deny\n");
@@ -1113,7 +1162,8 @@ _cupsAdminSetServerSettings(
         }
        else
        {
-         cupsFilePuts(temp, "# Disable printer sharing and shared printers.\n");
+         cupsFilePuts(temp,
+                      "# Disable printer sharing and shared printers.\n");
          cupsFilePuts(temp, "Browsing Off\n");
        }
       }
@@ -1124,7 +1174,8 @@ _cupsAdminSetServerSettings(
 
       if (debug_logging)
       {
-        cupsFilePuts(temp, "# Show troubleshooting information in error_log.\n");
+        cupsFilePuts(temp,
+                    "# Show troubleshooting information in error_log.\n");
        cupsFilePuts(temp, "LogLevel debug\n");
       }
       else
@@ -1149,7 +1200,8 @@ _cupsAdminSetServerSettings(
        wrote_policy = 1;
 
         if (!user_cancel_any)
-         cupsFilePuts(temp, "  # Only the owner or an administrator can cancel a job...\n"
+         cupsFilePuts(temp, "  # Only the owner or an administrator can "
+                            "cancel a job...\n"
                             "  <Limit Cancel-Job>\n"
                             "    Order deny,allow\n"
                             "    Allow @SYSTEM\n"
@@ -1200,9 +1252,11 @@ _cupsAdminSetServerSettings(
        wrote_conf_location = 1;
 
        if (remote_admin)
-          cupsFilePuts(temp, "  # Allow remote access to the configuration files...\n");
+          cupsFilePuts(temp, "  # Allow remote access to the configuration "
+                            "files...\n");
        else
-          cupsFilePuts(temp, "  # Restrict access to the configuration files...\n");
+          cupsFilePuts(temp, "  # Restrict access to the configuration "
+                            "files...\n");
 
         cupsFilePuts(temp, "  Order allow,deny\n");
 
@@ -1216,7 +1270,8 @@ _cupsAdminSetServerSettings(
        wrote_root_location = 1;
 
        if (remote_admin && share_printers)
-          cupsFilePuts(temp, "  # Allow shared printing and remote administration...\n");
+          cupsFilePuts(temp, "  # Allow shared printing and remote "
+                            "administration...\n");
        else if (remote_admin)
           cupsFilePuts(temp, "  # Allow remote administration...\n");
        else if (share_printers)
@@ -1295,7 +1350,8 @@ _cupsAdminSetServerSettings(
       wrote_policy = 1;
 
       if (!user_cancel_any)
-       cupsFilePuts(temp, "  # Only the owner or an administrator can cancel a job...\n"
+       cupsFilePuts(temp, "  # Only the owner or an administrator can cancel "
+                          "a job...\n"
                           "  <Limit Cancel-Job>\n"
                           "    Order deny,allow\n"
                           "    Require user @OWNER @SYSTEM\n"
@@ -1418,8 +1474,9 @@ _cupsAdminSetServerSettings(
     }
     else
     {
-      cupsFilePuts(temp, "# Only listen for connections from the local machine.\n");
-      cupsFilePrintf(temp, "Listen 127.0.0.1:%d\n", ippPort());
+      cupsFilePuts(temp,
+                   "# Only listen for connections from the local machine.\n");
+      cupsFilePrintf(temp, "Listen localhost:%d\n", ippPort());
     }
 
 #ifdef CUPS_DEFAULT_DOMAINSOCKET
@@ -1431,7 +1488,8 @@ _cupsAdminSetServerSettings(
   if (!wrote_root_location)
   {
     if (remote_admin && share_printers)
-      cupsFilePuts(temp, "# Allow shared printing and remote administration...\n");
+      cupsFilePuts(temp,
+                   "# Allow shared printing and remote administration...\n");
     else if (remote_admin)
       cupsFilePuts(temp, "# Allow remote administration...\n");
     else if (share_printers)
@@ -1471,7 +1529,8 @@ _cupsAdminSetServerSettings(
   if (!wrote_conf_location)
   {
     if (remote_admin)
-      cupsFilePuts(temp, "# Allow remote access to the configuration files...\n");
+      cupsFilePuts(temp,
+                   "# Allow remote access to the configuration files...\n");
     else
       cupsFilePuts(temp, "# Restrict access to the configuration files...\n");
 
@@ -1491,7 +1550,8 @@ _cupsAdminSetServerSettings(
   if (!wrote_policy)
   {
     cupsFilePuts(temp, "<Policy default>\n"
-                       "  # Job-related operations must be done by the owner or an adminstrator...\n"
+                       "  # Job-related operations must be done by the owner "
+                      "or an adminstrator...\n"
                        "  <Limit Send-Document Send-URI Hold-Job Release-Job "
                       "Restart-Job Purge-Jobs Set-Job-Attributes "
                       "Create-Job-Subscription Renew-Subscription "
@@ -1501,7 +1561,8 @@ _cupsAdminSetServerSettings(
                        "    Require user @OWNER @SYSTEM\n"
                        "    Order deny,allow\n"
                        "  </Limit>\n"
-                       "  # All administration operations require an adminstrator to authenticate...\n"
+                       "  # All administration operations require an "
+                      "adminstrator to authenticate...\n"
                       "  <Limit Pause-Printer Resume-Printer "
                        "Set-Printer-Attributes Enable-Printer "
                       "Disable-Printer Pause-Printer-After-Current-Job "
@@ -1518,7 +1579,8 @@ _cupsAdminSetServerSettings(
                        "</Limit>\n");
 
     if (!user_cancel_any)
-      cupsFilePuts(temp, "  # Only the owner or an administrator can cancel a job...\n"
+      cupsFilePuts(temp, "  # Only the owner or an administrator can cancel "
+                         "a job...\n"
                         "  <Limit Cancel-Job>\n"
                         "    Require user @OWNER @SYSTEM\n"
                         "    Order deny,allow\n"
@@ -1655,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
   {
@@ -1718,9 +1781,15 @@ get_cupsd_conf(
 
     if (stat(name, &info))
     {
-      *name = '\0';
+      char     message[1024];          /* Message string */
 
-      _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
+
+      snprintf(message, sizeof(message),
+               _cupsLangString(cupsLangDefault(), _("stat of %s failed: %s")),
+               name, strerror(errno));
+      _cupsSetError(IPP_INTERNAL_ERROR, message);
+
+      *name = '\0';
 
       return (HTTP_SERVER_ERROR);
     }
@@ -1735,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';
 
@@ -1896,5 +1965,5 @@ write_option(cups_file_t     *dstfp,      /* I - PPD file */
 
 
 /*
- * End of "$Id: adminutil.c 5240 2006-03-07 21:55:29Z mike $".
+ * End of "$Id: adminutil.c 5970 2006-09-19 20:11:08Z mike $".
  */