xref: /freebsd/crypto/krb5/src/lib/gssapi/generic/gssapiP_generic.h (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubert /* -*- mode: c; indent-tabs-mode: nil -*- */
2*7f2fe78bSCy Schubert /*
3*7f2fe78bSCy Schubert  * Copyright 1993 by OpenVision Technologies, Inc.
4*7f2fe78bSCy Schubert  *
5*7f2fe78bSCy Schubert  * Permission to use, copy, modify, distribute, and sell this software
6*7f2fe78bSCy Schubert  * and its documentation for any purpose is hereby granted without fee,
7*7f2fe78bSCy Schubert  * provided that the above copyright notice appears in all copies and
8*7f2fe78bSCy Schubert  * that both that copyright notice and this permission notice appear in
9*7f2fe78bSCy Schubert  * supporting documentation, and that the name of OpenVision not be used
10*7f2fe78bSCy Schubert  * in advertising or publicity pertaining to distribution of the software
11*7f2fe78bSCy Schubert  * without specific, written prior permission. OpenVision makes no
12*7f2fe78bSCy Schubert  * representations about the suitability of this software for any
13*7f2fe78bSCy Schubert  * purpose.  It is provided "as is" without express or implied warranty.
14*7f2fe78bSCy Schubert  *
15*7f2fe78bSCy Schubert  * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16*7f2fe78bSCy Schubert  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17*7f2fe78bSCy Schubert  * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18*7f2fe78bSCy Schubert  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
19*7f2fe78bSCy Schubert  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20*7f2fe78bSCy Schubert  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21*7f2fe78bSCy Schubert  * PERFORMANCE OF THIS SOFTWARE.
22*7f2fe78bSCy Schubert  */
23*7f2fe78bSCy Schubert 
24*7f2fe78bSCy Schubert #ifndef _GSSAPIP_GENERIC_H_
25*7f2fe78bSCy Schubert #define _GSSAPIP_GENERIC_H_
26*7f2fe78bSCy Schubert 
27*7f2fe78bSCy Schubert /*
28*7f2fe78bSCy Schubert  * $Id$
29*7f2fe78bSCy Schubert  */
30*7f2fe78bSCy Schubert 
31*7f2fe78bSCy Schubert #if defined(_WIN32)
32*7f2fe78bSCy Schubert #include "k5-int.h"
33*7f2fe78bSCy Schubert #else
34*7f2fe78bSCy Schubert #include "autoconf.h"
35*7f2fe78bSCy Schubert #ifdef HAVE_STDLIB_H
36*7f2fe78bSCy Schubert #include <stdlib.h>
37*7f2fe78bSCy Schubert #endif
38*7f2fe78bSCy Schubert #endif
39*7f2fe78bSCy Schubert 
40*7f2fe78bSCy Schubert #include "k5-thread.h"
41*7f2fe78bSCy Schubert 
42*7f2fe78bSCy Schubert #include "gssapi_generic.h"
43*7f2fe78bSCy Schubert #include "gssapi_ext.h"
44*7f2fe78bSCy Schubert #include <gssapi/gssapi_alloc.h>
45*7f2fe78bSCy Schubert #include "gssapi_err_generic.h"
46*7f2fe78bSCy Schubert #include <errno.h>
47*7f2fe78bSCy Schubert 
48*7f2fe78bSCy Schubert #include "k5-platform.h"
49*7f2fe78bSCy Schubert #include "k5-buf.h"
50*7f2fe78bSCy Schubert 
51*7f2fe78bSCy Schubert /** helper macros **/
52*7f2fe78bSCy Schubert 
53*7f2fe78bSCy Schubert #define g_OID_equal(o1, o2)                                             \
54*7f2fe78bSCy Schubert         (((o1)->length == (o2)->length) &&                              \
55*7f2fe78bSCy Schubert         (memcmp((o1)->elements, (o2)->elements, (o1)->length) == 0))
56*7f2fe78bSCy Schubert 
57*7f2fe78bSCy Schubert /** malloc wrappers; these may actually do something later */
58*7f2fe78bSCy Schubert 
59*7f2fe78bSCy Schubert #define xmalloc(n) malloc(n)
60*7f2fe78bSCy Schubert #define xrealloc(p,n) realloc(p,n)
61*7f2fe78bSCy Schubert #ifdef xfree
62*7f2fe78bSCy Schubert #undef xfree
63*7f2fe78bSCy Schubert #endif
64*7f2fe78bSCy Schubert #define xfree(p) free(p)
65*7f2fe78bSCy Schubert 
66*7f2fe78bSCy Schubert /** helper functions **/
67*7f2fe78bSCy Schubert 
68*7f2fe78bSCy Schubert /* hide names from applications, especially glib applications */
69*7f2fe78bSCy Schubert #define g_set_init              gssint_g_set_init
70*7f2fe78bSCy Schubert #define g_set_destroy           gssint_g_set_destroy
71*7f2fe78bSCy Schubert #define g_set_entry_add         gssint_g_set_entry_add
72*7f2fe78bSCy Schubert #define g_set_entry_delete      gssint_g_set_entry_delete
73*7f2fe78bSCy Schubert #define g_set_entry_get         gssint_g_set_entry_get
74*7f2fe78bSCy Schubert #define g_make_string_buffer    gssint_g_make_string_buffer
75*7f2fe78bSCy Schubert #define g_token_size            gssint_g_token_size
76*7f2fe78bSCy Schubert #define g_make_token_header     gssint_g_make_token_header
77*7f2fe78bSCy Schubert #define g_verify_token_header   gssint_g_verify_token_header
78*7f2fe78bSCy Schubert #define g_display_major_status  gssint_g_display_major_status
79*7f2fe78bSCy Schubert #define g_display_com_err_status gssint_g_display_com_err_status
80*7f2fe78bSCy Schubert #define g_seqstate_init         gssint_g_seqstate_init
81*7f2fe78bSCy Schubert #define g_seqstate_check        gssint_g_seqstate_check
82*7f2fe78bSCy Schubert #define g_seqstate_free         gssint_g_seqstate_free
83*7f2fe78bSCy Schubert #define g_seqstate_size         gssint_g_seqstate_size
84*7f2fe78bSCy Schubert #define g_seqstate_externalize  gssint_g_seqstate_externalize
85*7f2fe78bSCy Schubert #define g_seqstate_internalize  gssint_g_seqstate_internalize
86*7f2fe78bSCy Schubert #define g_canonicalize_host     gssint_g_canonicalize_host
87*7f2fe78bSCy Schubert #define g_local_host_name       gssint_g_local_host_name
88*7f2fe78bSCy Schubert #define g_strdup                gssint_g_strdup
89*7f2fe78bSCy Schubert 
90*7f2fe78bSCy Schubert typedef struct _g_set_elt *g_set_elt;
91*7f2fe78bSCy Schubert typedef struct {
92*7f2fe78bSCy Schubert     k5_mutex_t mutex;
93*7f2fe78bSCy Schubert     void *data;
94*7f2fe78bSCy Schubert } g_set;
95*7f2fe78bSCy Schubert #define G_SET_INIT { K5_MUTEX_PARTIAL_INITIALIZER, 0 }
96*7f2fe78bSCy Schubert 
97*7f2fe78bSCy Schubert typedef struct g_seqnum_state_st *g_seqnum_state;
98*7f2fe78bSCy Schubert 
99*7f2fe78bSCy Schubert int g_set_init (g_set_elt *s);
100*7f2fe78bSCy Schubert int g_set_destroy (g_set_elt *s);
101*7f2fe78bSCy Schubert int g_set_entry_add (g_set_elt *s, void *key, void *value);
102*7f2fe78bSCy Schubert int g_set_entry_delete (g_set_elt *s, void *key);
103*7f2fe78bSCy Schubert int g_set_entry_get (g_set_elt *s, void *key, void **value);
104*7f2fe78bSCy Schubert 
105*7f2fe78bSCy Schubert int g_save_name (g_set *vdb, gss_name_t name);
106*7f2fe78bSCy Schubert int g_save_cred_id (g_set *vdb, gss_cred_id_t cred);
107*7f2fe78bSCy Schubert int g_save_ctx_id (g_set *vdb, gss_ctx_id_t ctx);
108*7f2fe78bSCy Schubert int g_save_lucidctx_id (g_set *vdb, void *lctx);
109*7f2fe78bSCy Schubert 
110*7f2fe78bSCy Schubert int g_validate_name (g_set *vdb, gss_name_t name);
111*7f2fe78bSCy Schubert int g_validate_cred_id (g_set *vdb, gss_cred_id_t cred);
112*7f2fe78bSCy Schubert int g_validate_ctx_id (g_set *vdb, gss_ctx_id_t ctx);
113*7f2fe78bSCy Schubert int g_validate_lucidctx_id (g_set *vdb, void *lctx);
114*7f2fe78bSCy Schubert 
115*7f2fe78bSCy Schubert int g_delete_name (g_set *vdb, gss_name_t name);
116*7f2fe78bSCy Schubert int g_delete_cred_id (g_set *vdb, gss_cred_id_t cred);
117*7f2fe78bSCy Schubert int g_delete_ctx_id (g_set *vdb, gss_ctx_id_t ctx);
118*7f2fe78bSCy Schubert int g_delete_lucidctx_id (g_set *vdb, void *lctx);
119*7f2fe78bSCy Schubert 
120*7f2fe78bSCy Schubert int g_make_string_buffer (const char *str, gss_buffer_t buffer);
121*7f2fe78bSCy Schubert 
122*7f2fe78bSCy Schubert unsigned int g_token_size (const gss_OID_desc * mech, unsigned int body_size);
123*7f2fe78bSCy Schubert 
124*7f2fe78bSCy Schubert void g_make_token_header (struct k5buf *buf, const gss_OID_desc *mech,
125*7f2fe78bSCy Schubert                           size_t body_size, int tok_type);
126*7f2fe78bSCy Schubert 
127*7f2fe78bSCy Schubert /* flags for g_verify_token_header() */
128*7f2fe78bSCy Schubert #define G_VFY_TOKEN_HDR_WRAPPER_REQUIRED        0x01
129*7f2fe78bSCy Schubert 
130*7f2fe78bSCy Schubert gss_int32 g_verify_token_header (const gss_OID_desc * mech,
131*7f2fe78bSCy Schubert                                  unsigned int *body_size,
132*7f2fe78bSCy Schubert                                  unsigned char **buf, int tok_type,
133*7f2fe78bSCy Schubert                                  unsigned int toksize_in,
134*7f2fe78bSCy Schubert                                  int flags);
135*7f2fe78bSCy Schubert 
136*7f2fe78bSCy Schubert OM_uint32 g_display_major_status (OM_uint32 *minor_status,
137*7f2fe78bSCy Schubert                                   OM_uint32 status_value,
138*7f2fe78bSCy Schubert                                   OM_uint32 *message_context,
139*7f2fe78bSCy Schubert                                   gss_buffer_t status_string);
140*7f2fe78bSCy Schubert 
141*7f2fe78bSCy Schubert OM_uint32 g_display_com_err_status (OM_uint32 *minor_status,
142*7f2fe78bSCy Schubert                                     OM_uint32 status_value,
143*7f2fe78bSCy Schubert                                     gss_buffer_t status_string);
144*7f2fe78bSCy Schubert 
145*7f2fe78bSCy Schubert long g_seqstate_init(g_seqnum_state *state_out, uint64_t seqnum,
146*7f2fe78bSCy Schubert                      int do_replay, int do_sequence, int wide);
147*7f2fe78bSCy Schubert OM_uint32 g_seqstate_check(g_seqnum_state state, uint64_t seqnum);
148*7f2fe78bSCy Schubert void g_seqstate_free(g_seqnum_state state);
149*7f2fe78bSCy Schubert void g_seqstate_size(g_seqnum_state state, size_t *sizep);
150*7f2fe78bSCy Schubert long g_seqstate_externalize(g_seqnum_state state, unsigned char **buf,
151*7f2fe78bSCy Schubert                             size_t *lenremain);
152*7f2fe78bSCy Schubert long g_seqstate_internalize(g_seqnum_state *state_out, unsigned char **buf,
153*7f2fe78bSCy Schubert                             size_t *lenremain);
154*7f2fe78bSCy Schubert 
155*7f2fe78bSCy Schubert char *g_strdup (char *str);
156*7f2fe78bSCy Schubert 
157*7f2fe78bSCy Schubert /** declarations of internal name mechanism functions **/
158*7f2fe78bSCy Schubert 
159*7f2fe78bSCy Schubert OM_uint32
160*7f2fe78bSCy Schubert generic_gss_release_buffer(
161*7f2fe78bSCy Schubert     OM_uint32 *,        /* minor_status */
162*7f2fe78bSCy Schubert     gss_buffer_t);      /* buffer */
163*7f2fe78bSCy Schubert 
164*7f2fe78bSCy Schubert OM_uint32
165*7f2fe78bSCy Schubert generic_gss_release_oid_set(
166*7f2fe78bSCy Schubert     OM_uint32 *,        /* minor_status */
167*7f2fe78bSCy Schubert     gss_OID_set *);     /* set */
168*7f2fe78bSCy Schubert 
169*7f2fe78bSCy Schubert OM_uint32
170*7f2fe78bSCy Schubert generic_gss_release_oid(
171*7f2fe78bSCy Schubert     OM_uint32 *,        /* minor_status */
172*7f2fe78bSCy Schubert     gss_OID *);         /* set */
173*7f2fe78bSCy Schubert 
174*7f2fe78bSCy Schubert OM_uint32
175*7f2fe78bSCy Schubert generic_gss_copy_oid(
176*7f2fe78bSCy Schubert     OM_uint32 *,                /* minor_status */
177*7f2fe78bSCy Schubert     const gss_OID_desc * const, /* oid */
178*7f2fe78bSCy Schubert     gss_OID *);                 /* new_oid */
179*7f2fe78bSCy Schubert 
180*7f2fe78bSCy Schubert OM_uint32
181*7f2fe78bSCy Schubert generic_gss_create_empty_oid_set(
182*7f2fe78bSCy Schubert     OM_uint32 *,        /* minor_status */
183*7f2fe78bSCy Schubert     gss_OID_set *);     /* oid_set */
184*7f2fe78bSCy Schubert 
185*7f2fe78bSCy Schubert OM_uint32
186*7f2fe78bSCy Schubert generic_gss_add_oid_set_member(
187*7f2fe78bSCy Schubert     OM_uint32 *,                /* minor_status */
188*7f2fe78bSCy Schubert     const gss_OID_desc * const, /* member_oid */
189*7f2fe78bSCy Schubert     gss_OID_set *);             /* oid_set */
190*7f2fe78bSCy Schubert 
191*7f2fe78bSCy Schubert OM_uint32
192*7f2fe78bSCy Schubert generic_gss_test_oid_set_member(
193*7f2fe78bSCy Schubert     OM_uint32 *,                /* minor_status */
194*7f2fe78bSCy Schubert     const gss_OID_desc * const, /* member */
195*7f2fe78bSCy Schubert     gss_OID_set,                /* set */
196*7f2fe78bSCy Schubert     int *);                     /* present */
197*7f2fe78bSCy Schubert 
198*7f2fe78bSCy Schubert OM_uint32
199*7f2fe78bSCy Schubert generic_gss_oid_to_str(
200*7f2fe78bSCy Schubert     OM_uint32 *,                /* minor_status */
201*7f2fe78bSCy Schubert     const gss_OID_desc * const, /* oid */
202*7f2fe78bSCy Schubert     gss_buffer_t);              /* oid_str */
203*7f2fe78bSCy Schubert 
204*7f2fe78bSCy Schubert OM_uint32
205*7f2fe78bSCy Schubert generic_gss_str_to_oid(
206*7f2fe78bSCy Schubert     OM_uint32 *,        /* minor_status */
207*7f2fe78bSCy Schubert     gss_buffer_t,       /* oid_str */
208*7f2fe78bSCy Schubert     gss_OID *);         /* oid */
209*7f2fe78bSCy Schubert 
210*7f2fe78bSCy Schubert OM_uint32
211*7f2fe78bSCy Schubert generic_gss_oid_compose(
212*7f2fe78bSCy Schubert     OM_uint32 *,        /* minor_status */
213*7f2fe78bSCy Schubert     const char *,       /* prefix */
214*7f2fe78bSCy Schubert     size_t,             /* prefix_len */
215*7f2fe78bSCy Schubert     int,                /* suffix */
216*7f2fe78bSCy Schubert     gss_OID_desc *);    /* oid */
217*7f2fe78bSCy Schubert 
218*7f2fe78bSCy Schubert OM_uint32
219*7f2fe78bSCy Schubert generic_gss_oid_decompose(
220*7f2fe78bSCy Schubert     OM_uint32 *,        /* minor_status */
221*7f2fe78bSCy Schubert     const char *,       /*prefix */
222*7f2fe78bSCy Schubert     size_t,             /* prefix_len */
223*7f2fe78bSCy Schubert     gss_OID_desc *,     /* oid */
224*7f2fe78bSCy Schubert     int *);             /* suffix */
225*7f2fe78bSCy Schubert 
226*7f2fe78bSCy Schubert int gssint_mecherrmap_init(void);
227*7f2fe78bSCy Schubert void gssint_mecherrmap_destroy(void);
228*7f2fe78bSCy Schubert OM_uint32 gssint_mecherrmap_map(OM_uint32 minor, const gss_OID_desc *oid);
229*7f2fe78bSCy Schubert int gssint_mecherrmap_get(OM_uint32 minor, gss_OID mech_oid,
230*7f2fe78bSCy Schubert                           OM_uint32 *mech_minor);
231*7f2fe78bSCy Schubert OM_uint32 gssint_mecherrmap_map_errcode(OM_uint32 errcode);
232*7f2fe78bSCy Schubert 
233*7f2fe78bSCy Schubert /*
234*7f2fe78bSCy Schubert  * Transfer contents of a k5buf to a gss_buffer and invalidate the source
235*7f2fe78bSCy Schubert  * On unix, this is a simple pointer copy
236*7f2fe78bSCy Schubert  * On windows, memory is reallocated and copied.
237*7f2fe78bSCy Schubert  */
238*7f2fe78bSCy Schubert static inline OM_uint32
k5buf_to_gss(OM_uint32 * minor,struct k5buf * input_k5buf,gss_buffer_t output_buffer)239*7f2fe78bSCy Schubert k5buf_to_gss(OM_uint32 *minor,
240*7f2fe78bSCy Schubert              struct k5buf *input_k5buf,
241*7f2fe78bSCy Schubert              gss_buffer_t output_buffer)
242*7f2fe78bSCy Schubert {
243*7f2fe78bSCy Schubert     OM_uint32 status = GSS_S_COMPLETE;
244*7f2fe78bSCy Schubert 
245*7f2fe78bSCy Schubert     if (k5_buf_status(input_k5buf) != 0) {
246*7f2fe78bSCy Schubert         *minor = ENOMEM;
247*7f2fe78bSCy Schubert         return GSS_S_FAILURE;
248*7f2fe78bSCy Schubert     }
249*7f2fe78bSCy Schubert     output_buffer->length = input_k5buf->len;
250*7f2fe78bSCy Schubert #if defined(_WIN32) || defined(DEBUG_GSSALLOC)
251*7f2fe78bSCy Schubert     if (output_buffer->length > 0) {
252*7f2fe78bSCy Schubert         output_buffer->value = gssalloc_malloc(output_buffer->length);
253*7f2fe78bSCy Schubert         if (output_buffer->value) {
254*7f2fe78bSCy Schubert             memcpy(output_buffer->value, input_k5buf->data,
255*7f2fe78bSCy Schubert                    output_buffer->length);
256*7f2fe78bSCy Schubert         } else {
257*7f2fe78bSCy Schubert             status = GSS_S_FAILURE;
258*7f2fe78bSCy Schubert             *minor = ENOMEM;
259*7f2fe78bSCy Schubert         }
260*7f2fe78bSCy Schubert     } else {
261*7f2fe78bSCy Schubert         output_buffer->value = NULL;
262*7f2fe78bSCy Schubert     }
263*7f2fe78bSCy Schubert     k5_buf_free(input_k5buf);
264*7f2fe78bSCy Schubert #else
265*7f2fe78bSCy Schubert     output_buffer->value = input_k5buf->data;
266*7f2fe78bSCy Schubert     memset(input_k5buf, 0, sizeof(*input_k5buf));
267*7f2fe78bSCy Schubert #endif
268*7f2fe78bSCy Schubert     return status;
269*7f2fe78bSCy Schubert }
270*7f2fe78bSCy Schubert 
271*7f2fe78bSCy Schubert OM_uint32 generic_gss_create_empty_buffer_set
272*7f2fe78bSCy Schubert (OM_uint32 * /*minor_status*/,
273*7f2fe78bSCy Schubert             gss_buffer_set_t * /*buffer_set*/);
274*7f2fe78bSCy Schubert 
275*7f2fe78bSCy Schubert OM_uint32 generic_gss_add_buffer_set_member
276*7f2fe78bSCy Schubert (OM_uint32 * /*minor_status*/,
277*7f2fe78bSCy Schubert             const gss_buffer_t /*member_buffer*/,
278*7f2fe78bSCy Schubert             gss_buffer_set_t * /*buffer_set*/);
279*7f2fe78bSCy Schubert 
280*7f2fe78bSCy Schubert OM_uint32 generic_gss_release_buffer_set
281*7f2fe78bSCy Schubert (OM_uint32 * /*minor_status*/,
282*7f2fe78bSCy Schubert             gss_buffer_set_t * /*buffer_set*/);
283*7f2fe78bSCy Schubert 
284*7f2fe78bSCy Schubert OM_uint32 generic_gss_copy_oid_set
285*7f2fe78bSCy Schubert (OM_uint32 *, /* minor_status */
286*7f2fe78bSCy Schubert             const gss_OID_set_desc * const /*oidset*/,
287*7f2fe78bSCy Schubert             gss_OID_set * /*new_oidset*/);
288*7f2fe78bSCy Schubert 
289*7f2fe78bSCy Schubert extern gss_OID_set gss_ma_known_attrs;
290*7f2fe78bSCy Schubert 
291*7f2fe78bSCy Schubert OM_uint32 generic_gss_display_mech_attr(
292*7f2fe78bSCy Schubert       OM_uint32         *minor_status,
293*7f2fe78bSCy Schubert       gss_const_OID      mech_attr,
294*7f2fe78bSCy Schubert       gss_buffer_t       name,
295*7f2fe78bSCy Schubert       gss_buffer_t       short_desc,
296*7f2fe78bSCy Schubert       gss_buffer_t       long_desc);
297*7f2fe78bSCy Schubert 
298*7f2fe78bSCy Schubert #endif /* _GSSAPIP_GENERIC_H_ */
299