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