]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/adminutil.c
Merge changes from CUPS 1.5svn-r9641
[thirdparty/cups.git] / cups / adminutil.c
index 96354a1120488f929aaa268a933b8676ff6106ad..99f8476c31696210fd0f43fda64af410346b2873 100644 (file)
@@ -1,10 +1,9 @@
 /*
- * "$Id: adminutil.c 7576 2008-05-15 21:05:14Z mike $"
+ * "$Id: adminutil.c 7850 2008-08-20 00:07:25Z mike $"
  *
- *   Administration utility API definitions for the Common UNIX Printing
- *   System (CUPS).
+ *   Administration utility API definitions for CUPS.
  *
- *   Copyright 2007-2008 by Apple Inc.
+ *   Copyright 2007-2011 by Apple Inc.
  *   Copyright 2001-2007 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
  *
  * Contents:
  *
- *   cupsAdminCreateWindowsPPD()   - Create the Windows PPD file for a printer.
- *   cupsAdminExportSamba()        - Export a printer to Samba.
- *   cupsAdminGetServerSettings()  - Get settings from the server.
- *   _cupsAdminGetServerSettings() - Get settings from the server (private).
- *   cupsAdminSetServerSettings()  - Set settings on the server.
- *   _cupsAdminSetServerSettings() - Set settings on the server (private).
- *   do_samba_command()            - Do a SAMBA command.
- *   get_cupsd_conf()              - Get the current cupsd.conf file.
- *   invalidate_cupsd_cache()      - Invalidate the cached cupsd.conf settings.
- *   write_option()                - Write a CUPS option to a PPD file.
+ *   cupsAdminCreateWindowsPPD()  - Create the Windows PPD file for a printer.
+ *   cupsAdminExportSamba()       - Export a printer to Samba.
+ *   cupsAdminGetServerSettings() - Get settings from the server.
+ *   cupsAdminSetServerSettings() - Set settings on the server.
+ *   do_samba_command()           - Do a SAMBA command.
+ *   get_cupsd_conf()             - Get the current cupsd.conf file.
+ *   invalidate_cupsd_cache()     - Invalidate the cached cupsd.conf settings.
+ *   write_option()               - Write a CUPS option to a PPD file.
  */
 
 /*
  * Include necessary headers...
  */
 
+#include "cups-private.h"
 #include "adminutil.h"
-#include "globals.h"
-#include "debug.h"
-#include <errno.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 #ifdef WIN32
  * Local functions...
  */
 
