/*
- * "$Id: auth.c 7720 2008-07-11 22:46:21Z mike $"
+ * "$Id$"
*
- * Authentication functions for CUPS.
+ * Authentication functions for CUPS.
*
- * Copyright 2007-2012 by Apple Inc.
- * Copyright 1997-2007 by Easy Software Products.
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2007 by Easy Software Products.
*
- * This file contains Kerberos support code, copyright 2006 by
- * Jelmer Vernooij.
+ * This file contains Kerberos support code, copyright 2006 by
+ * Jelmer Vernooij.
*
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law. Distribution and use rights are outlined in the file "LICENSE.txt"
- * which should have been included with this file. If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file. If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
- * This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- * cupsDoAuthentication() - Authenticate a request.
- * _cupsSetNegotiateAuthString() - Set the Kerberos authentication string.
- * cups_gss_acquire() - Kerberos credentials callback.
- * cups_gss_getname() - Get CUPS service credentials for
- * authentication.
- * cups_gss_printf() - Show debug error messages from GSSAPI.
- * cups_local_auth() - Get the local authorization certificate if
- * available/applicable.
+ * This file is subject to the Apple OS-Developed Software exception.
*/
/*
/*
* 'cupsDoAuthentication()' - Authenticate a request.
*
- * This function should be called in response to a @code HTTP_UNAUTHORIZED@
+ * This function should be called in response to a @code HTTP_STATUS_UNAUTHORIZED@
* status, prior to resubmitting your request.
*
* @since CUPS 1.1.20/OS X 10.4@
DEBUG_printf(("2cupsDoAuthentication: authstring=\"%s\"",
http->authstring));
- if (http->status == HTTP_UNAUTHORIZED)
+ if (http->status == HTTP_STATUS_UNAUTHORIZED)
http->digest_tries ++;
return (0);
}
else if (localauth == -1)
{
- http->status = HTTP_AUTHORIZATION_CANCELED;
+ http->status = HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED;
return (-1); /* Error or canceled */
}
}
if ((password = cupsGetPassword2(prompt, http, method, resource)) == NULL)
{
- http->status = HTTP_AUTHORIZATION_CANCELED;
+ http->status = HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED;
return (-1);
}
snprintf(http->userpass, sizeof(http->userpass), "%s:%s", cupsUser(),
password);
}
- else if (http->status == HTTP_UNAUTHORIZED)
+ else if (http->status == HTTP_STATUS_UNAUTHORIZED)
http->digest_tries ++;
- if (http->status == HTTP_UNAUTHORIZED && http->digest_tries >= 3)
+ if (http->status == HTTP_STATUS_UNAUTHORIZED && http->digest_tries >= 3)
{
DEBUG_printf(("1cupsDoAuthentication: Too many authentication tries (%d)",
http->digest_tries));
- http->status = HTTP_AUTHORIZATION_CANCELED;
+ http->status = HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED;
return (-1);
}
if (_cupsSetNegotiateAuthString(http, method, resource))
{
- http->status = HTTP_AUTHORIZATION_CANCELED;
+ http->status = HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED;
return (-1);
}
}
{
DEBUG_printf(("1cupsDoAuthentication: Unknown auth type: \"%s\"",
www_auth));
- http->status = HTTP_AUTHORIZATION_CANCELED;
+ http->status = HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED;
return (-1);
}
* arbitrarily large credentials...
*/
- int authsize = 10 + /* "Negotiate " */
- output_token.length * 4 / 3 + 1 + /* Base64 */
- 1; /* nul */
+ int authsize = 10 + /* "Negotiate " */
+ (int)output_token.length * 4 / 3 + 1 + 1;
+ /* Base64 + nul */
httpSetAuthString(http, NULL, NULL);
- if ((http->authstring = malloc(authsize)) == NULL)
+ if ((http->authstring = malloc((size_t)authsize)) == NULL)
{
http->authstring = http->_authstring;
authsize = sizeof(http->_authstring);
strlcpy(http->authstring, "Negotiate ", authsize);
httpEncode64_2(http->authstring + 10, authsize - 10, output_token.value,
- output_token.length);
+ (int)output_token.length);
gss_release_buffer(&minor_status, &output_token);
}
int pid; /* Current process ID */
FILE *fp; /* Certificate file */
char trc[16], /* Try Root Certificate parameter */
- filename[1024], /* Certificate filename */
- certificate[33];/* Certificate string */
+ filename[1024]; /* Certificate filename */
_cups_globals_t *cg = _cupsGlobals(); /* Global data */
# if defined(HAVE_AUTHORIZATION_H)
OSStatus status; /* Status */
* Read the certificate from the file...
*/
- fgets(certificate, sizeof(certificate), fp);
+ char certificate[33], /* Certificate string */
+ *certptr; /* Pointer to certificate string */
+
+ certptr = fgets(certificate, sizeof(certificate), fp);
fclose(fp);
- /*
- * Set the authorization string and return...
- */
+ if (certptr)
+ {
+ /*
+ * Set the authorization string and return...
+ */
- httpSetAuthString(http, "Local", certificate);
+ httpSetAuthString(http, "Local", certificate);
- DEBUG_printf(("8cups_local_auth: Returning authstring=\"%s\"",
- http->authstring));
+ DEBUG_printf(("8cups_local_auth: Returning authstring=\"%s\"",
+ http->authstring));
- return (0);
+ return (0);
+ }
}
return (1);
/*
- * End of "$Id: auth.c 7720 2008-07-11 22:46:21Z mike $".
+ * End of "$Id$".
*/