]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Fix the adminurl field in the TXT record for fully-qualified `ServerName`
authorMichael Sweet <michael.r.sweet@gmail.com>
Tue, 1 Aug 2017 01:29:20 +0000 (21:29 -0400)
committerMichael Sweet <michael.r.sweet@gmail.com>
Tue, 1 Aug 2017 01:29:20 +0000 (21:29 -0400)
values (Issue #5074)

CHANGES.md
scheduler/dirsvc.c

index 7dcba56a1729b4442c51bc98bf5c7c5c42043ab6..1ed21316782317efd68b05f16fbdebbe28191a47 100644 (file)
@@ -22,6 +22,8 @@ CHANGES IN CUPS V2.2.5
 - Fixed the `SSLOptions DenyCBC` option when using GNU TLS (Issue #5065)
 - Fixed the `ServerTokens None` option (Issue #5065)
 - Fixed the default `ServerAlias` value from `ServerName` (Issue #5072)
+- Fixed the adminurl field in the TXT record for fully-qualified `ServerName`
+  values (Issue #5074)
 - Fixed an issue with Chinese localizations on macOS (rdar://32419311)
 - The IPP backend now always sends the "finishings" attribute for printers that
   support it because otherwise the client cannot override printer defaults
index fdbd7f1b385165e37f2b2e74b1f048e42ae9e5c8..6f6aa8bb446dc38f1ccbd416e39b2ad3771fdfd3 100644 (file)
@@ -346,14 +346,17 @@ dnssdBuildTxtRecord(
 {
   int          i,                      /* Looping var */
                count;                  /* Count of key/value pairs */
-  char         admin_hostname[256],    /* .local hostname for admin page */
+  char         admin_hostname[256],    /* Hostname for admin page */
                adminurl_str[256],      /* URL for the admin page */
                type_str[32],           /* Type to string buffer */
                state_str[32],          /* State to string buffer */
                rp_str[1024],           /* Queue name string buffer */
                air_str[1024],          /* auth-info-required string buffer */
-               *keyvalue[32][2];       /* Table of key/value pairs */
+               *keyvalue[32][2],       /* Table of key/value pairs */
+                *ptr;                   /* Pointer in string */
   cupsd_txt_t  txt;                    /* TXT record */
+  cupsd_listener_t *lis;                /* Current listener */
+  const char    *admin_scheme = "http"; /* Admin page URL scheme */
 
 
  /*
@@ -382,20 +385,46 @@ dnssdBuildTxtRecord(
     keyvalue[count  ][0] = "ty";
     keyvalue[count++][1] = p->make_model ? p->make_model : "Unknown";
 
-    if (strstr(DNSSDHostName, ".local"))
-      strlcpy(admin_hostname, DNSSDHostName, sizeof(admin_hostname));
+   /*
+    * Get the hostname for the admin page...
+    */
+
+    if (strchr(DNSSDHostName, '.'))
+    {
+     /*
+      * Use the provided hostname, but make sure it ends with a period...
+      */
+
+      if ((ptr = DNSSDHostName + strlen(DNSSDHostName) - 1) >= DNSSDHostName && *ptr == '.')
+        strlcpy(admin_hostname, DNSSDHostName, sizeof(admin_hostname));
+      else
+        snprintf(admin_hostname, sizeof(admin_hostname), "%s.", DNSSDHostName);
+    }
     else
-      snprintf(admin_hostname, sizeof(admin_hostname), "%s.local.",
-               DNSSDHostName);
-    httpAssembleURIf(HTTP_URI_CODING_ALL, adminurl_str, sizeof(adminurl_str),
+    {
+     /*
+      * Unqualified hostname gets ".local." added to it...
+      */
+
+      snprintf(admin_hostname, sizeof(admin_hostname), "%s.local.", DNSSDHostName);
+    }
+
+   /*
+    * Get the URL scheme for the admin page...
+    */
+
 #  ifdef HAVE_SSL
-                    "https",
-#  else
-                    "http",
+    for (lis = (cupsd_listener_t *)cupsArrayFirst(Listeners); lis; lis = (cupsd_listener_t *)cupsArrayNext(Listeners))
+    {
+      if (lis->encryption != HTTP_ENCRYPTION_NEVER)
+      {
+        admin_scheme = "https";
+        break;
+      }
+    }
 #  endif /* HAVE_SSL */
-                    NULL, admin_hostname, DNSSDPort, "/%s/%s",
-                    (p->type & CUPS_PRINTER_CLASS) ? "classes" : "printers",
-                    p->name);
+
+    httpAssembleURIf(HTTP_URI_CODING_ALL, adminurl_str, sizeof(adminurl_str), admin_scheme,  NULL, admin_hostname, DNSSDPort, "/%s/%s", (p->type & CUPS_PRINTER_CLASS) ? "classes" : "printers", p->name);
     keyvalue[count  ][0] = "adminurl";
     keyvalue[count++][1] = adminurl_str;