Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libcups.so.2::cupsCreateJob failed on remote CUPS server ( client-error-not-found for Get-Printer-Attributes ) #586

Closed
chri50 opened this issue Jan 18, 2023 · 10 comments
Assignees
Labels
bug Something isn't working priority-low
Milestone

Comments

@chri50
Copy link

chri50 commented Jan 18, 2023

Hi, I am working on printing services using CUPS as printing backend and run into a problem and may ask for suggestions.

pls note: issue reported at: apple/cups#6100 as well.

Short: using libcups.so:2::cupsPrintFile to hand over print requests - this works fine on localhost.
Doing the same using identical remote CUPS server instead failed with client-error-not-found .
I am uncertain if i am doing something terribly wrong. From my point of view I would like to point out what went wrong and kindly ask for support.

host_ = any-non-local-ip
port_ = 1631 # using CUPS server compiled with --with-ipp-port=1631
cancel_ = FALSE
msec_to = 3000

All starts with cupsPrintFile
using http_t* httpConnect2(host_.data(),port_,NULL,AF_UNSPEC,HTTP_ENCRYPTION_IF_REQUESTED,TRUE,msec_to_,&cancel_); will come down to cupsCreateJob. cupsCreateJob will send three IPP requests to the remote CUPS server:

  1. dest = cupsGetNamedDest(http, name, NULL)

Response OK, as shared printer exists.

  1. info = cupsCopyDestInfo(http, dest)

