1 #pragma ident	"%Z%%M%	%I%	%E% SMI"
2 
3 /*
4  * Copyright 1997 by Massachusetts Institute of Technology
5  * All Rights Reserved.
6  *
7  * Export of this software from the United States of America may
8  *   require a specific license from the United States Government.
9  *   It is the responsibility of any person or organization contemplating
10  *   export to obtain such a license before exporting.
11  *
12  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13  * distribute this software and its documentation for any purpose and
14  * without fee is hereby granted, provided that the above copyright
15  * notice appear in all copies and that both that copyright notice and
16  * this permission notice appear in supporting documentation, and that
17  * the name of M.I.T. not be used in advertising or publicity pertaining
18  * to distribution of the software without specific, written prior
19  * permission.  Furthermore if you modify this software you must label
20  * your software as modified software and not distribute it in such a
21  * fashion that it might be confused with the original M.I.T. software.
22  * M.I.T. makes no representations about the suitability of
23  * this software for any purpose.  It is provided "as is" without express
24  * or implied warranty.
25  *
26  */
27 
28 #include "gssapiP_krb5.h"
29 
30 /*
31  * Check to see whether or not a GSSAPI krb5 credential is valid.  If
32  * it is not, return an error.
33  */
34 
35 OM_uint32
36 krb5_gss_validate_cred_1(OM_uint32 *minor_status, gss_cred_id_t cred_handle,
37 			 krb5_context context)
38 {
39     krb5_gss_cred_id_t cred;
40     krb5_error_code code;
41     krb5_principal princ;
42 
43     if (!kg_validate_cred_id(cred_handle)) {
44 	*minor_status = (OM_uint32) G_VALIDATE_FAILED;
45 	return(GSS_S_CALL_BAD_STRUCTURE|GSS_S_DEFECTIVE_CREDENTIAL);
46     }
47 
48     cred = (krb5_gss_cred_id_t) cred_handle;
49 
50     code = k5_mutex_lock(&cred->lock);
51     if (code) {
52 	*minor_status = code;
53 	return GSS_S_FAILURE;
54     }
55 
56     if (cred->ccache) {
57 	if ((code = krb5_cc_get_principal(context, cred->ccache, &princ))) {
58 	    k5_mutex_unlock(&cred->lock);
59 	    *minor_status = code;
60 	    return(GSS_S_DEFECTIVE_CREDENTIAL);
61 	}
62 	if (!krb5_principal_compare(context, princ, cred->princ)) {
63 	    k5_mutex_unlock(&cred->lock);
64 	    *minor_status = KG_CCACHE_NOMATCH;
65 	    return(GSS_S_DEFECTIVE_CREDENTIAL);
66 	}
67 	(void)krb5_free_principal(context, princ);
68     }
69     *minor_status = 0;
70     return GSS_S_COMPLETE;
71 }
72 
73 OM_uint32
74 krb5_gss_validate_cred(minor_status, cred_handle)
75      OM_uint32 *minor_status;
76      gss_cred_id_t cred_handle;
77 {
78     krb5_context context;
79     krb5_error_code code;
80     OM_uint32 maj;
81 
82     code = krb5_gss_init_context(&context);
83     if (code) {
84 	*minor_status = code;
85 	return GSS_S_FAILURE;
86     }
87 
88     maj = krb5_gss_validate_cred_1(minor_status, cred_handle, context);
89     if (maj == 0) {
90 	krb5_gss_cred_id_t cred = (krb5_gss_cred_id_t) cred_handle;
91 	k5_mutex_assert_locked(&cred->lock);
92 	k5_mutex_unlock(&cred->lock);
93     }
94     krb5_free_context(context);
95     return maj;
96 }
97 
98 
99 
100 
101