1 /* $NetBSD: fcache.c,v 1.1.1.2 2014/04/24 12:45:49 pettai Exp $ */
4 * Copyright (c) 1997 - 2008 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
8 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the Institute nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include "krb5_locl.h"
40 typedef struct krb5_fcache
{
50 #define KRB5_FCC_FVNO_1 1
51 #define KRB5_FCC_FVNO_2 2
52 #define KRB5_FCC_FVNO_3 3
53 #define KRB5_FCC_FVNO_4 4
55 #define FCC_TAG_DELTATIME 1
57 #define FCACHE(X) ((krb5_fcache*)(X)->data.data)
59 #define FILENAME(X) (FCACHE(X)->filename)
61 #define FCC_CURSOR(C) ((struct fcc_cursor*)(C))
63 static const char* KRB5_CALLCONV
64 fcc_get_name(krb5_context context
,
67 if (FCACHE(id
) == NULL
)
74 _krb5_xlock(krb5_context context
, int fd
, krb5_boolean exclusive
,
83 l
.l_type
= exclusive
? F_WRLCK
: F_RDLCK
;
84 l
.l_whence
= SEEK_SET
;
85 ret
= fcntl(fd
, F_SETLKW
, &l
);
87 ret
= flock(fd
, exclusive
? LOCK_EX
: LOCK_SH
);
91 if(ret
== EACCES
) /* fcntl can return EACCES instead of EAGAIN */
97 case EINVAL
: /* filesystem doesn't support locking, let the user have it */
101 krb5_set_error_message(context
, ret
,
102 N_("timed out locking cache file %s", "file"),
107 rk_strerror_r(ret
, buf
, sizeof(buf
));
108 krb5_set_error_message(context
, ret
,
109 N_("error locking cache file %s: %s",
110 "file, error"), filename
, buf
);
118 _krb5_xunlock(krb5_context context
, int fd
)
126 l
.l_whence
= SEEK_SET
;
127 ret
= fcntl(fd
, F_SETLKW
, &l
);
129 ret
= flock(fd
, LOCK_UN
);
136 case EINVAL
: /* filesystem doesn't support locking, let the user have it */
141 rk_strerror_r(ret
, buf
, sizeof(buf
));
142 krb5_set_error_message(context
, ret
,
143 N_("Failed to unlock file: %s", ""), buf
);
150 static krb5_error_code
151 write_storage(krb5_context context
, krb5_storage
*sp
, int fd
)
157 ret
= krb5_storage_to_data(sp
, &data
);
159 krb5_set_error_message(context
, ret
, N_("malloc: out of memory", ""));
162 sret
= write(fd
, data
.data
, data
.length
);
163 ret
= (sret
!= (ssize_t
)data
.length
);
164 krb5_data_free(&data
);
167 krb5_set_error_message(context
, ret
,
168 N_("Failed to write FILE credential data", ""));
175 static krb5_error_code KRB5_CALLCONV
176 fcc_lock(krb5_context context
, krb5_ccache id
,
177 int fd
, krb5_boolean exclusive
)
179 return _krb5_xlock(context
, fd
, exclusive
, fcc_get_name(context
, id
));
182 static krb5_error_code KRB5_CALLCONV
183 fcc_unlock(krb5_context context
, int fd
)
185 return _krb5_xunlock(context
, fd
);
188 static krb5_error_code KRB5_CALLCONV
189 fcc_resolve(krb5_context context
, krb5_ccache
*id
, const char *res
)
192 f
= malloc(sizeof(*f
));
194 krb5_set_error_message(context
, KRB5_CC_NOMEM
,
195 N_("malloc: out of memory", ""));
196 return KRB5_CC_NOMEM
;
198 f
->filename
= strdup(res
);
199 if(f
->filename
== NULL
){
201 krb5_set_error_message(context
, KRB5_CC_NOMEM
,
202 N_("malloc: out of memory", ""));
203 return KRB5_CC_NOMEM
;
206 (*id
)->data
.data
= f
;
207 (*id
)->data
.length
= sizeof(*f
);
212 * Try to scrub the contents of `filename' safely.
221 pos
= lseek(fd
, 0, SEEK_END
);
224 if (lseek(fd
, 0, SEEK_SET
) < 0)
226 memset(buf
, 0, sizeof(buf
));
228 ssize_t tmp
= write(fd
, buf
, min((off_t
)sizeof(buf
), pos
));
243 * Erase `filename' if it exists, trying to remove the contents if
244 * it's `safe'. We always try to remove the file, it it exists. It's
245 * only overwritten if it's a regular file (not a symlink and not a
250 _krb5_erase_file(krb5_context context
, const char *filename
)
253 struct stat sb1
, sb2
;
256 ret
= lstat (filename
, &sb1
);
260 fd
= open(filename
, O_RDWR
| O_BINARY
);
268 ret
= _krb5_xlock(context
, fd
, 1, filename
);
273 if (unlink(filename
) < 0) {
274 _krb5_xunlock(context
, fd
);
278 ret
= fstat (fd
, &sb2
);
280 _krb5_xunlock(context
, fd
);
285 /* check if someone was playing with symlinks */
287 if (sb1
.st_dev
!= sb2
.st_dev
|| sb1
.st_ino
!= sb2
.st_ino
) {
288 _krb5_xunlock(context
, fd
);
293 /* there are still hard links to this file */
295 if (sb2
.st_nlink
!= 0) {
296 _krb5_xunlock(context
, fd
);
301 ret
= scrub_file (fd
);
303 _krb5_xunlock(context
, fd
);
307 ret
= _krb5_xunlock(context
, fd
);
312 static krb5_error_code KRB5_CALLCONV
313 fcc_gen_new(krb5_context context
, krb5_ccache
*id
)
315 char *file
= NULL
, *exp_file
= NULL
;
320 f
= malloc(sizeof(*f
));
322 krb5_set_error_message(context
, KRB5_CC_NOMEM
,
323 N_("malloc: out of memory", ""));
324 return KRB5_CC_NOMEM
;
326 ret
= asprintf (&file
, "%sXXXXXX", KRB5_DEFAULT_CCFILE_ROOT
);
327 if(ret
< 0 || file
== NULL
) {
329 krb5_set_error_message(context
, KRB5_CC_NOMEM
,
330 N_("malloc: out of memory", ""));
331 return KRB5_CC_NOMEM
;
333 ret
= _krb5_expand_path_tokens(context
, file
, &exp_file
);
340 fd
= mkstemp(exp_file
);
343 krb5_set_error_message(context
, xret
, N_("mkstemp %s failed", ""), exp_file
);
349 f
->filename
= exp_file
;
351 (*id
)->data
.data
= f
;
352 (*id
)->data
.length
= sizeof(*f
);
357 storage_set_flags(krb5_context context
, krb5_storage
*sp
, int vno
)
361 case KRB5_FCC_FVNO_1
:
362 flags
|= KRB5_STORAGE_PRINCIPAL_WRONG_NUM_COMPONENTS
;
363 flags
|= KRB5_STORAGE_PRINCIPAL_NO_NAME_TYPE
;
364 flags
|= KRB5_STORAGE_HOST_BYTEORDER
;
366 case KRB5_FCC_FVNO_2
:
367 flags
|= KRB5_STORAGE_HOST_BYTEORDER
;
369 case KRB5_FCC_FVNO_3
:
370 flags
|= KRB5_STORAGE_KEYBLOCK_KEYTYPE_TWICE
;
372 case KRB5_FCC_FVNO_4
:
376 "storage_set_flags called with bad vno (%x)", vno
);
378 krb5_storage_set_flags(sp
, flags
);
381 static krb5_error_code KRB5_CALLCONV
382 fcc_open(krb5_context context
,
388 krb5_boolean exclusive
= ((flags
| O_WRONLY
) == flags
||
389 (flags
| O_RDWR
) == flags
);
391 const char *filename
;
394 if (FCACHE(id
) == NULL
)
395 return krb5_einval(context
, 2);
397 filename
= FILENAME(id
);
399 fd
= open(filename
, flags
, mode
);
403 rk_strerror_r(ret
, buf
, sizeof(buf
));
404 krb5_set_error_message(context
, ret
, N_("open(%s): %s", "file, error"),
410 if((ret
= fcc_lock(context
, id
, fd
, exclusive
)) != 0) {
418 static krb5_error_code KRB5_CALLCONV
419 fcc_initialize(krb5_context context
,
421 krb5_principal primary_principal
)
423 krb5_fcache
*f
= FCACHE(id
);
428 return krb5_einval(context
, 2);
430 unlink (f
->filename
);
432 ret
= fcc_open(context
, id
, &fd
, O_RDWR
| O_CREAT
| O_EXCL
| O_BINARY
| O_CLOEXEC
, 0600);
437 sp
= krb5_storage_emem();
438 krb5_storage_set_eof_code(sp
, KRB5_CC_END
);
439 if(context
->fcache_vno
!= 0)
440 f
->version
= context
->fcache_vno
;
442 f
->version
= KRB5_FCC_FVNO_4
;
443 ret
|= krb5_store_int8(sp
, 5);
444 ret
|= krb5_store_int8(sp
, f
->version
);
445 storage_set_flags(context
, sp
, f
->version
);
446 if(f
->version
== KRB5_FCC_FVNO_4
&& ret
== 0) {
448 if (context
->kdc_sec_offset
) {
449 ret
|= krb5_store_int16 (sp
, 12); /* length */
450 ret
|= krb5_store_int16 (sp
, FCC_TAG_DELTATIME
); /* Tag */
451 ret
|= krb5_store_int16 (sp
, 8); /* length of data */
452 ret
|= krb5_store_int32 (sp
, context
->kdc_sec_offset
);
453 ret
|= krb5_store_int32 (sp
, context
->kdc_usec_offset
);
455 ret
|= krb5_store_int16 (sp
, 0);
458 ret
|= krb5_store_principal(sp
, primary_principal
);
460 ret
|= write_storage(context
, sp
, fd
);
462 krb5_storage_free(sp
);
464 fcc_unlock(context
, fd
);
469 rk_strerror_r(ret
, buf
, sizeof(buf
));
470 krb5_set_error_message (context
, ret
, N_("close %s: %s", ""),
476 static krb5_error_code KRB5_CALLCONV
477 fcc_close(krb5_context context
,
480 if (FCACHE(id
) == NULL
)
481 return krb5_einval(context
, 2);
484 krb5_data_free(&id
->data
);
488 static krb5_error_code KRB5_CALLCONV
489 fcc_destroy(krb5_context context
,
492 if (FCACHE(id
) == NULL
)
493 return krb5_einval(context
, 2);
495 _krb5_erase_file(context
, FILENAME(id
));
499 static krb5_error_code KRB5_CALLCONV
500 fcc_store_cred(krb5_context context
,
507 ret
= fcc_open(context
, id
, &fd
, O_WRONLY
| O_APPEND
| O_BINARY
| O_CLOEXEC
, 0);
513 sp
= krb5_storage_emem();
514 krb5_storage_set_eof_code(sp
, KRB5_CC_END
);
515 storage_set_flags(context
, sp
, FCACHE(id
)->version
);
516 if (!krb5_config_get_bool_default(context
, NULL
, TRUE
,
518 "fcc-mit-ticketflags",
520 krb5_storage_set_flags(sp
, KRB5_STORAGE_CREDS_FLAGS_WRONG_BITORDER
);
521 ret
= krb5_store_creds(sp
, creds
);
523 ret
= write_storage(context
, sp
, fd
);
524 krb5_storage_free(sp
);
526 fcc_unlock(context
, fd
);
530 rk_strerror_r(ret
, buf
, sizeof(buf
));
532 krb5_set_error_message (context
, ret
, N_("close %s: %s", ""),
539 static krb5_error_code
540 init_fcc (krb5_context context
,
542 krb5_storage
**ret_sp
,
544 krb5_deltat
*kdc_offset
)
554 ret
= fcc_open(context
, id
, &fd
, O_RDONLY
| O_BINARY
| O_CLOEXEC
, 0);
558 sp
= krb5_storage_from_fd(fd
);
560 krb5_clear_error_message(context
);
564 krb5_storage_set_eof_code(sp
, KRB5_CC_END
);
565 ret
= krb5_ret_int8(sp
, &pvno
);
567 if(ret
== KRB5_CC_END
) {
569 krb5_set_error_message(context
, ret
,
570 N_("Empty credential cache file: %s", ""),
573 krb5_set_error_message(context
, ret
, N_("Error reading pvno "
574 "in cache file: %s", ""),
579 ret
= KRB5_CCACHE_BADVNO
;
580 krb5_set_error_message(context
, ret
, N_("Bad version number in credential "
581 "cache file: %s", ""),
585 ret
= krb5_ret_int8(sp
, &tag
); /* should not be host byte order */
587 ret
= KRB5_CC_FORMAT
;
588 krb5_set_error_message(context
, ret
, "Error reading tag in "
589 "cache file: %s", FILENAME(id
));
592 FCACHE(id
)->version
= tag
;
593 storage_set_flags(context
, sp
, FCACHE(id
)->version
);
595 case KRB5_FCC_FVNO_4
: {
598 ret
= krb5_ret_int16 (sp
, &length
);
600 ret
= KRB5_CC_FORMAT
;
601 krb5_set_error_message(context
, ret
,
602 N_("Error reading tag length in "
603 "cache file: %s", ""), FILENAME(id
));
607 int16_t dtag
, data_len
;
611 ret
= krb5_ret_int16 (sp
, &dtag
);
613 ret
= KRB5_CC_FORMAT
;
614 krb5_set_error_message(context
, ret
, N_("Error reading dtag in "
615 "cache file: %s", ""),
619 ret
= krb5_ret_int16 (sp
, &data_len
);
621 ret
= KRB5_CC_FORMAT
;
622 krb5_set_error_message(context
, ret
,
623 N_("Error reading dlength "
624 "in cache file: %s",""),
629 case FCC_TAG_DELTATIME
: {
632 ret
= krb5_ret_int32 (sp
, &offset
);
633 ret
|= krb5_ret_int32 (sp
, &context
->kdc_usec_offset
);
635 ret
= KRB5_CC_FORMAT
;
636 krb5_set_error_message(context
, ret
,
637 N_("Error reading kdc_sec in "
638 "cache file: %s", ""),
642 context
->kdc_sec_offset
= offset
;
644 *kdc_offset
= offset
;
648 for (i
= 0; i
< data_len
; ++i
) {
649 ret
= krb5_ret_int8 (sp
, &dummy
);
651 ret
= KRB5_CC_FORMAT
;
652 krb5_set_error_message(context
, ret
,
653 N_("Error reading unknown "
654 "tag in cache file: %s", ""),
661 length
-= 4 + data_len
;
665 case KRB5_FCC_FVNO_3
:
666 case KRB5_FCC_FVNO_2
:
667 case KRB5_FCC_FVNO_1
:
670 ret
= KRB5_CCACHE_BADVNO
;
671 krb5_set_error_message(context
, ret
,
672 N_("Unknown version number (%d) in "
673 "credential cache file: %s", ""),
674 (int)tag
, FILENAME(id
));
683 krb5_storage_free(sp
);
684 fcc_unlock(context
, fd
);
689 static krb5_error_code KRB5_CALLCONV
690 fcc_get_principal(krb5_context context
,
692 krb5_principal
*principal
)
698 ret
= init_fcc (context
, id
, &sp
, &fd
, NULL
);
701 ret
= krb5_ret_principal(sp
, principal
);
703 krb5_clear_error_message(context
);
704 krb5_storage_free(sp
);
705 fcc_unlock(context
, fd
);
710 static krb5_error_code KRB5_CALLCONV
711 fcc_end_get (krb5_context context
,
713 krb5_cc_cursor
*cursor
);
715 static krb5_error_code KRB5_CALLCONV
716 fcc_get_first (krb5_context context
,
718 krb5_cc_cursor
*cursor
)
721 krb5_principal principal
;
723 if (FCACHE(id
) == NULL
)
724 return krb5_einval(context
, 2);
726 *cursor
= malloc(sizeof(struct fcc_cursor
));
727 if (*cursor
== NULL
) {
728 krb5_set_error_message(context
, ENOMEM
, N_("malloc: out of memory", ""));
731 memset(*cursor
, 0, sizeof(struct fcc_cursor
));
733 ret
= init_fcc (context
, id
, &FCC_CURSOR(*cursor
)->sp
,
734 &FCC_CURSOR(*cursor
)->fd
, NULL
);
740 ret
= krb5_ret_principal (FCC_CURSOR(*cursor
)->sp
, &principal
);
742 krb5_clear_error_message(context
);
743 fcc_end_get(context
, id
, cursor
);
746 krb5_free_principal (context
, principal
);
747 fcc_unlock(context
, FCC_CURSOR(*cursor
)->fd
);
751 static krb5_error_code KRB5_CALLCONV
752 fcc_get_next (krb5_context context
,
754 krb5_cc_cursor
*cursor
,
759 if (FCACHE(id
) == NULL
)
760 return krb5_einval(context
, 2);
762 if (FCC_CURSOR(*cursor
) == NULL
)
763 return krb5_einval(context
, 3);
765 if((ret
= fcc_lock(context
, id
, FCC_CURSOR(*cursor
)->fd
, FALSE
)) != 0)
768 ret
= krb5_ret_creds(FCC_CURSOR(*cursor
)->sp
, creds
);
770 krb5_clear_error_message(context
);
772 fcc_unlock(context
, FCC_CURSOR(*cursor
)->fd
);
776 static krb5_error_code KRB5_CALLCONV
777 fcc_end_get (krb5_context context
,
779 krb5_cc_cursor
*cursor
)
782 if (FCACHE(id
) == NULL
)
783 return krb5_einval(context
, 2);
785 if (FCC_CURSOR(*cursor
) == NULL
)
786 return krb5_einval(context
, 3);
788 krb5_storage_free(FCC_CURSOR(*cursor
)->sp
);
789 close (FCC_CURSOR(*cursor
)->fd
);
795 static krb5_error_code KRB5_CALLCONV
796 fcc_remove_cred(krb5_context context
,
802 krb5_ccache copy
, newfile
;
803 char *newname
= NULL
;
806 if (FCACHE(id
) == NULL
)
807 return krb5_einval(context
, 2);
809 ret
= krb5_cc_new_unique(context
, krb5_cc_type_memory
, NULL
, ©
);
813 ret
= krb5_cc_copy_cache(context
, id
, copy
);
815 krb5_cc_destroy(context
, copy
);
819 ret
= krb5_cc_remove_cred(context
, copy
, which
, cred
);
821 krb5_cc_destroy(context
, copy
);
825 ret
= asprintf(&newname
, "FILE:%s.XXXXXX", FILENAME(id
));
826 if (ret
< 0 || newname
== NULL
) {
827 krb5_cc_destroy(context
, copy
);
831 fd
= mkstemp(&newname
[5]);
834 krb5_cc_destroy(context
, copy
);
839 ret
= krb5_cc_resolve(context
, newname
, &newfile
);
843 krb5_cc_destroy(context
, copy
);
847 ret
= krb5_cc_copy_cache(context
, copy
, newfile
);
848 krb5_cc_destroy(context
, copy
);
851 krb5_cc_destroy(context
, newfile
);
855 ret
= rk_rename(&newname
[5], FILENAME(id
));
859 krb5_cc_close(context
, newfile
);
864 static krb5_error_code KRB5_CALLCONV
865 fcc_set_flags(krb5_context context
,
869 if (FCACHE(id
) == NULL
)
870 return krb5_einval(context
, 2);
875 static int KRB5_CALLCONV
876 fcc_get_version(krb5_context context
,
879 if (FCACHE(id
) == NULL
)
882 return FCACHE(id
)->version
;
889 static krb5_error_code KRB5_CALLCONV
890 fcc_get_cache_first(krb5_context context
, krb5_cc_cursor
*cursor
)
892 struct fcache_iter
*iter
;
894 iter
= calloc(1, sizeof(*iter
));
896 krb5_set_error_message(context
, ENOMEM
, N_("malloc: out of memory", ""));
904 static krb5_error_code KRB5_CALLCONV
905 fcc_get_cache_next(krb5_context context
, krb5_cc_cursor cursor
, krb5_ccache
*id
)
907 struct fcache_iter
*iter
= cursor
;
910 char *expandedfn
= NULL
;
913 return krb5_einval(context
, 2);
916 krb5_clear_error_message(context
);
921 fn
= krb5_cc_default_name(context
);
922 if (fn
== NULL
|| strncasecmp(fn
, "FILE:", 5) != 0) {
923 ret
= _krb5_expand_default_cc_name(context
,
924 KRB5_DEFAULT_CCNAME_FILE
,
930 /* check if file exists, don't return a non existant "next" */
931 if (strncasecmp(fn
, "FILE:", 5) == 0) {
933 ret
= stat(fn
+ 5, &sb
);
939 ret
= krb5_cc_resolve(context
, fn
, id
);
947 static krb5_error_code KRB5_CALLCONV
948 fcc_end_cache_get(krb5_context context
, krb5_cc_cursor cursor
)
950 struct fcache_iter
*iter
= cursor
;
953 return krb5_einval(context
, 2);
959 static krb5_error_code KRB5_CALLCONV
960 fcc_move(krb5_context context
, krb5_ccache from
, krb5_ccache to
)
962 krb5_error_code ret
= 0;
964 ret
= rk_rename(FILENAME(from
), FILENAME(to
));
966 if (ret
&& errno
!= EXDEV
) {
969 rk_strerror_r(ret
, buf
, sizeof(buf
));
970 krb5_set_error_message(context
, ret
,
971 N_("Rename of file from %s "
972 "to %s failed: %s", ""),
973 FILENAME(from
), FILENAME(to
), buf
);
975 } else if (ret
&& errno
== EXDEV
) {
976 /* make a copy and delete the orignal */
977 krb5_ssize_t sz1
, sz2
;
981 ret
= fcc_open(context
, from
, &fd1
, O_RDONLY
| O_BINARY
| O_CLOEXEC
, 0);
985 unlink(FILENAME(to
));
987 ret
= fcc_open(context
, to
, &fd2
,
988 O_WRONLY
| O_CREAT
| O_EXCL
| O_BINARY
| O_CLOEXEC
, 0600);
992 while((sz1
= read(fd1
, buf
, sizeof(buf
))) > 0) {
993 sz2
= write(fd2
, buf
, sz1
);
996 krb5_set_error_message(context
, ret
,
997 N_("Failed to write data from one file "
998 "credential cache to the other", ""));
1004 krb5_set_error_message(context
, ret
,
1005 N_("Failed to read data from one file "
1006 "credential cache to the other", ""));
1010 fcc_unlock(context
, fd2
);
1014 fcc_unlock(context
, fd1
);
1017 _krb5_erase_file(context
, FILENAME(from
));
1020 _krb5_erase_file(context
, FILENAME(to
));
1025 /* make sure ->version is uptodate */
1029 if ((ret
= init_fcc (context
, to
, &sp
, &fd
, NULL
)) == 0) {
1031 krb5_storage_free(sp
);
1032 fcc_unlock(context
, fd
);
1037 fcc_close(context
, from
);
1042 static krb5_error_code KRB5_CALLCONV
1043 fcc_get_default_name(krb5_context context
, char **str
)
1045 return _krb5_expand_default_cc_name(context
,
1046 KRB5_DEFAULT_CCNAME_FILE
,
1050 static krb5_error_code KRB5_CALLCONV
1051 fcc_lastchange(krb5_context context
, krb5_ccache id
, krb5_timestamp
*mtime
)
1053 krb5_error_code ret
;
1057 ret
= fcc_open(context
, id
, &fd
, O_RDONLY
| O_BINARY
| O_CLOEXEC
, 0);
1060 ret
= fstat(fd
, &sb
);
1064 krb5_set_error_message(context
, ret
, N_("Failed to stat cache file", ""));
1067 *mtime
= sb
.st_mtime
;
1071 static krb5_error_code KRB5_CALLCONV
1072 fcc_set_kdc_offset(krb5_context context
, krb5_ccache id
, krb5_deltat kdc_offset
)
1077 static krb5_error_code KRB5_CALLCONV
1078 fcc_get_kdc_offset(krb5_context context
, krb5_ccache id
, krb5_deltat
*kdc_offset
)
1080 krb5_error_code ret
;
1081 krb5_storage
*sp
= NULL
;
1083 ret
= init_fcc(context
, id
, &sp
, &fd
, kdc_offset
);
1085 krb5_storage_free(sp
);
1086 fcc_unlock(context
, fd
);
1094 * Variable containing the FILE based credential cache implemention.
1096 * @ingroup krb5_ccache
1099 KRB5_LIB_VARIABLE
const krb5_cc_ops krb5_fcc_ops
= {
1100 KRB5_CC_OPS_VERSION
,
1109 NULL
, /* fcc_retrieve */
1117 fcc_get_cache_first
,
1121 fcc_get_default_name
,