]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/conf.c
Load cups into easysw/current.
[thirdparty/cups.git] / scheduler / conf.c
index 0963e5fec41b52a7620dcc939b2f2b8ae122f128..d033627ad73b0105e47f135b69ae6a3e526f91c0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: conf.c 4903 2006-01-10 20:02:46Z mike $"
+ * "$Id: conf.c 6253 2007-02-10 18:48:40Z mike $"
  *
  *   Configuration routines for the Common UNIX Printing System (CUPS).
  *
  * Contents:
  *
  *   cupsdReadConfiguration() - Read the cupsd.conf file.
+ *   check_permissions()      - Fix the mode and ownership of a file or
+ *                              directory.
  *   get_address()            - Get an address + port number from a line.
  *   get_addr_and_mask()      - Get an IP address and netmask.
  *   parse_aaa()              - Parse authentication, authorization, and
  *                              access control lines.
+ *   parse_groups()           - Parse system group names in a string.
+ *   parse_protocols()        - Parse browse protocols in a string.
  *   read_configuration()     - Read a configuration file.
  *   read_location()          - Read a <Location path> definition.
  *   read_policy()            - Read a <Policy name> definition.
@@ -85,6 +89,12 @@ static cupsd_var_t   variables[] =
   { "AccessLog",               &AccessLog,             CUPSD_VARTYPE_STRING },
   { "AutoPurgeJobs",           &JobAutoPurge,          CUPSD_VARTYPE_BOOLEAN },
   { "BrowseInterval",          &BrowseInterval,        CUPSD_VARTYPE_INTEGER },
+#ifdef HAVE_LDAP
+  { "BrowseLDAPBindDN",                &BrowseLDAPBindDN,      CUPSD_VARTYPE_STRING },
+  { "BrowseLDAPDN",            &BrowseLDAPDN,          CUPSD_VARTYPE_STRING },
+  { "BrowseLDAPPassword",      &BrowseLDAPPassword,    CUPSD_VARTYPE_STRING },
+  { "BrowseLDAPServer",                &BrowseLDAPServer,      CUPSD_VARTYPE_STRING },
+#endif /* HAVE_LDAP */
   { "BrowseLocalOptions",      &BrowseLocalOptions,    CUPSD_VARTYPE_STRING },
   { "BrowsePort",              &BrowsePort,            CUPSD_VARTYPE_INTEGER },
   { "BrowseRemoteOptions",     &BrowseRemoteOptions,   CUPSD_VARTYPE_STRING },
@@ -100,19 +110,26 @@ static cupsd_var_t        variables[] =
   { "DefaultLanguage",         &DefaultLanguage,       CUPSD_VARTYPE_STRING },
   { "DefaultLeaseDuration",    &DefaultLeaseDuration,  CUPSD_VARTYPE_INTEGER },
   { "DefaultPolicy",           &DefaultPolicy,         CUPSD_VARTYPE_STRING },
+  { "DefaultShared",           &DefaultShared,         CUPSD_VARTYPE_BOOLEAN },
   { "DocumentRoot",            &DocumentRoot,          CUPSD_VARTYPE_STRING },
   { "ErrorLog",                        &ErrorLog,              CUPSD_VARTYPE_STRING },
   { "FileDevice",              &FileDevice,            CUPSD_VARTYPE_BOOLEAN },
   { "FilterLimit",             &FilterLimit,           CUPSD_VARTYPE_INTEGER },
   { "FilterNice",              &FilterNice,            CUPSD_VARTYPE_INTEGER },
   { "FontPath",                        &FontPath,              CUPSD_VARTYPE_STRING },
-  { "HideImplicitMembers",     &HideImplicitMembers,   CUPSD_VARTYPE_BOOLEAN },
+#ifdef HAVE_GSSAPI
+  { "GSSServiceName",          &GSSServiceName,        CUPSD_VARTYPE_STRING },
+#endif /* HAVE_GSSAPI */
   { "ImplicitClasses",         &ImplicitClasses,       CUPSD_VARTYPE_BOOLEAN },
   { "ImplicitAnyClasses",      &ImplicitAnyClasses,    CUPSD_VARTYPE_BOOLEAN },
   { "JobRetryLimit",           &JobRetryLimit,         CUPSD_VARTYPE_INTEGER },
   { "JobRetryInterval",                &JobRetryInterval,      CUPSD_VARTYPE_INTEGER },
   { "KeepAliveTimeout",                &KeepAliveTimeout,      CUPSD_VARTYPE_INTEGER },
   { "KeepAlive",               &KeepAlive,             CUPSD_VARTYPE_BOOLEAN },
+#ifdef HAVE_LAUNCHD
+  { "LaunchdTimeout",          &LaunchdTimeout,        CUPSD_VARTYPE_INTEGER },
+  { "LaunchdConf",             &LaunchdConf,           CUPSD_VARTYPE_STRING },
+#endif /* HAVE_LAUNCHD */
   { "LimitRequestBody",                &MaxRequestSize,        CUPSD_VARTYPE_INTEGER },
   { "ListenBackLog",           &ListenBackLog,         CUPSD_VARTYPE_INTEGER },
   { "LogFilePerm",             &LogFilePerm,           CUPSD_VARTYPE_INTEGER },
@@ -141,7 +158,6 @@ static cupsd_var_t  variables[] =
   { "RemoteRoot",              &RemoteRoot,            CUPSD_VARTYPE_STRING },
   { "RequestRoot",             &RequestRoot,           CUPSD_VARTYPE_STRING },
   { "RIPCache",                        &RIPCache,              CUPSD_VARTYPE_STRING },
-  { "RunAsUser",               &RunAsUser,             CUPSD_VARTYPE_BOOLEAN },
   { "RootCertDuration",                &RootCertDuration,      CUPSD_VARTYPE_INTEGER },
   { "ServerAdmin",             &ServerAdmin,           CUPSD_VARTYPE_STRING },
   { "ServerBin",               &ServerBin,             CUPSD_VARTYPE_STRING },
@@ -154,8 +170,12 @@ static cupsd_var_t variables[] =
   { "ServerName",              &ServerName,            CUPSD_VARTYPE_STRING },
   { "ServerRoot",              &ServerRoot,            CUPSD_VARTYPE_STRING },
   { "StateDir",                        &StateDir,              CUPSD_VARTYPE_STRING },
+#ifdef HAVE_AUTHORIZATION_H
+  { "SystemGroupAuthKey",      &SystemGroupAuthKey,    CUPSD_VARTYPE_STRING },
+#endif /* HAVE_AUTHORIZATION_H */
   { "TempDir",                 &TempDir,               CUPSD_VARTYPE_STRING },
-  { "Timeout",                 &Timeout,               CUPSD_VARTYPE_INTEGER }
+  { "Timeout",                 &Timeout,               CUPSD_VARTYPE_INTEGER },
+  { "UseNetworkDefault",       &UseNetworkDefault,     CUPSD_VARTYPE_BOOLEAN }
 };
 #define NUM_VARS       (sizeof(variables) / sizeof(variables[0]))
 
@@ -173,12 +193,17 @@ static unsigned           zeros[4] =
 /*
  * Local functions...
  */
-
+static int             check_permissions(const char *filename,
+                                         const char *suffix, int mode,
+                                         int user, int group, int is_dir,
+                                         int create_dir);
 static http_addrlist_t *get_address(const char *value, int defport);
 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_groups(const char *s);
+static int             parse_protocols(const char *s);
 static int             read_configuration(cups_file_t *fp);
 static int             read_location(cups_file_t *fp, char *name, int linenum);
 static int             read_policy(cups_file_t *fp, char *name, int linenum);
@@ -196,19 +221,14 @@ cupsdReadConfiguration(void)
   int          status;                 /* Return status */
   char         temp[1024],             /* Temporary buffer */
                *slash;                 /* Directory separator */
