]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/conf.c
Merge changes from CUPS 1.4svn-r8628.
[thirdparty/cups.git] / scheduler / conf.c
index 26ca30b9624181ebedb026cbdaa56ab2fdd16aa3..0e915b4f74f3bbf98eb347f2737c10adb5373900 100644 (file)
  *
  * Contents:
  *
+ *   cupsdAddAlias()          - Add a host alias.
  *   cupsdCheckPermissions()  - Fix the mode and ownership of a file or
  *                              directory.
+ *   cupsdFreeAliases()       - Free all of the alias entries.
  *   cupsdReadConfiguration() - Read the cupsd.conf file.
  *   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_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.
@@ -116,12 +118,10 @@ static const cupsd_var_t  variables[] =
   { "FilterLimit",             &FilterLimit,           CUPSD_VARTYPE_INTEGER },
   { "FilterNice",              &FilterNice,            CUPSD_VARTYPE_INTEGER },
   { "FontPath",                        &FontPath,              CUPSD_VARTYPE_STRING },
-#ifdef HAVE_GSSAPI
-  { "GSSServiceName",          &GSSServiceName,        CUPSD_VARTYPE_STRING },
-#endif /* HAVE_GSSAPI */
   { "HideImplicitMembers",     &HideImplicitMembers,   CUPSD_VARTYPE_BOOLEAN },
   { "ImplicitClasses",         &ImplicitClasses,       CUPSD_VARTYPE_BOOLEAN },
   { "ImplicitAnyClasses",      &ImplicitAnyClasses,    CUPSD_VARTYPE_BOOLEAN },
+  { "JobKillDelay",            &JobKillDelay,          CUPSD_VARTYPE_INTEGER },
   { "JobRetryLimit",           &JobRetryLimit,         CUPSD_VARTYPE_INTEGER },
   { "JobRetryInterval",                &JobRetryInterval,      CUPSD_VARTYPE_INTEGER },
   { "KeepAliveTimeout",                &KeepAliveTimeout,      CUPSD_VARTYPE_INTEGER },
@@ -132,6 +132,7 @@ static const cupsd_var_t    variables[] =
 #endif /* HAVE_LAUNCHD */
   { "LimitRequestBody",                &MaxRequestSize,        CUPSD_VARTYPE_INTEGER },
   { "ListenBackLog",           &ListenBackLog,         CUPSD_VARTYPE_INTEGER },
+  { "LogDebugHistory",         &LogDebugHistory,       CUPSD_VARTYPE_INTEGER },
   { "LogFilePerm",             &LogFilePerm,           CUPSD_VARTYPE_INTEGER },
   { "LPDConfigFile",           &LPDConfigFile,         CUPSD_VARTYPE_STRING },
   { "MaxActiveJobs",           &MaxActiveJobs,         CUPSD_VARTYPE_INTEGER },
@@ -197,6 +198,7 @@ static const unsigned       zeros[4] =
 /*
  * Local functions...
  */
+
 static http_addrlist_t *get_address(const char *value, int defport);
 static int             get_addr_and_mask(const char *value, unsigned *ip,
                                          unsigned *mask);
@@ -210,6 +212,30 @@ static int         read_location(cups_file_t *fp, char *name, int linenum);
 static int             read_policy(cups_file_t *fp, char *name, int linenum);
 
 
+/*
+ * 'cupsdAddAlias()' - Add a host alias.
+ */
+
+void
+cupsdAddAlias(cups_array_t *aliases,   /* I - Array of aliases */
+              const char   *name)      /* I - Name to add */
+{
+  cupsd_alias_t        *a;                     /*  New alias */
+  size_t       namelen;                /* Length of name */
+
+
+  namelen = strlen(name);
+
+  if ((a = (cupsd_alias_t *)malloc(sizeof(cupsd_alias_t) + namelen)) == NULL)
+    return;
+
+  a->namelen = namelen;
+  strcpy(a->name, name);               /* OK since a->name is allocated */
+
+  cupsArrayAdd(aliases, a);
+}
+
+
 /*
  * 'cupsdCheckPermissions()' - Fix the mode and ownership of a file or directory.
  */
@@ -361,6 +387,25 @@ cupsdCheckPermissions(
 }
 
 
+/*
+ * 'cupsdFreeAliases()' - Free all of the alias entries.
+ */
+
+void
+cupsdFreeAliases(cups_array_t *aliases)        /* I - Array of aliases */
+{
+  cupsd_alias_t        *a;                     /* Current alias */
+
+
+  for (a = (cupsd_alias_t *)cupsArrayFirst(aliases);
+       a;
+       a = (cupsd_alias_t *)cupsArrayNext(aliases))
+    free(a);
+
+  cupsArrayDelete(aliases);
+}
+
+
 /*
  * 'cupsdReadConfiguration()' - Read the cupsd.conf file.
  */
@@ -379,6 +424,7 @@ cupsdReadConfiguration(void)
   struct group *group;                 /* Default group */
   char         *old_serverroot,        /* Old ServerRoot */
                *old_requestroot;       /* Old RequestRoot */
+  int          old_remote_port;        /* Old RemotePort */
   const char   *tmpdir;                /* TMPDIR environment variable */
   struct stat  tmpinfo;                /* Temporary directory info */
   cupsd_policy_t *p;                   /* Policy */
@@ -427,12 +473,16 @@ cupsdReadConfiguration(void)
 
   cupsdDeleteAllListeners();
 
-  RemoteAccessEnabled = 0;
+  old_remote_port = RemotePort;
+  RemotePort      = 0;
 
  /*
   * String options...
   */
 
+  cupsdFreeAliases(ServerAlias);
+  ServerAlias = NULL;
+
   cupsdClearString(&ServerName);
   cupsdClearString(&ServerAdmin);
   cupsdSetString(&ServerBin, CUPS_SERVERBIN);