-extern int             _cupsAdminGetServerSettings(http_t *http,
-                                                   int *num_settings,
-                                                   cups_option_t **settings);
-extern int             _cupsAdminSetServerSettings(http_t *http,
-                                                   int num_settings,
-                                                   cups_option_t *settings);
 static int             do_samba_command(const char *command,
                                         const char *address,
                                         const char *subcommand,
@@ -75,6 +64,8 @@ static void           write_option(cups_file_t *dstfp, int order,
 
 /*
  * 'cupsAdminCreateWindowsPPD()' - Create the Windows PPD file for a printer.
+ *
+ * @since CUPS 1.2/Mac OS X 10.5@
  */
 
 char *                                 /* O - PPD file or NULL */
@@ -241,7 +232,7 @@ cupsAdminCreateWindowsPPD(
     }
     else if (jcloption && !strncmp(line, "*OrderDependency:", 17))
     {
-      for (ptr = line + 17; *ptr && isspace(*ptr & 255); ptr ++);
+      for (ptr = line + 17; _cups_isspace(*ptr); ptr ++);
 
       ptr = strchr(ptr, ' ');
 
@@ -260,7 +251,7 @@ cupsAdminCreateWindowsPPD(
       if ((ptr = strchr(line, ':')) == NULL)
       {
         snprintf(line, sizeof(line),
-                _cupsLangString(language, _("Missing value on line %d!")),
+                _cupsLangString(language, _("Missing value on line %d.")),
                 linenum);
         _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line, 0);
 
@@ -279,7 +270,7 @@ cupsAdminCreateWindowsPPD(
       {
         snprintf(line, sizeof(line),
                 _cupsLangString(language,
-                                _("Missing double quote on line %d!")),
+                                _("Missing double quote on line %d.")),
                 linenum);
         _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line, 0);
 
@@ -298,7 +289,7 @@ cupsAdminCreateWindowsPPD(
       {
         snprintf(line, sizeof(line),
                 _cupsLangString(language,
-                                _("Bad option + choice on line %d!")),
+                                _("Bad option + choice on line %d.")),
                 linenum);
         _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line, 0);
 
@@ -343,7 +334,7 @@ cupsAdminCreateWindowsPPD(
 
   if (linenum == 0)
   {
-    _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, _("Empty PPD file!"), 1);
+    _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, _("Empty PPD file."), 1);
 
     cupsFileClose(dstfp);
     unlink(buffer);
@@ -401,6 +392,8 @@ cupsAdminCreateWindowsPPD(
 
 /*
  * 'cupsAdminExportSamba()' - Export a printer to Samba.
+ *
+ * @since CUPS 1.2/Mac OS X 10.5@
  */
 
 int                                    /* O - 1 on success, 0 on failure */
@@ -492,12 +485,12 @@ cupsAdminExportSamba(
       snprintf(message, sizeof(message),
                _cupsLangString(language,
                               _("Unable to copy Windows 2000 printer "
-                                "driver files (%d)!")), status);
+                                "driver files (%d).")), status);
 
       _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
 
       if (logfile)
-       _cupsLangPrintf(logfile, "%s\n", message);
+       _cupsLangPuts(logfile, message);
 
       unlink(authfile);
 
@@ -527,12 +520,12 @@ cupsAdminExportSamba(
        snprintf(message, sizeof(message),
                 _cupsLangString(language,
                                 _("Unable to copy CUPS printer driver "
-                                  "files (%d)!")), status);
+                                  "files (%d).")), status);
 
        _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
 
        if (logfile)
-         _cupsLangPrintf(logfile, "%s\n", message);
+         _cupsLangPuts(logfile, message);
 
         unlink(authfile);
 
@@ -570,12 +563,12 @@ cupsAdminExportSamba(
       snprintf(message, sizeof(message),
                _cupsLangString(language,
                               _("Unable to install Windows 2000 printer "
-                                "driver files (%d)!")), status);
+                                "driver files (%d).")), status);
 
       _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
 
       if (logfile)
-       _cupsLangPrintf(logfile, "%s\n", message);
+       _cupsLangPuts(logfile, message);
 
       unlink(authfile);
 
@@ -615,12 +608,12 @@ cupsAdminExportSamba(
       snprintf(message, sizeof(message),
                _cupsLangString(language,
                               _("Unable to copy Windows 9x printer "
-                                "driver files (%d)!")), status);
+                                "driver files (%d).")), status);
 
       _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
 
       if (logfile)
-       _cupsLangPrintf(logfile, "%s\n", message);
+       _cupsLangPuts(logfile, message);
 
       unlink(authfile);
 
@@ -644,12 +637,12 @@ cupsAdminExportSamba(
       snprintf(message, sizeof(message),
                _cupsLangString(language,
                               _("Unable to install Windows 9x printer "
-                                "driver files (%d)!")), status);
+                                "driver files (%d).")), status);
 
       _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
 
       if (logfile)
-       _cupsLangPrintf(logfile, "%s\n", message);
+       _cupsLangPuts(logfile, message);
 
       unlink(authfile);
 
@@ -696,12 +689,12 @@ cupsAdminExportSamba(
       snprintf(message, sizeof(message),
                _cupsLangString(language,
                               _("Unable to copy 64-bit Windows printer "
-                                "driver files (%d)!")), status);
+                                "driver files (%d).")), status);
 
       _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
 
       if (logfile)
-       _cupsLangPrintf(logfile, "%s\n", message);
+       _cupsLangPuts(logfile, message);
 
       unlink(authfile);
 
@@ -731,12 +724,12 @@ cupsAdminExportSamba(
        snprintf(message, sizeof(message),
                 _cupsLangString(language,
                                 _("Unable to copy 64-bit CUPS printer driver "
-                                  "files (%d)!")), status);
+                                  "files (%d).")), status);
 
        _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
 
        if (logfile)
-         _cupsLangPrintf(logfile, "%s\n", message);
+         _cupsLangPuts(logfile, message);
 
         unlink(authfile);
 
