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

« back to all changes in this revision

Viewing changes to src/appl/telnet/libtelnet/kerberos5.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:
66
66
#include <errno.h>
67
67
#include <stdio.h>
68
68
#include "krb5.h"
 
69
#include "k5-platform.h"
69
70
 
70
71
#include "com_err.h"
71
72
#include <netdb.h>
266
267
 
267
268
            rdata.magic = 0;
268
269
            rdata.length = strlen(telnet_krb5_realm);
269
 
            rdata.data = (char *) malloc(rdata.length + 1);
 
270
            rdata.data = strdup(telnet_krb5_realm);
270
271
            if (rdata.data == NULL) {
271
272
                fprintf(stderr, "malloc failed\n");
272
273
                return(0);
273
274
            }
274
 
            strcpy(rdata.data, telnet_krb5_realm);
275
275
            krb5_princ_set_realm(telnet_context, creds.server, &rdata);
276
276
        }
277
277
 
440
440
                    r = krb5_rd_req(telnet_context, &auth_context, &auth,
441
441
                                    NULL, keytabid, NULL, &ticket);
442
442
                if (r) {
443
 
                        (void) strcpy(errbuf, "krb5_rd_req failed: ");
444
 
                        errbuf[sizeof(errbuf) - 1] = '\0';
445
 
                        (void) strncat(errbuf, error_message(r), sizeof(errbuf) - 1 - strlen(errbuf));
 
443
                        (void) snprintf(errbuf, sizeof(errbuf),
 
444
                                        "krb5_rd_req failed: %s",
 
445
                                        error_message(r));
446
446
                        goto errout;
447
447
                }
448
448
 
452
452
                 * the default is of length 4.
453
453
                 */
454
454
                if (krb5_princ_size(telnet_context,ticket->server) < 1) {
455
 
                    (void) strcpy(errbuf, "malformed service name");
 
455
                    (void) strlcpy(errbuf, "malformed service name",
 
456
                                   sizeof(errbuf));
456
457
                    goto errout;
457
458
                }
458
459
                if (krb5_princ_component(telnet_context,ticket->server,0)->length < 256) {
464
465
                                               ticket->server,0)->length] = '\0';
465
466
                    if (strcmp("host", princ)) {
466
467
                        if(strlen(princ) < sizeof(errbuf) - 39) {
467
 
                            (void) sprintf(errbuf, "incorrect service name: \"%s\" != \"host\"",
 
468
                            (void) snprintf(errbuf, sizeof(errbuf), "incorrect service name: \"%s\" != \"host\"",
468
469
                                           princ);
469
470
                        } else {
470
 
                            (void) sprintf(errbuf, "incorrect service name: principal != \"host\"");
 
471
                            (void) snprintf(errbuf, sizeof(errbuf), "incorrect service name: principal != \"host\"");
471
472
                        }
472
473
                        goto errout;
473
474
                    }
474
475
                } else {
475
 
                    (void) strcpy(errbuf, "service name too long");
 
476
                    (void) strlcpy(errbuf, "service name too long",
 
477
                                   sizeof(errbuf));
476
478
                    goto errout;
477
479
                }
478
480
 
480
482
                                                   auth_context,
481
483
                                                   &authenticator);
482
484
                if (r) {
483
 
                    (void) strcpy(errbuf,
484
 
                                  "krb5_auth_con_getauthenticator failed: ");
485
 
                    errbuf[sizeof(errbuf) - 1] = '\0';
486
 
                    (void) strncat(errbuf, error_message(r), sizeof(errbuf) - 1 - strlen(errbuf));
487
 
                    goto errout;
 
485
                        (void) snprintf(errbuf, sizeof(errbuf),
 
486
                                        "krb5_auth_con_getauthenticator failed: %s",
 
487
                                        error_message(r));
 
488
                        goto errout;
488
489
                }
489
490
                if ((ap->way & AUTH_ENCRYPT_MASK) == AUTH_ENCRYPT_ON &&
490
491
                    !authenticator->checksum) {
491
 
                        (void) strcpy(errbuf,
492
 
                                "authenticator is missing required checksum");
 
492
                        (void) strlcpy(errbuf,
 
493
                                "authenticator is missing required checksum",
 
494
                                       sizeof(errbuf));
493
495
                        goto errout;
494
496
                }
