Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions pappl/dnssd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

system->hostname cannot be NULL.

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;
Copy link
Owner

Choose a reason for hiding this comment

The 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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The 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);
}
2 changes: 2 additions & 0 deletions pappl/printer-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ struct _pappl_printer_s // Printer data
//
// Functions...
//
//
extern bool _papplDNSSDIsLoopback(const char *name) _PAPPL_PRIVATE;

extern bool _papplPrinterAddRawListeners(pappl_printer_t *printer) _PAPPL_PRIVATE;
extern void *_papplPrinterRunRaw(pappl_printer_t *printer) _PAPPL_PRIVATE;
Expand Down
20 changes: 20 additions & 0 deletions pappl/system-accessors.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ papplSystemAddListeners(
if (ret)
system->port = port;
}

Copy link
Owner

Choose a reason for hiding this comment

The 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 == '[')
{
Expand Down Expand Up @@ -169,6 +176,11 @@ papplSystemAddListeners(
if (ret)
system->port = port;
}

if (system->hostname)
free(system->hostname);

system->hostname = strdup(name);
}
else
{
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion pappl/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The 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)
Expand Down
Loading