From: Till Kamppeter Date: Fri, 10 Jun 2022 19:19:29 +0000 (+0200) Subject: create_local_printer(): Improved comparison of device URI host name X-Git-Tag: v2.4.3~170^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fcreate-local-printer-localhost-fix;p=thirdparty%2Fcups.git create_local_printer(): Improved comparison of device URI host name Improved the comparison of the device URI host name with the CUPS server's host name to find out whether the temporary queue is for a local IPP service. - Compare case-insensitively as host names are case-insensitive - If we have the DNS-SD host name (DNSSDHostName) of the CUPS server, consider names equal if they only differ by the presence or absense of a trailing dot ('.') - If we only have the ServerName (for example with "Browsing = Off", not sharing printers), consider also a server name without ".local" equal to a device URI host name with ".local" as equal. --- diff --git a/scheduler/ipp.c b/scheduler/ipp.c index 1769ef8dcb..56bd8b3049 100644 --- a/scheduler/ipp.c +++ b/scheduler/ipp.c @@ -5547,8 +5547,9 @@ create_local_printer( * the hostname by localhost. This way we assure that local-only services * like ipp-usb or Printer Applications always work. * - * When comparing our hostname with the one in the device URI, consider - * names with ¨.local(.)" suffix and names without suffix the same. + * When comparing our hostname with the one in the device URI, + * consider names with or without trailing dot ('.') the same. Also + * compare case-insensitively. */ #ifdef HAVE_DNSSD @@ -5566,23 +5567,30 @@ create_local_printer( int host_len, server_name_len; + /* Get host name of device URI */ httpSeparateURI(HTTP_URI_CODING_ALL, ptr, scheme, sizeof(scheme), userpass, sizeof(userpass), host, sizeof(host), &port, resource, sizeof(resource)); + /* Take trailing dot out of comparison */ host_len = strlen(host); - if (strcmp(host + host_len - 6, ".local") == 0) - host_len -= 6; - if (strcmp(host + host_len - 7, ".local.") == 0) - host_len -= 7; + if (host_len > 1 && host[host_len - 1] == '.') + host_len --; server_name_len = strlen(nameptr); - if (strcmp(nameptr + server_name_len - 6, ".local") == 0) - server_name_len -= 6; - if (strcmp(nameptr + server_name_len - 7, ".local.") == 0) - server_name_len -= 7; + if (server_name_len > 1 && nameptr[server_name_len - 1] == '.') + server_name_len --; + + /* + * If we have no DNSSDHostName but only a ServerName (if we are not + * sharing printers, Browsing = Off) the ServerName has no ".local" + * but the requested device URI has. Take this into account. + */ + + if (nameptr == ServerName && host_len >= 6 && (server_name_len < 6 || strcmp(nameptr + server_name_len - 6, ".local") != 0) && strcmp(host + host_len - 6, ".local") == 0) + host_len -= 6; - if (host_len == server_name_len && strncmp(host, nameptr, host_len) == 0) + if (host_len == server_name_len && strncasecmp(host, nameptr, host_len) == 0) ptr = "localhost"; else ptr = host;