zdohnal [Fri, 18 Jun 2021 10:27:53 +0000 (12:27 +0200)]
cups-browsed.c: Make NotifLeaseDuration configurable and renew after half the lease duration not 60 sec before end
1) NotifLeaseDuration directive for cups-browsed.conf - it will make
lease duration for notifications configurable by users. IMO it is not
useful for regular users, but it is helpful during sanity testing
(for verifying that we actually renew the subscription when time
comes). The current hardcoded 1 day is unusuable for that :( .
I implemented the lowest threshold to 300s to prevent a possible DoS.
2) Subscription renewal is set to happen in the middle of NotifLeaseDuration,
not one minute before lease expiration. This was a problem on busy servers,
where cups-browsed was busy and wasn't able to renew the subscription
before cupsd removed it. Then if some jobs had come before the subscription
was created again, the queue got disabled. The proposed approach is based
on behavior of DHCP.
cups-browsed: Lock before all 'examine_discovered_printer_record()' (#364)
The current code doesn't use rwlock in found_cups_printer() and
cupsdUpdateLDAPBrowse(), which causes deadlock when discovering queues
via BrowsePoll or LDAP.
It happens because the code in 'examine_discovered_printer_record()'
expects the rwlock to be locked already, so it unlocks the lock, calls
'get_local_queue_name()' and locks again.
The commit contains change '&(lock)' -> '&lock' too, it represents the
same thing, so we should use the same code for it.
cups-browsed can be set to browsepolling remote servers, browsing remote
queues via CUPS protocol or sharing local queues via CUPS protocol.
Although sharing and browsing happens via browsesocket (which can be
solved by setting socket option IP_FREEBIND), browsepolling must have
network working to communicate with a remote server.
Zdenek Dohnal [Mon, 23 Nov 2020 13:53:37 +0000 (14:53 +0100)]
cups-browsed.c: Fix conditional jumps based on uninitialized value
Strings added with IPP_TAG_MIMETYPE and IPP_TAG_KEYWORD tags use uninitialized
buffers, which causes random behavior. The buffers can be initialized via f.e.
'snprintf()'.
Zdenek Dohnal [Mon, 23 Nov 2020 13:47:15 +0000 (14:47 +0100)]
cups-browsed.c: Fix nickname pointer memory leak
This memory leak was caused by losing the original pointer to allocated memory and
trying to free incomplete pointer. The fix reimplements acquiring of nickname
algorithm and allocates the precise memory for nickname. In case of error, the algorithm
reports an warning into debug log and continue with reading from PPD.
Zdenek Dohnal [Mon, 23 Nov 2020 13:34:04 +0000 (14:34 +0100)]
ppdgenerator.c: Free printer_sizes array
We need to free 'printer_sizes', which is allocated in 'ppdCreateFromIPP2()', instead of
'sizes', which is passed as a parameter - because it solves a memory leak and it doesn't
leave an invalid pointer.
It looks like 'get_cluster_attributes()' needs to be called earlier than where it is now,
because the code checks 'printer_attributes' (where is the result of 'get_cluster_attributes()'
for clustered queues) before the first 'get_cluster_attributes()' right now, which looks like
an error. So the fix moves the 'get_cluster_attributes()' call before the first 'printer_attributes'
query.
Zdenek Dohnal [Mon, 23 Nov 2020 13:01:34 +0000 (14:01 +0100)]
cups-browsed.c: Add tagzero attributes as IPP_TAG_KEYWORD
These attributes were added previously ass IPP_CONST_TAG(IPP_TAG_KEYWORD), which causes a problem
during 'ippDelete()' - const strings are not freed during 'ippDelete', which causes memory leaks,
because we send allocated strings into 'ippAddStrings'.
I chose this solution instead of defining a new function for freeing ipp_t struct, please let me
know if it is acceptable.
The code leaks res_t struct in several places:
- if struct is added to CUPS array, which is defined with copy_resolution() as a copy function.
copy_resolution() uses calloc(), so the original allocated res_t can be freed. The resolution
functions are used in cups-browsed.c, so 'free_resolution()' has to be available outside in header
file.
- overwritting previously allocated pointer with a new one in 'on_job_state()'
Pranav Batra [Fri, 13 Nov 2020 08:25:48 +0000 (08:25 +0000)]
cups-filters: Fix foomatic-rip infinite loop
If the foomatic rip command is not present in the PPD file, the foomatic
rip filter runs cat by default to forward stdin to stdout. However,
if input is provided through a file instead of stdin, then this file
needs to be dup'd to stdin for the command to work properly.
Also, the next file needs to be selected each time an input file is
processed by calling strok_r in order to prevent an infinite loop.