Skip to content

Stop manually managing http_t, use CUPS_HTTP_DEFAULT everywhere#64

Merged
tillkamppeter merged 22 commits intoOpenPrinting:masterfrom
Souptik-De:master
Mar 26, 2026
Merged

Stop manually managing http_t, use CUPS_HTTP_DEFAULT everywhere#64
tillkamppeter merged 22 commits intoOpenPrinting:masterfrom
Souptik-De:master

Conversation

@Souptik-De
Copy link
Copy Markdown

  • Remove p->http , All CUPS API calls
    now use CUPS_HTTP_DEFAULT, letting the library manage its own per-thread
    Unix domain socket connection to cupsd.

  • replace ensure_printer_connection()
    with ensure_dest_info() which only manages p->dinfo.

  • Also fix a memory leak in cups_get_Resolution which never
    freed its dinfo or closed its http_t.

…ket and add cupsFreeOptions and g_free for failure return paths
cupsCreateDestJob() was called with a manually managed http_t* from
cupsConnectDest(). This creates a TCP connection to the printer queue
where Local peer credential auth is impossible and Kerberos is
unavailable, causing a 401 Unauthorized when the CUPS policy requires
authentication.

Fix by using CUPS_HTTP_DEFAULT for all CUPS job I/O. This causes the
CUPS library to connect to cupsd via the Unix domain socket, where the
kernel automatically vouches for the caller's UID via peer credentials
(SO_PEERCRED), satisfying the authenticated policy without a password.

Also fix a thread safety bug: cupsStartDestDocument was called on the
main thread but cupsWriteRequestData and cupsFinishDestDocument were
called on the worker thread using the same http_t*. Since
CUPS_HTTP_DEFAULT is per-thread (stored in _cups_globals_t), all three
calls must be on the same thread. Move cupsStartDestDocument and
cupsCopyDestInfo into the worker thread alongside the data transfer
calls.
Remove p->http from PrinterCUPS and replace ensure_printer_connection()
with ensure_dest_info() which only manages p->dinfo. All CUPS API calls
now use CUPS_HTTP_DEFAULT, letting the library manage its own per-thread
Unix domain socket connection to cupsd.

Also fix a memory leak in cups_get_Resolution which never
freed its dinfo or closed its http_t.
Comment thread src/backend_helper.c Outdated
@tillkamppeter tillkamppeter merged commit 56a1596 into OpenPrinting:master Mar 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants