]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Add support for FatalErrors directive (STR #2536)
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Mon, 8 Sep 2008 22:03:01 +0000 (22:03 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Mon, 8 Sep 2008 22:03:01 +0000 (22:03 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@7918 7a7537e8-13f0-0310-91df-b6672ffda945

CHANGES.txt
config-scripts/cups-defaults.m4
config-scripts/cups-network.m4
config.h.in
doc/help/ref-cupsd-conf.html.in
man/cupsd.conf.man.in
scheduler/conf.c
scheduler/conf.h
scheduler/dirsvc.c
scheduler/listen.c
scheduler/log.c

index 6da87f3a196f7e2aa3d41ac25e4dddbf19358af7..cfbcb710c2f2d28363e4c6421572d9e2decd106a 100644 (file)
@@ -1,8 +1,10 @@
-CHANGES.txt - 2008-09-07
+CHANGES.txt - 2008-09-08
 ------------------------
 
 CHANGES IN CUPS V1.4b1
 
+       - The scheduler now supports a FatalErrors directive to control
+         which errors should cause the scheduler to exit (STR #2536)
        - The scheduler now uses the php-cgi program if it is available
          (STR #2923)
        - The scheduler now supports a DefaultPaperSize directive
index 1e090ba26955ce49ee79d9c3b4774ede9d2e28e1..d7f704212af7c54d7ed82f3f06ed43bb564560e6 100644 (file)
@@ -39,6 +39,14 @@ AC_ARG_WITH(log_file_perm, [  --with-log-file-perm    set default LogFilePerm va
 AC_SUBST(CUPS_LOG_FILE_PERM)
 AC_DEFINE_UNQUOTED(CUPS_DEFAULT_LOG_FILE_PERM, 0$CUPS_LOG_FILE_PERM)
 
+dnl Default FatalErrors
+AC_ARG_WITH(fatal_errors, [  --with-fatal-errors set default FatalErrors value, default=config],
+       CUPS_FATAL_ERRORS="$withval",
+       CUPS_FATAL_ERRORS="config")
+AC_SUBST(CUPS_FATAL_ERRORS)
+AC_DEFINE_UNQUOTED(CUPS_DEFAULT_FATAL_ERRORS, "$CUPS_FATAL_ERRORS")
+
+
 dnl Default LogLevel
 AC_ARG_WITH(log_level, [  --with-log-level        set default LogLevel value, default=warn],
        CUPS_LOG_LEVEL="$withval",
index 2788d99efa9e3381123aefde3f843a4a8e8b52a0..19427f67def5e7439b6e928a4bb03070cd299518 100644 (file)
@@ -19,8 +19,9 @@ AC_SEARCH_LIBS(gethostbyaddr, nsl)
 AC_SEARCH_LIBS(getifaddrs, nsl, AC_DEFINE(HAVE_GETIFADDRS))
 AC_SEARCH_LIBS(hstrerror, nsl socket resolv, AC_DEFINE(HAVE_HSTRERROR))
 AC_SEARCH_LIBS(rresvport_af, nsl, AC_DEFINE(HAVE_RRESVPORT_AF))
-AC_SEARCH_LIBS(res_init, resolv bind, AC_DEFINE(HAVE_RES_INIT),
-       AC_SEARCH_LIBS(__res_init, resolv bind, AC_DEFINE(HAVE_RES_INIT)))
+AC_SEARCH_LIBS(__res_init, resolv bind, AC_DEFINE(HAVE_RES_INIT),
+       AC_SEARCH_LIBS(res_9_init, resolv bind, AC_DEFINE(HAVE_RES_INIT),
+       AC_SEARCH_LIBS(res_init, resolv bind, AC_DEFINE(HAVE_RES_INIT))))
 
 # Tru64 5.1b leaks file descriptors with these functions; disable until
 # we can come up with a test for this...
index 7b4c4b54759ad6890603f0c7571962ab092fb158..e657b09028ea2ad55e5199e8853bb56e2a952b4c 100644 (file)
 #define CUPS_DEFAULT_ACCESS_LOG_LEVEL "actions"
 
 
+/*
+ * Default fatal error settings...
+ */
+
+#define CUPS_DEFAULT_FATAL_ERRORS      "config"
+
+
 /*
  * Default browsing settings...
  */
index 300b0f85d654bf55a2749537cce8cc4bfa777b27..2d05d4cb4f2969eb71fbfcaf65562a40740be106 100644 (file)
@@ -1197,6 +1197,57 @@ printer.</P>
 </UL>
 
 
+
+<H2 CLASS="title"><SPAN CLASS="info">CUPS 1.4</SPAN><A NAME="FatalErrors">FatalErrors</A></H2>
+
+<H3>Examples</H3>
+
+<PRE CLASS="command">
+FatalErrors none
+FatalErrors all
+FatalErrors browse
+FatalErrors config
+FatalErrors listen
+FatalErrors log
+FatalErrors permissions
+FatalErrors all -permissions
+FatalErrors config permissions log
+</PRE>
+
+<H3>Description</H3>
+
+<P>The <CODE>FatalErrors</CODE> directive determines whether certain kinds of
+errors are fatal. The following kinds of errors are currently recognized:</P>
+
+<UL>
+
+       <LI><CODE>none</CODE> - No errors are fatal</LI>
+
+       <LI><CODE>all</CODE> - All of the errors below are fatal</LI>
+
+       <LI><CODE>browse</CODE> - Browsing initialization errors are fatal,
+       for example failed binding to the CUPS browse port or failed connections
+       to LDAP servers</LI>
+
+       <LI><CODE>config</CODE> - Configuration file syntax errors are
+       fatal</LI>
+
+       <LI><CODE>listen</CODE> - Listen or Port errors are fatal, except for
+       IPv6 failures on the loopback or "any" addresses</LI>
+
+       <LI><CODE>log</CODE> - Log file creation or write errors are fatal</LI>
+
+       <LI><CODE>permissions</CODE> - Bad startup file permissions are
+       fatal, for example shared SSL certificate and key files with world-
+       read permissions</LI>
+
+</UL>
+
+<P>Multiple errors can be listed, and the form "-kind" can be used with
+<CODE>all</CODE> to remove specific kinds of errors. The default setting is
+<CODE>@CUPS_FATAL_ERRORS@</CODE>.</P>
+
+
 <H2 CLASS="title"><SPAN CLASS="info">CUPS 1.1.18</SPAN><A NAME="FileDevice">FileDevice</A></H2>
 
 <H3>Examples</H3>
index ffbc276728fc8a9aa4400465b19eacdb73c32f44..5ad88f907d96f3693dacb9e6e6b218c8fb1bc0c8 100644 (file)
@@ -312,6 +312,15 @@ ErrorLog syslog
 .br
 Specifies the error log filename.
 .TP 5
+FatalErrors none
+.TP 5
+FatalErrors all -kind [... -kind]
+.TP 5
+FatalErrors kind [... kind]
+.br
+Specifies which errors are fatal, causing the scheduler to exit. "Kind" is
+"browse", "config", "listen", "log", or "permissions".
+.TP 5
 FileDevice Yes
 .TP 5
 FileDevice No
index d8c6805492d490ea14d046cd52475c3832226f12..cec2f7085747db0ddc416cc5d2921750efdce6c8 100644 (file)
@@ -21,6 +21,7 @@
  *   get_addr_and_mask()      - Get an IP address and netmask.
  *   parse_aaa()              - Parse authentication, authorization, and
  *                              access control lines.
+ *   parse_fatal_errors()     - Parse FatalErrors values in a string.
  *   parse_groups()           - Parse system group names in a string.
  *   parse_protocols()        - Parse browse protocols in a string.
  *   read_configuration()     - Read a configuration file.
@@ -199,6 +200,7 @@ static int          get_addr_and_mask(const char *value, unsigned *ip,
                                          unsigned *mask);
 static int             parse_aaa(cupsd_location_t *loc, char *line,
                                  char *value, int linenum);
+static int             parse_fatal_errors(const char *s);
 static int             parse_groups(const char *s);
 static int             parse_protocols(const char *s);
 static int             read_configuration(cups_file_t *fp);
@@ -542,6 +544,7 @@ cupsdReadConfiguration(void)
 
   AccessLogLevel        = CUPSD_ACCESSLOG_ACTIONS;
   ConfigFilePerm        = CUPS_DEFAULT_CONFIG_FILE_PERM;
+  FatalErrors           = parse_fatal_errors(CUPS_DEFAULT_FATAL_ERRORS);
   DefaultAuthType       = CUPSD_AUTH_BASIC;
 #ifdef HAVE_SSL
   DefaultEncryption     = HTTP_ENCRYPT_REQUIRED;
@@ -796,7 +799,8 @@ cupsdReadConfiguration(void)
 
   if (!strncmp(ServerRoot, ServerCertificate, strlen(ServerRoot)) &&
       cupsdCheckPermissions(ServerCertificate, NULL, 0600, RunUser, Group,
-                            0, 0) < 0)
+                            0, 0) < 0 &&
+      (FatalErrors & CUPSD_FATAL_PERMISSIONS))
     return (0);
 
 #  if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
@@ -804,7 +808,8 @@ cupsdReadConfiguration(void)
     cupsdSetStringf(&ServerKey, "%s/%s", ServerRoot, ServerKey);
 
   if (!strncmp(ServerRoot, ServerKey, strlen(ServerRoot)) &&
-      cupsdCheckPermissions(ServerKey, NULL, 0600, RunUser, Group, 0, 0) < 0)
+      cupsdCheckPermissions(ServerKey, NULL, 0600, RunUser, Group, 0, 0) < 0 &&
+      (FatalErrors & CUPSD_FATAL_PERMISSIONS))
     return (0);
 #  endif /* HAVE_LIBSSL || HAVE_GNUTLS */
 #endif /* HAVE_SSL */
@@ -816,30 +821,31 @@ cupsdReadConfiguration(void)
 
   snprintf(temp, sizeof(temp), "%s/rss", CacheDir);
 
-  if (cupsdCheckPermissions(RequestRoot, NULL, 0710, RunUser,
-                           Group, 1, 1) < 0 ||
-      cupsdCheckPermissions(CacheDir, NULL, 0775, RunUser,
-                           Group, 1, 1) < 0 ||
-      cupsdCheckPermissions(temp, NULL, 0775, RunUser,
-                           Group, 1, 1) < 0 ||
-      cupsdCheckPermissions(StateDir, NULL, 0755, RunUser,
-                           Group, 1, 1) < 0 ||
-      cupsdCheckPermissions(StateDir, "certs", RunUser ? 0711 : 0511, User,
-                           SystemGroupIDs[0], 1, 1) < 0 ||
-      cupsdCheckPermissions(ServerRoot, NULL, 0755, RunUser, 
-                           Group, 1, 0) < 0 ||
-      cupsdCheckPermissions(ServerRoot, "ppd", 0755, RunUser,
-                           Group, 1, 1) < 0 ||
-      cupsdCheckPermissions(ServerRoot, "ssl", 0700, RunUser,
-                           Group, 1, 0) < 0 ||
-      cupsdCheckPermissions(ServerRoot, "cupsd.conf", ConfigFilePerm, RunUser,
-                           Group, 0, 0) < 0 ||
-      cupsdCheckPermissions(ServerRoot, "classes.conf", 0600, RunUser,
-                           Group, 0, 0) < 0 ||
-      cupsdCheckPermissions(ServerRoot, "printers.conf", 0600, RunUser,
-                           Group, 0, 0) < 0 ||
-      cupsdCheckPermissions(ServerRoot, "passwd.md5", 0600, User,
-                           Group, 0, 0) < 0)
+  if ((cupsdCheckPermissions(RequestRoot, NULL, 0710, RunUser,
+                            Group, 1, 1) < 0 ||
+       cupsdCheckPermissions(CacheDir, NULL, 0775, RunUser,
+                            Group, 1, 1) < 0 ||
+       cupsdCheckPermissions(temp, NULL, 0775, RunUser,
+                            Group, 1, 1) < 0 ||
+       cupsdCheckPermissions(StateDir, NULL, 0755, RunUser,
+                            Group, 1, 1) < 0 ||
+       cupsdCheckPermissions(StateDir, "certs", RunUser ? 0711 : 0511, User,
+                            SystemGroupIDs[0], 1, 1) < 0 ||
+       cupsdCheckPermissions(ServerRoot, NULL, 0755, RunUser, 
+                            Group, 1, 0) < 0 ||
+       cupsdCheckPermissions(ServerRoot, "ppd", 0755, RunUser,
+                            Group, 1, 1) < 0 ||
+       cupsdCheckPermissions(ServerRoot, "ssl", 0700, RunUser,
+                            Group, 1, 0) < 0 ||
+       cupsdCheckPermissions(ServerRoot, "cupsd.conf", ConfigFilePerm, RunUser,
+                            Group, 0, 0) < 0 ||
+       cupsdCheckPermissions(ServerRoot, "classes.conf", 0600, RunUser,
+                            Group, 0, 0) < 0 ||
+       cupsdCheckPermissions(ServerRoot, "printers.conf", 0600, RunUser,
+                            Group, 0, 0) < 0 ||
+       cupsdCheckPermissions(ServerRoot, "passwd.md5", 0600, User,
+                            Group, 0, 0) < 0) &&
+      (FatalErrors & CUPSD_FATAL_PERMISSIONS))
     return (0);
 
  /*
@@ -889,7 +895,8 @@ cupsdReadConfiguration(void)
     * is under the spool directory or does not exist...
     */
 
-    if (cupsdCheckPermissions(TempDir, NULL, 01770, RunUser, Group, 1, 1) < 0)
+    if (cupsdCheckPermissions(TempDir, NULL, 01770, RunUser, Group, 1, 1) < 0 &&
+       (FatalErrors & CUPSD_FATAL_PERMISSIONS))
       return (0);
   }
 
@@ -948,8 +955,10 @@ cupsdReadConfiguration(void)
   if (MaxClients > (MaxFDs / 3) || MaxClients <= 0)
   {
     if (MaxClients > 0)
-      cupsdLogMessage(CUPSD_LOG_INFO, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
-                 MaxFDs / 3, MaxFDs);
+      cupsdLogMessage(CUPSD_LOG_INFO,
+                      "MaxClients limited to 1/3 (%d) of the file descriptor "
+                     "limit (%d)...",
+                      MaxFDs / 3, MaxFDs);
 
     MaxClients = MaxFDs / 3;
   }
@@ -1186,7 +1195,8 @@ cupsdReadConfiguration(void)
       cupsdLogMessage(CUPSD_LOG_EMERG,
                       "Unable to load MIME database from \"%s\" or \"%s\"!",
                      mimedir, ServerRoot);
-      exit(errno);
+      if (FatalErrors & CUPSD_FATAL_CONFIG)
+        return (0);
     }
 
     cupsdLogMessage(CUPSD_LOG_INFO,
@@ -1982,6 +1992,86 @@ parse_aaa(cupsd_location_t *loc, /* I - Location */
 }
 
 
+/*
+ * 'parse_fatal_errors()' - Parse FatalErrors values in a string.
+ */
+
+static int                             /* O - FatalErrors bits */
+parse_fatal_errors(const char *s)      /* I - FatalErrors string */
+{
+  int  fatal;                          /* FatalErrors bits */
+  char value[1024],                    /* Value string */
+       *valstart,                      /* Pointer into value */
+       *valend;                        /* End of value */
+
+
+ /*
+  * Empty FatalErrors line yields NULL pointer...
+  */
+
+  if (!s)
+    return (CUPSD_FATAL_NONE);
+
+ /*
+  * Loop through the value string,...
+  */
+
+  strlcpy(value, s, sizeof(value));
+
+  fatal = CUPSD_FATAL_NONE;
+
+  for (valstart = value; *valstart;)
+  {
+   /*
+    * Get the current space/comma-delimited kind name...
+    */
+
+    for (valend = valstart; *valend; valend ++)
+      if (isspace(*valend & 255) || *valend == ',')
+       break;
+
+    if (*valend)
+      *valend++ = '\0';
+
+   /*
+    * Add the error to the bitmask...
+    */
+
+    if (!strcasecmp(valstart, "all"))
+      fatal = CUPSD_FATAL_ALL;
+    else if (!strcasecmp(valstart, "browse"))
+      fatal |= CUPSD_FATAL_BROWSE;
+    else if (!strcasecmp(valstart, "-browse"))
+      fatal &= ~CUPSD_FATAL_BROWSE;
+    else if (!strcasecmp(valstart, "config"))
+      fatal |= CUPSD_FATAL_CONFIG;
+    else if (!strcasecmp(valstart, "-config"))
+      fatal &= ~CUPSD_FATAL_CONFIG;
+    else if (!strcasecmp(valstart, "listen"))
+      fatal |= CUPSD_FATAL_LISTEN;
+    else if (!strcasecmp(valstart, "-listen"))
+      fatal &= ~CUPSD_FATAL_LISTEN;
+    else if (!strcasecmp(valstart, "log"))
+      fatal |= CUPSD_FATAL_LOG;
+    else if (!strcasecmp(valstart, "-log"))
+      fatal &= ~CUPSD_FATAL_LOG;
+    else if (!strcasecmp(valstart, "permissions"))
+      fatal |= CUPSD_FATAL_PERMISSIONS;
+    else if (!strcasecmp(valstart, "-permissions"))
+      fatal &= ~CUPSD_FATAL_PERMISSIONS;
+    else if (strcasecmp(valstart, "none"))
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "Unknown FatalErrors kind \"%s\" ignored!", valstart);
+
+    for (valstart = valend; *valstart; valstart ++)
+      if (!isspace(*valstart & 255) || *valstart != ',')
+       break;
+  }
+
+  return (fatal);
+}
+
+
 /*
  * 'parse_groups()' - Parse system group names in a string.
  */
@@ -2216,6 +2306,8 @@ read_configuration(cups_file_t *fp)       /* I - File to read from */
       if (linenum == 0)
        return (0);
     }
+    else if (!strcasecmp(line, "FatalErrors"))
+      FatalErrors = parse_fatal_errors(value);
     else if (!strcasecmp(line, "FaxRetryInterval") && value)
     {
       JobRetryInterval = atoi(value);
@@ -2834,7 +2926,8 @@ read_configuration(cups_file_t *fp)       /* I - File to read from */
        cupsdLogMessage(CUPSD_LOG_WARN,
                        "Unknown default authorization type %s on line %d.",
                        value, linenum);
-       return (0);
+       if (FatalErrors & CUPSD_FATAL_CONFIG)
+         return (0);
       }
     }
 #ifdef HAVE_SSL
@@ -2855,7 +2948,8 @@ read_configuration(cups_file_t *fp)       /* I - File to read from */
        cupsdLogMessage(CUPSD_LOG_WARN,
                        "Unknown default encryption %s on line %d.",
                        value, linenum);
-       return (0);
+       if (FatalErrors & CUPSD_FATAL_CONFIG)
+         return (0);
       }
     }
 #endif /* HAVE_SSL */
