Handle CHAP-Challenge
authorAlan T. DeKok <aland@freeradius.org>
Wed, 25 May 2011 12:42:34 +0000 (14:42 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 25 May 2011 12:42:45 +0000 (14:42 +0200)
src/modules/rlm_replicate/rlm_replicate.c

index b2b8150..c328741 100644 (file)
@@ -113,7 +113,6 @@ static int replicate_packet(void *instance, REQUEST *request)
                        packet->sockfd = -1;
                        packet->code = request->packet->code;
                        packet->id = fr_rand() & 0xff;
-                       packet->vps = paircopy(request->packet->vps);
 
                        packet->sockfd = fr_socket(&home->src_ipaddr, 0);
                        if (packet->sockfd < 0) {
@@ -121,6 +120,28 @@ static int replicate_packet(void *instance, REQUEST *request)
                                cleanup(packet);
                                return RLM_MODULE_FAIL;
                        }
+
+                       packet->vps = paircopy(request->packet->vps);
+                       if (!packet->vps) {
+                               RDEBUG("ERROR: Out of memory!");
+                               cleanup(packet);
+                               return RLM_MODULE_FAIL;
+                       }
+
+                       /*
+                        *      For CHAP, create the CHAP-Challenge if
+                        *      it doesn't exist.
+                        */
+                       if ((request->packet->code == PW_AUTHENTICATION_REQUEST) &&
+                           (pairfind(request->packet->vps, PW_CHAP_PASSWORD) != NULL) &&
+                           (pairfind(request->packet->vps, PW_CHAP_CHALLENGE) == NULL)) {
+                               vp = radius_paircreate(request, &packet->vps,
+                                                      PW_CHAP_CHALLENGE,
+                                                      PW_TYPE_OCTETS);
+                               vp->length = AUTH_VECTOR_LEN;
+                               memcpy(vp->vp_strvalue, request->packet->vector,
+                                      AUTH_VECTOR_LEN);
+                       }
                } else {
                        size_t i;