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

« back to all changes in this revision

Viewing changes to src/lib/krb5/os/locate_kdc.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:
1
1
/*
2
2
 * lib/krb5/os/locate_kdc.c
3
3
 *
4
 
 * Copyright 1990,2000,2001,2002,2003,2004,2006 Massachusetts Institute of Technology.
 
4
 * Copyright 1990,2000,2001,2002,2003,2004,2006,2008 Massachusetts Institute of Technology.
5
5
 * All Rights Reserved.
6
6
 *
7
7
 * Export of this software from the United States of America may
70
70
    char * value = NULL;
71
71
    int use_dns = 0;
72
72
 
73
 
    code = profile_get_string(context->profile, "libdefaults",
 
73
    code = profile_get_string(context->profile, KRB5_CONF_LIBDEFAULTS,
74
74
                              name, 0, 0, &value);
75
75
    if (value == 0 && code == 0)
76
 
        code = profile_get_string(context->profile, "libdefaults",
77
 
                                  "dns_fallback", 0, 0, &value);
 
76
        code = profile_get_string(context->profile, KRB5_CONF_LIBDEFAULTS,
 
77
                                  KRB5_CONF_DNS_FALLBACK, 0, 0, &value);
78
78
    if (code)
79
79
        return defalt;
80
80
 
89
89
int
90
90
_krb5_use_dns_kdc(krb5_context context)
91
91
{
92
 
    return maybe_use_dns (context, "dns_lookup_kdc", DEFAULT_LOOKUP_KDC);
 
92
    return maybe_use_dns (context, KRB5_CONF_DNS_LOOKUP_KDC, DEFAULT_LOOKUP_KDC);
93
93
}
94
94
 
95
95
int
96
96
_krb5_use_dns_realm(krb5_context context)
97
97
{
98
 
    return maybe_use_dns (context, "dns_lookup_realm", DEFAULT_LOOKUP_REALM);
 
98
    return maybe_use_dns (context, KRB5_CONF_DNS_LOOKUP_REALM, DEFAULT_LOOKUP_REALM);
99
99
}
100
100
 
101
101
#endif /* KRB5_DNS_LOOKUP */
110
110
 
111
111
    newaddrs = realloc (lp->addrs, newsize);
112
112
    if (newaddrs == NULL)
113
 
        return errno;
 
113
        return ENOMEM;
114
114
    lp->addrs = newaddrs;