@@ -3258,7 +3352,8 @@ read_location(cups_file_t *fp,            /* I - Configuration file */
       if (!value)
       {
         cupsdLogMessage(CUPSD_LOG_ERROR, "Syntax error on line %d.", linenum);
-        return (0);
+        if (FatalErrors & CUPSD_FATAL_CONFIG)
+         return (0);
       }
       
       if ((loc = cupsdCopyLocation(&parent)) == NULL)
@@ -3306,7 +3401,8 @@ read_location(cups_file_t *fp,            /* I - Configuration file */
       cupsdLogMessage(CUPSD_LOG_ERROR,
                       "Unknown Location directive %s on line %d.",
                      line, linenum);
-      return (0);
+      if (FatalErrors & CUPSD_FATAL_CONFIG)
+       return (0);
     }
   }
 
@@ -3314,7 +3410,7 @@ read_location(cups_file_t *fp,            /* I - Configuration file */
                   "Unexpected end-of-file at line %d while reading location!",
                   linenum);
 
-  return (0);
+  return ((FatalErrors & CUPSD_FATAL_CONFIG) ? 0 : linenum);
 }
 
 
@@ -3396,7 +3492,8 @@ read_policy(cups_file_t *fp,              /* I - Configuration file */
       if (!value)
       {
         cupsdLogMessage(CUPSD_LOG_ERROR, "Syntax error on line %d.", linenum);
-        return (0);
+        if (FatalErrors & CUPSD_FATAL_CONFIG)
+         return (0);
       }
       
      /*
@@ -3470,7 +3567,8 @@ read_policy(cups_file_t *fp,              /* I - Configuration file */
       cupsdLogMessage(CUPSD_LOG_ERROR,
                       "Missing <Limit ops> directive before %s on line %d.",
                       line, linenum);
-      return (0);
+      if (FatalErrors & CUPSD_FATAL_CONFIG)
+       return (0);
     }
     else if (!parse_aaa(op, line, value, linenum))
     {
@@ -3483,7 +3581,8 @@ read_policy(cups_file_t *fp,              /* I - Configuration file */
                        "Unknown Policy directive %s on line %d.",
                        line, linenum);
 
-      return (0);
+      if (FatalErrors & CUPSD_FATAL_CONFIG)
+       return (0);
     }
   }
 
