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