2 * Copyright (c) 2004 - 2007 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
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.
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.
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
34 #include "krb5_locl.h"
35 #include <krb5_ccapi.h>
42 /* XXX should we fetch these for each open ? */
43 static HEIMDAL_MUTEX acc_mutex
= HEIMDAL_MUTEX_INITIALIZER
;
44 static cc_initialize_func init_func
;
47 static void *cc_handle
;
50 typedef struct krb5_acc
{
56 static krb5_error_code
acc_close(krb5_context
, krb5_ccache
);
58 #define ACACHE(X) ((krb5_acc *)(X)->data.data)
64 { ccErrBadName
, KRB5_CC_BADNAME
},
65 { ccErrCredentialsNotFound
, KRB5_CC_NOTFOUND
},
66 { ccErrCCacheNotFound
, KRB5_FCC_NOFILE
},
67 { ccErrContextNotFound
, KRB5_CC_NOTFOUND
},
68 { ccIteratorEnd
, KRB5_CC_END
},
69 { ccErrNoMem
, KRB5_CC_NOMEM
},
70 { ccErrServerUnavailable
, KRB5_CC_NOSUPP
},
71 { ccErrInvalidCCache
, KRB5_CC_BADNAME
},
75 static krb5_error_code
76 translate_cc_error(krb5_context context
, cc_int32 error
)
79 krb5_clear_error_string(context
);
80 for(i
= 0; i
< sizeof(cc_errors
)/sizeof(cc_errors
[0]); i
++)
81 if (cc_errors
[i
].error
== error
)
82 return cc_errors
[i
].ret
;
83 return KRB5_FCC_INTERNAL
;
86 static krb5_error_code
87 init_ccapi(krb5_context context
)
91 HEIMDAL_MUTEX_lock(&acc_mutex
);
93 HEIMDAL_MUTEX_unlock(&acc_mutex
);
94 krb5_clear_error_string(context
);
98 lib
= krb5_config_get_string(context
, NULL
,
99 "libdefaults", "ccapi_library",
103 lib
= "/System/Library/Frameworks/Kerberos.framework/Kerberos";
105 lib
= "/usr/lib/libkrb5_cc.so";
115 cc_handle
= dlopen(lib
, RTLD_LAZY
);
116 if (cc_handle
== NULL
) {
117 HEIMDAL_MUTEX_unlock(&acc_mutex
);
118 krb5_set_error_string(context
, "Failed to load %s", lib
);
119 return KRB5_CC_NOSUPP
;
122 init_func
= (cc_initialize_func
)dlsym(cc_handle
, "cc_initialize");
123 HEIMDAL_MUTEX_unlock(&acc_mutex
);
124 if (init_func
== NULL
) {
125 krb5_set_error_string(context
, "Failed to find cc_initialize"
126 "in %s: %s", lib
, dlerror());
128 return KRB5_CC_NOSUPP
;
133 HEIMDAL_MUTEX_unlock(&acc_mutex
);
134 krb5_set_error_string(context
, "no support for shared object");
135 return KRB5_CC_NOSUPP
;
139 static krb5_error_code
140 make_cred_from_ccred(krb5_context context
,
141 const cc_credentials_v5_t
*incred
,
147 memset(cred
, 0, sizeof(*cred
));
149 ret
= krb5_parse_name(context
, incred
->client
, &cred
->client
);
153 ret
= krb5_parse_name(context
, incred
->server
, &cred
->server
);
157 cred
->session
.keytype
= incred
->keyblock
.type
;
158 cred
->session
.keyvalue
.length
= incred
->keyblock
.length
;
159 cred
->session
.keyvalue
.data
= malloc(incred
->keyblock
.length
);
160 if (cred
->session
.keyvalue
.data
== NULL
)
162 memcpy(cred
->session
.keyvalue
.data
, incred
->keyblock
.data
,
163 incred
->keyblock
.length
);
165 cred
->times
.authtime
= incred
->authtime
;
166 cred
->times
.starttime
= incred
->starttime
;
167 cred
->times
.endtime
= incred
->endtime
;
168 cred
->times
.renew_till
= incred
->renew_till
;
170 ret
= krb5_data_copy(&cred
->ticket
,
172 incred
->ticket
.length
);
176 ret
= krb5_data_copy(&cred
->second_ticket
,
177 incred
->second_ticket
.data
,
178 incred
->second_ticket
.length
);
182 cred
->authdata
.val
= NULL
;
183 cred
->authdata
.len
= 0;
185 cred
->addresses
.val
= NULL
;
186 cred
->addresses
.len
= 0;
188 for (i
= 0; incred
->authdata
&& incred
->authdata
[i
]; i
++)
192 cred
->authdata
.val
= calloc(i
, sizeof(cred
->authdata
.val
[0]));
193 if (cred
->authdata
.val
== NULL
)
195 cred
->authdata
.len
= i
;
196 for (i
= 0; i
< cred
->authdata
.len
; i
++) {
197 cred
->authdata
.val
[i
].ad_type
= incred
->authdata
[i
]->type
;
198 ret
= krb5_data_copy(&cred
->authdata
.val
[i
].ad_data
,
199 incred
->authdata
[i
]->data
,
200 incred
->authdata
[i
]->length
);
206 for (i
= 0; incred
->addresses
&& incred
->addresses
[i
]; i
++)
210 cred
->addresses
.val
= calloc(i
, sizeof(cred
->addresses
.val
[0]));
211 if (cred
->addresses
.val
== NULL
)
213 cred
->addresses
.len
= i
;
215 for (i
= 0; i
< cred
->addresses
.len
; i
++) {
216 cred
->addresses
.val
[i
].addr_type
= incred
->addresses
[i
]->type
;
217 ret
= krb5_data_copy(&cred
->addresses
.val
[i
].address
,
218 incred
->addresses
[i
]->data
,
219 incred
->addresses
[i
]->length
);
226 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_FORWARDABLE
)
227 cred
->flags
.b
.forwardable
= 1;
228 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_FORWARDED
)
229 cred
->flags
.b
.forwarded
= 1;
230 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_PROXIABLE
)
231 cred
->flags
.b
.proxiable
= 1;
232 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_PROXY
)
233 cred
->flags
.b
.proxy
= 1;
234 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_MAY_POSTDATE
)
235 cred
->flags
.b
.may_postdate
= 1;
236 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_POSTDATED
)
237 cred
->flags
.b
.postdated
= 1;
238 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_INVALID
)
239 cred
->flags
.b
.invalid
= 1;
240 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_RENEWABLE
)
241 cred
->flags
.b
.renewable
= 1;
242 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_INITIAL
)
243 cred
->flags
.b
.initial
= 1;
244 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_PRE_AUTH
)
245 cred
->flags
.b
.pre_authent
= 1;
246 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_HW_AUTH
)
247 cred
->flags
.b
.hw_authent
= 1;
248 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_TRANSIT_POLICY_CHECKED
)
249 cred
->flags
.b
.transited_policy_checked
= 1;
250 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_OK_AS_DELEGATE
)
251 cred
->flags
.b
.ok_as_delegate
= 1;
252 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_ANONYMOUS
)
253 cred
->flags
.b
.anonymous
= 1;
259 krb5_set_error_string(context
, "malloc - out of memory");
262 krb5_free_cred_contents(context
, cred
);
267 free_ccred(cc_credentials_v5_t
*cred
)
271 if (cred
->addresses
) {
272 for (i
= 0; cred
->addresses
[i
] != 0; i
++) {
273 if (cred
->addresses
[i
]->data
)
274 free(cred
->addresses
[i
]->data
);
275 free(cred
->addresses
[i
]);
277 free(cred
->addresses
);
283 memset(cred
, 0, sizeof(*cred
));
286 static krb5_error_code
287 make_ccred_from_cred(krb5_context context
,
288 const krb5_creds
*incred
,
289 cc_credentials_v5_t
*cred
)
294 memset(cred
, 0, sizeof(*cred
));
296 ret
= krb5_unparse_name(context
, incred
->client
, &cred
->client
);
300 ret
= krb5_unparse_name(context
, incred
->server
, &cred
->server
);
304 cred
->keyblock
.type
= incred
->session
.keytype
;
305 cred
->keyblock
.length
= incred
->session
.keyvalue
.length
;
306 cred
->keyblock
.data
= incred
->session
.keyvalue
.data
;
308 cred
->authtime
= incred
->times
.authtime
;
309 cred
->starttime
= incred
->times
.starttime
;
310 cred
->endtime
= incred
->times
.endtime
;
311 cred
->renew_till
= incred
->times
.renew_till
;
313 cred
->ticket
.length
= incred
->ticket
.length
;
314 cred
->ticket
.data
= incred
->ticket
.data
;
316 cred
->second_ticket
.length
= incred
->second_ticket
.length
;
317 cred
->second_ticket
.data
= incred
->second_ticket
.data
;
319 /* XXX this one should also be filled in */
320 cred
->authdata
= NULL
;
322 cred
->addresses
= calloc(incred
->addresses
.len
+ 1,
323 sizeof(cred
->addresses
[0]));
324 if (cred
->addresses
== NULL
) {
330 for (i
= 0; i
< incred
->addresses
.len
; i
++) {
332 addr
= malloc(sizeof(*addr
));
337 addr
->type
= incred
->addresses
.val
[i
].addr_type
;
338 addr
->length
= incred
->addresses
.val
[i
].address
.length
;
339 addr
->data
= malloc(addr
->length
);
340 if (addr
->data
== NULL
) {
344 memcpy(addr
->data
, incred
->addresses
.val
[i
].address
.data
,
346 cred
->addresses
[i
] = addr
;
348 cred
->addresses
[i
] = NULL
;
350 cred
->ticket_flags
= 0;
351 if (incred
->flags
.b
.forwardable
)
352 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_FORWARDABLE
;
353 if (incred
->flags
.b
.forwarded
)
354 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_FORWARDED
;
355 if (incred
->flags
.b
.proxiable
)
356 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_PROXIABLE
;
357 if (incred
->flags
.b
.proxy
)
358 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_PROXY
;
359 if (incred
->flags
.b
.may_postdate
)
360 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_MAY_POSTDATE
;
361 if (incred
->flags
.b
.postdated
)
362 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_POSTDATED
;
363 if (incred
->flags
.b
.invalid
)
364 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_INVALID
;
365 if (incred
->flags
.b
.renewable
)
366 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_RENEWABLE
;
367 if (incred
->flags
.b
.initial
)
368 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_INITIAL
;
369 if (incred
->flags
.b
.pre_authent
)
370 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_PRE_AUTH
;
371 if (incred
->flags
.b
.hw_authent
)
372 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_HW_AUTH
;
373 if (incred
->flags
.b
.transited_policy_checked
)
374 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_TRANSIT_POLICY_CHECKED
;
375 if (incred
->flags
.b
.ok_as_delegate
)
376 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_OK_AS_DELEGATE
;
377 if (incred
->flags
.b
.anonymous
)
378 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_ANONYMOUS
;
385 krb5_clear_error_string(context
);
390 get_cc_name(krb5_acc
*a
)
395 error
= (*a
->ccache
->func
->get_name
)(a
->ccache
, &name
);
399 a
->cache_name
= strdup(name
->data
);
400 (*name
->func
->release
)(name
);
401 if (a
->cache_name
== NULL
)
408 acc_get_name(krb5_context context
,
411 krb5_acc
*a
= ACACHE(id
);
414 if (a
->cache_name
== NULL
) {
416 krb5_principal principal
;
419 ret
= _krb5_get_default_principal_local(context
, &principal
);
423 ret
= krb5_unparse_name(context
, principal
, &name
);
424 krb5_free_principal(context
, principal
);
428 error
= (*a
->context
->func
->create_new_ccache
)(a
->context
,
436 error
= get_cc_name(a
);
441 return a
->cache_name
;
444 static krb5_error_code
445 acc_alloc(krb5_context context
, krb5_ccache
*id
)
451 ret
= init_ccapi(context
);
455 ret
= krb5_data_alloc(&(*id
)->data
, sizeof(*a
));
457 krb5_clear_error_string(context
);
463 error
= (*init_func
)(&a
->context
, ccapi_version_3
, NULL
, NULL
);
465 krb5_data_free(&(*id
)->data
);
466 return translate_cc_error(context
, error
);
469 a
->cache_name
= NULL
;
474 static krb5_error_code
475 acc_resolve(krb5_context context
, krb5_ccache
*id
, const char *res
)
481 ret
= acc_alloc(context
, id
);
487 error
= (*a
->context
->func
->open_ccache
)(a
->context
, res
, &a
->ccache
);
488 if (error
== ccNoError
) {
489 error
= get_cc_name(a
);
490 if (error
!= ccNoError
) {
491 acc_close(context
, *id
);
493 return translate_cc_error(context
, error
);
495 } else if (error
== ccErrCCacheNotFound
) {
497 a
->cache_name
= NULL
;
501 return translate_cc_error(context
, error
);
507 static krb5_error_code
508 acc_gen_new(krb5_context context
, krb5_ccache
*id
)
513 ret
= acc_alloc(context
, id
);
520 a
->cache_name
= NULL
;
525 static krb5_error_code
526 acc_initialize(krb5_context context
,
528 krb5_principal primary_principal
)
530 krb5_acc
*a
= ACACHE(id
);
535 ret
= krb5_unparse_name(context
, primary_principal
, &name
);
539 if (a
->cache_name
== NULL
) {
540 error
= (*a
->context
->func
->create_new_ccache
)(a
->context
,
545 if (error
== ccNoError
)
546 error
= get_cc_name(a
);
548 cc_credentials_iterator_t iter
;
549 cc_credentials_t ccred
;
551 error
= (*a
->ccache
->func
->new_credentials_iterator
)(a
->ccache
, &iter
);
554 return translate_cc_error(context
, error
);
558 error
= (*iter
->func
->next
)(iter
, &ccred
);
561 (*a
->ccache
->func
->remove_credentials
)(a
->ccache
, ccred
);
562 (*ccred
->func
->release
)(ccred
);
564 (*iter
->func
->release
)(iter
);
566 error
= (*a
->ccache
->func
->set_principal
)(a
->ccache
,
571 return translate_cc_error(context
, error
);
574 static krb5_error_code
575 acc_close(krb5_context context
,
578 krb5_acc
*a
= ACACHE(id
);
581 (*a
->ccache
->func
->release
)(a
->ccache
);
586 a
->cache_name
= NULL
;
589 (*a
->context
->func
->release
)(a
->context
);
592 krb5_data_free(&id
->data
);
596 static krb5_error_code
597 acc_destroy(krb5_context context
,
600 krb5_acc
*a
= ACACHE(id
);
604 error
= (*a
->ccache
->func
->destroy
)(a
->ccache
);
608 error
= (a
->context
->func
->release
)(a
->context
);
611 return translate_cc_error(context
, error
);
614 static krb5_error_code
615 acc_store_cred(krb5_context context
,
619 krb5_acc
*a
= ACACHE(id
);
620 cc_credentials_union cred
;
621 cc_credentials_v5_t v5cred
;
625 if (a
->ccache
== NULL
) {
626 krb5_set_error_string(context
, "No API credential found");
627 return KRB5_CC_NOTFOUND
;
630 cred
.version
= cc_credentials_v5
;
631 cred
.credentials
.credentials_v5
= &v5cred
;
633 ret
= make_ccred_from_cred(context
,
639 error
= (*a
->ccache
->func
->store_credentials
)(a
->ccache
, &cred
);
641 ret
= translate_cc_error(context
, error
);
648 static krb5_error_code
649 acc_get_principal(krb5_context context
,
651 krb5_principal
*principal
)
653 krb5_acc
*a
= ACACHE(id
);
658 if (a
->ccache
== NULL
) {
659 krb5_set_error_string(context
, "No API credential found");
660 return KRB5_CC_NOTFOUND
;
663 error
= (*a
->ccache
->func
->get_principal
)(a
->ccache
,
667 return translate_cc_error(context
, error
);
669 ret
= krb5_parse_name(context
, name
->data
, principal
);
671 (*name
->func
->release
)(name
);
675 static krb5_error_code
676 acc_get_first (krb5_context context
,
678 krb5_cc_cursor
*cursor
)
680 cc_credentials_iterator_t iter
;
681 krb5_acc
*a
= ACACHE(id
);
684 if (a
->ccache
== NULL
) {
685 krb5_set_error_string(context
, "No API credential found");
686 return KRB5_CC_NOTFOUND
;
689 error
= (*a
->ccache
->func
->new_credentials_iterator
)(a
->ccache
, &iter
);
691 krb5_clear_error_string(context
);
699 static krb5_error_code
700 acc_get_next (krb5_context context
,
702 krb5_cc_cursor
*cursor
,
705 cc_credentials_iterator_t iter
= *cursor
;
706 cc_credentials_t cred
;
711 error
= (*iter
->func
->next
)(iter
, &cred
);
713 return translate_cc_error(context
, error
);
714 if (cred
->data
->version
== cc_credentials_v5
)
716 (*cred
->func
->release
)(cred
);
719 ret
= make_cred_from_ccred(context
,
720 cred
->data
->credentials
.credentials_v5
,
722 (*cred
->func
->release
)(cred
);
726 static krb5_error_code
727 acc_end_get (krb5_context context
,
729 krb5_cc_cursor
*cursor
)
731 cc_credentials_iterator_t iter
= *cursor
;
732 (*iter
->func
->release
)(iter
);
736 static krb5_error_code
737 acc_remove_cred(krb5_context context
,
742 cc_credentials_iterator_t iter
;
743 krb5_acc
*a
= ACACHE(id
);
744 cc_credentials_t ccred
;
747 char *client
, *server
;
749 if (a
->ccache
== NULL
) {
750 krb5_set_error_string(context
, "No API credential found");
751 return KRB5_CC_NOTFOUND
;
755 ret
= krb5_unparse_name(context
, cred
->client
, &client
);
761 ret
= krb5_unparse_name(context
, cred
->server
, &server
);
767 error
= (*a
->ccache
->func
->new_credentials_iterator
)(a
->ccache
, &iter
);
771 return translate_cc_error(context
, error
);
774 ret
= KRB5_CC_NOTFOUND
;
776 cc_credentials_v5_t
*v5cred
;
778 error
= (*iter
->func
->next
)(iter
, &ccred
);
782 if (ccred
->data
->version
!= cc_credentials_v5
)
785 v5cred
= ccred
->data
->credentials
.credentials_v5
;
787 if (client
&& strcmp(v5cred
->client
, client
) != 0)
790 if (strcmp(v5cred
->server
, server
) != 0)
793 (*a
->ccache
->func
->remove_credentials
)(a
->ccache
, ccred
);
796 (*ccred
->func
->release
)(ccred
);
799 (*iter
->func
->release
)(iter
);
802 krb5_set_error_string(context
, "Can't find credential %s in cache",
810 static krb5_error_code
811 acc_set_flags(krb5_context context
,
819 acc_get_version(krb5_context context
,
826 cc_context_t context
;
827 cc_ccache_iterator_t iter
;
830 static krb5_error_code
831 acc_get_cache_first(krb5_context context
, krb5_cc_cursor
*cursor
)
833 struct cache_iter
*iter
;
837 ret
= init_ccapi(context
);
841 iter
= calloc(1, sizeof(*iter
));
843 krb5_set_error_string(context
, "malloc - out of memory");
847 error
= (*init_func
)(&iter
->context
, ccapi_version_3
, NULL
, NULL
);
850 return translate_cc_error(context
, error
);
853 error
= (*iter
->context
->func
->new_ccache_iterator
)(iter
->context
,
857 krb5_clear_error_string(context
);
864 static krb5_error_code
865 acc_get_cache_next(krb5_context context
, krb5_cc_cursor cursor
, krb5_ccache
*id
)
867 struct cache_iter
*iter
= cursor
;
873 error
= (*iter
->iter
->func
->next
)(iter
->iter
, &cache
);
875 return translate_cc_error(context
, error
);
877 ret
= _krb5_cc_allocate(context
, &krb5_acc_ops
, id
);
879 (*cache
->func
->release
)(cache
);
883 ret
= acc_alloc(context
, id
);
885 (*cache
->func
->release
)(cache
);
893 error
= get_cc_name(a
);
895 acc_close(context
, *id
);
897 return translate_cc_error(context
, error
);
902 static krb5_error_code
903 acc_end_cache_get(krb5_context context
, krb5_cc_cursor cursor
)
905 struct cache_iter
*iter
= cursor
;
907 (*iter
->iter
->func
->release
)(iter
->iter
);
909 (*iter
->context
->func
->release
)(iter
->context
);
910 iter
->context
= NULL
;
915 static krb5_error_code
916 acc_move(krb5_context context
, krb5_ccache from
, krb5_ccache to
)
918 krb5_acc
*afrom
= ACACHE(from
);
919 krb5_acc
*ato
= ACACHE(to
);
922 if (ato
->ccache
== NULL
) {
925 error
= (*afrom
->ccache
->func
->get_principal
)(afrom
->ccache
,
929 return translate_cc_error(context
, error
);
931 error
= (*ato
->context
->func
->create_new_ccache
)(ato
->context
,
935 (*name
->func
->release
)(name
);
937 return translate_cc_error(context
, error
);
941 error
= (*ato
->ccache
->func
->move
)(afrom
->ccache
, ato
->ccache
);
942 return translate_cc_error(context
, error
);
945 static krb5_error_code
946 acc_get_default_name(krb5_context context
, char **str
)
953 ret
= init_ccapi(context
);
957 error
= (*init_func
)(&cc
, ccapi_version_3
, NULL
, NULL
);
959 return translate_cc_error(context
, error
);
961 error
= (*cc
->func
->get_default_ccache_name
)(cc
, &name
);
963 (*cc
->func
->release
)(cc
);
964 return translate_cc_error(context
, error
);
967 asprintf(str
, "API:%s", name
->data
);
968 (*name
->func
->release
)(name
);
969 (*cc
->func
->release
)(cc
);
972 krb5_set_error_string(context
, "out of memory");
978 static krb5_error_code
979 acc_set_default(krb5_context context
, krb5_ccache id
)
981 krb5_acc
*a
= ACACHE(id
);
984 if (a
->ccache
== NULL
) {
985 krb5_set_error_string(context
, "No API credential found");
986 return KRB5_CC_NOTFOUND
;
989 error
= (*a
->ccache
->func
->set_default
)(a
->ccache
);
991 return translate_cc_error(context
, error
);
997 * Variable containing the API based credential cache implemention.
999 * @ingroup krb5_ccache
1002 KRB5_LIB_VARIABLE
const krb5_cc_ops krb5_acc_ops
= {
1003 KRB5_CC_OPS_VERSION
,
1012 NULL
, /* acc_retrieve */
1020 acc_get_cache_first
,
1024 acc_get_default_name
,