@@ -3491,7 +3590,7 @@ read_policy(cups_file_t *fp,              /* I - Configuration file */
                   "Unexpected end-of-file at line %d while reading policy \"%s\"!",
                   linenum, policy);
 
-  return (0);
+  return ((FatalErrors & CUPSD_FATAL_CONFIG) ? 0 : linenum);
 }
 
 
index 779345180a2b83fc8aecfb5f578f4c1d2d2ac495..4eeee7995e97aa42055556ea33972ccd921b5d31 100644 (file)
@@ -45,6 +45,19 @@ typedef enum
 } cupsd_accesslog_t;
 
 
+/*
+ * FatalErrors flags...
+ */
+
+#define CUPSD_FATAL_NONE       0       /* No errors are fatal */
+#define CUPSD_FATAL_BROWSE     1       /* Browse bind errors are fatal */
+#define CUPSD_FATAL_CONFIG     2       /* Config file syntax errors are fatal */
+#define CUPSD_FATAL_LISTEN     4       /* Listen/Port bind errors are fatal */
+#define CUPSD_FATAL_LOG                8       /* Log file errors are fatal */
+#define CUPSD_FATAL_PERMISSIONS        16      /* File permission errors are fatal */
+#define CUPSD_FATAL_ALL                ~0      /* All errors are fatal */
+
+
 /*
  * Printcap formats...
  */