@@ -452,9 +502,6 @@ cupsdReadConfiguration(void)
   cupsdSetString(&RemoteRoot, "remroot");
   cupsdSetString(&ServerHeader, "CUPS/1.4");
   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;
@@ -559,6 +606,7 @@ cupsdReadConfiguration(void)
   SSLOptions               = CUPSD_SSL_NONE;
 #endif /* HAVE_SSL */
   DirtyCleanInterval       = DEFAULT_KEEPALIVE;
+  JobKillDelay             = DEFAULT_TIMEOUT;
   JobRetryLimit            = 5;
   JobRetryInterval         = 300;
   FileDevice               = FALSE;
@@ -572,6 +620,7 @@ cupsdReadConfiguration(void)
   KeepAlive                = TRUE;
   KeepAliveTimeout         = DEFAULT_KEEPALIVE;
   ListenBackLog            = SOMAXCONN;
+  LogDebugHistory          = 200;
   LogFilePerm              = CUPS_DEFAULT_LOG_FILE_PERM;
   LogLevel                 = CUPSD_LOG_WARN;
   LogTimeFormat            = CUPSD_TIME_STANDARD;
@@ -663,17 +712,22 @@ cupsdReadConfiguration(void)
   RunUser = getuid();
 
   cupsdLogMessage(CUPSD_LOG_INFO, "Remote access is %s.",
-                  RemoteAccessEnabled ? "enabled" : "disabled");
+                  RemotePort ? "enabled" : "disabled");
 
  /*
   * See if the ServerName is an IP address...
   */
 
-  if (!ServerName)
+  if (ServerName)
+  {
+    if (!ServerAlias)
+      ServerAlias = cupsArrayNew(NULL, NULL);
+
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "Added auto ServerAlias %s", ServerName);
+  }
+  else
   {
-    if (HostNameLookups || RemoteAccessEnabled)
-      httpGetHostname(NULL, temp, sizeof(temp));
-    else if (gethostname(temp, sizeof(temp)))
+    if (gethostname(temp, sizeof(temp)))
     {
       cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to get hostname: %s",
                       strerror(errno));
@@ -681,6 +735,50 @@ cupsdReadConfiguration(void)
     }
 
     cupsdSetString(&ServerName, temp);
+
+    if (!ServerAlias)
+      ServerAlias = cupsArrayNew(NULL, NULL);
+
+    cupsdAddAlias(ServerAlias, temp);
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "Added auto ServerAlias %s", temp);
+
+    if (HostNameLookups || RemotePort)
+    {
+      struct hostent   *host;          /* Host entry to get FQDN */
+
+      if ((host = gethostbyname(temp)) != NULL)
+      {
+        if (strcasecmp(temp, host->h_name))
+        {
+         cupsdSetString(&ServerName, host->h_name);
+         cupsdAddAlias(ServerAlias, host->h_name);
+          cupsdLogMessage(CUPSD_LOG_DEBUG, "Added auto ServerAlias %s",
+                         host->h_name);
+       }
+
+        if (host->h_aliases)
+       {
+          for (i = 0; host->h_aliases[i]; i ++)
+           if (strcasecmp(temp, host->h_aliases[i]))
+           {
+             cupsdAddAlias(ServerAlias, host->h_aliases[i]);
+             cupsdLogMessage(CUPSD_LOG_DEBUG, "Added auto ServerAlias %s",
+                             host->h_aliases[i]);
+           }
+       }
+      }
+    }
+
+   /*
+    * Make sure we have the base hostname added as an alias, too!
+    */
+
+    if ((slash = strchr(temp, '.')) != NULL)
+    {
+      *slash = '\0';
+      cupsdAddAlias(ServerAlias, temp);
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "Added auto ServerAlias %s", temp);
+    }
   }
 
   for (slash = ServerName; isdigit(*slash & 255) || *slash == '.'; slash ++);
@@ -1182,6 +1280,7 @@ cupsdReadConfiguration(void)
   */
 
   if (NeedReload == RELOAD_ALL ||
+      old_remote_port != RemotePort ||
       !old_serverroot || !ServerRoot || strcmp(old_serverroot, ServerRoot) ||
       !old_requestroot || !RequestRoot || strcmp(old_requestroot, RequestRoot))
   {
@@ -2483,7 +2582,14 @@ read_configuration(cups_file_t *fp)      /* I - File to read from */
                         ntohs(lis->address.ipv4.sin_port));
 
         if (!httpAddrLocalhost(&(lis->address)))
-         RemoteAccessEnabled = 1;
+       {
+#ifdef AF_INET6
+         if (lis->address.addr.sa_family == AF_INET6)
+           RemotePort = ntohs(lis->address.ipv6.sin6_port);
+         else
+#endif /* AF_INET6 */
+         RemotePort = ntohs(lis->address.ipv4.sin_port);
+       }
       }
 
      /*
@@ -3033,19 +3139,6 @@ read_configuration(cups_file_t *fp)      /* I - File to read from */
       }
     }
 #endif /* HAVE_SSL */
-#ifdef HAVE_GSSAPI
-    else if (!strcasecmp(line, "Krb5Keytab") && value)
-    {
-      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") && value)
     {
      /*
@@ -3270,6 +3363,13 @@ read_configuration(cups_file_t *fp)      /* I - File to read from */
            break;
       }
     }
+    else if (!strcasecmp(line, "ServerAlias") && value)
+    {
+      if (!ServerAlias)
+        ServerAlias = cupsArrayNew(NULL, NULL);
+
+      cupsdAddAlias(ServerAlias, value);
+    }
     else if (!strcasecmp(line, "SetEnv") && value)
     {
      /*