~ubuntu-branches/ubuntu/natty/freeradius/natty-updates

« back to all changes in this revision

Viewing changes to src/modules/rlm_mschap/rlm_mschap.c

  • Committer: Bazaar Package Importer
  • Author(s): Josip Rodin
  • Date: 2009-11-23 03:57:37 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20091123035737-zsgtzhfych8hir68
Tags: 2.1.7+dfsg-1
* Adopting the package, closes: #536623.
* New upstream version, closes: #513484.
  + Fixes the blooper in unlang evaluation logic, closes: #526175.
* Used quilt (and added README.source), and moved upstream file patching
  into debian/patches/. The source is no longer in collab-maint git
  (to make it simpler for me to finally get this out the door), but
  kept the .gitignore should we need that again.
* Dropped the dialup_admin/bin/backup_radacct patch (integrated upstream).
* Dropped the raddb/Makefile patch (problem no longer exists upstream).
* Dropped the lib/packet.c lib/radius.c main/listen.c patches (was from
  upstream 2.0.5 anyway).
* Dropped references to otp.conf, it no longer exists upstream.
  Keep removing the conffile statoverride in prerm.
* Dropped references to snmp.conf, it no longer exists upstream.
  Keep removing the conffile statoverride in prerm.
* Ship /etc/freeradius/modules/* in the freeradius package.
* Stop shipping sites-enabled symlinks in the package and instead create
  them only on initial install, thanks to Matej Vela, closes: #533396.
* Add export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" to the init script
  at the request of John Morrissey, closes: #550143.
* Stop installing /var/run/freeradius in the package to silence Lintian.
  The init script already recreates it at will.
* Remove executable bit from example.pl to silence Lintian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * rlm_mschap.c
3
3
 *
4
 
 * Version:     $Id: rlm_mschap.c,v 1.99 2008/01/09 13:20:56 aland Exp $
 
4
 * Version:     $Id$
5
5
 *
6
6
 *   This program is free software; you can redistribute it and/or modify
7
7
 *   it under the terms of the GNU General Public License as published by
43
43
/*  MPPE support from Takahiro Wagatsuma <waga@sic.shibaura-it.ac.jp> */
44
44
 
45
45
#include        <freeradius-devel/ident.h>
46
 
RCSID("$Id: rlm_mschap.c,v 1.99 2008/01/09 13:20:56 aland Exp $")
 
46
RCSID("$Id$")
47
47
 
48
48
#include        <freeradius-devel/radiusd.h>
49
49
#include        <freeradius-devel/modules.h>
50
50
#include        <freeradius-devel/rad_assert.h>
51
51
#include        <freeradius-devel/md5.h>
 
52
#include        <freeradius-devel/sha1.h>
52
53
 
53
54
#include        <ctype.h>
54
55
 
287
288
        VALUE_PAIR      *chap_challenge, *response;
288
289
        rlm_mschap_t    *inst = instance;
289
290
 
290
 
        chap_challenge = response = NULL;
 
291
        response = NULL;
291
292
 
292
293
        func = func;            /* -Wunused */
293
294
 
299
300
                chap_challenge = pairfind(request->packet->vps,
300
301
                                          PW_MSCHAP_CHALLENGE);
301
302
                if (!chap_challenge) {
302
 
                        DEBUG2("  rlm_mschap: No MS-CHAP-Challenge in the request.");
 
303
                        RDEBUG2("No MS-CHAP-Challenge in the request.");
303
304
                        return 0;
304
305
                }
305
306
 
308
309
                 *      for MS-CHAPv2
309
310
                 */
