Sync usage with man page.
[netbsd-mini2440.git] / crypto / dist / heimdal / kcm / glue.c
blob2e3e005a086b6b0a57aba3ed42a06463d24e1a78
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("$Heimdal: glue.c 14566 2005-02-06 01:22:49Z lukeh $"
36 "$NetBSD$");
39 * Server-side loopback glue for credentials cache operations; this
40 * must be initialized with kcm_internal_ccache(), it is not for real
41 * use. This entire file assumes the cache is locked, it does not do
42 * any concurrency checking for multithread applications.
45 #define KCMCACHE(X) ((kcm_ccache)(X)->data.data)
46 #define CACHENAME(X) (KCMCACHE(X)->name)
48 static const char *
49 kcmss_get_name(krb5_context context,
50 krb5_ccache id)
52 return CACHENAME(id);
55 static krb5_error_code
56 kcmss_resolve(krb5_context context, krb5_ccache *id, const char *res)
58 return KRB5_FCC_INTERNAL;
61 static krb5_error_code
62 kcmss_gen_new(krb5_context context, krb5_ccache *id)
64 return KRB5_FCC_INTERNAL;
67 static krb5_error_code
68 kcmss_initialize(krb5_context context,
69 krb5_ccache id,
70 krb5_principal primary_principal)
72 krb5_error_code ret;
73 kcm_ccache c = KCMCACHE(id);
75 KCM_ASSERT_VALID(c);
77 ret = kcm_zero_ccache_data_internal(context, c);
78 if (ret)
79 return ret;
81 ret = krb5_copy_principal(context, primary_principal,
82 &c->client);
84 return ret;
87 static krb5_error_code
88 kcmss_close(krb5_context context,
89 krb5_ccache id)
91 kcm_ccache c = KCMCACHE(id);
93 KCM_ASSERT_VALID(c);
95 id->data.data = NULL;
96 id->data.length = 0;
98 return 0;
101 static krb5_error_code
102 kcmss_destroy(krb5_context context,
103 krb5_ccache id)
105 krb5_error_code ret;
106 kcm_ccache c = KCMCACHE(id);
108 KCM_ASSERT_VALID(c);
110 ret = kcm_ccache_destroy(context, CACHENAME(id));
112 return ret;
115 static krb5_error_code
116 kcmss_store_cred(krb5_context context,
117 krb5_ccache id,
118 krb5_creds *creds)
120 krb5_error_code ret;
121 kcm_ccache c = KCMCACHE(id);
122 krb5_creds *tmp;
124 KCM_ASSERT_VALID(c);
126 ret = kcm_ccache_store_cred_internal(context, c, creds, 1, &tmp);
128 return ret;
131 static krb5_error_code
132 kcmss_retrieve(krb5_context context,
133 krb5_ccache id,
134 krb5_flags which,
135 const krb5_creds *mcred,
136 krb5_creds *creds)
138 krb5_error_code ret;
139 kcm_ccache c = KCMCACHE(id);
140 krb5_creds *credp;
142 KCM_ASSERT_VALID(c);
144 ret = kcm_ccache_retrieve_cred_internal(context, c, which,
145 mcred, &credp);
146 if (ret)
147 return ret;
149 ret = krb5_copy_creds_contents(context, credp, creds);
150 if (ret)
151 return ret;
153 return 0;
156 static krb5_error_code
157 kcmss_get_principal(krb5_context context,
158 krb5_ccache id,
159 krb5_principal *principal)
161 krb5_error_code ret;
162 kcm_ccache c = KCMCACHE(id);
164 KCM_ASSERT_VALID(c);
166 ret = krb5_copy_principal(context, c->client,
167 principal);
169 return ret;
172 static krb5_error_code
173 kcmss_get_first (krb5_context context,
174 krb5_ccache id,
175 krb5_cc_cursor *cursor)
177 kcm_ccache c = KCMCACHE(id);
179 KCM_ASSERT_VALID(c);
181 *cursor = c->creds;
183 return (*cursor == NULL) ? KRB5_CC_END : 0;
186 static krb5_error_code
187 kcmss_get_next (krb5_context context,
188 krb5_ccache id,
189 krb5_cc_cursor *cursor,
190 krb5_creds *creds)
192 krb5_error_code ret;
193 kcm_ccache c = KCMCACHE(id);
195 KCM_ASSERT_VALID(c);
197 ret = krb5_copy_creds_contents(context,
198 &((struct kcm_creds *)cursor)->cred,
199 creds);
200 if (ret)
201 return ret;
203 *cursor = ((struct kcm_creds *)cursor)->next;
204 if (*cursor == 0)
205 ret = KRB5_CC_END;
207 return ret;
210 static krb5_error_code
211 kcmss_end_get (krb5_context context,
212 krb5_ccache id,
213 krb5_cc_cursor *cursor)
215 *cursor = NULL;
216 return 0;
219 static krb5_error_code
220 kcmss_remove_cred(krb5_context context,
221 krb5_ccache id,
222 krb5_flags which,
223 krb5_creds *cred)
225 krb5_error_code ret;
226 kcm_ccache c = KCMCACHE(id);
228 KCM_ASSERT_VALID(c);
230 ret = kcm_ccache_remove_cred_internal(context, c, which, cred);
232 return ret;
235 static krb5_error_code
236 kcmss_set_flags(krb5_context context,
237 krb5_ccache id,
238 krb5_flags flags)
240 return 0;
243 static krb5_error_code
244 kcmss_get_version(krb5_context context,
245 krb5_ccache id)
247 return 0;
250 static const krb5_cc_ops krb5_kcmss_ops = {
251 "KCM",
252 kcmss_get_name,
253 kcmss_resolve,
254 kcmss_gen_new,
255 kcmss_initialize,
256 kcmss_destroy,
257 kcmss_close,
258 kcmss_store_cred,
259 kcmss_retrieve,
260 kcmss_get_principal,
261 kcmss_get_first,
262 kcmss_get_next,
263 kcmss_end_get,
264 kcmss_remove_cred,
265 kcmss_set_flags,
266 kcmss_get_version
269 krb5_error_code
270 kcm_internal_ccache(krb5_context context,
271 kcm_ccache c,
272 krb5_ccache id)
274 id->ops = &krb5_kcmss_ops;
275 id->data.length = sizeof(*c);
276 id->data.data = c;
278 return 0;