@@ -132,6 +145,8 @@ VAR int                     AccessLogLevel          VALUE(CUPSD_ACCESSLOG_ACTIONS),
                                        /* Allow overrides? */
                        ConfigFilePerm          VALUE(0640),
                                        /* Permissions for config files */
+                       FatalErrors             VALUE(CUPSD_FATAL_CONFIG),
+                                       /* Which errors are fatal? */
                        LogFilePerm             VALUE(0644),
                                        /* Permissions for log files */
                        LogLevel                VALUE(CUPSD_LOG_WARN),
index 112439911d8ea85dfd8e08b130f5d30f3f4f3b29..aa0febc5a185fd703dadbcc7fbb147d1a76622c0 100644 (file)
@@ -1422,9 +1422,14 @@ cupsdStartBrowsing(void)
                        strerror(errno));
        BrowseLocalProtocols &= ~BROWSE_CUPS;
        BrowseRemoteProtocols &= ~BROWSE_CUPS;
-       return;
+
+       if (FatalErrors & CUPSD_FATAL_BROWSE)
+         cupsdEndProcess(getpid(), 0);
       }
+    }
 
+    if (BrowseSocket >= 0)
+    {
      /*
       * Bind the socket to browse port...
       */
@@ -1449,50 +1454,60 @@ cupsdStartBrowsing(void)
        BrowseSocket = -1;
        BrowseLocalProtocols &= ~BROWSE_CUPS;
        BrowseRemoteProtocols &= ~BROWSE_CUPS;
-       return;
+
+       if (FatalErrors & CUPSD_FATAL_BROWSE)
+         cupsdEndProcess(getpid(), 0);
       }
     }
 
