From 0e10746d904113140bc4a7c631525e51c16eb621 Mon Sep 17 00:00:00 2001 From: Zdenek Dohnal Date: Mon, 20 Feb 2023 17:35:31 +0100 Subject: [PATCH] Initial import (fedora#2170547) --- .gitignore | 1 + 0001-Coverity-fixes.patch | 210 ++++++++++++++++++ ...igure.ac-cups-browsed-doesn-t-need-C.patch | 56 +++++ cups-browsed.spec | 185 +++++++++++++++ sources | 1 + 5 files changed, 453 insertions(+) create mode 100644 .gitignore create mode 100644 0001-Coverity-fixes.patch create mode 100644 0001-configure.ac-cups-browsed-doesn-t-need-C.patch create mode 100644 cups-browsed.spec create mode 100644 sources diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..21a2366 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/cups-browsed-2.0b3.tar.gz diff --git a/0001-Coverity-fixes.patch b/0001-Coverity-fixes.patch new file mode 100644 index 0000000..e0a3f54 --- /dev/null +++ b/0001-Coverity-fixes.patch @@ -0,0 +1,210 @@ +From e780e476c4fb18c9dfff4d164158f5fd535a8ad8 Mon Sep 17 00:00:00 2001 +From: Zdenek Dohnal +Date: Thu, 16 Feb 2023 17:10:32 +0100 +Subject: [PATCH] Coverity fixes 3 + +--- + daemon/cups-browsed.c | 67 +++++++++++++++++++++++++++++++++++++------ + 1 file changed, 59 insertions(+), 8 deletions(-) + +diff --git a/daemon/cups-browsed.c b/daemon/cups-browsed.c +index cf38d38e..276a3483 100644 +--- a/daemon/cups-browsed.c ++++ b/daemon/cups-browsed.c +@@ -673,6 +673,8 @@ copyToFile(FILE **fp1, + fwrite(buf, sizeof(char), r, *fp2); + } + while(r == buffer_size); ++ ++ free(buf); + } + + +@@ -2056,7 +2058,10 @@ get_pagesize(ipp_t *printer_attributes) + if ((page_media = cupsArrayNew3((cups_array_func_t)strcasecmp, NULL, NULL, 0, + (cups_acopy_func_t)strdup, + (cups_afree_func_t)free)) == NULL) ++ { ++ free(ppdsizename); + return (NULL); ++ } + for (size = (cups_size_t *)cupsArrayFirst(sizes); size; + size = (cups_size_t *)cupsArrayNext(sizes)) + { +@@ -2809,7 +2814,10 @@ generate_cluster_conflicts(char *cluster_name, + NULL, NULL, 0, + (cups_acopy_func_t)strdup, + (cups_afree_func_t)free)) == NULL) ++ { ++ free(ppdsizename); + return (NULL); ++ } + + // Storing all the values supported by the cluster in cluster_options + no_of_ppd_keywords = sizeof(ppd_keywords) / sizeof(ppd_keywords[0]); +@@ -2827,7 +2835,10 @@ generate_cluster_conflicts(char *cluster_name, + cupsArrayNew3((cups_array_func_t)strcasecmp, NULL, NULL, 0, + (cups_acopy_func_t)strdup, + (cups_afree_func_t)free)) == NULL) ++ { ++ free(ppdsizename); + return (NULL); ++ } + for (size = (cups_size_t *)cupsArrayFirst(sizes); size; + size = (cups_size_t *)cupsArrayNext(sizes)) + { +@@ -4151,6 +4162,7 @@ prepare_browse_data (void) + ipp_t *request, *response = NULL; + ipp_attribute_t *attr; + http_t *conn = NULL; ++ GString *browse_options = NULL; + + conn = http_connect_local (); + +@@ -4186,7 +4198,7 @@ prepare_browse_data (void) + gchar *location = NULL; + gchar *info = NULL; + gchar *make_model = NULL; +- GString *browse_options = g_string_new (""); ++ browse_options = g_string_new (""); + + // Skip any non-printer attributes + while (attr && ippGetGroupTag(attr) != IPP_TAG_PRINTER) +@@ -4319,13 +4331,18 @@ prepare_browse_data (void) + g_free (location); + + if (browse_options) ++ { + g_string_free (browse_options, TRUE); ++ browse_options = NULL; ++ } + + if (!attr) + break; + } + + fail: ++ if (browse_options) ++ g_string_free(browse_options, TRUE); + if (response) + ippDelete(response); + } +@@ -5759,7 +5776,9 @@ retrieve_default_printer(int local) + return (NULL); + } + p = buf; +- n = fscanf(fp, "%s", p); ++ n = fscanf(fp, "%1023s", p); ++ buf[1023] = '\0'; ++ + if (n == 1) + { + if (strlen(p) > 0) +@@ -6314,6 +6333,8 @@ get_local_queue_name(const char *service_name, + } + if (cluster) + { ++ if (local_queue_name) ++ free(local_queue_name); + local_queue_name = strdup(cluster->local_queue_name); + *is_cups_queue = 2; + free(str); +@@ -7685,6 +7706,22 @@ create_remote_printer_entry (const char *queue_name, + if (p->ipp_discoveries == NULL) + { + debug_printf("ERROR: Unable to allocate memory.\n"); ++ free(p->queue_name); ++ free(p->location); ++ free(p->info); ++ if (p->make_model) ++ free(p->make_model); ++ if (p->pdl) ++ free(p->pdl); ++ free(p->uri); ++ free(p->host); ++ if (p->ip) ++ free(p->ip); ++ free(resource); ++ free(service_name); ++ free(type); ++ free(domain); ++ free(p); + return (NULL); + } + if (domain != NULL && domain[0] != '\0' && +@@ -8453,6 +8490,8 @@ create_queue(void* arg) + current_time = time(NULL); + p->timeout = current_time + TIMEOUT_IMMEDIATELY; + cannot_create = 1; ++ free(loadedppd); ++ free(ppdfile); + goto end; + } + num_cluster_printers = 0; +@@ -8461,10 +8500,16 @@ create_queue(void* arg) + { + if (!strcmp(s->queue_name, p->queue_name)) + { +- if (s->status == STATUS_DISAPPEARED || ++ if (s->status == STATUS_DISAPPEARED || + s->status == STATUS_UNCONFIRMED || + s->status == STATUS_TO_BE_RELEASED) ++ { ++ if (ppdfile) ++ free(ppdfile); ++ if (loadedppd) ++ free(loadedppd); + goto end; ++ } + num_cluster_printers ++; + } + } +@@ -8599,7 +8644,12 @@ create_queue(void* arg) + // load balancing. In this case we will assign an + // implicitclass://... device URI, which makes cups-browsed find + // the best destination for each job. +- loadedppd = NULL; ++ if (loadedppd) ++ { ++ free(loadedppd); ++ loadedppd = NULL; ++ } ++ + if (cups_notifier != NULL && p->netprinter == 0) + { + // We are not an IPP network printer, so we use the device URI +@@ -11099,7 +11149,7 @@ resolve_callback(void* arg) + if (a->type) free((char*)a->type); + if (a->domain) free((char*)a->domain); + if (a->host_name) free((char*)a->host_name); +- if (a->txt) free(a->txt); ++ if (a->txt) avahi_string_list_free(a->txt); + if (a->address) free((AvahiAddress*)a->address); + free(a); + pthread_rwlock_unlock(&resolvelock); +@@ -11127,10 +11177,11 @@ resolver_wrapper(AvahiServiceResolver *r, + debug_printf("resolver_wrapper() in THREAD %ld\n", pthread_self()); + + resolver_args_t *arg = (resolver_args_t*)malloc(sizeof(resolver_args_t)); +- AvahiStringList* temp_txt = (AvahiStringList*)malloc(sizeof(AvahiStringList)); ++ AvahiStringList* temp_txt = NULL; + AvahiAddress* temp_addr = (AvahiAddress*)malloc(sizeof(AvahiAddress)); + +- temp_txt = avahi_string_list_copy(txt); ++ if (txt) ++ temp_txt = avahi_string_list_copy(txt); + + if (address) + { +@@ -11177,7 +11228,7 @@ resolver_wrapper(AvahiServiceResolver *r, + if (arg->type) free((char*)arg->type); + if (arg->domain) free((char*)arg->domain); + if (arg->host_name) free((char*)arg->host_name); +- if (arg->txt) free(arg->txt); ++ if (arg->txt) avahi_string_list_free(arg->txt); + if (arg->address) free((AvahiAddress*)arg->address); + free(arg); + return; +-- +2.39.2 + diff --git a/0001-configure.ac-cups-browsed-doesn-t-need-C.patch b/0001-configure.ac-cups-browsed-doesn-t-need-C.patch new file mode 100644 index 0000000..834d8a8 --- /dev/null +++ b/0001-configure.ac-cups-browsed-doesn-t-need-C.patch @@ -0,0 +1,56 @@ +From f481b848646c99d935b4dc300c87e5c3f049b9c3 Mon Sep 17 00:00:00 2001 +From: Zdenek Dohnal +Date: Thu, 2 Feb 2023 15:55:16 +0100 +Subject: [PATCH] configure.ac: cups-browsed doesn't need C++ + +--- + INSTALL | 7 +++---- + configure.ac | 5 +---- + 2 files changed, 4 insertions(+), 8 deletions(-) + +diff --git a/INSTALL b/INSTALL +index 7a2cf563..192ee5b1 100644 +--- a/INSTALL ++++ b/INSTALL +@@ -8,10 +8,9 @@ in "CHANGES.md". + + BEFORE YOU BEGIN + +- You'll need ANSI-compliant C and C++ compilers, plus a make program and +- POSIX-compliant shell (/bin/sh). The GNU compiler tools and Bash work well +- and we have tested the current CUPS code against several versions of GCC +- with excellent results. ++ You'll need ANSI-compliant C, plus a make program and POSIX-compliant ++ shell (/bin/sh). The GNU compiler tools and Bash work well and we have tested ++ the current CUPS code against several versions of GCC with excellent results. + + The Makefiles used by the project should work with most versions of make. + We've tested them with GNU make as well as the make programs shipped by +diff --git a/configure.ac b/configure.ac +index cf2ca1fa..c33ac7e3 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -19,7 +19,7 @@ m4_include([m4/ax_compare_version.m4]) + m4_include([m4/basic-directories.m4]) + AM_INIT_AUTOMAKE([1.11 gnu dist-xz dist-bzip2 subdir-objects foreign]) + AM_SILENT_RULES([yes]) +-AC_LANG([C++]) ++AC_LANG([C]) + AC_CONFIG_HEADERS([config.h]) + # Extra defines for the config.h + AH_BOTTOM([ +@@ -50,11 +50,8 @@ AH_BOTTOM([ + # Find required base packages + # =========================== + AC_PROG_CC +-AC_PROG_CXX +-AX_CXX_COMPILE_STDCXX([11],[noext],[mandatory]) + AM_PROG_CC_C_O + AM_ICONV +-AC_PROG_CPP + AC_PROG_INSTALL + AC_PROG_LN_S + AC_PROG_MAKE_SET +-- +2.39.1 + diff --git a/cups-browsed.spec b/cups-browsed.spec new file mode 100644 index 0000000..a54ebf4 --- /dev/null +++ b/cups-browsed.spec @@ -0,0 +1,185 @@ +%global _cup_serverbin %{_prefix}/lib/cups + +%if 0%{?fedora} +%bcond_without mdns +%else +%bcond_with mdns +%endif + + +Name: cups-browsed +Version: 2.0b3 +Release: 1%{?dist} +Summary: Daemon for local auto-installation of remote printers +# the CUPS exception text is the same as LLVM exception, so using that name with +# agreement from legal team +# https://lists.fedoraproject.org/archives/list/legal@lists.fedoraproject.org/message/A7GFSD6M3GYGSI32L2FC5KB22DUAEQI3/ +License: Apache-2.0 WITH LLVM-exception +URL: https://github.com/OpenPrinting/cups-browsed +Source0: %{URL}/archive/%{version}/%{name}-%{version}.tar.gz + + +# Patches +# https://github.com/OpenPrinting/cups-browsed/pull/4 +Patch0001: 0001-configure.ac-cups-browsed-doesn-t-need-C.patch +# https://github.com/OpenPrinting/cups-browsed/pull/6 +Patch0002: 0001-Coverity-fixes.patch + + +# remove once CentOS Stream 10 is released, cups-browsed +# was shipped in cups-filters before 2.0 +Conflicts: cups-filters < 2.0 + +# for generating configure and Makefile scripts in autogen.h +BuildRequires: autoconf +# for generating configure and Makefile scripts in autogen.h +BuildRequires: automake +# most filter functions written in C +BuildRequires: gcc +# for generating configure and Makefile scripts in autogen.h +BuildRequires: gettext-devel +# for autosetup +BuildRequires: git-core +# for generating configure and Makefile scripts in autogen.h +BuildRequires: libtool +# uses Makefiles +BuildRequires: make +# for pkg-config in configure and in SPEC file +BuildRequires: pkgconf-pkg-config +# for looking for devices on mDNS and their sharing on mDNS +BuildRequires: pkgconfig(avahi-client) +# for polling avahi +BuildRequires: pkgconfig(avahi-glib) +# uses CUPS and IPP API +BuildRequires: pkgconfig(cups) >= 2.2.2 +# uses cupsfilters API +BuildRequires: pkgconfig(libcupsfilters) >= 2.0b3 +# implicitclass uses libppd +BuildRequires: pkgconfig(libppd) >= 2.0b3 +# for dBUS proxy from GLib +BuildRequires: pkgconfig(glib-2.0) +# needed for systemd rpm macros in scriptlets +BuildRequires: systemd-rpm-macros + +%if %{with mdns} +# Avahi has to run for mDNS support +Recommends: avahi +# if set to browse or share mDNS, we need a resolver +Recommends: nss-mdns +%endif +# only recommends cups RPM in case someone wants to use CUPS container/SNAP +# - cups-browsed has to have a cupsd daemon to send requests to +# using a weak dep will work for bootstraping as well in case the old cups-filters +# 1.x, which is CUPS dependency, will be in repos when cups-browsed +Recommends: cups + +# requires cups directories +Requires: cups-filesystem + +Requires(post): systemd +Requires(preun): systemd +Requires(postun): systemd + + +%description +cups-browsed is a helper daemon, which automatically installs printers +locally, provides load balancing and clustering of print queues. +The daemon installs the printers based on found mDNS records and CUPS +broadcast, or by polling a remote print server. + + +%prep +%autosetup -S git + + +%build +# generate configuration/compilation files +./autogen.sh + +# --enable-auto-setup-driverless-only - enable autoinstalling of driverless IPP +# destinations +# --disable-saving-created-queues - don't save the queues during shutdown +# --disable-frequent-netif-update - don't update network interfaces after +# every found printer, update only on NM dBUS event +# --with-browseremoteprotocols - which protocols to use for looking for printers, default DNSSD and CUPS +# --with-remote-cups-local-queue-naming - use the name from remote server +# if polling the server for printers via BrowsePoll +%configure --enable-auto-setup-driverless-only\ + --disable-rpath\ + --disable-saving-created-queues\ + --disable-frequent-netif-update\ +%if %{without mdns} + --with-browseremoteprotocols=none\ +%endif + --with-remote-cups-local-queue-naming=RemoteName\ + --without-rcdir + +%make_build + + +%install +%make_install + +# systemd unit file +mkdir -p %{buildroot}%{_unitdir} +install -p -m 644 daemon/cups-browsed.service %{buildroot}%{_unitdir} + +# remove INSTALL file +rm -f %{buildroot}%{_pkgdocdir}/INSTALL + +# provided by cups-browsed dependency +rm -f %{buildroot}%{_pkgdocdir}/CHANGES-1.x.md + +# license related files are already under /usr/share/licenses +rm -f %{buildroot}%{_pkgdocdir}/{LICENSE,COPYING,NOTICE} + + +%check +make check + + +%post +%systemd_post cups-browsed.service + +# put UpdateCUPSQueuesMaxPerCall and PauseBetweenCUPSQueueUpdates into cups-browsed.conf +# for making cups-browsed work more stable for environments with many print queues +# remove this after 1-2 releases +for directive in "UpdateCUPSQueuesMaxPerCall" "PauseBetweenCUPSQueueUpdates" +do + found=`%{_bindir}/grep "^[[:blank:]]*$directive" %{_sysconfdir}/cups/cups-browsed.conf` + if [ -z "$found" ] + then + if [ "x$directive" == "xUpdateCUPSQueuesMaxPerCall" ] + then + %{_bindir}/echo "UpdateCUPSQueuesMaxPerCall 20" >> %{_sysconfdir}/cups/cups-browsed.conf + else + %{_bindir}/echo "PauseBetweenCUPSQueueUpdates 5" >> %{_sysconfdir}/cups/cups-browsed.conf + fi + fi +done + +%preun +%systemd_preun cups-browsed.service + +%postun +%systemd_postun_with_restart cups-browsed.service + + +%files +%license COPYING LICENSE NOTICE +%doc ABOUT-NLS AUTHORS CHANGES.md CONTRIBUTING.md DEVELOPING.md README.md +# implicitclass backend must be run as root +# https://github.com/OpenPrinting/cups-filters/issues/183#issuecomment-570196216 +%attr(0744,root,root) %{_cups_serverbin}/backend/implicitclass +# 2123809 - rpm -Va reports changes due %%post scriptlet (remove the verify part once we remove +# cups-browsed.conf update from %%post scriptlet) +%config(noreplace) %verify(not size filedigest mtime) %{_sysconfdir}/cups/cups-browsed.conf +%{_mandir}/man5/cups-browsed.conf.5.gz +%{_mandir}/man8/cups-browsed.8.gz +%{_sbindir}/cups-browsed +%{_unitdir}/cups-browsed.service + + +%changelog +* Thu Feb 02 2023 Zdenek Dohnal - 2.0b3-1 +- Initial import (fedora#2170547) diff --git a/sources b/sources new file mode 100644 index 0000000..655f0f6 --- /dev/null +++ b/sources @@ -0,0 +1 @@ +SHA512 (cups-browsed-2.0b3.tar.gz) = 3656fa070966db96e99cf1141bbeca75b9fe4664342014f94efc86affe26e2ad47919d878c5f4ab4b66d04b907ce2da8e6a1a959c03e6b120c2bc718ae785999