@@ -774,12 +767,12 @@ cupsAdminExportSamba(
       snprintf(message, sizeof(message),
                _cupsLangString(language,
                               _("Unable to install Windows 2000 printer "
-                                "driver files (%d)!")), status);
+                                "driver files (%d).")), status);
 
       _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
 
       if (logfile)
-       _cupsLangPrintf(logfile, "%s\n", message);
+       _cupsLangPuts(logfile, message);
 
       unlink(authfile);
 
@@ -792,17 +785,17 @@ cupsAdminExportSamba(
     if (!have_drivers)
       strlcpy(message,
               _cupsLangString(language,
-                             _("No Windows printer drivers are installed!")),
+                             _("No Windows printer drivers are installed.")),
               sizeof(message));
     else
       strlcpy(message,
               _cupsLangString(language,
                              _("Warning, no Windows 2000 printer drivers "
-                               "are installed!")),
+                               "are installed.")),
               sizeof(message));
 
     _cupsSetError(IPP_NOT_FOUND, message, 0);
-    _cupsLangPrintf(logfile, "%s\n", message);
+    _cupsLangPuts(logfile, message);
   }
 
   if (have_drivers == 0)
@@ -825,13 +818,13 @@ cupsAdminExportSamba(
   {
     snprintf(message, sizeof(message),
              _cupsLangString(language,
-                            _("Unable to set Windows printer driver (%d)!")),
+                            _("Unable to set Windows printer driver (%d).")),
                             status);
 
     _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
 
     if (logfile)
-      _cupsLangPrintf(logfile, "%s\n", message);
+      _cupsLangPuts(logfile, message);
 
     unlink(authfile);
 
@@ -850,7 +843,7 @@ cupsAdminExportSamba(
  * The returned settings should be freed with cupsFreeOptions() when
  * you are done with them.
  *
- * @since CUPS 1.3@
+ * @since CUPS 1.3/Mac OS X 10.5@
  */
 
 int                                    /* O - 1 on success, 0 on failure */
@@ -858,25 +851,6 @@ cupsAdminGetServerSettings(
     http_t        *http,               /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
     int           *num_settings,       /* O - Number of settings */
     cups_option_t **settings)          /* O - Settings */
-{
-  return (_cupsAdminGetServerSettings(http, num_settings, settings));
-}
-
-
-/*
- * '_cupsAdminGetServerSettings()' - Get settings from the server.
- *
- * The returned settings should be freed with cupsFreeOptions() when
- * you are done with them.
- *
- * @since CUPS 1.2@
- */
-
-int                                    /* O - 1 on success, 0 on failure */
-_cupsAdminGetServerSettings(
-    http_t        *http,               /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
-    int           *num_settings,       /* O - Number of settings */
-    cups_option_t **settings)          /* O - Settings */
 {
   int          i;                      /* Looping var */
   cups_file_t  *cupsd;                 /* cupsd.conf file */
@@ -927,8 +901,8 @@ _cupsAdminGetServerSettings(
 
     if (!cg->http)
     {
-      if ((cg->http = _httpCreate(cupsServer(), ippPort(),
-                                  cupsEncryption())) == NULL)
+      if ((cg->http = _httpCreate(cupsServer(), ippPort(), NULL,
+                                  cupsEncryption(), AF_UNSPEC)) == NULL)
       {
        if (errno)
          _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0);
@@ -945,6 +919,8 @@ _cupsAdminGetServerSettings(
        return (0);
       }
     }
+
+    http = cg->http;
   }
 
   if (!http || !num_settings || !settings)
@@ -1037,7 +1013,7 @@ _cupsAdminGetServerSettings(
             && *value != '/'
 #endif /* AF_LOCAL */
 #ifdef AF_INET6
-            && strcmp(value, "::1")
+            && strcmp(value, "[::1]")
 #endif /* AF_INET6 */
            )
          remote_access = 1;
@@ -1082,7 +1058,7 @@ _cupsAdminGetServerSettings(
 
        while (*value)
        {
-         for (valptr = value; !isspace(*valptr & 255) && *valptr; valptr ++);
+         for (valptr = value; *valptr && !_cups_isspace(*valptr); valptr ++);
 
          if (*valptr)
            *valptr++ = '\0';
@@ -1093,7 +1069,7 @@ _cupsAdminGetServerSettings(
            break;
          }
 
-          for (value = valptr; isspace(*value & 255); value ++);
+          for (value = valptr; _cups_isspace(*value); value ++);
        }
       }
       else if (!strcasecmp(line, "</Limit>"))
@@ -1129,7 +1105,13 @@ _cupsAdminGetServerSettings(
         else if (!strcasecmp(value, "all"))
          remote_any = 1;
       }
-      else if (line[0] != '<' && !in_location && !in_policy)
+      else if (line[0] != '<' && !in_location && !in_policy &&
+              strcasecmp(line, "Allow") &&
+               strcasecmp(line, "AuthType") &&
+              strcasecmp(line, "Deny") &&
+              strcasecmp(line, "Order") &&
+              strcasecmp(line, "Require") &&
+              strcasecmp(line, "Satisfy"))
         cg->cupsd_num_settings = cupsAddOption(line, value,
                                               cg->cupsd_num_settings,
                                               &(cg->cupsd_settings));
@@ -1193,7 +1175,7 @@ _cupsAdminGetServerSettings(
 /*
  * 'cupsAdminSetServerSettings()' - Set settings on the server.
  *
- * @since CUPS 1.3@
+ * @since CUPS 1.3/Mac OS X 10.5@
  */
 
 int                                    /* O - 1 on success, 0 on failure */
@@ -1201,22 +1183,6 @@ cupsAdminSetServerSettings(
     http_t        *http,               /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
     int           num_settings,                /* I - Number of settings */
     cups_option_t *settings)           /* I - Settings */
-{
-  return (_cupsAdminSetServerSettings(http, num_settings, settings));
-}
-
-
-/*
- * '_cupsAdminSetServerSettings()' - Set settings on the server.
- *
- * @since CUPS 1.2@
- */
-
-int                                    /* O - 1 on success, 0 on failure */
-_cupsAdminSetServerSettings(
-    http_t        *http,               /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
-    int           num_settings,                /* I - Number of settings */
-    cups_option_t *settings)           /* I - Settings */
 {
   int          i;                      /* Looping var */
   http_status_t status;                        /* GET/PUT status */
@@ -1297,8 +1263,8 @@ _cupsAdminSetServerSettings(
   * Get current settings...
   */
 
-  if (!_cupsAdminGetServerSettings(http, &cupsd_num_settings,
-                                   &cupsd_settings))
+  if (!cupsAdminGetServerSettings(http, &cupsd_num_settings,
+                                 &cupsd_settings))
     return (0);
 
   if ((val = cupsGetOption(CUPS_SERVER_DEBUG_LOGGING, cupsd_num_settings,
@@ -1307,36 +1273,54 @@ _cupsAdminSetServerSettings(
   else
     old_debug_logging = 0;
 
+  DEBUG_printf(("1cupsAdminSetServerSettings: old debug_logging=%d",
+                old_debug_logging));
+
   if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ADMIN, cupsd_num_settings,
                            cupsd_settings)) != NULL)
     old_remote_admin = atoi(val);
   else
     old_remote_admin = 0;
 
+  DEBUG_printf(("1cupsAdminSetServerSettings: old remote_admin=%d",
+                old_remote_admin));
+
   if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ANY, cupsd_num_settings,
                            cupsd_settings)) != NULL)
     remote_any = atoi(val);
   else
     remote_any = 0;
 
+  DEBUG_printf(("1cupsAdminSetServerSettings: old remote_any=%d",
+                remote_any));
+
   if ((val = cupsGetOption(CUPS_SERVER_REMOTE_PRINTERS, cupsd_num_settings,
                            cupsd_settings)) != NULL)
     old_remote_printers = atoi(val);
   else
     old_remote_printers = 1;
 
+  DEBUG_printf(("1cupsAdminSetServerSettings: old remote_printers=%d",
+                old_remote_printers));
+
   if ((val = cupsGetOption(CUPS_SERVER_SHARE_PRINTERS, cupsd_num_settings,
                            cupsd_settings)) != NULL)
     old_share_printers = atoi(val);
   else
     old_share_printers = 0;
 
+  DEBUG_printf(("1cupsAdminSetServerSettings: old share_printers=%d",
+                old_share_printers));
+
   if ((val = cupsGetOption(CUPS_SERVER_USER_CANCEL_ANY, cupsd_num_settings,
                            cupsd_settings)) != NULL)
     old_user_cancel_any = atoi(val);
   else
     old_user_cancel_any = 0;
 
+  DEBUG_printf(("1cupsAdminSetServerSettings: old user_cancel_any=%d",
+                old_user_cancel_any));
+
   cupsFreeOptions(cupsd_num_settings, cupsd_settings);
 
  /*
@@ -1360,16 +1344,22 @@ _cupsAdminSetServerSettings(
   else
     debug_logging = -1;
 
+  DEBUG_printf(("1cupsAdminSetServerSettings: debug_logging=%d",
+                debug_logging));
+
   if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ANY, num_settings,
                            settings)) != NULL)
     remote_any = atoi(val);
 
+  DEBUG_printf(("1cupsAdminSetServerSettings: remote_any=%d",
+                remote_any));
+
   if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ADMIN, num_settings,
                            settings)) != NULL)
   {
     remote_admin = atoi(val);
 
-    if (remote_admin == old_remote_admin && remote_any < 0)
+    if (remote_admin == old_remote_admin)
     {
      /*
       * No change to this setting...
@@ -1381,6 +1371,9 @@ _cupsAdminSetServerSettings(
   else
     remote_admin = -1;
 
+  DEBUG_printf(("1cupsAdminSetServerSettings: remote_admin=%d",
+                remote_admin));
+
   if ((val = cupsGetOption(CUPS_SERVER_REMOTE_PRINTERS, num_settings,
                            settings)) != NULL)
   {
@@ -1398,12 +1391,15 @@ _cupsAdminSetServerSettings(
   else
     remote_printers = -1;
 
+  DEBUG_printf(("1cupsAdminSetServerSettings: remote_printers=%d",
+                remote_printers));
+
   if ((val = cupsGetOption(CUPS_SERVER_SHARE_PRINTERS, num_settings,
                            settings)) != NULL)
   {
     share_printers = atoi(val);
 
-    if (share_printers == old_share_printers && remote_any < 0)
+    if (share_printers == old_share_printers)
     {
      /*
       * No change to this setting...
@@ -1415,6 +1411,9 @@ _cupsAdminSetServerSettings(
   else
     share_printers = -1;
 
+  DEBUG_printf(("1cupsAdminSetServerSettings: share_printers=%d",
+                share_printers));
+
   if ((val = cupsGetOption(CUPS_SERVER_USER_CANCEL_ANY, num_settings,
                            settings)) != NULL)
   {
@@ -1432,6 +1431,9 @@ _cupsAdminSetServerSettings(
   else
     user_cancel_any = -1;
 
+  DEBUG_printf(("1cupsAdminSetServerSettings: user_cancel_any=%d",
+                user_cancel_any));
+
  /*
   * Create a temporary file for the new cupsd.conf file...
   */
@@ -1483,13 +1485,13 @@ _cupsAdminSetServerSettings(
   while (cupsFileGetConf(cupsd, line, sizeof(line), &value, &linenum))
   {
     if ((!strcasecmp(line, "Port") || !strcasecmp(line, "Listen")) &&
-        (share_printers >= 0 || remote_admin >= 0))
+        (remote_admin >= 0 || remote_any > 0 || share_printers >= 0))
     {
       if (!wrote_port_listen)
       {
         wrote_port_listen = 1;
 
-       if (share_printers > 0 || remote_admin > 0)
+       if (remote_admin > 0 || remote_any > 0 || share_printers > 0)
        {
          cupsFilePuts(temp, "# Allow remote access\n");
          cupsFilePrintf(temp, "Port %d\n", server_port);
@@ -1541,7 +1543,7 @@ _cupsAdminSetServerSettings(
          const char *remotep = cupsGetOption("BrowseRemoteProtocols",
                                              num_settings, settings);
 
-          if (!localp)
+          if (!localp || !localp[0])
            localp = cupsGetOption("BrowseLocalProtocols", cupsd_num_settings,
                                   cupsd_settings);
 
@@ -1566,27 +1568,33 @@ _cupsAdminSetServerSettings(
          {
            cupsFilePuts(temp, "BrowseAllow all\n");
 
-           if (!remotep || !*remotep)
-             cupsFilePuts(temp, "BrowseRemoteProtocols "
-                                CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS "\n");
-            else if (remotep)
-             cupsFilePrintf(temp, "BrowseRemoteProtocols %s\n", remotep);
+           if (!remotep)
+             remotep = CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS;
+
+           cupsFilePrintf(temp, "BrowseRemoteProtocols %s\n", remotep);
           }
          else
            cupsFilePuts(temp, "BrowseRemoteProtocols\n");
 
+         cupsd_num_settings = cupsAddOption("BrowseRemoteProtocols", remotep,
+                                            cupsd_num_settings,
+                                            &cupsd_settings);
+
          if (new_share_printers)
          {
            cupsFilePuts(temp, "BrowseAddress @LOCAL\n");
 
-           if (!localp || !*localp)
-             cupsFilePuts(temp, "BrowseLocalProtocols "
-                                CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS "\n");
-            else if (localp)
-             cupsFilePrintf(temp, "BrowseLocalProtocols %s\n", localp);
+           if (!localp)
+             localp = CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS;
+
+           cupsFilePrintf(temp, "BrowseLocalProtocols %s\n", localp);
          }
          else
            cupsFilePuts(temp, "BrowseLocalProtocols\n");
+
+         cupsd_num_settings = cupsAddOption("BrowseLocalProtocols", localp,
+                                            cupsd_num_settings,
+                                            &cupsd_settings);
         }
        else
        {
@@ -1633,7 +1641,7 @@ _cupsAdminSetServerSettings(
                             "  <Limit Cancel-Job>\n"
                             "    Order deny,allow\n"
                             "    Require user @OWNER "
-                            CUPS_DEFAULT_PRINTADMIN_AUTH "\n"
+                            CUPS_DEFAULT_PRINTOPERATOR_AUTH "\n"
                             "  </Limit>\n");
       }
 
@@ -1691,7 +1699,8 @@ _cupsAdminSetServerSettings(
          cupsFilePrintf(temp, "  Allow %s\n",
                         remote_any > 0 ? "all" : "@LOCAL");
       }
-      else if (in_root_location && (remote_admin >= 0 || share_printers >= 0))
+      else if (in_root_location &&
+               (remote_admin >= 0 || remote_any > 0 || share_printers >= 0))
       {
        wrote_root_location = 1;
 
@@ -1702,12 +1711,14 @@ _cupsAdminSetServerSettings(
           cupsFilePuts(temp, "  # Allow remote administration...\n");
        else if (share_printers > 0)
           cupsFilePuts(temp, "  # Allow shared printing...\n");
+       else if (remote_any > 0)
+          cupsFilePuts(temp, "  # Allow remote access...\n");
        else
           cupsFilePuts(temp, "  # Restrict access to the server...\n");
 
         cupsFilePuts(temp, "  Order allow,deny\n");
 
-       if (remote_admin > 0 || share_printers > 0)
+       if (remote_admin > 0 || remote_any > 0 || share_printers > 0)
          cupsFilePrintf(temp, "  Allow %s\n",
                         remote_any > 0 ? "all" : "@LOCAL");
       }
@@ -1718,84 +1729,86 @@ _cupsAdminSetServerSettings(
 
       cupsFilePuts(temp, "</Location>\n");
     }
-    else if (!strcasecmp(line, "<Limit") && in_default_policy)
+    else if (!strcasecmp(line, "<Limit"))
     {
-     /*
-      * See if the policy limit is for the Cancel-Job operation...
-      */
-
-      char     *valptr;                /* Pointer into value */
-
-
-      indent += 2;
-
-      if (!strcasecmp(value, "cancel-job") && user_cancel_any >= 0)
+      if (in_default_policy)
       {
        /*
-       * Don't write anything for this limit section...
+       * See if the policy limit is for the Cancel-Job operation...
        */
-
-       in_cancel_job = 2;
-      }
-      else
-      {
-       cupsFilePrintf(temp, "  %s", line);
-
-       while (*value)
+  
+       char    *valptr;                /* Pointer into value */
+  
+  
+       if (!strcasecmp(value, "cancel-job") && user_cancel_any >= 0)
        {
-         for (valptr = value; !isspace(*valptr & 255) && *valptr; valptr ++);
-
-         if (*valptr)
-           *valptr++ = '\0';
-
-          if (!strcasecmp(value, "cancel-job") && user_cancel_any >= 0)
+        /*
+         * Don't write anything for this limit section...
+         */
+  
+         in_cancel_job = 2;
+       }
+       else
+       {
+         cupsFilePrintf(temp, "%*s%s", indent, "", line);
+  
+         while (*value)
          {
-          /*
-           * Write everything except for this definition...
-           */
-
-           in_cancel_job = 1;
+           for (valptr = value; *valptr && !_cups_isspace(*valptr); valptr ++);
+  
+           if (*valptr)
+             *valptr++ = '\0';
+  
+           if (!strcasecmp(value, "cancel-job") && user_cancel_any >= 0)
+           {
+            /*
+             * Write everything except for this definition...
+             */
+  
+             in_cancel_job = 1;
+           }
+           else
+             cupsFilePrintf(temp, " %s", value);
+  
+           for (value = valptr; _cups_isspace(*value); value ++);
          }
-         else
-           cupsFilePrintf(temp, " %s", value);
-
-          for (value = valptr; isspace(*value & 255); value ++);
+  
+         cupsFilePuts(temp, ">\n");
        }
-
-       cupsFilePuts(temp, ">\n");
       }
+      else
+        cupsFilePrintf(temp, "%*s%s %s>\n", indent, "", line, value);
+
+      indent += 2;
     }
     else if (!strcasecmp(line, "</Limit>") && in_cancel_job)
     {
       indent -= 2;
 
       if (in_cancel_job == 1)
-        cupsFilePuts(temp, "  </Limit>\n");
+       cupsFilePuts(temp, "  </Limit>\n");
 
       wrote_policy = 1;
 
       if (!user_cancel_any)
        cupsFilePuts(temp, "  # Only the owner or an administrator can cancel "
-                          "a job...\n"
-                          "  <Limit Cancel-Job>\n"
-                          "    Order deny,allow\n"
-                          "    Require user @OWNER "
-                          CUPS_DEFAULT_PRINTADMIN_AUTH "\n"
+                          "a job...\n"
+                          "  <Limit Cancel-Job>\n"
+                          "    Order deny,allow\n"
+                          "    Require user @OWNER "
+                          CUPS_DEFAULT_PRINTOPERATOR_AUTH "\n"
                           "  </Limit>\n");
 
       in_cancel_job = 0;
     }
     else if ((((in_admin_location || in_conf_location || in_root_location) &&
-               remote_admin >= 0) ||
+               (remote_admin >= 0 || remote_any > 0)) ||
               (in_root_location && share_printers >= 0)) &&
-             (((!strcasecmp(line, "Allow") || !strcasecmp(line, "Deny")) &&
-              !strcasecmp(value, "@LOCAL")) ||
+             (!strcasecmp(line, "Allow") || !strcasecmp(line, "Deny") ||
              !strcasecmp(line, "Order")))
       continue;
     else if (in_cancel_job == 2)
       continue;
-    else if (!strcasecmp(line, "<Limit")  && value)
-      cupsFilePrintf(temp, "  %s %s>\n", line, value);
     else if (line[0] == '<')
     {
       if (value)
@@ -1835,7 +1848,7 @@ _cupsAdminSetServerSettings(
        /*
         * Record the non-policy, non-location directives that we find
        * in the server settings, since we cache this info and record it
-       * in _cupsAdminGetServerSettings()...
+       * in cupsAdminGetServerSettings()...
        */
 
        cupsd_num_settings = cupsAddOption(line, value, cupsd_num_settings,
@@ -1893,9 +1906,10 @@ _cupsAdminSetServerSettings(
     }
   }
 
-  if (!wrote_port_listen && (share_printers >= 0 || remote_admin >= 0))
+  if (!wrote_port_listen &&
+      (remote_admin >= 0 || remote_any > 0 || share_printers >= 0))
   {
-    if (share_printers > 0 || remote_admin > 0)
+    if (remote_admin > 0 || remote_any > 0 || share_printers > 0)
     {
       cupsFilePuts(temp, "# Allow remote access\n");
       cupsFilePrintf(temp, "Port %d\n", ippPort());
@@ -1913,7 +1927,8 @@ _cupsAdminSetServerSettings(
 #endif /* CUPS_DEFAULT_DOMAINSOCKET */
   }
 
-  if (!wrote_root_location && (remote_admin >= 0 || share_printers >= 0))
+  if (!wrote_root_location &&
+      (remote_admin >= 0 || remote_any > 0 || share_printers >= 0))
   {
     if (remote_admin > 0 && share_printers > 0)
       cupsFilePuts(temp,
@@ -1922,13 +1937,15 @@ _cupsAdminSetServerSettings(
       cupsFilePuts(temp, "# Allow remote administration...\n");
     else if (share_printers > 0)
       cupsFilePuts(temp, "# Allow shared printing...\n");
+    else if (remote_any > 0)
+      cupsFilePuts(temp, "# Allow remote access...\n");
     else
       cupsFilePuts(temp, "# Restrict access to the server...\n");
 
     cupsFilePuts(temp, "<Location />\n"
                        "  Order allow,deny\n");
 
-    if (remote_admin > 0 || share_printers > 0)
+    if (remote_admin > 0 || remote_any > 0 || share_printers > 0)
       cupsFilePrintf(temp, "  Allow %s\n", remote_any > 0 ? "all" : "@LOCAL");
 
     cupsFilePuts(temp, "</Location>\n");
@@ -2006,7 +2023,7 @@ _cupsAdminSetServerSettings(
                         "  <Limit Cancel-Job>\n"
                         "    Order deny,allow\n"
                         "    Require user @OWNER "
-                        CUPS_DEFAULT_PRINTADMIN_AUTH "\n"
+                        CUPS_DEFAULT_PRINTOPERATOR_AUTH "\n"
                         "  </Limit>\n");
 
     cupsFilePuts(temp, "  <Limit All>\n"
@@ -2017,6 +2034,8 @@ _cupsAdminSetServerSettings(
 
   for (i = num_settings, setting = settings; i > 0; i --, setting ++)
     if (setting->name[0] != '_' &&
+        strcasecmp(setting->name, "Listen") &&
+       strcasecmp(setting->name, "Port") &&
         !cupsGetOption(setting->name, cupsd_num_settings, cupsd_settings))
     {
      /*
@@ -2147,7 +2166,7 @@ do_samba_command(const char *command,     /* I - Command to run */
 
   if (logfile)
     _cupsLangPrintf(logfile,
-                    _("Running command: %s %s -N -A %s -c \'%s\'\n"),
+                    _("Running command: %s %s -N -A %s -c \'%s\'"),
                    command, address, authfile, subcmd);
 
   if ((pid = fork()) == 0)
@@ -2156,18 +2175,23 @@ do_samba_command(const char *command,   /* I - Command to run */
     * Child goes here, redirect stdin/out/err and execute the command...
     */
 
-    close(0);
-    open("/dev/null", O_RDONLY);
+    int fd = open("/dev/null", O_RDONLY);
 
-    close(1);
+    if (fd > 0)
+    {
+      dup2(fd, 0);
+      close(fd);
+    }
 
     if (logfile)
-      dup(fileno(logfile));
-    else
-      open("/dev/null", O_WRONLY);
+      dup2(fileno(logfile), 1);
+    else if ((fd = open("/dev/null", O_WRONLY)) > 1)
+    {
+      dup2(fd, 1);
+      close(fd);
+    }
 
-    close(2);
-    dup(1);
+    dup2(1, 2);
 
     execlp(command, command, address, "-N", "-A", authfile, "-c", subcmd,
            (char *)0);
@@ -2178,7 +2202,7 @@ do_samba_command(const char *command,     /* I - Command to run */
     status = -1;
 
     if (logfile)
-      _cupsLangPrintf(logfile, _("Unable to run \"%s\": %s\n"),
+      _cupsLangPrintf(logfile, _("Unable to run \"%s\": %s"),
                       command, strerror(errno));
   }
   else
@@ -2191,9 +2215,9 @@ do_samba_command(const char *command,     /* I - Command to run */
   }
 
   if (logfile)
-    _cupsLangPuts(logfile, "\n");
+    _cupsLangPuts(logfile, "");
 
-  DEBUG_printf(("status=%d\n", status));
+  DEBUG_printf(("9do_samba_command: status=%d", status));
 
   if (WIFEXITED(status))
     return (WEXITSTATUS(status));
@@ -2430,5 +2454,5 @@ write_option(cups_file_t     *dstfp,      /* I - PPD file */
 
 
 /*
- * End of "$Id: adminutil.c 7576 2008-05-15 21:05:14Z mike $".
+ * End of "$Id: adminutil.c 7850 2008-08-20 00:07:25Z mike $".
  */