xref: /freebsd/crypto/krb5/src/lib/krb5/ccache/cc-int.h (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* lib/krb5/ccache/cc-int.h */
3 /*
4  * Copyright 1990,1991 by the Massachusetts Institute of Technology.
5  * All Rights Reserved.
6  *
7  * Export of this software from the United States of America may
8  *   require a specific license from the United States Government.
9  *   It is the responsibility of any person or organization contemplating
10  *   export to obtain such a license before exporting.
11  *
12  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13  * distribute this software and its documentation for any purpose and
14  * without fee is hereby granted, provided that the above copyright
15  * notice appear in all copies and that both that copyright notice and
16  * this permission notice appear in supporting documentation, and that
17  * the name of M.I.T. not be used in advertising or publicity pertaining
18  * to distribution of the software without specific, written prior
19  * permission.  Furthermore if you modify this software you must label
20  * your software as modified software and not distribute it in such a
21  * fashion that it might be confused with the original M.I.T. software.
22  * M.I.T. makes no representations about the suitability of
23  * this software for any purpose.  It is provided "as is" without express
24  * or implied warranty.
25  */
26 
27 /* This file contains constant and function declarations used in the
28  * file-based credential cache routines. */
29 
30 #ifndef __KRB5_CCACHE_H__
31 #define __KRB5_CCACHE_H__
32 
33 #include "k5-int.h"
34 
35 struct _krb5_ccache {
36     krb5_magic magic;
37     const struct _krb5_cc_ops *ops;
38     krb5_pointer data;
39 };
40 
41 krb5_error_code
42 k5_cc_retrieve_cred_default(krb5_context, krb5_ccache, krb5_flags,
43                             krb5_creds *, krb5_creds *);
44 
45 krb5_boolean
46 krb5int_cc_creds_match_request(krb5_context, krb5_flags whichfields, krb5_creds *mcreds, krb5_creds *creds);
47 
48 int
49 krb5int_cc_initialize(void);
50 
51 void
52 krb5int_cc_finalize(void);
53 
54 krb5_error_code
55 k5_nonatomic_replace(krb5_context context, krb5_ccache ccache,
56                      krb5_principal princ, krb5_creds **creds);
57 
58 /*
59  * Cursor for iterating over ccache types
60  */
61 struct krb5_cc_typecursor;
62 typedef struct krb5_cc_typecursor *krb5_cc_typecursor;
63 
64 krb5_error_code
65 krb5int_cc_typecursor_new(krb5_context context, krb5_cc_typecursor *cursor);
66 
67 krb5_error_code
68 krb5int_cc_typecursor_next(
69     krb5_context context,
70     krb5_cc_typecursor cursor,
71     const struct _krb5_cc_ops **ops);
72 
73 krb5_error_code
74 krb5int_cc_typecursor_free(
75     krb5_context context,
76     krb5_cc_typecursor *cursor);
77 
78 /* reentrant mutex used by krb5_cc_* functions */
79 typedef struct _k5_cc_mutex {
80     k5_mutex_t lock;
81     krb5_context owner;
82     krb5_int32 refcount;
83 } k5_cc_mutex;
84 
85 #define K5_CC_MUTEX_PARTIAL_INITIALIZER         \
86     { K5_MUTEX_PARTIAL_INITIALIZER, NULL, 0 }
87 
88 krb5_error_code
89 k5_cc_mutex_init(k5_cc_mutex *m);
90 
91 krb5_error_code
92 k5_cc_mutex_finish_init(k5_cc_mutex *m);
93 
94 #define k5_cc_mutex_destroy(M)                  \
95     k5_mutex_destroy(&(M)->lock);
96 
97 void
98 k5_cc_mutex_assert_locked(krb5_context context, k5_cc_mutex *m);
99 
100 void
101 k5_cc_mutex_assert_unlocked(krb5_context context, k5_cc_mutex *m);
102 
103 void
104 k5_cc_mutex_lock(krb5_context context, k5_cc_mutex *m);
105 
106 void
107 k5_cc_mutex_unlock(krb5_context context, k5_cc_mutex *m);
108 
109 extern k5_cc_mutex krb5int_mcc_mutex;
110 extern k5_cc_mutex krb5int_krcc_mutex;
111 extern k5_cc_mutex krb5int_cc_file_mutex;
112 
113 extern krb5_error_code KRB5_CALLCONV krb5_stdccv3_context_lock
114 (krb5_context context);
115 
116 extern krb5_error_code KRB5_CALLCONV krb5_stdccv3_context_unlock
117 (krb5_context context);
118 
119 krb5_error_code
120 k5_cc_lock(krb5_context context, krb5_ccache ccache);
121 
122 krb5_error_code
123 k5_cc_unlock(krb5_context context, krb5_ccache ccache);
124 
125 krb5_error_code
126 k5_cccol_lock(krb5_context context);
127 
128 krb5_error_code
129 k5_cccol_unlock(krb5_context context);
130 
131 void
132 k5_cc_mutex_force_unlock(k5_cc_mutex *m);
133 
134 void
135 k5_cccol_force_unlock(void);
136 
137 krb5_error_code
138 krb5int_fcc_new_unique(krb5_context context, char *template, krb5_ccache *id);
139 
140 krb5_error_code
141 ccselect_hostname_initvt(krb5_context context, int maj_ver, int min_ver,
142                          krb5_plugin_vtable vtable);
143 
144 krb5_error_code
145 ccselect_realm_initvt(krb5_context context, int maj_ver, int min_ver,
146                       krb5_plugin_vtable vtable);
147 
148 krb5_error_code
149 ccselect_k5identity_initvt(krb5_context context, int maj_ver, int min_ver,
150                            krb5_plugin_vtable vtable);
151 
152 krb5_error_code
153 k5_unmarshal_cred(const unsigned char *data, size_t len, int version,
154                   krb5_creds *creds);
155 
156 krb5_error_code
157 k5_unmarshal_princ(const unsigned char *data, size_t len, int version,
158                    krb5_principal *princ_out);
159 
160 void
161 k5_marshal_cred(struct k5buf *buf, int version, krb5_creds *creds);
162 
163 void
164 k5_marshal_mcred(struct k5buf *buf, krb5_creds *mcred);
165 
166 void
167 k5_marshal_princ(struct k5buf *buf, int version, krb5_principal princ);
168 
169 krb5_error_code
170 k5_kcm_primary_name(krb5_context context, char **name_out);
171 
172 /*
173  * Per-type ccache cursor.
174  */
175 struct krb5_cc_ptcursor_s {
176     const struct _krb5_cc_ops *ops;
177     krb5_pointer data;
178 };
179 typedef struct krb5_cc_ptcursor_s *krb5_cc_ptcursor;
180 
181 struct _krb5_cc_ops {
182     krb5_magic magic;
183     char *prefix;
184     const char * (KRB5_CALLCONV *get_name)(krb5_context, krb5_ccache);
185     krb5_error_code (KRB5_CALLCONV *resolve)(krb5_context, krb5_ccache *,
186                                              const char *);
187     krb5_error_code (KRB5_CALLCONV *gen_new)(krb5_context, krb5_ccache *);
188     krb5_error_code (KRB5_CALLCONV *init)(krb5_context, krb5_ccache,
189                                           krb5_principal);
190     krb5_error_code (KRB5_CALLCONV *destroy)(krb5_context, krb5_ccache);
191     krb5_error_code (KRB5_CALLCONV *close)(krb5_context, krb5_ccache);
192     krb5_error_code (KRB5_CALLCONV *store)(krb5_context, krb5_ccache,
193                                            krb5_creds *);
194     krb5_error_code (KRB5_CALLCONV *retrieve)(krb5_context, krb5_ccache,
195                                               krb5_flags, krb5_creds *,
196                                               krb5_creds *);
197     krb5_error_code (KRB5_CALLCONV *get_princ)(krb5_context, krb5_ccache,
198                                                krb5_principal *);
199     krb5_error_code (KRB5_CALLCONV *get_first)(krb5_context, krb5_ccache,
200                                                krb5_cc_cursor *);
201     krb5_error_code (KRB5_CALLCONV *get_next)(krb5_context, krb5_ccache,
202                                               krb5_cc_cursor *, krb5_creds *);
203     krb5_error_code (KRB5_CALLCONV *end_get)(krb5_context, krb5_ccache,
204                                              krb5_cc_cursor *);
205     krb5_error_code (KRB5_CALLCONV *remove_cred)(krb5_context, krb5_ccache,
206                                                  krb5_flags, krb5_creds *);
207     krb5_error_code (KRB5_CALLCONV *set_flags)(krb5_context, krb5_ccache,
208                                                krb5_flags);
209     krb5_error_code (KRB5_CALLCONV *get_flags)(krb5_context, krb5_ccache,
210                                                krb5_flags *);
211     krb5_error_code (KRB5_CALLCONV *ptcursor_new)(krb5_context,
212                                                   krb5_cc_ptcursor *);
213     krb5_error_code (KRB5_CALLCONV *ptcursor_next)(krb5_context,
214                                                    krb5_cc_ptcursor,
215                                                    krb5_ccache *);
216     krb5_error_code (KRB5_CALLCONV *ptcursor_free)(krb5_context,
217                                                    krb5_cc_ptcursor *);
218     krb5_error_code (KRB5_CALLCONV *replace)(krb5_context, krb5_ccache,
219                                              krb5_principal, krb5_creds **);
220     krb5_error_code (KRB5_CALLCONV *wasdefault)(krb5_context, krb5_ccache,
221                                                 krb5_timestamp *);
222     krb5_error_code (KRB5_CALLCONV *lock)(krb5_context, krb5_ccache);
223     krb5_error_code (KRB5_CALLCONV *unlock)(krb5_context, krb5_ccache);
224     krb5_error_code (KRB5_CALLCONV *switch_to)(krb5_context, krb5_ccache);
225 };
226 
227 extern const krb5_cc_ops *krb5_cc_dfl_ops;
228 
229 #endif /* __KRB5_CCACHE_H__ */
230