-   /*
-    * Set the "broadcast" flag...
-    */
-
-    val = 1;
-    if (setsockopt(BrowseSocket, SOL_SOCKET, SO_BROADCAST, &val, sizeof(val)))
+    if (BrowseSocket >= 0)
     {
-      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to set broadcast mode - %s.",
-                     strerror(errno));
+     /*
+      * Set the "broadcast" flag...
+      */
+
+      val = 1;
+      if (setsockopt(BrowseSocket, SOL_SOCKET, SO_BROADCAST, &val, sizeof(val)))
+      {
+       cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to set broadcast mode - %s.",
+                       strerror(errno));
 
 #ifdef WIN32
-      closesocket(BrowseSocket);
+       closesocket(BrowseSocket);
 #else
-      close(BrowseSocket);
+       close(BrowseSocket);
 #endif /* WIN32 */
 
-      BrowseSocket = -1;
-      BrowseLocalProtocols &= ~BROWSE_CUPS;
-      BrowseRemoteProtocols &= ~BROWSE_CUPS;
-      return;
-    }
+       BrowseSocket = -1;
+       BrowseLocalProtocols &= ~BROWSE_CUPS;
+       BrowseRemoteProtocols &= ~BROWSE_CUPS;
 
-   /*
-    * Close the socket on exec...
-    */
+       if (FatalErrors & CUPSD_FATAL_BROWSE)
+         cupsdEndProcess(getpid(), 0);
+      }
+    }
 
