cf/largefile.m4: Fix build with autoconf-2.72
[heimdal.git] / kcm / glue.c
blob0895f48f051cde8e2077efb72f8e9dcdde7b2712
1 /*
2 * Copyright (c) 2005, PADL Software Pty Ltd.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of PADL Software nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY PADL SOFTWARE AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL PADL SOFTWARE OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
33 #include "kcm_locl.h"
35 RCSID("$Id$");
38 * Server-side loopback glue for credentials cache operations; this
39 * must be initialized with kcm_internal_ccache(), it is not for real
40 * use. This entire file assumes the cache is locked, it does not do
41 * any concurrency checking for multithread applications.
44 #define KCMCACHE(X) ((kcm_ccache)(X)->data.data)
45 #define CACHENAME(X) (KCMCACHE(X)->name)
47 static krb5_error_code
48 kcmss_get_name_2(krb5_context context,
49 krb5_ccache id,
50 const char **name,
51 const char **col,
52 const char **sub)
54 if (name)
55 *name = CACHENAME(id);
56 if (col)
57 *col = NULL;
58 if (sub)
59 *sub = CACHENAME(id);
60 return 0;
63 static krb5_error_code
64 kcmss_resolve_2(krb5_context context,
65 krb5_ccache *id,
66 const char *res,
67 const char *sub)
69 return KRB5_FCC_INTERNAL;
72 static krb5_error_code
73 kcmss_gen_new(krb5_context context, krb5_ccache *id)
75 return KRB5_FCC_INTERNAL;
78 static krb5_error_code
79 kcmss_initialize(krb5_context context,
80 krb5_ccache id,
81 krb5_principal primary_principal)
83 krb5_error_code ret;
84 kcm_ccache c = KCMCACHE(id);
86 KCM_ASSERT_VALID(c);
88 ret = kcm_zero_ccache_data_internal(context, c);
89 if (ret)
90 return ret;
92 ret = krb5_copy_principal(context, primary_principal,
93 &c->client);
95 return ret;
98 static krb5_error_code
99 kcmss_close(krb5_context context,
100 krb5_ccache id)
102 kcm_ccache c = KCMCACHE(id);
104 KCM_ASSERT_VALID(c);
106 id->data.data = NULL;
107 id->data.length = 0;
109 return 0;
112 static krb5_error_code
113 kcmss_destroy(krb5_context context,
114 krb5_ccache id)
116 krb5_error_code ret;
117 kcm_ccache c = KCMCACHE(id);
119 KCM_ASSERT_VALID(c);
121 ret = kcm_ccache_destroy(context, CACHENAME(id));
123 return ret;
126 static krb5_error_code
127 kcmss_store_cred(krb5_context context,
128 krb5_ccache id,
129 krb5_creds *creds)
131 krb5_error_code ret;
132 kcm_ccache c = KCMCACHE(id);
133 krb5_creds *tmp;
135 KCM_ASSERT_VALID(c);
137 ret = kcm_ccache_store_cred_internal(context, c, creds, 1, &tmp);
139 return ret;
142 static krb5_error_code
143 kcmss_retrieve(krb5_context context,
144 krb5_ccache id,
145 krb5_flags which,
146 const krb5_creds *mcred,
147 krb5_creds *creds)
149 krb5_error_code ret;
150 kcm_ccache c = KCMCACHE(id);
151 krb5_creds *credp;
153 KCM_ASSERT_VALID(c);
155 ret = kcm_ccache_retrieve_cred_internal(context, c, which,
156 mcred, &credp);
157 if (ret)
158 return ret;
160 ret = krb5_copy_creds_contents(context, credp, creds);
161 if (ret)
162 return ret;
164 return 0;
167 static krb5_error_code
168 kcmss_get_principal(krb5_context context,
169 krb5_ccache id,
170 krb5_principal *principal)
172 krb5_error_code ret;
173 kcm_ccache c = KCMCACHE(id);
175 KCM_ASSERT_VALID(c);
177 ret = krb5_copy_principal(context, c->client,
178 principal);
180 return ret;
183 static krb5_error_code
184 kcmss_get_first (krb5_context context,
185 krb5_ccache id,
186 krb5_cc_cursor *cursor)
188 kcm_ccache c = KCMCACHE(id);
190 KCM_ASSERT_VALID(c);
192 *cursor = c->creds;
194 return (*cursor == NULL) ? KRB5_CC_END : 0;
197 static krb5_error_code
198 kcmss_get_next (krb5_context context,
199 krb5_ccache id,
200 krb5_cc_cursor *cursor,
201 krb5_creds *creds)
203 krb5_error_code ret;
204 kcm_ccache c = KCMCACHE(id);
206 KCM_ASSERT_VALID(c);
208 ret = krb5_copy_creds_contents(context,
209 &((struct kcm_creds *)cursor)->cred,
210 creds);
211 if (ret)
212 return ret;
214 *cursor = ((struct kcm_creds *)cursor)->next;
215 if (*cursor == 0)
216 ret = KRB5_CC_END;
218 return ret;
221 static krb5_error_code
222 kcmss_end_get (krb5_context context,
223 krb5_ccache id,
224 krb5_cc_cursor *cursor)
226 *cursor = NULL;
227 return 0;
230 static krb5_error_code
231 kcmss_remove_cred(krb5_context context,
232 krb5_ccache id,
233 krb5_flags which,
234 krb5_creds *cred)
236 krb5_error_code ret;
237 kcm_ccache c = KCMCACHE(id);
239 KCM_ASSERT_VALID(c);
241 ret = kcm_ccache_remove_cred_internal(context, c, which, cred);
243 return ret;
246 static krb5_error_code
247 kcmss_set_flags(krb5_context context,
248 krb5_ccache id,
249 krb5_flags flags)
251 return 0;
254 static krb5_error_code
255 kcmss_get_version(krb5_context context,
256 krb5_ccache id)
258 return 0;
261 static const krb5_cc_ops krb5_kcmss_ops = {
262 KRB5_CC_OPS_VERSION_5,
263 "KCM",
264 NULL,
265 NULL,
266 kcmss_gen_new,
267 kcmss_initialize,
268 kcmss_destroy,
269 kcmss_close,
270 kcmss_store_cred,
271 kcmss_retrieve,
272 kcmss_get_principal,
273 kcmss_get_first,
274 kcmss_get_next,
275 kcmss_end_get,
276 kcmss_remove_cred,
277 kcmss_set_flags,
278 kcmss_get_version,
279 NULL,
280 NULL,
281 NULL,
282 NULL,
283 NULL,
284 NULL,
285 NULL,
286 NULL,
287 NULL,
288 kcmss_get_name_2,
289 kcmss_resolve_2,
292 krb5_error_code
293 kcm_internal_ccache(krb5_context context,
294 kcm_ccache c,
295 krb5_ccache id)
297 id->ops = &krb5_kcmss_ops;
298 id->data.length = sizeof(*c);
299 id->data.data = c;
301 return 0;