4 * Authentication functions for CUPS.
6 * Copyright 2007-2012 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products.
9 * This file contains Kerberos support code, copyright 2006 by
12 * These coded instructions, statements, and computer programs are the
13 * property of Apple Inc. and are protected by Federal copyright
14 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
15 * which should have been included with this file. If this file is
16 * file is missing or damaged, see the license at "http://www.cups.org/".
18 * This file is subject to the Apple OS-Developed Software exception.
22 * cupsDoAuthentication() - Authenticate a request.
23 * _cupsSetNegotiateAuthString() - Set the Kerberos authentication string.
24 * cups_gss_acquire() - Kerberos credentials callback.
25 * cups_gss_getname() - Get CUPS service credentials for
27 * cups_gss_printf() - Show debug error messages from GSSAPI.
28 * cups_local_auth() - Get the local authorization certificate if
29 * available/applicable.
33 * Include necessary headers...
36 #include "cups-private.h"
39 #if defined(WIN32) || defined(__EMX__)
43 #endif /* WIN32 || __EMX__ */
45 #if HAVE_AUTHORIZATION_H
46 # include <Security/Authorization.h>
47 # ifdef HAVE_SECBASEPRIV_H
48 # include <Security/SecBasePriv.h>
50 extern const char *cssmErrorString(int error
);
51 # endif /* HAVE_SECBASEPRIV_H */
52 #endif /* HAVE_AUTHORIZATION_H */
54 #if defined(SO_PEERCRED) && defined(AF_LOCAL)
56 #endif /* SO_PEERCRED && AF_LOCAL */
64 # ifdef HAVE_GSS_ACQUIRE_CRED_EX_F
65 # ifdef HAVE_GSS_GSSAPI_SPI_H
66 # include <GSS/gssapi_spi.h>
68 # define GSS_AUTH_IDENTITY_TYPE_1 1
69 # define gss_acquire_cred_ex_f __ApplePrivate_gss_acquire_cred_ex_f
70 typedef struct gss_auth_identity
77 gss_buffer_t
*credentialsRef
;
78 } gss_auth_identity_desc
;
79 extern OM_uint32
gss_acquire_cred_ex_f(gss_status_id_t
, const gss_name_t
,
80 OM_uint32
, OM_uint32
, const gss_OID
,
81 gss_cred_usage_t
, gss_auth_identity_t
,
82 void *, void (*)(void *, OM_uint32
,
87 # endif /* HAVE_GSS_GSSAPI_SPI_H */
88 # include <dispatch/dispatch.h>
89 typedef struct _cups_gss_acquire_s
/* Acquire callback data */
91 dispatch_semaphore_t sem
; /* Synchronization semaphore */
92 OM_uint32 major
; /* Returned status code */
93 gss_cred_id_t creds
; /* Returned credentials */
94 } _cups_gss_acquire_t
;
96 static void cups_gss_acquire(void *ctx
, OM_uint32 major
,
97 gss_status_id_t status
,
98 gss_cred_id_t creds
, gss_OID_set oids
,
100 # endif /* HAVE_GSS_ACQUIRE_CRED_EX_F */
101 static gss_name_t
cups_gss_getname(http_t
*http
, const char *service_name
);
103 static void cups_gss_printf(OM_uint32 major_status
, OM_uint32 minor_status
,
104 const char *message
);
106 # define cups_gss_printf(major, minor, message)
108 #endif /* HAVE_GSSAPI */
109 static int cups_local_auth(http_t
*http
);
113 * 'cupsDoAuthentication()' - Authenticate a request.
115 * This function should be called in response to a @code HTTP_UNAUTHORIZED@
116 * status, prior to resubmitting your request.
118 * @since CUPS 1.1.20/OS X 10.4@
121 int /* O - 0 on success, -1 on error */
122 cupsDoAuthentication(
123 http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
124 const char *method
, /* I - Request method ("GET", "POST", "PUT") */
125 const char *resource
) /* I - Resource path */
127 const char *password
, /* Password string */
128 *www_auth
; /* WWW-Authenticate header */
129 char prompt
[1024], /* Prompt for user */
130 realm
[HTTP_MAX_VALUE
], /* realm="xyz" string */
131 nonce
[HTTP_MAX_VALUE
]; /* nonce="xyz" string */
132 int localauth
; /* Local authentication result */
133 _cups_globals_t
*cg
; /* Global data */
136 DEBUG_printf(("cupsDoAuthentication(http=%p, method=\"%s\", resource=\"%s\")",
137 http
, method
, resource
));
140 http
= _cupsConnect();
142 if (!http
|| !method
|| !resource
)
145 DEBUG_printf(("2cupsDoAuthentication: digest_tries=%d, userpass=\"%s\"",
146 http
->digest_tries
, http
->userpass
));
147 DEBUG_printf(("2cupsDoAuthentication: WWW-Authenticate=\"%s\"",
148 httpGetField(http
, HTTP_FIELD_WWW_AUTHENTICATE
)));
151 * Clear the current authentication string...
154 httpSetAuthString(http
, NULL
, NULL
);
157 * See if we can do local authentication...
160 if (http
->digest_tries
< 3)
162 if ((localauth
= cups_local_auth(http
)) == 0)
164 DEBUG_printf(("2cupsDoAuthentication: authstring=\"%s\"",
167 if (http
->status
== HTTP_UNAUTHORIZED
)
168 http
->digest_tries
++;
172 else if (localauth
== -1)
174 http
->status
= HTTP_AUTHORIZATION_CANCELED
;
175 return (-1); /* Error or canceled */
180 * Nope, see if we should retry the current username:password...
183 www_auth
= http
->fields
[HTTP_FIELD_WWW_AUTHENTICATE
];
185 if ((http
->digest_tries
> 1 || !http
->userpass
[0]) &&
186 (!_cups_strncasecmp(www_auth
, "Basic", 5) ||
187 !_cups_strncasecmp(www_auth
, "Digest", 6)))
190 * Nope - get a new password from the user...
193 char default_username
[HTTP_MAX_VALUE
];
194 /* Default username */
198 if (!cg
->lang_default
)
199 cg
->lang_default
= cupsLangDefault();
201 if (httpGetSubField(http
, HTTP_FIELD_WWW_AUTHENTICATE
, "username",
203 cupsSetUser(default_username
);
205 snprintf(prompt
, sizeof(prompt
),
206 _cupsLangString(cg
->lang_default
, _("Password for %s on %s? ")),
208 http
->hostname
[0] == '/' ? "localhost" : http
->hostname
);
210 http
->digest_tries
= _cups_strncasecmp(www_auth
, "Digest", 6) != 0;
211 http
->userpass
[0] = '\0';
213 if ((password
= cupsGetPassword2(prompt
, http
, method
, resource
)) == NULL
)
215 http
->status
= HTTP_AUTHORIZATION_CANCELED
;
219 snprintf(http
->userpass
, sizeof(http
->userpass
), "%s:%s", cupsUser(),
222 else if (http
->status
== HTTP_UNAUTHORIZED
)
223 http
->digest_tries
++;
225 if (http
->status
== HTTP_UNAUTHORIZED
&& http
->digest_tries
>= 3)
227 DEBUG_printf(("1cupsDoAuthentication: Too many authentication tries (%d)",
228 http
->digest_tries
));
230 http
->status
= HTTP_AUTHORIZATION_CANCELED
;
235 * Got a password; encode it for the server...
239 if (!_cups_strncasecmp(www_auth
, "Negotiate", 9))
242 * Kerberos authentication...
245 if (_cupsSetNegotiateAuthString(http
, method
, resource
))
247 http
->status
= HTTP_AUTHORIZATION_CANCELED
;
252 #endif /* HAVE_GSSAPI */
253 if (!_cups_strncasecmp(www_auth
, "Basic", 5))
256 * Basic authentication...
259 char encode
[256]; /* Base64 buffer */
262 httpEncode64_2(encode
, sizeof(encode
), http
->userpass
,
263 (int)strlen(http
->userpass
));
264 httpSetAuthString(http
, "Basic", encode
);
266 else if (!_cups_strncasecmp(www_auth
, "Digest", 6))
269 * Digest authentication...
272 char encode
[33], /* MD5 buffer */
273 digest
[1024]; /* Digest auth data */
276 httpGetSubField(http
, HTTP_FIELD_WWW_AUTHENTICATE
, "realm", realm
);
277 httpGetSubField(http
, HTTP_FIELD_WWW_AUTHENTICATE
, "nonce", nonce
);
279 httpMD5(cupsUser(), realm
, strchr(http
->userpass
, ':') + 1, encode
);
280 httpMD5Final(nonce
, method
, resource
, encode
);
281 snprintf(digest
, sizeof(digest
),
282 "username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", "
283 "response=\"%s\"", cupsUser(), realm
, nonce
, resource
, encode
);
284 httpSetAuthString(http
, "Digest", digest
);
288 DEBUG_printf(("1cupsDoAuthentication: Unknown auth type: \"%s\"",
290 http
->status
= HTTP_AUTHORIZATION_CANCELED
;
294 DEBUG_printf(("1cupsDoAuthentication: authstring=\"%s\"", http
->authstring
));
302 * '_cupsSetNegotiateAuthString()' - Set the Kerberos authentication string.
305 int /* O - 0 on success, -1 on error */
306 _cupsSetNegotiateAuthString(
307 http_t
*http
, /* I - Connection to server */
308 const char *method
, /* I - Request method ("GET", "POST", "PUT") */
309 const char *resource
) /* I - Resource path */
311 OM_uint32 minor_status
, /* Minor status code */
312 major_status
; /* Major status code */
313 gss_buffer_desc output_token
= GSS_C_EMPTY_BUFFER
;
322 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
326 if (gss_init_sec_context
== NULL
)
328 DEBUG_puts("1_cupsSetNegotiateAuthString: Weak-linked GSSAPI/Kerberos "
329 "framework is not present");
332 # endif /* __APPLE__ */
334 if (http
->gssname
== GSS_C_NO_NAME
)
336 http
->gssname
= cups_gss_getname(http
, _cupsGSSServiceName());
339 if (http
->gssctx
!= GSS_C_NO_CONTEXT
)
341 gss_delete_sec_context(&minor_status
, &http
->gssctx
, GSS_C_NO_BUFFER
);
342 http
->gssctx
= GSS_C_NO_CONTEXT
;
345 major_status
= gss_init_sec_context(&minor_status
, GSS_C_NO_CREDENTIAL
,
347 http
->gssname
, http
->gssmech
,
348 GSS_C_MUTUAL_FLAG
| GSS_C_INTEG_FLAG
,
350 GSS_C_NO_CHANNEL_BINDINGS
,
351 GSS_C_NO_BUFFER
, &http
->gssmech
,
352 &output_token
, NULL
, NULL
);
354 #ifdef HAVE_GSS_ACQUIRE_CRED_EX_F
355 if (major_status
== GSS_S_NO_CRED
)
358 * Ask the user for credentials...
361 char prompt
[1024], /* Prompt for user */
362 userbuf
[256]; /* Kerberos username */
363 const char *username
, /* Username string */
364 *password
; /* Password string */
365 _cups_gss_acquire_t data
; /* Callback data */
366 gss_auth_identity_desc identity
; /* Kerberos user identity */
367 _cups_globals_t
*cg
= _cupsGlobals();
368 /* Per-thread global data */
370 if (!cg
->lang_default
)
371 cg
->lang_default
= cupsLangDefault();
373 snprintf(prompt
, sizeof(prompt
),
374 _cupsLangString(cg
->lang_default
, _("Password for %s on %s? ")),
375 cupsUser(), http
->gsshost
);
377 if ((password
= cupsGetPassword2(prompt
, http
, method
, resource
)) == NULL
)
381 * Try to acquire credentials...
384 username
= cupsUser();
385 if (!strchr(username
, '@'))
387 snprintf(userbuf
, sizeof(userbuf
), "%s@%s", username
, http
->gsshost
);
391 identity
.type
= GSS_AUTH_IDENTITY_TYPE_1
;
393 identity
.username
= (char *)username
;
394 identity
.realm
= (char *)"";
395 identity
.password
= (char *)password
;
396 identity
.credentialsRef
= NULL
;
398 data
.sem
= dispatch_semaphore_create(0);
404 major_status
= gss_acquire_cred_ex_f(NULL
, GSS_C_NO_NAME
, 0,
405 GSS_C_INDEFINITE
, GSS_KRB5_MECHANISM
,
406 GSS_C_INITIATE
, &identity
, &data
,
409 if (major_status
== GSS_S_COMPLETE
)
411 dispatch_semaphore_wait(data
.sem
, DISPATCH_TIME_FOREVER
);
412 major_status
= data
.major
;
415 dispatch_release(data
.sem
);
417 if (major_status
== GSS_S_COMPLETE
)
419 OM_uint32 release_minor
; /* Minor status from releasing creds */
421 major_status
= gss_init_sec_context(&minor_status
, data
.creds
,
423 http
->gssname
, http
->gssmech
,
424 GSS_C_MUTUAL_FLAG
| GSS_C_INTEG_FLAG
,
426 GSS_C_NO_CHANNEL_BINDINGS
,
427 GSS_C_NO_BUFFER
, &http
->gssmech
,
428 &output_token
, NULL
, NULL
);
429 gss_release_cred(&release_minor
, &data
.creds
);
433 #endif /* HAVE_GSS_ACQUIRED_CRED_EX_F */
435 if (GSS_ERROR(major_status
))
437 cups_gss_printf(major_status
, minor_status
,
438 "_cupsSetNegotiateAuthString: Unable to initialize "
444 else if (major_status
== GSS_S_CONTINUE_NEEDED
)
445 cups_gss_printf(major_status
, minor_status
,
446 "_cupsSetNegotiateAuthString: Continuation needed!");
449 if (output_token
.length
> 0 && output_token
.length
<= 65536)
452 * Allocate the authorization string since Windows KDCs can have
453 * arbitrarily large credentials...
456 int authsize
= 10 + /* "Negotiate " */
457 output_token
.length
* 4 / 3 + 1 + /* Base64 */
460 httpSetAuthString(http
, NULL
, NULL
);
462 if ((http
->authstring
= malloc(authsize
)) == NULL
)
464 http
->authstring
= http
->_authstring
;
465 authsize
= sizeof(http
->_authstring
);
468 strlcpy(http
->authstring
, "Negotiate ", authsize
);
469 httpEncode64_2(http
->authstring
+ 10, authsize
- 10, output_token
.value
,
470 output_token
.length
);
472 gss_release_buffer(&minor_status
, &output_token
);
476 DEBUG_printf(("1_cupsSetNegotiateAuthString: Kerberos credentials too "
477 "large - %d bytes!", (int)output_token
.length
));
478 gss_release_buffer(&minor_status
, &output_token
);
487 # ifdef HAVE_GSS_ACQUIRE_CRED_EX_F
489 * 'cups_gss_acquire()' - Kerberos credentials callback.
493 void *ctx
, /* I - Caller context */
494 OM_uint32 major
, /* I - Major error code */
495 gss_status_id_t status
, /* I - Status (unused) */
496 gss_cred_id_t creds
, /* I - Credentials (if any) */
497 gss_OID_set oids
, /* I - Mechanism OIDs (unused) */
498 OM_uint32 time_rec
) /* I - Timestamp (unused) */
500 uint32_t min
; /* Minor error code */
501 _cups_gss_acquire_t
*data
; /* Callback data */
507 data
= (_cups_gss_acquire_t
*)ctx
;
511 gss_release_oid_set(&min
, &oids
);
512 dispatch_semaphore_signal(data
->sem
);
514 # endif /* HAVE_GSS_ACQUIRE_CRED_EX_F */
518 * 'cups_gss_getname()' - Get CUPS service credentials for authentication.
521 static gss_name_t
/* O - Server name */
523 http_t
*http
, /* I - Connection to server */
524 const char *service_name
) /* I - Service name */
526 gss_buffer_desc token
= GSS_C_EMPTY_BUFFER
;
528 OM_uint32 major_status
, /* Major status code */
529 minor_status
; /* Minor status code */
530 gss_name_t server_name
; /* Server name */
531 char buf
[1024]; /* Name buffer */
534 DEBUG_printf(("7cups_gss_getname(http=%p, service_name=\"%s\")", http
,
539 * Get the hostname...
542 if (!http
->gsshost
[0])
544 httpGetHostname(http
, http
->gsshost
, sizeof(http
->gsshost
));
546 if (!strcmp(http
->gsshost
, "localhost"))
548 if (gethostname(http
->gsshost
, sizeof(http
->gsshost
)) < 0)
550 DEBUG_printf(("1cups_gss_getname: gethostname() failed: %s",
552 http
->gsshost
[0] = '\0';
556 if (!strchr(http
->gsshost
, '.'))
559 * The hostname is not a FQDN, so look it up...
562 struct hostent
*host
; /* Host entry to get FQDN */
564 if ((host
= gethostbyname(http
->gsshost
)) != NULL
&& host
->h_name
)
567 * Use the resolved hostname...
570 strlcpy(http
->gsshost
, host
->h_name
, sizeof(http
->gsshost
));
574 DEBUG_printf(("1cups_gss_getname: gethostbyname(\"%s\") failed.",
576 http
->gsshost
[0] = '\0';
584 * Get a service name we can use for authentication purposes...
587 snprintf(buf
, sizeof(buf
), "%s@%s", service_name
, http
->gsshost
);
589 DEBUG_printf(("8cups_gss_getname: Looking up \"%s\".", buf
));
592 token
.length
= strlen(buf
);
593 server_name
= GSS_C_NO_NAME
;
594 major_status
= gss_import_name(&minor_status
, &token
,
595 GSS_C_NT_HOSTBASED_SERVICE
,
598 if (GSS_ERROR(major_status
))
600 cups_gss_printf(major_status
, minor_status
,
601 "cups_gss_getname: gss_import_name() failed");
605 return (server_name
);
611 * 'cups_gss_printf()' - Show debug error messages from GSSAPI.
615 cups_gss_printf(OM_uint32 major_status
,/* I - Major status code */
616 OM_uint32 minor_status
,/* I - Minor status code */
617 const char *message
) /* I - Prefix for error message */
619 OM_uint32 err_major_status
, /* Major status code for display */
620 err_minor_status
; /* Minor status code for display */
621 OM_uint32 msg_ctx
; /* Message context */
622 gss_buffer_desc major_status_string
= GSS_C_EMPTY_BUFFER
,
623 /* Major status message */
624 minor_status_string
= GSS_C_EMPTY_BUFFER
;
625 /* Minor status message */
629 err_major_status
= gss_display_status(&err_minor_status
,
634 &major_status_string
);
636 if (!GSS_ERROR(err_major_status
))
637 gss_display_status(&err_minor_status
, minor_status
, GSS_C_MECH_CODE
,
638 GSS_C_NULL_OID
, &msg_ctx
, &minor_status_string
);
640 DEBUG_printf(("1%s: %s, %s", message
, (char *)major_status_string
.value
,
641 (char *)minor_status_string
.value
));
643 gss_release_buffer(&err_minor_status
, &major_status_string
);
644 gss_release_buffer(&err_minor_status
, &minor_status_string
);
647 #endif /* HAVE_GSSAPI */
651 * 'cups_local_auth()' - Get the local authorization certificate if
652 * available/applicable.
655 static int /* O - 0 if available */
656 /* 1 if not available */
658 cups_local_auth(http_t
*http
) /* I - HTTP connection to server */
660 #if defined(WIN32) || defined(__EMX__)
662 * Currently WIN32 and OS-2 do not support the CUPS server...
667 int pid
; /* Current process ID */
668 FILE *fp
; /* Certificate file */
669 char trc
[16], /* Try Root Certificate parameter */
670 filename
[1024], /* Certificate filename */
671 certificate
[33];/* Certificate string */
672 _cups_globals_t
*cg
= _cupsGlobals(); /* Global data */
673 # if defined(HAVE_AUTHORIZATION_H)
674 OSStatus status
; /* Status */
675 AuthorizationItem auth_right
; /* Authorization right */
676 AuthorizationRights auth_rights
; /* Authorization rights */
677 AuthorizationFlags auth_flags
; /* Authorization flags */
678 AuthorizationExternalForm auth_extrn
; /* Authorization ref external */
679 char auth_key
[1024]; /* Buffer */
680 char buffer
[1024]; /* Buffer */
681 # endif /* HAVE_AUTHORIZATION_H */
684 DEBUG_printf(("7cups_local_auth(http=%p) hostaddr=%s, hostname=\"%s\"",
685 http
, httpAddrString(http
->hostaddr
, filename
, sizeof(filename
)), http
->hostname
));
688 * See if we are accessing localhost...
691 if (!httpAddrLocalhost(http
->hostaddr
) &&
692 _cups_strcasecmp(http
->hostname
, "localhost") != 0)
694 DEBUG_puts("8cups_local_auth: Not a local connection!");
698 # if defined(HAVE_AUTHORIZATION_H)
700 * Delete any previous authorization reference...
705 AuthorizationFree(http
->auth_ref
, kAuthorizationFlagDefaults
);
706 http
->auth_ref
= NULL
;
709 if (!getenv("GATEWAY_INTERFACE") &&
710 httpGetSubField2(http
, HTTP_FIELD_WWW_AUTHENTICATE
, "authkey",
711 auth_key
, sizeof(auth_key
)))
713 status
= AuthorizationCreate(NULL
, kAuthorizationEmptyEnvironment
,
714 kAuthorizationFlagDefaults
, &http
->auth_ref
);
715 if (status
!= errAuthorizationSuccess
)
717 DEBUG_printf(("8cups_local_auth: AuthorizationCreate() returned %d (%s)",
718 (int)status
, cssmErrorString(status
)));
722 auth_right
.name
= auth_key
;
723 auth_right
.valueLength
= 0;
724 auth_right
.value
= NULL
;
725 auth_right
.flags
= 0;
727 auth_rights
.count
= 1;
728 auth_rights
.items
= &auth_right
;
730 auth_flags
= kAuthorizationFlagDefaults
|
731 kAuthorizationFlagPreAuthorize
|
732 kAuthorizationFlagInteractionAllowed
|
733 kAuthorizationFlagExtendRights
;
735 status
= AuthorizationCopyRights(http
->auth_ref
, &auth_rights
,
736 kAuthorizationEmptyEnvironment
,
738 if (status
== errAuthorizationSuccess
)
739 status
= AuthorizationMakeExternalForm(http
->auth_ref
, &auth_extrn
);
741 if (status
== errAuthorizationSuccess
)
744 * Set the authorization string and return...
747 httpEncode64_2(buffer
, sizeof(buffer
), (void *)&auth_extrn
,
750 httpSetAuthString(http
, "AuthRef", buffer
);
752 DEBUG_printf(("8cups_local_auth: Returning authstring=\"%s\"",
756 else if (status
== errAuthorizationCanceled
)
759 DEBUG_printf(("9cups_local_auth: AuthorizationCopyRights() returned %d (%s)",
760 (int)status
, cssmErrorString(status
)));
763 * Fall through to try certificates...
766 # endif /* HAVE_AUTHORIZATION_H */
768 # if defined(SO_PEERCRED) && defined(AF_LOCAL)
770 * See if we can authenticate using the peer credentials provided over a
771 * domain socket; if so, specify "PeerCred username" as the authentication
777 strncmp(http
->fields
[HTTP_FIELD_WWW_AUTHENTICATE
], "Negotiate", 9) &&
778 # endif /* HAVE_GSSAPI */
779 # ifdef HAVE_AUTHORIZATION_H
780 !httpGetSubField2(http
, HTTP_FIELD_WWW_AUTHENTICATE
, "authkey",
781 auth_key
, sizeof(auth_key
)) &&
782 # endif /* HAVE_AUTHORIZATION_H */
783 http
->hostaddr
->addr
.sa_family
== AF_LOCAL
&&
784 !getenv("GATEWAY_INTERFACE")) /* Not via CGI programs... */
787 * Verify that the current cupsUser() matches the current UID...
790 struct passwd
*pwd
; /* Password information */
791 const char *username
; /* Current username */
793 username
= cupsUser();
795 if ((pwd
= getpwnam(username
)) != NULL
&& pwd
->pw_uid
== getuid())
797 httpSetAuthString(http
, "PeerCred", username
);
799 DEBUG_printf(("8cups_local_auth: Returning authstring=\"%s\"",
805 # endif /* SO_PEERCRED && AF_LOCAL */
808 * Try opening a certificate file for this PID. If that fails,
809 * try the root certificate...
813 snprintf(filename
, sizeof(filename
), "%s/certs/%d", cg
->cups_statedir
, pid
);
814 if ((fp
= fopen(filename
, "r")) == NULL
&& pid
> 0)
817 * No certificate for this PID; see if we can get the root certificate...
820 DEBUG_printf(("9cups_local_auth: Unable to open file %s: %s",
821 filename
, strerror(errno
)));
824 if (!strncmp(http
->fields
[HTTP_FIELD_WWW_AUTHENTICATE
], "Negotiate", 9))
827 * Kerberos required, don't try the root certificate...
832 # endif /* HAVE_GSSAPI */
834 # ifdef HAVE_AUTHORIZATION_H
835 if (httpGetSubField2(http
, HTTP_FIELD_WWW_AUTHENTICATE
, "authkey",
836 auth_key
, sizeof(auth_key
)))
839 * Don't use the root certificate as a replacement for an authkey...
844 # endif /* HAVE_AUTHORIZATION_H */
845 if (!httpGetSubField2(http
, HTTP_FIELD_WWW_AUTHENTICATE
, "trc", trc
,
849 * Scheduler doesn't want us to use the root certificate...
855 snprintf(filename
, sizeof(filename
), "%s/certs/0", cg
->cups_statedir
);
856 fp
= fopen(filename
, "r");
862 * Read the certificate from the file...
865 fgets(certificate
, sizeof(certificate
), fp
);
869 * Set the authorization string and return...
872 httpSetAuthString(http
, "Local", certificate
);
874 DEBUG_printf(("8cups_local_auth: Returning authstring=\"%s\"",
881 #endif /* WIN32 || __EMX__ */