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.

Kerberos authentication fails with large tickets #2695

Closed

Description

@michaelrsweet

Version: 1.3-current
CUPS.org User: prefect

Kerberos authentication is likely to fail with Active Directory tickets due to their relatively large size, and limited allowed sizes within CUPS.

A fix has already been made to cups/auth.c, but cupsdSendHeader() in scheduler/client.c looks to be similarly restricted, as it looks like it uses a 2048 byte buffer.

I also wasn't sure whether you wanted to lose the test for the token length being zero from cups/auth.c.

Here's a patch as a starting point anyhows.

Activity

  1. michaelrsweet commented on Jan 30, 2008

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: mike

    Your patch wouldn't compile, but I changed the cupsd code to allocate the buffer and keep it around for the life of the scheduler, resizing as needed, so we aren't allocating and freeing all the time. The code includes an error message for tokens larger than 64k so it will be possible to debug size problems more easily.

    I also added a 0-length token check to the client side - not strictly necessary, but there is no sense sending a 0-length token...

  2. michaelrsweet commented on Jan 30, 2008

    @michaelrsweet
    ContributorAuthor

    "patch":

    Index: scheduler/client.c

    --- scheduler/client.c (revision 7271)
    +++ scheduler/client.c (working copy)
    @@ -2478,12 +2478,17 @@

    • non-401 replies...
      */
    • if (con->gss_output_token.length > 0)
    • if (con->gss_output_token.length > 0 && con->gss_output_token.length < 65536)
      {
    • char buf[2048]; /* Output token buffer */
    • char buf; / Output token buffer /
      OM_uint32 minor_status; /
      Minor status code */
    • int authsize = 10 + /* "Negotiate " */
    •               output_token.length \* 4 / 3 + 1 +  /\* Base64 */
      
    •               1;                                 /* null */
      
    • buf = malloc(authsize);

    httpEncode64_2(buf, sizeof(buf),
    con->gss_output_token.value,
    con->gss_output_token.length);
    @@ -2493,7 +2498,11 @@
    "cupsdSendHeader: WWW-Authenticate: Negotiate %s", buf);

    if (httpPrintf(HTTP(con), "WWW-Authenticate: Negotiate %s\r\n", buf) < 0)

    • {
    •  free(buf);
      
      return (0);
    • }
    • free(buf);
      }
      #endif /* HAVE_GSSAPI */
  3. michaelrsweet commented on Jan 30, 2008

    @michaelrsweet
    ContributorAuthor

    "str2695.patch":

    Index: cups/auth.c

    --- cups/auth.c (revision 7271)
    +++ cups/auth.c (working copy)
    @@ -300,7 +300,7 @@
    if (major_status == GSS_S_CONTINUE_NEEDED)
    DEBUG_gss_printf(major_status, minor_status, "Continuation needed!");

    • if (output_token.length < 65536)
    • if (output_token.length > 0 && output_token.length <= 65536)
      {
      /*
    • Allocate the authorization string since Windows KDCs can have
      Index: scheduler/client.c

      --- scheduler/client.c (revision 7271)
      +++ scheduler/client.c (working copy)
      @@ -2369,7 +2369,11 @@
      char type, / I - MIME type of document /
      int auth_type) /
      I - Type of authentication */
      {
    • char auth_str[1024]; /* Authorization string */
    • char auth_str[1024]; /* Authorization string */
      +#ifdef HAVE_GSSAPI
    • static char gss_buf = NULL; / Kerberos auth data buffer */
    • static int gss_bufsize = 0; /* Size of Kerberos auth data buffer /
      +#endif /
      HAVE_GSSAPI */

    /*
    @@ -2478,23 +2482,57 @@

    • non-401 replies...
      */
    • if (con->gss_output_token.length > 0)
    • if (con->gss_output_token.length > 0 && con->gss_output_token.length <= 65536)
      {
    • char buf[2048]; /* Output token buffer /
      OM_uint32 minor_status; /
      Minor status code */
    • int bufsize; /* Size of output token buffer */
    • httpEncode64_2(buf, sizeof(buf),
    •              con->gss_output_token.value,
      
    • bufsize = con->gss_output_token.length * 4 / 3 + 2;
    • if (bufsize > gss_bufsize)
    • {
    •  char _buf;           /_ New buffer */
      
    •  bufsize = (bufsize + 1023) & 1023;/\* Round up */
      
    •  if (gss_buf)
      
    •    buf = realloc(gss_buf, bufsize);
      
    •  else
      
    •    buf = malloc(bufsize);
      
    •  if (!buf)
      
    •  {
      
    • cupsdLogMessage(CUPSD_LOG_ERROR,
    •       "Unable to allocate %d bytes for Kerberos credentials!",
      
    •       bufsize);
      
    • return (0);
    •  }
      
    •  gss_buf     = buf;
      
    •  gss_bufsize = bufsize;
      
    • }
    • httpEncode64_2(gss_buf, gss_bufsize,

    •      con->gss_output_token.value,
         con->gss_output_token.length);
      

      gss_release_buffer(&minor_status, &con->gss_output_token);

      cupsdLogMessage(CUPSD_LOG_DEBUG,

    •                "cupsdSendHeader: WWW-Authenticate: Negotiate %s", buf);
      
    •       "cupsdSendHeader: WWW-Authenticate: Negotiate %s", gss_buf);
      
    • if (httpPrintf(HTTP(con), "WWW-Authenticate: Negotiate %s\r\n", buf) < 0)

    • if (httpPrintf(HTTP(con), "WWW-Authenticate: Negotiate %s\r\n",

    •               gss_buf) < 0)
      

      return (0);
      }

    • else if (con->gss_output_token.length > 65536)

    • {

    • cupsdLogMessage(CUPSD_LOG_ERROR,

    •                "Kerberos credentials larger than 64k (%d)!",
      
    •       con->gss_output_token.length);
      
    • return (0);

    • }
      #endif /* HAVE_GSSAPI */

      if (con->language && strcmp(con->language->language, "C"))

  4. added this to the Stable milestone on Mar 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions