1 /* 2 * Copyright (c) 1997-1999 Kungliga Tekniska H�gskolan 3 * (Royal Institute of Technology, Stockholm, Sweden). 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * 3. Neither the name of the Institute nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34 #include "krb5_locl.h" 35 36 RCSID("$Id: mcache.c,v 1.10 1999/12/02 17:05:11 joda Exp $"); 37 38 typedef struct krb5_mcache { 39 krb5_principal primary_principal; 40 struct link { 41 krb5_creds cred; 42 struct link *next; 43 } *creds; 44 } krb5_mcache; 45 46 #define MCC_CURSOR(C) ((struct link*)(C)) 47 48 static char* 49 mcc_get_name(krb5_context context, 50 krb5_ccache id) 51 { 52 return ""; /* XXX */ 53 } 54 55 static krb5_error_code 56 mcc_resolve(krb5_context context, krb5_ccache *id, const char *res) 57 { 58 krb5_abortx(context, "unimplemented mcc_resolve called"); 59 } 60 61 static krb5_error_code 62 mcc_gen_new(krb5_context context, krb5_ccache *id) 63 { 64 krb5_mcache *m; 65 66 m = malloc (sizeof(*m)); 67 if (m == NULL) 68 return KRB5_CC_NOMEM; 69 m->primary_principal = NULL; 70 m->creds = NULL; 71 (*id)->data.data = m; 72 (*id)->data.length = sizeof(*m); 73 return 0; 74 } 75 76 static krb5_error_code 77 mcc_initialize(krb5_context context, 78 krb5_ccache id, 79 krb5_principal primary_principal) 80 { 81 krb5_error_code ret; 82 krb5_mcache *m; 83 84 m = (krb5_mcache *)id->data.data; 85 86 ret = krb5_copy_principal (context, 87 primary_principal, 88 &m->primary_principal); 89 if (ret) 90 return ret; 91 return 0; 92 } 93 94 static krb5_error_code 95 mcc_close(krb5_context context, 96 krb5_ccache id) 97 { 98 krb5_mcache *m = (krb5_mcache *)id->data.data; 99 struct link *l; 100 101 krb5_free_principal (context, m->primary_principal); 102 l = m->creds; 103 while (l != NULL) { 104 struct link *old; 105 106 krb5_free_creds_contents (context, &l->cred); 107 old = l; 108 l = l->next; 109 free (old); 110 } 111 krb5_data_free(&id->data); 112 return 0; 113 } 114 115 static krb5_error_code 116 mcc_destroy(krb5_context context, 117 krb5_ccache id) 118 { 119 return 0; 120 } 121 122 static krb5_error_code 123 mcc_store_cred(krb5_context context, 124 krb5_ccache id, 125 krb5_creds *creds) 126 { 127 krb5_error_code ret; 128 krb5_mcache *m = (krb5_mcache *)id->data.data; 129 struct link *l; 130 131 l = malloc (sizeof(*l)); 132 if (l == NULL) 133 return KRB5_CC_NOMEM; 134 l->next = m->creds; 135 m->creds = l; 136 memset (&l->cred, 0, sizeof(l->cred)); 137 ret = krb5_copy_creds_contents (context, creds, &l->cred); 138 if (ret) { 139 m->creds = l->next; 140 free (l); 141 return ret; 142 } 143 return 0; 144 } 145 146 static krb5_error_code 147 mcc_get_principal(krb5_context context, 148 krb5_ccache id, 149 krb5_principal *principal) 150 { 151 krb5_mcache *m = (krb5_mcache *)id->data.data; 152 153 return krb5_copy_principal (context, 154 m->primary_principal, 155 principal); 156 } 157 158 static krb5_error_code 159 mcc_get_first (krb5_context context, 160 krb5_ccache id, 161 krb5_cc_cursor *cursor) 162 { 163 krb5_mcache *m = (krb5_mcache *)id->data.data; 164 *cursor = m->creds; 165 return 0; 166 } 167 168 static krb5_error_code 169 mcc_get_next (krb5_context context, 170 krb5_ccache id, 171 krb5_cc_cursor *cursor, 172 krb5_creds *creds) 173 { 174 struct link *l; 175 176 l = *cursor; 177 if (l != NULL) { 178 *cursor = l->next; 179 return krb5_copy_creds_contents (context, 180 &l->cred, 181 creds); 182 } else 183 return KRB5_CC_END; 184 } 185 186 static krb5_error_code 187 mcc_end_get (krb5_context context, 188 krb5_ccache id, 189 krb5_cc_cursor *cursor) 190 { 191 return 0; 192 } 193 194 static krb5_error_code 195 mcc_remove_cred(krb5_context context, 196 krb5_ccache id, 197 krb5_flags which, 198 krb5_creds *cred) 199 { 200 return 0; /* XXX */ 201 } 202 203 static krb5_error_code 204 mcc_set_flags(krb5_context context, 205 krb5_ccache id, 206 krb5_flags flags) 207 { 208 return 0; /* XXX */ 209 } 210 211 const krb5_cc_ops krb5_mcc_ops = { 212 "MEMORY", 213 mcc_get_name, 214 mcc_resolve, 215 mcc_gen_new, 216 mcc_initialize, 217 mcc_destroy, 218 mcc_close, 219 mcc_store_cred, 220 NULL, /* mcc_retrieve */ 221 mcc_get_principal, 222 mcc_get_first, 223 mcc_get_next, 224 mcc_end_get, 225 mcc_remove_cred, 226 mcc_set_flags 227 }; 228