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