-    fcntl(BrowseSocket, F_SETFD, fcntl(BrowseSocket, F_GETFD) | FD_CLOEXEC);
+    if (BrowseSocket >= 0)
+    {
+     /*
+      * Close the socket on exec...
+      */
 
-   /*
-    * Finally, add the socket to the input selection set as needed...
-    */
+      fcntl(BrowseSocket, F_SETFD, fcntl(BrowseSocket, F_GETFD) | FD_CLOEXEC);
 
-    if (BrowseRemoteProtocols & BROWSE_CUPS)
-    {
      /*
-      * We only listen if we want remote printers...
+      * Finally, add the socket to the input selection set as needed...
       */
 
-      cupsdAddSelect(BrowseSocket, (cupsd_selfunc_t)update_cups_browse,
-                     NULL, NULL);
+      if (BrowseRemoteProtocols & BROWSE_CUPS)
+      {
+       /*
+       * We only listen if we want remote printers...
+       */
+
+       cupsdAddSelect(BrowseSocket, (cupsd_selfunc_t)update_cups_browse,
+                      NULL, NULL);
+      }
     }
   }
   else
@@ -1511,8 +1526,13 @@ cupsdStartBrowsing(void)
 
     if ((error = DNSServiceCreateConnection(&DNSSDRef))
            != kDNSServiceErr_NoError)
