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 (*set_target_uid
)(uid
);
179 _heim_krb5_ipc_client_clear_target(void)
185 static krb5_error_code
186 make_cred_from_ccred(krb5_context context
,
187 const cc_credentials_v5_t
*incred
,
193 memset(cred
, 0, sizeof(*cred
));
195 ret
= krb5_parse_name(context
, incred
->client
, &cred
->client
);
199 ret
= krb5_parse_name(context
, incred
->server
, &cred
->server
);
203 cred
->session
.keytype
= incred
->keyblock
.type
;
204 cred
->session
.keyvalue
.length
= incred
->keyblock
.length
;
205 cred
->session
.keyvalue
.data
= malloc(incred
->keyblock
.length
);
206 if (cred
->session
.keyvalue
.data
== NULL
)
208 memcpy(cred
->session
.keyvalue
.data
, incred
->keyblock
.data
,
209 incred
->keyblock
.length
);
211 cred
->times
.authtime
= incred
->authtime
;
212 cred
->times
.starttime
= incred
->starttime
;
213 cred
->times
.endtime
= incred
->endtime
;
214 cred
->times
.renew_till
= incred
->renew_till
;
216 ret
= krb5_data_copy(&cred
->ticket
,
218 incred
->ticket
.length
);
222 ret
= krb5_data_copy(&cred
->second_ticket
,
223 incred
->second_ticket
.data
,
224 incred
->second_ticket
.length
);
228 cred
->authdata
.val
= NULL
;
229 cred
->authdata
.len
= 0;
231 cred
->addresses
.val
= NULL
;
232 cred
->addresses
.len
= 0;
234 for (i
= 0; incred
->authdata
&& incred
->authdata
[i
]; i
++)
238 cred
->authdata
.val
= calloc(i
, sizeof(cred
->authdata
.val
[0]));
239 if (cred
->authdata
.val
== NULL
)
241 cred
->authdata
.len
= i
;
242 for (i
= 0; i
< cred
->authdata
.len
; i
++) {
243 cred
->authdata
.val
[i
].ad_type
= incred
->authdata
[i
]->type
;
244 ret
= krb5_data_copy(&cred
->authdata
.val
[i
].ad_data
,
245 incred
->authdata
[i
]->data
,
246 incred
->authdata
[i
]->length
);
252 for (i
= 0; incred
->addresses
&& incred
->addresses
[i
]; i
++)
256 cred
->addresses
.val
= calloc(i
, sizeof(cred
->addresses
.val
[0]));
257 if (cred
->addresses
.val
== NULL
)
259 cred
->addresses
.len
= i
;
261 for (i
= 0; i
< cred
->addresses
.len
; i
++) {
262 cred
->addresses
.val
[i
].addr_type
= incred
->addresses
[i
]->type
;
263 ret
= krb5_data_copy(&cred
->addresses
.val
[i
].address
,
264 incred
->addresses
[i
]->data
,
265 incred
->addresses
[i
]->length
);
272 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_FORWARDABLE
)
273 cred
->flags
.b
.forwardable
= 1;
274 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_FORWARDED
)
275 cred
->flags
.b
.forwarded
= 1;
276 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_PROXIABLE
)
277 cred
->flags
.b
.proxiable
= 1;
278 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_PROXY
)
279 cred
->flags
.b
.proxy
= 1;
280 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_MAY_POSTDATE
)
281 cred
->flags
.b
.may_postdate
= 1;
282 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_POSTDATED
)
283 cred
->flags
.b
.postdated
= 1;
284 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_INVALID
)
285 cred
->flags
.b
.invalid
= 1;
286 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_RENEWABLE
)
287 cred
->flags
.b
.renewable
= 1;
288 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_INITIAL
)
289 cred
->flags
.b
.initial
= 1;
290 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_PRE_AUTH
)
291 cred
->flags
.b
.pre_authent
= 1;
292 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_HW_AUTH
)
293 cred
->flags
.b
.hw_authent
= 1;
294 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_TRANSIT_POLICY_CHECKED
)
295 cred
->flags
.b
.transited_policy_checked
= 1;
296 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_OK_AS_DELEGATE
)
297 cred
->flags
.b
.ok_as_delegate
= 1;
298 if (incred
->ticket_flags
& KRB5_CCAPI_TKT_FLG_ANONYMOUS
)
299 cred
->flags
.b
.anonymous
= 1;
305 krb5_set_error_message(context
, ret
, N_("malloc: out of memory", "malloc"));
308 krb5_free_cred_contents(context
, cred
);
313 free_ccred(cc_credentials_v5_t
*cred
)
317 if (cred
->addresses
) {
318 for (i
= 0; cred
->addresses
[i
] != 0; i
++) {
319 if (cred
->addresses
[i
]->data
)
320 free(cred
->addresses
[i
]->data
);
321 free(cred
->addresses
[i
]);
323 free(cred
->addresses
);
329 memset(cred
, 0, sizeof(*cred
));
332 static krb5_error_code
333 make_ccred_from_cred(krb5_context context
,
334 const krb5_creds
*incred
,
335 cc_credentials_v5_t
*cred
)
340 memset(cred
, 0, sizeof(*cred
));
342 ret
= krb5_unparse_name(context
, incred
->client
, &cred
->client
);
346 ret
= krb5_unparse_name(context
, incred
->server
, &cred
->server
);
350 cred
->keyblock
.type
= incred
->session
.keytype
;
351 cred
->keyblock
.length
= incred
->session
.keyvalue
.length
;
352 cred
->keyblock
.data
= incred
->session
.keyvalue
.data
;
354 cred
->authtime
= incred
->times
.authtime
;
355 cred
->starttime
= incred
->times
.starttime
;
356 cred
->endtime
= incred
->times
.endtime
;
357 cred
->renew_till
= incred
->times
.renew_till
;
359 cred
->ticket
.length
= incred
->ticket
.length
;
360 cred
->ticket
.data
= incred
->ticket
.data
;
362 cred
->second_ticket
.length
= incred
->second_ticket
.length
;
363 cred
->second_ticket
.data
= incred
->second_ticket
.data
;
365 /* XXX this one should also be filled in */
366 cred
->authdata
= NULL
;
368 cred
->addresses
= calloc(incred
->addresses
.len
+ 1,
369 sizeof(cred
->addresses
[0]));
370 if (cred
->addresses
== NULL
) {
376 for (i
= 0; i
< incred
->addresses
.len
; i
++) {
378 addr
= malloc(sizeof(*addr
));
383 addr
->type
= incred
->addresses
.val
[i
].addr_type
;
384 addr
->length
= incred
->addresses
.val
[i
].address
.length
;
385 addr
->data
= malloc(addr
->length
);
386 if (addr
->data
== NULL
) {
391 memcpy(addr
->data
, incred
->addresses
.val
[i
].address
.data
,
393 cred
->addresses
[i
] = addr
;
395 cred
->addresses
[i
] = NULL
;
397 cred
->ticket_flags
= 0;
398 if (incred
->flags
.b
.forwardable
)
399 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_FORWARDABLE
;
400 if (incred
->flags
.b
.forwarded
)
401 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_FORWARDED
;
402 if (incred
->flags
.b
.proxiable
)
403 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_PROXIABLE
;
404 if (incred
->flags
.b
.proxy
)
405 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_PROXY
;
406 if (incred
->flags
.b
.may_postdate
)
407 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_MAY_POSTDATE
;
408 if (incred
->flags
.b
.postdated
)
409 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_POSTDATED
;
410 if (incred
->flags
.b
.invalid
)
411 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_INVALID
;
412 if (incred
->flags
.b
.renewable
)
413 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_RENEWABLE
;
414 if (incred
->flags
.b
.initial
)
415 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_INITIAL
;
416 if (incred
->flags
.b
.pre_authent
)
417 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_PRE_AUTH
;
418 if (incred
->flags
.b
.hw_authent
)
419 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_HW_AUTH
;
420 if (incred
->flags
.b
.transited_policy_checked
)
421 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_TRANSIT_POLICY_CHECKED
;
422 if (incred
->flags
.b
.ok_as_delegate
)
423 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_OK_AS_DELEGATE
;
424 if (incred
->flags
.b
.anonymous
)
425 cred
->ticket_flags
|= KRB5_CCAPI_TKT_FLG_ANONYMOUS
;
432 krb5_clear_error_message(context
);
437 get_cc_name(krb5_acc
*a
)
442 error
= (*a
->ccache
->func
->get_name
)(a
->ccache
, &name
);
446 a
->cache_name
= strdup(name
->data
);
447 (*name
->func
->release
)(name
);
448 if (a
->cache_name
== NULL
)
454 static const char* KRB5_CALLCONV
455 acc_get_name(krb5_context context
,
458 krb5_acc
*a
= ACACHE(id
);
461 if (a
->cache_name
== NULL
) {
463 krb5_principal principal
;
466 ret
= _krb5_get_default_principal_local(context
, &principal
);
470 ret
= krb5_unparse_name(context
, principal
, &name
);
471 krb5_free_principal(context
, principal
);
475 error
= (*a
->context
->func
->create_new_ccache
)(a
->context
,
483 error
= get_cc_name(a
);
488 return a
->cache_name
;
491 static krb5_error_code KRB5_CALLCONV
492 acc_alloc(krb5_context context
, krb5_ccache
*id
)
498 ret
= init_ccapi(context
);
502 ret
= krb5_data_alloc(&(*id
)->data
, sizeof(*a
));
504 krb5_clear_error_message(context
);
510 error
= (*init_func
)(&a
->context
, ccapi_version_3
, NULL
, NULL
);
512 krb5_data_free(&(*id
)->data
);
513 return translate_cc_error(context
, error
);
516 a
->cache_name
= NULL
;
521 static krb5_error_code KRB5_CALLCONV
522 acc_resolve(krb5_context context
, krb5_ccache
*id
, const char *res
)
528 ret
= acc_alloc(context
, id
);
534 error
= (*a
->context
->func
->open_ccache
)(a
->context
, res
, &a
->ccache
);
535 if (error
== ccNoError
) {
537 error
= get_cc_name(a
);
538 if (error
!= ccNoError
) {
539 acc_close(context
, *id
);
541 return translate_cc_error(context
, error
);
544 error
= (*a
->ccache
->func
->get_kdc_time_offset
)(a
->ccache
,
548 context
->kdc_sec_offset
= offset
;
550 } else if (error
== ccErrCCacheNotFound
) {
552 a
->cache_name
= NULL
;
555 return translate_cc_error(context
, error
);
561 static krb5_error_code KRB5_CALLCONV
562 acc_gen_new(krb5_context context
, krb5_ccache
*id
)
567 ret
= acc_alloc(context
, id
);
574 a
->cache_name
= NULL
;
579 static krb5_error_code KRB5_CALLCONV
580 acc_initialize(krb5_context context
,
582 krb5_principal primary_principal
)
584 krb5_acc
*a
= ACACHE(id
);
589 ret
= krb5_unparse_name(context
, primary_principal
, &name
);
593 if (a
->cache_name
== NULL
) {
594 error
= (*a
->context
->func
->create_new_ccache
)(a
->context
,
599 if (error
== ccNoError
)
600 error
= get_cc_name(a
);
602 cc_credentials_iterator_t iter
;
603 cc_credentials_t ccred
;
605 error
= (*a
->ccache
->func
->new_credentials_iterator
)(a
->ccache
, &iter
);
608 return translate_cc_error(context
, error
);
612 error
= (*iter
->func
->next
)(iter
, &ccred
);
615 (*a
->ccache
->func
->remove_credentials
)(a
->ccache
, ccred
);
616 (*ccred
->func
->release
)(ccred
);
618 (*iter
->func
->release
)(iter
);
620 error
= (*a
->ccache
->func
->set_principal
)(a
->ccache
,
625 if (error
== 0 && context
->kdc_sec_offset
)
626 error
= (*a
->ccache
->func
->set_kdc_time_offset
)(a
->ccache
,
628 context
->kdc_sec_offset
);
630 return translate_cc_error(context
, error
);
633 static krb5_error_code KRB5_CALLCONV
634 acc_close(krb5_context context
,
637 krb5_acc
*a
= ACACHE(id
);
640 (*a
->ccache
->func
->release
)(a
->ccache
);
645 a
->cache_name
= NULL
;
648 (*a
->context
->func
->release
)(a
->context
);
651 krb5_data_free(&id
->data
);
655 static krb5_error_code KRB5_CALLCONV
656 acc_destroy(krb5_context context
,
659 krb5_acc
*a
= ACACHE(id
);
663 error
= (*a
->ccache
->func
->destroy
)(a
->ccache
);
667 error
= (a
->context
->func
->release
)(a
->context
);
670 return translate_cc_error(context
, error
);
673 static krb5_error_code KRB5_CALLCONV
674 acc_store_cred(krb5_context context
,
678 krb5_acc
*a
= ACACHE(id
);
679 cc_credentials_union cred
;
680 cc_credentials_v5_t v5cred
;
684 if (a
->ccache
== NULL
) {
685 krb5_set_error_message(context
, KRB5_CC_NOTFOUND
,
686 N_("No API credential found", ""));
687 return KRB5_CC_NOTFOUND
;
690 cred
.version
= cc_credentials_v5
;
691 cred
.credentials
.credentials_v5
= &v5cred
;
693 ret
= make_ccred_from_cred(context
,
699 error
= (*a
->ccache
->func
->store_credentials
)(a
->ccache
, &cred
);
701 ret
= translate_cc_error(context
, error
);
708 static krb5_error_code KRB5_CALLCONV
709 acc_get_principal(krb5_context context
,
711 krb5_principal
*principal
)
713 krb5_acc
*a
= ACACHE(id
);
718 if (a
->ccache
== NULL
) {
719 krb5_set_error_message(context
, KRB5_CC_NOTFOUND
,
720 N_("No API credential found", ""));
721 return KRB5_CC_NOTFOUND
;
724 error
= (*a
->ccache
->func
->get_principal
)(a
->ccache
,
728 return translate_cc_error(context
, error
);
730 ret
= krb5_parse_name(context
, name
->data
, principal
);
732 (*name
->func
->release
)(name
);
736 static krb5_error_code KRB5_CALLCONV
737 acc_get_first (krb5_context context
,
739 krb5_cc_cursor
*cursor
)
741 cc_credentials_iterator_t iter
;
742 krb5_acc
*a
= ACACHE(id
);
745 if (a
->ccache
== NULL
) {
746 krb5_set_error_message(context
, KRB5_CC_NOTFOUND
,
747 N_("No API credential found", ""));
748 return KRB5_CC_NOTFOUND
;
751 error
= (*a
->ccache
->func
->new_credentials_iterator
)(a
->ccache
, &iter
);
753 krb5_clear_error_message(context
);
761 static krb5_error_code KRB5_CALLCONV
762 acc_get_next (krb5_context context
,
764 krb5_cc_cursor
*cursor
,
767 cc_credentials_iterator_t iter
= *cursor
;
768 cc_credentials_t cred
;
773 error
= (*iter
->func
->next
)(iter
, &cred
);
775 return translate_cc_error(context
, error
);
776 if (cred
->data
->version
== cc_credentials_v5
)
778 (*cred
->func
->release
)(cred
);
781 ret
= make_cred_from_ccred(context
,
782 cred
->data
->credentials
.credentials_v5
,
784 (*cred
->func
->release
)(cred
);
788 static krb5_error_code KRB5_CALLCONV
789 acc_end_get (krb5_context context
,
791 krb5_cc_cursor
*cursor
)
793 cc_credentials_iterator_t iter
= *cursor
;
794 (*iter
->func
->release
)(iter
);
798 static krb5_error_code KRB5_CALLCONV
799 acc_remove_cred(krb5_context context
,
804 cc_credentials_iterator_t iter
;
805 krb5_acc
*a
= ACACHE(id
);
806 cc_credentials_t ccred
;
809 char *client
, *server
;
811 if (a
->ccache
== NULL
) {
812 krb5_set_error_message(context
, KRB5_CC_NOTFOUND
,
813 N_("No API credential found", ""));
814 return KRB5_CC_NOTFOUND
;
818 ret
= krb5_unparse_name(context
, cred
->client
, &client
);
824 ret
= krb5_unparse_name(context
, cred
->server
, &server
);
830 error
= (*a
->ccache
->func
->new_credentials_iterator
)(a
->ccache
, &iter
);
834 return translate_cc_error(context
, error
);
837 ret
= KRB5_CC_NOTFOUND
;
839 cc_credentials_v5_t
*v5cred
;
841 error
= (*iter
->func
->next
)(iter
, &ccred
);
845 if (ccred
->data
->version
!= cc_credentials_v5
)
848 v5cred
= ccred
->data
->credentials
.credentials_v5
;
850 if (client
&& strcmp(v5cred
->client
, client
) != 0)
853 if (strcmp(v5cred
->server
, server
) != 0)
856 (*a
->ccache
->func
->remove_credentials
)(a
->ccache
, ccred
);
859 (*ccred
->func
->release
)(ccred
);
862 (*iter
->func
->release
)(iter
);
865 krb5_set_error_message(context
, ret
,
866 N_("Can't find credential %s in cache",
867 "principal"), server
);
874 static krb5_error_code KRB5_CALLCONV
875 acc_set_flags(krb5_context context
,
882 static int KRB5_CALLCONV
883 acc_get_version(krb5_context context
,
890 cc_context_t context
;
891 cc_ccache_iterator_t iter
;
894 static krb5_error_code KRB5_CALLCONV
895 acc_get_cache_first(krb5_context context
, krb5_cc_cursor
*cursor
)
897 struct cache_iter
*iter
;
901 ret
= init_ccapi(context
);
905 iter
= calloc(1, sizeof(*iter
));
907 krb5_set_error_message(context
, ENOMEM
, "malloc: out of memory");
911 error
= (*init_func
)(&iter
->context
, ccapi_version_3
, NULL
, NULL
);
914 return translate_cc_error(context
, error
);
917 error
= (*iter
->context
->func
->new_ccache_iterator
)(iter
->context
,
921 krb5_clear_error_message(context
);
928 static krb5_error_code KRB5_CALLCONV
929 acc_get_cache_next(krb5_context context
, krb5_cc_cursor cursor
, krb5_ccache
*id
)
931 struct cache_iter
*iter
= cursor
;
937 error
= (*iter
->iter
->func
->next
)(iter
->iter
, &cache
);
939 return translate_cc_error(context
, error
);
941 ret
= _krb5_cc_allocate(context
, &krb5_acc_ops
, id
);
943 (*cache
->func
->release
)(cache
);
947 ret
= acc_alloc(context
, id
);
949 (*cache
->func
->release
)(cache
);
957 error
= get_cc_name(a
);
959 acc_close(context
, *id
);
961 return translate_cc_error(context
, error
);
966 static krb5_error_code KRB5_CALLCONV
967 acc_end_cache_get(krb5_context context
, krb5_cc_cursor cursor
)
969 struct cache_iter
*iter
= cursor
;
971 (*iter
->iter
->func
->release
)(iter
->iter
);
973 (*iter
->context
->func
->release
)(iter
->context
);
974 iter
->context
= NULL
;
979 static krb5_error_code KRB5_CALLCONV
980 acc_move(krb5_context context
, krb5_ccache from
, krb5_ccache to
)
982 krb5_acc
*afrom
= ACACHE(from
);
983 krb5_acc
*ato
= ACACHE(to
);
986 if (ato
->ccache
== NULL
) {
989 error
= (*afrom
->ccache
->func
->get_principal
)(afrom
->ccache
,
993 return translate_cc_error(context
, error
);
995 error
= (*ato
->context
->func
->create_new_ccache
)(ato
->context
,
999 (*name
->func
->release
)(name
);
1001 return translate_cc_error(context
, error
);
1004 error
= (*ato
->ccache
->func
->move
)(afrom
->ccache
, ato
->ccache
);
1006 acc_destroy(context
, from
);
1008 return translate_cc_error(context
, error
);
1011 static krb5_error_code KRB5_CALLCONV
1012 acc_get_default_name(krb5_context context
, char **str
)
1014 krb5_error_code ret
;
1019 ret
= init_ccapi(context
);
1023 error
= (*init_func
)(&cc
, ccapi_version_3
, NULL
, NULL
);
1025 return translate_cc_error(context
, error
);
1027 error
= (*cc
->func
->get_default_ccache_name
)(cc
, &name
);
1029 (*cc
->func
->release
)(cc
);
1030 return translate_cc_error(context
, error
);
1033 error
= asprintf(str
, "API:%s", name
->data
);
1034 (*name
->func
->release
)(name
);
1035 (*cc
->func
->release
)(cc
);
1037 if (error
< 0 || *str
== NULL
) {
1038 krb5_set_error_message(context
, ENOMEM
, N_("malloc: out of memory", ""));
1044 static krb5_error_code KRB5_CALLCONV
1045 acc_set_default(krb5_context context
, krb5_ccache id
)
1047 krb5_acc
*a
= ACACHE(id
);
1050 if (a
->ccache
== NULL
) {
1051 krb5_set_error_message(context
, KRB5_CC_NOTFOUND
,
1052 N_("No API credential found", ""));
1053 return KRB5_CC_NOTFOUND
;
1056 error
= (*a
->ccache
->func
->set_default
)(a
->ccache
);
1058 return translate_cc_error(context
, error
);
1063 static krb5_error_code KRB5_CALLCONV
1064 acc_lastchange(krb5_context context
, krb5_ccache id
, krb5_timestamp
*mtime
)
1066 krb5_acc
*a
= ACACHE(id
);
1070 if (a
->ccache
== NULL
) {
1071 krb5_set_error_message(context
, KRB5_CC_NOTFOUND
,
1072 N_("No API credential found", ""));
1073 return KRB5_CC_NOTFOUND
;
1076 error
= (*a
->ccache
->func
->get_change_time
)(a
->ccache
, &t
);
1078 return translate_cc_error(context
, error
);
1086 * Variable containing the API based credential cache implemention.
1088 * @ingroup krb5_ccache
1091 KRB5_LIB_VARIABLE
const krb5_cc_ops krb5_acc_ops
= {
1092 KRB5_CC_OPS_VERSION
,
1101 NULL
, /* acc_retrieve */
1109 acc_get_cache_first
,
1113 acc_get_default_name
,