-  char         type[MIME_MAX_SUPER + MIME_MAX_TYPE];
-                                       /* MIME type name */
   cups_lang_t  *language;              /* Language */
   struct passwd        *user;                  /* Default user */
   struct group *group;                 /* Default group */
   char         *old_serverroot,        /* Old ServerRoot */
                *old_requestroot;       /* Old RequestRoot */
+  const char   *tmpdir;                /* TMPDIR environment variable */
+  struct stat  tmpinfo;                /* Temporary directory info */
 
- /*
-  * Shutdown the server...
-  */
-
-  cupsdStopServer();
 
  /*
   * Save the old root paths...
@@ -228,6 +248,7 @@ cupsdReadConfiguration(void)
   if (NumBrowsers > 0)
   {
     free(Browsers);
+    Browsers = NULL;
 
     NumBrowsers = 0;
   }
@@ -250,17 +271,13 @@ cupsdReadConfiguration(void)
     NumRelays = 0;
   }
 
-  if (NumListeners > 0)
-  {
-    free(Listeners);
-    NumListeners = 0;
-  }
+  cupsdDeleteAllListeners();
 
  /*
   * String options...
   */
 
-  cupsdSetString(&ServerName, httpGetHostname(temp, sizeof(temp)));
+  cupsdSetString(&ServerName, httpGetHostname(NULL, temp, sizeof(temp)));
   cupsdSetStringf(&ServerAdmin, "root@%s", temp);
   cupsdSetString(&ServerBin, CUPS_SERVERBIN);
   cupsdSetString(&RequestRoot, CUPS_REQUESTS);
@@ -270,12 +287,20 @@ cupsdReadConfiguration(void)
   cupsdSetString(&AccessLog, CUPS_LOGDIR "/access_log");
   cupsdSetString(&ErrorLog, CUPS_LOGDIR "/error_log");
   cupsdSetString(&PageLog, CUPS_LOGDIR "/page_log");
-  cupsdSetString(&Printcap, "/etc/printcap");
+  cupsdSetString(&Printcap, CUPS_DEFAULT_PRINTCAP);
   cupsdSetString(&PrintcapGUI, "/usr/bin/glpoptions");
   cupsdSetString(&FontPath, CUPS_FONTPATH);
   cupsdSetString(&RemoteRoot, "remroot");
-  cupsdSetString(&ServerHeader, "CUPS/1.1");
+  cupsdSetString(&ServerHeader, "CUPS/1.2");
   cupsdSetString(&StateDir, CUPS_STATEDIR);
+#ifdef HAVE_GSSAPI
+  cupsdSetString(&GSSServiceName, CUPS_DEFAULT_GSSSERVICENAME);
+#endif /* HAVE_GSSAPI */
+
+  if (!strcmp(CUPS_DEFAULT_PRINTCAP, "/etc/printers.conf"))
+    PrintcapFormat = PRINTCAP_SOLARIS;
+  else
+    PrintcapFormat = PRINTCAP_BSD;
 
   strlcpy(temp, ConfigurationFile, sizeof(temp));
   if ((slash = strrchr(temp, '/')) != NULL)
@@ -288,7 +313,7 @@ cupsdReadConfiguration(void)
 
 #ifdef HAVE_SSL
 #  ifdef HAVE_CDSASSL
-  cupsdSetString(&ServerCertificate, "/var/root/Library/Keychains/CUPS");
+  cupsdSetString(&ServerCertificate, "/Library/Keychains/System.keychain");
 #  else
   cupsdSetString(&ServerCertificate, "ssl/server.crt");
   cupsdSetString(&ServerKey, "ssl/server.key");
@@ -306,46 +331,7 @@ cupsdReadConfiguration(void)
 
   cupsdSetString(&RIPCache, "8m");
 
-  if (getenv("TMPDIR") == NULL)
-    cupsdSetString(&TempDir, CUPS_REQUESTS "/tmp");
-  else
-    cupsdSetString(&TempDir, getenv("TMPDIR"));
-
- /*
-  * Find the default system group: "sys", "system", or "root"...
-  */
-
-  group = getgrnam(CUPS_DEFAULT_GROUP);
-  endgrent();
-
-  NumSystemGroups = 0;
-
-  if (group != NULL)
-  {
-   /*
-    * Found the group, use it!
-    */
-
-    cupsdSetString(&SystemGroups[0], CUPS_DEFAULT_GROUP);
-
-    SystemGroupIDs[0] = group->gr_gid;
-  }
-  else
-  {
-   /*
-    * Find the group associated with GID 0...
-    */
-
-    group = getgrgid(0);
-    endgrent();
-
-    if (group != NULL)
-      cupsdSetString(&SystemGroups[0], group->gr_name);
-    else
-      cupsdSetString(&SystemGroups[0], "unknown");
-
-    SystemGroupIDs[0] = 0;
-  }
+  cupsdSetString(&TempDir, NULL);
 
  /*
   * Find the default user...
@@ -366,66 +352,89 @@ cupsdReadConfiguration(void)
   endpwent();
 
  /*
-  * Find the default group (nobody)...
+  * Find the default group...
   */
 
-  group = getgrnam("nobody");
+  group = getgrnam(CUPS_DEFAULT_GROUP);
   endgrent();
 
-  if (group != NULL)
+  if (group)
     Group = group->gr_gid;
   else
   {
    /*
-    * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
-    * complement number...)
+    * Fallback to group "nobody"...
     */
 
-    Group = 65534;
+    group = getgrnam("nobody");
+    endgrent();
+
+    if (group)
+      Group = group->gr_gid;
+    else
+    {
+     /*
+      * Use the (historical) NFS nobody group ID (-2 as a 16-bit twos-
+      * complement number...)
+      */
+
+      Group = 65534;
+    }
   }
 
  /*
   * Numeric options...
   */
 
-  ConfigFilePerm      = 0640;
-  DefaultAuthType     = AUTH_BASIC;
-  JobRetryLimit       = 5;
-  JobRetryInterval    = 300;
-  FileDevice          = FALSE;
-  FilterLevel         = 0;
-  FilterLimit         = 0;
-  FilterNice          = 0;
-  HostNameLookups     = FALSE;
-  ImplicitClasses     = TRUE;
-  ImplicitAnyClasses  = FALSE;
-  HideImplicitMembers = TRUE;
-  KeepAlive           = TRUE;
-  KeepAliveTimeout    = DEFAULT_KEEPALIVE;
-  ListenBackLog       = SOMAXCONN;
-  LogFilePerm         = 0644;
-  LogLevel            = CUPSD_LOG_ERROR;
-  MaxClients          = 100;
-  MaxClientsPerHost   = 0;
-  MaxLogSize          = 1024 * 1024;
-  MaxPrinterHistory   = 10;
-  MaxRequestSize      = 0;
-  ReloadTimeout              = 60;
-  RootCertDuration    = 300;
-  RunAsUser           = FALSE;
-  Timeout             = DEFAULT_TIMEOUT;
+  ConfigFilePerm        = CUPS_DEFAULT_CONFIG_FILE_PERM;
+  DefaultAuthType       = AUTH_BASIC;
+#ifdef HAVE_SSL
+  DefaultEncryption     = HTTP_ENCRYPT_REQUIRED;
+#endif /* HAVE_SSL */
+  JobRetryLimit         = 5;
+  JobRetryInterval      = 300;
+  FileDevice            = FALSE;
+  FilterLevel           = 0;
+  FilterLimit           = 0;
+  FilterNice            = 0;
+  HostNameLookups       = FALSE;
+  ImplicitClasses       = CUPS_DEFAULT_IMPLICIT_CLASSES;
+  ImplicitAnyClasses    = FALSE;
+  HideImplicitMembers   = TRUE;
+  KeepAlive             = TRUE;
+  KeepAliveTimeout      = DEFAULT_KEEPALIVE;
+  ListenBackLog         = SOMAXCONN;
+  LogFilePerm           = CUPS_DEFAULT_LOG_FILE_PERM;
+  LogLevel              = CUPSD_LOG_ERROR;
+  MaxClients            = 100;
+  MaxClientsPerHost     = 0;
+  MaxLogSize            = 1024 * 1024;
+  MaxPrinterHistory     = 10;
+  MaxRequestSize        = 0;
+  ReloadTimeout                = 60;
+  RootCertDuration      = 300;
+  Timeout               = DEFAULT_TIMEOUT;
+  NumSystemGroups       = 0;
 
   BrowseInterval        = DEFAULT_INTERVAL;
   BrowsePort            = ippPort();
