1*13132SGlenn.Barry@oracle.com /*
2*13132SGlenn.Barry@oracle.com * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
3*13132SGlenn.Barry@oracle.com */
40Sstevel@tonic-gate /*
50Sstevel@tonic-gate * Copyright 1997 by Massachusetts Institute of Technology
60Sstevel@tonic-gate * All Rights Reserved.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * Export of this software from the United States of America may
90Sstevel@tonic-gate * require a specific license from the United States Government.
100Sstevel@tonic-gate * It is the responsibility of any person or organization contemplating
110Sstevel@tonic-gate * export to obtain such a license before exporting.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
140Sstevel@tonic-gate * distribute this software and its documentation for any purpose and
150Sstevel@tonic-gate * without fee is hereby granted, provided that the above copyright
160Sstevel@tonic-gate * notice appear in all copies and that both that copyright notice and
170Sstevel@tonic-gate * this permission notice appear in supporting documentation, and that
180Sstevel@tonic-gate * the name of M.I.T. not be used in advertising or publicity pertaining
190Sstevel@tonic-gate * to distribution of the software without specific, written prior
200Sstevel@tonic-gate * permission. Furthermore if you modify this software you must label
210Sstevel@tonic-gate * your software as modified software and not distribute it in such a
220Sstevel@tonic-gate * fashion that it might be confused with the original M.I.T. software.
230Sstevel@tonic-gate * M.I.T. makes no representations about the suitability of
240Sstevel@tonic-gate * this software for any purpose. It is provided "as is" without express
250Sstevel@tonic-gate * or implied warranty.
260Sstevel@tonic-gate *
270Sstevel@tonic-gate */
280Sstevel@tonic-gate
295053Sgtb #include "gssapiP_krb5.h"
300Sstevel@tonic-gate
310Sstevel@tonic-gate /*
320Sstevel@tonic-gate * Check to see whether or not a GSSAPI krb5 credential is valid. If
330Sstevel@tonic-gate * it is not, return an error.
340Sstevel@tonic-gate */
350Sstevel@tonic-gate
360Sstevel@tonic-gate OM_uint32
krb5_gss_validate_cred_1(OM_uint32 * minor_status,gss_cred_id_t cred_handle,krb5_context context)375053Sgtb krb5_gss_validate_cred_1(OM_uint32 *minor_status, gss_cred_id_t cred_handle,
385053Sgtb krb5_context context)
390Sstevel@tonic-gate {
400Sstevel@tonic-gate krb5_gss_cred_id_t cred;
410Sstevel@tonic-gate krb5_error_code code;
420Sstevel@tonic-gate krb5_principal princ;
430Sstevel@tonic-gate
440Sstevel@tonic-gate if (!kg_validate_cred_id(cred_handle)) {
450Sstevel@tonic-gate *minor_status = (OM_uint32) G_VALIDATE_FAILED;
465053Sgtb return(GSS_S_CALL_BAD_STRUCTURE|GSS_S_DEFECTIVE_CREDENTIAL);
470Sstevel@tonic-gate }
480Sstevel@tonic-gate
490Sstevel@tonic-gate cred = (krb5_gss_cred_id_t) cred_handle;
505053Sgtb
515053Sgtb code = k5_mutex_lock(&cred->lock);
525053Sgtb if (code) {
535053Sgtb *minor_status = code;
545053Sgtb return GSS_S_FAILURE;
555053Sgtb }
565053Sgtb
570Sstevel@tonic-gate if (cred->ccache) {
585053Sgtb if ((code = krb5_cc_get_principal(context, cred->ccache, &princ))) {
595053Sgtb k5_mutex_unlock(&cred->lock);
600Sstevel@tonic-gate *minor_status = code;
615053Sgtb return(GSS_S_DEFECTIVE_CREDENTIAL);
620Sstevel@tonic-gate }
630Sstevel@tonic-gate if (!krb5_principal_compare(context, princ, cred->princ)) {
645053Sgtb k5_mutex_unlock(&cred->lock);
650Sstevel@tonic-gate *minor_status = KG_CCACHE_NOMATCH;
665053Sgtb return(GSS_S_DEFECTIVE_CREDENTIAL);
670Sstevel@tonic-gate }
680Sstevel@tonic-gate (void)krb5_free_principal(context, princ);
690Sstevel@tonic-gate }
700Sstevel@tonic-gate *minor_status = 0;
715053Sgtb return GSS_S_COMPLETE;
720Sstevel@tonic-gate }
735053Sgtb
745053Sgtb OM_uint32
krb5_gss_validate_cred(minor_status,cred_handle)755053Sgtb krb5_gss_validate_cred(minor_status, cred_handle)
765053Sgtb OM_uint32 *minor_status;
775053Sgtb gss_cred_id_t cred_handle;
785053Sgtb {
795053Sgtb krb5_context context;
805053Sgtb krb5_error_code code;
815053Sgtb OM_uint32 maj;
825053Sgtb
835053Sgtb code = krb5_gss_init_context(&context);
845053Sgtb if (code) {
855053Sgtb *minor_status = code;
865053Sgtb return GSS_S_FAILURE;
875053Sgtb }
885053Sgtb
895053Sgtb maj = krb5_gss_validate_cred_1(minor_status, cred_handle, context);
905053Sgtb if (maj == 0) {
915053Sgtb krb5_gss_cred_id_t cred = (krb5_gss_cred_id_t) cred_handle;
925053Sgtb k5_mutex_assert_locked(&cred->lock);
935053Sgtb k5_mutex_unlock(&cred->lock);
94*13132SGlenn.Barry@oracle.com } else /* Solaris Kerberos - added this else */
95*13132SGlenn.Barry@oracle.com save_error_info(*minor_status, context);
965053Sgtb krb5_free_context(context);
975053Sgtb return maj;
985053Sgtb }
995053Sgtb
1005053Sgtb
1015053Sgtb
1025053Sgtb
103