No empty .Rs/.Re
[netbsd-mini2440.git] / crypto / dist / heimdal / kcm / cursor.c
blobb385b927c55e87124e02b04ebcdf79b25f41059c
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: cursor.c 17447 2006-05-05 10:52:01Z lha $"
36 "$NetBSD$");
38 krb5_error_code
39 kcm_cursor_new(krb5_context context,
40 pid_t pid,
41 kcm_ccache ccache,
42 uint32_t *cursor)
44 kcm_cursor **p;
45 krb5_error_code ret;
47 *cursor = 0;
49 KCM_ASSERT_VALID(ccache);
51 HEIMDAL_MUTEX_lock(&ccache->mutex);
52 for (p = &ccache->cursors; *p != NULL; p = &(*p)->next)
55 *p = (kcm_cursor *)malloc(sizeof(kcm_cursor));
56 if (*p == NULL) {
57 ret = KRB5_CC_NOMEM;
58 goto out;
61 (*p)->pid = pid;
62 (*p)->key = ++ccache->n_cursor;
63 (*p)->credp = ccache->creds;
64 (*p)->next = NULL;
66 *cursor = (*p)->key;
68 ret = 0;
70 out:
71 HEIMDAL_MUTEX_unlock(&ccache->mutex);
73 return ret;
76 krb5_error_code
77 kcm_cursor_find(krb5_context context,
78 pid_t pid,
79 kcm_ccache ccache,
80 uint32_t key,
81 kcm_cursor **cursor)
83 kcm_cursor *p;
84 krb5_error_code ret;
86 KCM_ASSERT_VALID(ccache);
88 if (key == 0)
89 return KRB5_CC_NOTFOUND;
91 ret = KRB5_CC_END;
93 HEIMDAL_MUTEX_lock(&ccache->mutex);
95 for (p = ccache->cursors; p != NULL; p = p->next) {
96 if (p->key == key) {
97 if (p->pid != pid)
98 ret = KRB5_FCC_PERM;
99 else
100 ret = 0;
101 break;
105 if (ret == 0)
106 *cursor = p;
108 HEIMDAL_MUTEX_unlock(&ccache->mutex);
110 return ret;
113 krb5_error_code
114 kcm_cursor_delete(krb5_context context,
115 pid_t pid,
116 kcm_ccache ccache,
117 uint32_t key)
119 kcm_cursor **p;
120 krb5_error_code ret;
122 KCM_ASSERT_VALID(ccache);
124 if (key == 0)
125 return KRB5_CC_NOTFOUND;
127 ret = KRB5_CC_END;
129 HEIMDAL_MUTEX_lock(&ccache->mutex);
131 for (p = &ccache->cursors; *p != NULL; p = &(*p)->next) {
132 if ((*p)->key == key) {
133 if ((*p)->pid != pid)
134 ret = KRB5_FCC_PERM;
135 else
136 ret = 0;
137 break;
141 if (ret == 0) {
142 kcm_cursor *x = *p;
144 *p = x->next;
145 free(x);
148 HEIMDAL_MUTEX_unlock(&ccache->mutex);
150 return ret;