934aa5fab0c6e133f63b002ce5addd953f04caf1
[mech_eap.orig] / util_radius.cpp
1 /*
2  * Copyright (c) 2011, 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 /*
34  * RADIUS attribute provider implementation.
35  */
36
37 #include "gssapiP_eap.h"
38
39 /* stuff that should be provided by libradsec/libfreeradius-radius */
40 #define VENDORATTR(vendor, attr)            (((vendor) << 16) | (attr))
41
42 #ifndef ATTRID
43 #define ATTRID(attr)                        ((attr) & 0xFFFF)
44 #endif
45
46 static gss_buffer_desc radiusUrnPrefix = {
47     sizeof("urn:x-radius:") - 1,
48     (void *)"urn:x-radius:"
49 };
50
51 static VALUE_PAIR *copyAvps(const VALUE_PAIR *src);
52
53 gss_eap_radius_attr_provider::gss_eap_radius_attr_provider(void)
54 {
55     m_vps = NULL;
56     m_authenticated = false;
57 }
58
59 gss_eap_radius_attr_provider::~gss_eap_radius_attr_provider(void)
60 {
61     if (m_vps != NULL)
62         pairfree(&m_vps);
63 }
64
65 bool
66 gss_eap_radius_attr_provider::initFromExistingContext(const gss_eap_attr_ctx *manager,
67                                                       const gss_eap_attr_provider *ctx)
68 {
69     const gss_eap_radius_attr_provider *radius;
70
71     if (!gss_eap_attr_provider::initFromExistingContext(manager, ctx))
72         return false;
73
74     radius = static_cast<const gss_eap_radius_attr_provider *>(ctx);
75
76     if (radius->m_vps != NULL)
77         m_vps = copyAvps(const_cast<VALUE_PAIR *>(radius->getAvps()));
78
79     m_authenticated = radius->m_authenticated;
80
81     return true;
82 }
83
84 bool
85 gss_eap_radius_attr_provider::initFromGssContext(const gss_eap_attr_ctx *manager,
86                                                  const gss_cred_id_t gssCred,
87                                                  const gss_ctx_id_t gssCtx)
88 {
89     if (!gss_eap_attr_provider::initFromGssContext(manager, gssCred, gssCtx))
90         return false;
91
92     if (gssCtx != GSS_C_NO_CONTEXT) {
93         if (gssCtx->acceptorCtx.vps != NULL) {
94             m_vps = copyAvps(gssCtx->acceptorCtx.vps);
95             if (m_vps == NULL)
96                 return false;
97
98             /* We assume libradsec validated this for us */
99             assert(pairfind(m_vps, PW_MESSAGE_AUTHENTICATOR) != NULL);
100             m_authenticated = true;
101         }
102     }
103
104     return true;
105 }
106
107 static bool
108 alreadyAddedAttributeP(std::vector <std::string> &attrs, VALUE_PAIR *vp)
109 {
110     for (std::vector<std::string>::const_iterator a = attrs.begin();
111          a != attrs.end();
112          ++a) {
113         if (strcmp(vp->name, (*a).c_str()) == 0)
114             return true;
115     }
116
117     return false;
118 }
119
120 static bool
121 isSecretAttributeP(uint16_t attrid, uint16_t vendor)
122 {
123     bool bSecretAttribute = false;
124
125     switch (vendor) {
126     case VENDORPEC_MS:
127         switch (attrid) {
128         case PW_MS_MPPE_SEND_KEY:
129         case PW_MS_MPPE_RECV_KEY:
130             bSecretAttribute = true;
131             break;
132         default:
133             break;
134         }
135     default:
136         break;
137     }
138
139     return bSecretAttribute;
140 }
141
142 static bool
143 isSecretAttributeP(uint32_t attribute)
144 {
145     return isSecretAttributeP(ATTRID(attribute), VENDOR(attribute));
146 }
147
148 static bool
149 isInternalAttributeP(uint16_t attrid, uint16_t vendor)
150 {
151     bool bInternalAttribute = false;
152
153     /* should have been filtered */
154     assert(!isSecretAttributeP(attrid, vendor));
155
156     switch (vendor) {
157     case VENDORPEC_UKERNA:
158         bInternalAttribute = true;
159         break;
160     default:
161         break;
162     }
163
164     return bInternalAttribute;
165 }
166
167 static bool
168 isInternalAttributeP(uint32_t attribute)
169 {
170     return isInternalAttributeP(ATTRID(attribute), VENDOR(attribute));
171 }
172
173 /*
174  * Copy AVP list, same as paircopy except it filters out attributes
175  * containing keys.
176  */
177 static VALUE_PAIR *
178 copyAvps(const VALUE_PAIR *src)
179 {
180     const VALUE_PAIR *vp;
181     VALUE_PAIR *dst = NULL, **pDst = &dst;
182
183     for (vp = src; vp != NULL; vp = vp->next) {
184         VALUE_PAIR *vpcopy;
185
186         if (isSecretAttributeP(vp->attribute))
187             continue;
188
189         vpcopy = paircopyvp(vp);
190         if (vpcopy == NULL) {
191             pairfree(&dst);
192             throw new std::bad_alloc;
193             return NULL;
194         }
195         *pDst = vpcopy;
196         pDst = &vpcopy->next;
197      }
198
199     return dst;
200 }
201
202 bool
203 gss_eap_radius_attr_provider::getAttributeTypes(gss_eap_attr_enumeration_cb addAttribute,
204                                                 void *data) const
205 {
206     VALUE_PAIR *vp;
207     std::vector <std::string> seen;
208
209     for (vp = m_vps; vp != NULL; vp = vp->next) {
210         gss_buffer_desc attribute;
211         char attrid[64];
212
213         /* Don't advertise attributes that are internal to the GSS-EAP mechanism */
214         if (isInternalAttributeP(vp->attribute))
215             continue;
216
217         if (alreadyAddedAttributeP(seen, vp))
218             continue;
219
220         snprintf(attrid, sizeof(attrid), "%s%d",
221             (char *)radiusUrnPrefix.value, vp->attribute);
222
223         attribute.value = attrid;
224         attribute.length = strlen(attrid);
225
226         if (!addAttribute(m_manager, this, &attribute, data))
227             return false;
228
229         seen.push_back(std::string(vp->name));
230     }
231
232     return true;
233 }
234
235 uint32_t
236 getAttributeId(const gss_buffer_t attr)
237 {
238     OM_uint32 tmpMinor;
239     gss_buffer_desc strAttr = GSS_C_EMPTY_BUFFER;
240     DICT_ATTR *da;
241     char *s;
242     uint32_t attrid = 0;
243
244     if (attr->length < radiusUrnPrefix.length ||
245         memcmp(attr->value, radiusUrnPrefix.value, radiusUrnPrefix.length) != 0)
246         return 0;
247
248     /* need to duplicate because attr may not be NUL terminated */
249     duplicateBuffer(*attr, &strAttr);
250     s = (char *)strAttr.value + radiusUrnPrefix.length;
251
252     if (isdigit(*s)) {
253         attrid = strtoul(s, NULL, 10);
254     } else {
255         da = dict_attrbyname(s);
256         if (da != NULL)
257             attrid = da->attr;
258     }
259
260     gss_release_buffer(&tmpMinor, &strAttr);
261
262     return attrid;
263 }
264
265 bool
266 gss_eap_radius_attr_provider::setAttribute(int complete GSSEAP_UNUSED,
267                                            uint32_t attrid,
268                                            const gss_buffer_t value)
269 {
270     OM_uint32 major = GSS_S_UNAVAILABLE, minor;
271
272     if (!isSecretAttributeP(attrid) &&
273         !isInternalAttributeP(attrid)) {
274         deleteAttribute(attrid);
275
276         major = gssEapRadiusAddAvp(&minor, &m_vps,
277                                    ATTRID(attrid), VENDOR(attrid), 
278                                    value);
279     }
280
281     return !GSS_ERROR(major);
282 }
283
284 bool
285 gss_eap_radius_attr_provider::setAttribute(int complete,
286                                            const gss_buffer_t attr,
287                                            const gss_buffer_t value)
288 {
289     uint32_t attrid = getAttributeId(attr);
290
291     if (!attrid)
292         return false;
293
294     return setAttribute(complete, attrid, value);
295 }
296
297 bool
298 gss_eap_radius_attr_provider::deleteAttribute(uint32_t attrid)
299 {
300     if (isSecretAttributeP(attrid) || isInternalAttributeP(attrid) ||
301         pairfind(m_vps, attrid) == NULL)
302         return false;
303
304     pairdelete(&m_vps, attrid);
305
306     return true;
307 }
308
309 bool
310 gss_eap_radius_attr_provider::deleteAttribute(const gss_buffer_t attr)
311 {
312     uint32_t attrid = getAttributeId(attr);
313
314     if (!attrid)
315         return false;
316
317     return deleteAttribute(attrid);
318 }
319
320 bool
321 gss_eap_radius_attr_provider::getAttribute(const gss_buffer_t attr,
322                                            int *authenticated,
323                                            int *complete,
324                                            gss_buffer_t value,
325                                            gss_buffer_t display_value,
326                                            int *more) const
327 {
328     uint32_t attrid;
329
330     attrid = getAttributeId(attr);
331     if (!attrid)
332         return false;
333
334     return getAttribute(attrid, authenticated, complete,
335                         value, display_value, more);
336 }
337
338 bool
339 gss_eap_radius_attr_provider::getAttribute(uint32_t attrid,
340                                            int *authenticated,
341                                            int *complete,
342                                            gss_buffer_t value,
343                                            gss_buffer_t display_value,
344                                            int *more) const
345 {
346     VALUE_PAIR *vp;
347     int i = *more, count = 0;
348
349     *more = 0;
350
351     if (i == -1)
352         i = 0;
353
354     for (vp = pairfind(m_vps, attrid);
355          vp != NULL;
356          vp = pairfind(vp->next, attrid)) {
357         if (count++ == i) {
358             if (pairfind(vp->next, attrid) != NULL)
359                 *more = count;
360             break;
361         }
362     }
363
364     if (vp == NULL && *more == 0)
365         return false;
366
367     if (value != GSS_C_NO_BUFFER) {
368         gss_buffer_desc valueBuf;
369
370         valueBuf.value = (void *)vp->vp_octets;
371         valueBuf.length = vp->length;
372
373         duplicateBuffer(valueBuf, value);
374     }
375
376     if (display_value != GSS_C_NO_BUFFER) {
377         char displayString[MAX_STRING_LEN];
378         gss_buffer_desc displayBuf;
379
380         displayBuf.length = vp_prints_value(displayString,
381                                             sizeof(displayString), vp, 0);
382         displayBuf.value = (void *)displayString;
383
384         duplicateBuffer(displayBuf, display_value);
385     }
386
387     if (authenticated != NULL)
388         *authenticated = m_authenticated;
389     if (complete != NULL)
390         *complete = true;
391
392     return true;
393 }
394
395 bool
396 gss_eap_radius_attr_provider::getFragmentedAttribute(uint16_t attribute,
397                                                      uint16_t vendor,
398                                                      int *authenticated,
399                                                      int *complete,
400                                                      gss_buffer_t value) const
401 {
402     OM_uint32 major, minor;
403
404     major = gssEapRadiusGetAvp(&minor, m_vps, attribute, vendor, value, TRUE);
405
406     if (authenticated != NULL)
407         *authenticated = m_authenticated;
408     if (complete != NULL)
409         *complete = true;
410
411     return !GSS_ERROR(major);
412 }
413
414 bool
415 gss_eap_radius_attr_provider::getAttribute(uint16_t attribute,
416                                            uint16_t vendor,
417                                            int *authenticated,
418                                            int *complete,
419                                            gss_buffer_t value,
420                                            gss_buffer_t display_value,
421                                            int *more) const
422 {
423
424     return getAttribute(VENDORATTR(attribute, vendor),
425                         authenticated, complete,
426                         value, display_value, more);
427 }
428
429 gss_any_t
430 gss_eap_radius_attr_provider::mapToAny(int authenticated,
431                                        gss_buffer_t type_id GSSEAP_UNUSED) const
432 {
433     if (authenticated && !m_authenticated)
434         return (gss_any_t)NULL;
435
436     return (gss_any_t)copyAvps(m_vps);
437 }
438
439 void
440 gss_eap_radius_attr_provider::releaseAnyNameMapping(gss_buffer_t type_id GSSEAP_UNUSED,
441                                                     gss_any_t input) const
442 {
443     VALUE_PAIR *vp = (VALUE_PAIR *)input;
444     pairfree(&vp);
445 }
446
447 bool
448 gss_eap_radius_attr_provider::init(void)
449 {
450     struct rs_context *radContext;
451
452     gss_eap_attr_ctx::registerProvider(ATTR_TYPE_RADIUS, createAttrContext);
453
454 #if 1
455     /*
456      * This hack is necessary in order to force the loading of the global
457      * dictionary, otherwise accepting reauthentication tokens fails unless
458      * the acceptor has already accepted a normal authentication token.
459      */
460     if (rs_context_create(&radContext) != 0)
461         return false;
462
463     if (rs_context_read_config(radContext, RS_CONFIG_FILE) != 0) {
464         rs_context_destroy(radContext);
465         return false;
466     }
467
468     if (rs_context_init_freeradius_dict(radContext, NULL)) {
469         rs_context_destroy(radContext);
470         return false;
471     }
472
473     rs_context_destroy(radContext);
474 #endif
475
476     return true;
477 }
478
479 void
480 gss_eap_radius_attr_provider::finalize(void)
481 {
482     gss_eap_attr_ctx::unregisterProvider(ATTR_TYPE_RADIUS);
483 }
484
485 gss_eap_attr_provider *
486 gss_eap_radius_attr_provider::createAttrContext(void)
487 {
488     return new gss_eap_radius_attr_provider;
489 }
490
491 OM_uint32
492 gssEapRadiusAddAvp(OM_uint32 *minor,
493                    VALUE_PAIR **vps,
494                    uint16_t attribute,
495                    uint16_t vendor,
496                    const gss_buffer_t buffer)
497 {
498     uint32_t attrid = VENDORATTR(vendor, attribute);
499     unsigned char *p = (unsigned char *)buffer->value;
500     size_t remain = buffer->length;
501
502     do {
503         VALUE_PAIR *vp;
504         size_t n = remain;
505
506         /*
507          * There's an extra byte of padding; RADIUS AVPs can only
508          * be 253 octets.
509          */
510         if (n >= MAX_STRING_LEN)
511             n = MAX_STRING_LEN - 1;
512
513         vp = paircreate(attrid, PW_TYPE_OCTETS);
514         if (vp == NULL) {
515             *minor = ENOMEM;
516             return GSS_S_FAILURE;
517         }
518
519         memcpy(vp->vp_octets, p, n);
520         vp->length = n;
521
522         pairadd(vps, vp);
523
524         p += n;
525         remain -= n;
526     } while (remain != 0);
527
528     return GSS_S_COMPLETE;
529 }
530
531 OM_uint32
532 gssEapRadiusGetRawAvp(OM_uint32 *minor,
533                       VALUE_PAIR *vps,
534                       uint16_t attribute,
535                       uint16_t vendor,
536                       VALUE_PAIR **vp)
537 {
538     uint32_t attr = VENDORATTR(vendor, attribute);
539
540     *vp = pairfind(vps, attr);
541     if (*vp == NULL) {
542         *minor = GSSEAP_NO_SUCH_ATTR;
543         return GSS_S_UNAVAILABLE;
544     }
545
546     return GSS_S_COMPLETE;
547 }
548
549 OM_uint32
550 gssEapRadiusGetAvp(OM_uint32 *minor,
551                    VALUE_PAIR *vps,
552                    uint16_t attribute,
553                    uint16_t vendor,
554                    gss_buffer_t buffer,
555                    int concat)
556 {
557     VALUE_PAIR *vp;
558     unsigned char *p;
559     uint32_t attr = VENDORATTR(vendor, attribute);
560
561     buffer->length = 0;
562     buffer->value = NULL;
563
564     vp = pairfind(vps, attr);
565     if (vp == NULL) {
566         *minor = GSSEAP_NO_SUCH_ATTR;
567         return GSS_S_UNAVAILABLE;
568     }
569
570     do {
571         buffer->length += vp->length;
572     } while (concat && (vp = pairfind(vp->next, attr)) != NULL);
573
574     buffer->value = GSSEAP_MALLOC(buffer->length);
575     if (buffer->value == NULL) {
576         *minor = ENOMEM;
577         return GSS_S_FAILURE;
578     }
579
580     p = (unsigned char *)buffer->value;
581
582     for (vp = pairfind(vps, attr);
583          concat && vp != NULL;
584          vp = pairfind(vp->next, attr)) {
585         memcpy(p, vp->vp_octets, vp->length);
586         p += vp->length;
587     }
588
589     *minor = 0;
590     return GSS_S_COMPLETE;
591 }
592
593 OM_uint32
594 gssEapRadiusFreeAvps(OM_uint32 *minor,
595                      VALUE_PAIR **vps)
596 {
597     pairfree(vps);
598     *minor = 0;
599     return GSS_S_COMPLETE;
600 }
601
602 OM_uint32
603 gssEapRadiusAttrProviderInit(OM_uint32 *minor)
604 {
605     if (!gss_eap_radius_attr_provider::init()) {
606         *minor = GSSEAP_RADSEC_INIT_FAILURE;
607         return GSS_S_FAILURE;
608     }
609
610     return GSS_S_COMPLETE;
611 }
612
613 OM_uint32
614 gssEapRadiusAttrProviderFinalize(OM_uint32 *minor)
615 {
616     gss_eap_radius_attr_provider::finalize();
617
618     *minor = 0;
619     return GSS_S_COMPLETE;
620 }
621
622 /*
623  * Encoding is:
624  * 4 octet NBO attribute ID | 4 octet attribute length | attribute data
625  */
626 static size_t
627 avpSize(const VALUE_PAIR *vp)
628 {
629     size_t size = 4 + 1;
630
631     if (vp != NULL)
632         size += vp->length;
633
634     return size;
635 }
636
637 static bool
638 avpExport(const VALUE_PAIR *vp,
639           unsigned char **pBuffer,
640           size_t *pRemain)
641 {
642     unsigned char *p = *pBuffer;
643     size_t remain = *pRemain;
644
645     assert(remain >= avpSize(vp));
646
647     store_uint32_be(vp->attribute, p);
648
649     switch (vp->type) {
650     case PW_TYPE_INTEGER:
651     case PW_TYPE_IPADDR:
652     case PW_TYPE_DATE:
653         p[4] = 4;
654         store_uint32_be(vp->lvalue, p + 5);
655         break;
656     default:
657         assert(vp->length <= MAX_STRING_LEN);
658         p[4] = (uint8_t)vp->length;
659         memcpy(p + 5, vp->vp_octets, vp->length);
660         break;
661     }
662
663     *pBuffer += 5 + p[4];
664     *pRemain -= 5 + p[4];
665
666     return true;
667
668 }
669
670 static bool
671 avpImport(VALUE_PAIR **pVp,
672           unsigned char **pBuffer,
673           size_t *pRemain)
674 {
675     unsigned char *p = *pBuffer;
676     size_t remain = *pRemain;
677     VALUE_PAIR *vp = NULL;
678     DICT_ATTR *da;
679     uint32_t attrid;
680
681     if (remain < avpSize(NULL))
682         goto fail;
683
684     attrid = load_uint32_be(p);
685     p += 4;
686     remain -= 4;
687
688     da = dict_attrbyvalue(attrid);
689     if (da != NULL) {
690         vp = pairalloc(da);
691     } else {
692         vp = paircreate(attrid, PW_TYPE_STRING);
693     }
694     if (vp == NULL) {
695         throw new std::bad_alloc;
696         goto fail;
697     }
698
699     if (remain < p[0])
700         goto fail;
701
702     switch (vp->type) {
703     case PW_TYPE_INTEGER:
704     case PW_TYPE_IPADDR:
705     case PW_TYPE_DATE:
706         if (p[0] != 4)
707             goto fail;
708
709         vp->length = 4;
710         vp->lvalue = load_uint32_be(p + 1);
711         p += 5;
712         remain -= 5;
713         break;
714     case PW_TYPE_STRING:
715     default:
716         if (p[0] >= MAX_STRING_LEN)
717             goto fail;
718
719         vp->length = (uint32_t)p[0];
720         memcpy(vp->vp_octets, p + 1, vp->length);
721
722         if (vp->type == PW_TYPE_STRING)
723             vp->vp_strvalue[vp->length] = '\0';
724
725         p += 1 + vp->length;
726         remain -= 1 + vp->length;
727         break;
728     }
729
730     *pVp = vp;
731     *pBuffer = p;
732     *pRemain = remain;
733
734     return true;
735
736 fail:
737     if (vp != NULL)
738         pairbasicfree(vp);
739     *pVp = NULL;
740     return false;
741 }
742
743 bool
744 gss_eap_radius_attr_provider::initFromBuffer(const gss_eap_attr_ctx *ctx,
745                                              const gss_buffer_t buffer)
746 {
747     unsigned char *p = (unsigned char *)buffer->value;
748     size_t remain = buffer->length;
749     VALUE_PAIR **pNext = &m_vps;
750
751     if (!gss_eap_attr_provider::initFromBuffer(ctx, buffer))
752         return false;
753
754     do {
755         VALUE_PAIR *attr;
756
757         if (!avpImport(&attr, &p, &remain))
758             return false;
759
760         *pNext = attr;
761         pNext = &attr->next;
762     } while (remain != 0);
763
764     return true;
765 }
766
767 const char *
768 gss_eap_radius_attr_provider::prefix(void) const
769 {
770     return "urn:ietf:params:gss-eap:radius-avp";
771 }
772
773 void
774 gss_eap_radius_attr_provider::exportToBuffer(gss_buffer_t buffer) const
775 {
776     VALUE_PAIR *vp;
777     unsigned char *p;
778     size_t remain = 0;
779
780     for (vp = m_vps; vp != NULL; vp = vp->next) {
781         remain += avpSize(vp);
782     }
783
784     buffer->value = GSSEAP_MALLOC(remain);
785     if (buffer->value == NULL) {
786         throw new std::bad_alloc;
787         return;
788     }
789     buffer->length = remain;
790
791     p = (unsigned char *)buffer->value;
792
793     for (vp = m_vps; vp != NULL; vp = vp->next) {
794         avpExport(vp, &p, &remain);
795     }
796
797     assert(remain == 0);
798 }
799
800 time_t
801 gss_eap_radius_attr_provider::getExpiryTime(void) const
802 {
803     VALUE_PAIR *vp;
804
805     vp = pairfind(m_vps, PW_SESSION_TIMEOUT);
806     if (vp == NULL || vp->lvalue == 0)
807         return 0;
808
809     return time(NULL) + vp->lvalue;
810 }
811
812 OM_uint32
813 gssEapRadiusMapError(OM_uint32 *minor,
814                      struct rs_error *err)
815 {
816     int code;
817
818     assert(err != NULL);
819
820     code = rs_err_code(err, 0);
821
822     if (code == RSE_OK) {
823         *minor = 0;
824         return GSS_S_COMPLETE;
825     }
826
827     *minor = ERROR_TABLE_BASE_rse + code;
828
829     gssEapSaveStatusInfo(*minor, "%s", rs_err_msg(err));
830     rs_err_free(err);
831
832     return GSS_S_FAILURE;
833 }