Skip to content
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
19 changes: 19 additions & 0 deletions man/cupsd.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,25 @@ The value "none" disables the "@ Computer Name" suffix added to shared printer n
\fBDNSSDHostName \fIHOSTNAME\fR
Specifies the fully-qualified domain name for the server that is used for DNS-SD sharing.
The default is typically the server's ".local" hostname and is updated whenever that hostname changes.
.\"#DNSSDServiceName
.TP 5
\fBDNSSDServiceName \fIservice-name\fR
Specifies the service name announced for a shared printer.
\fIservice-name\fR may contain the following placeholders:
.RS
.IP %n 5
The printer's name.
.IP %i 5
The printer's \fIinfo\fR field.
.IP %l 5
The printer's \fIlocation\fR field.
.IP %m 5
The printer's \fImake & model\fR field.
.IP %c 5
The server's name.
.IP %% 5
A literal percent sign.
.RE
.\"#ErrorPolicy
.TP 5
\fBErrorPolicy abort-job\fR
Expand Down
1 change: 1 addition & 0 deletions scheduler/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ static const cupsd_var_t cupsd_vars[] =
{ "DirtyCleanInterval", &DirtyCleanInterval, CUPSD_VARTYPE_TIME },
{ "DNSSDComputerName", &DNSSDComputerName, CUPSD_VARTYPE_STRING },
{ "DNSSDHostName", &DNSSDHostName, CUPSD_VARTYPE_STRING },
{ "DNSSDServiceName", &DNSSDServiceName, CUPSD_VARTYPE_STRING },
{ "ErrorPolicy", &ErrorPolicy, CUPSD_VARTYPE_STRING },
{ "FilterLimit", &FilterLimit, CUPSD_VARTYPE_INTEGER },
#ifdef HAVE_GSSAPI
Expand Down
40 changes: 39 additions & 1 deletion scheduler/dirsvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,45 @@ dnssdRegisterPrinter(

if (!p->reg_name)
{
if (p->info && strlen(p->info) > 0)
if (DNSSDServiceName && DNSSDServiceName[0] != '\0') {
char *s = DNSSDServiceName, *e = name + sizeof(name), *q = name, c;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The normal coding style here would be to set the end pointer to "name + sizeof(name) - 1" to leave room for the NUL at the end.

Also, you might use "src", "dst", and "dstend" as variable names to make things clearer... :)


while (1) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"while (*src && dst < dstend)"?

c = *s++;
/* assert(q < e); */
if (c == '\0' || q == e - 1) {
*q = '\0';
break;
} else if (c == '%') {
c = *s++;
if (c == '\0') { /* putting this into the case would need a break 2 */
*q = '\0';
break;
} else if (c == '%') { /* could be put into case */
*q++ = '%';
} else {
char *r;
switch (c) {
case 'n': r = p->name; break;
case 'l': r = p->location; break;
case 'i': r = p->info; break;
case 'm': r = p->make_model; break;
case 'c': r = DNSSDComputerName; break;
default: continue;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe log a warning message for unknown substitution characters?

}
if (r == NULL) continue;
q += strlcpy(q, r, e - q);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

strlcpy isn't standard. cupsCopyString is the CUPS API that uses strlcpy or its equivalent. But the return value is the number of characters that would have been copied if there was infinite space - I usually do copy and then "q += strlen(q)".

if (q >= e) {
*(e - 1) = '\0';
break;
}
}
} else {
*q++ = c;
}
}
}
else if (p->info && strlen(p->info) > 0)
{
if (DNSSDComputerName)
snprintf(name, sizeof(name), "%s @ %s", p->info, DNSSDComputerName);
Expand Down
5 changes: 4 additions & 1 deletion scheduler/dirsvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ VAR char *DNSSDHostName VALUE(NULL);
/* Hostname */
VAR int DNSSDHostNameConfigured VALUE(0);
/* Was the DNSSDHostName value configured in cupsd.conf? */
VAR char *DNSSDSubTypes VALUE(NULL);
VAR char *DNSSDSubTypes VALUE(NULL).
/* Bonjour registration subtypes */
*DNSSDServiceName
VALUE(NULL);
/* DNSSD service name */
VAR cups_array_t *DNSSDAlias VALUE(NULL);
/* List of dynamic ServerAlias's */
VAR int DNSSDPort VALUE(0);
Expand Down