Skip to content

Commit 3c86e2f

Browse files
committed
Fix some regressions/style issues with the duplicate printer fixes (Issue #1620)
1 parent d0b6695 commit 3c86e2f

3 files changed

Lines changed: 27 additions & 56 deletions

File tree

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Changes in CUPS v2.4.20 (YYYY-MM-DD)
2626
- Fixed some compression issues in the rastertoepson and rastertohp drivers
2727
(Issue #1613)
2828
- Fixed MIME `char` rule handling (Issue #1614)
29+
- Fixed duplicate local printers (Issue #1531, Issue #1586, Issue #1593,
30+
Issue #1620)
2931
- Fixed several issues reported by Coverity
3032
- Fixed case-sensitive PPD keyword comparisons when filtering keyword updates
3133
from filters.

cups/dest.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* User-defined destination (and option) support for CUPS.
33
*
4-
* Copyright © 2020-2025 by OpenPrinting.
4+
* Copyright © 2020-2026 by OpenPrinting.
55
* Copyright © 2007-2019 by Apple Inc.
66
* Copyright © 1997-2007 by Easy Software Products.
77
*
@@ -3064,6 +3064,7 @@ cups_dnssd_query_cb(
30643064
uri[1024]; /* Printer URI */
30653065
cups_ptype_t type = CUPS_PRINTER_DISCOVERED | CUPS_PRINTER_BW;
30663066
/* Printer type */
3067+
const char *uuid; /* Printer UUID */
30673068
int saw_printer_type = 0;
30683069
/* Did we see a printer-type key? */
30693070

@@ -3177,16 +3178,13 @@ cups_dnssd_query_cb(
31773178
else if (!_cups_strcasecmp(key, "UUID"))
31783179
{
31793180
// Suppress local printer being re-discovered via DNS-SD
3180-
int i;
3181-
device->dest.num_options = cupsAddOption("UUID", value,
3182-
device->dest.num_options,
3183-
&device->dest.options);
3181+
int i; /* Looping var */
31843182

3185-
for (i = 0; i < data->num_local; i++)
3183+
device->dest.num_options = cupsAddOption("UUID", value, device->dest.num_options,&device->dest.options);
3184+
3185+
for (i = 0; i < data->num_local; i ++)
31863186
{
3187-
const char *local_uuid = cupsGetOption("printer-uuid",
3188-
data->local_dests[i].num_options,
3189-
data->local_dests[i].options);
3187+
const char *local_uuid = cupsGetOption("printer-uuid", data->local_dests[i].num_options, data->local_dests[i].options);
31903188
if (local_uuid && !_cups_strcasecmp(value, local_uuid + 9))
31913189
{
31923190
device->state = _CUPS_DNSSD_INCOMPATIBLE;
@@ -3275,9 +3273,10 @@ cups_dnssd_query_cb(
32753273
*/
32763274

32773275
cups_dnssd_unquote(uriname, device->fullName, sizeof(uriname));
3278-
httpAssembleURI(HTTP_URI_CODING_ALL, uri, sizeof(uri),
3279-
!strcmp(device->regtype, "_ipps._tcp") ? "ipps" : "ipp",
3280-
NULL, uriname, 0, saw_printer_type ? "/cups" : "/");
3276+
if ((uuid = cupsGetOption("UUID", device->dest.num_options, device->dest.options)) != NULL)
3277+
httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "dnssd", NULL, uriname, 0, saw_printer_type ? "/cups?uuid=%s" : "/?uuid=%s", uuid);
3278+
else
3279+
httpAssembleURI(HTTP_URI_CODING_ALL, uri, sizeof(uri), "dnssd", NULL, uriname, 0, saw_printer_type ? "/cups" : "/");
32813280

32823281
DEBUG_printf(("6cups_dnssd_query: device-uri=\"%s\"", uri));
32833282

scheduler/ipp.c

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5449,7 +5449,10 @@ create_local_bg_thread(
54495449
}
54505450
}
54515451

5452-
// Validate response from printer...
5452+
/*
5453+
* Validate response from printer...
5454+
*/
5455+
54535456
if (!ippValidateAttributes(response))
54545457
{
54555458
/* Force printer to timeout and be deleted */
@@ -5613,7 +5616,8 @@ create_local_printer(
56135616
char name[128], /* Sanitized printer name */
56145617
*nameptr, /* Pointer into name */
56155618
uri[1024]; /* printer-uri-supported value */
5616-
const char *ptr; /* Pointer into attribute value */
5619+
const char *ptr, /* Pointer into attribute value */
5620+
*device_uri_ptr; /* Pointer into device URI value */
56175621
char scheme[HTTP_MAX_URI], /* Scheme portion of URI */
56185622
userpass[HTTP_MAX_URI], /* Username portion of URI */
56195623
host[HTTP_MAX_URI], /* Host portion of URI */
@@ -5683,11 +5687,11 @@ create_local_printer(
56835687
return;
56845688
}
56855689

5686-
ptr = ippGetString(device_uri, 0, NULL);
5690+
device_uri_ptr = ippGetString(device_uri, 0, NULL);
56875691

5688-
if (!ptr || !ptr[0] || (strncmp(ptr, "ipp://", 6) && strncmp(ptr, "ipps://", 7)))
5692+
if (!device_uri_ptr || !device_uri_ptr[0] || (strncmp(device_uri_ptr, "dnssd://", 8) && strncmp(device_uri_ptr, "ipp://", 6) && strncmp(device_uri_ptr, "ipps://", 7)))
56895693
{
5690-
send_ipp_status(con, IPP_STATUS_ERROR_NOT_POSSIBLE, _("Bad device-uri \"%s\"."), ptr);
5694+
send_ipp_status(con, IPP_STATUS_ERROR_NOT_POSSIBLE, _("Bad device-uri \"%s\"."), device_uri_ptr);
56915695

56925696
return;
56935697
}
@@ -5709,51 +5713,17 @@ create_local_printer(
57095713

57105714
for (printer = (cupsd_printer_t *)cupsArrayFirst(Printers); printer; printer = (cupsd_printer_t *)cupsArrayNext(Printers))
57115715
{
5712-
if (printer->device_uri && !strcmp(ptr, printer->device_uri))
5716+
/*
5717+
* Check for a matching device URI...
5718+
*/
5719+
5720+
if (printer->device_uri && !strcmp(device_uri_ptr, printer->device_uri))
57135721
{
57145722
printer->state_time = time(NULL);
57155723
send_ipp_status(con, IPP_STATUS_OK, _("Printer \"%s\" already exists."), printer->name);
57165724
goto add_printer_attributes;
57175725
}
5718-
/* Check for existing permanent queue with same UUID */
5719-
{
5720-
cupsd_printer_t *perm;
5721-
char req_uuid[64] = "";
5722-
5723-
/* Extract UUID from hostname like: UUID.local */
5724-
const char *host_start = strstr(ptr, "://");
5725-
if (host_start)
5726-
{
5727-
host_start += 3;
5728-
const char *dot_local = strstr(host_start, ".local");
5729-
if (dot_local)
5730-
{
5731-
size_t ulen = (size_t)(dot_local - host_start);
5732-
if (ulen < sizeof(req_uuid))
5733-
{
5734-
memcpy(req_uuid, host_start, ulen);
5735-
req_uuid[ulen] = '\0';
5736-
}
5737-
}
5738-
}
5739-
5740-
if (req_uuid[0])
5741-
{
5742-
for (perm = (cupsd_printer_t *)cupsArrayFirst(Printers); perm; perm = (cupsd_printer_t *)cupsArrayNext(Printers))
5743-
{
5744-
if (!perm->temporary && perm->uuid && !strcasecmp(req_uuid, perm->uuid + 9))
5745-
{
5746-
cupsdLogMessage(CUPSD_LOG_DEBUG, "create_local_printer: FOUND MATCHING PERMANENT QUEUE: %s", perm->name);
5747-
printer = perm;
5748-
printer->state_time = time(NULL);
5749-
send_ipp_status(con, IPP_STATUS_OK, _("Printer \"%s\" already exists."), printer->name);
5750-
goto add_printer_attributes;
5751-
}
5752-
}
5753-
}
57545726
}
5755-
}
5756-
57575727

57585728
/*
57595729
* Create the printer...

0 commit comments

Comments
 (0)