-  BrowseLocalProtocols  = BROWSE_CUPS;
-  BrowseRemoteProtocols = BROWSE_CUPS;
-  BrowseShortNames      = TRUE;
+  BrowseLocalProtocols  = parse_protocols(CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS);
+  BrowseRemoteProtocols = parse_protocols(CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS);
+  BrowseShortNames      = CUPS_DEFAULT_BROWSE_SHORT_NAMES;
   BrowseTimeout         = DEFAULT_TIMEOUT;
-  Browsing              = TRUE;
+  Browsing              = CUPS_DEFAULT_BROWSING;
+  DefaultShared         = CUPS_DEFAULT_DEFAULT_SHARED;
 
   cupsdClearString(&BrowseLocalOptions);
   cupsdClearString(&BrowseRemoteOptions);
 
+#ifdef HAVE_LDAP
+  cupsdClearString(&BrowseLDAPBindDN);
+  cupsdClearString(&BrowseLDAPDN);
+  cupsdClearString(&BrowseLDAPPassword);
+  cupsdClearString(&BrowseLDAPServer);
+#endif /* HAVE_LDAP */
+
   JobHistory          = DEFAULT_HISTORY;
   JobFiles            = DEFAULT_FILES;
   JobAutoPurge        = 0;
@@ -433,11 +442,15 @@ cupsdReadConfiguration(void)
   MaxActiveJobs       = 0;
   MaxJobsPerUser      = 0;
   MaxJobsPerPrinter   = 0;
-  MaxCopies           = 100;
+  MaxCopies           = CUPS_DEFAULT_MAX_COPIES;
 
   cupsdDeleteAllPolicies();
   cupsdClearString(&DefaultPolicy);
 
+#ifdef HAVE_AUTHORIZATION_H
+  cupsdClearString(&SystemGroupAuthKey);
+#endif /* HAVE_AUTHORIZATION_H */
+
   MaxSubscriptions           = 100;
   MaxSubscriptionsPerJob     = 0;
   MaxSubscriptionsPerPrinter = 0;
@@ -445,6 +458,11 @@ cupsdReadConfiguration(void)
   DefaultLeaseDuration       = 86400;
   MaxLeaseDuration           = 0;
 
+#ifdef HAVE_LAUNCHD
+  LaunchdTimeout = DEFAULT_TIMEOUT + 10;
+  cupsdSetString(&LaunchdConf, CUPS_DEFAULT_LAUNCHD_CONF);
+#endif /* HAVE_LAUNCHD */
+
  /*
   * Read the configuration file...
   */
@@ -459,17 +477,40 @@ cupsdReadConfiguration(void)
   if (!status)
     return (0);
 
-  if (RunAsUser)
-    RunUser = User;
-  else
-    RunUser = getuid();
+  RunUser = getuid();
+
+ /*
+  * See if the ServerName is an IP address...
+  */
+
+  for (slash = ServerName; isdigit(*slash & 255) || *slash == '.'; slash ++);
+
+  ServerNameIsIP = !*slash;
 
  /*
   * Use the default system group if none was supplied in cupsd.conf...
   */
 
   if (NumSystemGroups == 0)
-    NumSystemGroups ++;
+  {
+    if (!parse_groups(CUPS_DEFAULT_SYSTEM_GROUPS))
+    {
+     /*
+      * Find the group associated with GID 0...
+      */
+
+      group = getgrgid(0);
+      endgrent();
+
+      if (group != NULL)
+       cupsdSetString(&SystemGroups[0], group->gr_name);
+      else
+       cupsdSetString(&SystemGroups[0], "unknown");
+
+      SystemGroupIDs[0] = 0;
+      NumSystemGroups   = 1;
+    }
+  }
 
  /*
   * Get the access control list for browsing...
@@ -539,7 +580,7 @@ cupsdReadConfiguration(void)
   * as an error and exit!
   */
 
-  if (NumListeners == 0)
+  if (cupsArrayCount(Listeners) == 0)
   {
    /*
     * No listeners!
@@ -587,7 +628,7 @@ cupsdReadConfiguration(void)
   if (!strncmp(ServerRoot, ServerCertificate, strlen(ServerRoot)))
   {
     chown(ServerCertificate, RunUser, Group);
-    chmod(ServerCertificate, ConfigFilePerm);
+    chmod(ServerCertificate, 0600);
   }
 
 #  if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
@@ -597,7 +638,7 @@ cupsdReadConfiguration(void)
   if (!strncmp(ServerRoot, ServerKey, strlen(ServerRoot)))
   {
     chown(ServerKey, RunUser, Group);
-    chmod(ServerKey, ConfigFilePerm);
+    chmod(ServerKey, 0600);
   }
 #  endif /* HAVE_LIBSSL || HAVE_GNUTLS */
 #endif /* HAVE_SSL */
@@ -607,65 +648,64 @@ cupsdReadConfiguration(void)
   * writable by the user and group in the cupsd.conf file...
   */
 
-  chown(CacheDir, RunUser, Group);
-  chmod(CacheDir, 0775);
-
-  snprintf(temp, sizeof(temp), "%s/ppd", CacheDir);
-  if (access(temp, 0))
-    mkdir(temp, 0755);
-  chown(temp, RunUser, Group);
-  chmod(temp, 0755);
-
-  chown(StateDir, RunUser, Group);
-  chmod(StateDir, 0775);
-
-  snprintf(temp, sizeof(temp), "%s/certs", StateDir);
-  if (access(temp, 0))
-    mkdir(temp, 0510);
-  chown(temp, User, SystemGroupIDs[0]);
-  if (RunUser)
-    chmod(temp, 0710);
-  else
-    chmod(temp, 0510);
-
-  chown(ServerRoot, RunUser, Group);
-  chmod(ServerRoot, 0755);
-
-  snprintf(temp, sizeof(temp), "%s/ppd", ServerRoot);
-  if (access(temp, 0))
-    mkdir(temp, 0755);
-  chown(temp, RunUser, Group);
-  chmod(temp, 0755);
-
-  snprintf(temp, sizeof(temp), "%s/ssl", ServerRoot);
-  if (access(temp, 0))
-    mkdir(temp, 0700);
-  chown(temp, RunUser, Group);
-  chmod(temp, 0700);
+  if (check_permissions(CacheDir, NULL, 0775, RunUser, Group, 1, 1) < 0 ||
+      check_permissions(StateDir, NULL, 0755, RunUser, Group, 1, 1) < 0 ||
+      check_permissions(StateDir, "certs", RunUser ? 0711 : 0511, User,
+                       SystemGroupIDs[0], 1, 1) < 0 ||
+      check_permissions(ServerRoot, NULL, 0755, RunUser, Group, 1, 0) < 0 ||
+      check_permissions(ServerRoot, "ppd", 0755, RunUser, Group, 1, 1) < 0 ||
+      check_permissions(ServerRoot, "ssl", 0700, RunUser, Group, 1, 0) < 0 ||
+      check_permissions(ServerRoot, "cupsd.conf", ConfigFilePerm, RunUser,
+                        Group, 0, 0) < 0 ||
+      check_permissions(ServerRoot, "classes.conf", 0600, RunUser, Group,
+                        0, 0) < 0 ||
+      check_permissions(ServerRoot, "printers.conf", 0600, RunUser, Group,
+                        0, 0) < 0 ||
+      check_permissions(ServerRoot, "passwd.md5", 0600, User, Group, 0, 0) < 0)
+    return (0);
 
-  snprintf(temp, sizeof(temp), "%s/cupsd.conf", ServerRoot);
-  chown(temp, RunUser, Group);
-  chmod(temp, ConfigFilePerm);
+ /*
+  * Update TempDir to the default if it hasn't been set already...
+  */
 
-  snprintf(temp, sizeof(temp), "%s/classes.conf", ServerRoot);
-  chown(temp, RunUser, Group);
-  chmod(temp, 0600);
+  if (!TempDir)
+  {
+    if ((tmpdir = getenv("TMPDIR")) != NULL)
+    {
+     /*
+      * TMPDIR is defined, see if it is OK for us to use...
+      */
 
-  snprintf(temp, sizeof(temp), "%s/printers.conf", ServerRoot);
-  chown(temp, RunUser, Group);
-  chmod(temp, 0600);
+      if (stat(tmpdir, &tmpinfo))
+        cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to access TMPDIR (%s): %s",
+                       tmpdir, strerror(errno));
+      else if (!S_ISDIR(tmpinfo.st_mode))
+        cupsdLogMessage(CUPSD_LOG_ERROR, "TMPDIR (%s) is not a directory!",
+                       tmpdir);
+      else if ((tmpinfo.st_uid != User || !(tmpinfo.st_mode & S_IWUSR)) &&
+               (tmpinfo.st_gid != Group || !(tmpinfo.st_mode & S_IWGRP)) &&
+              !(tmpinfo.st_mode & S_IWOTH))
+        cupsdLogMessage(CUPSD_LOG_ERROR,
+                       "TMPDIR (%s) has the wrong permissions!", tmpdir);
+      else
+        cupsdSetString(&TempDir, tmpdir);
+    }
 
-  snprintf(temp, sizeof(temp), "%s/passwd.md5", ServerRoot);
-  chown(temp, User, Group);
-  chmod(temp, 0600);
+    if (!TempDir)
+    {
+      cupsdLogMessage(CUPSD_LOG_INFO, "Using default TempDir of %s/tmp...",
+                     RequestRoot);
+      cupsdSetStringf(&TempDir, "%s/tmp", RequestRoot);
+    }
+  }
 
  /*
   * Make sure the request and temporary directories have the right
   * permissions...
   */
 
