fix octet string length check
[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(uint16_t 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     uint32_t 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     uint32_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         vp->length = n;
438
439         pairadd(vps, vp);
440
441         p += n;
442         remain -= n;
443     } while (remain != 0);
444
445     return GSS_S_COMPLETE;
446 }
447
448 OM_uint32
449 gssEapRadiusGetRawAvp(OM_uint32 *minor,
450                       VALUE_PAIR *vps,
451                       uint16_t type,
452                       uint16_t vendor,
453                       VALUE_PAIR **vp)
454 {
455     uint32_t attr = VENDORATTR(vendor, type);
456
457     *vp = pairfind(vps, attr);
458
459     return (*vp == NULL) ? GSS_S_UNAVAILABLE : GSS_S_COMPLETE;
460 }
461
462 OM_uint32
463 gssEapRadiusGetAvp(OM_uint32 *minor,
464                    VALUE_PAIR *vps,
465                    uint16_t type,
466                    uint16_t vendor,
467                    gss_buffer_t buffer,
468                    int concat)
469 {
470     VALUE_PAIR *vp;
471     unsigned char *p;
472     uint32_t attr = VENDORATTR(vendor, type);
473
474     buffer->length = 0;
475     buffer->value = NULL;
476
477     vp = pairfind(vps, attr);
478     if (vp == NULL)
479         return GSS_S_UNAVAILABLE;
480
481     do {
482         buffer->length += vp->length;
483     } while (concat && (vp = pairfind(vp->next, attr)) != NULL);
484
485     buffer->value = GSSEAP_MALLOC(buffer->length);
486     if (buffer->value == NULL) {
487         *minor = ENOMEM;
488         return GSS_S_FAILURE;
489     }
490
491     p = (unsigned char *)buffer->value;
492
493     for (vp = pairfind(vps, attr);
494          concat && vp != NULL;
495          vp = pairfind(vp->next, attr)) {
496         memcpy(p, vp->vp_octets, vp->length);
497         p += vp->length;
498     }
499
500     *minor = 0;
501     return GSS_S_COMPLETE;
502 }
503
504 OM_uint32
505 gssEapRadiusFreeAvps(OM_uint32 *minor,
506                      VALUE_PAIR **vps)
507 {
508     pairfree(vps);
509 }
510
511 OM_uint32
512 gssEapRadiusAttrProviderInit(OM_uint32 *minor)
513 {
514     return gss_eap_radius_attr_provider::init()
515         ? GSS_S_COMPLETE : GSS_S_FAILURE;
516 }
517
518 OM_uint32
519 gssEapRadiusAttrProviderFinalize(OM_uint32 *minor)
520 {
521     gss_eap_radius_attr_provider::finalize();
522     return GSS_S_COMPLETE;
523 }
524
525 /* partition error namespace so it does not conflict with krb5 */
526 #define ERROR_TABLE_BASE_rse (46882560L)
527
528 #define RS_TO_COM_ERR(rse)                  ((rse) == RSE_OK ? 0 : (rse) + ERROR_TABLE_BASE_rse)
529 #define COM_TO_RS_ERR(err)                  ((err) > ERROR_TABLE_BASE_rse && \
530                                              (err) <= (ERROR_TABLE_BASE_rse + RSE_SOME_ERROR) ? \
531                                              (err) - ERROR_TABLE_BASE_rse : RSE_SOME_ERROR)
532
533 OM_uint32
534 gssEapRadiusMapError(OM_uint32 *minor,
535                      struct rs_error *err)
536 {
537     int code = RSE_OK;
538
539     if (err != NULL)
540         code = rs_err_code(err, 0);
541     else
542         code = RSE_SOME_ERROR;
543
544     *minor = RS_TO_COM_ERR(code);
545
546     gssEapSaveStatusInfo(*minor, "radsec: %s", rs_err_msg(err, 0));
547
548     rs_err_free(err);
549     return GSS_S_FAILURE;
550 }
551
552 OM_uint32
553 gssEapRadiusAllocConn(OM_uint32 *minor,
554                       const gss_cred_id_t cred,
555                       gss_ctx_id_t ctx)
556 {
557     struct gss_eap_acceptor_ctx *actx = &ctx->acceptorCtx;
558     const char *configFile = NULL;
559     const char *configStanza = "gss-eap";
560     struct rs_error *err;
561
562     assert(actx->radHandle == NULL);
563     assert(actx->radConn == NULL);
564
565     if (cred != GSS_C_NO_CREDENTIAL) {
566         if (cred->radiusConfigFile != NULL)
567             configFile = cred->radiusConfigFile;
568         if (cred->radiusConfigStanza != NULL)
569             configStanza = cred->radiusConfigStanza;
570     }
571
572     err = radiusAllocHandle(configFile, &actx->radHandle);
573     if (err != NULL || actx->radHandle == NULL) {
574         return gssEapRadiusMapError(minor, err);
575     }
576
577     if (rs_conn_create(actx->radHandle, &actx->radConn, configStanza) != 0) {
578         return gssEapRadiusMapError(minor, rs_err_conn_pop(actx->radConn));
579     }
580
581     /* XXX TODO rs_conn_select_server does not exist yet */
582 #if 0
583     if (actx->radServer != NULL) {
584         if (rs_conn_select_server(actx->radConn, actx->radServer) != 0)
585             return gssEapRadiusMapError(minor, rs_err_conn_pop(actx->radConn));
586     }
587 #endif
588
589     *minor = 0;
590     return GSS_S_COMPLETE;
591 }
592
593 /*
594  * Encoding is:
595  * 4 octet NBO attribute ID | 4 octet attribute length | attribute data
596  */
597 static size_t
598 avpSize(const VALUE_PAIR *vp)
599 {
600     size_t size = 4 + 1;
601
602     if (vp != NULL)
603         size += vp->length;
604
605     return size;
606 }
607
608 static bool
609 avpExport(rs_handle *rh,
610           const VALUE_PAIR *vp,
611           unsigned char **pBuffer,
612           size_t *pRemain)
613 {
614     unsigned char *p = *pBuffer;
615     size_t remain = *pRemain;
616
617     assert(remain >= avpSize(vp));
618
619     store_uint32_be(vp->attribute, p);
620
621     switch (vp->type) {
622     case PW_TYPE_INTEGER:
623     case PW_TYPE_IPADDR:
624     case PW_TYPE_DATE:
625         p[4] = 4;
626         store_uint32_be(vp->lvalue, p + 5);
627         break;
628     default:
629         assert(vp->length <= MAX_STRING_LEN);
630         p[4] = (uint8_t)vp->length;
631         memcpy(p + 5, vp->vp_octets, vp->length);
632         break;
633     }
634
635     *pBuffer += 5 + p[4];
636     *pRemain -= 5 + p[4];
637
638     return true;
639
640 }
641
642 static bool
643 avpImport(rs_handle *rh,
644           VALUE_PAIR **pVp,
645           unsigned char **pBuffer,
646           size_t *pRemain)
647 {
648     unsigned char *p = *pBuffer;
649     size_t remain = *pRemain;
650     VALUE_PAIR *vp = NULL;
651     DICT_ATTR *da;
652     OM_uint32 attrid;
653
654     if (remain < avpSize(NULL))
655         goto fail;
656
657     attrid = load_uint32_be(p);
658     p += 4;
659     remain -= 4;
660
661     da = dict_attrbyvalue(attrid);
662     if (da == NULL)
663         goto fail;
664
665     vp = pairalloc(da);
666     if (vp == NULL) {
667         throw new std::bad_alloc;
668         goto fail;
669     }
670
671     if (remain < p[0])
672         goto fail;
673
674     switch (vp->type) {
675     case PW_TYPE_INTEGER:
676     case PW_TYPE_IPADDR:
677     case PW_TYPE_DATE:
678         if (p[0] != 4)
679             goto fail;
680
681         vp->length = 4;
682         vp->lvalue = load_uint32_be(p + 1);
683         p += 5;
684         remain -= 5;
685         break;
686     case PW_TYPE_STRING:
687         /* check enough room to NUL terminate */
688         if (p[0] == MAX_STRING_LEN)
689             goto fail;
690         else
691         /* fallthrough */
692     default:
693         if (p[0] > MAX_STRING_LEN)
694             goto fail;
695
696         vp->length = (uint32_t)p[0];
697         memcpy(vp->vp_octets, p + 1, vp->length);
698
699         if (vp->type == PW_TYPE_STRING)
700             vp->vp_strvalue[vp->length] = '\0';
701
702         p += 1 + vp->length;
703         remain -= 1 + vp->length;
704         break;
705     }
706
707     *pVp = vp;
708     *pBuffer = p;
709     *pRemain = remain;
710
711     return true;
712
713 fail:
714     pairbasicfree(vp);
715     return false;
716 }
717
718 bool
719 gss_eap_radius_attr_provider::initFromBuffer(const gss_eap_attr_ctx *ctx,
720                                              const gss_buffer_t buffer)
721 {
722     unsigned char *p = (unsigned char *)buffer->value;
723     size_t remain = buffer->length;
724     OM_uint32 configFileLen, count;
725     VALUE_PAIR **pNext = &m_vps;
726
727     if (!gss_eap_attr_provider::initFromBuffer(ctx, buffer))
728         return false;
729
730     if (remain < 4)
731         return false;
732
733     configFileLen = load_uint32_be(p);
734     p += 4;
735     remain -= 4;
736
737     if (remain < configFileLen)
738         return false;
739
740     std::string configFile((char *)p, configFileLen);
741     p += configFileLen;
742     remain -= configFileLen;
743
744     if (!allocRadHandle(configFile))
745         return false;
746
747     if (remain < 4)
748         return false;
749
750     count = load_uint32_be(p);
751     p += 4;
752     remain -= 4;
753
754     do {
755         VALUE_PAIR *attr;
756
757         if (!avpImport(m_rh, &attr, &p, &remain))
758             return false;
759
760         *pNext = attr;
761         pNext = &attr->next;
762
763         count--;
764     } while (remain != 0);
765
766     if (count != 0)
767         return false;
768
769     return true;
770 }
771
772 void
773 gss_eap_radius_attr_provider::exportToBuffer(gss_buffer_t buffer) const
774 {
775     OM_uint32 count = 0;
776     VALUE_PAIR *vp;
777     unsigned char *p;
778     size_t remain = 4 + m_configFile.length() + 4;
779
780     for (vp = m_vps; vp != NULL; vp = vp->next) {
781         remain += avpSize(vp);
782         count++;
783     }
784
785     buffer->value = GSSEAP_MALLOC(remain);
786     if (buffer->value == NULL) {
787         throw new std::bad_alloc;
788         return;
789     }
790     buffer->length = remain;
791
792     p = (unsigned char *)buffer->value;
793
794     store_uint32_be(m_configFile.length(), p);
795     p += 4;
796     remain -= 4;
797
798     memcpy(p, m_configFile.c_str(), m_configFile.length());
799     p += m_configFile.length();
800     remain -= m_configFile.length();
801
802     store_uint32_be(count, p);
803     p += 4;
804     remain -= 4;
805
806     for (vp = m_vps; vp != NULL; vp = vp->next) {
807         avpExport(m_rh, vp, &p, &remain);
808     }
809
810     assert(remain == 0);
811 }
812
813 time_t
814 gss_eap_radius_attr_provider::getExpiryTime(void) const
815 {
816     VALUE_PAIR *vp;
817
818     vp = pairfind(m_vps, PW_SESSION_TIMEOUT);
819     if (vp == NULL || vp->lvalue == 0)
820         return 0;
821
822     return time(NULL) + vp->lvalue;
823 }