310
311
                if (chap_challenge->length == 8) {
311
 
                        DEBUG2(" mschap1: %02x",
 
312
                        RDEBUG2(" mschap1: %02x",
312
313
                               chap_challenge->vp_octets[0]);
313
314
                        data = chap_challenge->vp_octets;
314
315
                        data_len = 8;
320
321
                } else if (chap_challenge->length == 16) {
321
322
                        char *username_string;
322
323
 
323
 
                        DEBUG2(" mschap2: %02x", chap_challenge->vp_octets[0]);
 
324
                        RDEBUG2(" mschap2: %02x", chap_challenge->vp_octets[0]);
324
325
                        response = pairfind(request->packet->vps,
325
326
                                            PW_MSCHAP2_RESPONSE);
326
327
                        if (!response) {
327
 
                                DEBUG2("  rlm_mschap: MS-CHAP2-Response is required to calculate MS-CHAPv1 challenge.");
 
328
                                RDEBUG2("MS-CHAP2-Response is required to calculate MS-CHAPv1 challenge.");
328
329
                                return 0;
329
330
                        }
330
331
 
332
333
                         *      Responses are 50 octets.
333
334
                         */
334
335
                        if (response->length < 50) {
335
 
                                radlog(L_AUTH, "rlm_mschap: MS-CHAP-Response has the wrong format.");
 
336
                                radlog_request(L_AUTH, 0, request, "MS-CHAP-Response has the wrong format.");
336
337
                                return 0;
337
338
                        }
338
339
 
339
340
                        user_name = pairfind(request->packet->vps,
340
341
                                             PW_USER_NAME);
341
342
                        if (!user_name) {
342
 
                                DEBUG2("  rlm_mschap: User-Name is required to calculateMS-CHAPv1 Challenge.");
 
343
                                RDEBUG2("User-Name is required to calculateMS-CHAPv1 Challenge.");
343
344
                                return 0;
344
345
                        }
345
346
 
350
351
                                if (inst->with_ntdomain_hack) {
351
352
                                        username_string++;
352
353
                                } else {
353
 
                                        DEBUG2("  rlm_mschap: NT Domain delimeter found, should we have enabled with_ntdomain_hack?");
 
354
                                        RDEBUG2("NT Domain delimeter found, should we have enabled with_ntdomain_hack?");
354
355
                                        username_string = user_name->vp_strvalue;
355
356
                                }
356
357
                        } else {
368
369
                        data = buffer;
369
370
                        data_len = 8;
370
371
                } else {
371
 
                        DEBUG2("  rlm_mschap: Invalid MS-CHAP challenge length");
 
372
                        RDEBUG2("Invalid MS-CHAP challenge length");
372
373
                        return 0;
373
374
                }
374
375
 
382
383
                if (!response) response = pairfind(request->packet->vps,
383
384
                                                   PW_MSCHAP2_RESPONSE);
384
385
                if (!response) {
385
 
                        DEBUG2("  rlm_mschap: No MS-CHAP-Response or MS-CHAP2-Response was found in the request.");
 
386
                        RDEBUG2("No MS-CHAP-Response or MS-CHAP2-Response was found in the request.");
386
387
                        return 0;
387
388
                }
388
389
 
392
393
                 */
393
394
                if ((response->attribute == PW_MSCHAP_RESPONSE) &&
394
395
                    ((response->vp_octets[1] & 0x01) == 0)) {
395
 
                        DEBUG2("  rlm_mschap: No NT-Response in MS-CHAP-Response");
 
396
                        RDEBUG2("No NT-Response in MS-CHAP-Response");
396
397
                        return 0;
397
398
                }
398
399
 
412
413
                response = pairfind(request->packet->vps,
413
414
                                    PW_MSCHAP_RESPONSE);
414
415
                if (!response) {
415
 
                        DEBUG2("  rlm_mschap: No MS-CHAP-Response was found in the request.");
 
416
                        RDEBUG2("No MS-CHAP-Response was found in the request.");
416
417
                        return 0;
417
418
                }
418
419
 
421
422
                 *      if the second octet says so.
422
423
                 */
423
424
                if ((response->vp_octets[1] & 0x01) != 0) {
424
 
                        DEBUG2("  rlm_mschap: No LM-Response in MS-CHAP-Response");
 
425
                        RDEBUG2("No LM-Response in MS-CHAP-Response");
425
426
                        return 0;
426
427
                }
427
428
                data = response->vp_octets + 2;
435
436
 
436
437
                user_name = pairfind(request->packet->vps, PW_USER_NAME);
437
438
                if (!user_name) {
438
 
                        DEBUG2("  rlm_mschap: No User-Name was found in the request.");
 
439
                        RDEBUG2("No User-Name was found in the request.");
439
440
                        return 0;
440
441
                }
441
442
 
452
453
                         */
453
454
                        p = strchr(user_name->vp_strvalue, '.');
454
455
                        if (!p) {
455
 
                                DEBUG2("  rlm_mschap: setting NT-Domain to same as machine name");
 
456
                                RDEBUG2("setting NT-Domain to same as machine name");
456
457
                                strlcpy(out, user_name->vp_strvalue + 5, outlen);
457
458
                        } else {
458
459
                                p++;    /* skip the period */
468
469
                } else {
469
470
                        p = strchr(user_name->vp_strvalue, '\\');
470
471
                        if (!p) {
471
 
                                DEBUG2("  rlm_mschap: No NT-Domain was found in the User-Name.");
 
472
                                RDEBUG2("No NT-Domain was found in the User-Name.");
472
473
                                return 0;
473
474
                        }
474
475
 
490
491
 
491
492
                user_name = pairfind(request->packet->vps, PW_USER_NAME);
492
493
                if (!user_name) {
493
 
                        DEBUG2("  rlm_mschap: No User-Name was found in the request.");
 
494
                        RDEBUG2("No User-Name was found in the request.");
494
495
                        return 0;
495
496
                }
496
497
 
538
539
                p = fmt + 8;    /* 7 is the length of 'NT-Hash' */
539
540
                if ((p == '\0')  || (outlen <= 32))
540
541
                        return 0;
541
 
                DEBUG("rlm_mschap: NT-Hash: %s",p);
 
542
                RDEBUG("rlm_mschap: NT-Hash: %s",p);
542
543
                ntpwdhash(buffer,p);
543
544
 
544
545
                fr_bin2hex(buffer, out, 16);
545
546
                out[32] = '\0';
546
 
                DEBUG("rlm_mschap: NT-Hash: Result: %s",out);
 
547
                RDEBUG("rlm_mschap: NT-Hash: Result: %s",out);
547
548
                return 32;
548
549
 
549
550
                /*
556
557
                if ((p == '\0') || (outlen <= 32))
557
558
                        return 0;
558
559
 
559
 
                DEBUG("rlm_mschap: LM-Hash: %s",p);
 
560
                RDEBUG("rlm_mschap: LM-Hash: %s",p);
560
561
                smbdes_lmpwdhash(p, buffer);
561
562
                fr_bin2hex(buffer, out, 16);
562
563
                out[32] = '\0';
563
 
                DEBUG("rlm_mschap: LM-Hash: Result: %s",out);
 
564
                RDEBUG("rlm_mschap: LM-Hash: Result: %s",out);
564
565
                return 32;
565
566
        } else {
566
 
                DEBUG2("  rlm_mschap: Unknown expansion string \"%s\"",
 
567
                RDEBUG2("Unknown expansion string \"%s\"",
567
568
                       fmt);
568
569
                return 0;
569
570
        }
574
575
         *      Didn't set anything: this is bad.
575
576
         */
576
577
        if (!data) {
577
 
                DEBUG2("  rlm_mschap: Failed to do anything intelligent");
 
578
                RDEBUG2("Failed to do anything intelligent");
578
579
                return 0;
579
580
        }
580
581
 
691
692
 *      add_reply() adds either MS-CHAP2-Success or MS-CHAP-Error
692
693
 *      attribute to reply packet
693
694
 */
694
 
void mschap_add_reply(VALUE_PAIR** vp, unsigned char ident,
 
695
void mschap_add_reply(REQUEST *request, VALUE_PAIR** vp, unsigned char ident,
695
696
                      const char* name, const char* value, int len)
696
697
{
697
698
        VALUE_PAIR *reply_attr;
698
699
        reply_attr = pairmake(name, "", T_OP_EQ);
699
700
        if (!reply_attr) {
700
 
                DEBUG("  rlm_mschap: Failed to create attribute %s: %s\n", name, librad_errstr);
 
701
                RDEBUG("Failed to create attribute %s: %s\n", name, fr_strerror());
701
702
                return;
702
703
        }
703
704
 
716
717
       VALUE_PAIR *vp;
717
718
       vp = radius_pairmake(request, &request->reply->vps, name, "", T_OP_EQ);
718
719
       if (!vp) {
719
 
               DEBUG("rlm_mschap: mppe_add_reply failed to create attribute %s: %s\n", name, librad_errstr);
 
720
               RDEBUG("rlm_mschap: mppe_add_reply failed to create attribute %s: %s\n", name, fr_strerror());
720
721
               return;
721
722
       }
722
723
 
735
736
static int do_mschap(rlm_mschap_t *inst,
736
737
                     REQUEST *request, VALUE_PAIR *password,
737
738
                     uint8_t *challenge, uint8_t *response,
738
 
                     uint8_t *nthashhash)
 
739
                     uint8_t *nthashhash, int do_ntlm_auth)
739
740
{
740
 
        int             do_ntlm_auth = 0;
741
741
        uint8_t         calculated[24];
742
 
        VALUE_PAIR      *vp = NULL;
743
 
 
744
 
        /*
745
 
         *      If we have ntlm_auth configured, use it unless told
746
 
         *      otherwise
747
 
         */
748
 
        if (inst->ntlm_auth) do_ntlm_auth = 1;
749
 
 
750
 
        /*
751
 
         *      If we have an ntlm_auth configuration, then we may
752
 
         *      want to use it.
753
 
         */
754
 
        vp = pairfind(request->config_items,
755
 
                      PW_MS_CHAP_USE_NTLM_AUTH);
756
 
        if (vp) do_ntlm_auth = vp->vp_integer;
757
 
 
758
 
        /*
759
 
         *      No ntlm_auth configured, attribute to tell us to
760
 
         *      use it exists, and we're told to use it.  We don't
761
 
         *      know what to do...
762
 
         */
763
 
        if (!inst->ntlm_auth && do_ntlm_auth) {
764
 
                DEBUG2("  rlm_mschap: Asked to use ntlm_auth, but it was not configured in the mschap{} section.");
765
 
                return -1;
766
 
        }
767
742
 
768
743
        /*
769
744
         *      Do normal authentication.
773
748
                 *      No password: can't do authentication.
774
749
                 */
775
750
                if (!password) {
776
 
                        DEBUG2("  rlm_mschap: FAILED: No NT/LM-Password.  Cannot perform authentication.");
 
751
                        RDEBUG2("FAILED: No NT/LM-Password.  Cannot perform authentication.");
777
752
                        return -1;
778
753
                }
779
754
 
806
781
                                             buffer, sizeof(buffer),
807
782
                                             NULL, NULL, 1);
808
783
                if (result != 0) {
809
 
                        DEBUG2("  rlm_mschap: External script failed.");
 
784
                        RDEBUG2("External script failed.");
810
785
                        return -1;
811
786
                }
812
787
 
817
792
                 *      NT_KEY: 000102030405060708090a0b0c0d0e0f
818
793
                 */
819
794
                if (memcmp(buffer, "NT_KEY: ", 8) != 0) {
820
 
                        DEBUG2("  rlm_mschap: Invalid output from ntlm_auth: expecting NT_KEY");
 
795
                        RDEBUG2("Invalid output from ntlm_auth: expecting NT_KEY");
821
796
                        return -1;
822
797
                }
823
798
 
826
801
                 *      with an LF at the end.
827
802
                 */
828
803
                if (strlen(buffer + 8) < 32) {
829
 
                        DEBUG2("  rlm_mschap: Invalid output from ntlm_auth: NT_KEY has unexpected length");
 
804
                        RDEBUG2("Invalid output from ntlm_auth: NT_KEY has unexpected length");
830
805
                        return -1;
831
806
                }
832
807
 
834
809
                 *      Update the NT hash hash, from the NT key.
835
810
                 */
836
811
                if (fr_hex2bin(buffer + 8, nthashhash, 16) != 16) {
837
 
                        DEBUG2("  rlm_mschap: Invalid output from ntlm_auth: NT_KEY has non-hex values");
 
812
                        RDEBUG2("Invalid output from ntlm_auth: NT_KEY has non-hex values");
838
813
                        return -1;
839
814
                }
840
815
        }
984
959
         *      Nothing we recognize.  Don't do anything.
985
960
         */
986
961
        if (!response) {
987
 
                DEBUG2("  rlm_mschap: Found MS-CHAP-Challenge, but no MS-CHAP-Response.");
 
962
                RDEBUG2("Found MS-CHAP-Challenge, but no MS-CHAP-Response.");
988
963
                return RLM_MODULE_NOOP;
989
964
        }
990
965
 
991
966
        if (pairfind(request->config_items, PW_AUTH_TYPE)) {
992
 
                DEBUG2("  rlm_mschap: Found existing Auth-Type.  Not changing it.");
 
967
                RDEBUG2("Found existing Auth-Type.  Not changing it.");
993
968
                return RLM_MODULE_NOOP;
994
969
        }
995
970
 
996
 
        DEBUG2("  rlm_mschap: Found MS-CHAP attributes.  Setting 'Auth-Type  = %s'", inst->xlat_name);
 
971
        RDEBUG2("Found MS-CHAP attributes.  Setting 'Auth-Type  = %s'", inst->xlat_name);
997
972
 
998
973
        /*
999
974
         *      Set Auth-Type to MS-CHAP.  The authentication code
1038
1013
        char msch2resp[42];
1039
1014
        char *username_string;
1040
1015
        int chap = 0;
 
1016
        int             do_ntlm_auth;
 
1017
 
 
1018
        /*
 
1019
         *      If we have ntlm_auth configured, use it unless told
 
1020
         *      otherwise
 
1021
         */
 
1022
        do_ntlm_auth = inst->ntlm_auth;
 
1023
 
 
1024
        /*
 
1025
         *      If we have an ntlm_auth configuration, then we may
 
1026
         *      want to suppress it.
 
1027
         */
 
1028
        if (do_ntlm_auth) {
 
1029
                VALUE_PAIR *vp = pairfind(request->config_items,
 
1030
                                          PW_MS_CHAP_USE_NTLM_AUTH);
 
1031
                if (vp) do_ntlm_auth = vp->vp_integer;
 
1032
        }
1041
1033
 
1042
1034
        /*
1043
1035
         *      Find the SMB-Account-Ctrl attribute, or the
1067
1059
                 *      Password is not required.
1068
1060
                 */
1069
1061
                if ((smb_ctrl->vp_integer & ACB_PWNOTREQ) != 0) {
1070
 
                        DEBUG2("  rlm_mschap: SMB-Account-Ctrl says no password is required.");
 
1062
                        RDEBUG2("SMB-Account-Ctrl says no password is required.");
1071
1063
                        return RLM_MODULE_OK;
1072
1064
                }
1073
1065
        }
1089
1081
                    ((lm_password->length == 32) &&
1090
1082
                     (fr_hex2bin(lm_password->vp_strvalue,
1091
1083
                                 lm_password->vp_octets, 16) == 16))) {
1092
 
                        DEBUG2("  rlm_mschap: Found LM-Password");
 
1084
                        RDEBUG2("Found LM-Password");
1093
1085
                        lm_password->length = 16;
1094
1086
 
1095
1087
                } else {
1096
 
                        radlog(L_ERR, "rlm_mschap: Invalid LM-Password");
 
1088
                        radlog_request(L_ERR, 0, request, "Invalid LM-Password");
1097
1089
                        lm_password = NULL;
1098
1090
                }
