~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): Paul Hampson
  • Date: 2006-01-15 13:34:13 UTC
  • mto: (3.1.3 dapper) (4.1.3 sid) (1.1.14 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20060115133413-zo1dslttvdoalqym
Tags: upstream-1.1.0
ImportĀ upstreamĀ versionĀ 1.1.0

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.59.2.2 2005/08/24 14:37:52 nbk Exp $
 
4
 * Version:     $Id: rlm_mschap.c,v 1.59.2.3 2005/10/19 16:49:46 mgriego Exp $
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
60
60
 
61
61
#include        "smbdes.h"
62
62
 
63
 
static const char rcsid[] = "$Id: rlm_mschap.c,v 1.59.2.2 2005/08/24 14:37:52 nbk Exp $";
 
63
static const char rcsid[] = "$Id: rlm_mschap.c,v 1.59.2.3 2005/10/19 16:49:46 mgriego Exp $";
64
64
 
65
65
static const char *letters = "0123456789ABCDEF";
66
66
 
453
453
                 *      Pull the NT-Domain out of the User-Name, if it exists.
454
454
                 */
455
455
        } else if (strcasecmp(fmt, "NT-Domain") == 0) {
456
 
                char *p;
 
456
                char *p, *q;
457
457
 
458
458
                user_name = pairfind(request->packet->vps, PW_USER_NAME);
459
459
                if (!user_name) {
461
461
                        return 0;
462
462
                }
463
463
                
464
 
                p = strchr(user_name->strvalue, '\\');
465
 
                if (!p) {
466
 
                        DEBUG2("  rlm_mschap: No NT-Domain was found in the User-Name.");
467
 
                        return 0;
468
 
                }
469
 
 
470
464
                /*
471
 
                 *      Hack.  This is simpler than the alternatives.
 
465
                 *      First check to see if this is a host/ style User-Name
 
466
                 *      (a la Kerberos host principal)
472
467
                 */
473
 
                *p = '\0';
474
 
                strNcpy(out, user_name->strvalue, outlen);
475
 
                *p = '\\';
 
468
                if (strncmp(user_name->strvalue, "host/", 5) == 0) {
 
469
                        /*
 
470
                         *      If we're getting a User-Name formatted in this way,
 
471
                         *      it's likely due to PEAP.  The Windows Domain will be
 
472
                         *      the first domain component following the hostname,
 
473
                         *      or the machine name itself if only a hostname is supplied
 
474
                         */
 
475
                        p = strchr(user_name->strvalue, '.');
 
476
                        if (!p) {
 
477
                                DEBUG2("  rlm_mschap: setting NT-Domain to same as machine name");
 
478
                                strNcpy(out, user_name->strvalue + 5, outlen);
 
479
                        } else {
 
480
                                p++;    /* skip the period */
 
481
                                q = strchr(p, '.');
 
482
                                /*
 
483
                                 * use the same hack as below
 
484
                                 * only if another period was found
 
485
                                 */
 
486
                                if (q) *q = '\0';
 
487
                                strNcpy(out, p, outlen);
 
488
                                if (q) *q = '.';
 
489
                        }
 
490
                } else {
 
491
                        p = strchr(user_name->strvalue, '\\');
 
492
                        if (!p) {
 
493
                                DEBUG2("  rlm_mschap: No NT-Domain was found in the User-Name.");
 
494
                                return 0;
 
495
                        }
 
496
 
 
497
                        /*
 
498
                         *      Hack.  This is simpler than the alternatives.
 
499
                         */
 
500
                        *p = '\0';
 
501
                        strNcpy(out, user_name->strvalue, outlen);
 
502
                        *p = '\\';
 
503
                }
476
504
 
477
505
                return strlen(out);
478
506
 
488
516
                        return 0;
489
517
                }
490
518
                
491
 
                p = strchr(user_name->strvalue, '\\');
492
 
                if (p) {
493
 
                        p++;    /* skip the backslash */
 
519
                /*
 
520
                 *      First check to see if this is a host/ style User-Name
 
521
                 *      (a la Kerberos host principal)
 
522
                 */
 
523
                if (strncmp(user_name->strvalue, "host/", 5) == 0) {
 
524
                        /*
 
525
                         *      If we're getting a User-Name formatted in this way,
 
526
                         *      it's likely due to PEAP.  When authenticating this against
 
527
                         *      a Domain, Windows will expect the User-Name to be in the
 
528
                         *      format of hostname$, the SAM version of the name, so we
 
529
                         *      have to convert it to that here.  We do so by stripping
 
530
                         *      off the first 5 characters (host/), and copying everything
 
531
                         *      from that point to the first period into a string and appending
 
532
                         *      a $ to the end.
 
533
                         */
 
534
                        p = strchr(user_name->strvalue, '.');
 
535
                        /*
 
536
                         * use the same hack as above
 
537
                         * only if a period was found
 
538
                         */
 
539
                        if (p) *p = '\0';
 
540
                        snprintf(out, outlen, "%s$", user_name->strvalue + 5);
 
541
                        if (p) *p = '.';
494
542
                } else {
495
 
                        p = user_name->strvalue; /* use the whole User-Name */
 
543
                        p = strchr(user_name->strvalue, '\\');
 
544
                        if (p) {
 
545
                                p++;    /* skip the backslash */
 
546
                        } else {
 
547
                                p = user_name->strvalue; /* use the whole User-Name */
 
548
                        }
 
549
                        strNcpy(out, p, outlen);
496
550
                }
497
551
 
498
 
                strNcpy(out, p, outlen);
499
552
                return strlen(out);
500
553
 
501
554
        } else {