X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=scheduler%2Fdirsvc.c;h=ddd3701e07c29de2402d5f89cd702b815aef2a86;hb=5c463d3fe0cdac4ed29c7124daf04e1fdcfe7186;hp=fdbd7f1b385165e37f2b2e74b1f048e42ae9e5c8;hpb=57b7b66b58a66426494ec13ffb18f730afeab8b5;p=thirdparty%2Fcups.git diff --git a/scheduler/dirsvc.c b/scheduler/dirsvc.c index fdbd7f1b3..ddd3701e0 100644 --- a/scheduler/dirsvc.c +++ b/scheduler/dirsvc.c @@ -1,14 +1,11 @@ /* * Directory services routines for the CUPS scheduler. * - * Copyright 2007-2015 by Apple Inc. - * Copyright 1997-2007 by Easy Software Products, all rights reserved. + * Copyright © 2007-2018 by Apple Inc. + * Copyright © 1997-2007 by Easy Software Products, all rights reserved. * - * These coded instructions, statements, and computer programs are the - * property of Apple Inc. and are protected by Federal copyright - * law. Distribution and use rights are outlined in the file "LICENSE.txt" - * which should have been included with this file. If this file is - * missing or damaged, see the license at "http://www.cups.org/". + * Licensed under Apache License v2.0. See the file "LICENSE" for more + * information. */ /* @@ -346,14 +343,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 +382,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; @@ -669,17 +695,21 @@ dnssdDeregisterInstance( DNSServiceRefDeallocate(*srv); + *srv = NULL; + # else /* HAVE_AVAHI */ if (!from_callback) avahi_threaded_poll_lock(DNSSDMaster); - avahi_entry_group_free(*srv); + if (*srv) + { + avahi_entry_group_free(*srv); + *srv = NULL; + } if (!from_callback) avahi_threaded_poll_unlock(DNSSDMaster); # endif /* HAVE_DNSSD */ - - *srv = NULL; } @@ -1043,7 +1073,7 @@ dnssdRegisterInstance( *srv = DNSSDMaster; error = DNSServiceRegister(srv, kDNSServiceFlagsShareConnection, - 0, name, temp, NULL, NULL, htons(port), + 0, name, temp, NULL, DNSSDHostName, htons(port), txt ? TXTRecordGetLength(txt) : 0, txt ? TXTRecordGetBytesPtr(txt) : NULL, dnssdRegisterCallback, p); @@ -1058,7 +1088,7 @@ dnssdRegisterInstance( error = avahi_entry_group_add_service_strlst(*srv, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, - type, NULL, NULL, port, + type, NULL, DNSSDHostName, port, txt ? *txt : NULL); if (error) cupsdLogMessage(CUPSD_LOG_DEBUG, "DNS-SD service add for \"%s\" failed.", @@ -1424,23 +1454,29 @@ dnssdUpdateDNSSDName(int from_callback) /* I - Called from callback? */ cupsdSetString(&DNSSDComputerName, ServerName); } - /* - * Get the local hostname from the dynamic store... - */ - - cupsdClearString(&DNSSDHostName); - - if ((nameRef = SCDynamicStoreCopyLocalHostName(sc)) != NULL) + if (!DNSSDHostName) { - if (CFStringGetCString(nameRef, nameBuffer, sizeof(nameBuffer), - kCFStringEncodingUTF8)) + /* + * Get the local hostname from the dynamic store... + */ + + if ((nameRef = SCDynamicStoreCopyLocalHostName(sc)) != NULL) { - cupsdLogMessage(CUPSD_LOG_DEBUG, - "Dynamic store host name is \"%s\".", nameBuffer); - cupsdSetString(&DNSSDHostName, nameBuffer); - } + if (CFStringGetCString(nameRef, nameBuffer, sizeof(nameBuffer), + kCFStringEncodingUTF8)) + { + cupsdLogMessage(CUPSD_LOG_DEBUG, "Dynamic store host name is \"%s\".", nameBuffer); - CFRelease(nameRef); + if (strchr(nameBuffer, '.')) + cupsdSetString(&DNSSDHostName, nameBuffer); + else + cupsdSetStringf(&DNSSDHostName, "%s.local", nameBuffer); + + cupsdLogMessage(CUPSD_LOG_INFO, "Defaulting to \"DNSSDHostName %s\".", DNSSDHostName); + } + + CFRelease(nameRef); + } } if (!DNSSDHostName) @@ -1449,9 +1485,10 @@ dnssdUpdateDNSSDName(int from_callback) /* I - Called from callback? */ * Use the ServerName instead... */ - cupsdLogMessage(CUPSD_LOG_DEBUG, - "Using ServerName \"%s\" as host name.", ServerName); + cupsdLogMessage(CUPSD_LOG_DEBUG, "Using ServerName \"%s\" as host name.", ServerName); cupsdSetString(&DNSSDHostName, ServerName); + + cupsdLogMessage(CUPSD_LOG_INFO, "Defaulting to \"DNSSDHostName %s\".", DNSSDHostName); } /* @@ -1485,26 +1522,37 @@ dnssdUpdateDNSSDName(int from_callback) /* I - Called from callback? */ if (DNSSDClient) { const char *host_name = avahi_client_get_host_name(DNSSDClient); - const char *host_fqdn = avahi_client_get_host_name_fqdn(DNSSDClient); cupsdSetString(&DNSSDComputerName, host_name ? host_name : ServerName); - if (host_fqdn) - cupsdSetString(&DNSSDHostName, host_fqdn); - else if (strchr(ServerName, '.')) - cupsdSetString(&DNSSDHostName, ServerName); - else - cupsdSetStringf(&DNSSDHostName, "%s.local", ServerName); + if (!DNSSDHostName) + { + const char *host_fqdn = avahi_client_get_host_name_fqdn(DNSSDClient); + + if (host_fqdn) + cupsdSetString(&DNSSDHostName, host_fqdn); + else if (strchr(ServerName, '.')) + cupsdSetString(&DNSSDHostName, ServerName); + else + cupsdSetStringf(&DNSSDHostName, "%s.local", ServerName); + + cupsdLogMessage(CUPSD_LOG_INFO, "Defaulting to \"DNSSDHostName %s\".", DNSSDHostName); + } } else # endif /* HAVE_AVAHI */ { cupsdSetString(&DNSSDComputerName, ServerName); - if (strchr(ServerName, '.')) - cupsdSetString(&DNSSDHostName, ServerName); - else - cupsdSetStringf(&DNSSDHostName, "%s.local", ServerName); + if (!DNSSDHostName) + { + if (strchr(ServerName, '.')) + cupsdSetString(&DNSSDHostName, ServerName); + else + cupsdSetStringf(&DNSSDHostName, "%s.local", ServerName); + + cupsdLogMessage(CUPSD_LOG_INFO, "Defaulting to \"DNSSDHostName %s\".", DNSSDHostName); + } } /*