-
-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dnssd.c: Enable service registration on loopback only #346
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,12 +51,12 @@ _papplPrinterRegisterDNSSDNoLock( | |
const char *papermax; // PaperMax string value (legacy) | ||
|
||
|
||
if (!printer->dns_sd_name || !printer->system->is_running || (printer->system->options & PAPPL_SOPTIONS_NO_DNS_SD)) | ||
if (!printer->dns_sd_name || !printer->system->is_running || (printer->system->options & PAPPL_SOPTIONS_NO_DNS_SD) || !system->hostname) | ||
return (false); | ||
|
||
papplLogPrinter(printer, PAPPL_LOGLEVEL_DEBUG, "Registering DNS-SD name '%s' on '%s'", printer->dns_sd_name, printer->system->hostname); | ||
|
||
if_index = !strcmp(system->hostname, "localhost") ? CUPS_DNSSD_IF_INDEX_LOCAL : CUPS_DNSSD_IF_INDEX_ANY; | ||
if_index = _papplDNSSDIsLoopback(system->hostname) ? CUPS_DNSSD_IF_INDEX_LOCAL : CUPS_DNSSD_IF_INDEX_ANY; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking we should examine the listeners or keep a boolean to track whether we are listening on an externally accessible address. |
||
|
||
// Get attributes and values for the TXT record... | ||
color_supported = ippFindAttribute(printer->driver_attrs, "color-supported", IPP_TAG_BOOLEAN); | ||
|
@@ -303,7 +303,7 @@ _papplSystemRegisterDNSSDNoLock( | |
|
||
papplLog(system, PAPPL_LOGLEVEL_DEBUG, "Registering DNS-SD name '%s' on '%s'", system->dns_sd_name, system->hostname); | ||
|
||
if_index = !strcmp(system->hostname, "localhost") ? CUPS_DNSSD_IF_INDEX_LOCAL : CUPS_DNSSD_IF_INDEX_ANY; | ||
if_index = _papplDNSSDIsLoopback(system->hostname) ? CUPS_DNSSD_IF_INDEX_LOCAL : CUPS_DNSSD_IF_INDEX_ANY; | ||
|
||
// Rename the service as needed... | ||
if (system->dns_sd_collision) | ||
|
@@ -460,3 +460,25 @@ dns_sd_system_callback( | |
if (flags & CUPS_DNSSD_FLAGS_ERROR) | ||
papplLog(system, PAPPL_LOGLEVEL_ERROR, "DNS-SD registration of '%s' failed.", system->dns_sd_name); | ||
} | ||
|
||
|
||
// | ||
// '_papplDNSSDIsLoopback()' - Find out whether the string means | ||
// localhost | ||
// | ||
|
||
bool | ||
_papplDNSSDIsLoopback(const char *name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still not clear why we need a function for this... |
||
{ | ||
if (!name) | ||
return (false); | ||
|
||
if (!strcasecmp(name, "localhost")) | ||
return (true); | ||
else if (!strcmp(name, "127.0.0.1")) | ||
return (true); | ||
else if (!strcmp(name, "[::1]")) | ||
return (true); | ||
|
||
return (false); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,6 +141,13 @@ papplSystemAddListeners( | |
if (ret) | ||
system->port = port; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't where I'd save the hostname... You can have multiple listeners. |
||
if (system->hostname) | ||
{ | ||
free(system->hostname); | ||
} | ||
|
||
system->hostname = strdup(name); | ||
} | ||
else if (name && *name == '[') | ||
{ | ||
|
@@ -169,6 +176,11 @@ papplSystemAddListeners( | |
if (ret) | ||
system->port = port; | ||
} | ||
|
||
if (system->hostname) | ||
free(system->hostname); | ||
|
||
system->hostname = strdup(name); | ||
} | ||
else | ||
{ | ||
|
@@ -201,6 +213,14 @@ papplSystemAddListeners( | |
add_listeners(system, name, port, AF_INET6); | ||
} | ||
} | ||
|
||
if (name && !strcasecmp(name, "localhost")) | ||
{ | ||
if (system->hostname) | ||
free(system->hostname); | ||
|
||
system->hostname = strdup(name); | ||
} | ||
} | ||
|
||
return (ret); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -677,7 +677,7 @@ papplSystemRun(pappl_system_t *system) // I - System | |
bool force_dns_sd = system->dns_sd_host_changes != dns_sd_host_changes; | ||
// Force re-registration? | ||
|
||
if (force_dns_sd) | ||
if (!_papplDNSSDIsLoopback(system->hostname) && force_dns_sd) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It isn't about being on the loopback interface since we still need to advertise on localhost. |
||
_papplSystemSetHostNameNoLock(system, NULL); | ||
|
||
if (system->dns_sd_collision || force_dns_sd) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
system->hostname
cannot beNULL
.