17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * lib/krb5/ccache/ccbase.c
37c478bd9Sstevel@tonic-gate  *
4505d05c7Sgtb  * Copyright 1990,2004 by the Massachusetts Institute of Technology.
57c478bd9Sstevel@tonic-gate  * All Rights Reserved.
67c478bd9Sstevel@tonic-gate  *
77c478bd9Sstevel@tonic-gate  * Export of this software from the United States of America may
87c478bd9Sstevel@tonic-gate  *   require a specific license from the United States Government.
97c478bd9Sstevel@tonic-gate  *   It is the responsibility of any person or organization contemplating
107c478bd9Sstevel@tonic-gate  *   export to obtain such a license before exporting.
11505d05c7Sgtb  *
127c478bd9Sstevel@tonic-gate  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
137c478bd9Sstevel@tonic-gate  * distribute this software and its documentation for any purpose and
147c478bd9Sstevel@tonic-gate  * without fee is hereby granted, provided that the above copyright
157c478bd9Sstevel@tonic-gate  * notice appear in all copies and that both that copyright notice and
167c478bd9Sstevel@tonic-gate  * this permission notice appear in supporting documentation, and that
177c478bd9Sstevel@tonic-gate  * the name of M.I.T. not be used in advertising or publicity pertaining
187c478bd9Sstevel@tonic-gate  * to distribution of the software without specific, written prior
197c478bd9Sstevel@tonic-gate  * permission.  Furthermore if you modify this software you must label
207c478bd9Sstevel@tonic-gate  * your software as modified software and not distribute it in such a
217c478bd9Sstevel@tonic-gate  * fashion that it might be confused with the original M.I.T. software.
227c478bd9Sstevel@tonic-gate  * M.I.T. makes no representations about the suitability of
237c478bd9Sstevel@tonic-gate  * this software for any purpose.  It is provided "as is" without express
247c478bd9Sstevel@tonic-gate  * or implied warranty.
25505d05c7Sgtb  *
267c478bd9Sstevel@tonic-gate  *
277c478bd9Sstevel@tonic-gate  * Registration functions for ccache.
287c478bd9Sstevel@tonic-gate  */
30d51f1d33Smp /*
31*159d09a2SMark Phalan  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
32d51f1d33Smp  * Use is subject to license terms.
33d51f1d33Smp  */
36505d05c7Sgtb #include "k5-int.h"
37505d05c7Sgtb #include "k5-thread.h"
39505d05c7Sgtb #include "fcc.h"
40505d05c7Sgtb #include "cc-int.h"
42505d05c7Sgtb struct krb5_cc_typelist {
43505d05c7Sgtb     const krb5_cc_ops *ops;
44505d05c7Sgtb     struct krb5_cc_typelist *next;
45505d05c7Sgtb };
46*159d09a2SMark Phalan 
47*159d09a2SMark Phalan struct krb5_cc_typecursor {
48*159d09a2SMark Phalan     struct krb5_cc_typelist *tptr;
49*159d09a2SMark Phalan };
50*159d09a2SMark Phalan /* typedef krb5_cc_typecursor in k5-int.h */
51*159d09a2SMark Phalan 
52505d05c7Sgtb extern const krb5_cc_ops krb5_mcc_ops;
53*159d09a2SMark Phalan #ifdef USE_KEYRING_CCACHE
54*159d09a2SMark Phalan extern const krb5_cc_ops krb5_krcc_ops;
55*159d09a2SMark Phalan #endif
57505d05c7Sgtb #ifdef _WIN32
58505d05c7Sgtb extern const krb5_cc_ops krb5_lcc_ops;
59505d05c7Sgtb static struct krb5_cc_typelist cc_lcc_entry = { &krb5_lcc_ops, NULL };
60505d05c7Sgtb static struct krb5_cc_typelist cc_mcc_entry = { &krb5_mcc_ops, &cc_lcc_entry };
61505d05c7Sgtb #else
62*159d09a2SMark Phalan 
63*159d09a2SMark Phalan #ifdef USE_CCAPI_V3
64*159d09a2SMark Phalan extern const krb5_cc_ops krb5_cc_stdcc_ops;
65*159d09a2SMark Phalan static struct krb5_cc_typelist cc_stdcc_entry = { &krb5_cc_stdcc_ops, NULL };
66*159d09a2SMark Phalan static struct krb5_cc_typelist cc_mcc_entry = { &krb5_mcc_ops, &cc_stdcc_entry };
67*159d09a2SMark Phalan #else
68*159d09a2SMark Phalan 
69505d05c7Sgtb static struct krb5_cc_typelist cc_mcc_entry = { &krb5_mcc_ops, NULL };
70*159d09a2SMark Phalan #endif /* USE_CCAPI_V3 */
71*159d09a2SMark Phalan 
72*159d09a2SMark Phalan #ifdef USE_KEYRING_CCACHE
73*159d09a2SMark Phalan static struct krb5_cc_typelist cc_file_entry = { &krb5_cc_file_ops,
74*159d09a2SMark Phalan 						 &cc_mcc_entry };
75*159d09a2SMark Phalan static struct krb5_cc_typelist cc_krcc_entry = { &krb5_krcc_ops,
76*159d09a2SMark Phalan 						 &cc_file_entry };
77*159d09a2SMark Phalan #endif /* USE_KEYRING_CCACHE */
78505d05c7Sgtb #endif
80505d05c7Sgtb static struct krb5_cc_typelist cc_fcc_entry = { &krb5_cc_file_ops,
81505d05c7Sgtb 						&cc_mcc_entry };
82*159d09a2SMark Phalan #ifdef USE_KEYRING_CCACHE
83*159d09a2SMark Phalan #define INITIAL_TYPEHEAD (&cc_krcc_entry)
84*159d09a2SMark Phalan #else
85*159d09a2SMark Phalan #define INITIAL_TYPEHEAD (&cc_fcc_entry)
86*159d09a2SMark Phalan #endif
87*159d09a2SMark Phalan static struct krb5_cc_typelist *cc_typehead = INITIAL_TYPEHEAD;
88505d05c7Sgtb static k5_mutex_t cc_typelist_lock = K5_MUTEX_PARTIAL_INITIALIZER;
90*159d09a2SMark Phalan static krb5_error_code
91*159d09a2SMark Phalan krb5int_cc_getops(krb5_context, const char *, const krb5_cc_ops **);
92*159d09a2SMark Phalan 
93505d05c7Sgtb int
krb5int_cc_initialize(void)94505d05c7Sgtb krb5int_cc_initialize(void)
95505d05c7Sgtb {
96505d05c7Sgtb     int err;
98505d05c7Sgtb     err = k5_mutex_finish_init(&krb5int_mcc_mutex);
99505d05c7Sgtb     if (err)
100505d05c7Sgtb 	return err;
101505d05c7Sgtb     err = k5_mutex_finish_init(&cc_typelist_lock);
102505d05c7Sgtb     if (err)
103505d05c7Sgtb 	return err;
104505d05c7Sgtb     err = k5_mutex_finish_init(&krb5int_cc_file_mutex);
105505d05c7Sgtb     if (err)
106505d05c7Sgtb 	return err;
107*159d09a2SMark Phalan #ifdef USE_KEYRING_CCACHE
108*159d09a2SMark Phalan     err = k5_mutex_finish_init(&krb5int_krcc_mutex);
109*159d09a2SMark Phalan     if (err)
110*159d09a2SMark Phalan 	return err;
111*159d09a2SMark Phalan #endif
112505d05c7Sgtb     return 0;
113505d05c7Sgtb }
115505d05c7Sgtb void
krb5int_cc_finalize(void)116505d05c7Sgtb krb5int_cc_finalize(void)
117505d05c7Sgtb {
118505d05c7Sgtb     struct krb5_cc_typelist *t, *t_next;
119505d05c7Sgtb     k5_mutex_destroy(&cc_typelist_lock);
120505d05c7Sgtb     k5_mutex_destroy(&krb5int_cc_file_mutex);
121505d05c7Sgtb     k5_mutex_destroy(&krb5int_mcc_mutex);
122*159d09a2SMark Phalan #ifdef USE_KEYRING_CCACHE
123*159d09a2SMark Phalan     k5_mutex_destroy(&krb5int_krcc_mutex);
124*159d09a2SMark Phalan #endif
125*159d09a2SMark Phalan     for (t = cc_typehead; t != INITIAL_TYPEHEAD; t = t_next) {
126505d05c7Sgtb 	t_next = t->next;
127505d05c7Sgtb 	free(t);
128505d05c7Sgtb     }
129505d05c7Sgtb }
1327c478bd9Sstevel@tonic-gate /*
1337c478bd9Sstevel@tonic-gate  * Register a new credentials cache type
1347c478bd9Sstevel@tonic-gate  * If override is set, replace any existing ccache with that type tag
1357c478bd9Sstevel@tonic-gate  */
137505d05c7Sgtb krb5_error_code KRB5_CALLCONV
krb5_cc_register(krb5_context context,krb5_cc_ops * ops,krb5_boolean override)138505d05c7Sgtb krb5_cc_register(krb5_context context, krb5_cc_ops *ops, krb5_boolean override)
1397c478bd9Sstevel@tonic-gate {
1407c478bd9Sstevel@tonic-gate     struct krb5_cc_typelist *t;
141505d05c7Sgtb     krb5_error_code err;