-  chown(RequestRoot, RunUser, Group);
-  chmod(RequestRoot, 0710);
+  if (check_permissions(RequestRoot, NULL, 0710, RunUser, Group, 1, 1) < 0)
+    return (0);
 
   if (!strncmp(TempDir, RequestRoot, strlen(RequestRoot)) ||
       access(TempDir, 0))
@@ -675,11 +715,8 @@ cupsdReadConfiguration(void)
     * is under the spool directory or does not exist...
     */
 
-    if (access(TempDir, 0))
-      mkdir(TempDir, 01770);
-
-    chown(TempDir, RunUser, Group);
-    chmod(TempDir, 01770);
+    if (check_permissions(TempDir, NULL, 01770, RunUser, Group, 1, 1) < 0)
+      return (0);
   }
 
   if (!strncmp(TempDir, RequestRoot, strlen(RequestRoot)))
@@ -738,16 +775,8 @@ cupsdReadConfiguration(void)
     MaxClients = MaxFDs / 3;
   }
 
-  if ((Clients = calloc(sizeof(cupsd_client_t), MaxClients)) == NULL)
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "cupsdReadConfiguration: Unable to allocate memory for %d clients: %s",
-                    MaxClients, strerror(errno));
-    exit(1);
-  }
-  else
-    cupsdLogMessage(CUPSD_LOG_INFO, "Configured for up to %d clients.",
-                    MaxClients);
+  cupsdLogMessage(CUPSD_LOG_INFO, "Configured for up to %d clients.",
+                  MaxClients);
 
  /*
   * Check the MaxActiveJobs setting; limit to 1/3 the available
@@ -757,7 +786,7 @@ cupsdReadConfiguration(void)
   if (MaxActiveJobs > (MaxFDs / 3))
     MaxActiveJobs = MaxFDs / 3;
 
-  if (Classification && strcasecmp(Classification, "none") == 0)
+  if (Classification && !strcasecmp(Classification, "none"))
     cupsdClearString(&Classification);
 
   if (Classification)
@@ -777,6 +806,24 @@ cupsdReadConfiguration(void)
                   "Allowing up to %d client connections per host.",
                   MaxClientsPerHost);
 
+ /*
+  * Make sure that BrowseTimeout is at least twice the interval...
+  */
+
+  if (BrowseTimeout < (2 * BrowseInterval) || BrowseTimeout <= 0)
+  {
+    cupsdLogMessage(CUPSD_LOG_ALERT, "Invalid BrowseTimeout value %d!",
+                    BrowseTimeout);
+
+    if (BrowseInterval)
+      BrowseTimeout = BrowseInterval * 2;
+    else
+      BrowseTimeout = DEFAULT_TIMEOUT;
+
+    cupsdLogMessage(CUPSD_LOG_ALERT, "Reset BrowseTimeout to %d!",
+                    BrowseTimeout);
+  }
+
  /*
   * Update the default policy, as needed...
   */
@@ -796,6 +843,8 @@ cupsdReadConfiguration(void)
       cupsdLogMessage(CUPSD_LOG_ERROR, "Default policy \"%s\" not found!",
                       DefaultPolicy);
 
+    cupsdSetString(&DefaultPolicy, "default");
+
     if ((DefaultPolicyPtr = cupsdFindPolicy("default")) != NULL)
       cupsdLogMessage(CUPSD_LOG_INFO,
                       "Using policy \"default\" as the default!");
@@ -901,9 +950,11 @@ cupsdReadConfiguration(void)
     }
   }
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG,"NumPolicies=%d", NumPolicies);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdReadConfiguration: NumPolicies=%d",
+                  NumPolicies);
   for (i = 0; i < NumPolicies; i ++)
-    cupsdLogMessage(CUPSD_LOG_DEBUG, "Policies[%d]=\"%s\"", i,
+    cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                    "cupsdReadConfiguration: Policies[%d]=\"%s\"", i,
                     Policies[i]->name);
 
  /*
@@ -915,6 +966,11 @@ cupsdReadConfiguration(void)
       !old_serverroot || !ServerRoot || strcmp(old_serverroot, ServerRoot) ||
       !old_requestroot || !RequestRoot || strcmp(old_requestroot, RequestRoot))
   {
+    mime_type_t        *type;                  /* Current type */
+    char       mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE];
+                                       /* MIME type name */
+
+
     cupsdLogMessage(CUPSD_LOG_INFO, "Full reload is required.");
 
    /*
@@ -934,7 +990,7 @@ cupsdReadConfiguration(void)
     if (NumMimeTypes)
     {
       for (i = 0; i < NumMimeTypes; i ++)
-       free((void *)MimeTypes[i]);
+       _cupsStrFree(MimeTypes[i]);
 
       free(MimeTypes);
     }
@@ -956,29 +1012,52 @@ cupsdReadConfiguration(void)
 
     cupsdLogMessage(CUPSD_LOG_INFO,
                     "Loaded MIME database from \'%s\': %d types, %d filters...",
-                    ServerRoot, MimeDatabase->num_types, MimeDatabase->num_filters);
+                    ServerRoot, mimeNumTypes(MimeDatabase),
+                   mimeNumFilters(MimeDatabase));
 
    /*
     * Create a list of MIME types for the document-format-supported
     * attribute...
     */
 
-    NumMimeTypes = MimeDatabase->num_types;
+    NumMimeTypes = mimeNumTypes(MimeDatabase);
     if (!mimeType(MimeDatabase, "application", "octet-stream"))
       NumMimeTypes ++;
 
     MimeTypes = calloc(NumMimeTypes, sizeof(const char *));
 
