2 * Copyright (c) 2004 - 2007 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include "krb5_locl.h"
37 #include <krb5_ccapi.h>
42 #ifndef KCM_IS_API_CACHE
44 static HEIMDAL_MUTEX acc_mutex
= HEIMDAL_MUTEX_INITIALIZER
;
45 static cc_initialize_func init_func
;
46 static void (KRB5_CALLCONV
*set_target_uid
)(uid_t
);
47 static void (KRB5_CALLCONV
*clear_target
)(void);
50 static void *cc_handle
;
53 typedef struct krb5_acc
{
59 static krb5_error_code KRB5_CALLCONV
acc_close(krb5_context
, krb5_ccache
);
61 #define ACACHE(X) ((krb5_acc *)(X)->data.data)
67 { ccErrBadName
, KRB5_CC_BADNAME
},
68 { ccErrCredentialsNotFound
, KRB5_CC_NOTFOUND
},
69 { ccErrCCacheNotFound
, KRB5_FCC_NOFILE
},
70 { ccErrContextNotFound
, KRB5_CC_NOTFOUND
},
71 { ccIteratorEnd
, KRB5_CC_END
},
72 { ccErrNoMem
, KRB5_CC_NOMEM
},
73 { ccErrServerUnavailable
, KRB5_CC_NOSUPP
},
74 { ccErrInvalidCCache
, KRB5_CC_BADNAME
},
78 static krb5_error_code
79 translate_cc_error(krb5_context context
, cc_int32 error
)
82 krb5_clear_error_message(context
);
83 for(i
= 0; i
< sizeof(cc_errors
)/sizeof(cc_errors
[0]); i
++)
84 if (cc_errors
[i
].error
== error
)
85 return cc_errors
[i
].ret
;
86 return KRB5_FCC_INTERNAL
;
89 static krb5_error_code
90 init_ccapi(krb5_context context
)
92 const char *lib
= NULL
;
94 HEIMDAL_MUTEX_lock(&acc_mutex
);
96 HEIMDAL_MUTEX_unlock(&acc_mutex
);
98 krb5_clear_error_message(context
);
103 lib
= krb5_config_get_string(context
, NULL
,
104 "libdefaults", "ccapi_library",
108 lib
= "/System/Library/Frameworks/Kerberos.framework/Kerberos";
109 #elif defined(KRB5_USE_PATH_TOKENS) && defined(_WIN32)
110 lib
= "%{LIBDIR}/libkrb5_cc.dll";
112 lib
= "/usr/lib/libkrb5_cc.so";
125 #ifdef KRB5_USE_PATH_TOKENS
127 char * explib
= NULL
;
128 if (_krb5_expand_path_tokens(context
, lib
, &explib
) == 0) {
129 cc_handle
= dlopen(explib
, RTLD_LAZY
|RTLD_LOCAL
);
134 cc_handle
= dlopen(lib
, RTLD_LAZY
|RTLD_LOCAL
);
137 if (cc_handle
== NULL
) {
138 HEIMDAL_MUTEX_unlock(&acc_mutex
);
140 krb5_set_error_message(context
, KRB5_CC_NOSUPP
,
141 N_("Failed to load API cache module %s", "file"),
143 return KRB5_CC_NOSUPP
;
146 init_func
= (cc_initialize_func
)dlsym(cc_handle
, "cc_initialize");
147 set_target_uid
= (void (KRB5_CALLCONV
*)(uid_t
))
148 dlsym(cc_handle
, "krb5_ipc_client_set_target_uid");
149 clear_target
= (void (KRB5_CALLCONV
*)(void))
150 dlsym(cc_handle
, "krb5_ipc_client_clear_target");
151 HEIMDAL_MUTEX_unlock(&acc_mutex
);
152 if (init_func
== NULL
) {
154 krb5_set_error_message(context
, KRB5_CC_NOSUPP
,
155 N_("Failed to find cc_initialize"
156 "in %s: %s", "file, error"), lib
, dlerror());
158 return KRB5_CC_NOSUPP
;
163 HEIMDAL_MUTEX_unlock(&acc_mutex
);
165 krb5_set_error_message(context
, KRB5_CC_NOSUPP
,
166 N_("no support for shared object", ""));
167 return KRB5_CC_NOSUPP
;
172 _heim_krb5_ipc_client_set_target_uid(uid_t uid
)
175 if (set_target_uid
!= NULL
)
176 (*set_target_uid
)(uid
);
180 _heim_krb5_ipc_client_clear_target(void)
183 if (clear_target
!= NULL
)
187 static krb5_error_code
188 make_cred_from_ccred(krb5_context context
,
189 const cc_credentials_v5_t
*incred
,
195 memset(cred
, 0, sizeof(*cred
));
197 ret
= krb5_parse_name(context
, incred
->client
, &cred
->client
);
201 ret
= krb5_parse_name(context
, incred
->server
, &cred
->server
);
205 cred
->session
.keytype
= incred
->keyblock
.type
;
206 cred
->session
.keyvalue
.length
= incred
->keyblock
.length
;
207 cred
->session
.keyvalue
.data
= malloc(incred
->keyblock
.length
);
208 if (cred
->session
.keyvalue
.data
== NULL
)
210 memcpy(cred
->session
.keyvalue
.data
, incred
->keyblock
.data
,
211 incred
->keyblock
.length
);
213 cred
->times
.authtime
= incred
->authtime
;
214 cred
->times
.starttime
= incred
->starttime
;
215 cred
->times
.endtime
= incred
->endtime
;
216 cred
->times
.renew_till
= incred
->renew_till
;
218 ret
= krb5_data_copy(&cred
->ticket
,
220 incred
->ticket
.length
);
224 ret
= krb5_data_copy(&cred
->second_ticket
,
225 incred
->second_ticket
.data
,
226 incred
->second_ticket
.length
);
230 cred
->authdata
.val
= NULL
;
231 cred
->authdata
.len
= 0;
233 cred
->addresses
.val
= NULL
;
234 cred
->addresses
.len
= 0;
236 for (i
= 0; incred
->authdata
&& incred
->authdata
[i
]; i
++)
240 cred
->authdata
.val
= calloc(i
, sizeof(cred
->authdata
.val
[0]));
241 if (cred
->authdata
.val
== NULL
)
243 cred
->authdata
.len
= i
;
244 for (i
= 0; i
< cred
->authdata
.len
; i
++) {
245 cred
->authdata
.val
[i
].ad_type
= incred
->authdata
[i
]->type
;
246 ret
= krb5_data_copy(&cred
->authdata
.val
[i
].ad_data
,
247 incred
->authdata
[i
]->data
,
248 incred
->authdata
[i
]->length
);
254 for (i
= 0; incred
->addresses
&& incred
->addresses
[i
]; i
++)
258 cred
->addresses
.val
= calloc(i
, sizeof(cred
->addresses
.val
[0]));
259 if (cred
->addresses
.val
== NULL
)
261 cred
->addresses
.len
= i
;
263 for (i
= 0; i
< cred
->addresses
.len
; i
++) {
264 cred
->addresses
.val
[i
].addr_type
= incred
->addresses
[i
]->type
;
265 ret
= krb5_data_copy(&cred
->addresses
.val
[i
].address
,
266 incred
->addresses
[i
]->data
,
267 incred
->addresses
[i
]->length
);
274 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_FORWARDABLE
)
275 cred
->flags
.b
.forwardable
= 1;
276 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_FORWARDED
)
277 cred
->flags
.b
.forwarded
= 1;
278 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_PROXIABLE
)
279 cred
->flags
.b
.proxiable
= 1;
280 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_PROXY
)
281 cred
->flags
.b
.proxy
= 1;
282 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_MAY_POSTDATE
)
283 cred
->flags
.b
.may_postdate
= 1;
284 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_POSTDATED
)
285 cred
->flags
.b
.postdated
= 1;
286 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_INVALID
)
287 cred
->flags
.b
.invalid
= 1;
288 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_RENEWABLE
)
289 cred
->flags
.b
.renewable
= 1;
290 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_INITIAL
)
291 cred
->flags
.b
.initial
= 1;
292 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_PRE_AUTH
)
293 cred
->flags
.b
.pre_authent
= 1;
294 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_HW_AUTH
)
295 cred
->flags
.b
.hw_authent
= 1;
296 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_TRANSIT_POLICY_CHECKED
)
297 cred
->flags
.b
.transited_policy_checked
= 1;
298 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_OK_AS_DELEGATE
)
299 cred
->flags
.b
.ok_as_delegate
= 1;
300 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_ANONYMOUS
)
301 cred
->flags
.b
.anonymous
= 1;
307 krb5_set_error_message(context
, ret
, N_("malloc: out of memory", "malloc"));
310 krb5_free_cred_contents(context
, cred
);
315 free_ccred(cc_credentials_v5_t
*cred
)
319 if (cred
->addresses
) {
320 for (i
= 0; cred
->addresses
[i
] != 0; i
++) {
321 if (cred
->addresses
[i
]->data
)
322 free(cred
->addresses
[i
]->data
);
323 free(cred
->addresses
[i
]);
325 free(cred
->addresses
);
331 memset(cred
, 0, sizeof(*cred
));
334 static krb5_error_code
335 make_ccred_from_cred(krb5_context context
,
336 const krb5_creds
*incred
,
337 cc_credentials_v5_t
*cred
)
342 memset(cred
, 0, sizeof(*cred
));
344 ret
= krb5_unparse_name(context
, incred
->client
, &cred
->client
);
348 ret
= krb5_unparse_name(context
, incred
->server
, &cred
->server
);
352 cred
->keyblock
.type
= incred
->session
.keytype
;
353 cred
->keyblock
.length
= incred
->session
.keyvalue
.length
;
354 cred
->keyblock
.data
= incred
->session
.keyvalue
.data
;
356 cred
->authtime
= incred
->times
.authtime
;
357 cred
->starttime
= incred
->times
.starttime
;
358 cred
->endtime
= incred
->times
.endtime
;
359 cred
->renew_till
= incred
->times
.renew_till
;
361 cred
->ticket
.length
= incred
->ticket
.length
;
362 cred
->ticket
.data
= incred
->ticket
.data
;
364 cred
->second_ticket
.length
= incred
->second_ticket
.length
;
365 cred
->second_ticket
.data
= incred
->second_ticket
.data
;
367 /* XXX this one should also be filled in */
368 cred
->authdata
= NULL
;
370 cred
->addresses
= calloc(incred
->addresses
.len
+ 1,
371 sizeof(cred
->addresses
[0]));
372 if (cred
->addresses
== NULL
) {
378 for (i
= 0; i
< incred
->addresses
.len
; i
++) {
380 addr
= malloc(sizeof(*addr
));
385 addr
->type
= incred
->addresses
.val
[i
].addr_type
;
386 addr
->length
= incred
->addresses
.val
[i
].address
.length
;
387 addr
->data
= malloc(addr
->length
);
388 if (addr
->data
== NULL
) {
393 memcpy(addr
->data
, incred
->addresses
.val
[i
].address
.data
,
395 cred
->addresses
[i
] = addr
;
397 cred
->addresses
[i
] = NULL
;
399 cred
->ticket_flags
= 0;
400 if (incred
->flags
.b
.forwardable
)
401 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_FORWARDABLE
;
402 if (incred
->flags
.b
.forwarded
)
403 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_FORWARDED
;
404 if (incred
->flags
.b
.proxiable
)
405 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_PROXIABLE
;
406 if (incred
->flags
.b
.proxy
)
407 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_PROXY
;
408 if (incred
->flags
.b
.may_postdate
)
409 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_MAY_POSTDATE
;
410 if (incred
->flags
.b
.postdated
)
411 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_POSTDATED
;
412 if (incred
->flags
.b
.invalid
)
413 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_INVALID
;
414 if (incred
->flags
.b
.renewable
)
415 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_RENEWABLE
;
416 if (incred
->flags
.b
.initial
)
417 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_INITIAL
;
418 if (incred
->flags
.b
.pre_authent
)
419 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_PRE_AUTH
;
420 if (incred
->flags
.b
.hw_authent
)
421 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_HW_AUTH
;
422 if (incred
->flags
.b
.transited_policy_checked
)
423 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_TRANSIT_POLICY_CHECKED
;
424 if (incred
->flags
.b
.ok_as_delegate
)
425 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_OK_AS_DELEGATE
;
426 if (incred
->flags
.b
.anonymous
)
427 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_ANONYMOUS
;
434 krb5_clear_error_message(context
);
439 get_cc_name(krb5_acc
*a
)
444 error
= (*a
->ccache
->func
->get_name
)(a
->ccache
, &name
);
448 a
->cache_name
= strdup(name
->data
);
449 (*name
->func
->release
)(name
);
450 if (a
->cache_name
== NULL
)
456 static const char* KRB5_CALLCONV
457 acc_get_name(krb5_context context
,
460 krb5_acc
*a
= ACACHE(id
);
463 if (a
->cache_name
== NULL
) {
465 krb5_principal principal
;
468 ret
= _krb5_get_default_principal_local(context
, &principal
);
472 ret
= krb5_unparse_name(context
, principal
, &name
);
473 krb5_free_principal(context
, principal
);
477 error
= (*a
->context
->func
->create_new_ccache
)(a
->context
,
485 error
= get_cc_name(a
);
490 return a
->cache_name
;
493 static krb5_error_code KRB5_CALLCONV
494 acc_alloc(krb5_context context
, krb5_ccache
*id
)
500 ret
= init_ccapi(context
);
504 ret
= krb5_data_alloc(&(*id
)->data
, sizeof(*a
));
506 krb5_clear_error_message(context
);
512 error
= (*init_func
)(&a
->context
, ccapi_version_3
, NULL
, NULL
);
514 krb5_data_free(&(*id
)->data
);
515 return translate_cc_error(context
, error
);
518 a
->cache_name
= NULL
;
523 static krb5_error_code KRB5_CALLCONV
524 acc_resolve(krb5_context context
, krb5_ccache
*id
, const char *res
)
530 ret
= acc_alloc(context
, id
);
536 error
= (*a
->context
->func
->open_ccache
)(a
->context
, res
, &a
->ccache
);
537 if (error
== ccNoError
) {
539 error
= get_cc_name(a
);
540 if (error
!= ccNoError
) {
541 acc_close(context
, *id
);
543 return translate_cc_error(context
, error
);
546 error
= (*a
->ccache
->func
->get_kdc_time_offset
)(a
->ccache
,
550 context
->kdc_sec_offset
= offset
;
552 } else if (error
== ccErrCCacheNotFound
) {
554 a
->cache_name
= NULL
;
557 return translate_cc_error(context
, error
);
563 static krb5_error_code KRB5_CALLCONV
564 acc_gen_new(krb5_context context
, krb5_ccache
*id
)
569 ret
= acc_alloc(context
, id
);
576 a
->cache_name
= NULL
;
581 static krb5_error_code KRB5_CALLCONV
582 acc_initialize(krb5_context context
,
584 krb5_principal primary_principal
)
586 krb5_acc
*a
= ACACHE(id
);
591 ret
= krb5_unparse_name(context
, primary_principal
, &name
);
595 if (a
->cache_name
== NULL
) {
596 error
= (*a
->context
->func
->create_new_ccache
)(a
->context
,
601 if (error
== ccNoError
)
602 error
= get_cc_name(a
);
604 cc_credentials_iterator_t iter
;
605 cc_credentials_t ccred
;
607 error
= (*a
->ccache
->func
->new_credentials_iterator
)(a
->ccache
, &iter
);
610 return translate_cc_error(context
, error
);
614 error
= (*iter
->func
->next
)(iter
, &ccred
);
617 (*a
->ccache
->func
->remove_credentials
)(a
->ccache
, ccred
);
618 (*ccred
->func
->release
)(ccred
);
620 (*iter
->func
->release
)(iter
);
622 error
= (*a
->ccache
->func
->set_principal
)(a
->ccache
,
627 if (error
== 0 && context
->kdc_sec_offset
)
628 error
= (*a
->ccache
->func
->set_kdc_time_offset
)(a
->ccache
,
630 context
->kdc_sec_offset
);
632 return translate_cc_error(context
, error
);
635 static krb5_error_code KRB5_CALLCONV
636 acc_close(krb5_context context
,
639 krb5_acc
*a
= ACACHE(id
);
642 (*a
->ccache
->func
->release
)(a
->ccache
);
647 a
->cache_name
= NULL
;
650 (*a
->context
->func
->release
)(a
->context
);
653 krb5_data_free(&id
->data
);
657 static krb5_error_code KRB5_CALLCONV
658 acc_destroy(krb5_context context
,
661 krb5_acc
*a
= ACACHE(id
);
665 error
= (*a
->ccache
->func
->destroy
)(a
->ccache
);
669 error
= (a
->context
->func
->release
)(a
->context
);
672 return translate_cc_error(context
, error
);
675 static krb5_error_code KRB5_CALLCONV
676 acc_store_cred(krb5_context context
,
680 krb5_acc
*a
= ACACHE(id
);
681 cc_credentials_union cred
;
682 cc_credentials_v5_t v5cred
;
686 if (a
->ccache
== NULL
) {
687 krb5_set_error_message(context
, KRB5_CC_NOTFOUND
,
688 N_("No API credential found", ""));
689 return KRB5_CC_NOTFOUND
;
692 cred
.version
= cc_credentials_v5
;
693 cred
.credentials
.credentials_v5
= &v5cred
;
695 ret
= make_ccred_from_cred(context
,
701 error
= (*a
->ccache
->func
->store_credentials
)(a
->ccache
, &cred
);
703 ret
= translate_cc_error(context
, error
);
710 static krb5_error_code KRB5_CALLCONV
711 acc_get_principal(krb5_context context
,
713 krb5_principal
*principal
)
715 krb5_acc
*a
= ACACHE(id
);
720 if (a
->ccache
== NULL
) {
721 krb5_set_error_message(context
, KRB5_CC_NOTFOUND
,
722 N_("No API credential found", ""));
723 return KRB5_CC_NOTFOUND
;
726 error
= (*a
->ccache
->func
->get_principal
)(a
->ccache
,
730 return translate_cc_error(context
, error
);
732 ret
= krb5_parse_name(context
, name
->data
, principal
);
734 (*name
->func
->release
)(name
);
738 static krb5_error_code KRB5_CALLCONV
739 acc_get_first (krb5_context context
,
741 krb5_cc_cursor
*cursor
)
743 cc_credentials_iterator_t iter
;
744 krb5_acc
*a
= ACACHE(id
);
747 if (a
->ccache
== NULL
) {
748 krb5_set_error_message(context
, KRB5_CC_NOTFOUND
,
749 N_("No API credential found", ""));
750 return KRB5_CC_NOTFOUND
;
753 error
= (*a
->ccache
->func
->new_credentials_iterator
)(a
->ccache
, &iter
);
755 krb5_clear_error_message(context
);
763 static krb5_error_code KRB5_CALLCONV
764 acc_get_next (krb5_context context
,
766 krb5_cc_cursor
*cursor
,
769 cc_credentials_iterator_t iter
= *cursor
;
770 cc_credentials_t cred
;
775 error
= (*iter
->func
->next
)(iter
, &cred
);
777 return translate_cc_error(context
, error
);
778 if (cred
->data
->version
== cc_credentials_v5
)
780 (*cred
->func
->release
)(cred
);
783 ret
= make_cred_from_ccred(context
,
784 cred
->data
->credentials
.credentials_v5
,
786 (*cred
->func
->release
)(cred
);
790 static krb5_error_code KRB5_CALLCONV
791 acc_end_get (krb5_context context
,
793 krb5_cc_cursor
*cursor
)
795 cc_credentials_iterator_t iter
= *cursor
;
796 (*iter
->func
->release
)(iter
);
800 static krb5_error_code KRB5_CALLCONV
801 acc_remove_cred(krb5_context context
,
806 cc_credentials_iterator_t iter
;
807 krb5_acc
*a
= ACACHE(id
);
808 cc_credentials_t ccred
;
811 char *client
, *server
;
813 if (a
->ccache
== NULL
) {
814 krb5_set_error_message(context
, KRB5_CC_NOTFOUND
,
815 N_("No API credential found", ""));
816 return KRB5_CC_NOTFOUND
;
820 ret
= krb5_unparse_name(context
, cred
->client
, &client
);
826 ret
= krb5_unparse_name(context
, cred
->server
, &server
);
832 error
= (*a
->ccache
->func
->new_credentials_iterator
)(a
->ccache
, &iter
);
836 return translate_cc_error(context
, error
);
839 ret
= KRB5_CC_NOTFOUND
;
841 cc_credentials_v5_t
*v5cred
;
843 error
= (*iter
->func
->next
)(iter
, &ccred
);
847 if (ccred
->data
->version
!= cc_credentials_v5
)
850 v5cred
= ccred
->data
->credentials
.credentials_v5
;
852 if (client
&& strcmp(v5cred
->client
, client
) != 0)
855 if (strcmp(v5cred
->server
, server
) != 0)
858 (*a
->ccache
->func
->remove_credentials
)(a
->ccache
, ccred
);
861 (*ccred
->func
->release
)(ccred
);
864 (*iter
->func
->release
)(iter
);
867 krb5_set_error_message(context
, ret
,
868 N_("Can't find credential %s in cache",
869 "principal"), server
);
876 static krb5_error_code KRB5_CALLCONV
877 acc_set_flags(krb5_context context
,
884 static int KRB5_CALLCONV
885 acc_get_version(krb5_context context
,
892 cc_context_t context
;
893 cc_ccache_iterator_t iter
;
896 static krb5_error_code KRB5_CALLCONV
897 acc_get_cache_first(krb5_context context
, krb5_cc_cursor
*cursor
)
899 struct cache_iter
*iter
;
903 ret
= init_ccapi(context
);
907 iter
= calloc(1, sizeof(*iter
));
909 krb5_set_error_message(context
, ENOMEM
, "malloc: out of memory");
913 error
= (*init_func
)(&iter
->context
, ccapi_version_3
, NULL
, NULL
);
916 return translate_cc_error(context
, error
);
919 error
= (*iter
->context
->func
->new_ccache_iterator
)(iter
->context
,
923 krb5_clear_error_message(context
);
930 static krb5_error_code KRB5_CALLCONV
931 acc_get_cache_next(krb5_context context
, krb5_cc_cursor cursor
, krb5_ccache
*id
)
933 struct cache_iter
*iter
= cursor
;
939 error
= (*iter
->iter
->func
->next
)(iter
->iter
, &cache
);
941 return translate_cc_error(context
, error
);
943 ret
= _krb5_cc_allocate(context
, &krb5_acc_ops
, id
);
945 (*cache
->func
->release
)(cache
);
949 ret
= acc_alloc(context
, id
);
951 (*cache
->func
->release
)(cache
);
959 error
= get_cc_name(a
);
961 acc_close(context
, *id
);
963 return translate_cc_error(context
, error
);
968 static krb5_error_code KRB5_CALLCONV
969 acc_end_cache_get(krb5_context context
, krb5_cc_cursor cursor
)
971 struct cache_iter
*iter
= cursor
;
973 (*iter
->iter
->func
->release
)(iter
->iter
);
975 (*iter
->context
->func
->release
)(iter
->context
);
976 iter
->context
= NULL
;
981 static krb5_error_code KRB5_CALLCONV
982 acc_move(krb5_context context
, krb5_ccache from
, krb5_ccache to
)
984 krb5_acc
*afrom
= ACACHE(from
);
985 krb5_acc
*ato
= ACACHE(to
);
988 if (ato
->ccache
== NULL
) {
991 error
= (*afrom
->ccache
->func
->get_principal
)(afrom
->ccache
,
995 return translate_cc_error(context
, error
);
997 error
= (*ato
->context
->func
->create_new_ccache
)(ato
->context
,
1001 (*name
->func
->release
)(name
);
1003 return translate_cc_error(context
, error
);
1006 error
= (*ato
->ccache
->func
->move
)(afrom
->ccache
, ato
->ccache
);
1008 acc_destroy(context
, from
);
1010 return translate_cc_error(context
, error
);
1013 static krb5_error_code KRB5_CALLCONV
1014 acc_get_default_name(krb5_context context
, char **str
)
1016 krb5_error_code ret
;
1021 ret
= init_ccapi(context
);
1025 error
= (*init_func
)(&cc
, ccapi_version_3
, NULL
, NULL
);
1027 return translate_cc_error(context
, error
);
1029 error
= (*cc
->func
->get_default_ccache_name
)(cc
, &name
);
1031 (*cc
->func
->release
)(cc
);
1032 return translate_cc_error(context
, error
);
1035 error
= asprintf(str
, "API:%s", name
->data
);
1036 (*name
->func
->release
)(name
);
1037 (*cc
->func
->release
)(cc
);
1039 if (error
< 0 || *str
== NULL
) {
1040 krb5_set_error_message(context
, ENOMEM
, N_("malloc: out of memory", ""));
1046 static krb5_error_code KRB5_CALLCONV
1047 acc_set_default(krb5_context context
, krb5_ccache id
)
1049 krb5_acc
*a
= ACACHE(id
);
1052 if (a
->ccache
== NULL
) {
1053 krb5_set_error_message(context
, KRB5_CC_NOTFOUND
,
1054 N_("No API credential found", ""));
1055 return KRB5_CC_NOTFOUND
;
1058 error
= (*a
->ccache
->func
->set_default
)(a
->ccache
);
1060 return translate_cc_error(context
, error
);
1065 static krb5_error_code KRB5_CALLCONV
1066 acc_lastchange(krb5_context context
, krb5_ccache id
, krb5_timestamp
*mtime
)
1068 krb5_acc
*a
= ACACHE(id
);
1072 if (a
->ccache
== NULL
) {
1073 krb5_set_error_message(context
, KRB5_CC_NOTFOUND
,
1074 N_("No API credential found", ""));
1075 return KRB5_CC_NOTFOUND
;
1078 error
= (*a
->ccache
->func
->get_change_time
)(a
->ccache
, &t
);
1080 return translate_cc_error(context
, error
);
1088 * Variable containing the API based credential cache implemention.
1090 * @ingroup krb5_ccache
1093 KRB5_LIB_VARIABLE
const krb5_cc_ops krb5_acc_ops
= {
1094 KRB5_CC_OPS_VERSION
,
1103 NULL
, /* acc_retrieve */
1111 acc_get_cache_first
,
1115 acc_get_default_name
,