* src/lib/gssapi/mechglue/mglueP.h: Add loopback field to opaque
[krb5.git] / src / lib / gssapi / mechglue / mglueP.h
1 /* #ident  "@(#)mglueP.h 1.2     96/01/18 SMI" */
2
3 /*
4  * This header contains the private mechglue definitions.
5  *
6  * Copyright (c) 1995, by Sun Microsystems, Inc.
7  * All rights reserved.
8  */
9
10 #ifndef _GSS_MECHGLUEP_H
11 #define _GSS_MECHGLUEP_H
12
13 #include "autoconf.h"
14 #include "mechglue.h"
15 #include "gssapiP_generic.h"
16
17 #define g_OID_copy(o1, o2)                                      \
18 do {                                                            \
19         memcpy((o1)->elements, (o2)->elements, (o2)->length);   \
20         (o1)->length = (o2)->length;                            \
21 } while (0)
22
23 #define GSS_EMPTY_BUFFER(buf)   ((buf) == NULL ||\
24         (buf)->value == NULL || (buf)->length == 0)
25
26 /*
27  * Array of context IDs typed by mechanism OID
28  */
29 typedef struct gss_ctx_id_struct {
30         struct gss_ctx_id_struct *loopback;
31         gss_OID                 mech_type;
32         gss_ctx_id_t            internal_ctx_id;
33 } gss_union_ctx_id_desc, *gss_union_ctx_id_t;
34
35 /*
36  * Generic GSSAPI names.  A name can either be a generic name, or a
37  * mechanism specific name....
38  */
39 typedef struct gss_name_struct {
40         struct gss_name_struct *loopback;
41         gss_OID                 name_type;
42         gss_buffer_t            external_name;
43         /*
44          * These last two fields are only filled in for mechanism
45          * names.
46          */
47         gss_OID                 mech_type;
48         gss_name_t              mech_name;
49 } gss_union_name_desc, *gss_union_name_t;
50
51 /*
52  * Structure for holding list of mechanism-specific name types
53  */
54 typedef struct gss_mech_spec_name_t {
55     gss_OID     name_type;
56     gss_OID     mech;
57     struct gss_mech_spec_name_t *next, *prev;
58 } gss_mech_spec_name_desc, *gss_mech_spec_name;
59
60 /*
61  * Credential auxiliary info, used in the credential structure
62  */
63 typedef struct gss_union_cred_auxinfo {
64         gss_buffer_desc         name;
65         gss_OID                 name_type;
66         OM_uint32               creation_time;
67         OM_uint32               time_rec;
68         int                     cred_usage;
69 } gss_union_cred_auxinfo;
70
71 /*
72  * Set of Credentials typed on mechanism OID
73  */
74 typedef struct gss_cred_id_struct {
75         struct gss_cred_id_struct *loopback;
76         int                     count;
77         gss_OID                 mechs_array;
78         gss_cred_id_t           *cred_array;
79         gss_union_cred_auxinfo  auxinfo;
80 } gss_union_cred_desc, *gss_union_cred_t;
81  
82 /*
83  * Rudimentary pointer validation macro to check whether the
84  * "loopback" field of an opaque struct points back to itself.  This
85  * field also catches some programming errors where an opaque pointer
86  * is passed to a function expecting the address of the opaque
87  * pointer.
88  */
89 #define GSSINT_CHK_LOOP(p) (!((p) != NULL && (p)->loopback == (p)))
90
91 /********************************************************/
92 /* The Mechanism Dispatch Table -- a mechanism needs to */
93 /* define one of these and provide a function to return */
94 /* it to initialize the GSSAPI library                  */
95
96 /*
97  * This is the definition of the mechs_array struct, which is used to
98  * define the mechs array table. This table is used to indirectly
99  * access mechanism specific versions of the gssapi routines through
100  * the routines in the glue module (gssd_mech_glue.c)
101  *
102  * This contants all of the functions defined in gssapi.h except for
103  * gss_release_buffer() and gss_release_oid_set(), which I am
104  * assuming, for now, to be equal across mechanisms.  
105  */
106  
107 typedef struct gss_config {
108     OM_uint32       priority;
109     char *          mechNameStr;
110     gss_OID_desc    mech_type;
111     void *          context;
112     OM_uint32       (*gss_acquire_cred)
113         (
114                     void*,              /* context */
115                     OM_uint32*,         /* minor_status */
116                     gss_name_t,         /* desired_name */
117                     OM_uint32,          /* time_req */
118                     gss_OID_set,        /* desired_mechs */
119                     int,                /* cred_usage */
120                     gss_cred_id_t*,     /* output_cred_handle */
121                     gss_OID_set*,       /* actual_mechs */
122                     OM_uint32*          /* time_rec */
123                     );
124     OM_uint32       (*gss_release_cred)
125         (
126                     void*,              /* context */                  
127                     OM_uint32*,         /* minor_status */
128                     gss_cred_id_t*      /* cred_handle */
129                     );
130     OM_uint32       (*gss_init_sec_context)
131         (
132                     void*,                      /* context */
133                     OM_uint32*,                 /* minor_status */
134                     gss_cred_id_t,              /* claimant_cred_handle */
135                     gss_ctx_id_t*,              /* context_handle */
136                     gss_name_t,                 /* target_name */
137                     gss_OID,                    /* mech_type */
138                     OM_uint32,                  /* req_flags */
139                     OM_uint32,                  /* time_req */
140                     gss_channel_bindings_t,     /* input_chan_bindings */
141                     gss_buffer_t,               /* input_token */
142                     gss_OID*,                   /* actual_mech_type */
143                     gss_buffer_t,               /* output_token */
144                     OM_uint32*,                 /* ret_flags */
145                     OM_uint32*                  /* time_rec */
146                     );
147     OM_uint32       (*gss_accept_sec_context)
148         (
149                     void*,                      /* context */
150                     OM_uint32*,                 /* minor_status */
151                     gss_ctx_id_t*,              /* context_handle */
152                     gss_cred_id_t,              /* verifier_cred_handle */
153                     gss_buffer_t,               /* input_token_buffer */
154                     gss_channel_bindings_t,     /* input_chan_bindings */
155                     gss_name_t*,                /* src_name */
156                     gss_OID*,                   /* mech_type */
157                     gss_buffer_t,               /* output_token */
158                     OM_uint32*,                 /* ret_flags */
159                     OM_uint32*,                 /* time_rec */
160                     gss_cred_id_t*              /* delegated_cred_handle */
161                     );
162     OM_uint32       (*gss_process_context_token)
163         (
164                     void*,              /* context */
165                     OM_uint32*,         /* minor_status */
166                     gss_ctx_id_t,       /* context_handle */
167                     gss_buffer_t        /* token_buffer */
168                     );
169     OM_uint32       (*gss_delete_sec_context)
170         (
171                     void*,              /* context */
172                     OM_uint32*,         /* minor_status */
173                     gss_ctx_id_t*,      /* context_handle */
174                     gss_buffer_t        /* output_token */
175                     );
176     OM_uint32       (*gss_context_time)
177         (
178                     void*,              /* context */
179                     OM_uint32*,         /* minor_status */
180                     gss_ctx_id_t,       /* context_handle */
181                     OM_uint32*          /* time_rec */
182                     );
183     OM_uint32       (*gss_sign)
184         (
185                     void*,              /* context */
186                     OM_uint32*,         /* minor_status */
187                     gss_ctx_id_t,       /* context_handle */
188                     int,                /* qop_req */
189                     gss_buffer_t,       /* message_buffer */
190                     gss_buffer_t        /* message_token */
191                     );
192     OM_uint32       (*gss_verify)
193         (
194                     void*,              /* context */
195                     OM_uint32*,         /* minor_status */
196                     gss_ctx_id_t,       /* context_handle */
197                     gss_buffer_t,       /* message_buffer */
198                     gss_buffer_t,       /* token_buffer */
199                     int*                /* qop_state */
200                     );
201     OM_uint32       (*gss_seal)
202         (
203                     void*,              /* context */
204                     OM_uint32*,         /* minor_status */
205                     gss_ctx_id_t,       /* context_handle */
206                     int,                /* conf_req_flag */
207                     int,                /* qop_req */
208                     gss_buffer_t,       /* input_message_buffer */
209                     int*,               /* conf_state */
210                     gss_buffer_t        /* output_message_buffer */
211                     );
212     OM_uint32       (*gss_unseal)
213         (
214                     void*,              /* context */
215                     OM_uint32*,         /* minor_status */
216                     gss_ctx_id_t,       /* context_handle */
217                     gss_buffer_t,       /* input_message_buffer */
218                     gss_buffer_t,       /* output_message_buffer */
219                     int*,               /* conf_state */
220                     int*                /* qop_state */
221                     );
222     OM_uint32       (*gss_display_status)
223         (
224                     void*,              /* context */
225                     OM_uint32*,         /* minor_status */
226                     OM_uint32,          /* status_value */
227                     int,                /* status_type */
228                     gss_OID,            /* mech_type */
229                     OM_uint32*,         /* message_context */
230                     gss_buffer_t        /* status_string */
231                     );
232     OM_uint32       (*gss_indicate_mechs)
233         (
234                     void*,              /* context */
235                     OM_uint32*,         /* minor_status */
236                     gss_OID_set*        /* mech_set */
237                     );
238     OM_uint32       (*gss_compare_name)
239         (
240                     void*,              /* context */
241                     OM_uint32*,         /* minor_status */
242                     gss_name_t,         /* name1 */
243                     gss_name_t,         /* name2 */
244                     int*                /* name_equal */
245                     );
246     OM_uint32       (*gss_display_name)
247         (
248                     void*,              /* context */
249                     OM_uint32*,         /* minor_status */
250                     gss_name_t,         /* input_name */
251                     gss_buffer_t,       /* output_name_buffer */
252                     gss_OID*            /* output_name_type */
253                     );
254     OM_uint32       (*gss_import_name)
255         (
256                     void*,              /* context */
257                     OM_uint32*,         /* minor_status */
258                     gss_buffer_t,       /* input_name_buffer */
259                     gss_OID,            /* input_name_type */
260                     gss_name_t*         /* output_name */
261                     );
262     OM_uint32       (*gss_release_name)
263         (
264                     void*,              /* context */
265                     OM_uint32*,         /* minor_status */
266                     gss_name_t*         /* input_name */
267                     );
268     OM_uint32       (*gss_inquire_cred)
269         (
270                     void*,                      /* context */
271                     OM_uint32 *,                /* minor_status */
272                     gss_cred_id_t,              /* cred_handle */
273                     gss_name_t *,               /* name */
274                     OM_uint32 *,                /* lifetime */
275                     int *,                      /* cred_usage */
276                     gss_OID_set *               /* mechanisms */
277                     );
278     OM_uint32       (*gss_add_cred)
279         (
280                     void*,              /* context */
281                     OM_uint32 *,        /* minor_status */
282                     gss_cred_id_t,      /* input_cred_handle */
283                     gss_name_t,         /* desired_name */
284                     gss_OID,            /* desired_mech */
285                     gss_cred_usage_t,   /* cred_usage */
286                     OM_uint32,          /* initiator_time_req */
287                     OM_uint32,          /* acceptor_time_req */
288                     gss_cred_id_t *,    /* output_cred_handle */
289                     gss_OID_set *,      /* actual_mechs */
290                     OM_uint32 *,        /* initiator_time_rec */
291                     OM_uint32 *         /* acceptor_time_rec */
292                     );
293     OM_uint32       (*gss_export_sec_context)
294         (
295                     void*,              /* context */
296                     OM_uint32 *,        /* minor_status */
297                     gss_ctx_id_t *,     /* context_handle */
298                     gss_buffer_t        /* interprocess_token */
299                     );
300     OM_uint32       (*gss_import_sec_context)
301         (
302                     void *,             /* context */
303                     OM_uint32 *,        /* minor_status */
304                     gss_buffer_t,       /* interprocess_token */
305                     gss_ctx_id_t *      /* context_handle */
306                     );
307     OM_uint32       (*gss_inquire_cred_by_mech)
308         (
309                     void *,             /* context */
310                     OM_uint32 *,        /* minor_status */
311                     gss_cred_id_t,      /* cred_handle */
312                     gss_OID,            /* mech_type */
313                     gss_name_t *,       /* name */
314                     OM_uint32 *,        /* initiator_lifetime */
315                     OM_uint32 *,        /* acceptor_lifetime */
316                     gss_cred_usage_t *  /* cred_usage */
317                     );
318     OM_uint32       (*gss_inquire_names_for_mech)
319         (
320                     void *,             /* context */
321                     OM_uint32 *,        /* minor_status */
322                     gss_OID,            /* mechanism */
323                     gss_OID_set *       /* name_types */
324                     );
325     OM_uint32   (*gss_inquire_context)
326         (
327                     void *,             /* context */
328                     OM_uint32 *,        /* minor_status */
329                     gss_ctx_id_t,       /* context_handle */
330                     gss_name_t *,       /* src_name */
331                     gss_name_t *,       /* targ_name */
332                     OM_uint32 *,        /* lifetime_rec */
333                     gss_OID *,          /* mech_type */
334                     OM_uint32 *,        /* ctx_flags */
335                     int *,              /* locally_initiated */
336                     int *               /* open */
337                     );
338     OM_uint32       (*gss_internal_release_oid)
339         (
340                     void *,             /* context */
341                     OM_uint32 *,        /* minor_status */
342                     gss_OID *           /* OID */
343          );
344     OM_uint32        (*gss_wrap_size_limit)
345         (
346                     void *,             /* context */
347                     OM_uint32 *,        /* minor_status */
348                     gss_ctx_id_t,       /* context_handle */
349                     int,                /* conf_req_flag */
350                     gss_qop_t,          /* qop_req */
351                     OM_uint32,          /* req_output_size */
352                     OM_uint32 *         /* max_input_size */
353          );
354         OM_uint32               (*gss_export_name)
355         (
356                 void *,                 /* context */
357                 OM_uint32 *,            /* minor_status */
358                 const gss_name_t,       /* input_name */
359                 gss_buffer_t            /* exported_name */
360         /* */);
361         OM_uint32       (*gss_store_cred)
362         (
363                 void *,                 /* context */
364                 OM_uint32 *,            /* minor_status */
365                 const gss_cred_id_t,    /* input_cred */
366                 gss_cred_usage_t,       /* cred_usage */
367                 const gss_OID,          /* desired_mech */
368                 OM_uint32,              /* overwrite_cred */
369                 OM_uint32,              /* default_cred */
370                 gss_OID_set *,          /* elements_stored */
371                 gss_cred_usage_t *      /* cred_usage_stored */
372         /* */);
373 } *gss_mechanism;
374
375 /*
376  * In the user space we use a wrapper structure to encompass the
377  * mechanism entry points.  The wrapper contain the mechanism
378  * entry points and other data which is only relevant to the gss-api
379  * layer.  In the kernel we use only the gss_config strucutre because
380  * the kernal does not cantain any of the extra gss-api specific data.
381  */
382 typedef struct gss_mech_config {
383         char *kmodName;                 /* kernel module name */
384         char *uLibName;                 /* user library name */
385         char *mechNameStr;              /* mechanism string name */
386         char *optionStr;                /* optional mech parameters */
387         void *dl_handle;                /* RTLD object handle for the mech */
388         gss_OID mech_type;              /* mechanism oid */
389         gss_mechanism mech;             /* mechanism initialization struct */
390         struct gss_mech_config *next;   /* next element in the list */
391 } *gss_mech_info;
392
393 /********************************************************/
394 /* Internal mechglue routines */
395
396 int gssint_mechglue_init(void);
397 void gssint_mechglue_fini(void);
398
399 gss_mechanism gssint_get_mechanism (gss_OID);
400 OM_uint32 gssint_get_mech_type (gss_OID, gss_buffer_t);
401 char *gssint_get_kmodName(const gss_OID);
402 char *gssint_get_modOptions(const gss_OID);
403 OM_uint32 gssint_import_internal_name (OM_uint32 *, gss_OID, gss_union_name_t,
404                                       gss_name_t *);
405 OM_uint32 gssint_export_internal_name(OM_uint32 *, const gss_OID,
406         const gss_name_t, gss_buffer_t);
407 OM_uint32 gssint_display_internal_name (OM_uint32 *, gss_OID, gss_name_t,
408                                        gss_buffer_t, gss_OID *);
409 OM_uint32 gssint_release_internal_name (OM_uint32 *, gss_OID, gss_name_t *);
410
411 OM_uint32 gssint_convert_name_to_union_name
412           (OM_uint32 *,         /* minor_status */
413            gss_mechanism,       /* mech */
414            gss_name_t,          /* internal_name */
415            gss_name_t *         /* external_name */
416            );
417 gss_cred_id_t gssint_get_mechanism_cred
418           (gss_union_cred_t,    /* union_cred */
419            gss_OID              /* mech_type */
420            );
421
422 OM_uint32 gssint_create_copy_buffer(
423         const gss_buffer_t,     /* src buffer */
424         gss_buffer_t *,         /* destination buffer */
425         int                     /* NULL terminate buffer ? */
426 );
427
428 OM_uint32 gssint_copy_oid_set(
429         OM_uint32 *,                    /* minor_status */
430         const gss_OID_set_desc *,       /* oid set */
431         gss_OID_set *                   /* new oid set */
432 );
433
434 gss_OID gss_find_mechanism_from_name_type (gss_OID); /* name_type */
435
436 OM_uint32 gss_add_mech_name_type
437            (OM_uint32 *,        /* minor_status */
438             gss_OID,            /* name_type */
439             gss_OID             /* mech */
440                );
441
442 /*
443  * Sun extensions to GSS-API v2
444  */
445
446 OM_uint32
447 gssint_mech_to_oid(
448         const char *mech,               /* mechanism string name */
449         gss_OID *oid                    /* mechanism oid */
450 );
451
452 const char *
453 gssint_oid_to_mech(
454         const gss_OID oid               /* mechanism oid */
455 );
456
457 OM_uint32
458 gssint_get_mechanisms(
459         char *mechArray[],              /* array to populate with mechs */
460         int arrayLen                    /* length of passed in array */
461 );
462
463 OM_uint32
464 gss_store_cred(
465         OM_uint32 *,            /* minor_status */
466         const gss_cred_id_t,    /* input_cred_handle */
467         gss_cred_usage_t,       /* cred_usage */
468         const gss_OID,          /* desired_mech */
469         OM_uint32,              /* overwrite_cred */
470         OM_uint32,              /* default_cred */
471         gss_OID_set *,          /* elements_stored */
472         gss_cred_usage_t *      /* cred_usage_stored */
473 );
474
475 int
476 gssint_get_der_length(
477         unsigned char **,       /* buf */
478         unsigned int,           /* buf_len */
479         unsigned int *          /* bytes */
480 );
481
482 unsigned int
483 gssint_der_length_size(unsigned int /* len */);
484
485 int
486 gssint_put_der_length(
487         unsigned int,           /* length */
488         unsigned char **,       /* buf */
489         unsigned int            /* max_len */
490 );
491
492 #endif /* _GSS_MECHGLUEP_H */