-    for (i = 0; i < MimeDatabase->num_types; i ++)
+    for (i = 0, type = mimeFirstType(MimeDatabase);
+         type;
+        i ++, type = mimeNextType(MimeDatabase))
     {
-      snprintf(type, sizeof(type), "%s/%s", MimeDatabase->types[i]->super,
-               MimeDatabase->types[i]->type);
+      snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type);
 
-      MimeTypes[i] = strdup(type);
+      MimeTypes[i] = _cupsStrAlloc(mimetype);
     }
 
     if (i < NumMimeTypes)
-      MimeTypes[i] = strdup("application/octet-stream");
+      MimeTypes[i] = _cupsStrAlloc("application/octet-stream");
+
+    if (LogLevel == CUPSD_LOG_DEBUG2)
+    {
+      mime_filter_t    *filter;        /* Current filter */
+
+
+      for (type = mimeFirstType(MimeDatabase);
+           type;
+          type = mimeNextType(MimeDatabase))
+       cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdReadConfiguration: type %s/%s",
+                       type->super, type->type);
+
+      for (filter = mimeFirstFilter(MimeDatabase);
+           filter;
+          filter = mimeNextFilter(MimeDatabase))
+       cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                       "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
+                       filter->src->super, filter->src->type,
+                       filter->dst->super, filter->dst->type,
+                       filter->cost, filter->filter);
+    }
 
    /*
     * Load banners...
@@ -1039,13 +1118,114 @@ cupsdReadConfiguration(void)
   cupsdClearString(&old_serverroot);
   cupsdClearString(&old_requestroot);
 
+  return (1);
+}
+
+
+/*
+ * 'check_permissions()' - Fix the mode and ownership of a file or directory.
+ */
+
+static int                             /* O - 0 on success, -1 on error, 1 on warning */
+check_permissions(const char *filename,        /* I - File/directory name */
+                  const char *suffix,  /* I - Additional file/directory name */
+                  int        mode,     /* I - Permissions */
+                 int        user,      /* I - Owner */
+                 int        group,     /* I - Group */
+                 int        is_dir,    /* I - 1 = directory, 0 = file */
+                 int        create_dir)/* I - 1 = create directory, 0 = not */
+{
+  int          dir_created = 0;        /* Did we create a directory? */
+  char         pathname[1024];         /* File name with prefix */
+  struct stat  fileinfo;               /* Stat buffer */
+
+
  /*
-  * Startup the server and return...
+  * Prepend the given root to the filename before testing it...
   */
 
-  cupsdStartServer();
+  if (suffix)
+  {
+    snprintf(pathname, sizeof(pathname), "%s/%s", filename, suffix);
+    filename = pathname;
+  }
 
-  return (1);
+ /*
+  * See if we can stat the file/directory...
+  */
+
+  if (stat(filename, &fileinfo))
+  {
+    if (errno == ENOENT && create_dir)
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR, "Creating missing directory \"%s\"",
+                      filename);
+
+      if (mkdir(filename, mode))
+      {
+        cupsdLogMessage(CUPSD_LOG_ERROR,
+                       "Unable to create directory \"%s\" - %s", filename,
+                       strerror(errno));
+        return (-1);
+      }
+
+      dir_created = 1;
+    }
+    else
+      return (create_dir ? -1 : 1);
+  }
+
+ /*
+  * Make sure it's a regular file...
+  */
+
+  if (!dir_created && !is_dir && !S_ISREG(fileinfo.st_mode))
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is not a regular file!", filename);
+    return (-1);
+  }
+
+  if (!dir_created && is_dir && !S_ISDIR(fileinfo.st_mode))
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is not a directory!", filename);
+    return (-1);
+  }
+
+ /*
+  * Fix owner, group, and mode as needed...
+  */
+
+  if (dir_created || fileinfo.st_uid != user || fileinfo.st_gid != group)
+  {
+    cupsdLogMessage(CUPSD_LOG_WARN, "Repairing ownership of \"%s\"", filename);
+
+    if (chown(filename, user, group))
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "Unable to change ownership of \"%s\" - %s", filename,
+                     strerror(errno));
+      return (1);
+    }
+  }
+
+  if (dir_created || (fileinfo.st_mode & 07777) != mode)
+  {
+    cupsdLogMessage(CUPSD_LOG_WARN, "Repairing access permissions of \"%s\"", filename);
+
+    if (chmod(filename, mode))
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "Unable to change permissions of \"%s\" - %s", filename,
+                     strerror(errno));
+      return (1);
+    }
+  }
+
+ /*
+  * Everything is OK...
+  */
+
+  return (0);
 }
 
 
