8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / gss_mechs / mech_krb5 / krb5 / ccache / ccfns.c
blob15bc87df6b76a24e519fb5fd3bc6b952011da9b6
1 /*
2 * lib/krb5/ccache/ccfns.c
4 * Copyright 2000, 2007 by the Massachusetts Institute of Technology.
5 * All Rights Reserved.
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.
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.
28 * Dispatch methods for credentials cache code.
31 #include "k5-int.h"
33 const char * KRB5_CALLCONV
34 krb5_cc_get_name (krb5_context context, krb5_ccache cache)
36 return cache->ops->get_name(context, cache);
39 krb5_error_code KRB5_CALLCONV
40 krb5_cc_gen_new (krb5_context context, krb5_ccache *cache)
42 return (*cache)->ops->gen_new(context, cache);
45 krb5_error_code KRB5_CALLCONV
46 krb5_cc_initialize(krb5_context context, krb5_ccache cache,
47 krb5_principal principal)
49 return cache->ops->init(context, cache, principal);
52 krb5_error_code KRB5_CALLCONV
53 krb5_cc_destroy (krb5_context context, krb5_ccache cache)
55 return cache->ops->destroy(context, cache);
58 krb5_error_code KRB5_CALLCONV
59 krb5_cc_close (krb5_context context, krb5_ccache cache)
61 return cache->ops->close(context, cache);
64 krb5_error_code KRB5_CALLCONV
65 krb5_cc_store_cred (krb5_context context, krb5_ccache cache,
66 krb5_creds *creds)
68 krb5_error_code ret;
69 krb5_ticket *tkt;
70 krb5_principal s1, s2;
72 ret = cache->ops->store(context, cache, creds);
73 if (ret) return ret;
76 * If creds->server and the server in the decoded ticket differ,
77 * store both principals.
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;
89 krb5_free_ticket(context, tkt);
90 return ret;
93 krb5_error_code KRB5_CALLCONV
94 krb5_cc_retrieve_cred (krb5_context context, krb5_ccache cache,
95 krb5_flags flags, krb5_creds *mcreds,
96 krb5_creds *creds)
98 krb5_error_code ret;
99 krb5_data tmprealm;
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;
108 * Retry using client's realm if service has referral realm.
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;
117 krb5_error_code KRB5_CALLCONV
118 krb5_cc_get_principal (krb5_context context, krb5_ccache cache,
119 krb5_principal *principal)
121 return cache->ops->get_princ(context, cache, principal);
124 krb5_error_code KRB5_CALLCONV
125 krb5_cc_start_seq_get (krb5_context context, krb5_ccache cache,
126 krb5_cc_cursor *cursor)
128 return cache->ops->get_first(context, cache, cursor);
131 krb5_error_code KRB5_CALLCONV
132 krb5_cc_next_cred (krb5_context context, krb5_ccache cache,
133 krb5_cc_cursor *cursor, krb5_creds *creds)
135 return cache->ops->get_next(context, cache, cursor, creds);
138 krb5_error_code KRB5_CALLCONV
139 krb5_cc_end_seq_get (krb5_context context, krb5_ccache cache,
140 krb5_cc_cursor *cursor)
142 return cache->ops->end_get(context, cache, cursor);
145 krb5_error_code KRB5_CALLCONV
146 krb5_cc_remove_cred (krb5_context context, krb5_ccache cache, krb5_flags flags,
147 krb5_creds *creds)
149 return cache->ops->remove_cred(context, cache, flags, creds);
152 krb5_error_code KRB5_CALLCONV
153 krb5_cc_set_flags (krb5_context context, krb5_ccache cache, krb5_flags flags)
155 return cache->ops->set_flags(context, cache, flags);
158 krb5_error_code KRB5_CALLCONV
159 krb5_cc_get_flags (krb5_context context, krb5_ccache cache, krb5_flags *flags)
161 return cache->ops->get_flags(context, cache, flags);
164 const char * KRB5_CALLCONV
165 krb5_cc_get_type (krb5_context context, krb5_ccache cache)
167 return cache->ops->prefix;