based on dest second request failed with Returning IPP client-error-not-found for Get-Printer-Attributes (lpd://printer-ip/LPT1)
due do sending the request to the remote CUPS server but using CUPS_DEST_FLAGS_DEVICE and using the device-uri instead of printer-uri.

Log:

[Client ] 2.0 Get-Printer-Attributes 24
cupsdProcessIPPRequest(0x5588b1f3d510[3]): operation_id=000b(Get-Printer-Attributes)
cupsdProcessIPPRequest: operation-attributes-tag
cupsdProcessIPPRequest: attributes-charset charset 'utf-8'
cupsdProcessIPPRequest: attributes-natural-language naturalLanguage 'en-us'
cupsdProcessIPPRequest: printer-uri uri 'lpd://printer-ip/LPT1'
cupsdProcessIPPRequest: requesting-user-name nameWithoutLanguage 'root'
cupsdProcessIPPRequest: requested-attributes 1setOf keyword 'job-template,media-col-database,printer-description'
Get-Printer-Attributes lpd://printer-ip/LPT1
get_printer_attrs(0x5588b1f3d510[3], lpd://printer-ip/LPT1)
Get-Printer-Attributes client-error-not-found: The printer or class does not exist.
[Client ] Returning IPP client-error-not-found for Get-Printer-Attributes (lpd://printer-ip/LPT1) from...

In my case i would like to talk to the remote CUPS server.
Especially due to line:

cups/cups/dest-options.c

Lines 719 to 723 in d74a3d1

else if ((strcmp(http->hostname, cg->server) && cg->server[0] != '/') || cg->ipp_port != httpAddrPort(http->hostaddr))
{
DEBUG_printf(("1cupsCopyDestInfo: Connection to device (%s).", http->hostname));
dflags = CUPS_DEST_FLAGS_DEVICE;
}

Question: Is there any change to force or configure to do the second IPP request right?
Many thanks for any suggestions!

cups/cups/dest-options.c

Lines 706 to 728 in d74a3d1

if (!http)
{
DEBUG_puts("1cupsCopyDestInfo: Default server connection.");
http = _cupsConnect();
dflags = CUPS_DEST_FLAGS_NONE;
}
#ifdef AF_LOCAL
else if (httpAddrFamily(http->hostaddr) == AF_LOCAL)
{
DEBUG_puts("1cupsCopyDestInfo: Connection to server (domain socket).");
dflags = CUPS_DEST_FLAGS_NONE;
}
#endif /* AF_LOCAL */
else if ((strcmp(http->hostname, cg->server) && cg->server[0] != '/') || cg->ipp_port != httpAddrPort(http->hostaddr))
{
DEBUG_printf(("1cupsCopyDestInfo: Connection to device (%s).", http->hostname));
dflags = CUPS_DEST_FLAGS_DEVICE;
}
else
{
DEBUG_printf(("1cupsCopyDestInfo: Connection to server (%s).", http->hostname));
dflags = CUPS_DEST_FLAGS_NONE;
}

  1. status = cupsCreateDestJob(http, dest, info, &job_id, title, num_options, options)

up to here, only on locally used CUPS server as i guess AF_LOCAL will take affect.

@michaelrsweet
Copy link
Member

What version of CUPS are you using?

@chri50
Copy link
Author

chri50 commented Jan 19, 2023

Currently running version 2.2.13 of apple/cups and relevant behaviour may be seen as of version 2.2.12

Corresponding changes of file dest-options.c can be traced back to apple/cups#5587 and commit apple/cups@9b48d16
Refer to: apple/cups dest-options.c:622
and OpenPrinting/cups dest-options.c:719

Many thanks for any kind of advice!

Notes:
aware of that the original intent may be violated:
evaluation build of version 2.2.13 tested with success by comment out referred lines of file dest-options:622-626

@michaelrsweet
Copy link
Member

Please re-test against CUPS 2.4.x to see if this is still an issue for OpenPrinting CUPS. Otherwise it is up to Apple to fix in their legacy version of CUPS.

@chri50
Copy link
Author

chri50 commented Jan 20, 2023

Re-tested with OpenPrinting/cups#v2.4.2.
Unfortunately, same erroneous result as described before.

Log:

D [20/Jan/2023] [Client 6] 2.0 Get-Printer-Attributes 2
d [20/Jan/2023] cupsdProcessIPPRequest(0x55eed927ade0[6]): operation_id=000b(Get-Printer-Attributes)
d [20/Jan/2023] cupsdProcessIPPRequest: operation-attributes-tag
d [20/Jan/2023] cupsdProcessIPPRequest: attributes-charset charset 'utf-8'
d [20/Jan/2023] cupsdProcessIPPRequest: attributes-natural-language naturalLanguage 'en-us'
d [20/Jan/2023] cupsdProcessIPPRequest: printer-uri uri 'lpd://printer-ip/LPT1'
d [20/Jan/2023] cupsdProcessIPPRequest: requesting-user-name nameWithoutLanguage 'root'
d [20/Jan/2023] cupsdProcessIPPRequest: requested-attributes 1setOf keyword 'job-template,media-col-database,printer-description'
D [20/Jan/2023] Get-Printer-Attributes lpd://printer-ip/LPT1
d [20/Jan/2023] get_printer_attrs(0x55eed927ade0[6], lpd://printer-ip/LPT1)
D [20/Jan/2023] Get-Printer-Attributes client-error-not-found: The printer or class does not exist.
D [20/Jan/2023] [Client 6] Returning IPP client-error-not-found for Get-Printer-Attributes (lpd://printer-ip/LPT1) from...
D [20/Jan/2023] [Client 6] Content-Length: 130
D [20/Jan/2023] [Client 6] cupsdSendHeader: code=200, type="application/ipp", auth_type=0

If I am interpreting this line correctly OpenPrinting/cups dest-options.c:719

else if ((strcmp(http->hostname, cg->server) && cg->server[0] != '/') || cg->ipp_port != httpAddrPort(http->hostaddr))

use CUPS_DEST_FLAGS_DEVICE
if http->hostname is not equal to cg->server and cg->server listener is not a /path/to/domain/socket
or
if cg->ipp_port is not equal to http->hostaddr

Some thoughts:
What are the defaults or how are they defined: _cups_globals_t *cg = _cupsGlobals()
May i be able to set values by libcups:API to trigger intended behavior
What should i do, to handled requests/jobs always via CUPS-Scheduler

Many thanks for any kind of advice!

@zdohnal
Copy link
Member

zdohnal commented Mar 8, 2023

Hi @chri50 ,

what about setting a different CUPS server via cupsSetServer()? The all CUPS API functions should automatically work with remote CUPS instead of the local one (but beware of permissions - in case your user doesn't have some permissions on the server, you won't get a full access).

Either way you are trying to communicate with LPD printer via IPP protocol, which IMHO would not work unless you send the IPP request to printer's IPP port.

@zdohnal zdohnal added question General usage question waiting for reporter There are data requested from the reporter labels Mar 8, 2023
@chri50
Copy link
Author

chri50 commented Mar 10, 2023

Hi @zdohnal ,

thank you very much for your suggestions, I'll take this into account and keep this thread updated.

Short Addition:
My service never wants to communicate directly with a print device, instead the communication and any kind of protocol to any print device should be handled by a "central" CUPS service. This is fine if this "central" CUPS service is located on the same host as my service, but fails if this "central" CUPS service is located on any other host.

@michaelrsweet michaelrsweet added bug Something isn't working priority-low and removed question General usage question waiting for reporter There are data requested from the reporter labels Jun 2, 2023
@michaelrsweet michaelrsweet added this to the v2.4.x milestone Jun 2, 2023
@michaelrsweet
Copy link
Member

Near as I can tell, the code deciding whether to connect to the device or server isn't properly detecting things - clearly if that test fails then it should only connect to the device if it uses an IPP URI.

@michaelrsweet michaelrsweet self-assigned this Jun 2, 2023
@michaelrsweet
Copy link
Member

OK, so for 2.5 and later we really need to add a cups_dest_flags_t flags argument to this function since auto-detection isn't going to work well. WRT the current API, if the connected host and port matches the "device-uri" host and port, then use CUPS_DEST_FLAGS_DEVICE otherwise use CUPS_DEST_FLAGS_NONE.

@michaelrsweet
Copy link
Member

[2.4.x 2d5deb7] Fix cupsCopyDestInfo device connection detection (Issue #586)

[master 32a8b5f] Fix cupsCopyDestInfo device connection detection (Issue #586)

@michaelrsweet
Copy link
Member

[master 79eaf86] Add cupsCopyDestInfo2 API (Issue #586)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority-low
Projects
None yet
Development

No branches or pull requests

3 participants