1099
1091
 
1100
1092
        } else if (!password) {
1101
 
                DEBUG2("  rlm_mschap: No Cleartext-Password configured.  Cannot create LM-Password.");
 
1093
                if (!do_ntlm_auth) RDEBUG2("No Cleartext-Password configured.  Cannot create LM-Password.");
1102
1094
 
1103
1095
        } else {                /* there is a configured Cleartext-Password */
1104
1096
                lm_password = radius_pairmake(request, &request->config_items,
1105
1097
                                              "LM-Password", "", T_OP_EQ);
1106
1098
                if (!lm_password) {
1107
 
                        radlog(L_ERR, "No memory");
 
1099
                        radlog_request(L_ERR, 0, request, "No memory");
1108
1100
                } else {
1109
1101
                        smbdes_lmpwdhash(password->vp_strvalue,
1110
1102
                                         lm_password->vp_octets);
1121
1113
                    ((nt_password->length == 32) &&
1122
1114
                     (fr_hex2bin(nt_password->vp_strvalue,
1123
1115
                                 nt_password->vp_octets, 16) == 16))) {
1124
 
                        DEBUG2("  rlm_mschap: Found NT-Password");
 
1116
                        RDEBUG2("Found NT-Password");
1125
1117
                        nt_password->length = 16;
1126
1118
 
1127
1119
                } else {
1128
 
                        radlog(L_ERR, "rlm_mschap: Invalid NT-Password");
 
1120
                        radlog_request(L_ERR, 0, request, "Invalid NT-Password");
1129
1121
                        nt_password = NULL;
1130
1122
                }
1131
1123
        } else if (!password) {
1132
 
                DEBUG2("  rlm_mschap: No Cleartext-Password configured.  Cannot create NT-Password.");
 
1124
                if (!do_ntlm_auth) RDEBUG2("No Cleartext-Password configured.  Cannot create NT-Password.");
1133
1125
 
1134
1126
        } else {                /* there is a configured Cleartext-Password */
1135
1127
                nt_password = radius_pairmake(request, &request->config_items,
1136
1128
                                              "NT-Password", "", T_OP_EQ);
1137
1129
                if (!nt_password) {
1138
 
                        radlog(L_ERR, "No memory");
 
1130
                        radlog_request(L_ERR, 0, request, "No memory");
1139
1131
                        return RLM_MODULE_FAIL;
1140
1132
                } else {
1141
1133
                        ntpwdhash(nt_password->vp_octets,
1146
1138
 
1147
1139
        challenge = pairfind(request->packet->vps, PW_MSCHAP_CHALLENGE);
1148
1140
        if (!challenge) {
1149
 
                DEBUG2("  rlm_mschap: No MS-CHAP-Challenge in the request");
 
1141
                RDEBUG2("No MS-CHAP-Challenge in the request");
1150
1142
                return RLM_MODULE_REJECT;
1151
1143
        }
1152
1144
 
1165
1157
                 *      MS-CHAPv1 challenges are 8 octets.
1166
1158
                 */
1167
1159
                if (challenge->length < 8) {
1168
 
                        radlog(L_AUTH, "rlm_mschap: MS-CHAP-Challenge has the wrong format.");
 
1160
                        radlog_request(L_AUTH, 0, request, "MS-CHAP-Challenge has the wrong format.");
1169
1161
                        return RLM_MODULE_INVALID;
1170
1162
                }
1171
1163
 
1173
1165
                 *      Responses are 50 octets.
1174
1166
                 */
1175
1167
                if (response->length < 50) {
1176
 
                        radlog(L_AUTH, "rlm_mschap: MS-CHAP-Response has the wrong format.");
 
1168
                        radlog_request(L_AUTH, 0, request, "MS-CHAP-Response has the wrong format.");
1177
1169
                        return RLM_MODULE_INVALID;
1178
1170
                }
1179
1171
 
1182
1174
                 *      response
1183
1175
                 */
1184
1176
                if (response->vp_octets[1] & 0x01) {
1185
 
                        DEBUG2("  rlm_mschap: Told to do MS-CHAPv1 with NT-Password");
 
1177
                        RDEBUG2("Told to do MS-CHAPv1 with NT-Password");
1186
1178
                        password = nt_password;
1187
1179
                        offset = 26;
1188
1180
                } else {
1189
 
                        DEBUG2("  rlm_mschap: Told to do MS-CHAPv1 with LM-Password");
 
1181
                        RDEBUG2("Told to do MS-CHAPv1 with LM-Password");
1190
1182
                        password = lm_password;
1191
1183
                        offset = 2;
1192
1184
                }
1195
1187
                 *      Do the MS-CHAP authentication.
1196
1188
                 */
1197
1189
                if (do_mschap(inst, request, password, challenge->vp_octets,
1198
 
                              response->vp_octets + offset, nthashhash) < 0) {
1199
 
                        DEBUG2("  rlm_mschap: MS-CHAP-Response is incorrect.");
1200
 
                        mschap_add_reply(&request->reply->vps,
 
1190
                              response->vp_octets + offset, nthashhash,
 
1191
                              do_ntlm_auth) < 0) {
 
1192
                        RDEBUG2("MS-CHAP-Response is incorrect.");
 
1193
                        mschap_add_reply(request, &request->reply->vps,
1201
1194
                                         *response->vp_octets,
1202
1195
                                         "MS-CHAP-Error", "E=691 R=1", 9);
1203
1196
                        return RLM_MODULE_REJECT;
1212
1205
                 *      MS-CHAPv2 challenges are 16 octets.
1213
1206
                 */
1214
1207
                if (challenge->length < 16) {
1215
 
                        radlog(L_AUTH, "rlm_mschap: MS-CHAP-Challenge has the wrong format.");
 
1208
                        radlog_request(L_AUTH, 0, request, "MS-CHAP-Challenge has the wrong format.");
1216
1209
                        return RLM_MODULE_INVALID;
1217
1210
                }
1218
1211
 
1220
1213
                 *      Responses are 50 octets.
1221
1214
                 */
1222
1215
                if (response->length < 50) {
1223
 
                        radlog(L_AUTH, "rlm_mschap: MS-CHAP-Response has the wrong format.");
 
1216
                        radlog_request(L_AUTH, 0, request, "MS-CHAP-Response has the wrong format.");
1224
1217
                        return RLM_MODULE_INVALID;
1225
1218
                }
1226
1219
 
1229
1222
                 */
1230
1223
                username = pairfind(request->packet->vps, PW_USER_NAME);
1231
1224
                if (!username) {
1232
 
                        radlog(L_AUTH, "rlm_mschap: We require a User-Name for MS-CHAPv2");
 
1225
                        radlog_request(L_AUTH, 0, request, "We require a User-Name for MS-CHAPv2");
1233
1226
                        return RLM_MODULE_INVALID;
1234
1227
                }
1235
1228
 
1241
1234
                        if (inst->with_ntdomain_hack) {
1242
1235
                                username_string++;
1243
1236
                        } else {
1244
 
                                DEBUG2("  rlm_mschap: NT Domain delimeter found, should we have enabled with_ntdomain_hack?");
 
1237
                                RDEBUG2("  NT Domain delimeter found, should we have enabled with_ntdomain_hack?");
1245
1238
                                username_string = username->vp_strvalue;
1246
1239
                        }
1247
1240
                } else {
1254
1247
                 *      OpenDirectory authentication.
1255
1248
                 */
1256
1249
                if (!nt_password && inst->open_directory) {
1257
 
                        DEBUG2("  rlm_mschap: No NT-Password configured. Trying DirectoryService Authentication.");
 
1250
                        RDEBUG2("No NT-Password configured. Trying DirectoryService Authentication.");
1258
1251
                        return od_mschap_auth(request, challenge, username);
1259
1252
                }
1260
1253
#endif
1270
1263
                               username_string, /* user name */
1271
1264
                               mschapv1_challenge); /* resulting challenge */
1272
1265
 
1273
 
                DEBUG2("  rlm_mschap: Told to do MS-CHAPv2 for %s with NT-Password",
 
1266
                RDEBUG2("Told to do MS-CHAPv2 for %s with NT-Password",
1274
1267
                       username_string);
1275
1268
 
1276
1269
                if (do_mschap(inst, request, nt_password, mschapv1_challenge,
1277
 
                              response->vp_octets + 26, nthashhash) < 0) {
1278
 
                        DEBUG2("  rlm_mschap: FAILED: MS-CHAP2-Response is incorrect");
1279
 
                        mschap_add_reply(&request->reply->vps,
 
1270
                              response->vp_octets + 26, nthashhash,
 
1271
                              do_ntlm_auth) < 0) {
 
1272
                        RDEBUG2("FAILED: MS-CHAP2-Response is incorrect");
 
1273
                        mschap_add_reply(request, &request->reply->vps,
1280
1274
                                         *response->vp_octets,
1281
1275
                                         "MS-CHAP-Error", "E=691 R=1", 9);
1282
1276
                        return RLM_MODULE_REJECT;
1294
1288
                              response->vp_octets + 2, /* peer challenge */
1295
1289
                              challenge->vp_octets, /* our challenge */
1296
1290
                              msch2resp); /* calculated MPPE key */
1297
 
                mschap_add_reply(&request->reply->vps, *response->vp_octets,
 
1291
                mschap_add_reply(request, &request->reply->vps, *response->vp_octets,
1298
1292
                                 "MS-CHAP2-Success", msch2resp, 42);
1299
1293
                chap = 2;
1300
1294
 
1301
1295
        } else {                /* Neither CHAPv1 or CHAPv2 response: die */
1302
 
                radlog(L_AUTH, "rlm_mschap: No MS-CHAP response found");
 
1296
                radlog_request(L_AUTH, 0, request, "No MS-CHAP response found");
1303
1297
                return RLM_MODULE_INVALID;
1304
1298
        }
1305
1299
 
1317
1311
                 */
1318
1312
                if (((smb_ctrl->vp_integer & ACB_DISABLED) != 0) ||
1319
1313
                    ((smb_ctrl->vp_integer & ACB_NORMAL) == 0)) {
1320
 
                        DEBUG2("  rlm_mschap: SMB-Account-Ctrl says that the account is disabled, or is not a normal account.");
1321
 
                        mschap_add_reply( &request->reply->vps,
 
1314
                        RDEBUG2("SMB-Account-Ctrl says that the account is disabled, or is not a normal account.");
 
1315
                        mschap_add_reply(request, &request->reply->vps,
1322
1316
                                          *response->vp_octets,
1323
1317
                                          "MS-CHAP-Error", "E=691 R=1", 9);
1324
1318
                        return RLM_MODULE_NOTFOUND;
1328
1322
                 *      User is locked out.
1329
1323
                 */
1330
1324
                if ((smb_ctrl->vp_integer & ACB_AUTOLOCK) != 0) {
1331
 
                        DEBUG2("  rlm_mschap: SMB-Account-Ctrl says that the account is locked out.");
1332
 
                        mschap_add_reply( &request->reply->vps,
 
1325
                        RDEBUG2("SMB-Account-Ctrl says that the account is locked out.");
 
1326
                        mschap_add_reply(request, &request->reply->vps,
1333
1327
                                          *response->vp_octets,
1334
1328
                                          "MS-CHAP-Error", "E=647 R=0", 9);
1335
1329
                        return RLM_MODULE_USERLOCK;
1342
1336
                uint8_t mppe_recvkey[34];
1343
1337
 
1344
1338
                if (chap == 1){
1345
 
                        DEBUG2("rlm_mschap: adding MS-CHAPv1 MPPE keys");
 
1339
                        RDEBUG2("adding MS-CHAPv1 MPPE keys");
1346
1340
                        memset(mppe_sendkey, 0, 32);
1347
1341
                        if (lm_password) {
1348
1342
                                memcpy(mppe_sendkey, lm_password->vp_octets, 8);
1366
1360
                                       "MS-CHAP-MPPE-Keys",
1367
1361
                                       mppe_sendkey, 32);
1368
1362
                } else if (chap == 2) {
1369
 
                        DEBUG2("rlm_mschap: adding MS-CHAPv2 MPPE keys");
 
1363
                        RDEBUG2("adding MS-CHAPv2 MPPE keys");
1370
1364
                        mppe_chap2_gen_keys128(nthashhash,
1371
1365
                                               response->vp_octets + 26,
1372
1366
                                               mppe_sendkey, mppe_recvkey);