~ubuntu-branches/ubuntu/maverick/krb5/maverick

« back to all changes in this revision

Viewing changes to src/appl/bsd/krlogin.c

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hartman
  • Date: 2009-05-07 16:16:34 UTC
  • mfrom: (13.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20090507161634-xqyk0s9na0le4flj
Tags: 1.7dfsg~beta1-4
When  decrypting the TGS response fails with the subkey, try with the
session key to work around Heimdal bug, Closes: #527353 

Show diffs side-by-side

added added

removed removed

Lines of Context:
158
158
#ifdef KERBEROS
159
159
#include <krb5.h>
160
160
#include <com_err.h>
161
 
#ifdef KRB5_KRB4_COMPAT
162
 
#include <kerberosIV/krb.h>
163
 
#endif
164
161
#include "defines.h"
165
162
     
166
163
#define RLOGIN_BUFSIZ 5120
174
171
krb5_context bsd_context;
175
172
krb5_auth_context auth_context;
176
173
 
177
 
#ifdef KRB5_KRB4_COMPAT
178
 
Key_schedule v4_schedule;
179
 
CREDENTIALS v4_cred;
180
 
#endif
181
 
 
182
174
#ifndef UCB_RLOGIN
183
175
#define UCB_RLOGIN      "/usr/ucb/rlogin"
184
176
#endif
382
374
    int sock;
383
375
    krb5_flags authopts;
384
376
    krb5_error_code status;
385
 
#ifdef KRB5_KRB4_COMPAT
386
 
    KTEXT_ST v4_ticket;
387
 
    MSG_DAT v4_msg_data;
388
 
    int v4only = 0;
389
 
#endif
390
377
#endif
391
378
    int port, debug_port = 0;
392
379
    enum kcmd_proto kcmd_proto = KCMD_PROTOCOL_COMPAT_HACK;
484
471
                    "rlogin: -k flag must be followed with a realm name.\n");
485
472
            exit (1);
486
473
        }
487
 
        if(!(krb_realm = (char *)malloc(strlen(*argv) + 1))){
 
474
        if(!(krb_realm = strdup(*argv))){
488
475
            fprintf(stderr, "rlogin: Cannot malloc.\n");
489
476
            exit(1);
490
477
        }
491
 
        strcpy(krb_realm, *argv);
492
478
        argv++, argc--;
493
479
        goto another;
494
480
    }
525
511
        argv++, argc--;
526
512
        goto another;
527
513
    }
528
 
#ifdef KRB5_KRB4_COMPAT
529
 
    if (argc > 0 && !strcmp(*argv, "-4")) {
530
 
        v4only++;
531
 
        argv++, argc--;
532
 
        goto another;
533
 
    }
534
 
#endif /* krb4 */
535
514
#endif /* KERBEROS */
536
515
    if (host == 0)
537
516
      goto usage;
538
517
    if (argc > 0)
539
518
      goto usage;
540
 
#ifdef KRB5_KRB4_COMPAT
541
 
    if (kcmd_proto != KCMD_PROTOCOL_COMPAT_HACK && v4only) {
542
 
        com_err (argv[0], 0,
543
 
                 "-4 is incompatible with -PO/-PN");
544
 
        exit(1);
545
 
    }
546
 
#endif
547
519
    pwd = getpwuid(getuid());
548
520
    if (pwd == 0) {
549
521
        fprintf(stderr, "Who are you?\n");
601
573
                if (ospeed >= 50)
602
574
                        /* On some systems, ospeed is the baud rate itself,
603
575
                           not a table index.  */
604
 
                        sprintf (term + strlen (term), "%d", ospeed);
 
576
                        snprintf (term + strlen (term),
 
577
                                  sizeof(term) - strlen(term), "%d", ospeed);
605
578
                else if (ospeed >= sizeof(speeds)/sizeof(char*))
606
579
                        /* Past end of table, but not high enough to
607
580
                           look like a real speed.  */
662
635
    if (Fflag)
663
636
      authopts |= OPTS_FORWARDABLE_CREDS;
664
637
 
665
 
#ifdef KRB5_KRB4_COMPAT
666
 
    if (v4only)
667
 
        goto try_v4;
668
 
#endif
669
638
    status = kcmd(&sock, &host, port,
670
639
                  null_local_username ? "" : pwd->pw_name,
671
640
                  name ? name : pwd->pw_name, term,
682
651
        if (kcmd_proto == KCMD_NEW_PROTOCOL && encrypt_flag)
683
652
            /* Don't fall back to something less secure.  */
684
653
            exit (1);
685
 
#ifdef KRB5_KRB4_COMPAT
686
 
        fprintf(stderr, "Trying krb4 rlogin...\n");
687
 
    try_v4:
688
 
        status = k4cmd(&sock, &host, port,
689
 
                       null_local_username ? "" : pwd->pw_name,
690
 
                       name ? name : pwd->pw_name, term,
691
 
                       0, &v4_ticket, "rcmd", krb_realm,
692
 
                       &v4_cred, v4_schedule, &v4_msg_data, &local, &foreign,
693
 
                       (encrypt_flag) ? KOPT_DO_MUTUAL : 0L, 0);
694
 
        if (status)
695
 
            try_normal(orig_argv);
696
 
        rcmd_stream_init_krb4(v4_cred.session, encrypt_flag, 1, 1);
697
 
#else
698
654
        try_normal(orig_argv);
699
 
#endif
700
655
    } else {
701
656
        krb5_keyblock *key = 0;
702
657
 
740
695
#ifdef KERBEROS
741
696
    fprintf (stderr,
742
697
             "usage: rlogin host [-option] [-option...] [-k realm ] [-t ttytype] [-l username]\n");
743
 
#ifdef KRB5_KRB4_COMPAT
744
 
    fprintf (stderr, "     where option is e, 7, 8, noflow, n, a, x, f, F, c, 4, PO, or PN\n");
745
 
#else
746
698
    fprintf (stderr, "     where option is e, 7, 8, noflow, n, a, x, f, F, c, PO, or PN\n");
747
 
#endif
748
699
#else /* !KERBEROS */
749
700
    fprintf (stderr,
750
701
             "usage: rlogin host [-option] [-option...] [-t ttytype] [-l username]\n");
763
714
    if (!confirm) return (1);   /* no confirm, just die */
764
715
    
765
716
    if (gethostname (hostname, sizeof(hostname)-1) != 0)
766
 
      strcpy (hostname, "???");
 
717
      strlcpy (hostname, "???", sizeof(hostname));
767
718
    else
768
719
      hostname[sizeof(hostname)-1] = '\0';
769
720
    
1795
1746
prf(f)
1796
1747
     char *f;
1797
1748
{
1798
 
    fprintf(stderr, f);
 
1749
    fprintf(stderr, "%s", f);
1799
1750
    fprintf(stderr, CRLF);
1800
1751
}
1801
1752