xref: /titanic_41/usr/src/lib/gss_mechs/mech_krb5/krb5/ccache/ccfns.c (revision 159d09a20817016f09b3ea28d1bdada4a336bb91)
1 /*
2  * lib/krb5/ccache/ccfns.c
3  *
4  * Copyright 2000, 2007 by the 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  * Dispatch methods for credentials cache code.
29  */
30 
31 #include "k5-int.h"
32 
33 const char * KRB5_CALLCONV
krb5_cc_get_name(krb5_context context,krb5_ccache cache)34 krb5_cc_get_name (krb5_context context, krb5_ccache cache)
35 {
36     return cache->ops->get_name(context, cache);
37 }
38 
39 krb5_error_code KRB5_CALLCONV
krb5_cc_gen_new(krb5_context context,krb5_ccache * cache)40 krb5_cc_gen_new (krb5_context context, krb5_ccache *cache)
41 {
42     return (*cache)->ops->gen_new(context, cache);
43 }
44 
45 krb5_error_code KRB5_CALLCONV
krb5_cc_initialize(krb5_context context,krb5_ccache cache,krb5_principal principal)46 krb5_cc_initialize(krb5_context context, krb5_ccache cache,
47 		   krb5_principal principal)
48 {
49     return cache->ops->init(context, cache, principal);
50 }
51 
52 krb5_error_code KRB5_CALLCONV
krb5_cc_destroy(krb5_context context,krb5_ccache cache)53 krb5_cc_destroy (krb5_context context, krb5_ccache cache)
54 {
55     return cache->ops->destroy(context, cache);
56 }
57 
58 krb5_error_code KRB5_CALLCONV
krb5_cc_close(krb5_context context,krb5_ccache cache)59 krb5_cc_close (krb5_context context, krb5_ccache cache)
60 {
61     return cache->ops->close(context, cache);
62 }
63 
64 krb5_error_code KRB5_CALLCONV
krb5_cc_store_cred(krb5_context context,krb5_ccache cache,krb5_creds * creds)65 krb5_cc_store_cred (krb5_context context, krb5_ccache cache,
66 		    krb5_creds *creds)
67 {
68     krb5_error_code ret;
69     krb5_ticket *tkt;
70     krb5_principal s1, s2;
71 
72     ret = cache->ops->store(context, cache, creds);
73     if (ret) return ret;
74 
75     /*
76      * If creds->server and the server in the decoded ticket differ,
77      * store both principals.
78      */
79     s1 = creds->server;
80     ret = decode_krb5_ticket(&creds->ticket, &tkt);
81     /* Bail out on errors in case someone is storing a non-ticket. */
82     if (ret) return 0;
83     s2 = tkt->server;
84     if (!krb5_principal_compare(context, s1, s2)) {
85 	creds->server = s2;
86 	ret = cache->ops->store(context, cache, creds);
87 	creds->server = s1;
88     }
89     krb5_free_ticket(context, tkt);
90     return ret;
91 }
92 
93 krb5_error_code KRB5_CALLCONV
krb5_cc_retrieve_cred(krb5_context context,krb5_ccache cache,krb5_flags flags,krb5_creds * mcreds,krb5_creds * creds)94 krb5_cc_retrieve_cred (krb5_context context, krb5_ccache cache,
95 		       krb5_flags flags, krb5_creds *mcreds,
96 		       krb5_creds *creds)
97 {
98     krb5_error_code ret;
99     krb5_data tmprealm;
100 
101     ret = cache->ops->retrieve(context, cache, flags, mcreds, creds);
102     if (ret != KRB5_CC_NOTFOUND)
103 	return ret;
104     if (!krb5_is_referral_realm(&mcreds->server->realm))
105 	return ret;
106 
107     /*
108      * Retry using client's realm if service has referral realm.
109      */
110     tmprealm = mcreds->server->realm;
111     mcreds->server->realm = mcreds->client->realm;
112     ret = cache->ops->retrieve(context, cache, flags, mcreds, creds);
113     mcreds->server->realm = tmprealm;
114     return ret;
115 }
116 
117 krb5_error_code KRB5_CALLCONV
krb5_cc_get_principal(krb5_context context,krb5_ccache cache,krb5_principal * principal)118 krb5_cc_get_principal (krb5_context context, krb5_ccache cache,
119 		       krb5_principal *principal)
120 {
121     return cache->ops->get_princ(context, cache, principal);
122 }
123 
124 krb5_error_code KRB5_CALLCONV
krb5_cc_start_seq_get(krb5_context context,krb5_ccache cache,krb5_cc_cursor * cursor)125 krb5_cc_start_seq_get (krb5_context context, krb5_ccache cache,
126 		       krb5_cc_cursor *cursor)
127 {
128     return cache->ops->get_first(context, cache, cursor);
129 }
130 
131 krb5_error_code KRB5_CALLCONV
krb5_cc_next_cred(krb5_context context,krb5_ccache cache,krb5_cc_cursor * cursor,krb5_creds * creds)132 krb5_cc_next_cred (krb5_context context, krb5_ccache cache,
133 		   krb5_cc_cursor *cursor, krb5_creds *creds)
134 {
135     return cache->ops->get_next(context, cache, cursor, creds);
136 }
137 
138 krb5_error_code KRB5_CALLCONV
krb5_cc_end_seq_get(krb5_context context,krb5_ccache cache,krb5_cc_cursor * cursor)139 krb5_cc_end_seq_get (krb5_context context, krb5_ccache cache,
140 		     krb5_cc_cursor *cursor)
141 {
142     return cache->ops->end_get(context, cache, cursor);
143 }
144 
145 krb5_error_code KRB5_CALLCONV
krb5_cc_remove_cred(krb5_context context,krb5_ccache cache,krb5_flags flags,krb5_creds * creds)146 krb5_cc_remove_cred (krb5_context context, krb5_ccache cache, krb5_flags flags,
147 		     krb5_creds *creds)
148 {
149     return cache->ops->remove_cred(context, cache, flags, creds);
150 }
151 
152 krb5_error_code KRB5_CALLCONV
krb5_cc_set_flags(krb5_context context,krb5_ccache cache,krb5_flags flags)153 krb5_cc_set_flags (krb5_context context, krb5_ccache cache, krb5_flags flags)
154 {
155     return cache->ops->set_flags(context, cache, flags);
156 }
157 
158 krb5_error_code KRB5_CALLCONV
krb5_cc_get_flags(krb5_context context,krb5_ccache cache,krb5_flags * flags)159 krb5_cc_get_flags (krb5_context context, krb5_ccache cache, krb5_flags *flags)
160 {
161     return cache->ops->get_flags(context, cache, flags);
162 }
163 
164 const char * KRB5_CALLCONV
krb5_cc_get_type(krb5_context context,krb5_ccache cache)165 krb5_cc_get_type (krb5_context context, krb5_ccache cache)
166 {
167     return cache->ops->prefix;
168 }
169