@@ -1142,33 +1322,14 @@ get_addr_and_mask(const char *value,    /* I - String from config file */
   const char   *maskval,               /* Pointer to start of mask value */
                *ptr,                   /* Pointer into value */
                *ptr2;                  /* ... */
-  static unsigned netmasks[4][4] =     /* Standard IPv4 netmasks... */
-  {
-    { 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000 },
-    { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
-    { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffff00 },
-    { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
-  };
-#ifdef AF_INET6
-  static unsigned netmasks6[8][4] =    /* Standard IPv6 netmasks... */
-  {
-    { 0xffff0000, 0x00000000, 0x00000000, 0x00000000 },
-    { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
-    { 0xffffffff, 0xffff0000, 0x00000000, 0x00000000 },
-    { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
-    { 0xffffffff, 0xffffffff, 0xffff0000, 0x00000000 },
-    { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
-    { 0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000 },
-    { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
-  };
-#endif /* AF_INET6 */
 
 
  /*
   * Get the address...
   */
 
-  memset(ip, 0, sizeof(unsigned) * 4);
+  ip[0]   = ip[1]   = ip[2]   = ip[3]   = 0x00000000;
+  mask[0] = mask[1] = mask[2] = mask[3] = 0xffffffff;
 
   if ((maskval = strchr(value, '/')) != NULL)
     maskval ++;
@@ -1199,6 +1360,7 @@ get_addr_and_mask(const char *value,      /* I - String from config file */
             ptr2 = strchr(ptr2 + 1, ':'), j ++);
 
         i = 7 - j;
+       ptr ++;
       }
       else if (isxdigit(*ptr & 255))
       {
@@ -1208,9 +1370,9 @@ get_addr_and_mask(const char *value,      /* I - String from config file */
          return (0);
 
         if (i & 1)
-          ip[i] |= ipval;
+          ip[i / 2] |= ipval;
        else
-          ip[i] |= ipval << 16;
+          ip[i / 2] |= ipval << 16;
       }
       else
         return (0);
@@ -1219,7 +1381,10 @@ get_addr_and_mask(const char *value,     /* I - String from config file */
         ptr ++;
     }
 
-    ipcount = i;
+    if (*ptr != ']')
+      return (0);
+
+    ptr ++;
 
     if (*ptr && *ptr != '/')
       return (0);
@@ -1231,70 +1396,55 @@ get_addr_and_mask(const char *value,    /* I - String from config file */
     * Parse dotted-decimal IPv4 address...
     */
 
-    family  = AF_INET;
-    ipcount = sscanf(value, "%u.%u.%u.%u", ip + 0, ip + 1, ip + 2, ip + 3);
+    unsigned val[4];                   /* IPv4 address values */
 
-    ip[3] |= ((((ip[0] << 8) | ip[1]) << 8) | ip[2]) << 8;
-    ip[0] = ip[1] = ip[2] = 0;
-  }
 
-  if (*maskval)
-  {
+    family  = AF_INET;
+    ipcount = sscanf(value, "%u.%u.%u.%u", val + 0, val + 1, val + 2, val + 3);
+
    /*
-    * Get the netmask value(s)...
+    * Range check the IP numbers...
     */
 
-    memset(mask, 0, sizeof(unsigned) * 4);
+    for (i = 0; i < ipcount; i ++)
+      if (val[i] > 255)
+        return (0);
 
-#ifdef AF_INET6
-    if (*maskval == '[')
-    {
-     /*
-      * Get hexadecimal mask value...
-      */
+   /*
+    * Make sure the trailing values are zeroed, as some C libraries like
+    * glibc apparently like to fill the unused arguments with garbage...
+    */
 
-      for (i = 0, ptr = maskval + 1; *ptr && i < 8; i ++)
-      {
-       if (*ptr == ']')
-         break;
-       else if (!strncmp(ptr, "::", 2))
-       {
-          for (ptr2 = strchr(ptr + 2, ':'), j = 0;
-              ptr2;
-              ptr2 = strchr(ptr2 + 1, ':'), j ++);
+    for (i = ipcount; i < 4; i ++)
+      val[i] = 0;
 
-          i = 7 - j;
-       }
-       else if (isxdigit(*ptr & 255))
-       {
-          ipval = strtoul(ptr, (char **)&ptr, 16);
+   /*
+    * Merge everything into a 32-bit IPv4 address in ip[3]...
+    */
 
-         if (ipval > 0xffff)
-           return (0);
+    ip[3] = (((((val[0] << 8) | val[1]) << 8) | val[2]) << 8) | val[3];
 
-          if (i & 1)
-            mask[i] |= ipval;
-         else
-            mask[i] |= ipval << 16;
-       }
-       else
-          return (0);
+    if (ipcount < 4)
+      mask[3] = (0xffffffff << (32 - 8 * ipcount)) & 0xffffffff;
+  }
 
-        while (*ptr == ':')
-          ptr ++;
-      }
+  if (*maskval)
+  {
+   /*
+    * Get the netmask value(s)...
+    */
+
+    memset(mask, 0, sizeof(unsigned) * 4);
 
-      if (*ptr)
-       return (0);
-    }
-    else
-#endif /* AF_INET6 */
     if (strchr(maskval, '.'))
     {
      /*
       * Get dotted-decimal mask...
       */
 
+      if (family != AF_INET)
+        return (0);
+
       if (sscanf(maskval, "%u.%u.%u.%u", mask + 0, mask + 1, mask + 2, mask + 3) != 4)
         return (0);
 
@@ -1312,6 +1462,9 @@ get_addr_and_mask(const char *value,      /* I - String from config file */
 #ifdef AF_INET6
       if (family == AF_INET6)
       {
+        if (i > 128)
+         return (0);
+
         i = 128 - i;
 
        if (i <= 96)
@@ -1343,29 +1496,24 @@ get_addr_and_mask(const char *value,    /* I - String from config file */
       else
 #endif /* AF_INET6 */
       {
-        i = 32 - i;
+        if (i > 32)
+         return (0);
 
         mask[0] = 0xffffffff;
         mask[1] = 0xffffffff;
         mask[2] = 0xffffffff;
 
-       if (i > 0)
-          mask[3] = (0xffffffff << i) & 0xffffffff;
+       if (i < 32)
+          mask[3] = (0xffffffff << (32 - i)) & 0xffffffff;
        else
          mask[3] = 0xffffffff;
       }
     }
   }
-#ifdef AF_INET6
-  else if (family == AF_INET6)
-    memcpy(mask, netmasks6[ipcount - 1], sizeof(unsigned) * 4);
-#endif /* AF_INET6 */
-  else
-    memcpy(mask, netmasks[ipcount - 1], sizeof(unsigned) * 4);
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2,
                   "get_addr_and_mask(value=\"%s\", "
-                  "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x]",
+                  "ip=[%08x:%08x:%08x:%08x], mask=[%08x:%08x:%08x:%08x])",
              value, ip[0], ip[1], ip[2], ip[3], mask[0], mask[1], mask[2],
             mask[3]);
 
@@ -1499,7 +1647,12 @@ parse_aaa(cupsd_location_t *loc, /* I - Location */
       else
        cupsdDenyIP(loc, ones, zeros);
     }
+#ifdef AF_INET6
+    else if (value[0] == '*' || value[0] == '.' || 
+             (!isdigit(value[0] & 255) && value[0] != '['))
+#else
     else if (value[0] == '*' || value[0] == '.' || !isdigit(value[0] & 255))
+#endif /* AF_INET6 */
     {
      /*
       * Host or domain name...
@@ -1564,6 +1717,16 @@ parse_aaa(cupsd_location_t *loc, /* I - Location */
       if (loc->level == AUTH_ANON)
        loc->level = AUTH_USER;
     }
+#ifdef HAVE_GSSAPI
+    else if (!strcasecmp(value, "kerberos") ||
+            !strcasecmp(value, "gssapi"))
+    {
+      loc->type = AUTH_KERBEROS;
+
+      if (loc->level == AUTH_ANON)
+       loc->level = AUTH_USER;
+    }
+#endif /* HAVE_GSSAPI */
     else
     {
       cupsdLogMessage(CUPSD_LOG_WARN,
@@ -1672,6 +1835,20 @@ parse_aaa(cupsd_location_t *loc, /* I - Location */
       while (isspace(*value & 255))
        value ++;
 
+#ifdef HAVE_AUTHORIZATION_H
+      if (!strncmp(value, "@AUTHKEY(", 9))
+      {
+       /*
+       * Grab "@AUTHKEY(name)" value...
+       */
+
+        for (valptr = value + 9; *valptr != ')' && *valptr; valptr ++);
+
+       if (*valptr)
+         *valptr++ = '\0';
+      }
+      else
+#endif /* HAVE_AUTHORIZATION_H */
       if (*value == '\"' || *value == '\'')
       {
        /*
@@ -1719,6 +1896,148 @@ parse_aaa(cupsd_location_t *loc,        /* I - Location */
 }
 
 
+/*
+ * 'parse_groups()' - Parse system group names in a string.
+ */
+
+static int                             /* O - 1 on success, 0 on failure */
+parse_groups(const char *s)            /* I - Space-delimited groups */
+{
+  int          status;                 /* Return status */
+  char         value[1024],            /* Value string */
+               *valstart,              /* Pointer into value */
+               *valend,                /* End of value */
+               quote;                  /* Quote character */
+  struct group *group;                 /* Group */
+
+
+ /*
+  * Make a copy of the string and parse out the groups...
+  */
+
+  strlcpy(value, s, sizeof(value));
+
+  status   = 1;
+  valstart = value;
+
+  while (*valstart && NumSystemGroups < MAX_SYSTEM_GROUPS)
+  {
+    if (*valstart == '\'' || *valstart == '\"')
+    {
+     /*
+      * Scan quoted name...
+      */
+
+      quote = *valstart++;
+
+      for (valend = valstart; *valend; valend ++)
+       if (*valend == quote)
+         break;
+    }
+    else
+    {
+     /*
+      * Scan space or comma-delimited name...
+      */
+
+      for (valend = valstart; *valend; valend ++)
+       if (isspace(*valend) || *valend == ',')
+         break;
+    }
+
+    if (*valend)
+      *valend++ = '\0';
+
+    group = getgrnam(valstart);
+    if (group)
+    {
+      cupsdSetString(SystemGroups + NumSystemGroups, valstart);
+      SystemGroupIDs[NumSystemGroups] = group->gr_gid;
+
+      NumSystemGroups ++;
+    }
+    else
+      status = 0;
+
+    endgrent();
+
+    valstart = valend;
+
+    while (*valstart == ',' || isspace(*valstart))
+      valstart ++;
+  }
+
+  return (status);
+}
+
+
+/*
+ * 'parse_protocols()' - Parse browse protocols in a string.
+ */
+
+static int                             /* O - Browse protocol bits */
+parse_protocols(const char *s)         /* I - Space-delimited protocols */
+{
+  int  protocols;                      /* Browse protocol bits */
+  char value[1024],                    /* Value string */
+       *valstart,                      /* Pointer into value */
+       *valend;                        /* End of value */
+
+
+ /*
+  * Empty protocol line yields NULL pointer...
+  */
+
+  if (!s)
+    return (0);
+
+ /*
+  * Loop through the value string,...
+  */
+
+  strlcpy(value, s, sizeof(value));
+
+  protocols = 0;
+
+  for (valstart = value; *valstart;)
+  {
+   /*
+    * Get the current space/comma-delimited protocol name...
+    */
+
+    for (valend = valstart; *valend; valend ++)
+      if (isspace(*valend & 255) || *valend == ',')
+       break;
+
+    if (*valend)
+      *valend++ = '\0';
+
+   /*
+    * Add the protocol to the bitmask...
+    */
+
+    if (!strcasecmp(valstart, "cups"))
+      protocols |= BROWSE_CUPS;
+    else if (!strcasecmp(valstart, "slp"))
+      protocols |= BROWSE_SLP;
+    else if (!strcasecmp(valstart, "ldap"))
+      protocols |= BROWSE_LDAP;
+    else if (!strcasecmp(valstart, "dnssd") || !strcasecmp(valstart, "bonjour"))
+      protocols |= BROWSE_DNSSD;
+    else if (!strcasecmp(valstart, "all"))
+      protocols |= BROWSE_ALL;
+    else if (strcasecmp(valstart, "none"))
+      return (-1);
+
+    for (valstart = valend; *valstart; valstart ++)
+      if (!isspace(*valstart & 255) || *valstart != ',')
+       break;
+  }
+
+  return (protocols);
+}
+
+
 /*
  * 'read_configuration()' - Read a configuration file.
  */
@@ -1736,8 +2055,7 @@ read_configuration(cups_file_t *fp)       /* I - File to read from */
                                        /* Temporary buffer 2 for value */
                        *ptr,           /* Pointer into line/temp */
                        *value,         /* Pointer to value */
-                       *valueptr,      /* Pointer into value */
-                       quote;          /* Quote character */
+                       *valueptr;      /* Pointer into value */
   int                  valuelen;       /* Length of value */
   cupsd_var_t          *var;           /* Current variable */
   http_addrlist_t      *addrlist,      /* Address list */
@@ -1888,12 +2206,10 @@ read_configuration(cups_file_t *fp)     /* I - File to read from */
         * Allocate another listener...
        */
 
-       if (NumListeners == 0)
-          lis = malloc(sizeof(cupsd_listener_t));
-       else
-          lis = realloc(Listeners, (NumListeners + 1) * sizeof(cupsd_listener_t));
+        if (!Listeners)
+         Listeners = cupsArrayNew(NULL, NULL);
 
-       if (!lis)
+       if (!Listeners)
        {
           cupsdLogMessage(CUPSD_LOG_ERROR,
                          "Unable to allocate %s at line %d - %s.",
@@ -1901,21 +2217,30 @@ read_configuration(cups_file_t *fp)     /* I - File to read from */
           break;
        }
 
-       Listeners = lis;
-       lis      += NumListeners;
+        if ((lis = calloc(1, sizeof(cupsd_listener_t))) == NULL)
+       {
+          cupsdLogMessage(CUPSD_LOG_ERROR,
+                         "Unable to allocate %s at line %d - %s.",
+                         line, linenum, strerror(errno));
+          break;
+       }
+
+        cupsArrayAdd(Listeners, lis);
 
        /*
         * Copy the current address and log it...
        */
 
-       memset(lis, 0, sizeof(cupsd_listener_t));
        memcpy(&(lis->address), &(addr->addr), sizeof(lis->address));
+       lis->fd = -1;
 
 #ifdef HAVE_SSL
         if (!strcasecmp(line, "SSLPort") || !strcasecmp(line, "SSLListen"))
           lis->encryption = HTTP_ENCRYPT_ALWAYS;
 #endif /* HAVE_SSL */
 
+       httpAddrString(&lis->address, temp, sizeof(temp));
+
 #ifdef AF_INET6
         if (lis->address.addr.sa_family == AF_INET6)
           cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s:%d (IPv6)", temp,
@@ -1929,8 +2254,6 @@ read_configuration(cups_file_t *fp)       /* I - File to read from */
 #endif /* AF_LOCAL */
        cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s:%d (IPv4)", temp,
                         ntohs(lis->address.ipv4.sin_port));
-
-       NumListeners ++;
       }
 
      /*
@@ -2046,66 +2369,25 @@ read_configuration(cups_file_t *fp)     /* I - File to read from */
              !strcasecmp(line, "BrowseRemoteProtocols"))
     {
      /*
-      * "BrowseProtocol name [... name]"
+      * "BrowseProtocols name [... name]"
+      * "BrowseLocalProtocols name [... name]"
+      * "BrowseRemoteProtocols name [... name]"
       */
 
-      if (strcasecmp(line, "BrowseLocalProtocols"))
-        BrowseRemoteProtocols = 0;
-      if (strcasecmp(line, "BrowseRemoteProtocols"))
-        BrowseLocalProtocols = 0;
+      int protocols = parse_protocols(value);
 
-      for (; *value;)
+      if (protocols < 0)
       {
-        for (valuelen = 0; value[valuelen]; valuelen ++)
-         if (isspace(value[valuelen]) || value[valuelen] == ',')
-           break;
-
-        if (value[valuelen])
-        {
-         value[valuelen] = '\0';
-         valuelen ++;
-       }
-
-        if (!strcasecmp(value, "cups"))
-       {
-         if (strcasecmp(line, "BrowseLocalProtocols"))
-           BrowseRemoteProtocols |= BROWSE_CUPS;
-         if (strcasecmp(line, "BrowseRemoteProtocols"))
-           BrowseLocalProtocols |= BROWSE_CUPS;
-       }
-        else if (!strcasecmp(value, "slp"))
-       {
-         if (strcasecmp(line, "BrowseLocalProtocols"))
-           BrowseRemoteProtocols |= BROWSE_SLP;
-         if (strcasecmp(line, "BrowseRemoteProtocols"))
-           BrowseLocalProtocols |= BROWSE_SLP;
-       }
-        else if (!strcasecmp(value, "ldap"))
-       {
-         if (strcasecmp(line, "BrowseLocalProtocols"))
-           BrowseRemoteProtocols |= BROWSE_LDAP;
-         if (strcasecmp(line, "BrowseRemoteProtocols"))
-           BrowseLocalProtocols |= BROWSE_LDAP;
-       }
-        else if (!strcasecmp(value, "all"))
-       {
-         if (strcasecmp(line, "BrowseLocalProtocols"))
-           BrowseRemoteProtocols |= BROWSE_ALL;
-         if (strcasecmp(line, "BrowseRemoteProtocols"))
-           BrowseLocalProtocols |= BROWSE_ALL;
-       }
-       else
-       {
-         cupsdLogMessage(CUPSD_LOG_ERROR,
-                         "Unknown browse protocol \"%s\" on line %d.",
-                         value, linenum);
-          break;
-       }
-
-        for (value += valuelen; *value; value ++)
-         if (!isspace(*value) || *value != ',')
-           break;
+       cupsdLogMessage(CUPSD_LOG_ERROR,
+                       "Unknown browse protocol \"%s\" on line %d.",
+                       value, linenum);
+        break;
       }
+
+      if (strcasecmp(line, "BrowseLocalProtocols"))
+        BrowseRemoteProtocols = protocols;
+      if (strcasecmp(line, "BrowseRemoteProtocols"))
+        BrowseLocalProtocols = protocols;
     }
     else if (!strcasecmp(line, "BrowseAllow") ||
              !strcasecmp(line, "BrowseDeny"))
@@ -2173,7 +2455,12 @@ read_configuration(cups_file_t *fp)      /* I - File to read from */
          else
            cupsdDenyIP(location, ones, zeros);
        }
-       else if (value[0] == '*' || value[0] == '.' || !isdigit(value[0]))
+#ifdef AF_INET6
+       else if (value[0] == '*' || value[0] == '.' || 
+                (!isdigit(value[0] & 255) && value[0] != '['))
+#else
+       else if (value[0] == '*' || value[0] == '.' || !isdigit(value[0] & 255))
+#endif /* AF_INET6 */
        {
         /*
           * Host or domain name...
@@ -2257,7 +2544,12 @@ read_configuration(cups_file_t *fp)      /* I - File to read from */
       *    nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
       */
 
-      if (value[0] == '*' || value[0] == '.' || !isdigit(value[0]))
+#ifdef AF_INET6
+      if (value[0] == '*' || value[0] == '.' || 
+          (!isdigit(value[0] & 255) && value[0] != '['))
+#else
+      if (value[0] == '*' || value[0] == '.' || !isdigit(value[0] & 255))
+#endif /* AF_INET6 */
       {
        /*
         * Host or domain name...
@@ -2351,7 +2643,7 @@ read_configuration(cups_file_t *fp)       /* I - File to read from */
            strlcpy(temp2, relay->from.mask.name.name, sizeof(temp2));
   
          cupsdLogMessage(CUPSD_LOG_INFO, "Relaying from %s to %s:%d (IPv4)",
-                         temp, temp2, ntohs(relay->to.ipv4.sin_port));
+                         temp2, temp, ntohs(relay->to.ipv4.sin_port));
   
          NumRelays ++;
        }
@@ -2444,6 +2736,10 @@ read_configuration(cups_file_t *fp)      /* I - File to read from */
        DefaultAuthType = AUTH_DIGEST;
       else if (!strcasecmp(value, "basicdigest"))
        DefaultAuthType = AUTH_BASICDIGEST;
+#ifdef HAVE_GSSAPI
+      else if (!strcasecmp(value, "kerberos"))
+        DefaultAuthType = AUTH_KERBEROS;
+#endif /* HAVE_GSSAPI */
       else
       {
        cupsdLogMessage(CUPSD_LOG_WARN,
@@ -2452,6 +2748,41 @@ read_configuration(cups_file_t *fp)      /* I - File to read from */
        return (0);
       }
     }
+#ifdef HAVE_SSL
+    else if (!strcasecmp(line, "DefaultEncryption"))
+    {
+     /*
+      * DefaultEncryption {Never,IfRequested,Required}
+      */
+
+      if (!value || !strcasecmp(value, "never"))
+       DefaultEncryption = HTTP_ENCRYPT_NEVER;
+      else if (!strcasecmp(value, "required"))
+       DefaultEncryption = HTTP_ENCRYPT_REQUIRED;
+      else if (!strcasecmp(value, "ifrequested"))
+       DefaultEncryption = HTTP_ENCRYPT_IF_REQUESTED;
+      else
+      {
+       cupsdLogMessage(CUPSD_LOG_WARN,
+                       "Unknown default encryption %s on line %d.",
+                       value, linenum);
+       return (0);
+      }
+    }
+#endif /* HAVE_SSL */
+#ifdef HAVE_GSSAPI
+    else if (!strcasecmp(line, "Krb5Keytab"))
+    {
+      cupsdSetStringf(&Krb5Keytab, "KRB5_KTNAME=%s", value);
+      putenv(Krb5Keytab);
+
+#  ifdef HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY
+      gsskrb5_register_acceptor_identity(value);
+#  else
+      cupsdSetEnv("KRB5_KTNAME", value);
+#  endif /* HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY */
+    }
+#endif /* HAVE_GSSAPI */
     else if (!strcasecmp(line, "User"))
     {
      /*
@@ -2523,60 +2854,13 @@ read_configuration(cups_file_t *fp)     /* I - File to read from */
     else if (!strcasecmp(line, "SystemGroup"))
     {
      /*
-      * System (admin) group(s)...
+      * SystemGroup (admin) group(s)...
       */
 
-      for (i = NumSystemGroups; *value && i < MAX_SYSTEM_GROUPS;)
-      {
-        if (*value == '\'' || *value == '\"')
-       {
-        /*
-         * Scan quoted name...
-         */
-
-         quote = *value++;
-
-         for (valueptr = value; *valueptr; valueptr ++)
-           if (*valueptr == quote)
-             break;
-       }
-       else
-       {
-        /*
-         * Scan space or comma-delimited name...
-         */
-
-          for (valueptr = value; *valueptr; valueptr ++)
-           if (isspace(*valueptr) || *valueptr == ',')
-             break;
-        }
-
-        if (*valueptr)
-          *valueptr++ = '\0';
-
-        group = getgrnam(value);
-        if (group)
-       {
-          cupsdSetString(SystemGroups + i, value);
-         SystemGroupIDs[i] = group->gr_gid;
-
-         i ++;
-       }
-       else
-         cupsdLogMessage(CUPSD_LOG_ERROR,
-                         "Unknown SystemGroup \"%s\" on line %d, ignoring!",
-                         value, linenum);
-
-        endgrent();
-
-        value = valueptr;
-
-        while (*value == ',' || isspace(*value))
-         value ++;
-      }
-
-      if (i)
-        NumSystemGroups = i;
+      if (!parse_groups(value))
+       cupsdLogMessage(CUPSD_LOG_ERROR,
+                       "Unknown SystemGroup \"%s\" on line %d, ignoring!",
+                       value, linenum);
     }
     else if (!strcasecmp(line, "HostNameLookups"))
     {
@@ -2654,7 +2938,7 @@ read_configuration(cups_file_t *fp)       /* I - File to read from */
       else if (!strcasecmp(value, "Major"))
        cupsdSetString(&ServerHeader, "CUPS/1");
       else if (!strcasecmp(value, "Minor"))
-       cupsdSetString(&ServerHeader, "CUPS/1.1");
+       cupsdSetString(&ServerHeader, "CUPS/1.2");
       else if (!strcasecmp(value, "Minimal"))
        cupsdSetString(&ServerHeader, CUPS_MINIMAL);
       else if (!strcasecmp(value, "OS"))
@@ -2741,6 +3025,11 @@ read_configuration(cups_file_t *fp)      /* I - File to read from */
       switch (var->type)
       {
         case CUPSD_VARTYPE_INTEGER :
+           if (!value)
+             cupsdLogMessage(CUPSD_LOG_ERROR,
+                             "Missing integer value for %s on line %d!",
+                             line, linenum);
+           else
            {
              int       n;              /* Number */
              char      *units;         /* Units */
@@ -2760,16 +3049,25 @@ read_configuration(cups_file_t *fp)     /* I - File to read from */
                  n *= 262144;
              }
 
-             *((int *)var->ptr) = n;
+              if (n < 0)
+               cupsdLogMessage(CUPSD_LOG_ERROR,
+                               "Bad negative integer value for %s on line %d!",
+                               line, linenum);
+             else
+               *((int *)var->ptr) = n;
            }
            break;
 
        case CUPSD_VARTYPE_BOOLEAN :
-           if (!strcasecmp(value, "true") ||
-               !strcasecmp(value, "on") ||
-               !strcasecmp(value, "enabled") ||
-               !strcasecmp(value, "yes") ||
-               atoi(value) != 0)
+           if (!value)
+             cupsdLogMessage(CUPSD_LOG_ERROR,
+                             "Missing boolean value for %s on line %d!",
+                             line, linenum);
+            else if (!strcasecmp(value, "true") ||
+                    !strcasecmp(value, "on") ||
+                    !strcasecmp(value, "enabled") ||
+                    !strcasecmp(value, "yes") ||
+                    atoi(value) != 0)
               *((int *)var->ptr) = TRUE;
            else if (!strcasecmp(value, "false") ||
                     !strcasecmp(value, "off") ||
@@ -3044,5 +3342,5 @@ read_policy(cups_file_t *fp,              /* I - Configuration file */
 
 
 /*
- * End of "$Id: conf.c 4903 2006-01-10 20:02:46Z mike $".
+ * End of "$Id: conf.c 6253 2007-02-10 18:48:40Z mike $".
  */