OpenPrinting / cups

OpenPrinting CUPS Sources
https://openprinting.github.io/cups
Apache License 2.0
1.05k stars 187 forks source link

can not print if authentication is necessary ? #947

Closed xiaowen581 closed 5 months ago

xiaowen581 commented 5 months ago

Describe the bug

Can not print if using a printer which authentication is necessary. (I think it's a normal use case but can not resolve it, apologize if I use CUPS in a wrong way ...)

To Reproduce

Printer: Brother with Basic/Digest authentication on.

Steps to reproduce the behavior in COMMAND way

  1. use lpadmin command to add local print queue(everywhere or ppd) with [device URI]
  2. use lp command to print. (lp -d [printer_name] [file] -U [username])

or the API way:

  1. use lpadmin command to add printer (everywhere or ppd) with [device URI]
  2. use cupsGetNamedDest to get [printer_name]'s dest
  3. use cupsSetUser and cupsSetPasswordCB2 to provide username and password
  4. use cupsCreateDestJob & cupsStartDestDocument & cupsWriteRequestData & cupsFinishDestDocument to send a job

in COMMAND way Unless I added my credentials to the device URI in [ipp://user:pass@PRINTER_IP/ipp/print] format which is not recommended for obvious reasons( #660 ), I have no chance to input the password.

in API way Even if I set the password_cb using cupsSetPasswordCB2, it won't work. Since the current password callback function is tracked separately for each thread in a program. I set the cupsSetPasswordCB2 to my APP but it won't affect the cupsd ... so is there any way to let the cupsd to use the correct username & password?

System Information:

OS and its version: Ubuntu 20
Application: lp, lpadmin, cupsd
CUPS version : 2.4.2

Additional context

in this case, [Job 86] used the default password_cb and finally fall to "held for authentication".


[Job 86] password_cb(prompt=\"Password for guest on BRNB42200C5A48E.local? \", http=0x559d1fc87ed0, method=\"POST\", resource=\"/ipp/print\", password_tries=0x7fff6d2c5cec(0)), password=(nil) [Job 86] ATTR: auth-info-default=\'\"guest\"\', [Job 86] Job held for authentication.


error_log.log image

xiaowen581 commented 5 months ago

After studying the related code of CUPS, I learned that the IPP backend supports two methods for passing username and password:

Method 1: User:password included in the device URI. Method 2: Obtain AUTH_USERNAME and AUTH_PASSWORD from environment variables.

In Method 1, the device URI is determined when logging into the printer via lpadmin, which is not suitable for our application (we want multiple users to use the same local permanent printer and authenticate different users through the printer's authentication feature).

Using Method 2, adding [ATTR text "auth-info" USERNAME, PASSWORD] in the ".test" file for ipptool successfully conducted printing.

{ 
    VERSION 2.0 
    OPERATION Print-Job 
    REQUEST-ID 42 
    GROUP operation-attributes-tag 
    ATTR charset "attributes-charset" "utf-8" 
    ATTR naturalLanguage "attributes-natural-language" "en" 
    ATTR uri "printer-uri" "ipp://localhost:631/printers/brother_auth" 
    ATTR name "requesting-user-name" "root" 
    ATTR mimeMediaType "document-format" "image/png" 
    ATTR text "auth-info" "ABC", "0001" 
    FILE "/home/user/print_test.png" 
}

Although "auth-info" appears to be an undocumented feature, I cannot find a more appropriate method to implement authentication for a remote printer.

xiaowen581 commented 5 months ago

It doesn't look like a "issue", so moving it to "discussions"...