Module-Failure-Message goes in request, not in reply
[freeradius.git] / src / modules / rlm_mschap / rlm_mschap.c
index 355bbfd..62d45ac 100644 (file)
@@ -704,7 +704,24 @@ static int do_mschap(rlm_mschap_t *inst,
                                             buffer, sizeof(buffer),
                                             NULL, NULL, 1);
                if (result != 0) {
+                       char *p;
+                       VALUE_PAIR *vp = NULL;
+
                        RDEBUG2("External script failed.");
+
+                       vp = pairmake("Module-Failure-Message", "", T_OP_EQ);
+                       if (!vp) {
+                               radlog_request(L_ERR, 0, request, "No memory to allocate Module-Failure-Message");
+                               return RLM_MODULE_FAIL;
+                       }
+
+                       p = strchr(buffer, '\n');
+                       if (p) *p = '\0';
+                       snprintf(vp->vp_strvalue, sizeof(vp->vp_strvalue),
+                               "%s: External script says %s",
+                                inst->xlat_name, buffer);
+                       vp->length = strlen(vp->vp_strvalue);
+                       pairadd(&request->request->vps, vp);
                        return -1;
                }
 
@@ -893,7 +910,7 @@ static int mschap_authorize(void * instance, REQUEST *request)
        }
 
        if (pairfind(request->config_items, PW_AUTH_TYPE, 0)) {
-               RDEBUG2("Found existing Auth-Type.  Not changing it.");
+               RDEBUG2("WARNING: Auth-Type already set.  Not setting to MS-CHAP");
                return RLM_MODULE_NOOP;
        }
 
@@ -1069,7 +1086,7 @@ static int mschap_authenticate(void * instance, REQUEST *request)
                             PW_MSCHAP_CHALLENGE,
                             VENDORPEC_MICROSOFT);
        if (!challenge) {
-               RDEBUG2("No MS-CHAP-Challenge in the request");
+               RDEBUG("ERROR: You set 'Auth-Type = MS-CHAP' for a request that does not contain any MS-CHAP attributes!");
                return RLM_MODULE_REJECT;
        }
 
@@ -1252,7 +1269,7 @@ static int mschap_authenticate(void * instance, REQUEST *request)
                chap = 2;
 
        } else {                /* Neither CHAPv1 or CHAPv2 response: die */
-               radlog_request(L_AUTH, 0, request, "No MS-CHAP response found");
+               RDEBUG("ERROR: You set 'Auth-Type = MS-CHAP' for a request that does not contain any MS-CHAP attributes!");
                return RLM_MODULE_INVALID;
        }