+    {
       cupsdLogMessage(CUPSD_LOG_ERROR,
                      "Unable to create master DNS-SD reference: %d", error);
+
+      if (FatalErrors & CUPSD_FATAL_BROWSE)
+       cupsdEndProcess(getpid(), 0);
+    }
     else
     {
      /*
@@ -1579,6 +1599,10 @@ cupsdStartBrowsing(void)
                       "Unable to open an SLP handle; disabling SLP browsing!");
       BrowseLocalProtocols &= ~BROWSE_SLP;
       BrowseRemoteProtocols &= ~BROWSE_SLP;
+      BrowseSLPHandle = NULL;
+
+      if (FatalErrors & CUPSD_FATAL_BROWSE)
+       cupsdEndProcess(getpid(), 0);
     }
 
     BrowseSLPRefresh = 0;
@@ -1596,11 +1620,19 @@ cupsdStartBrowsing(void)
                       "Need to set BrowseLDAPDN to use LDAP browsing!");
       BrowseLocalProtocols &= ~BROWSE_LDAP;
       BrowseRemoteProtocols &= ~BROWSE_LDAP;
+
+      if (FatalErrors & CUPSD_FATAL_BROWSE)
+       cupsdEndProcess(getpid(), 0);
     }
     else
     {
-      /* Open LDAP handle... */
-      BrowseLDAPHandle = ldap_connect();
+     /*
+      * Open LDAP handle...
+      */
+
+      if ((BrowseLDAPHandle = ldap_connect()) == NULL &&
+          (FatalErrors & CUPSD_FATAL_BROWSE))
+       cupsdEndProcess(getpid(), 0);
     }
 
     BrowseLDAPRefresh = 0;
index f257762f83f4458a1fb3a1ad7de687b1673aae34..c41b94cc63d68bb223b9240b0eb026a7bc9452ce 100644 (file)
@@ -150,10 +150,15 @@ cupsdStartListening(void)
     httpAddrFreeList(ServerAddrs);
 
   if ((ServerAddrs = httpAddrGetList(ServerName, AF_UNSPEC, NULL)) == NULL)
