support for lucid export
[mech_eap.git] / util_reauth.c
1 /*
2  * Copyright (c) 2010, JANET(UK)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * 3. Neither the name of JANET(UK) nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32
33 #include "gssapiP_eap.h"
34
35 #include <dlfcn.h>
36
37 /*
38  * Fast reauthentication support for EAP GSS.
39  */
40
41 krb5_error_code
42 krb5_encrypt_tkt_part(krb5_context, const krb5_keyblock *, krb5_ticket *);
43
44 krb5_error_code
45 encode_krb5_ticket(const krb5_ticket *rep, krb5_data **code);
46
47 static OM_uint32
48 gssDisplayName(OM_uint32 *minor,
49                gss_name_t name,
50                gss_buffer_t buffer,
51                gss_OID *name_type);
52
53 static OM_uint32
54 gssImportName(OM_uint32 *minor,
55               gss_buffer_t buffer,
56               gss_OID name_type,
57               gss_name_t *name);
58
59 static krb5_error_code
60 getAcceptorKey(krb5_context krbContext,
61                gss_ctx_id_t ctx,
62                gss_cred_id_t cred,
63                krb5_principal *princ,
64                krb5_keyblock *key)
65 {
66     krb5_error_code code;
67     krb5_keytab keytab = NULL;
68     krb5_keytab_entry ktent = { 0 };
69     krb5_kt_cursor cursor = NULL;
70
71     *princ = NULL;
72     memset(key, 0, sizeof(*key));
73
74     code = krb5_kt_default(krbContext, &keytab);
75     if (code != 0)
76         goto cleanup;
77
78     if (cred != GSS_C_NO_CREDENTIAL && cred->name != GSS_C_NO_NAME) {
79         code = krb5_kt_get_entry(krbContext, keytab,
80                                  cred->name->krbPrincipal, 0,
81                                  ctx->encryptionType, &ktent);
82         if (code != 0)
83             goto cleanup;
84     } else {
85         /*
86          * It's not clear that looking encrypting the ticket in the
87          * requested EAP enctype provides any value.
88          */
89         code = krb5_kt_start_seq_get(krbContext, keytab, &cursor);
90         if (code != 0)
91             goto cleanup;
92
93         while ((code = krb5_kt_next_entry(krbContext, keytab,
94                                           &ktent, &cursor)) == 0) {
95             if (ktent.key.enctype == ctx->encryptionType)
96                 break;
97             else
98                 krb5_free_keytab_entry_contents(krbContext, &ktent);
99         }
100     }
101
102     if (code == 0) {
103         *princ = ktent.principal;
104         *key = ktent.key;
105     }
106
107 cleanup:
108     if (cred == GSS_C_NO_CREDENTIAL || cred->name == GSS_C_NO_NAME)
109         krb5_kt_end_seq_get(krbContext, keytab, &cursor);
110     krb5_kt_close(krbContext, keytab);
111
112     if (code != 0)
113         krb5_free_keytab_entry_contents(krbContext, &ktent);
114
115     return code;
116 }
117
118 static OM_uint32
119 freezeAttrContext(OM_uint32 *minor,
120                   gss_name_t initiatorName,
121                   krb5_const_principal acceptorPrinc,
122                   krb5_keyblock *session,
123                   krb5_authdata ***authdata)
124 {
125     OM_uint32 major, tmpMinor;
126     krb5_error_code code;
127     gss_buffer_desc attrBuf = GSS_C_EMPTY_BUFFER;
128     krb5_authdata *authData[2], authDatum = { 0 };
129     krb5_context krbContext;
130
131     GSSEAP_KRB_INIT(&krbContext);
132
133     major = gssEapExportAttrContext(minor, initiatorName, &attrBuf);
134     if (GSS_ERROR(major))
135         return major;
136
137     authDatum.ad_type = KRB5_AUTHDATA_RADIUS_AVP;
138     authDatum.length = attrBuf.length;
139     authDatum.contents = attrBuf.value;
140     authData[0] = &authDatum;
141     authData[1] = NULL;
142
143     code = krb5_make_authdata_kdc_issued(krbContext, session, acceptorPrinc,
144                                          authData, authdata);
145     if (code != 0) {
146         major = GSS_S_FAILURE;
147         *minor = code;
148     } else {
149         major = GSS_S_COMPLETE;
150     }
151
152     gss_release_buffer(&tmpMinor, &attrBuf);
153
154     return major;
155 }
156
157 /*
158  * Fabricate a ticket to ourselves given a GSS EAP context.
159  */
160 OM_uint32
161 gssEapMakeReauthCreds(OM_uint32 *minor,
162                       gss_ctx_id_t ctx,
163                       gss_cred_id_t cred,
164                       gss_buffer_t credBuf)
165 {
166     OM_uint32 major = GSS_S_COMPLETE;
167     krb5_error_code code;
168     krb5_context krbContext = NULL;
169     krb5_ticket ticket = { 0 };
170     krb5_keyblock session = { 0 }, acceptorKey = { 0 };
171     krb5_enc_tkt_part enc_part = { 0 };
172     krb5_data *ticketData = NULL, *credsData = NULL;
173     krb5_creds creds = { 0 };
174     krb5_auth_context authContext = NULL;
175
176     credBuf->length = 0;
177     credBuf->value = NULL;
178
179     GSSEAP_KRB_INIT(&krbContext);
180
181     code = getAcceptorKey(krbContext, ctx, cred,
182                           &ticket.server, &acceptorKey);
183     if (code == KRB5_KT_NOTFOUND) {
184         gss_buffer_desc emptyToken = { 0, "" };
185
186         /*
187          * If we can't produce the KRB-CRED message, we need to
188          * return an empty (not NULL) token to the caller so we
189          * don't change the number of authentication legs.
190          */
191         return duplicateBuffer(minor, &emptyToken, credBuf);
192     } else if (code != 0)
193         goto cleanup;
194
195     enc_part.flags = TKT_FLG_INITIAL;
196
197     /*
198      * Generate a random session key to place in the ticket and
199      * sign the "KDC-Issued" authorization data element.
200      */
201     code = krb5_c_make_random_key(krbContext, ctx->encryptionType,
202                                   &session);
203     if (code != 0)
204         goto cleanup;
205
206     enc_part.session = &session;
207     enc_part.client = ctx->initiatorName->krbPrincipal;
208     enc_part.times.authtime = time(NULL);
209     enc_part.times.starttime = enc_part.times.authtime;
210     enc_part.times.endtime = ctx->expiryTime
211                              ? ctx->expiryTime
212                              : KRB5_INT32_MAX;
213     enc_part.times.renew_till = 0;
214
215     major = freezeAttrContext(minor, ctx->initiatorName, ticket.server,
216                               &session, &enc_part.authorization_data);
217     if (GSS_ERROR(major))
218         goto cleanup;
219
220     ticket.enc_part2 = &enc_part;
221
222     code = krb5_encrypt_tkt_part(krbContext, &acceptorKey, &ticket);
223     if (code != 0)
224         goto cleanup;
225
226     code = encode_krb5_ticket(&ticket, &ticketData);
227     if (code != 0)
228         goto cleanup;
229
230     creds.client = enc_part.client;
231     creds.server = ticket.server;
232     creds.keyblock = session;
233     creds.times = enc_part.times;
234     creds.ticket_flags = enc_part.flags;
235     creds.ticket = *ticketData;
236     creds.authdata = enc_part.authorization_data;
237
238     code = krb5_auth_con_init(krbContext, &authContext);
239     if (code != 0)
240         goto cleanup;
241
242     code = krb5_auth_con_setflags(krbContext, authContext, 0);
243     if (code != 0)
244         goto cleanup;
245
246     code = krb5_auth_con_setsendsubkey(krbContext, authContext,
247                                        &ctx->rfc3961Key);
248     if (code != 0)
249         goto cleanup;
250
251     code = krb5_mk_1cred(krbContext, authContext, &creds, &credsData, NULL);
252     if (code != 0)
253         goto cleanup;
254
255     krbDataToGssBuffer(credsData, credBuf);
256
257 cleanup:
258     if (ticket.enc_part.ciphertext.data != NULL)
259         GSSEAP_FREE(ticket.enc_part.ciphertext.data);
260     krb5_free_keyblock_contents(krbContext, &session);
261     krb5_free_keyblock_contents(krbContext, &acceptorKey);
262     krb5_free_data(krbContext, ticketData);
263     krb5_auth_con_free(krbContext, authContext);
264     krb5_free_authdata(krbContext, enc_part.authorization_data);
265     if (credsData != NULL)
266         GSSEAP_FREE(credsData);
267
268     if (major == GSS_S_COMPLETE) {
269         *minor = code;
270         major = code != 0 ? GSS_S_FAILURE : GSS_S_COMPLETE;
271     }
272
273     return major;
274 }
275
276 static int
277 isTicketGrantingServiceP(krb5_context krbContext,
278                          krb5_const_principal principal)
279 {
280     if (krb5_princ_size(krbContext, principal) == 2 &&
281         krb5_princ_component(krbContext, principal, 0)->length == 6 &&
282         memcmp(krb5_princ_component(krbContext,
283                                     principal, 0)->data, "krbtgt", 6) == 0)
284         return TRUE;
285
286     return FALSE;
287 }
288
289 /*
290  * Store re-authentication (Kerberos) credentials in a credential handle.
291  */
292 OM_uint32
293 gssEapStoreReauthCreds(OM_uint32 *minor,
294                        gss_ctx_id_t ctx,
295                        gss_cred_id_t cred,
296                        gss_buffer_t credBuf)
297 {
298     OM_uint32 major = GSS_S_COMPLETE, code;
299     krb5_context krbContext = NULL;
300     krb5_auth_context authContext = NULL;
301     krb5_data credData = { 0 };
302     krb5_creds **creds = NULL;
303     krb5_principal canonPrinc;
304     int i;
305
306     if (credBuf->length == 0 || cred == GSS_C_NO_CREDENTIAL)
307         return GSS_S_COMPLETE;
308
309     GSSEAP_KRB_INIT(&krbContext);
310
311     code = krb5_auth_con_init(krbContext, &authContext);
312     if (code != 0)
313         goto cleanup;
314
315     code = krb5_auth_con_setflags(krbContext, authContext, 0);
316     if (code != 0)
317         goto cleanup;
318
319     code = krb5_auth_con_setrecvsubkey(krbContext, authContext,
320                                        &ctx->rfc3961Key);
321     if (code != 0)
322         goto cleanup;
323
324     gssBufferToKrbData(credBuf, &credData);
325
326     code = krb5_rd_cred(krbContext, authContext, &credData, &creds, NULL);
327     if (code != 0)
328         goto cleanup;
329
330     if (creds == NULL || creds[0] == NULL)
331         goto cleanup;
332
333     code = krb5_copy_principal(krbContext, creds[0]->client, &canonPrinc);
334     if (code != 0)
335         goto cleanup;
336
337     krb5_free_principal(krbContext, cred->name->krbPrincipal);
338     cred->name->krbPrincipal = canonPrinc;
339
340     cred->expiryTime = creds[0]->times.endtime;
341
342     code = krb5_cc_new_unique(krbContext, "MEMORY", NULL, &cred->krbCredCache);
343     if (code != 0)
344         goto cleanup;
345
346     code = krb5_cc_initialize(krbContext, cred->krbCredCache,
347                               creds[0]->client);
348     if (code != 0)
349         goto cleanup;
350
351     for (i = 0; creds[i] != NULL; i++) {
352         krb5_creds kcred = *(creds[i]);
353
354         /*
355          * Swap in the acceptor name the client asked for so
356          * get_credentials() works. We're making the assumption that
357          * any service tickets returned are for us. We'll need to
358          * reflect some more on whether that is a safe assumption.
359          */
360         if (!isTicketGrantingServiceP(krbContext, kcred.server))
361             kcred.server = ctx->acceptorName->krbPrincipal;
362
363         code = krb5_cc_store_cred(krbContext, cred->krbCredCache, &kcred);
364         if (code != 0)
365             goto cleanup;
366     }
367
368 #ifdef HAVE_GSS_KRB5_IMPORT_CRED
369     /*
370      * To turn a credentials cache into a GSS credentials handle, we
371      * require the gss_krb5_import_cred() API (present in Heimdal, but
372      * not shipped in MIT yet).
373      */
374     major = gss_krb5_import_cred(minor, cred->krbCredCache, NULL, NULL,
375                                  &cred->krbCred);
376     if (GSS_ERROR(major))
377         goto cleanup;
378 #else
379 #warning Missing gss_krb5_import_cred() implementation
380 #endif
381
382 cleanup:
383     *minor = code;
384
385     krb5_auth_con_free(krbContext, authContext);
386     if (creds != NULL) {
387         for (i = 0; creds[i] != NULL; i++)
388             krb5_free_creds(krbContext, creds[i]);
389         GSSEAP_FREE(creds);
390     }
391     if (major == GSS_S_COMPLETE)
392         major = *minor ? GSS_S_FAILURE : GSS_S_COMPLETE;
393
394     return major;
395 }
396
397 static gss_buffer_desc radiusAvpKrbAttr = {
398     sizeof("urn:authdata-radius-avp") - 1, "urn:authdata-radius-avp"
399 };
400
401 /*
402  * Unfortunately extracting an AD-KDCIssued authorization data element
403  * is pretty implementation-dependent. It's not possible to verify the
404  * signature ourselves because the ticket session key is not exposed
405  * outside GSS. In an ideal world, all AD-KDCIssued elements would be
406  * verified by the Kerberos library and authentication would fail if
407  * verification failed. We're not quite there yet and as a result have
408  * to go through some hoops to get this to work. The alternative would
409  * be to sign the authorization data with our long-term key, but it
410  * seems a pity to compromise the design because of current implementation
411  * limitations.
412  *
413  * (Specifically, the hoops involve a libkrb5 authorisation data plugin
414  * that exposes the verified and serialised attribute context through
415  * the Kerberos GSS mechanism's naming extensions API.)
416  */
417 static OM_uint32
418 defrostAttrContext(OM_uint32 *minor,
419                    gss_name_t glueName,
420                    gss_name_t mechName)
421 {
422     OM_uint32 major, tmpMinor;
423     gss_buffer_desc authData = GSS_C_EMPTY_BUFFER;
424     gss_buffer_desc authDataDisplay = GSS_C_EMPTY_BUFFER;
425     int more = -1;
426     int authenticated, complete;
427
428     major = gssGetNameAttribute(minor, glueName, &radiusAvpKrbAttr,
429                                 &authenticated, &complete,
430                                 &authData, &authDataDisplay, &more);
431     if (major == GSS_S_COMPLETE) {
432         if (authenticated == 0)
433             major = GSS_S_BAD_NAME;
434         else
435             major = gssEapImportAttrContext(minor, &authData, mechName);
436     } else if (major == GSS_S_UNAVAILABLE) {
437         major = GSS_S_COMPLETE;
438     }
439
440     gss_release_buffer(&tmpMinor, &authData);
441     gss_release_buffer(&tmpMinor, &authDataDisplay);
442
443     return major;
444 }
445
446 /*
447  * Convert a mechanism glue to an EAP mechanism name by displaying and
448  * importing it. This also handles the RADIUS attributes.
449  */
450 OM_uint32
451 gssEapGlueToMechName(OM_uint32 *minor,
452                      gss_name_t glueName,
453                      gss_name_t *pMechName)
454 {
455     OM_uint32 major, tmpMinor;
456     gss_buffer_desc nameBuf = GSS_C_EMPTY_BUFFER;
457
458     *pMechName = GSS_C_NO_NAME;
459
460     major = gssDisplayName(minor, glueName, &nameBuf, NULL);
461     if (GSS_ERROR(major))
462         goto cleanup;
463
464     major = gssEapImportName(minor, &nameBuf, GSS_C_NT_USER_NAME,
465                              pMechName);
466     if (GSS_ERROR(major))
467         goto cleanup;
468
469     major = defrostAttrContext(minor, glueName, *pMechName);
470     if (GSS_ERROR(major))
471         goto cleanup;
472
473 cleanup:
474     if (GSS_ERROR(major)) {
475         gssReleaseName(&tmpMinor, pMechName);
476         *pMechName = GSS_C_NO_NAME;
477     }
478
479     gss_release_buffer(&tmpMinor, &nameBuf);
480
481     return major;
482 }
483
484 /*
485  * Convert an EAP mechanism name to a mechanism glue name by displaying
486  * and importing it.
487  */
488 OM_uint32
489 gssEapMechToGlueName(OM_uint32 *minor,
490                      gss_name_t mechName,
491                      gss_name_t *pGlueName)
492 {
493     OM_uint32 major, tmpMinor;
494     gss_buffer_desc nameBuf = GSS_C_EMPTY_BUFFER;
495
496     *pGlueName = GSS_C_NO_NAME;
497
498     major = gssEapDisplayName(minor, mechName, &nameBuf, NULL);
499     if (GSS_ERROR(major))
500         goto cleanup;
501
502     major = gssImportName(minor, &nameBuf, GSS_C_NT_USER_NAME,
503                           pGlueName);
504     if (GSS_ERROR(major))
505         goto cleanup;
506
507 cleanup:
508     gss_release_buffer(&tmpMinor, &nameBuf);
509
510     return major;
511 }
512
513 /*
514  * Suck out the analgous elements of a Kerberos GSS context into an EAP
515  * one so that the application doesn't know the difference.
516  */
517 OM_uint32
518 gssEapReauthComplete(OM_uint32 *minor,
519                     gss_ctx_id_t ctx,
520                     gss_cred_id_t cred,
521                     const gss_OID mech,
522                     OM_uint32 timeRec)
523 {
524     OM_uint32 major, tmpMinor;
525     gss_buffer_set_t keyData = GSS_C_NO_BUFFER_SET;
526
527     if (!oidEqual(mech, gss_mech_krb5)) {
528         major = GSS_S_BAD_MECH;
529         goto cleanup;
530     }
531
532     /* Get the raw subsession key and encryption type*/
533     major = gssInquireSecContextByOid(minor, ctx->kerberosCtx,
534                                       GSS_C_INQ_SSPI_SESSION_KEY, &keyData);
535     if (GSS_ERROR(major))
536         goto cleanup;
537
538     {
539         gss_OID_desc oid;
540         int suffix;
541
542         oid.length = keyData->elements[1].length;
543         oid.elements = keyData->elements[1].value;
544
545         /* GSS_KRB5_SESSION_KEY_ENCTYPE_OID */
546         major = decomposeOid(minor,
547                              "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x04",
548                              10, &oid, &suffix);
549         if (GSS_ERROR(major))
550             goto cleanup;
551
552         ctx->encryptionType = suffix;
553     }
554
555     {
556         krb5_context krbContext = NULL;
557         krb5_keyblock key;
558
559         GSSEAP_KRB_INIT(&krbContext);
560
561         KRB_KEY_LENGTH(&key) = keyData->elements[0].length;
562         KRB_KEY_DATA(&key)   = keyData->elements[0].value;
563         KRB_KEY_TYPE(&key)   = ctx->encryptionType;
564
565         *minor = krb5_copy_keyblock_contents(krbContext,
566                                              &key, &ctx->rfc3961Key);
567         if (*minor != 0) {
568             major = GSS_S_FAILURE;
569             goto cleanup;
570         }
571     }
572
573     major = rfc3961ChecksumTypeForKey(minor, &ctx->rfc3961Key,
574                                       &ctx->checksumType);
575     if (GSS_ERROR(major))
576         goto cleanup;
577
578     if (timeRec != GSS_C_INDEFINITE)
579         ctx->expiryTime = time(NULL) + timeRec;
580
581     /* Initialize our sequence state */
582     major = sequenceInit(minor,
583                          &ctx->seqState, ctx->recvSeq,
584                          ((ctx->gssFlags & GSS_C_REPLAY_FLAG) != 0),
585                          ((ctx->gssFlags & GSS_C_SEQUENCE_FLAG) != 0),
586                          TRUE);
587     if (GSS_ERROR(major))
588         goto cleanup;
589
590     major = GSS_S_COMPLETE;
591
592 cleanup:
593     gss_release_buffer_set(&tmpMinor, &keyData);
594
595     return major;
596 }
597
598 /*
599  * The remainder of this file consists of wrappers so we can call into the
600  * mechanism glue without calling ourselves.
601  */
602 static OM_uint32
603 (*gssInitSecContextNext)(OM_uint32 *,
604                          gss_cred_id_t,
605                          gss_ctx_id_t *,
606                          gss_name_t,
607                          gss_OID,
608                          OM_uint32,
609                          OM_uint32,
610                          gss_channel_bindings_t,
611                          gss_buffer_t,
612                          gss_OID *,
613                          gss_buffer_t,
614                          OM_uint32 *,
615                          OM_uint32 *);
616
617 static OM_uint32
618 (*gssAcceptSecContextNext)(OM_uint32 *,
619                            gss_ctx_id_t *,
620                            gss_cred_id_t,
621                            gss_buffer_t,
622                            gss_channel_bindings_t,
623                            gss_name_t *,
624                            gss_OID *,
625                            gss_buffer_t,
626                            OM_uint32 *,
627                            OM_uint32 *,
628                            gss_cred_id_t *);
629
630 static OM_uint32
631 (*gssReleaseCredNext)(OM_uint32 *, gss_cred_id_t *);
632
633 static OM_uint32
634 (*gssReleaseNameNext)(OM_uint32 *, gss_name_t *);
635
636 static OM_uint32
637 (*gssInquireSecContextByOidNext)(OM_uint32 *,
638                                  const gss_ctx_id_t,
639                                  const gss_OID,
640                                  gss_buffer_set_t *);
641
642 static OM_uint32
643 (*gssDeleteSecContextNext)(OM_uint32 *,
644                           gss_ctx_id_t *,
645                           gss_buffer_t);
646
647 static OM_uint32
648 (*gssDisplayNameNext)(OM_uint32 *,
649                       gss_name_t,
650                       gss_buffer_t,
651                       gss_OID *);
652
653 static OM_uint32
654 (*gssImportNameNext)(OM_uint32 *,
655                      gss_buffer_t,
656                      gss_OID,
657                      gss_name_t *);
658
659 static OM_uint32
660 (*gssStoreCredNext)(OM_uint32 *,
661                     const gss_cred_id_t,
662                     gss_cred_usage_t,
663                     const gss_OID,
664                     OM_uint32,
665                     OM_uint32,
666                     gss_OID_set *,
667                     gss_cred_usage_t *);
668
669 static OM_uint32
670 (*gssGetNameAttributeNext)(OM_uint32 *,
671                           gss_name_t,
672                           gss_buffer_t,
673                           int *,
674                           int *,
675                           gss_buffer_t,
676                           gss_buffer_t,
677                           int *);
678
679 #define NEXT_SYMBOL(local, global)  ((local) = dlsym(RTLD_NEXT, (global)))
680
681 OM_uint32
682 gssEapReauthInitialize(OM_uint32 *minor)
683 {
684     NEXT_SYMBOL(gssInitSecContextNext,         "gss_init_sec_context");
685     NEXT_SYMBOL(gssAcceptSecContextNext,       "gss_accept_sec_context");
686     NEXT_SYMBOL(gssReleaseCredNext,            "gss_release_cred");
687     NEXT_SYMBOL(gssReleaseNameNext,            "gss_release_name");
688     NEXT_SYMBOL(gssInquireSecContextByOidNext, "gss_inquire_sec_context_by_oid");
689     NEXT_SYMBOL(gssDeleteSecContextNext,       "gss_delete_sec_context");
690     NEXT_SYMBOL(gssDisplayNameNext,            "gss_display_name");
691     NEXT_SYMBOL(gssImportNameNext,             "gss_import_name");
692     NEXT_SYMBOL(gssStoreCredNext,              "gss_store_cred");
693     NEXT_SYMBOL(gssGetNameAttributeNext,       "gss_get_name_attribute");
694
695     return GSS_S_COMPLETE;
696 }
697
698 OM_uint32
699 gssInitSecContext(OM_uint32 *minor,
700                   gss_cred_id_t cred,
701                   gss_ctx_id_t *context_handle,
702                   gss_name_t target_name,
703                   gss_OID mech_type,
704                   OM_uint32 req_flags,
705                   OM_uint32 time_req,
706                   gss_channel_bindings_t input_chan_bindings,
707                   gss_buffer_t input_token,
708                   gss_OID *actual_mech_type,
709                   gss_buffer_t output_token,
710                   OM_uint32 *ret_flags,
711                   OM_uint32 *time_rec)
712 {
713     if (gssInitSecContextNext == NULL)
714         return GSS_S_UNAVAILABLE;
715
716     return gssInitSecContextNext(minor, cred, context_handle,
717                                  target_name, mech_type, req_flags,
718                                  time_req, input_chan_bindings,
719                                  input_token, actual_mech_type,
720                                  output_token, ret_flags, time_rec);
721 }
722
723 OM_uint32
724 gssAcceptSecContext(OM_uint32 *minor,
725                     gss_ctx_id_t *context_handle,
726                     gss_cred_id_t cred,
727                     gss_buffer_t input_token,
728                     gss_channel_bindings_t input_chan_bindings,
729                     gss_name_t *src_name,
730                     gss_OID *mech_type,
731                     gss_buffer_t output_token,
732                     OM_uint32 *ret_flags,
733                     OM_uint32 *time_rec,
734                     gss_cred_id_t *delegated_cred_handle)
735 {
736     if (gssAcceptSecContextNext == NULL)
737         return GSS_S_UNAVAILABLE;
738
739     return gssAcceptSecContextNext(minor, context_handle, cred,
740                                    input_token, input_chan_bindings,
741                                    src_name, mech_type, output_token,
742                                    ret_flags, time_rec, delegated_cred_handle);
743 }
744
745 OM_uint32
746 gssReleaseCred(OM_uint32 *minor,
747                gss_cred_id_t *cred_handle)
748 {
749     if (gssReleaseCredNext == NULL)
750         return GSS_S_UNAVAILABLE;
751
752     return gssReleaseCredNext(minor, cred_handle);
753 }
754
755 OM_uint32
756 gssReleaseName(OM_uint32 *minor,
757                gss_name_t *name)
758 {
759     if (gssReleaseName == NULL)
760         return GSS_S_UNAVAILABLE;
761
762     return gssReleaseNameNext(minor, name);
763 }
764
765 OM_uint32
766 gssDeleteSecContext(OM_uint32 *minor,
767                     gss_ctx_id_t *context_handle,
768                     gss_buffer_t output_token)
769 {
770     if (gssDeleteSecContextNext == NULL)
771         return GSS_S_UNAVAILABLE;
772
773     return gssDeleteSecContextNext(minor, context_handle, output_token);
774 }
775
776 static OM_uint32
777 gssDisplayName(OM_uint32 *minor,
778                gss_name_t name,
779                gss_buffer_t buffer,
780                gss_OID *name_type)
781 {
782     if (gssDisplayNameNext == NULL)
783         return GSS_S_UNAVAILABLE;
784
785     return gssDisplayNameNext(minor, name, buffer, name_type);
786 }
787
788 static OM_uint32
789 gssImportName(OM_uint32 *minor,
790               gss_buffer_t buffer,
791               gss_OID name_type,
792               gss_name_t *name)
793 {
794     if (gssImportNameNext == NULL)
795         return GSS_S_UNAVAILABLE;
796
797     return gssImportNameNext(minor, buffer, name_type, name);
798 }
799
800 OM_uint32
801 gssInquireSecContextByOid(OM_uint32 *minor,
802                           const gss_ctx_id_t context_handle,
803                           const gss_OID desired_object,
804                           gss_buffer_set_t *data_set)
805 {
806     if (gssInquireSecContextByOidNext == NULL)
807         return GSS_S_UNAVAILABLE;
808
809     return gssInquireSecContextByOidNext(minor, context_handle,
810                                          desired_object, data_set);
811 }
812
813 OM_uint32
814 gssStoreCred(OM_uint32 *minor,
815              const gss_cred_id_t input_cred_handle,
816              gss_cred_usage_t input_usage,
817              const gss_OID desired_mech,
818              OM_uint32 overwrite_cred,
819              OM_uint32 default_cred,
820              gss_OID_set *elements_stored,
821              gss_cred_usage_t *cred_usage_stored)
822 {
823     if (gssStoreCredNext == NULL)
824         return GSS_S_UNAVAILABLE;
825
826     return gssStoreCredNext(minor, input_cred_handle, input_usage,
827                             desired_mech, overwrite_cred, default_cred,
828                             elements_stored, cred_usage_stored);
829 }
830
831 OM_uint32
832 gssGetNameAttribute(OM_uint32 *minor,
833                     gss_name_t name,
834                     gss_buffer_t attr,
835                     int *authenticated,
836                     int *complete,
837                     gss_buffer_t value,
838                     gss_buffer_t display_value,
839                     int *more)
840 {
841     if (gssGetNameAttributeNext == NULL)
842         return GSS_S_UNAVAILABLE;
843
844     return gssGetNameAttributeNext(minor, name, attr, authenticated, complete,
845                                    value, display_value, more);
846 }