Imported Upstream version 1.15.1
[platform/upstream/krb5.git] / src / lib / krb5 / ccache / cc-int.h
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 /*
55  * Cursor for iterating over ccache types
56  */
57 struct krb5_cc_typecursor;
58 typedef struct krb5_cc_typecursor *krb5_cc_typecursor;
59
60 krb5_error_code
61 krb5int_cc_typecursor_new(krb5_context context, krb5_cc_typecursor *cursor);
62
63 krb5_error_code
64 krb5int_cc_typecursor_next(
65     krb5_context context,
66     krb5_cc_typecursor cursor,
67     const struct _krb5_cc_ops **ops);
68
69 krb5_error_code
70 krb5int_cc_typecursor_free(
71     krb5_context context,
72     krb5_cc_typecursor *cursor);
73
74 /* reentrant mutex used by krb5_cc_* functions */
75 typedef struct _k5_cc_mutex {
76     k5_mutex_t lock;
77     krb5_context owner;
78     krb5_int32 refcount;
79 } k5_cc_mutex;
80
81 #define K5_CC_MUTEX_PARTIAL_INITIALIZER         \
82     { K5_MUTEX_PARTIAL_INITIALIZER, NULL, 0 }
83
84 krb5_error_code
85 k5_cc_mutex_init(k5_cc_mutex *m);
86
87 krb5_error_code
88 k5_cc_mutex_finish_init(k5_cc_mutex *m);
89
90 #define k5_cc_mutex_destroy(M)                  \
91     k5_mutex_destroy(&(M)->lock);
92
93 void
94 k5_cc_mutex_assert_locked(krb5_context context, k5_cc_mutex *m);
95
96 void
97 k5_cc_mutex_assert_unlocked(krb5_context context, k5_cc_mutex *m);
98
99 void
100 k5_cc_mutex_lock(krb5_context context, k5_cc_mutex *m);
101
102 void
103 k5_cc_mutex_unlock(krb5_context context, k5_cc_mutex *m);
104
105 extern k5_cc_mutex krb5int_mcc_mutex;
106 extern k5_cc_mutex krb5int_krcc_mutex;
107 extern k5_cc_mutex krb5int_cc_file_mutex;
108
109 #ifdef USE_CCAPI_V3
110 extern krb5_error_code KRB5_CALLCONV krb5_stdccv3_context_lock
111 (krb5_context context);
112
113 extern krb5_error_code KRB5_CALLCONV krb5_stdccv3_context_unlock
114 (krb5_context context);
115 #endif
116
117 void
118 k5_cc_mutex_force_unlock(k5_cc_mutex *m);
119
120 void
121 k5_cccol_force_unlock(void);
122
123 krb5_error_code
124 krb5int_fcc_new_unique(krb5_context context, char *template, krb5_ccache *id);
125
126 krb5_error_code
127 ccselect_realm_initvt(krb5_context context, int maj_ver, int min_ver,
128                       krb5_plugin_vtable vtable);
129
130 krb5_error_code
131 ccselect_k5identity_initvt(krb5_context context, int maj_ver, int min_ver,
132                            krb5_plugin_vtable vtable);
133
134 krb5_error_code
135 k5_unmarshal_cred(const unsigned char *data, size_t len, int version,
136                   krb5_creds *creds);
137
138 krb5_error_code
139 k5_unmarshal_princ(const unsigned char *data, size_t len, int version,
140                    krb5_principal *princ_out);
141
142 void
143 k5_marshal_cred(struct k5buf *buf, int version, krb5_creds *creds);
144
145 void
146 k5_marshal_mcred(struct k5buf *buf, krb5_creds *mcred);
147
148 void
149 k5_marshal_princ(struct k5buf *buf, int version, krb5_principal princ);
150
151 /*
152  * Per-type ccache cursor.
153  */
154 struct krb5_cc_ptcursor_s {
155     const struct _krb5_cc_ops *ops;
156     krb5_pointer data;
157 };
158 typedef struct krb5_cc_ptcursor_s *krb5_cc_ptcursor;
159
160 struct _krb5_cc_ops {
161     krb5_magic magic;
162     char *prefix;
163     const char * (KRB5_CALLCONV *get_name)(krb5_context, krb5_ccache);
164     krb5_error_code (KRB5_CALLCONV *resolve)(krb5_context, krb5_ccache *,
165                                              const char *);
166     krb5_error_code (KRB5_CALLCONV *gen_new)(krb5_context, krb5_ccache *);
167     krb5_error_code (KRB5_CALLCONV *init)(krb5_context, krb5_ccache,
168                                           krb5_principal);
169     krb5_error_code (KRB5_CALLCONV *destroy)(krb5_context, krb5_ccache);
170     krb5_error_code (KRB5_CALLCONV *close)(krb5_context, krb5_ccache);
171     krb5_error_code (KRB5_CALLCONV *store)(krb5_context, krb5_ccache,
172                                            krb5_creds *);
173     krb5_error_code (KRB5_CALLCONV *retrieve)(krb5_context, krb5_ccache,
174                                               krb5_flags, krb5_creds *,
175                                               krb5_creds *);
176     krb5_error_code (KRB5_CALLCONV *get_princ)(krb5_context, krb5_ccache,
177                                                krb5_principal *);
178     krb5_error_code (KRB5_CALLCONV *get_first)(krb5_context, krb5_ccache,
179                                                krb5_cc_cursor *);
180     krb5_error_code (KRB5_CALLCONV *get_next)(krb5_context, krb5_ccache,
181                                               krb5_cc_cursor *, krb5_creds *);
182     krb5_error_code (KRB5_CALLCONV *end_get)(krb5_context, krb5_ccache,
183                                              krb5_cc_cursor *);
184     krb5_error_code (KRB5_CALLCONV *remove_cred)(krb5_context, krb5_ccache,
185                                                  krb5_flags, krb5_creds *);
186     krb5_error_code (KRB5_CALLCONV *set_flags)(krb5_context, krb5_ccache,
187                                                krb5_flags);
188     krb5_error_code (KRB5_CALLCONV *get_flags)(krb5_context, krb5_ccache,
189                                                krb5_flags *);
190     krb5_error_code (KRB5_CALLCONV *ptcursor_new)(krb5_context,
191                                                   krb5_cc_ptcursor *);
192     krb5_error_code (KRB5_CALLCONV *ptcursor_next)(krb5_context,
193                                                    krb5_cc_ptcursor,
194                                                    krb5_ccache *);
195     krb5_error_code (KRB5_CALLCONV *ptcursor_free)(krb5_context,
196                                                    krb5_cc_ptcursor *);
197     krb5_error_code (KRB5_CALLCONV *move)(krb5_context, krb5_ccache,
198                                           krb5_ccache);
199     krb5_error_code (KRB5_CALLCONV *lastchange)(krb5_context,
200                                                 krb5_ccache, krb5_timestamp *);
201     krb5_error_code (KRB5_CALLCONV *wasdefault)(krb5_context, krb5_ccache,
202                                                 krb5_timestamp *);
203     krb5_error_code (KRB5_CALLCONV *lock)(krb5_context, krb5_ccache);
204     krb5_error_code (KRB5_CALLCONV *unlock)(krb5_context, krb5_ccache);
205     krb5_error_code (KRB5_CALLCONV *switch_to)(krb5_context, krb5_ccache);
206 };
207
208 extern const krb5_cc_ops *krb5_cc_dfl_ops;
209
210 #endif /* __KRB5_CCACHE_H__ */