Allow control:MS-CHAPv2-Challenge in rlm_eap_mschapv2
authorAlan T. DeKok <aland@freeradius.org>
Thu, 19 Feb 2015 16:18:10 +0000 (11:18 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 19 Feb 2015 16:18:10 +0000 (11:18 -0500)
So that we can control the challenge sent to the user

src/modules/rlm_eap/types/rlm_eap_mschapv2/rlm_eap_mschapv2.c

index 7c57b36..e582092 100644 (file)
@@ -207,16 +207,26 @@ static int mschapv2_initiate(UNUSED void *instance, eap_handler_t *handler)
        mschapv2_opaque_t *data;
        REQUEST         *request = handler->request;
        uint8_t         *p;
+       bool            created_challenge = false;
 
-       challenge = pairmake(handler, NULL, "MS-CHAP-Challenge", NULL, T_OP_EQ);
+       challenge = pairfind(request->config_items, PW_MSCHAP_CHALLENGE, VENDORPEC_MICROSOFT, TAG_ANY);
+       if (challenge && (challenge->vp_length != MSCHAPV2_CHALLENGE_LEN)) {
+               RWDEBUG("control:MS-CHAP-Challenge is incorrect length.  Ignoring it.");
+               challenge = NULL;
+       }
 
-       /*
-        *      Get a random challenge.
-        */
-       challenge->vp_length = MSCHAPV2_CHALLENGE_LEN;
-       challenge->vp_octets = p = talloc_array(challenge, uint8_t, challenge->vp_length);
-       for (i = 0; i < MSCHAPV2_CHALLENGE_LEN; i++) {
-               p[i] = fr_rand();
+       if (!challenge) {
+               created_challenge = true;
+               challenge = pairmake(handler, NULL, "MS-CHAP-Challenge", NULL, T_OP_EQ);
+
+               /*
+                *      Get a random challenge.
+                */
+               challenge->vp_length = MSCHAPV2_CHALLENGE_LEN;
+               challenge->vp_octets = p = talloc_array(challenge, uint8_t, challenge->vp_length);
+               for (i = 0; i < MSCHAPV2_CHALLENGE_LEN; i++) {
+                       p[i] = fr_rand();
+               }
        }
        RDEBUG2("Issuing Challenge");
 
@@ -241,7 +251,7 @@ static int mschapv2_initiate(UNUSED void *instance, eap_handler_t *handler)
         *      and free it.
         */
        eapmschapv2_compose(handler, challenge);
-       pairfree(&challenge);
+       if (created_challenge) pairfree(&challenge);
 
 #ifdef WITH_PROXY
        /*