+  {
     cupsdLogMessage(CUPSD_LOG_ERROR,
                     "Unable to find IP address for server name \"%s\"!",
                    ServerName);
 
+    if (FatalErrors & CUPSD_FATAL_LISTEN)
+      cupsdEndProcess(getpid(), 0);
+  }
+
  /*
   * Setup socket listeners...
   */
@@ -194,6 +199,20 @@ cupsdStartListening(void)
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Unable to open listen socket for address %s:%d - %s.",
                        s, p, strerror(errno));
+
+#ifdef AF_INET6
+       /*
+        * IPv6 is often disabled while DNS returns IPv6 addresses...
+       */
+
+       if (lis->address.addr.sa_family != AF_INET6 &&
+           (FatalErrors & CUPSD_FATAL_LISTEN))
+         cupsdEndProcess(getpid(), 0);
+#else
+       if (FatalErrors & CUPSD_FATAL_LISTEN)
+         cupsdEndProcess(getpid(), 0);
+#endif /* AF_INET6 */
+
        continue;
       }
 
@@ -278,6 +297,10 @@ cupsdStartListening(void)
                        s, p, strerror(errno));
        close(lis->fd);
        lis->fd = -1;
+
+       if (FatalErrors & CUPSD_FATAL_LISTEN)
+         cupsdEndProcess(getpid(), 0);
+
        continue;
       }
 
@@ -290,7 +313,14 @@ cupsdStartListening(void)
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Unable to listen for clients on address %s:%d - %s.",
                        s, p, strerror(errno));
-       exit(errno);
+
+       close(lis->fd);
+       lis->fd = -1;
+
+       if (FatalErrors & CUPSD_FATAL_LISTEN)
+         cupsdEndProcess(getpid(), 0);
+
+        continue;
       }
     }
 
@@ -339,11 +369,8 @@ cupsdStartListening(void)
                     "No Listen or Port lines were found to allow access via "
                    "localhost!");
 
-   /*
-    * Commit suicide...
-    */
-
-    cupsdEndProcess(getpid(), 0);
+    if (FatalErrors & (CUPSD_FATAL_CONFIG | CUPSD_FATAL_LISTEN))
+      cupsdEndProcess(getpid(), 0);
   }
 
  /*
index b58badac0200f67dde13b8767c9533dfb6f093eb..1dba8c3f60ba13123184880296bac0f41a742981 100644 (file)
@@ -807,7 +807,20 @@ check_log_file(cups_file_t **lf,   /* IO - Log file */
 
       if (!strncmp(filename, CUPS_LOGDIR, strlen(CUPS_LOGDIR)))
       {
-        cupsdCheckPermissions(CUPS_LOGDIR, NULL, 0755, RunUser, Group, 1, -1);
+       /*
+        * Try updating the permissions of the containing log directory, using
+       * the log file permissions as a basis...
+       */
+
+        int log_dir_perm = 0300 | LogFilePerm;
+                                       /* LogFilePerm + owner write/search */
+       if (log_dir_perm & 0040)
+         log_dir_perm |= 0010;         /* Add group search */
+       if (log_dir_perm & 0004)
+         log_dir_perm |= 0001;         /* Add other search */
+
+        cupsdCheckPermissions(CUPS_LOGDIR, NULL, log_dir_perm, RunUser, Group,
+                             1, -1);
 
         *lf = cupsFileOpen(filename, "a");
       }
@@ -816,6 +829,10 @@ check_log_file(cups_file_t **lf,   /* IO - Log file */
       {
        syslog(LOG_ERR, "Unable to open log file \"%s\" - %s", filename,
               strerror(errno));
+
+        if (FatalErrors & CUPSD_FATAL_LOG)
+         cupsdEndProcess(getpid(), 0);
+
        return (0);
       }
     }
@@ -855,6 +872,9 @@ check_log_file(cups_file_t **lf,    /* IO - Log file */
       syslog(LOG_ERR, "Unable to open log file \"%s\" - %s", filename,
              strerror(errno));
 
+      if (FatalErrors & CUPSD_FATAL_LOG)
+       cupsdEndProcess(getpid(), 0);
+
       return (0);
     }