495
497
                if (authenticator->checksum) {
503
505
                    r = krb5_auth_con_getkey(telnet_context, auth_context,
504
506
                                             &key);
505
507
                    if (r) {
506
 
                        (void) strcpy(errbuf, "krb5_auth_con_getkey failed: ");
507
 
                        errbuf[sizeof(errbuf) - 1] = '\0';
508
 
                        (void) strncat(errbuf, error_message(r), sizeof(errbuf) - 1 - strlen(errbuf));
 
508
                        (void) snprintf(errbuf, sizeof(errbuf),
 
509
                                        "krb5_auth_con_getkey failed: %s",
 
510
                                        error_message(r));
509
511
                        goto errout;
510
512
                    }
511
513
                    r = krb5_verify_checksum(telnet_context,
522
524
                 * present at this time.
523
525
                 */
524
526
                    if (r) {
525
 
                        (void) strcpy(errbuf,
526
 
                                      "checksum verification failed: ");
527
 
                        errbuf[sizeof(errbuf) - 1] = '\0';
528
 
                        (void) strncat(errbuf, error_message(r), sizeof(errbuf) - 1 - strlen(errbuf));
 
527
                        (void) snprintf(errbuf, sizeof(errbuf),
 
528
                                        "checksum verification failed: %s",
 
529
                                        error_message(r));
529
530
                        goto errout;
530
531
                    }
531
532
                    krb5_free_keyblock(telnet_context, key);
535
536
                    /* do ap_rep stuff here */
536
537
                    if ((r = krb5_mk_rep(telnet_context, auth_context,
537
538
                                         &outbuf))) {
538
 
                        (void) strcpy(errbuf, "Make reply failed: ");
539
 
                        errbuf[sizeof(errbuf) - 1] = '\0';
540
 
                        (void) strncat(errbuf, error_message(r), sizeof(errbuf) - 1 - strlen(errbuf));
 
539
                        (void) snprintf(errbuf, sizeof(errbuf),
 
540
                                        "Make reply failed: %s",
 
541
                                        error_message(r));
541
542
                        goto errout;
542
543
                    }
543
544
 
589
590
                           &inbuf, ticket))) {
590
591
 
591
592
                    char kerrbuf[128];
592
 
                    
593
 
                    (void) strcpy(kerrbuf, "Read forwarded creds failed: ");
594
 
                    kerrbuf[sizeof(kerrbuf) - 1] = '\0';
595
 
                    (void) strncat(kerrbuf, error_message(r), 
596
 
                        sizeof(kerrbuf) - 1 - strlen(kerrbuf));
 
593
 
 
594
                    (void) snprintf(kerrbuf, sizeof(kerrbuf),
 
595
                                    "Read forwarded creds failed: %s",
 
596
                                    error_message(r));
597
597
                    Data(ap, KRB_FORWARD_REJECT, kerrbuf, -1);
598
598
                    if (auth_debug_mode)
599
599
                      printf(
618
618
        {
619
619
            char eerrbuf[329];
620
620
 
621
 
            strcpy(eerrbuf, "telnetd: ");
622
 
            eerrbuf[sizeof(eerrbuf) - 1] = '\0';
623
 
            strncat(eerrbuf, errbuf, sizeof(eerrbuf) - 1 - strlen(eerrbuf));
 
621
            snprintf(eerrbuf, sizeof(eerrbuf), "telnetd: %s", errbuf);
624
622
            Data(ap, KRB_REJECT, eerrbuf, -1);
625
623
        }
626
624
        if (auth_debug_mode)
813
811
#endif  /* FORWARD */
814
812
 
815
813
        default:
816
 
                sprintf(lbuf, " %d (unknown)", data[3]);
 
814
                snprintf(lbuf, sizeof(lbuf), " %d (unknown)", data[3]);
817
815
                strncpy((char *)buf, lbuf, buflen);
818
816
        common2:
819
817
                BUMP(buf, buflen);
820
818
                for (i = 4; i < cnt; i++) {
821
 
                        sprintf(lbuf, " %d", data[i]);
 
819
                        snprintf(lbuf, sizeof(lbuf), " %d", data[i]);
822
820
                        strncpy((char *)buf, lbuf, buflen);
823
821
                        BUMP(buf, buflen);
824
822
                }