From b6cbd1fec0b8695ce64f582248dbc228243faad8 Mon Sep 17 00:00:00 2001 From: V1krant Date: Thu, 12 Mar 2020 12:35:45 +0530 Subject: [PATCH] Added NewBrowsePollQueuesShared and AllowResharingcupsQueues directives to cups-browsed --- utils/cups-browsed.c | 35 ++++++++++++++++++++++++++++++++--- utils/cups-browsed.conf.5 | 25 +++++++++++++++++++++++++ utils/cups-browsed.conf.in | 17 ++++++++++++++++- 3 files changed, 73 insertions(+), 4 deletions(-) diff --git a/utils/cups-browsed.c b/utils/cups-browsed.c index dd0fcbb3d..c649eab63 100644 --- a/utils/cups-browsed.c +++ b/utils/cups-browsed.c @@ -430,6 +430,8 @@ static unsigned int BrowseInterval = 60; static unsigned int BrowseTimeout = 300; static uint16_t BrowsePort = 631; static browsepoll_t **BrowsePoll = NULL; +static unsigned int NewBrowsePollQueuesShared = 0; +static unsigned int AllowResharingRemoteCUPSPrinters = 0; static size_t NumBrowsePoll = 0; static guint update_netifs_sourceid = 0; static char local_server_str[1024]; @@ -7897,7 +7899,7 @@ gboolean update_cups_queues(gpointer unused) { * only if we have CUPS older than 2.2. * When you have remote queue, clean up and break from the loop. */ - if (p->netprinter != 0 || !HAVE_CUPS_2_2) + if (p->netprinter != 0 || !HAVE_CUPS_2_2 || AllowResharingRemoteCUPSPrinters) ippDelete(cupsDoRequest(http, request, "/admin/")); else { ippDelete(request); @@ -8465,7 +8467,8 @@ gboolean update_cups_queues(gpointer unused) { if (p->netprinter == 0 && strncmp(line, "*%", 2) && strncmp(line, "*PPD-Adobe:", 11) && - ap_remote_queue_id_line_inserted == 0) { + ap_remote_queue_id_line_inserted == 0 && + !AllowResharingRemoteCUPSPrinters) { ap_remote_queue_id_line_inserted = 1; cupsFilePrintf(out, "*APRemoteQueueID: \"\"\n"); } @@ -8605,6 +8608,12 @@ gboolean update_cups_queues(gpointer unused) { num_options = cupsAddOption("printer-is-shared", "true", num_options, &options); debug_printf("Setting printer-is-shared bit.\n"); + } else if (NewBrowsePollQueuesShared && + (val = cupsGetOption("printer-to-be-shared", p->num_options, + p->options)) != NULL) { + num_options = cupsAddOption("printer-is-shared", "true", + num_options, &options); + debug_printf("Setting printer-is-shared bit.\n"); } else { num_options = cupsAddOption("printer-is-shared", "false", num_options, &options); @@ -8617,7 +8626,7 @@ gboolean update_cups_queues(gpointer unused) { * network printer or if we have remote CUPS queue, do IPP request * only if we have CUPS older than 2.2. */ - if (p->netprinter != 0 || !HAVE_CUPS_2_2) + if (p->netprinter != 0 || !HAVE_CUPS_2_2 || AllowResharingRemoteCUPSPrinters) ippDelete(cupsDoRequest(http, request, "/admin/")); else ippDelete(request); @@ -10417,12 +10426,18 @@ found_cups_printer (const char *remote_host, const char *uri, (printer->domain == NULL || printer->domain[0] == '\0' || printer->type == NULL || printer->type[0] == '\0')) { printer->is_legacy = 1; + if (printer->status != STATUS_TO_BE_CREATED) { printer->timeout = time(NULL) + BrowseTimeout; debug_printf("starting BrowseTimeout timer for %s (%ds)\n", printer->queue_name, BrowseTimeout); } } + + if (printer && NewBrowsePollQueuesShared && + (HAVE_CUPS_1_6 || (!HAVE_CUPS_1_6 && !printer->is_legacy))) + printer->num_options = cupsAddOption("printer-to-be-shared", "true", printer->num_options, &(printer->options)); + } gboolean @@ -11588,6 +11603,20 @@ read_configuration (const char *filename) else if (!strcasecmp(value, "no") || !strcasecmp(value, "false") || !strcasecmp(value, "off") || !strcasecmp(value, "0")) NewIPPPrinterQueuesShared = 0; + } else if (!strcasecmp(line, "AllowResharingRemoteCUPSPrinters") && value) { + if (!strcasecmp(value, "yes") || !strcasecmp(value, "true") || + !strcasecmp(value, "on") || !strcasecmp(value, "1")) + AllowResharingRemoteCUPSPrinters = 1; + else if (!strcasecmp(value, "no") || !strcasecmp(value, "false") || + !strcasecmp(value, "off") || !strcasecmp(value, "0")) + AllowResharingRemoteCUPSPrinters = 0; + } else if (!strcasecmp(line, "NewBrowsePollQueuesShared") && value) { + if (!strcasecmp(value, "yes") || !strcasecmp(value, "true") || + !strcasecmp(value, "on") || !strcasecmp(value, "1")) + NewBrowsePollQueuesShared = 1; + else if (!strcasecmp(value, "no") || !strcasecmp(value, "false") || + !strcasecmp(value, "off") || !strcasecmp(value, "0")) + NewBrowsePollQueuesShared = 0; } else if (!strcasecmp(line, "AutoClustering") && value) { if (!strcasecmp(value, "yes") || !strcasecmp(value, "true") || !strcasecmp(value, "on") || !strcasecmp(value, "1")) diff --git a/utils/cups-browsed.conf.5 b/utils/cups-browsed.conf.5 index c592ac7a5..99ed3796e 100644 --- a/utils/cups-browsed.conf.5 +++ b/utils/cups-browsed.conf.5 @@ -466,6 +466,31 @@ this timeout if no further broadcast from the server happens. .fam C BrowseTimeout 300 +.fam T +.fi +The AllowResharingRemoteCUPSPrinters directive determines whether a +print queue pointing to a remote CUPS queue will be re-shared to the +local network or not. Since the queues generated using the BrowsePoll +directive are also pointing to remote queues, they are also shared +automatically if the following option is set. Default is not to share +remote queues. +.PP +.nf +.fam C + AllowResharingRemoteCUPSPrinters Yes + +.fam T +.fi +The NewBrowsePollQueuesShared directive determines whether a print +queue for a newly discovered printer (discovered by the BrowsePoll directive) +will be shared to the local network or not. This directive will only work +if AllowResharingRemoteCUPSPrinters is set to yes. Default is +not to share printers discovered using BrowsePoll. +.PP +.nf +.fam C + NewBrowsePollQueuesShared Yes + .fam T .fi Set OnlyUnsupportedByCUPS to "Yes" will make cups-browsed not create diff --git a/utils/cups-browsed.conf.in b/utils/cups-browsed.conf.in index 82536aaf1..ca4371fe5 100644 --- a/utils/cups-browsed.conf.in +++ b/utils/cups-browsed.conf.in @@ -125,7 +125,6 @@ BrowseRemoteProtocols @BROWSEREMOTEPROTOCOLS@ # BrowseTimeout 300 - # Filtering of remote printers by other properties than IP addresses # of their servers @@ -436,6 +435,22 @@ BrowseRemoteProtocols @BROWSEREMOTEPROTOCOLS@ # IPBasedDeviceURIs IPv4 # IPBasedDeviceURIs IPv6 +# The AllowResharingRemoteCUPSPrinters directive determines whether a +# print queue pointing to a remote CUPS queue will be re-shared to the +# local network or not. Since the queues generated using the BrowsePoll +# directive are also pointing to remote queues, they are also shared +# automatically if the following option is set. Default is not to share +# remote printers. + +# AllowResharingRemoteCUPSPrinters Yes + +# The NewBrowsePollQueuesShared directive determines whether a print +# queue for a newly discovered printer (discovered by the BrowsePoll directive) +# will be shared to the local network or not. This directive will only work +# if AllowResharingRemoteCUPSPrinters is set to yes. Default is +# not to share printers discovered using BrowsePoll. + +# NewBrowsePollQueuesShared Yes # Set CreateRemoteRawPrinterQueues to "Yes" to let cups-browsed also # create local queues pointing to remote raw CUPS queues. Normally,