115
115
    for (i = lp->space; i < newspace; i++) {
116
116
        lp->addrs[i].ai = NULL;
257
257
#ifdef AI_NUMERICSERV
258
258
    hint.ai_flags = AI_NUMERICSERV;
259
259
#endif
260
 
    sprintf(portbuf, "%d", ntohs(port));
261
 
    sprintf(secportbuf, "%d", ntohs(secport));
 
260
    if (snprintf(portbuf, sizeof(portbuf), "%d", ntohs(port)) >= sizeof(portbuf))
 
261
        /* XXX */
 
262
        return EINVAL;
 
263
    if (snprintf(secportbuf, sizeof(secportbuf), "%d", ntohs(secport)) >= sizeof(secportbuf))
 
264
        return EINVAL;
262
265
    err = getaddrinfo (hostname, portbuf, &hint, &addrs);
263
266
    if (err) {
264
267
        Tprintf ("\tgetaddrinfo(\"%s\", \"%s\", ...)\n\treturns %d: %s\n",
322
325
 
323
326
    masterlist = NULL;
324
327
 
325
 
    realm_srv_names[0] = "realms";
 
328
    realm_srv_names[0] = KRB5_CONF_REALMS;
326
329
    realm_srv_names[1] = host;
327
330
    realm_srv_names[2] = name;
328
331
    realm_srv_names[3] = 0;
334
337
                 error_message(code));
335
338
        if (code == PROF_NO_SECTION || code == PROF_NO_RELATION)
336
339
            code = KRB5_REALM_UNKNOWN;
337
 
        krb5_xfree(host);
 
340
        free(host);
338
341
        return code;
339
342
     }
340
343
 
345
348
    
346
349
    if (count == 0) {
347
350
        profile_free_list(hostlist);
348
 
        krb5_xfree(host);
 
351
        free(host);
349
352
        addrlist->naddrs = 0;
350
353
        return 0;
351
354
    }
352
355
    
353
356
    if (get_masters) {
354
 
        realm_srv_names[0] = "realms";
 
357
        realm_srv_names[0] = KRB5_CONF_REALMS;
355
358
        realm_srv_names[1] = host;
356
 
        realm_srv_names[2] = "admin_server";
 
359
        realm_srv_names[2] = KRB5_CONF_ADMIN_SERVER;
357
360
        realm_srv_names[3] = 0;
358
361
 
359
362
        code = profile_get_values(context->profile, realm_srv_names,
360
363
                                  &masterlist);
361
364
 
362
 
        krb5_xfree(host);
 
365
        free(host);
363
366
 
364
367
        if (code == 0) {
365
368
            for (i=0; masterlist[i]; i++) {
380
383
            }
381
384
        }
382
385
    } else {
383
 
        krb5_xfree(host);
 
386
        free(host);
384
387
    }
385
388
 
386
389
    /* at this point, if master is non-NULL, then either the master kdc
569
572
        struct addrinfo ai;
570
573
        union {
571
574
            struct sockaddr_in sin;
 
575
#ifdef KRB5_USE_INET6
572
576
            struct sockaddr_in6 sin6;
 
577
#endif
573
578
        } u;
574
579
    } *x;
575
580
 
576
581
    if (socktype != SOCK_STREAM && socktype != SOCK_DGRAM)
577
582
        return 0;
578
 
    if (sa->sa_family != AF_INET && sa->sa_family != AF_INET6)
 
583
    if (sa->sa_family != AF_INET
 
584
#ifdef KRB5_USE_INET6
 
585
        && sa->sa_family != AF_INET6
 
586
#endif
 
587
        )
579
588
        return 0;
580
 
    x = malloc (sizeof (*x));
 
589
    x = calloc (1, sizeof (*x));
581
590
    if (x == 0) {
582
591
        d->out_of_mem = 1;
583
592
        return 1;
584
593
    }
585
 
    memset(x, 0, sizeof (*x));
586
594
    x->ai.ai_addr = (struct sockaddr *) &x->u;
587
595
    x->ai.ai_socktype = socktype;
588
596
    x->ai.ai_family = sa->sa_family;
590
598
        x->u.sin = *(struct sockaddr_in *)sa;
591
599
        x->ai.ai_addrlen = sizeof(struct sockaddr_in);
592
600
    }
 
601
#ifdef KRB5_USE_INET6
593
602
    if (sa->sa_family == AF_INET6) {
594
603
        x->u.sin6 = *(struct sockaddr_in6 *)sa;
595
604
        x->ai.ai_addrlen = sizeof(struct sockaddr_in6);
596
605
    }
 
606
#endif
597
607
    if (add_addrinfo_to_list (d->lp, &x->ai, free, x) != 0) {
598
608
        /* Assumes only error is ENOMEM.  */
599
609
        d->out_of_mem = 1;
702
712
 
703
713
    switch (svc) {
704
714
    case locate_service_kdc:
705
 
        profname = "kdc";
 
715
        profname = KRB5_CONF_KDC;
706
716
        /* We used to use /etc/services for these, but enough systems
707
717
           have old, crufty, wrong settings that this is probably
708
718
           better.  */
711
721
        dflport2 = htons(KRB5_DEFAULT_SEC_PORT);
712
722
        break;
713
723
    case locate_service_master_kdc:
714
 
        profname = "master_kdc";
 
724
        profname = KRB5_CONF_MASTER_KDC;
715
725
        goto kdc_ports;
716
726
    case locate_service_kadmin:
717
 
        profname = "admin_server";
 
727
        profname = KRB5_CONF_ADMIN_SERVER;
718
728
        dflport1 = htons(DEFAULT_KADM5_PORT);
719
729
        break;
720
730
    case locate_service_krb524:
721
 
        profname = "krb524_server";
 
731
        profname = KRB5_CONF_KRB524_SERVER;
722
732
        serv = getservbyname(KRB524_SERVICE, "udp");
723
733
        dflport1 = serv ? serv->s_port : htons (KRB524_PORT);
724
734
        break;
725
735
    case locate_service_kpasswd:
726
 
        profname = "kpasswd_server";
 
736
        profname = KRB5_CONF_KPASSWD_SERVER;
727
737
        dflport1 = htons(DEFAULT_KPASSWD_PORT);
728
738
        break;
729
739
    default: