Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

OpenBSD, web interface: authentication works, but not authorizationΒ #5166

Closed

Description

@ajacoutot

Hi.

I am running CUPS 2.2.6 on OpenBSD/amd64.
As a member or the wheel group (which is included in SystemGroup), I cannot manage printers over the web interface. External clients (like using the GNOME print dialog) works fine.
Here's an hopefully relevant extract from the cups error_log in debug mode.
Authentication works fine but I am puzzled by this entry: cupsdIsAuthorized: username="" which may be the reason for Returning HTTP Unauthorized for CUPS-Get-Devices (no URI) from localhost.

D [08/Nov/2017:18:01:54 +0100] [Client 116] Read: status=200, state=6
D [08/Nov/2017:18:01:54 +0100] [Client 116] Authorized as "ajacoutot" using Basic.
D [08/Nov/2017:18:01:54 +0100] [CGI] argv[0] = "/usr/local/libexec/cups/cgi-bin/admin.cgi"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[0] = "CUPS_CACHEDIR=/var/cache/cups"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[1] = "CUPS_DATADIR=/usr/local/share/cups"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[2] = "CUPS_DOCROOT=/usr/local/share/doc/cups"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[3] = "CUPS_FONTPATH=/usr/local/share/cups/fonts"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[4] = "CUPS_REQUESTROOT=/var/spool/cups"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[5] = "CUPS_SERVERBIN=/usr/local/libexec/cups"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[6] = "CUPS_SERVERROOT=/etc/cups"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[7] = "CUPS_STATEDIR=/var/run/cups"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[8] = "HOME=/var/spool/cups/tmp"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[9] = "PATH=/usr/local/libexec/cups/filter:/usr/local/bin:/usr/local/sbin:/bin:/usr/bin"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[10] = "SERVER_ADMIN=root@peck.home.bsdfrog.org"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[11] = "SOFTWARE=CUPS/2.2.6"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[12] = "TMPDIR=/var/spool/cups/tmp"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[13] = "USER=root"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[14] = "CUPS_MAX_MESSAGE=2047"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[15] = "CUPS_SERVER=/var/run/cups/cups.sock"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[16] = "CUPS_ENCRYPTION=IfRequested"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[17] = "IPP_PORT=631"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[18] = "AUTH_TYPE=Basic"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[19] = "LANG=en_US.UTF8"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[20] = "REDIRECT_STATUS=1"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[21] = "GATEWAY_INTERFACE=CGI/1.1"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[22] = "SERVER_NAME=localhost"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[23] = "SERVER_PORT=631"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[24] = "REMOTE_ADDR=127.0.0.1"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[25] = "REMOTE_HOST=localhost"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[26] = "SCRIPT_NAME=/admin/"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[27] = "SCRIPT_FILENAME=/usr/local/share/doc/cups/admin/"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[28] = "REMOTE_USER=ajacoutot"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[29] = "SERVER_PROTOCOL=HTTP/1.1"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[30] = "HTTP_COOKIE=_ga=GA1.1.129303679.1495441594; org.cups.sid=f5d732a2ec61b2eaed7720c4d12c5b3f; cookieconsent_status=dismiss; _ga=GA1.1.129303679.1495441594"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[31] = "HTTP_USER_AGENT=Mozilla/5.0 (X11; OpenBSD amd64; rv:56.0) Gecko/20100101 Firefox/56.0"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[32] = "HTTP_REFERER=http://localhost:631/admin"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[33] = "REQUEST_METHOD=POST"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[34] = "CONTENT_LENGTH=60"
D [08/Nov/2017:18:01:54 +0100] [CGI] envp[35] = "CONTENT_TYPE=application/x-www-form-urlencoded"
D [08/Nov/2017:18:01:54 +0100] cupsdAddCert: Adding certificate for PID 89333
D [08/Nov/2017:18:01:54 +0100] [CGI] Started /usr/local/libexec/cups/cgi-bin/admin.cgi (PID 89333)
I [08/Nov/2017:18:01:54 +0100] [Client 116] Started "/usr/local/libexec/cups/cgi-bin/admin.cgi" (pid=89333, file=15)
D [08/Nov/2017:18:01:54 +0100] [Client 116] Waiting for CGI data.
D [08/Nov/2017:18:01:54 +0100] [CGI] admin.cgi started...
D [08/Nov/2017:18:01:54 +0100] cupsdSetBusyState: newbusy="Active clients and dirty files", busy="Active clients and dirty files"
D [08/Nov/2017:18:01:54 +0100] [Client 117] Server address is "/var/run/cups/cups.sock".
D [08/Nov/2017:18:01:54 +0100] [Client 117] Accepted from localhost (Domain)
D [08/Nov/2017:18:01:54 +0100] [Client 117] Waiting for request.
D [08/Nov/2017:18:01:54 +0100] [CGI] http=0x146728c9000
D [08/Nov/2017:18:01:54 +0100] [CGI] cgiSetVariable: SECTION="admin"
D [08/Nov/2017:18:01:54 +0100] [CGI] cgiSetVariable: REFRESH_PAGE=""
D [08/Nov/2017:18:01:54 +0100] [CGI] org.cups.sid cookie is "f5d732a2ec61b2eaed7720c4d12c5b3f"
D [08/Nov/2017:18:01:54 +0100] [CGI] cgiSetVariable: org.cups.sid="f5d732a2ec61b2eaed7720c4d12c5b3f"
D [08/Nov/2017:18:01:54 +0100] [CGI] cgiSetVariable: OP="add-printer"
D [08/Nov/2017:18:01:54 +0100] [CGI] op="add-printer"...
D [08/Nov/2017:18:01:54 +0100] [CGI] do_am_printer: DEVICE_URI="(null)"
D [08/Nov/2017:18:01:54 +0100] [CGI] Getting list of devices...
D [08/Nov/2017:18:01:54 +0100] [Client 117] POST / HTTP/1.1
D [08/Nov/2017:18:01:54 +0100] cupsdSetBusyState: newbusy="Active clients and dirty files", busy="Active clients and dirty files"
D [08/Nov/2017:18:01:54 +0100] [Client 117] Read: status=200, state=6
D [08/Nov/2017:18:01:54 +0100] [Client 117] No authentication data provided.
D [08/Nov/2017:18:01:54 +0100] [Client 117] Read: status=100, state=6
D [08/Nov/2017:18:01:54 +0100] [Client 117] Read: status=100, state=6
D [08/Nov/2017:18:01:54 +0100] [Client 117] Read: status=100, state=6
D [08/Nov/2017:18:01:54 +0100] [Client 117] Read: status=100, state=6
D [08/Nov/2017:18:01:54 +0100] [Client 117] 2.0 CUPS-Get-Devices 1
D [08/Nov/2017:18:01:54 +0100] CUPS-Get-Devices
D [08/Nov/2017:18:01:54 +0100] cupsdIsAuthorized: username=""
D [08/Nov/2017:18:01:54 +0100] [Client 117] Returning HTTP Unauthorized for CUPS-Get-Devices (no URI) from localhost
D [08/Nov/2017:18:01:54 +0100] [Client 117] cupsdSendHeader: code=401, type="text/html", auth_type=0
D [08/Nov/2017:18:01:54 +0100] [Client 117] WWW-Authenticate: Basic realm="CUPS", trc="y"
D [08/Nov/2017:18:01:54 +0100] [Client 117] HTTP_STATE_WAITING Closing for error 32 (Broken pipe)
D [08/Nov/2017:18:01:54 +0100] [Client 117] Closing connection.

Activity

  1. ajacoutot commented on Nov 8, 2017

    @ajacoutot
    Author

    I forgot to mention that it works fine as the root user.

  2. michaelrsweet commented on Nov 8, 2017

    @michaelrsweet
    Contributor

    Hmm, it should be getting the local authentication certificate from the certs directory - can you attach your /etc/cups/cups-files.conf file? I'm wondering if something is messed up with the directory used for passing credentials to the CGI programs?

  3. ajacoutot commented on Nov 9, 2017

    @ajacoutot
    Author

    Sure, here you go.

    cups-files.conf.txt

  4. michaelrsweet commented on Nov 9, 2017

    @michaelrsweet
    Contributor

    OK, that looks pretty standard, so can you send me the output of:

    ls -ld /var/run
    ls -ld /var/run/cups
    ls -ld /var/run/cups/certs
    

    The certs directory is the one the CGI programs will need to be able to access...

  5. ajacoutot commented on Nov 9, 2017

    @ajacoutot
    Author

    Here you go:

    # ls -ld /var/run/{,cups/{,certs}}
    drwxr-xr-x  9 root   wheel  512 Nov  9 11:50 /var/run/
    drwxr-xr-x  3 root   _cups  512 Nov  9 10:24 /var/run/cups/
    dr-x--x--x  2 _cups  wheel  512 Nov  9 13:20 /var/run/cups/certs
    
  6. michaelrsweet commented on Nov 9, 2017

    @michaelrsweet
    Contributor

    OK, that should be enough for the CGIs to get the local certs... Alright, try enabling debug2 logging ("cupsctl LogLevel=debug2") and see what is coming from the CGI Get-Devices request...

  7. self-assigned this
    on Nov 9, 2017
  8. ajacoutot commented on Nov 9, 2017

    @ajacoutot
    Author

    Here's the error log. I really don't understand what is going on :-/ ...
    cups-debug2-log.txt

  9. michaelrsweet commented on Nov 9, 2017

    @michaelrsweet
    Contributor

    So the new log shows admin.cgi getting run and then the CUPS-Get-Devices operation being done over a domain socket which (correctly) gets the logged-in credentials from the cert cache, but then it thinks that ajacoutot is not a member of group wheel...

    Can you verify that your user account is, in fact, listed in /etc/groups for the wheel account?

  10. ajacoutot commented on Nov 9, 2017

    @ajacoutot
    Author

    It is :-)

    $ id
    uid=1000(ajacoutot) gid=1000(ajacoutot) groups=1000(ajacoutot), 0(wheel), 9(wsrc), 10(users), 21(wobj)
    $ grep wheel /etc/group                                        
    wheel:*:0:root,ajacoutot
    

    At least I have a better hint of where to look at in the code..

  11. michaelrsweet commented on Nov 9, 2017

    @michaelrsweet
    Contributor

    Well, the CUPS group lookup code is not seeing it - are you using LDAP or other network account stuff on this system? Something that might prevent /etc/group from being the first to get looked up?

  12. ajacoutot commented on Nov 9, 2017

    @ajacoutot
    Author

    Nope, only using flat files. No external authentication.
    I'll start digging in the code in a few...

  13. ajacoutot commented on Nov 9, 2017

    @ajacoutot
    Author

    group->gr_gid looks corrupted somehow. If I print "group->gr_gid groups[i]", I have the following in the logs:

    E [09/Nov/2017:18:41:33 +0100] 724 0
    E [09/Nov/2017:18:41:33 +0100] 724 9
    E [09/Nov/2017:18:41:33 +0100] 724 10
    E [09/Nov/2017:18:41:33 +0100] 724 21
    
  14. ajacoutot commented on Nov 10, 2017

    @ajacoutot
    Author

    Ok I found the cullprit. Our getgrouplist(3) implementation has a documented bug:

    BUGS
         The getgrouplist() function uses the routines based on getgrent(3).  If
         the invoking program uses any of these routines, the group structure will
         be overwritten in the call to getgrouplist().
    

    So the solution would be to either:

    • only check for getgrouplist in configure if we are not OpenBSD (or force disable it)
    • call getgrnam(3) again on OpenBSD after the call to getgrouplist
      I just tested this patch and it works:
    Index: scheduler/auth.c
    --- scheduler/auth.c.orig
    +++ scheduler/auth.c
    @@ -1192,6 +1192,12 @@ cupsdCheckGroup(
     #  else
           getgrouplist(username, user->pw_gid, groups, &ngroups);
     #endif /* __APPLE__ */
    +
    +/* On OpenBSD, getgrouplist overwrites the group structure */
    +#  ifdef __OpenBSD__
    +      group = getgrnam(groupname);
    +      endgrent();
    +#  endif
    
           for (i = 0; i < ngroups; i ++)
             if ((int)group->gr_gid == (int)groups[i])
    

    I'd rather not open a pull request until you advise me what you prefered solution would be.
    Thank you @michaelrsweet

  15. michaelrsweet commented on Nov 10, 2017

    @michaelrsweet
    Contributor

    OK, just pushed some changes to auth.c that copy the gr_gid value so that we don't care that the group structure has been overwritten. Try this:

    [master 3637469] Workaround getgrouplist group data overwrite bug on OpenBSD (Issue #5166)

  16. added this to the milestone on Nov 10, 2017
  17. ajacoutot commented on Nov 10, 2017

    @ajacoutot
    Author

    Works like a charm \o/
    Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions